Repository navigation
feat(intake): work orders carry a default deadline from intake [TURNWRK-785] - #50
Conversation
…RK-785] Scheduled is when the vendor intends to come; nothing said when the work is owed. Add WORK_ORDER_DEADLINE_DEFAULTS (emergency +4h, High +24h, Medium +72h, Low +7d), the pure defaultWorkOrderDeadline, and a workOrderDeadline reader that keeps legacy work orders undated (no scheduledDate fallback). The shared Accept builder now stamps dueAtUtc and dueReason from the final priority and the emergency flag. PR 1 of 3; dispatch and cortex adopt it next. Refs: TURNWRK-785 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
practical-bot
left a comment
There was a problem hiding this comment.
✅ Approve
The shared helper is deterministic and the focused tests verify every deadline row, emergency precedence, final-priority stamping, and undated legacy reads.
| Check | Result | Ref |
|---|---|---|
| focused intake tests | ✅ 23 tests passed in 2 files | npm exec vitest run tests/intake/deadline.test.ts tests/intake/accept.test.ts |
| typecheck + unit CI | ✅ success; typecheck, unit suite, build, email typecheck, vendored checks | GitHub Actions run 47058444190 |
| firestore rules behavior tests CI | ✅ success | GitHub Actions run 47058444190 |
| secret scan CI | ✅ success | GitHub Actions run 47058444190 |
| diff whitespace | ✅ no whitespace errors | git diff --check origin/main...HEAD |
| PR mutation ledger | ⚪ The body claims 11 one-line mutations were killed; focused tests and CI were run, but the mutations were not independently replayed in this read-only review. | PR body Mutations table |
Review record
DESIGN: DESIGN: Put one named deadline table and pure calculator in the shared intake package, with WorkOrder deadline fields optional so legacy documents remain undated.
DESIGN: DESIGN: Stamp the calculated deadline in the shared acceptance builder after emergency and rule priority resolution, without deriving it from scheduledDate or adding a model/config dependency.
DESIGN: DESIGN: Test each table row, emergency precedence, final-priority stamping, invalid timestamps, and a legacy reader that returns null without dueAtUtc.
ADVERSARIAL: ADVERSARIAL: The strongest case against approval is that a deadline could be stamped from the draft priority rather than the final rule/emergency priority; the focused accept tests passed for both rule override and emergency precedence, and CI typecheck/unit/build passed on head 922334b.
REVIEW VERDICT: approve
REVIEWED DIFF: base=main files=6 lines=205
REVIEW RUN: dispatch=rev-sweep-turnwrk-shared-50-922334b thread=ae00b91c-a9dc-4353-a274-5378d37578f2 model=codex/gpt-5.6-luna
NOT READ: none
Legend: ✅ approve or pass · ❌ changes requested or fail · 👤 a person approves too ·
|
🤖 alan+factory's merge:on-approve on TURNWRK-785, checks green, queued for merge ( |
Why
PR 1 of 3: the shared default table, the pure deadline function, the undated reader, and the Accept builder stamping it. Dispatch (create paths, UI override) and cortex (AI intake) adopt it in PRs 2 and 3.
A work order carries
scheduledDate(when the vendor intends to come) but nothing says when the work is owed, which is what tells a manager when to step in. Every writer needs the same deterministic default, so the table lives here.What changed
Net source lines vs main: +95 (tests excluded): one new 70-line module (table, function, reader), 21 lines of types, a 3-line stamp in the Accept builder, one export line.
src/intake/deadline.ts(new, exported from@turnwrk/shared/intake):WORK_ORDER_DEADLINE_DEFAULTS, a named constant in hours from intake: emergency 4, High 24, Medium 72, Low 168 (7 days).defaultWorkOrderDeadline({ priority, isEmergency }, intakeAtMs) -> { dueAtUtc, dueReason }. The emergency flag wins over priority. A priority outside the union (untyped model output) reads as Medium, the same defaultacceptedDraftsuses. A non-finiteintakeAtMsthrowsRangeErrorrather than writing NaN. Plain elapsed hours, no timezone math: an instant plus a duration is the same instant in every zone, DST included. An invoice'sdueAtUtcneeds the org timezone only because its terms end on a calendar day.workOrderDeadline(wo) -> { dueAtUtc, dueReason } | null. Null unlessdueAtUtcis a finite number. It never derives a date fromscheduledDate. A date with no recognised reason reads asoverride.src/types/workOrder.ts:WODueReason='default:emergency' | 'default:high' | 'default:medium' | 'default:low' | 'override'.overrideis reserved for dispatch's UI leg.WorkOrderDeadlineand the optionalWorkOrderDeadlineFields. The naming follows thedueAtUtcprecedent insrc/money/types.ts.src/intake/accept.ts:buildAcceptedWorkOrdersstampsdueAtUtcanddueReasonfrom the final priority (after the emergency and rule overrides) andisEmergency, counted fromctx.now.What deliberately did NOT change
WorkOrderinterface was added. Shared has never had a fullWorkOrdertype; dispatch'stypes.tsowns it.WorkOrderDeadlineFieldsis there for dispatch'sWorkOrderto extend in PR 2.scheduledDatefallback. Legacy work orders stay undated.buildAcceptedWorkOrdersis the only builder of a new work-order payload insrc/.testFixtures.buildWorkOrderstays undated on purpose: it models an existing work order, and consumer e2e and visual specs build on it.package.jsonor.github/change../intakeis already an export subpath.Proof
The new tests fail on old code (b6ec869 plus the new tests only): 15 failed. The new deadline tests fail with
defaultWorkOrderDeadline is not a function, and the 3 new accept tests fail withexpected { … } to match object { dueAtUtc: … }.Mutations. Each guard was broken with a one-line edit, its single test file run, then restored:
if (false) throwknown ? wo.priority : 'Medium'→wo.priorityrow = priorityPRIORITY_REASON[priority]7 * 24→6 * 24dueAtUtcmust be a number=== undefinedcheck onlydueAtUtcmust be finiteisFiniteDUE_REASONS.haspriority: draft.priorityisEmergency: falseNo new gate: nothing that used to pass is now withheld.
Consumer impact. Read at dispatch
origin/main, restockorigin/main, cleanorigin/trunkand turnwrk-cortexorigin/main:buildAcceptedWorkOrdersare dispatchlib/intake/createIntakeItem.tsandlib/intake/triage.ts, and cortexsrc/services/vendorIngestCore.ts. All pass a numericnow.toEqual,toStrictEqualor snapshot on it). Cortex'svendorIngestIntake.test.tscompares{ id, title }only.WOPriorityis unchanged, so noRecord<…>keyed by it can break. The new names (WODueReason,WorkOrderDeadline*,WORK_ORDER_DEADLINE_DEFAULTS,defaultWorkOrderDeadline,workOrderDeadline) collide with nothing in any consumer.Verification
npm run typecheck: clean.npm run test:run: 80 files, 854 tests passed.npm run build: clean. These ran on the final tree.npx vitest run tests/intake/: 6 files, 112 tests passed.commit-msgwas run by hand: exit 0.git ls-remote origin turnwrk-785-wo-deadline-default=922334ba8d93998979be2c31ed58ee883f0577d7=HEAD.Refs: TURNWRK-785
🤖 Generated with Claude Code