--- name: dankvoice-bundle-swap-red-proof description: Prove a dankvoice behavior test is red against the pre-change bundle by pointing DV_EXT at a built old bundle; includes the source-swap fallback when the extracted bundle cannot resolve node_modules outside the repo. --- # Red-proofing a dankvoice behavior test against the pre-change bundle The suite drives the **built** bundle (`dist/index.js`, rebuilt by `setup()` from `src/`), so "is this new assertion actually red-capable?" is a question about a bundle that no longer exists after the fix. Two routes; try A first, fall back to B. ## Route A — `DV_EXT` at the old committed bundle ```bash git show HEAD:dist/index.js > "$W/old-dist.js" DV_EXT="$W/old-dist.js" DV_STUB=... bun "$DV_DRIVER" # expect RED DV_EXT="$PWD/dist/index.js" bun "$DV_DRIVER" # expect GREEN ``` Build the driver harness by extracting the heredoc `setup()` writes into `tests/behavior.bats`: ```bash sed -n ',p' tests/behavior.bats > "$W/driver.ts" ``` Re-check that range after every edit that adds lines to the driver (`console.log` census blocks included) — a stale end line silently appends the `TS` terminator and the driver dies after printing, which looks like a passing probe. Copy the project's real player stub, `wpctl` fixture, `models.yml` and `ompconfig.yml` verbatim; a simplified stub prints a false `PLAYS 0`. **Trap (why A fails in a worktree):** module externals resolve from the *bundle's* directory. A bundle extracted to `/tmp` cannot resolve `@oh-my-pi/pi-natives` and dies with a version-pinned `Cannot find module .../pi-natives@/.../loader-state.js` — nothing to do with the fix under test. Putting the old bundle inside the repo (next to `node_modules`) fixes resolution, but in a linked-worktree where `node_modules` is a symlink to another checkout whose installed version differs from the version baked into `HEAD:dist`, it still fails. Then use route B. ## Route B — swap the source, rebuild, restore (private worktree only) `setup()` rebuilds `dist` from `src/`, so reverting one source file reproduces the pre-fix bundle exactly: ```bash cp src/.ts /tmp/new-.ts git show HEAD:src/.ts > src/.ts bun run build >/dev/null bats tests/behavior.bats --filter '' # expect every new test NOT ok cp /tmp/new-.ts src/.ts && bun run build >/dev/null && echo RESTORED ``` Always restore in the same command line that ran the red check, so an interrupted session cannot leave pre-fix source behind. `bats --filter` takes a regex over the `@test` titles; use it instead of the whole suite (the full run is ~5 min). Read the failure lines, not just the count: a red test that fails because the driver crashed (`PLAYS 0`, no `CALL` lines) proves nothing about the fix. ## Gate afterwards `bun run build` and commit `dist/` in the same commit as `src/` — `tests/packaging.bats` byte-compares the **committed** dist (`git diff --name-only -- dist` must be empty), so an uncommitted rebuild shows up as a red packaging test, not as a missing fix.