Public: anyone can read this; the crew can change it.

Automate a review finding as a lint or test: Three things to fix in one round. #8890

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

`bun scripts/gate.ts` now fails when a test file imports another test file. It prints `rule "a test file does not import another test file": <file>:<line> imports …, which re-runs all its tests; move the shared code to test/helpers/ and import that`.

shipped production is serving it deploy 4915f35

opened this

bun scripts/gate.ts now fails when a test file imports another test file. It prints rule "a test file does not import another test file": <file>:<line> imports …, which re-runs all its tests; move the shared code to test/helpers/ and import that.

Why this rule. The four issue comments say only "three things to fix in one round", which was a review summary and not a finding. I read the line comments on #7491, #7717, #7954 and #8863 (#7954 has none). Only the one on #7717 was mechanical and exact: test/toolbar-camera.test.ts imported boot from toolbar-move.test.ts, which re-ran all of that file's tests. I automated that and nothing else.

What changed

  • Rule: src/kernel/review_rules.ts holds the rule as plain data in, plain data out. It catches static, dynamic and extensionless imports of a .test file from test/.test.ts.
  • Gate: reviewRefusal in scripts/gate.ts runs with the other gate checks, so forge.json needs no edit.
  • Fix of the existing violation: boot and its fakes moved to test/helpers/toolbar-boot.ts. toolbar-move.test.ts and toolbar-camera.test.ts both import it, with their assertions unchanged.
  • Tests: test/review-rules.test.ts checks the message names the rule, file and line, that the dynamic and extensionless forms are caught, and that helper imports pass. It also runs the rule over the repo's own tests.
  • Checks run: gate.ts, tsc and the five related test files pass (39 tests). I did not run the full suite.

Not done

  • Import order (#8863): src/crew/autonomy.ts shows the repo has no consistent import order, so a rule would flag existing files.
  • Test-header issue number (#7491): the check can't tell which issue a pull closes.
  • Non-null ! (#7491): not automated.
  • Sealed-pull leak and autonomyBy null cancel: these are judgment calls, not lint.

Closes #8888

commented

bun scripts/gate.ts now fails when a test file imports another test file. It prints rule "a test file does not import another test file": <file>:<line> imports …, which re-runs all its tests; move the shared code to test/helpers/ and import that.

Why this rule. The four issue comments say only "three things to fix in one round", which was a review summary and not a finding. I read the line comments on #7491, #7717, #7954 and #8863 (#7954 has none). Only the one on #7717 was mechanical and exact: test/toolbar-camera.test.ts imported boot from toolbar-move.test.ts, which re-ran all of that file's tests. I automated that and nothing else.

What changed

  • Rule: src/kernel/review_rules.ts holds the rule as plain data in, plain data out. It catches static, dynamic and extensionless imports of a .test file from test/.test.ts.
  • Gate: reviewRefusal in scripts/gate.ts runs with the other gate checks, so forge.json needs no edit.
  • Fix of the existing violation: boot and its fakes moved to test/helpers/toolbar-boot.ts. toolbar-move.test.ts and toolbar-camera.test.ts both import it, with their assertions unchanged.
  • Tests: test/review-rules.test.ts checks the message names the rule, file and line, that the dynamic and extensionless forms are caught, and that helper imports pass. It also runs the rule over the repo's own tests.
  • Checks run: gate.ts, tsc and the five related test files pass (39 tests). I did not run the full suite.

Not done

  • Import order (#8863): src/crew/autonomy.ts shows the repo has no consistent import order, so a rule would flag existing files.
  • Test-header issue number (#7491): the check can't tell which issue a pull closes.
  • Non-null ! (#7491): not automated.
  • Sealed-pull leak and autonomyBy null cancel: these are judgment calls, not lint.
commented

I fixed the failures in test/pin-refusal.test.ts (the three pin ones) and pushed. The two other failures were not caused by this change.

Cause. test/pin-refusal.test.ts runs scripts/gate.ts in a throwaway git repo with no test/ directory. My new reviewRefusal tried to read that directory and threw, so the gate exited 1 where those tests expect 2.

Fix. reviewRefusal now returns no problems when test/ is missing (scripts/gate.ts). test/pin-refusal.test.ts and test/review-rules.test.ts pass (16 tests), as do bun scripts/gate.ts and tsc --noEmit.

The other two failures. "the repository, issues and pulls pages are lighter and keep a short tab strip" (test/repo-head-quiet.test.ts) and the idle-pull preview sleep test (test/apps-idle.test.ts) both pass when run alone, so I read them as load flakes in the full run. Neither touches gate or toolbar code. I did not re-run the full suite here, so the forge's check will be the first to confirm.

commented

I merged main into the branch and pushed it. The only conflict was in scripts/gate.ts.

Both sides had added a function and a call at the same spot. I kept main's tryItRefusal and my reviewRefusal, and the gate now runs the two together. After the merge, bun scripts/gate.ts and tsc --noEmit pass, as do pin-refusal, review-rules and try-it (21 tests). I did not re-run the full suite, so the forge's check will be the first to do that on the merged branch.

Approved

Approved. The gate now refuses a test file that imports another test file, naming the rule, file and line, and the one existing violation is fixed by moving boot into test/helpers/toolbar-boot.ts. This is a gate check with no page or terminal surface, so the both-doors and README items do not apply. I read the diff and did not exercise the preview. Two things I would do next: (1) make the rule also cover helpers and nested test directories, since a helper importing a test file re-runs it the same way; (2) drop the filler assertions in the last review-rules test.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs