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

A test proves a spawn body id beginning with `-` is refused before it reaches tar #15046

Merged opened this

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

Merged

A new test, test/spawn-archive-dash-id.test.ts, shows that a spawn body id starting with - is refused at the archive's boundary (BODYID in src/spawn/archive.ts:61) and that no tar process starts. No src change. The test: It makes a hosted forge through POST /forges/start.

Notes

shipped production is serving it deploy 15342fb

opened this

A new test, test/spawn-archive-dash-id.test.ts, shows that a spawn body id starting with - is refused at the archive's boundary (BODY_ID in src/spawn/archive.ts:61) and that no tar process starts. No src change.

The test:

  • It makes a hosted forge through POST /forges/start.
  • It renames the forge's data directory and ledger body id to --checkpoint-action=exec=touch pwned.
  • It archives the forge in a child bun process (test/helpers/archive-child.ts). A spy tar comes first on that process's PATH: it writes down each call and runs nothing.
  • It expects:
    • the answer dash-body has no data directory to archive
    • no tar calls
    • the ledger and data directory still in place
    • nothing written to the backup destination.

Why a child process: Bun looks tar up on the PATH the process started with. Changing process.env.PATH inside the test never reaches Bun.spawn; I tried that first. A first test checks the spy is actually reached, so "no tar calls" can't pass just because the spy was never on the path.

Checked against the guard: with the BODY_ID check in archiveOne turned off, the test fails. The archive got past the refusal and tar ran: the answer became "the copy could not be written". With the guard back, both tests pass in about 3 s.

Gate list: scripts/gate.ts no longer keeps one by hand; every test/*.test.ts is gated unless excluded. So there is nothing to add, and the file is well under the per-file budget.

Left out: test/forge-archive.test.ts already has a test from #15004 that checks what the refusal leaves on disk for --remove-files. It doesn't show that tar never starts, so I left it as it is.

Checks run:

  • bun scripts/gate.ts --fix: it rewrapped one comment in the new test, which is committed.
  • bun x tsc --noEmit: clean.
  • The 118 files scripts/fast.ts named: 1706 pass, 2 skip, 0 fail.

Try it: bun test test/spawn-archive-dash-id.test.ts

🤖 Generated with Claude Code

Closes #15029

Closes #15029

commented

A new test, test/spawn-archive-dash-id.test.ts, shows that a spawn body id starting with - is refused at the archive's boundary (BODY_ID in src/spawn/archive.ts:61) and that no tar process starts. No src change.

The test:

  • It makes a hosted forge through POST /forges/start.
  • It renames the forge's data directory and ledger body id to --checkpoint-action=exec=touch pwned.
  • It archives the forge in a child bun process (test/helpers/archive-child.ts). A spy tar comes first on that process's PATH: it writes down each call and runs nothing.
  • It expects:
    • the answer dash-body has no data directory to archive
    • no tar calls
    • the ledger and data directory still in place
    • nothing written to the backup destination.

Why a child process: Bun looks tar up on the PATH the process started with. Changing process.env.PATH inside the test never reaches Bun.spawn; I tried that first. A first test checks the spy is actually reached, so "no tar calls" can't pass just because the spy was never on the path.

Checked against the guard: with the BODY_ID check in archiveOne turned off, the test fails. The archive got past the refusal and tar ran: the answer became "the copy could not be written". With the guard back, both tests pass in about 3 s.

Gate list: scripts/gate.ts no longer keeps one by hand; every test/*.test.ts is gated unless excluded. So there is nothing to add, and the file is well under the per-file budget.

Left out: test/forge-archive.test.ts already has a test from #15004 that checks what the refusal leaves on disk for --remove-files. It doesn't show that tar never starts, so I left it as it is.

Checks run:

  • bun scripts/gate.ts --fix: it rewrapped one comment in the new test, which is committed.
  • bun x tsc --noEmit: clean.
  • The 118 files scripts/fast.ts named: 1706 pass, 2 skip, 0 fail.

Try it: bun test test/spawn-archive-dash-id.test.ts

🤖 Generated with Claude Code

Closes #15029

Approved

Test-only change; the guard at src/spawn/archive.ts:110 (BODY_ID) is what it exercises. The spy tar on the child process PATH plus the sanity test that the spy is reached make the no-tar-call assertion meaningful. I could not run the test here (the file is not in my checkout), so I rely on the green check and the builder report that removing the guard fails it. Next: 1) add a unit-level assertion for the ledger loader at archive.ts:75 dropping a dash id; 2) consider a shared helper for spy-on-PATH child tests if more appear.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs