import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import test from 'node:test' const source = readFileSync(new URL('./phase3-evidence-gate.mjs', import.meta.url), 'utf8') test('evidence gate requires stable PDA identity and server LOADING before any evidence request', () => { for (const field of ['taskId', 'inboundId', 'loadingPlanId', 'containerBookingId', 'warehouseId']) { assert.match(source, new RegExp(`${field}`), `${field} must be part of the preflight identity`) } assert.match(source, /pda-loading\/tasks\/\$\{encodeURIComponent\(taskId\)\}\?warehouseId=/) assert.doesNotMatch(source, /pda-loading\/tasks\?loadingPlanId=/) assert.match(source, /task\?\.id\) === taskId/) assert.match(source, /task\?\.loadingPlanId\) === loadingPlanId/) assert.match(source, /task\?\.containerBookingId\) === containerBookingId/) assert.match(source, /taskItem\?\.inboundId\) === inboundId/) assert.match(source, /\['LOADING', 'LOADED'\]\.includes\(inbound\?\.summary\?\.processStatus\)/) assert.match(source, /if \(!evidenceReadable\)[\s\S]*return/) assert.match(source, /AWAITING_REVIEW 不作为证据开放条件/) const gate = source.slice(source.indexOf('const taskResponse'), source.indexOf('const path =')) assert.doesNotMatch(gate, /loading\/evidence/) assert.match(source, /const path = `\/api\/platform\/v1\/first-leg\/pda-loading\/tasks\/\$\{encodeURIComponent\(taskId\)\}\/evidence\?warehouseId=/) assert.doesNotMatch(source, /api\/platform\/v1\/inbounds\/\$\{inboundId\}\/loading\/evidence/) assert.doesNotMatch(source, /loading\/evidence\?tenantId=/) })