import { readFileSync } from 'node:fs'; import path from 'path'; import { describe, expect, it } from 'vitest'; describe('称上识别轻量候选名单', () => { const weighSrc = readFileSync( path.join(__dirname, '../src/services/weighStationService.ts'), 'utf8' ); const processingSrc = readFileSync( path.join(__dirname, '../src/services/processingTaskService.ts'), 'utf8' ); const routesSrc = readFileSync( path.join(__dirname, '../src/routes/mobile/mobileWarehouseRoutes.ts'), 'utf8' ); it('验收识别走 catalog,不走重列表 attach/received_qty', () => { expect(weighSrc).toContain('listPendingInspectionWeighStationCatalog'); const recognizeBody = weighSrc.slice( weighSrc.indexOf('export async function recognizeInspectionWeighStation'), weighSrc.indexOf('export async function recognizeProcessingInspectWeighStation') ); expect(recognizeBody).toContain('listPendingInspectionWeighStationCatalog'); expect(recognizeBody).not.toContain('listPendingInspectionWeighStationItems'); expect(recognizeBody).not.toContain('attachCategoryPhotoInspectionRequirements'); expect(recognizeBody).not.toContain('received_qty'); const catalogBody = weighSrc.slice( weighSrc.indexOf('export async function listPendingInspectionWeighStationCatalog'), weighSrc.indexOf('export async function recognizeInspectionWeighStation') ); expect(catalogBody).not.toContain('received_qty'); expect(catalogBody).not.toContain('attachCategoryPhotoInspectionRequirements'); expect(catalogBody).not.toContain('LIMIT 200'); }); it('分拣识别走 catalog,不拉 enriched 全量', () => { const recognizeBody = weighSrc.slice( weighSrc.indexOf('export async function recognizeWeighStation'), weighSrc.indexOf('function inspectionPendingBranchClause') ); expect(recognizeBody).toContain('listPendingWeighStationCatalog'); expect(recognizeBody).not.toContain('listPendingWeighStationItems'); expect(weighSrc).toContain('listPendingWeighStationCatalog'); }); it('加工验收识别走轻量 catalog', () => { expect(processingSrc).toContain('listProcessingInspectCatalogForRecognize'); const recognizeBody = weighSrc.slice( weighSrc.indexOf('export async function recognizeProcessingInspectWeighStation'), weighSrc.indexOf('export async function commitWeighStation') ); expect(recognizeBody).toContain('listProcessingInspectCatalogForRecognize'); expect(recognizeBody).not.toContain('listProcessingTasks'); }); it('AI_CATALOG_MAX 仍导出;开放认品对全量 catalog 匹配、不截断再喂模型', () => { expect(weighSrc).toContain('export const AI_CATALOG_MAX = 80'); const recognizeBody = weighSrc.slice( weighSrc.indexOf('export async function recognizeAgainstCatalog'), weighSrc.indexOf('export async function recognizeWeighStation') ); expect(recognizeBody).toContain('recognizeProductFromImage'); expect(recognizeBody).toContain('catalog,'); expect(recognizeBody).not.toContain('catalogForAi.slice(0, AI_CATALOG_MAX)'); expect(recognizeBody).toContain('toCandidateRows(items'); }); it('待验/待拣 meta、search、product 函数存在', () => { expect(weighSrc).toContain('export async function getPendingInspectionWeighStationMeta'); expect(weighSrc).toContain('export async function searchPendingInspectionWeighStation'); expect(weighSrc).toContain('export async function listPendingInspectionWeighStationByProduct'); expect(weighSrc).toContain('export async function getPendingWeighStationMeta'); expect(weighSrc).toContain('export async function searchPendingWeighStation'); expect(weighSrc).toContain('export async function listPendingWeighStationByProduct'); }); it('pending 路由默认 meta,search/product 已挂载', () => { expect(routesSrc).toContain("/inspection/weigh-station/pending"); expect(routesSrc).toContain("/inspection/weigh-station/search"); expect(routesSrc).toContain("/inspection/weigh-station/product"); expect(routesSrc).toContain("/picking/weigh-station/pending"); expect(routesSrc).toContain("/picking/weigh-station/search"); expect(routesSrc).toContain("/picking/weigh-station/product"); expect(routesSrc).toContain("getPendingInspectionWeighStationMeta"); expect(routesSrc).toContain("getPendingWeighStationMeta"); expect(routesSrc).toContain("mode"); expect(routesSrc).toContain('meta'); expect(routesSrc).toContain("!== 'full'"); }); });