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

A test names every synchronous file or process call on a request path, and the list only shrinks #17895

opened this

Merged 21h 11m ago, live in production

A new test, test/request-path-sync.test.ts, fails when a synchronous file or process call is added to a request path. It reads src/http, src/web/pages and src/apps/proxy.ts as text and counts the calls in each file to spawnSync, execSync, readFileSync, readdirSync, statSync, writeFileSync and appendFileSync.

Notes

opened this

A new test, test/request-path-sync.test.ts, fails when a synchronous file or process call is added to a request path. It reads src/http, src/web/pages and src/apps/proxy.ts as text and counts the calls in each file to spawnSync, execSync, readFileSync, readdirSync, statSync, writeFileSync and appendFileSync. Imports and comments are not counted. The counts are checked against ALLOWED, a list in the test with a count and a reason for each file and call:

  • More calls than the list allows: the test fails and says the fix — cache it, slice it, or move it off the thread. Adding a row is only for a call that truly never runs per request.
  • Fewer calls than the list says: the test fails until the row's count is lowered, so the list only shrinks.
  • A row with no reason, or a file that no longer exists: the test fails.

Every existing call is named in the list. None were changed, because this is a test-only change.

  • src/http/plugin_routes.ts:
    • readdirSync runs only once, when the routes are registered at boot.
    • readFileSync reads once and then keeps the result for the life of the process.
  • src/web/pages/security.ts: one statSync and one readFileSync of security-report.json, on a page only admins can open. The file is refused above 64 KiB.
  • src/http/access_log.ts: readdirSync ×2, statSync ×4, writeFileSync ×1 and appendFileSync ×1. Writes are batched: a flush runs about once a second on a timer, old files are cleaned up at most once a day, and the half-file rewrite only happens when a day's file hits its size cap. One reason is weaker than the others: when 200 lines are waiting, the flush runs inside the request that adds the 200th. That is listed honestly and not fixed here; it is the obvious next thing to move off the thread.

What to look at: whether the reasons are fair. The access log's 200th-line flush is the one most worth a second look.

Checks:

  • The new test passes on the current tree.
  • When I briefly added a readFileSync call to src/apps/proxy.ts, the test failed and the message named the fix. I removed the call before committing.
  • bun x tsc --noEmit and bun scripts/gate.ts are clean.
  • I did not run the full suite; the forge runs it on the push.

scripts/gate.ts did not need a change, because it already picks up every test/*.test.ts. I reused the read-as-text scan approach from src/core/review_scan.ts and wrote no new src/ function.

Try it: bun test test/request-path-sync.test.ts. Then add a readFileSync(…) call to any handler in src/http and run it again.

🤖 Generated with Claude Code

Closes #17885

commented

A new test, test/request-path-sync.test.ts, fails when a synchronous file or process call is added to a request path. It reads src/http, src/web/pages and src/apps/proxy.ts as text and counts the calls in each file to spawnSync, execSync, readFileSync, readdirSync, statSync, writeFileSync and appendFileSync. Imports and comments are not counted. The counts are checked against ALLOWED, a list in the test with a count and a reason for each file and call:

  • More calls than the list allows: the test fails and says the fix — cache it, slice it, or move it off the thread. Adding a row is only for a call that truly never runs per request.
  • Fewer calls than the list says: the test fails until the row's count is lowered, so the list only shrinks.
  • A row with no reason, or a file that no longer exists: the test fails.

Every existing call is named in the list. None were changed, because this is a test-only change.

  • src/http/plugin_routes.ts:
    • readdirSync runs only once, when the routes are registered at boot.
    • readFileSync reads once and then keeps the result for the life of the process.
  • src/web/pages/security.ts: one statSync and one readFileSync of security-report.json, on a page only admins can open. The file is refused above 64 KiB.
  • src/http/access_log.ts: readdirSync ×2, statSync ×4, writeFileSync ×1 and appendFileSync ×1. Writes are batched: a flush runs about once a second on a timer, old files are cleaned up at most once a day, and the half-file rewrite only happens when a day's file hits its size cap. One reason is weaker than the others: when 200 lines are waiting, the flush runs inside the request that adds the 200th. That is listed honestly and not fixed here; it is the obvious next thing to move off the thread.

What to look at: whether the reasons are fair. The access log's 200th-line flush is the one most worth a second look.

Checks:

  • The new test passes on the current tree.
  • When I briefly added a readFileSync call to src/apps/proxy.ts, the test failed and the message named the fix. I removed the call before committing.
  • bun x tsc --noEmit and bun scripts/gate.ts are clean.
  • I did not run the full suite; the forge runs it on the push.

scripts/gate.ts did not need a change, because it already picks up every test/*.test.ts. I reused the read-as-text scan approach from src/core/review_scan.ts and wrote no new src/ function.

Try it: bun test test/request-path-sync.test.ts. Then add a readFileSync(…) call to any handler in src/http and run it again.

🤖 Generated with Claude Code

commented

Left #17885 open: 1 unticked item remain (A test scans src/http, src/web/pages and src/apps/proxy.ts for spawnSync, execSync, readFileSync, readdirSync, statSync, writeFileSync, appendFileSync and lists each with file and count.).

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs