Skip to content

Check the trace readers with tsc, not with a regex - #8

Merged
gabe4coding merged 1 commit into
claude/codebase-hardening-audit-b8e47ffrom
claude/trace-tsc-3659a5
Oct 13, 2026
Merged

gabe4coding merged 1 commit into
claude/codebase-hardening-audit-b8e47ffrom
claude/trace-tsc-3659a5

Conversation

@gabe4coding

Copy link
Copy Markdown
Owner

Summary

This PR goes on top of #7. It replaces the regex check of the trace readers in tests/contract.check.mjs with tsc.

The regex check had these problems:

  • It found a trace read only when the variable had the name t. Another name passed with no check.
  • It merged the fields of all members of TraceLine. A field of a different event (t.removed on a listing line) passed.

Now tsc checks each read against the TraceLine union in types/index.d.ts.

Changes

  • // @ts-check in tests/session.mjs, tests/smoke.e2e.mjs and evals/impact.mjs. session.mjs gives the trace the type TraceLine[].
  • New tsconfig.scripts.json for the .mjs scripts, with the Node types. tsconfig.json stays without them. The engine runs the hooks without Node, so tsc must reject process or setTimeout in a hook.
  • New package.json with @types/node 24.13.6. Run npm install one time before the type check.
  • The eval options and the session settings use the Options type, so a misspelled option fails.
  • Removed traceContract and traceReadProblems from contract.check.mjs.
  • CODING_STANDARDS.md and docs/development.mdx describe the second type check command.

Problems that tsc found

  • smoke.e2e.mjs: two reads of t.type and t.isScoped did not check the event first.
  • evals/impact.mjs: the report could crash on sample.plugins when a session failed with an error. The list of failures also printed (undefined) as the folder of such a session.

Test plan

  • npx -p typescript@7.0.2 tsc -p tsconfig.json
  • npx -p typescript@7.0.2 tsc -p tsconfig.scripts.json
  • A test file with a wrong event name, a wrong field, a field of a different event and a misspelled option: tsc rejects all four.
  • claude plugin validate .
  • claude plugin test . (57 pass)
  • node tests/docs.check.mjs
  • node tests/contract.check.mjs
  • node tests/smoke.e2e.mjs (8 of 8 pass)
  • /verify drive with 3 prompts: correct cuts, note and server calls

No change to hooks/, types/ or .claude-plugin/plugin.json, so the version stays the same.

🤖 Generated with Claude Code

The regex check in tests/contract.check.mjs found a trace read only when
the variable had the name `t`. It also accepted a field of a different
event (`t.removed` on a listing line). tsc now checks each read against
the TraceLine union in types/index.d.ts.

- Add `// @ts-check` to tests/session.mjs, tests/smoke.e2e.mjs and
  evals/impact.mjs. session.mjs gives the trace the type TraceLine[].
- Add tsconfig.scripts.json for the .mjs scripts, with the Node types.
  tsconfig.json stays without them: the engine runs the hooks without
  Node, so tsc must reject `process` or `setTimeout` in a hook.
- Add package.json with @types/node 24.13.6. Run `npm install` one time
  before the type check.
- Type the eval options and the session settings with Options, so a
  misspelled option fails.
- Fix two reads in smoke.e2e.mjs that did not check the event first.
- Fix the eval report for a session that failed with an error: it could
  crash on `sample.plugins`, and it printed "(undefined)" as the folder.
- Remove traceContract and traceReadProblems from contract.check.mjs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gabe4coding
gabe4coding merged commit ecaf300 into claude/codebase-hardening-audit-b8e47f Oct 13, 2026
5 checks passed
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.

2 participants