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}'`); } } }); });