Repository navigation
ci(protect-ffi): stop the test typecheck rewriting lib/ - #1909
Conversation
Root `pnpm test` runs `turbo test` over every package at once. protect-ffi's `test:typecheck` began with a plain `tsc`. That command rewrites every file in `lib/`. The builds of @cipherstash/stack and other packages read `lib/*.d.*` at the same time, and nothing in the turbo graph ordered the two. A file tsc is rewriting is briefly empty, so a build sometimes read an empty `lib/types.d.ts` and failed with TS2305. That failed Test JS in run 45801077255 on #1845. The typecheck now runs `tsc --noEmit`, so `test` never writes `lib/`. TypeScript 5.9 still reports declaration errors such as TS4094 under `--noEmit`, so the check loses nothing. The unit tests still need the emitted `lib/index.cjs`, so turbo.json gives protect-ffi's `test` its own task that depends on the package's `build`. A new scripts test checks both rules: no tsc reachable from protect-ffi's `test` emits files, and turbo runs that `test` after its own `build`. Refs #1845
|
cipherstash-agent
left a comment
There was a problem hiding this comment.
Review attestation
Reviewed 9038078 · posted from Claude Code (scheduled routine) · claude-opus-5-5 · effort medium
Sources: code-review (medium) · claude-opus-5-5; mattpocock-skills:code-review Standards and Spec agents · claude-opus-5-5; review-cross-check verifiers · claude-opus-5-5
Skills: code-review, mattpocock-skills:code-review, company-skills:rust-security (loaded; the diff contains no Rust, so it did not apply), company-skills:review-cross-check
Findings (8): 8 minor. 7 are inline comments and 1 is below. None blocks the race fix. Every finding was checked against 9038078 before posting.
languages/typescript/packages/protect-ffi/src/nativeLoading.test.ts:30(outside the diff, and it predates this PR) minor The header still quotesturbo test --filter './languages/typescript/packages/*'. The root script is now--filter './languages/typescript/packages/**' --filter './packages/**'. The same old quote is atnativeLoading.test.ts:203,src/lintWiring.test.ts:399and:427, and.github/workflows/tests.yml:132.
Refuted during verification: tsc --noEmit with declaration: true still reports declaration-only errors (TS4094 and TS4058 on TypeScript 5.9.3), so the typecheck catches as much as before. No changeset is needed, because no published file changes.
Generated by Claude Code
The package's test no longer writes lib/, so after a source edit a bare test run asserted on the previous build's JavaScript and passed. The guard now also fails when a compiled source under src/ is newer than lib/index.cjs, and tells the reader to run build.
No CI job runs protect-ffi's test or test:unit directly. CI reaches them only through root pnpm test, which runs turbo.
The unit tests no longer run tsc. They run vitest against the lib/ that build writes. The fresh-clone promise now names root pnpm test, because the package's own test needs build first.
Root pnpm test now runs turbo test with two filters, './languages/typescript/packages/**' and './packages/**'. Five comments still quoted the old single filter.
tsc accepts comments and trailing commas in a tsconfig. JSON.parse threw a SyntaxError on them, so the guard failed for the wrong reason. It now uses readJsonc, which the file already imports.
The guard looked for the exact word tsc, so ./node_modules/.bin/tsc, npx [email protected], sh -c 'tsc' and (tsc) were missed, and an emitting tsc spelled that way passed. A word now counts as tsc when its last path part, without quotes, parentheses or an @Version, is tsc.
The walk followed only 'pnpm run X' and 'npm run X'. pnpm also runs a script as 'pnpm X', and after flags such as -s or --silent, so an emitting tsc reached that way passed the guard. The walk now follows those calls, and only names that are scripts.
|
On the review-body finding about the old root test filter ( Fixed in 011934d. All five comments now quote |
Summary
This fixes a race that sometimes failed the Test JS job for a reason outside the code under test. The root
pnpm testcommand runsturbo test(turbo is the task runner this repository uses), and turbo runs many package tasks at once in one checkout.The test script of
@cipherstash/protect-ffi(the native encryption module) typechecked with a plaintsc, and plaintscrewrites every file in the package'slib/folder. At the same time, the builds of@cipherstash/stackand other packages read the type files in that folder. A file thattscis rewriting is empty for a moment, so a build sometimes saw no exports and failed with TS2305. Now the test typechecks without writing files, and turbo buildslib/before the test runs.Stack
This is pull request 4 of 4 in stack 1735. Below it are #1416 (merged), #1419 and #1845. Merging this pull request also merges #1419 and #1845 if they have not merged yet.
Changes
languages/typescript/packages/protect-ffi/package.json:test:typechecknow runstsc --noEmitinstead of plaintsc, so the test never writeslib/.turbo.json: a new@cipherstash/protect-ffi#testtask depends on the package's ownbuildas well as its dependencies' builds. The unit tests read the builtlib/index.cjs, and the test no longer builds it. The other settings copy the generictesttask.scripts/__tests__/protect-ffi-test-no-emit.test.mjs(new): checks that notscreachable from protect-ffi'stestscript writes files, and that turbo runs that test after its own build. It follows script calls with or withoutrunand after flags, findstscby path, version or quoting, and reads tsconfig files as JSONC. Its helpers have their own tests.languages/typescript/packages/protect-ffi/src/nativeLoading.test.ts: the header comment and the error message for a missinglib/no longer say that the test script buildslib/. The suite now also stops when a compiled source undersrc/is newer thanlib/index.cjs, and says to runbuild.src/nativeLoading.test.ts,src/lintWiring.test.tsand.github/workflows/tests.yml: five comments now quote the current root test filter.languages/typescript/packages/protect-ffi/README.md: says thatpnpm testin the package needspnpm run buildfirst, and that rootpnpm testdoes this on its own. The fresh-clone promise now names rootpnpm testonly.Verification
node_modules/.bin/vitest run --config scripts/vitest.config.mjs scripts/__tests__/protect-ffi-test-no-emit.test.mjs: 3 of 3 failed. It reportedtest:typecheck: tscas a command that writes files, and no@cipherstash/protect-ffi#testtask inturbo.json.node_modules/.bin/vitest run --config scripts/vitest.config.mjs: 86 files passed, 1442 tests passed, 3 skipped.lib/withtsc -p languages/typescript/packages/protect-ffi, then ran protect-ffi'svitest run: 9 files passed, 108 tests passed. After touchingsrc/index.cts, the suite stopped with the new stale-lib/message.tsc --noEmitandtsc -p tsconfig.test.jsonin protect-ffi: both exited 0. The modification times and sizes oflib/types.d.tsandlib/index.cjswere the same before and after.tsc --noEmitstill reports declaration errors whendeclaration: trueis set. On TypeScript 5.9.3, a test project withexport const C = class { private x = 1 }reported TS4094 undertsc --noEmit, the same as under plaintsc. So the typecheck catches the same errors as before, andbuildstill runs plaintsc.node_modules/.bin/turbo run test --filter './languages/typescript/packages/**' --filter './packages/**' --dry=json:@cipherstash/protect-ffi#testnow depends on@cipherstash/protect-ffi#build, plus the builds of the six platform packages.node_modules/.bin/biome checkon the changed files: no problems.pnpm test, because pnpm is not installed on the machine where this change was made. CI runs it.Related
Refs #1845: Test JS failed this way in run 45801077255, job "Run Tests (Node 22)".
Review notes
tsc10 times while readinglib/types.d.tsin a loop, 312 of 235,725 reads found the file empty. So green runs cannot show whether the race is present. The new test checks the two rules that close it.pnpm testinsidelanguages/typescript/packages/protect-ffiwithout a build first, or after editing a source, now fails at once, with a message that says to runbuild. Before this change, the test builtlib/itself. Every CI job that runs the package's scripts directly buildslib/first, through.github/actions/build-ffi-binding.Summary by CodeRabbit