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

src/kernel imports nothing outside src/kernel, held by a rule test with today's exceptions named #13650

Merged opened this

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

Merged

This adds one new rule test, test/kernel-boundary.test.ts, that holds the kernel's first package boundary: a file in src/kernel/ may import only other kernel files and the runtime (node:, bun:). Each import that leaves the kernel today is listed in CROSSINGS as file -> specifier, with one line saying why.

Notes

shipped production is serving it deploy 59903fa

opened this

This adds one new rule test, test/kernel-boundary.test.ts, that holds the kernel's first package boundary: a file in src/kernel/ may import only other kernel files and the runtime (node:, bun:). Each import that leaves the kernel today is listed in CROSSINGS as file -> specifier, with one line saying why. 28 exceptions remain: 23 in vitals.ts, which reads every subsystem's state, and one each in full_disk.ts, guard.ts, outbound.ts, preflight.ts and worker_ask.ts. Removing them is later work.

How it works:

  • Reading imports: Bun's own import scanner finds the static, dynamic and re-exported imports. A regex anchored at the start of a line adds the type-only imports, which Bun's scanner leaves out. Imports quoted inside comments and strings are not counted.
  • New crossings fail: an import that leaves the kernel and is not in CROSSINGS gets its own failing test, named src/kernel/<file> -> <specifier>: not in CROSSINGS, so the check's summary names the file and the import. This covers a new kernel file as well as a new line in an old one. I checked it by adding a probe file to src/kernel that imported ../http/health.ts: the test went red, then I deleted the probe.
  • The list only shrinks: an entry in CROSSINGS that the code no longer makes also fails, so removed crossings have to come off the list.
  • Fixture test: a temporary kernel directory holds type-only, multi-line, re-exported, bare (side-effect), dynamic and bare-package imports, a sibling kernel import, and one inside a comment. The test checks that exactly the outside ones are reported.
  • Speed: it only reads files and starts nothing; it runs in about 0.6 s. Its header says @tree-scan, so every pull's fast tier runs it without a change to RULE_TESTS.

Only the test file changed; there is no change at runtime. bun scripts/gate.ts --fix, bun x tsc --noEmit, and the test files kernel-boundary, tree-scans and rule-tests-always all pass.

To try it: bun test test/kernel-boundary.test.ts. Then add import { health } from "../http/health.ts" to any file in src/kernel/ and run it again to see it fail.

🤖 Generated with Claude Code

Closes #13646

commented

This adds one new rule test, test/kernel-boundary.test.ts, that holds the kernel's first package boundary: a file in src/kernel/ may import only other kernel files and the runtime (node:, bun:). Each import that leaves the kernel today is listed in CROSSINGS as file -> specifier, with one line saying why. 28 exceptions remain: 23 in vitals.ts, which reads every subsystem's state, and one each in full_disk.ts, guard.ts, outbound.ts, preflight.ts and worker_ask.ts. Removing them is later work.

How it works:

  • Reading imports: Bun's own import scanner finds the static, dynamic and re-exported imports. A regex anchored at the start of a line adds the type-only imports, which Bun's scanner leaves out. Imports quoted inside comments and strings are not counted.
  • New crossings fail: an import that leaves the kernel and is not in CROSSINGS gets its own failing test, named src/kernel/<file> -> <specifier>: not in CROSSINGS, so the check's summary names the file and the import. This covers a new kernel file as well as a new line in an old one. I checked it by adding a probe file to src/kernel that imported ../http/health.ts: the test went red, then I deleted the probe.
  • The list only shrinks: an entry in CROSSINGS that the code no longer makes also fails, so removed crossings have to come off the list.
  • Fixture test: a temporary kernel directory holds type-only, multi-line, re-exported, bare (side-effect), dynamic and bare-package imports, a sibling kernel import, and one inside a comment. The test checks that exactly the outside ones are reported.
  • Speed: it only reads files and starts nothing; it runs in about 0.6 s. Its header says @tree-scan, so every pull's fast tier runs it without a change to RULE_TESTS.

Only the test file changed; there is no change at runtime. bun scripts/gate.ts --fix, bun x tsc --noEmit, and the test files kernel-boundary, tree-scans and rule-tests-always all pass.

To try it: bun test test/kernel-boundary.test.ts. Then add import { health } from "../http/health.ts" to any file in src/kernel/ and run it again to see it fail.

🤖 Generated with Claude Code

Approved

Test-only change, no runtime or UI effect. It reads the kernel files, flags any import that leaves src/kernel and is not named in CROSSINGS, and fails on a stale entry. A fixture test covers multi-line, type-only, re-export, bare, dynamic and comment cases. The count in the pull (28) matches the 28 outside imports I counted in src/kernel. I could not run the test here: this checkout does not contain the file. Two next steps: (1) retire the 23 vitals.ts crossings by having subsystems hand the kernel their readings as plain data; (2) have the fixture assert the file -> specifier pairs, not only the specifiers.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs