Skip to content

A Playable factory for tests, so the next required field costs one edit - #40

Merged
ninjudd merged 2 commits into
mainfrom
fix/test-playable-factory
Aug 7, 2026
Merged

ninjudd merged 2 commits into
mainfrom
fix/test-playable-factory

Conversation

@ninjudd

@ninjudd ninjudd commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Hand-built Playable literals in tests have broken three times running,
each time in a way the usual signals missed:

playable({ path }) fills every required field. The two call sites in
click.test.ts use it.

The property, verified rather than assumed

I added a temporary required field to Playable and checked who breaks:

before updating the factory:   src/commands/play.ts, src/testing/playable.ts
after updating only the factory: src/commands/play.ts

play.ts is real code and has to change anyway. No test file does.

Two small decisions

path has no default. A Playable's job is to name a file, and
defaulting it would turn a missing fixture into an ENOENT somewhere far
away instead of a compile error at the call site.

The helper lives in src/testing/ and is excluded from
tsconfig.build.json, so it does not ship in dist. *.test.ts was
the only exclusion before; a helper that is not itself a test needed its
own.

pnpm typecheck exit 0, 301/301. Built in a git worktree off main, so
the shared checkout — whose dist the global bloom symlinks into —
was never switched or rebuilt.


Note

Low Risk
Test-only helper and test refactors; no production runtime behavior changes.

Overview
Adds playable() in src/testing/playable.ts so tests can build a full Playable with defaults for label, pkg, sha256, and committed, while path stays required at the call site.

click.test.ts now uses playable({ path: src }) (and overrides sha256 in the re-hash test) instead of hand-written literals.

tsconfig.build.json excludes src/testing/** so the helper is not emitted to dist alongside test files.

Reviewed by Cursor Bugbot for commit f3a353e. Configure here.

Hand-built Playable literals in tests have broken three times running,
each time in a way the usual signals missed: `sha256` in #35 (vitest
does not typecheck, and the build excludes tests, so both were green),
`committed` in #39, and again merging #38 into #39 — a type error
neither branch's CI could see, because a conflicting pull request has no
merge ref to build.

`playable({ path })` fills every required field; the two call sites in
click.test.ts now use it. Verified the property rather than assuming it:
adding a temporary required field to Playable breaks play.ts and the
factory and nothing else, where before it would have broken every test
that builds one.

`path` deliberately has no default — a Playable's job is to name a file,
and defaulting it would turn a missing fixture into an ENOENT somewhere
far away instead of a compile error at the call site.

The helper lives in src/testing/ and is excluded from tsconfig.build,
so it does not ship in dist.
Comment thread src/testing/playable.ts Resolved
Comment thread src/testing/playable.ts Resolved
Comment thread tsconfig.build.json Resolved
@ninjudd

ninjudd commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Review — head f3a353e7, verified by running it

Reviewed in a throwaway clone at the exact head, never in the working checkout. Nothing blocking. Three inline notes, all P3 or informational; the change does what its title says and I could not break the claim.

Green, positively confirmed

  • npx tsc --noEmit -p tsconfig.json — exit 0. (This matters here more than usual: pnpm build uses tsconfig.build.json, which excludes tests, and vitest does not typecheck, so this is the only thing that typechecks click.test.ts at all.)
  • npx vitest run — Test Files 25 passed | 1 skipped (26), Tests 278 passed | 23 skipped (301). Matches the 301/301 in the PR body.
  • Check runs at f3a353e77aac989afb5572d1897c0af0c8df4c82 exactly: test → success, Cursor Bugbot → success. mergeable: MERGEABLE, mergeStateStatus: CLEAN, and git rev-list --count f3a353e7..origin/main = 0 — the branch sits directly on current main, so the "conflicting PR has no merge ref, CI never runs" trap that bit Watch cleanup: honest build statuses, one source path, teardown evidence #38/bloom export: build a label, put a versioned file where a human works #39 does not apply here.

The thesis, tested rather than taken on trust

I added a required probeField: string to Playable and ran tsc --noEmit on each side:

base 5c4ddde:   src/commands/click.test.ts(69,44)  TS2345
                src/commands/click.test.ts(87,44)  TS2345
                src/commands/play.ts(56,3)         TS2322

head f3a353e:   src/commands/play.ts(56,3)         TS2322
                src/testing/playable.ts(16,3)      TS2322

Exactly the claim in the PR body. play.ts is real code that has to change anyway; no test file breaks. And the signal stays loud where it should — the return-type annotation still catches the new field, so the factory cannot quietly ship an incomplete Playable.

I also confirmed this is the whole surface: grep -rn Playable src --include=*.ts shows click.test.ts was the only file with hand-built literals. Every other test (play-daemon.test.ts, choose.test.ts, build.test.ts) gets its Playables from resolvePlayables, so they ride along on the play.ts edit for free.

The type safety question — it does not weaken

The obvious hazard with a defaults factory is a parameter typed loosely enough to absorb anything. Partial<Playable> & Pick<Playable, 'path'> does not:

playable({})                          -> TS2345  path is missing
playable({ path, bogus: 1 })          -> TS2353  excess property rejected
playable({ path, label: undefined })  -> TS2379  exactOptionalPropertyTypes honoured

path having no default is the right call and the stated reasoning holds up.

Assertions preserved

Both converted call sites produce byte-identical inputs to the originals: default label //songs/x/mix:main and derived pkg songs/x/mix match the old literals exactly, and the re-hash test still passes the source's own sha256FileSync(src). The added comment explaining why that override stays is well judged — I checked, and the test passes either way, so the override is buying assertion strength rather than a pass. That distinction is easy to lose in a refactor like this and it wasn't.

Inline notes

  • P3 — the derived pkg has no coverage; replacing it with pkg: '' keeps all 5 click tests green. Suggested a three-line test for the helper.
  • Informational — the Partial<> shape means a future required field is absorbed once someone picks its default here. Verified concretely; it is the intended tradeoff, just worth being deliberate about.
  • P3 — the tsconfig.build.json exclusion genuinely keeps dist/testing/ out (A/B'd both ways), but exclude does not prevent emission if shipped code ever imports the helper (verified). Recording it so the line isn't later read as a stronger guarantee than it is.

Nothing here needs a fix before merge. Reviewed locally per AGENTS.md; not resolving threads and not merging.

**The derived `pkg` had no coverage** — the one line in this file that
computes rather than defaults, and the one that fails silently:
`withClick` uses it only to choose a directory, so a wrong derivation
surfaces much later as a missing tempo map. The reviewer's A/B
(`pkg: ''`) left the click tests green; it now fails a test that asserts
the derivation, an override of it, and the path passing through
untouched.

**The defaulting trade is now stated rather than discovered.** A future
required field gets whatever default is written here, so a test can
assert on a value nobody chose. That is the same question the compile
errors asked at every call site — the difference is that it is answered
once, in the open, by whoever adds the field. The comment says to give a
new field a default only where every caller would be indifferent, and
otherwise leave it required like `path`.

**And `exclude` is documented as what it is.** It filters the root file
set, not emission: src/testing/ stays out of dist/ only while nothing in
src/ imports it. Verified the exclusion still works (`dist/testing`
absent after a build) and wrote down the condition it depends on.
@ninjudd

ninjudd commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Re-verified at a39192a1 — all three hold

Verification pass only, same throwaway clone, working checkout untouched.

Green: npx tsc --noEmit -p tsconfig.json exit 0. npx vitest run → 26 files passed / 1 skipped, 281 passed, 23 skipped (304) — up from 301, the three new tests. CI test at exactly a39192a14e65b6ddb42f7fe58ceb991f791fc584: success, 04:41:10 → 04:43:18 UTC, a real two-minute run.

1. pkg coverage — holds. My original A/B is now caught, and so is every other way I could bend that line:

pkg: ''                          -> × derives pkg from the label
'//' prefix no longer stripped   -> × derives pkg from the label
split(':')[0] -> split(':')[1]   -> × derives pkg from the label
spread moved ahead of the        -> × lets a caller override the derivation
  defaults (overrides stop
  winning)
path forced after the spread     -> × keeps the path it was given
                                    × withClick > overlays clicks on beats
                                    × withClick > re-hashes

Each of the three new tests fails under a mutation aimed at it, so none of them is decorative. The override test in particular pins something worth pinning — that deriving is the convenience and not the contract.

One note on my own method: my first attempt at the override mutation was a no-op (I inserted a second spread while leaving the trailing one in place) and it passed. That was my bug, not missing coverage; redone properly, the test fails as it should.

2. The trade — recorded, and recorded correctly. The added comment states it as a choice rather than leaving it to be found, and the operative sentence is the right rule: default a new field only where every caller would be indifferent, otherwise leave it out like path and let the compiler ask. That is exactly the line between the two failure modes. Closed by explanation, and the explanation is sound.

3. The exclude nuance — documented, and the documentation is accurate. I re-ran both halves against the new head rather than trusting the previous run:

as committed                          -> dist/testing present? NO   (0 .test.js in dist)
+ one import of playable from
  src/commands/click.ts               -> dist/testing present? YES
                                         playable.d.ts  playable.js  playable.js.map

So "stays out of dist/ only for as long as nothing in src/ imports it" is literally true. I also checked the thing the fix itself could have broken: the // comments are fine, tsc -p tsconfig.build.json exits 0, and package.json's build script is the only consumer of that file — nothing parses it as strict JSON.

Resolution honesty: all three resolved threads carry a corresponding change on the branch, each reply naming a39192a. No thread was resolved without one.

Outstanding: nothing. Not resolving threads, not merging — still yours.

@ninjudd
ninjudd merged commit 50f4ecd into main Aug 7, 2026
1 check passed
@ninjudd
ninjudd deleted the fix/test-playable-factory branch September 28, 2026 04:11
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