Skip to content

feat(intake): work orders carry a default deadline from intake [TURNWRK-785] - #50

Merged
practical-bot merged 1 commit into
mainfrom
turnwrk-785-wo-deadline-default
Dec 3, 2026
Merged

practical-bot merged 1 commit into
mainfrom
turnwrk-785-wo-deadline-default

Conversation

@Echobob

@Echobob Echobob commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

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 default acceptedDrafts uses. A non-finite intakeAtMs throws RangeError rather 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's dueAtUtc needs the org timezone only because its terms end on a calendar day.
    • workOrderDeadline(wo) -> { dueAtUtc, dueReason } | null. Null unless dueAtUtc is a finite number. It never derives a date from scheduledDate. A date with no recognised reason reads as override.
  • src/types/workOrder.ts:
    • WODueReason = 'default:emergency' | 'default:high' | 'default:medium' | 'default:low' | 'override'. override is reserved for dispatch's UI leg.
    • WorkOrderDeadline and the optional WorkOrderDeadlineFields. The naming follows the dueAtUtc precedent in src/money/types.ts.
  • src/intake/accept.ts: buildAcceptedWorkOrders stamps dueAtUtc and dueReason from the final priority (after the emergency and rule overrides) and isEmergency, counted from ctx.now.

What deliberately did NOT change

  • No WorkOrder interface was added. Shared has never had a full WorkOrder type; dispatch's types.ts owns it. WorkOrderDeadlineFields is there for dispatch's WorkOrder to extend in PR 2.
  • No backfill and no scheduledDate fallback. Legacy work orders stay undated.
  • Other create paths in shared: buildAcceptedWorkOrders is the only builder of a new work-order payload in src/. testFixtures.buildWorkOrder stays undated on purpose: it models an existing work order, and consumer e2e and visual specs build on it.
  • No package.json or .github/ change. ./intake is 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 with expected { … } to match object { dueAtUtc: … }.

Mutations. Each guard was broken with a one-line edit, its single test file run, then restored:

Guard Mutation Result
finite intake time if (false) throw killed (1 failed)
off-union priority reads as Medium known ? wo.priority : 'Medium' → wo.priority killed (1)
emergency row wins, hours row = priority killed (1)
emergency row wins, reason reason = PRIORITY_REASON[priority] killed (2)
Low row is 7 days 7 * 24 → 6 * 24 killed (2)
reader: dueAtUtc must be a number === undefined check only killed (1)
reader: dueAtUtc must be finite drop isFinite killed (1)
reader: unknown reason reads as override drop DUE_REASONS.has killed (1)
accept stamps the deadline delete the spread line killed (3)
accept uses the final (rule) priority priority: draft.priority killed (1)
accept passes the emergency flag isEmergency: false killed (1)

No new gate: nothing that used to pass is now withheld.

Consumer impact. Read at dispatch origin/main, restock origin/main, clean origin/trunk and turnwrk-cortex origin/main:

  • The only consumer callers of buildAcceptedWorkOrders are dispatch lib/intake/createIntakeItem.ts and lib/intake/triage.ts, and cortex src/services/vendorIngestCore.ts. All pass a numeric now.
  • No consumer test asserts the exact accept payload (no toEqual, toStrictEqual or snapshot on it). Cortex's vendorIngestIntake.test.ts compares { id, title } only.
  • No union was widened. WOPriority is unchanged, so no Record<…> 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.
  • The hooks do not run in a worktree, so commit-msg was run by hand: exit 0.
  • git ls-remote origin turnwrk-785-wo-deadline-default = 922334ba8d93998979be2c31ed58ee883f0577d7 = HEAD.

Refs: TURNWRK-785

🤖 Generated with Claude Code

…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 practical-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 · ⚠️ could not run here · ⚪ not re-run

@practical-bot practical-bot added the merge:queued Hand this PR to the factory merge queue label Dec 3, 2026
@practical-bot

Copy link
Copy Markdown

🤖 alan+factory's merge:on-approve on TURNWRK-785, checks green, queued for merge (merge:queued).

@practical-bot
practical-bot merged commit dff5561 into main Dec 3, 2026
3 checks passed
@practical-bot
practical-bot deleted the turnwrk-785-wo-deadline-default branch December 3, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge:queued Hand this PR to the factory merge queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants