fix: forward -- args through devbox scripts, fail serve loudly (#84)

devbox 0.17.2 runs .devbox/gen/scripts/<name>.sh with the args as positional
parameters but does not append "$@", so tools/serve.sh (and seed, bench,
mutation, import-scale, fogbench) saw an empty argv and a documented
`serve -- --image=...` silently served the default 4096 scene. End every
argument-taking script body with "$@".

serve: --dry-run parses and prints the options without building; unknown
options, non-numeric ports/tile sizes and --tile-size without --image fail
loudly; a no-image start prints the current map read from state.db; NixOS
gets security.pki.certificateFiles instead of the Debian trust steps.

Guard the faults import in worldmap/vision/markers with
`when defined(leakfault)` (it is only used inside those blocks), removing
the three UnusedImport warnings; leakfault builds still compile.

tools/devboxargs.test.mjs goes through `devbox run <script> -- <args>` for
serve (dry-run, unknown flag, tile-size without image) and seed (--help,
unknown flag), the seam the direct-tool tests missed.
This commit is contained in:
2026-11-21 21:35:39 +01:00
parent c8b5289a3d
commit 30b35592c7
9 changed files with 190 additions and 15 deletions
+61
View File
@@ -0,0 +1,61 @@
// #84: the devbox seam. Every other harness calls tools/*.mjs directly, which hides the fact that
// `devbox run <script> -- <args>` never delivered the args: devbox 0.17.2 runs the generated
// .devbox/gen/scripts/<name>.sh with the args as positional parameters but does not append "$@",
// so the script body has to. These tests go through `devbox run` on purpose: a direct
// `node tools/serve.mjs --dry-run` would pass even with the broken devbox.json.
import test from 'node:test'
import assert from 'node:assert/strict'
import path from 'node:path'
import { spawnSync } from 'node:child_process'
import { projectRoot } from './lib.mjs'
const devbox = spawnSync('devbox', ['version'], { encoding: 'utf8' })
function devboxRun(script, args) {
const r = spawnSync('devbox', ['run', script, '--', ...args], {
cwd: projectRoot,
encoding: 'utf8',
timeout: 120000,
env: process.env,
})
return { status: r.status, signal: r.signal, stdout: r.stdout ?? '', stderr: r.stderr ?? '' }
}
// `devbox run test` itself runs inside the devbox shell; nested `devbox run` still works there.
// Skip only if the binary is genuinely absent (a bare `node --test` outside devbox).
const skip = devbox.status !== 0
test('devbox run serve -- --dry-run: the args reach serve.mjs', { timeout: 150000, skip }, () => {
const r = devboxRun('serve', ['--dry-run', '--host=127.0.0.1', '--port=9555',
'--tile-size=64', '--image=maps/demo.png'])
assert.equal(r.status, 0, r.stderr)
assert.match(r.stdout, /serve: dry-run/)
assert.match(r.stdout, /host:\s+127\.0\.0\.1/)
assert.match(r.stdout, /port:\s+9555/)
assert.match(r.stdout, /tile-size:\s+64/)
assert.match(r.stdout, /image:\s+.*maps\/demo\.png/)
})
test('devbox run serve -- --dry-run --bogus: an unknown flag fails loudly, no build', { timeout: 60000, skip }, () => {
const r = devboxRun('serve', ['--dry-run', '--bogus'])
assert.notEqual(r.status, 0, 'an ignored flag must not exit 0')
assert.match(r.stderr, /unknown option --bogus/)
})
test('devbox run serve -- --dry-run --tile-size=64: --tile-size without --image fails', { timeout: 60000, skip }, () => {
const r = devboxRun('serve', ['--dry-run', '--tile-size=64'])
assert.notEqual(r.status, 0)
assert.match(r.stderr, /--tile-size requires --image/)
})
test('devbox run seed -- --help: the args reach seed.mjs (usage from the real devbox path)', { timeout: 120000, skip }, () => {
const r = devboxRun('seed', ['--help'])
assert.equal(r.status, 0, r.stderr)
assert.match(r.stdout, /usage: devbox run seed -- --url=<origin>/)
})
test('devbox run seed -- --bogus: an unknown flag fails instead of seeding', { timeout: 120000, skip }, () => {
const r = devboxRun('seed', ['--bogus'])
assert.notEqual(r.status, 0)
assert.match(r.stderr, /unknown option --bogus/)
})