Repository navigation
Conversation
Nothing type-checked the test tree: tsconfig.test.json sets isolatedModules, the main config includes only src, and CI never ran the compiler over tests. A test could assert a shape the compiler rejects and still pass. Gate new and changed test files first while the existing 261 errors are worked down. The gate feeds tsc a config containing only the files the PR touches, then reports diagnostics against those files; pre-existing errors in unchanged files are counted but do not fail the build. Part of OWASP#1364
|
CI probe, as promised:
So the gate catches exactly the failure mode the issue describes, and a changed test cannot ship untyped. |
Read paths from git diff -z so spaces, Unicode and newlines survive. Drive tsc through the compiler API and match diagnostics on resolved absolute paths, so only diagnostics attached to unchanged files are ignored. Configuration and compiler failures now fail the gate. Add regression coverage for the failure paths, including a changed file that imports an unchanged file with its own errors.
|
Review points addressed:
CI is green, and the gate type-checked the new test file on this PR ( |
Remove the unused result bookkeeping and exports now that the tests drive the CLI, correct the comment to say Jest only transpiles tests, and keep configuration failures on the fatal path. Add regression coverage for an unparseable test config and make the messages refer to errors in unchanged files rather than pre-existing debt.
|
Cleanup applied: shorter header with the corrected Jest/type-checking explanation, unused |
sonukapoor
left a comment
There was a problem hiding this comment.
Approving this. The gap it closes is real and the shape of the fix is right.
Jest transpiles the test files without type-checking them, so a type error in a test never surfaces: the suite goes green and nothing tells you. On current main there are 264 such errors across 51 test files. That is not a backlog this pull request has to clear, and it correctly does not try.
What makes it workable is that it only looks at the test files a pull request actually changes, so those 264 stay where they are and only new ones block. I planted a type error in a test file and the gate exits 1 while the suite on that same file passes, which is exactly the behaviour that could not happen before.
Two things I liked that you were not asked for. The workflow passes the base commit through the environment and quotes it rather than interpolating it into the shell, which is the same pattern we had to retrofit onto the release workflow last week. And there are no casts, no any and no suppression comments anywhere in it, which would have been the easy way to make a type-check gate go green.
Merge result is clean against current main at 178 suites and 2,470 tests. Replacing the failing exit with a successful one fails 4 of your 6 tests, so the coverage discriminates.
One number for the record: your body says 261 pre-existing errors and I measure 264 today. That is main moving under you rather than a miscount, and it is an argument for the gate rather than against it.
What changed and why
Jest transpiles tests without type-checking them, so a test can assert a shape the compiler would reject and stay green.
tsconfig.test.jsonalso setsisolatedModules, but the missing gate is the point: no workflow ran the compiler over the test tree.Decision: gate new and changed files first, rather than fixing the whole backlog in this PR. The full test tree currently reports 261 errors, concentrated in a handful of files (
scanner-cache83,parent-upgrade33,scanner-npm-advisory31). Fixing them all here would turn the gate review into a large, risky refactor; gating changed files stops new debt immediately.How it works
scripts/typecheck-changed-tests.mjs <base-ref>lists thetests/**/*.tsfiles the branch added or modified withgit diff -z, so spaces, Unicode and newlines survive.buildjob runs it onpull_requestevents. The base commit is fetched shallowly by SHA, so it works for fork PRs too.CONTRIBUTING.mddocuments the local command.Verification
tests/scripts/typecheck-changed-tests.test.tsruns the real script against throwaway git repositories and covers: a normal type error, a Unicode filename, a filename with spaces plus errors in an imported unchanged file, a valid changed file with unchanged-file debt, no changed tests, and an unparseable TypeScript config.actionlintclean;npm run buildandnpm run lint:testspass.buildfail atType-check changed testswithTS2322(https://github.com/OWASP/cve-lite-cli/actions/runs/39554341092), while the suite itself still passed. The probe was reverted.Type-checked 1 changed test file(s): no errors.Part of #1364 - the gate is in place; the remaining pre-existing errors are backlog work.