8000 test(scheduler): cover the Nudges route, which had none by simon-inkie · Pull Request #3 · simon-inkie/inkie-deck · GitHub
[go: up one dir, main page]

Skip to content

test(scheduler): cover the Nudges route, which had none - #3

Merged
simon-inkie merged 3 commits into
mainfrom
test/scheduler-coverage
Aug 18, 2026
Merged

simon-inkie merged 3 commits into
mainfrom
test/scheduler-coverage

Conversation

@simon-inkie
Copy link
Copy Markdown
Owner

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.ts and cron-validate.ts have been covered since the extraction commit, thoroughly: 1802 lines across cron.server.test.ts, cron-validate.test.ts and api-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 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. That is the layer holding the crontab.

What is now covered

File Tests Covers
test/scheduler-route.test.ts 59 (new) loader 404 + action refusal per intent (asserting the seam is never reached, not just that an error came back); required fields; schedule validation incl. newline/CR injection on both create and edit; enabled and targetType coercion; schedule normalisation; result passthrough; a create/toggle/delete round trip carrying one id through loader and action
test/scheduler-nav.test.tsx 12 (new) the Nudges nav link's presence and absence on both surfaces it renders on, default-closed, and independence from the sibling Activity gate
test/instance.test.ts +7 cronAdminEnabled had no direct test despite deciding both of the above
test/cron-validate.test.ts +39 validateField's range/list/step branches had only ever run against minute bounds; adds the other four fields, token shapes, and humanizeSchedule fallbacks

117 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 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. 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 in cron.server.ts so 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.mjs asserts 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.mjs passes (77 checks).

Red-then-green

Each group was run against a deliberately broken source before being trusted:

Mutant Caught by
month max 12 -> 13 1 test
reversed-range check dropped 1 test
step magnitude cap dropped 2 tests
enabled === "true" reverted to !== "false" 4 tests
action gate removed 9 tests
loader 404 gate removed 3 tests
nav gate ignored 5 tests
nav gate leaked on the mobile surface only 5 tests

All source restored afterwards; git diff origin/main touches no file under app/.

Verification

  • node scripts/leak-gate.mjs clean (368 files, 30 rules)
  • node scripts/licence-gate.mjs clean
  • pnpm typecheck Done
  • pnpm check:dashes clean (ASCII only, FND-05)
  • pnpm check:boundaries no violations (486 modules)
  • pnpm test (workspace) green: deck 1936 passed / 11 skipped / 90 files, base 38 passed / 4 files
  • node rig/self-test.mjs 77 checks passed

One thing that is not mine, but you should know

check:leaks:history reports 1 finding and check:leaks:messages reports 2, on this branch and identically on origin/main. They are pre-existing: the history one is the internal product name in a CLAUDE.md blob 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

… 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
@simon-inkie
Copy link
Copy Markdown
Owner Author

CI is red, and none of it is this PR

Both failing jobs fail identically without this branch. Evidence, since "the tests are red" is not a thing to take on trust:

test (22.x) / test (24.x) - missing ripgrep on the runner

Error: check-dashes tests require ripgrep (rg) on PATH; spawning rg failed: spawnSync rg ENOENT
  ❯ runGuardOnFile test/dashes.test.ts:35:11
Test Files  1 failed | 89 passed (90)
     Tests  4 failed | 1932 passed | 11 skipped (1947)

ubuntu-latest has no rg, and test/dashes.test.ts hard-requires it. This job has failed on every run in the repo's history, including pushes straight to main (run 32047451193, test (22.x): failure, test (24.x): failure).

The workflow comment says this job "runs exactly the command list in the root README's Development section, so CI can never report greener than a developer's local run". It currently reports redder, permanently, for a reason the README already documents as an environment diagnostic rather than a defect.

Worth noting what that number is: 1932 passing with ripgrep missing is exactly the degraded figure this PR writes into the README. I derived it as a delta and could not reproduce the condition locally; CI just measured it independently. The full figure (1936) and the boundary, typecheck, leak and licence gates are all green locally.

Fix, when you want it, is one line in .github/workflows/ci.yml:

- name: Install ripgrep
  run: sudo apt-get update && sudo apt-get install -y ripgrep

guards - gitleaks cannot read the PR, 403

RequestError [HttpError]: Resource not accessible by integration
  at async Object.ScanPullRequest (.../gitleaks-action/v2/dist/index.js:129568:17)
  status: 403
  url: 'https://api.github.com/repos/simon-inkie/inkie-deck/pulls/3/commits'

gitleaks-action lists a PR's commits before scanning them. The workflow declares no permissions: block, so the default GITHUB_TOKEN on a pull_request event cannot read them. This is why guards passes on push-to-main and fails on every PR - PR #1 (run 32046376759) and PR #2 (run 32065717729) both failed here too, before this branch existed.

The repo's own gates ran and passed inside that same job before gitleaks blew up:

leak-gate self-test: all 30 rules fire correctly
leak-gate: clean (368 files scanned, 30 rules)

Fix is a permissions block on the job:

guards:
  runs-on: ubuntu-latest
  permissions:
    contents: read
    pull-requests: read

Not fixing either here

CLAUDE.md says keep PRs scoped to one change, and CI infrastructure is not test coverage. Both are one-liners and I am happy to open a separate PR for them on your word - that one is arguably the higher priority of the two, since as it stands the branch-and-PR workflow you just adopted cannot produce a green check on any PR.

@simon-inkie simon-inkie left a comment
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.

@simon-inkie
simon-inkie merged commit 6bb5c0d into main Aug 18, 2026
4 checks passed
@simon-inkie
simon-inkie deleted the test/scheduler-coverage branch August 18, 2026 15:27
simon-inkie added a commit that referenced this pull request Aug 18, 2026
… 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0