4.3 KiB
4.3 KiB
Task 12 report
Implementation
- Code commit:
5d094183e66663dca69e7d95325cabebc38e5d82 - Added
POST /api/dn-batches/[id]/notes/[noteId]/post.- Reloads the batch, candidate, pages, supplier, PO, every PO item, and checks server-side.
- Reuses the fail-closed readiness evaluator and returns
409 needs_reviewwith reasons. - Calls
promoteNotedirectly so it owns the batch lease. - Validates posted-candidate associations and returns the existing delivery note on retry.
- Adds an idempotent
postaudit event after promotion.
- Added read-only
scripts/compare-dn-pipelines.tswith<batch-id>and--allmodes. - Documented migration, environment, tick/lock recovery, shadow rollout, metrics, feature flag, rollback, and direct-financial-edit warnings in
docs/operations.md. - Added route tests for review blocking, one-time posting, and idempotent retry.
Verification
npx vitest run 'src/app/api/dn-batches/[id]/notes/[noteId]/post/route.test.ts' src/lib/dn-pipeline/readiness.test.ts src/lib/dn-pipeline/promote.test.ts --maxWorkers=1 --minWorkers=1- 36 tests passed.
npm run typecheck- Passed.
npm run test:run- 104 test files, 1,176 tests passed.
- No Poppler concurrency timeout occurred; serial rerun was not needed.
npm run build- Passed; Next.js listed the new posting route.
git diff --check- Passed.
python3 scripts/pb-add-dn-staged-ingestion.py --dry-runwith the configured PocketBase environment- Passed; reported intended additive collections/fields/indexes and no writes.
Production migration was not applied and DN_STAGED_INGESTION_ENABLED was not changed.
Fix round 1
- Code commit:
2914eefacfeed674c587984d1064914c258df28c - Posting now requires
stage=ready_to_post, selects exactlynote.pagesusing the canonical global ordering (source ordinal, source page, region), and rejects duplicate/missing page assignments. - Posted retries validate the current candidate/batch/site/PO/supplier association before returning the existing delivery note.
- Post-audit writes use deterministic
event_key=dn-post:<noteId>with a unique migration index. Audit failure returns a truthful posted response withauditPending: true, so a retry can converge without duplicating financial rows. - Comparison reads now fail loudly on PocketBase/schema errors and report unit compatibility as
compatible,incompatible, orunknown; missing units are never counted as compatible. - Added regression tests for the ready-stage gate, non-first page selection, audit failure, posted association mismatch, and unit classification.
- Focused verification: 40 tests passed;
npm run typecheckpassed; migration--self-testpassed;git diff --checkpassed. - Follow-up code commit:
310219d09bc464f3e01bc9a5054e36c98c3714a7keeps the additive migration dry-run valid beforedn_review_eventsexists;--self-testand configured--dry-runboth pass. - Production migration was not applied and
DN_STAGED_INGESTION_ENABLEDwas not changed.
Fix round 3
- Code commit:
eed128ebb3818b89b7828adc0d8e461518dfdca5 - Audit identity now reads and validates
after.delivery_notein addition to event key, batch, note, and action. A same-note event pointing to another delivery note is treated as a collision and remains pending. - Added the mismatched-delivery-note regression test.
- Focused verification: 9 posting tests passed;
npm run typecheckpassed;git diff --checkpassed. - Production migration was not applied and
DN_STAGED_INGESTION_ENABLEDwas not changed.
Fix round 2
- Code commit:
11bc1a4b6bb9bebb7e145449346bc46a99c437cf - Deterministic audit-key create collisions are re-read immediately. A winner is accepted only when its batch, note, and action match; wrong-entity collisions remain
auditPendingwithaudit_key_collision. - Comparison now verifies every referenced PO server-side. Output separates linked and verified PO counts; missing POs remain unresolved while non-404 PocketBase read errors fail loudly.
- Added regression tests for concurrent audit winner confirmation, wrong-key collisions, valid/missing/error PO verification, and verified PO match counts.
- Focused verification: 11 tests passed;
npm run typecheckpassed;git diff --checkpassed. - Production migration was not applied and
DN_STAGED_INGESTION_ENABLEDwas not changed.