Repository navigation
test(scheduler): cover the Nudges route, which had none - #3
Conversation
… the route
The audit that prompted this reported the feature as untested. That was
half right, and the half it got wrong is the interesting half.
cron.server.ts and cron-validate.ts are covered, thoroughly, and have
been since the extraction commit: 1802 lines across cron.server.test.ts,
cron-validate.test.ts and api-cron.test.ts. What had nothing at all was
scheduler.tsx, and it is not a thin wrapper over the tested seam. It
carries a SECOND action beside api.cron.tsx's, with its own gate, its own
field extraction and its own coercions, reading formData by hand where
api.cron.tsx parses with a zod schema. Two implementations of one
contract, one of them watched. They can drift, and the drift is silent.
So the gap was never the service layer. It was every layer above it, and
that layer is the one holding the crontab.
test/scheduler-route.test.ts (new, 59)
The loader's 404 and the action's refusal on an instance the gate
closes, per intent, asserting the seam is never reached rather than
only that an error came back. Then the coercions, which is what
mocking the seam buys that the existing gate suite could not: an
omitted checkbox reads false (the route comments on getting this
wrong once; nothing had pinned the fix), an unrecognised targetType
falls back to agent rather than writing a raw script, and the
schedule handed to the seam is the NORMALISED one. Plus a create,
toggle, delete round trip carrying one id through loader and action
together, which is the circuit the page actually is.
Every cron.server call is mocked, and that is a safety property, not
a convenience. This route calls createCron with its default deps,
and the default writeCrontab runs `crontab -` against the real user
crontab. There is no env seam here the way projects has
PROJECTS_ROOT, so one real call through would rewrite the crontab of
whoever ran the suite. It is also why this feature gets no e2e flow:
a browser test of the create button has no safe target to point at.
test/scheduler-nav.test.tsx (new, 12)
The link is rendered twice off one flag, a top-bar NavLink and an
agent-strip Link, and a gate that closes one and leaves the other
open is the shape this mistake takes. Both asserted, absence
included, in the style sidebar-activity.test.tsx uses for the sibling
Activity feature. Also pins that the prop defaults to closed, and
that the two nav gates stay independent of each other.
test/instance.test.ts (+7)
cronAdminEnabled had no direct test, though it decides both of the
above. The property worth naming is that the kill switch is one-way:
it can shut a trusted principal out, and MC_CRON_ADMIN_ENABLED=1
cannot let anyone else in.
test/cron-validate.test.ts (+39)
validateField is one shared function, and its range, list and step
branches had only ever run against minute bounds. Bounds for the
other four fields, token shapes across all of them (reversed ranges,
a list with one bad member, step divisors and bases, a trailing
command appended to a valid expression), and humanizeSchedule's
fallbacks including dow=7, which the validator accepts as Sunday and
the day-name table has no entry for.
Each of the four was run against a deliberately broken source first:
month max widened to 13, the reversed-range check dropped, the step
magnitude cap dropped, the checkbox fix reverted, each gate removed in
turn, and the nav gate leaked on one surface only. Every mutant was
caught by the tests naming it. No source file is modified by this commit.
deck's suite moves 1819 -> 1936 and 88 -> 90 files, so the rig's
instrument and the README's diagnostic move with it. None of the 117
shells out or reads the repository, so the README's two degraded figures
move by the same 117 as the full one.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FhBTSuNwHtEx3yKBbEtzeX
CI is red, and none of it is this PRBoth failing jobs fail identically without this branch. Evidence, since "the tests are red" is not a thing to take on trust:
|
There was a problem hiding this comment.
Independent review outcome: clean. The suite exercises the real scheduler loader and action with only the destructive crontab seam mocked, and covers gate ordering, coercion, normalisation, navigation absence, and validator branches. The seam isolation is appropriate because the default dependency writes the real user crontab. I would approve this change, but GitHub prevents the currently authenticated PR-author account from self-approving.
# Conflicts: # README.md # rig/expected.mjs
… the route (#3) The audit that prompted this reported the feature as untested. That was half right, and the half it got wrong is the interesting half. cron.server.ts and cron-validate.ts are covered, thoroughly, and have been since the extraction commit: 1802 lines across cron.server.test.ts, cron-validate.test.ts and api-cron.test.ts. What had nothing at all was scheduler.tsx, and it is not a thin wrapper over the tested seam. It carries a SECOND action beside api.cron.tsx's, with its own gate, its own field extraction and its own coercions, reading formData by hand where api.cron.tsx parses with a zod schema. Two implementations of one contract, one of them watched. They can drift, and the drift is silent. So the gap was never the service layer. It was every layer above it, and that layer is the one holding the crontab. test/scheduler-route.test.ts (new, 59) The loader's 404 and the action's refusal on an instance the gate closes, per intent, asserting the seam is never reached rather than only that an error came back. Then the coercions, which is what mocking the seam buys that the existing gate suite could not: an omitted checkbox reads false (the route comments on getting this wrong once; nothing had pinned the fix), an unrecognised targetType falls back to agent rather than writing a raw script, and the schedule handed to the seam is the NORMALISED one. Plus a create, toggle, delete round trip carrying one id through loader and action together, which is the circuit the page actually is. Every cron.server call is mocked, and that is a safety property, not a convenience. This route calls createCron with its default deps, and the default writeCrontab runs `crontab -` against the real user crontab. There is no env seam here the way projects has PROJECTS_ROOT, so one real call through would rewrite the crontab of whoever ran the suite. It is also why this feature gets no e2e flow: a browser test of the create button has no safe target to point at. test/scheduler-nav.test.tsx (new, 12) The link is rendered twice off one flag, a top-bar NavLink and an agent-strip Link, and a gate that closes one and leaves the other open is the shape this mistake takes. Both asserted, absence included, in the style sidebar-activity.test.tsx uses for the sibling Activity feature. Also pins that the prop defaults to closed, and that the two nav gates stay independent of each other. test/instance.test.ts (+7) cronAdminEnabled had no direct test, though it decides both of the above. The property worth naming is that the kill switch is one-way: it can shut a trusted principal out, and MC_CRON_ADMIN_ENABLED=1 cannot let anyone else in. test/cron-validate.test.ts (+39) validateField is one shared function, and its range, list and step branches had only ever run against minute bounds. Bounds for the other four fields, token shapes across all of them (reversed ranges, a list with one bad member, step divisors and bases, a trailing command appended to a valid expression), and humanizeSchedule's fallbacks including dow=7, which the validator accepts as Sunday and the day-name table has no entry for. Each of the four was run against a deliberately broken source first: month max widened to 13, the reversed-range check dropped, the step magnitude cap dropped, the checkbox fix reverted, each gate removed in turn, and the nav gate leaked on one surface only. Every mutant was caught by the tests naming it. No source file is modified by this commit. deck's suite moves 1819 -> 1936 and 88 -> 90 files, so the rig's instrument and the README's diagnostic move with it. None of the 117 shells out or reads the repository, so the README's two degraded figures move by the same 117 as the full one. Co-authored-by: Simon <simon@inkie.ink> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
What this is
Test coverage for the Nudges feature (
/scheduler). No source file is modified.The finding that shaped it
The brief was "Nudges has zero tests". That turned out to be half right, and the wrong half is the useful one.
cron.server.tsandcron-validate.tshave been covered since the extraction commit, thoroughly: 1802 lines acrosscron.server.test.ts,cron-validate.test.tsandapi-cron.test.ts. Writing a second service-layer suite would have duplicated work already done.What genuinely had nothing was
app/routes/scheduler.tsx, and it is not a thin wrapper over the tested seam. It carries a second action besideapi.cron.tsx's, with its own gate, its own field extraction and its own coercions, readingformDataby hand whereapi.cron.tsxparses with a zod schema. Two implementations of one contract, one of them watched. That is the layer holding the crontab.What is now covered
test/scheduler-route.test.tsenabledandtargetTypecoercion; schedule normalisation; result passthrough; a create/toggle/delete round trip carrying one id through loader and actiontest/scheduler-nav.test.tsxtest/instance.test.tscronAdminEnabledhad no direct test despite deciding both of the abovetest/cron-validate.test.tsvalidateField's range/list/step branches had only ever run against minute bounds; adds the other four fields, token shapes, andhumanizeSchedulefallbacks117 tests added. Deck's suite: 1819 -> 1936, 88 -> 90 files.
Two judgement calls worth your eye
1. The seam is mocked, and that is a safety property. This route calls
createCronwith its default deps, and the defaultwriteCrontabrunscrontab -against the real user crontab. There is no env seam here the way projects hasPROJECTS_ROOT. One real call through and the suite rewrites the crontab of whoever ran it.That is also why this feature gets no e2e flow: a browser test of the create button has no safe target to point at. If you would rather have one, the prerequisite is a
CRON_*env seam incron.server.tsso e2e can point at a scratch crontab. Happy to do that as a follow-up if you want it, but it is a source change and this PR deliberately is not.2. The test-count instrument.
rig/expected.mjsasserts the exact figure and the README publishes it as a diagnostic, so both moved. None of the 117 shells out or reads the repository, so the README's two degraded figures move by the same 117 as the full one.node rig/self-test.mjspasses (77 checks).Red-then-green
Each group was run against a deliberately broken source before being trusted:
max12 -> 13enabled === "true"reverted to!== "false"All source restored afterwards;
git diff origin/maintouches no file underapp/.Verification
node scripts/leak-gate.mjsclean (368 files, 30 rules)node scripts/licence-gate.mjscleanpnpm typecheckDonepnpm check:dashesclean (ASCII only, FND-05)pnpm check:boundariesno violations (486 modules)pnpm test(workspace) green: deck 1936 passed / 11 skipped / 90 files, base 38 passed / 4 filesnode rig/self-test.mjs77 checks passedOne thing that is not mine, but you should know
check:leaks:historyreports 1 finding andcheck:leaks:messagesreports 2, on this branch and identically onorigin/main. They are pre-existing: the history one is the internal product name in aCLAUDE.mdblob that a later commit fixed but which is still reachable, and the messages ones include a company email address in a commit body. This PR adds none of them and does not attempt to fix them (rewriting history is your call, not something to slip into a test PR).🤖 Generated with Claude Code
https://claude.ai/code/session_01FhBTSuNwHtEx3yKBbEtzeX