现象(开发者 2026-10-14 截图报障):验收照片复核页「出库照片」Tab 的 KPI 卡显示 2 条,
列表却提示「当前筛选范围暂无出库照片」(近七天 / 指定 2026-10-14~2026-10-14 / 下单日)。
根因:**同一份照片,读的一方用了另一个桶**。
- 上传侧写 `delivery-photos`:`/storage/delivery-photos/upload`
(src/utils/workflowApi.ts 注释「分拣出库留证照片上传(bucket=delivery-photos)」);
- 分拣详情读图也用 `delivery-photos`(pickingService.buildSignedStoragePath('delivery-photos', p));
- 但「出库照片」Tab 走 signedExistingPhotos 的**默认桶 inspection-photos**。
`signedExistingPhotos` 会逐个 storage.exists 校验,且列表末尾 `filter(photos.length > 0)`
把取不到照片的行整行丢掉 ⇒ 列表恒空;而 KPI 计数只查库
(array_length(outbound_photos,1) > 0),不做存储校验 ⇒ 照常有数。这就是「卡片 2、列表 0」。
实测证据(BR002 / 本地库 + 真实 COS):
- 库里恰有 2 行 picking_items.outbound_photos(抄手皮、瘦肉,2026-10-14);
- 存储探针:exists('inspection-photos', …) = **false**;exists('delivery-photos', …) = **true**;
- 改前 listPickingOutboundPhotoReviews 返回 0 行 / KPI picking_outbound = 2;
- 改后返回 **2 行且照片带签名 URL** / KPI 仍 2 ⇒ 两侧一致。
改法:该 Tab 显式传 `DELIVERY_PHOTO_BUCKET`(本文件已有该常量,配送签收照在用)。
其余三个 Tab 的桶不变(入库照/配送补拍都在 inspection-photos,本来就对)。
测试:server/tests/pickingOutboundPhotos.test.ts 增用例钉住「读 delivery-photos 桶」
且「上传侧同桶」(防止单侧再被改回去)。
回归:0 新增失败(2960 passed / 32 failed);tsc 0 错误;设计门禁 8 通过 / 2 既有红。
无迁移、无数据变更(照片一直在原桶,只是读错桶)。
99 lines
4.5 KiB
TypeScript
99 lines
4.5 KiB
TypeScript
import { readFileSync } from 'fs';
|
||
import { describe, expect, it } from 'vitest';
|
||
|
||
const reviewSrc = readFileSync(
|
||
new URL('../src/services/inspectionReviewService.ts', import.meta.url),
|
||
'utf8'
|
||
);
|
||
const reviewOps = readFileSync(
|
||
new URL('../src/services/inspectionReviewOps.ts', import.meta.url),
|
||
'utf8'
|
||
);
|
||
const reviewRoute = readFileSync(
|
||
new URL('../src/modules/workflow/routes/inspectionRoutes.ts', import.meta.url),
|
||
'utf8'
|
||
);
|
||
const mcpTool = readFileSync(new URL('../src/mcp/tools/inspectionReview.ts', import.meta.url), 'utf8');
|
||
const page = readFileSync(
|
||
new URL('../../src/pages/inspection/InspectionReviewManagement.tsx', import.meta.url),
|
||
'utf8'
|
||
);
|
||
const contract = readFileSync(
|
||
new URL('../../src/pages/inspection/copilotInspectionReviewPageContract.ts', import.meta.url),
|
||
'utf8'
|
||
);
|
||
const api = readFileSync(new URL('../../src/utils/workflowApi.ts', import.meta.url), 'utf8');
|
||
const zh = readFileSync(new URL('../../src/i18n/locales/zh-CN/inspection.ts', import.meta.url), 'utf8');
|
||
const en = readFileSync(new URL('../../src/i18n/locales/en/inspection.ts', import.meta.url), 'utf8');
|
||
const id = readFileSync(new URL('../../src/i18n/locales/id/inspection.ts', import.meta.url), 'utf8');
|
||
|
||
describe('出库照片复核 Tab(picking_items.outbound_photos)', () => {
|
||
it('服务读 picking_items.outbound_photos 并标 picking_outbound(与配送补拍口径独立)', () => {
|
||
expect(reviewSrc).toContain('export async function listPickingOutboundPhotoReviews');
|
||
expect(reviewSrc).toContain('pi.outbound_photos');
|
||
expect(reviewSrc).toContain("'picking_outbound'::text AS source_type");
|
||
expect(reviewOps).toContain('listPickingOutboundPhotoReviews');
|
||
});
|
||
|
||
it('Tab 计数含 picking_outbound(四项)', () => {
|
||
expect(reviewSrc).toContain('delivery_sign, picking_outbound] = await Promise.all([');
|
||
expect(reviewSrc).toContain(
|
||
'return { inspections, loading_photos, delivery_sign, picking_outbound }'
|
||
);
|
||
});
|
||
|
||
/**
|
||
* **出库留证照片存在 `delivery-photos` 桶**(上传侧 `/storage/delivery-photos/upload`,
|
||
* 分拣详情读图同用 `buildSignedStoragePath('delivery-photos', p)`)。
|
||
*
|
||
* 2026-10-14 实测缺陷:列表原来走 `signedExistingPhotos` 的默认桶 `inspection-photos`
|
||
* ⇒ `storage.exists` 全 false ⇒ 行被 `photos.length > 0` 过滤掉,**列表恒为空**,
|
||
* 而 KPI 卡只数库里的 `array_length(outbound_photos,1) > 0` 照常有数
|
||
* (BR002 实测:KPI「出库照片 2」而列表 0 行;两个文件确实在 delivery-photos 桶里)。
|
||
*/
|
||
it('出库照片读 delivery-photos 桶(否则 storage.exists 全 false ⇒ 列表恒空而 KPI 有数)', () => {
|
||
const fn = reviewSrc.slice(reviewSrc.indexOf('export async function listPickingOutboundPhotoReviews'));
|
||
const body = fn.slice(0, fn.indexOf('export async function listDeliverySignPhotoReviews'));
|
||
expect(body).toContain('await signedExistingPhotos(row.inspection_photos, DELIVERY_PHOTO_BUCKET)');
|
||
expect(body).not.toContain('await signedExistingPhotos(row.inspection_photos);');
|
||
// 上传侧必须是同一个桶(本用例的意义在于两侧一致,不只单侧改)
|
||
expect(api).toContain('/storage/delivery-photos/upload');
|
||
});
|
||
|
||
it('Web 路由与 MCP 按 source=picking_outbound 分流', () => {
|
||
expect(reviewRoute).toContain("source === 'picking_outbound'");
|
||
expect(reviewRoute).toContain('listPickingOutboundPhotoReviews');
|
||
expect(mcpTool).toContain("statusRaw === 'picking_outbound'");
|
||
expect(mcpTool).toContain('listPickingOutboundPhotoReviews');
|
||
});
|
||
|
||
it('前端接入第 4 个 Tab、列与 Copilot 动作', () => {
|
||
expect(page).toContain('PICKING_OUTBOUND_COLUMNS');
|
||
expect(page).toContain("t('inspection.review.tab.pickingOutbound')");
|
||
expect(page).toContain("t('inspection.review.empty.pickingOutbound')");
|
||
expect(page).toContain("actionId === 'show_picking_outbound'");
|
||
expect(contract).toContain("'picking_outbound'");
|
||
expect(contract).toContain('show_picking_outbound');
|
||
expect(api).toContain('picking_outbound');
|
||
});
|
||
|
||
it('三语均含 6 个新键(i18n 键一致)', () => {
|
||
for (const [name, src] of [
|
||
['zh-CN', zh],
|
||
['en', en],
|
||
['id', id],
|
||
] as const) {
|
||
for (const key of [
|
||
'review.tab.pickingOutbound',
|
||
'review.aria.pickingOutbound',
|
||
'review.col.pickingTime',
|
||
'review.source.pickingOutbound',
|
||
'review.list.pickingOutbound',
|
||
'review.empty.pickingOutbound',
|
||
]) {
|
||
expect(src, `${name} 缺 ${key}`).toContain(`'${key}'`);
|
||
}
|
||
}
|
||
});
|
||
});
|