Skip to content

chore(ci): cut the BATS suite runtime - #1690

Merged
c-vigo merged 10 commits into
devfrom
feature/1687-bats-runtime
Sep 25, 2026
Merged

c-vigo merged 10 commits into
devfrom
feature/1687-bats-runtime

Conversation

@c-vigo

@c-vigo c-vigo commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

The BATS suite is ~54% of Project Checks, the only job on CI's critical path (6m14s of 11m28s, measured on run 36050981328), and 80% of that is init-workspace.bats making ~274 full init-workspace.sh renders. This PR pulls the three levers measured in #1687, in order of payoff:

  • WP1 — run BATS under bats --jobs. bats -j shells out to GNU parallel, which was nowhere on PATH, so the just test-bats "parallel" branch was dead and CI ran the suite serially. parallel now rides with the bats wrapper in nix/bats.nix (bats is its only consumer; it lands on no consumer's PATH; incremental closure over the delivered toolchain is 0.77 MiB — perl and friends were already there). Both entry points, the recipe and the test-project composite action, run bats -j "$(nproc)". Jobs are spread within files, the right axis when one file is 80% of the time.
  • WP2 — batch the two per-file fork loops in init-workspace.sh. The chmod u+w scaffold sweep (production path) and the host-side placeholder-substitution fallback each forked once per file across a ~163-file tree, 65% of a scaffold's ~4.3k forks. Both are now one xargs batch. Rendered trees are byte- and permission-identical (diff -r + find -printf '%m %y %p') for all four modes, all four old/new upgrade orderings, smoke mode, and nested/.git//symlink/binary edge cases. Per scaffold: 680 ms → 267 ms (hyperfine, 20 runs).
  • WP3 — stop re-rendering trees an earlier test already built. _clone_shared <fixture> <ws> copies a setup_file-rendered tree (cp -a, ~36 ms) instead of re-running the script; three seeded fixtures (node-both, python-both, trunk-both) join the four per-mode ones. Only pure-setup calls were converted (no $output/failure assertion on the render, empty target, stock env and flags); every _upgrade, --prune-devcontainer, --smoke-test, preview and consumer-seeded site keeps its real invocation. 343 → 250 script invocations per file run; 300 tests, identical @test list.

One real finding along the way: the suite was not fully parallel-safe. Four tests in worktree.bats drive real tmux sessions and just worktree-clean against the repo's live <repo>-worktrees directory, and raced under -j 8. That file now opts out of within-file parallelism via BATS_NO_PARALLELIZE_WITHIN_FILE (10 tests, no cost). Those tests skip under CI=true, so CI never saw it.

Type of Change

  • feat -- New feature
  • fix -- Bug fix
  • docs -- Documentation only
  • chore -- Maintenance task (deps, config, etc.)
  • refactor -- Code restructuring (no behavior change)
  • test -- Adding or updating tests
  • ci -- CI/CD pipeline changes
  • build -- Build system or dependency changes
  • revert -- Reverts a previous commit
  • style -- Code style (formatting, whitespace)

Modifiers

  • Breaking change (!) -- This change breaks backward compatibility

Changes Made

  • nix/bats.nix — symlinkJoin over bats.withLibraries, re-wrapping bin/bats with --prefix PATH to GNU parallel. name and meta are inherited so devShellToolNames (meta.mainProgram) and test_flake_devshell.py::test_devshell_provides_bats stay stable. share/bats (BATS_LIB_PATH) is unchanged.
  • .github/actions/test-project/action.yml — bats -j "$(nproc)" tests/bats/.
  • justfile — test-bats drops the dead per-file GNU-parallel branch for bats -j "$(nproc)".
  • tests/bats/just.bats — two RED-first pins: the recipe and the action use bats -j, and the command -v parallel branch is gone.
  • tests/bats/worktree.bats — setup_file exports BATS_NO_PARALLELIZE_WITHIN_FILE=true (see above).
  • assets/init-workspace.sh — sweep_scaffold_writable collects targets and issues one xargs -0 -r chmod u+w --; the manifest-less fallback is one grep -rl --null --exclude-dir=.git … | xargs -0 -r sed -i … --. The image-only manifest fast path is untouched. Accepted semantic differences: grep -r follows a symlinked $WORKSPACE_DIR itself (old find walked nothing there — strictly more correct); traversal order differs (edits are per-file independent); a failing chmod now aborts after the batch rather than at the first file.
  • tests/bats/init-workspace.bats — _render_shared in setup_file, _clone_shared helper, three new fixtures, 94 call sites converted (61 both, 9 direnv, 2 devcontainer, 2 bare, 1 three-mode loop, 9 node-both, 4 python-both, 5 trunk-both). Converted sites keep the run …; assert_success shape, so a broken clone still fails the test; the fixture render's own exit status is checked once per file in setup_file.
  • CHANGELOG.md (+ scaffold mirror via sync-manifest) — Changed entry.

Changelog Entry

Changed

  • BATS suite runs under bats --jobs, and a scaffold forks 65% less
    (#1687)
    • bats tests/bats/ was 6m14s of the 11m28s Project Checks job — the only
      job on CI's critical path — and ran serially. init-workspace.bats alone
      was 80% of it, so the per-file GNU-parallel branch in just test-bats
      (dead anyway: parallel was never on PATH) was the wrong axis
    • GNU parallel now rides with the bats wrapper in nix/bats.nix — bats is
      its only consumer, it lands on nobody's PATH, and the incremental closure
      is under 1 MiB — and both entry points, just test-bats and the
      test-project composite action, run bats -j "$(nproc)". worktree.bats
      opts out of within-file jobs: its tests drive real tmux sessions and the
      repo's sibling worktrees directory
    • init-workspace.sh batches its two per-file fork loops — the chmod u+w
      scaffold sweep, which is on the production path, and the host-side
      placeholder-substitution fallback — into one xargs each. Rendered trees
      are byte- and permission-identical; a scaffold drops from ~680 ms to
      ~270 ms
    • init-workspace.bats clones setup_file-rendered fixtures
      (_clone_shared) instead of re-rendering a stock scaffold per test: 343 →
      250 script invocations per run, 300 tests unchanged

Testing

  • Tests pass locally (just test)
  • Manual testing performed (describe below)

Manual Testing Details

Local, 8 cores, through the flake's new wrapper (nix develop --command bats -j 8 tests/bats/):

Check Result
Full suite, -j 8 602/602 ok (600 + 2 new pins)
Full suite, -j 4 (CI core count) 602/602 ok, 221 s
init-workspace.bats sequential, before → after WP3 277 s → 204 s, 300/300
init-workspace.bats -j 8, before → after WP3 174 s → 85 s, 300/300
init-workspace.sh invocations per file run 343 → 250
Scaffold --mode both, old → new script 680 ms → 267 ms
Byte-identity (4 modes, 4 upgrade orderings, smoke, edge cases) all diff -r + mode/type clean
tests/test_flake_devshell.py 15 passed, 1 skipped
packages.devkitImageEnv builds; bin/bats is the wrapper, share/bats intact, bats -j green from it, parallel not on PATH
prek run --all-files green

CI Project Checks before/after (cross-cutting criterion):

BATS step Project Checks job whole run
before (run 36050981328) 6m14s 11m28s 11m35s
after (run 36108278820, this PR) 3m11s (602/602, 4 jobs) 9m59s 10m46s

The BATS step halved (1.96x on 4 vCPU; the issue predicted 2.5-3x from 8-core measurements, and the runner's per-core throughput is lower than the local box). The job-level saving is smaller than the step-level one because the six nix/flake steps took 4m00s on this run against 2m40s on the baseline: the Tier 0 nix-fast-build gate had to build the changed dev shell (new bats derivation) instead of pulling it from Cachix. That is a one-off per derivation change and unrelated to the suite.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly (edit docs/templates/, then run just docs)
  • I have updated CHANGELOG.md in the [Unreleased] section (and pasted the entry above)
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

Not built locally: the full devkitImage tarball (its toolchain env was built and checked instead; the Image Tests job covers the rest).

Follow-ups, filed:

Refs: #1687

sweep_scaffold_writable collected one chmod fork per template file (23%
of a scaffold's ~4.3k forks) and the placeholder-substitution fallback
one grep fork per workspace file (42%). Collect the sweep's targets and
chmod them through a single xargs, and replace the fallback's per-file
grep/sed loop with one `grep -rl --null` piped into one xargs sed.

File selection and permissions are unchanged: rendered trees are
byte-identical old vs new for all four modes and across upgrade runs,
`.git/` stays excluded, in-tree symlinks stay unfollowed, and binary
files still match. A fresh `--mode both` scaffold drops from 680ms to
267ms locally.

Refs: #1687
…ures

setup_file already rendered one read-only tree per delivery mode, but a test
that mutates its workspace could not reuse one, so 111 of the ~274
init-workspace.sh invocations in this file re-render a tree an earlier test
already built. Copying a rendered tree costs ~36ms against ~1770ms for a
render, and the render is path-independent, so a cp -a of a fixture is
byte- and permission-identical to a fresh scaffold into an empty directory.

Factor the per-mode render into a _render_shared helper, add the node-both,
python-both and trunk-both fixtures for the three largest seeded/flagged
groups, and expose _clone_shared <fixture> <ws> as a pure-setup replacement
for a stock scaffold call.

Refs: #1687
76 tests scaffolded a stock tree into an empty workspace purely to have
something to mutate, then asserted on what a later invocation did to it. Each
such call is byte-for-byte what setup_file already rendered, so replace it with
a _clone_shared copy: 61 both-mode, 9 direnv, 2 devcontainer, 2 bare, and the
three-mode inference loop.

Only the pure-setup call is converted. Every test that asserts on a scaffold
run own output, seeds files the shared render did not, or passes extra flags
keeps its real invocation, as does the second invocation in the tests that
scaffold and then upgrade.

Refs: #1687
…caffolding

Three more groups share a setup the shared per-mode trees could not cover: a
package.json or pyproject.toml language marker seeded before a both-mode
scaffold, and --workflow trunk on an otherwise stock both-mode tree. Each is
now a setup_file fixture, so the 18 tests clone it instead of rendering it.

The marker file moves from the test body into the fixture, where it is seeded
before the identical render; the fixture name records which marker is in play.

Refs: #1687
@c-vigo c-vigo self-assigned this Sep 25, 2026
@c-vigo
c-vigo merged commit 77e1895 into dev Sep 25, 2026
14 checks passed
@c-vigo
c-vigo deleted the feature/1687-bats-runtime branch September 25, 2026 07:47
c-vigo added a commit that referenced this pull request Sep 25, 2026
## Description

`Project Checks` was the only job on CI's critical path and a serial
chain of
independent work: 9m59s on run

[36108278820](https://github.com/vig-os/devkit/actions/runs/36108278820)
while
every other job finished by 8m37s. Nothing after `setup-env` consumed
another
block's output — prek, BATS, pytest and the nix gates each read the
checkout and
the warm dev-shell and nothing else — so the job cost the **sum** of its
blocks
rather than the longest one.

This splits it into four parallel lanes (`Project Lint`, `Project
Tests`,
`Project BATS`, `Project Flake Gates`), each running `setup-env` once
and one
block, with the `test-project` composite as the single source of truth
for every
block body. The critical path becomes setup + the longest block.

## Type of Change

- [ ] `feat` -- New feature
- [ ] `fix` -- Bug fix
- [ ] `docs` -- Documentation only
- [ ] `chore` -- Maintenance task (deps, config, etc.)
- [ ] `refactor` -- Code restructuring (no behavior change)
- [ ] `test` -- Adding or updating tests
- [x] `ci` -- CI/CD pipeline changes
- [ ] `build` -- Build system or dependency changes
- [ ] `revert` -- Reverts a previous commit
- [ ] `style` -- Code style (formatting, whitespace)

### Modifiers

- [ ] Breaking change (`!`) -- This change breaks backward compatibility

## Changes Made

**1. The composite owns every block
(`.github/actions/test-project/action.yml`).**
The seven flake gates (Tier 0 `nix-fast-build`, flake output schema,
dev-shell
contracts, hooks fidelity + services, capability modules, downstream
stub, zizmor
audit) lived inline in `ci.yml` — in the composite's only caller. They
moved into
the composite verbatim (each body gaining the `shell: bash` a composite
step
requires) under a new `flake` suite value, and the BATS and pytest
blocks gained
their own values. `suite` is now a single enum: `all | lint | bats |
pytest |
flake`, with `all` unchanged. Coverage summary + upload are guarded to
`pytest`
(nothing else produces `coverage.xml`) and the prek cache to `lint`.

`setup-env`'s `sync-dependencies` is derived from the suite
(`inputs.suite == 'bats' && 'false' || 'true'`) rather than exposed as a
caller
input: the environment a block needs is a property of the block. The
bats block
needs the flake toolchain but never the project venv — verified:
`init.bats` only
probes `command -v uv`, the `uv sync` strings in `init-workspace.bats`
are heredoc
payloads, and `just.bats`/`init-workspace.bats` stub the binary.

An unrecognized `suite` is refused by a first, toolchain-free step
(`::error::unknown test-project suite '<value>'`). Every block is
guarded on an
exact match, so a typo in a lane (`flakes`, `tests`) would run
**nothing** and
report the lane green — the one silent-pass mode a per-lane split
introduces that
the serial chain could not have. The static half of the same gap is
pinned in
`tests/test_workflow_summary_gate.py`: each lane passes the block it is
named
for, no two lanes pass the same block, and every block the composite
guards (bar
`all`) is some lane's suite, so a block cannot be implemented with no
job running
it.

I did **not** add the optional `bats-files` input that would let a later
matrix
split the BATS lane without touching the composite: it costs a
word-splitting
`$BATS_FILES` and a `shellcheck disable` for a split the issue itself
says to
measure first. YAGNI — it is a two-line change when that measurement
happens.

**2. Four lanes (`.github/workflows/ci.yml`).** `project-lint` (15 min),
`project-tests` (15), `project-bats` (15), `project-flake` (25 — it
keeps the old
chain's budget for a cold-Cachix dev-shell rebuild). The short lanes are
sized for
`setup-env`, not for their block: a `flake.lock` change that misses
Cachix builds
the dev-shell in every lane rather than once, so 15 minutes buys that
headroom
four times over. Each lane carries the
*unchanged* `workflow_dispatch` gate
(`inputs.test-suite == 'all' || … == 'project'`), so a dispatch of
`project` still
runs all four, and each keeps its own checkout (a local `uses: ./…` is
resolved
from the workspace before the composite's own checkout runs).

**3. `summary` fans in over all four.** `needs:`, the four echo lines
and four
failure/cancelled legs. `skipped` stays tolerated. This is load-bearing:
with
`if: always()` a lane left out of `needs:` is not merely unchecked, it
is
*invisible* to the only required status check.

**4. Docs.** `docs/WORKFLOW_SECURITY.md` names `project-flake` as the
job running
the zizmor regression gate (that file is hand-written, not generated
from
`docs/templates/`). `zizmor.yml`'s own header pointed a reader at
`.github/workflows/ci.yml → "Audit managed workflows"`, where that step
no longer
lives; it now names the composite step and the `project-flake` lane that
runs it.

That correction could not be confined to the root file:
`assets/workspace/zizmor.yml`
is **not** hand-edited — `sync-manifest` regenerates it from the root
copy and only
prepends the managed banner, so the hook rewrites the mirror (and fails
the commit)
the moment the root text changes. Both files therefore carry the same
comment-only
edit; no rule changes, so a consumer sees one line of header drift on
their next
upgrade and no behavior difference. Deferring the fix instead would have
meant
leaving the pointer wrong in the file a maintainer actually reads.

Archival `docs/issues/*`, `docs/pull-requests/*` and released CHANGELOG
entries
that mention "Project Checks" are left as the historical record they
are.

### Critical path

| Block | Before (run 36108278820) | After |
|---|---|---|
| `setup-env` | 44s (paid once) | ~42s per lane (34s dev-shell pull), in
parallel |
| prek linters | 42s | 42s — `Project Lint` job 1m36s |
| `bats -j 4 tests/bats/` | 3m11s | 3m17s — `Project BATS` job 4m08s |
| pytest + coverage | 1m18s | 1m24s — `Project Tests` job 2m14s |
| nix gates (Tier 0 45s, schema 29s, dev-shell 2s, hooks+services 35s,
modules 1m58s, stub+zizmor 6s) | 3m55s | 3m52s (Tier 0 46s, schema 31s,
dev-shell 2s, hooks+services 31s, modules 1m57s, stub+zizmor 5s) —
`Project Flake Gates` job 4m49s |
| **critical path** | **9m59s** (one serial job) | **4m49s** (`Project
Flake Gates`); BATS lane 4m08s. Whole run 10m46s → 8m58s; the run's path
is now build-image 1m49s → Security Scan 6m39s (#1701) |

Target from the issue: ≤ 5 min for the longest lane on a warm cache —
met (4m49s) on run
[36118110737](https://github.com/vig-os/devkit/actions/runs/36118110737).

## Changelog Entry

No changelog needed — CI-internal. No consumer-visible artifact changes:
nothing
under `assets/workspace/` or the image is touched, and the issue's own
Changelog
Category is "No changelog needed".

## Testing

- [ ] Tests pass locally (`just test`)
- [x] Manual testing performed (describe below)

`just test` is left unticked deliberately: it runs the whole of
`tests/`,
including `test_image.py` / `test_integration.py`, which need a freshly
built
image and podman and fail off a stale local `:dev` image. What ran
instead is the
selection the `project-tests` lane itself runs, plus the workflow-shape
suites —
below.

### Manual Testing Details

- `nix develop --command actionlint` — rc 0 over all workflows.
- `nix run nixpkgs#zizmor -- --offline .github/workflows/ci.yml
.github/actions/test-project/action.yml`
— 1 medium, 0 high, same as `dev` (the known `artipacked` on the
composite's
  own checkout). The three new lanes only add findings that are already
ignored/suppressed: 42 findings (8 ignored, 33 suppressed) on `dev` → 57
  (11 ignored, 45 suppressed), identical severity profile.
- Every `run:` body of the composite shellchecked by hand (`shellcheck
-x`, GH
expressions neutralised) — actionlint does not lint composite-action
shells.
All seven moved bodies clean; the only finding is the pre-existing,
deliberate
  `SC2086` on `$TEST_ARGS`.
- The pytest lane's own sweep — exactly what `project-tests` runs
(`tests/` minus
the 9 heavy Nix/image modules, plus `packages/vig-utils/tests`): **1591
passed**.
- Every workflow-shape suite (`tests/test_workflow_*.py`): **312
passed**.
- The suite guard exercised directly for each accepted value, an unknown
one and
  the empty string: rc 0 / rc 1 with the annotation, as intended.
- The new lane pins mutation-checked: pointing `project-tests` at `lint`
fails the
  per-lane pin and the distinctness pin.
- `nix develop --command prek run --all-files`: all hooks Passed, exit
0, tree
  still clean.
- The lanes themselves can only be proven by the PR's first CI run —
that is what
  fills the table above.

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have updated the documentation accordingly (edit
`docs/templates/`, then run `just docs`)
- [ ] I have updated `CHANGELOG.md` in the `[Unreleased]` section (and
pasted the entry above)
- [x] My changes generate no new warnings or errors
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] Any dependent changes have been merged and published

## Additional Notes

**Two of the issue's acceptance criteria need correcting.**

*Rulesets:* the criterion assumes a ruleset names `Project Checks`. It
does not.
`gh api repos/vig-os/devkit/rulesets` shows Dev protection and Release
protection
requiring only `Test Summary`, and Main protection requiring `Test
Summary` +
`CodeQL Analysis (actions)` + `CodeQL Analysis (python)`. The aggregate
absorbs
the rename, so **no `org-config` change is needed** and no aggregate job
has to be
kept for the check name.

*Scope:* the criterion says only `.github/**` changes. This PR also
touches
`tests/test_workflow_summary_gate.py` (the exact `needs:` set —
deliberately not
relaxed to a subset), `tests/test_workflow_zizmor_baseline.py` (the
zizmor gate
now lives in the composite) and one line of `docs/WORKFLOW_SECURITY.md`.
All three
are consequences of the rename, none is a consumer artifact.

*Lane:* this targets `dev`, not the release-neutral lane (#1676) —
`main` does not
yet carry the `bats -j` wrapper from #1690, so the drvPath-identity
guard has no
matching base there. It ships with the next train.

Three prose comments still say "project-checks" where the lane is now
named —
`flake.nix:1221`, `tests/test_utils.py:459` and
`tests/test_install_script.py:5`
(the complete live set; `grep -rn project-checks` over non-archival
files finds no
others). All three read correctly as generic descriptions of "the cheap
project
lane", none is a path or a job reference a tool resolves, so they are
left out of
this diff rather than widening it further.

Follow-up the issue predicted: `Security Scan` is now the whole-run
bottleneck
(build-image 1m57s → security-scan 6m28s = 8m25s on the same run). Filed
as #1701.

Refs: #1692
c-vigo added a commit that referenced this pull request Sep 25, 2026
## Description

Four tests-only issues in one PR. The load-bearing one is #1694:
`tests/bats/worktree.bats`
drove `just worktree-clean` against the repository's **live**
`<repo>-worktrees` sibling
directory, and that recipe force-removes every entry in it and `git
branch -D`s its branch.
On 2026-09-25 a local full-suite run deleted three agent worktrees and
their branches
mid-work. The file now drives every recipe against a throwaway `git
init` fixture under
`BATS_TEST_TMPDIR`, which also lets it drop its `CI=true` skips and
rejoin `bats -j`'s
within-file parallelism. The other three tighten the same suite: a
per-file
`bats_require_minimum_version` declaration with a pytest guard (#1697),
concurrent fixture
rendering in `init-workspace.bats`'s `setup_file` (#1695), and the
settled
`_upgrade` ≡ `_scaffold` equivalence that collapses the last pure-setup
renders (#1696).

No product code changes: `justfile.worktree`, its scaffolded mirror and
`assets/init-workspace.sh` are untouched. The only non-test file is
`CHANGELOG.md` (plus its synced mirror), where an **unreleased** #1687
sentence
had to be corrected — see Changelog Entry.

Review fixes are appended as their own commits rather than folded into
the
reviewed history.

## Type of Change

- [ ] `feat` -- New feature
- [ ] `fix` -- Bug fix
- [ ] `docs` -- Documentation only
- [x] `chore` -- Maintenance task (deps, config, etc.)
- [ ] `refactor` -- Code restructuring (no behavior change)
- [x] `test` -- Adding or updating tests
- [ ] `ci` -- CI/CD pipeline changes
- [ ] `build` -- Build system or dependency changes
- [ ] `revert` -- Reverts a previous commit
- [ ] `style` -- Code style (formatting, whitespace)

### Modifiers

- [ ] Breaking change (`!`) -- This change breaks backward compatibility

## Changes Made

**#1694 — worktree.bats no longer touches the live worktrees directory**

- `_wt_assert_throwaway` (committed red-first) asserts the base is
non-empty and under
`$BATS_TEST_TMPDIR` before any recipe runs or any directory is created.
6 of the 10 tests
  were red against the old wiring.
- `_wt_fixture` `git init`s a one-commit throwaway repo at
`$BATS_TEST_TMPDIR/fixture`;
`_wt_just` runs the recipes with `--justfile "$WT_MAIN"
--working-directory "$FIX"`.
`_wt_base` is `../<basename $(git rev-parse --show-toplevel)>-worktrees`
resolved against
just's working directory, so that one flag moves the whole base to
`$FIX-worktrees` —
no product knob, and the `#1463` tests in the same file already used the
idiom.
- The five `[ "${CI:-}" = "true" ] && skip` lines go: tmux reaches the
CI PATH via
`setup-env` and `tmux new-session -d` needs no TTY. The `command -v
tmux/just/claude`
  skips stay.
- `setup_file`'s `BATS_NO_PARALLELIZE_WITHIN_FILE` (added by #1690) goes
too — it was a
symptom of the shared base, not of the tmux server. Issue numbers carry
a
  `$$-$BATS_TEST_NUMBER` tag so derived session names stay unique.
- `/tmp/bats-claude-$$` and a `mktemp -d` move under `BATS_TEST_TMPDIR`,
which retires the
  manual `rm -rf` / `rmdir` cleanups.
- `tests/bats/worktree-claude-cli.bats` needs no change: pure
recipe-grep, no directories,
  no recipe invocations, no tmux.

**#1697 — `bats_require_minimum_version` in every file**

- New `tests/test_bats_shape.py`: one parametrized case per
`tests/bats/*.bats` asserting
the declaration is the file's first statement, plus a discovery guard so
a zero-file glob
  cannot pass silently. Committed red (20 failures) before the fix.
- The declaration is added to the 20 files that lacked it;
`githooks.bats` already had it.

**#1695 — concurrent `setup_file` renders**

- The fixture list is declarative (one `<name> <mode> [extra args]` line
each), marker
seeding moves into `_seed_shared`, and all renders are backgrounded and
`wait`ed on, with
  **every** failed fixture's log dumped rather than the first.
- Two new fixtures (`cargo-both`, `nix-module-both`) now that a fixture
costs ~0 wall time;
the four `Cargo.toml` / `nix/module.nix` seed-group tests clone them.
The two nix tests
create `$ws` instead of `$ws/nix` — `_clone_shared` refuses a non-empty
target.

**#1696 — collapse the pure-setup `_upgrade both` renders**

- The `_upgrade` ≡ `_scaffold` question is settled by evidence (below)
and the verdict is
written into `_clone_shared`'s CONTRACT comment so it is not
re-litigated.
- The 5 pure-setup sites clone the `both` fixture: the first run of the
`#878` stock test
(whose subject is the second run) and the four `#886` `--preview`
setups. The other 30 of
the 35 `_upgrade` tests seed a consumer file first or assert on the run
itself and keep
  their real invocation.

**Review round**

- The guard pinned `WT_BASE`, which **no recipe reads** — the recipes
derive
`../<basename $(git rev-parse --show-toplevel)>-worktrees` from just's
working directory,
and that is `FIX`. `FIX` is now pinned first (the `WT_BASE` asserts
stay, so the two cannot
drift), and `_wt_fixture` runs the guard **before its `git init`**: that
helper
`git add -A`s and commits inside `FIX`, so it mutates a real checkout
before any recipe
would. `_run_wt_start` — the file's one other real-recipe path, and the
one that actually
  `git worktree add`s — runs the same guard against its own sandbox.
- A `teardown()` reaps leaked tmux sessions: only a `wt-` name ending in
this test's unique
`WT_TAG`, or the claude probe's PID-tagged name. An unset `WT_TAG`
matches nothing, so
  `wt-*` can never sweep a developer's real sessions.
- Test 1 gave a backgrounded `just` exactly 2 s before a single
`has-session`; it now polls
up to 5 s, so a cold runner is a slow pass rather than a false negative.
- Both asserts in `tests/test_bats_shape.py` name the offending file,
the exact line required
  and where it goes.
- `CHANGELOG.md`: the unreleased #1687 sub-bullet is corrected (below).

## Changelog Entry

No changelog needed for the work itself. All four issues are labelled
"No changelog needed":
the change is confined to `tests/` and alters no consumer-visible
behaviour, no scaffolded
asset and no recipe.

What this PR does touch is a **correction to an existing,
still-unreleased sentence**, not a
new entry. The #1687 bullet under `## Unreleased` claimed the opposite
of what is now true:

```md
  - GNU parallel now rides with the bats wrapper in `nix/bats.nix` — … and both entry
    points, `just test-bats` and the `test-project` composite action, run
    `bats -j "$(nproc)"`. `worktree.bats` first opted out of within-file jobs, because its
    tests drove real tmux sessions against the repository's own sibling worktrees directory;
    it now drives an isolated per-test fixture repo instead, so it runs under `-j` and in CI
    like every other file
    ([#1694](#1694))
```

Nothing below `## Unreleased` is touched.
`assets/workspace/.devcontainer/CHANGELOG.md` is
the hook-synced mirror, regenerated by `sync-manifest`.

## Testing

- [x] Tests pass locally (`just test`)
- [x] Manual testing performed (describe below)

### Manual Testing Details

**#1694 red-first pin** — `bats tests/bats/worktree.bats`, `CI` unset:

```
not ok 1 worktree-attach restarts stopped session when worktree dir exists
# expression : [ /…/devkit-worktrees/1694-worktrees != /…/devkit-worktrees/1694-worktrees ]
ok   2 claude CLI launches in tmux without an interactive trust prompt
not ok 3 worktree-attach errors when neither worktree dir nor session exists   # [ -n  ]
not ok 4 worktree-clean stopped-only skips worktrees with running tmux session
not ok 5 worktree-clean all removes worktrees with running tmux sessions
not ok 6 wt-clean alias works for stopped-only and all                         # [ -n  ]
not ok 7 worktree-clean rejects invalid mode                                   # [ -n  ]
ok   8-10 (#1203, #1463 x2)
```

The pin fires before the `mkdir` and before the recipe, so nothing was
created outside a
tmpdir and no worktree or branch was removed. Note test 6 (`wt-clean
alias`) had **no**
`CI` skip — it ran `just wt-clean` against the real base even under
`CI=true`.

**#1694 green** — `worktree.bats` 10/10 with **0 skips** serially (`CI`
unset), 10/10 under
`CI=true bats -j 8`, and 10/10 on five consecutive `bats -j 8` runs — 0
flakes. The five
worktrees of this checkout (`devkit`, `1692`, `1693`, `1694`, `1698`)
are listed unchanged
before and after every run.

**#1697** — before: exactly one `BW02`, from `init-workspace.bats:1801`
(`run --separate-stderr`), printed in a trailing warnings block rather
than interleaved.
After: `bats -j 8 tests/bats/ 2>&1 | grep -c BW02` = **0**, 602/602
unchanged.
`pytest tests/test_bats_shape.py` 22 passed.

**#1695** — `setup_file` wall time, measured with `EPOCHREALTIME` inside
`bats -j 8` runs on
an 8-core host (instrumentation not committed):

| | run 1 | run 2 | run 3 |
|---|---|---|---|
| before (7 fixtures, serial) | 4.849 s | 5.814 s | 6.245 s |
| after (9 fixtures, concurrent) | 0.643 s | 0.607 s | 0.578 s |

`init-workspace.sh` invocations per file run (counting shim, not
committed): 250 -> 248.
`init-workspace.bats` 300/300 under `bats -j 8` and 300/300
sequentially.

Multi-failure diagnostics proved by temporarily breaking two fixtures
(`direnv`, `bare`):

```
not ok 1 setup_file failed
# shared direnv scaffold failed:
# Unknown option: --bogus-flag
# shared bare scaffold failed:
# Unknown option: --bogus-flag
```

**#1696 equivalence verdict — identical.** `_upgrade both` and
`_scaffold both` rendered
into empty directories, three rounds:

```
=== round 1 ===   DIFF CLEAN   MODES CLEAN
=== round 2 ===   DIFF CLEAN   MODES CLEAN
=== round 3 ===   DIFF CLEAN   MODES CLEAN
```

`diff -r` is clean and the `find -printf '%m %y %p' | sort` listings are
identical in every
round. Only stdout differs — the workspace path echo, rsync's byte
counters, and the extra
line the real `just` produces:

```
196a197
> just sync: no pyproject.toml — skipping
```

Invocations after the conversion: 248 -> **243**. `init-workspace.bats`
300/300.

**Review round — the `FIX` assert is load-bearing.** Temporarily
pointing `FIX` at
`$PROJECT_ROOT` (not committed): the guard fires from `_wt_fixture` at
the line before
`git init`, so nothing is created, staged or committed.

```
not ok 1 worktree-attach restarts stopped session when worktree dir exists
#  from function `_wt_fixture' in file tests/bats/worktree.bats, line 65,
#   `_wt_fixture' failed
# expression : [ /…/devkit-worktrees/1694 != /…/devkit-worktrees/1694 ]
…  (same for tests 3, 4, 5, 6, 7; tests 2, 8, 9, 10 pass)
```

That is why the guard moved into `_wt_fixture`: the reviewed version
protected only the
recipes, and `_wt_fixture` itself does `git add -A` + `commit` inside
`FIX`.

**Review round — green.** `worktree.bats` 10/10 on three consecutive
`bats -j 8` runs with
**0 skips**, and 10/10 under `CI=true bats -j 8`. `tmux list-sessions |
grep -c '^wt-'` = 0
after every run, so the new `teardown` leaks nothing.

**Review round — the assertion message.** With the declaration removed
from `just.bats`:

```
AssertionError: tests/bats/just.bats must declare `bats_require_minimum_version 1.5.0` as
its first statement (after the header comment, before setup); found 'setup() {'
```

**Whole suite** — `bats -j 8 tests/bats/`: **602/602**, 0 failures,
`grep -c BW02` = 0, and
**0 skipped tests** (`grep -c '# skip'` = 0). An earlier draft of this
body said "19 skips";
that number came from `grep -c skip`, which counts test *names*
containing the word — e.g.
`init-precommit.sh skips cleanly when no config is present (#854)`.
Nothing in the suite
skips.
`prek run --all-files`: 53 hooks, every one **Passed**, exit 0, in both
hook roots (`.` and
`assets/workspace`).

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have updated the documentation accordingly (edit
`docs/templates/`, then run `just docs`)
- [x] I have updated `CHANGELOG.md` in the `[Unreleased]` section (and
pasted the entry above)
- [x] My changes generate no new warnings or errors
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published

## Additional Notes

Three of the four issues carry factual corrections, posted separately as
issue comments:
#1694 misses that test 6 was unguarded by the `CI` skip and asserts a
TTY requirement that
does not exist; #1697 states that no file declares the version and
implies many warnings,
where `githooks.bats` already declared it and the suite emitted exactly
one; #1696 estimates
~13 convertible sites where 5 qualify under WP3's conversion rule.

The `#1694` fix is what makes the rest of this PR safe to run: until it
landed, any local
`bats tests/bats/` or `just test-bats` could delete a sibling worktree.

Refs: #1694, #1697, #1695, #1696
c-vigo added a commit that referenced this pull request Sep 25, 2026
#1108 evicted perl from the image and retired its CVE exception batch;
#1690 re-imported it by putting GNU parallel — a perl script — on the
bats wrapper's PATH, and nothing failed. Nothing pinned the eviction.

The test asserts both halves: no perl on PATH, and no perl derivation
anywhere under /nix/store in the image. The second is the one that
matters — perl was never on PATH even while it sat in the closure, which
is exactly where the nightly vulnix gate looks.

RED, proven against a locally built pre-fix image (`nix build
.#devkitImage` at this branch's parent, loaded as
`ghcr.io/vig-os/devcontainer:nix-dev`):

    AssertionError: perl is back in the image's runtime closure:
    myzwgd3ylpl3d8zrl7kl3l97i7zl8mw6-perl-5.42.0

The PATH half passed; the closure half failed.

Refs: #1708
c-vigo added a commit that referenced this pull request Sep 25, 2026
`bats --jobs N` shells out to a parallel runner on bats' own PATH, and
#1690 supplied GNU parallel. GNU parallel is a perl script, and the bats
wrapper ships in the image env, so perl 5.42.0 walked straight back into
the image's runtime closure — the one #1108 emptied of perl so its CVE
exception batch could be retired. The nightly vulnix gate on `dev` found
it with three unexcepted findings (CVE-2026-4176 9.8, CVE-2026-13221 9.1,
CVE-2026-57432 8.4); `main`, on the same nixpkgs pin, stayed green.

bats accepts shenwei356/rush as well as GNU parallel: bats-exec-suite
resolves the runner through BATS_PARALLEL_BINARY_NAME, which the wrapper
now sets by default so `bats -j` needs nothing from the caller. rush is
Go, so no interpreter rides behind it.

GREEN:

    nix build .#devkitImageEnv --print-out-paths
      /nix/store/9kcjnjxn...-devcontainer-image-env
    nix path-info -r <out> | grep -- '-perl-'            -> no matches
    nix path-info -r <out> | grep -- '-rush-parallel-'
      /nix/store/26ibnf7m...-rush-parallel-0.9.0

The image closure drops 47 MiB (1718506032 -> 1668846688 bytes).

    nix develop --command bats -j 4 tests/bats/just.bats \
        tests/bats/upgrade-atomicity.bats
      65 tests, 0 failures

rush stays off the dev-shell PATH (`command -v rush` finds nothing there)
— it rides inside the wrapper, bats being its only consumer — and jobs are
genuinely engaged: just.bats is 5.4s serial against 1.9s at -j 8, and the
same run with a deliberately bogus BATS_PARALLEL_BINARY_NAME fails with
"command not found", so the lookup is live rather than silently serial.

Refs: #1708
c-vigo added a commit that referenced this pull request Sep 25, 2026
## Description

The 2026-09-25 nightly vulnix scan went red on `dev` (#1708) with three
unexcepted HIGH/CRITICAL findings in **perl 5.42.0** (CVE-2026-4176 9.8,
CVE-2026-13221 9.1, CVE-2026-57432 8.4) while `main` scanned green on
the same nixpkgs pin. The runtime-closure diff `main` → `dev` is exactly
`+ bats-with-libraries`, `+ parallel`, `+ perl`: #1690 (#1687) put GNU
`parallel` on the bats wrapper's PATH so `bats --jobs` works, GNU
parallel is a perl script, and the wrapper ships in the image env. That
silently reversed the perl eviction from #1108, whose CVE exception
batch had been retired on the strength of perl being gone.

`nixos-26.05` still carries perl 5.42.0 (5.42.3 is only on
`master`/`nixos-unstable`, no backport), so a pin advance cannot clear
this. The fix swaps the runner for shenwei356/rush, which
`bats-exec-suite` supports natively via `BATS_PARALLEL_BINARY_NAME`; the
wrapper sets it, so `bats -j` still needs nothing from the caller. rush
is Go: no interpreter, and the image's runtime closure measures 47 MiB
smaller. No `.vulnixignore` entry is needed since perl leaves the
closure.

A negative image test now pins the eviction on both axes (`command -v
perl` fails **and** no `*-perl-*` derivation in `/nix/store`). The PATH
half alone was blind — perl was never on PATH while it sat in the
closure, which is where vulnix looks — and that blindness is why nothing
caught #1690.

## Type of Change

- [ ] `feat` -- New feature
- [x] `fix` -- Bug fix
- [ ] `docs` -- Documentation only
- [ ] `chore` -- Maintenance task (deps, config, etc.)
- [ ] `refactor` -- Code restructuring (no behavior change)
- [x] `test` -- Adding or updating tests
- [ ] `ci` -- CI/CD pipeline changes
- [ ] `build` -- Build system or dependency changes
- [ ] `revert` -- Reverts a previous commit
- [ ] `style` -- Code style (formatting, whitespace)

### Modifiers

- [ ] Breaking change (`!`) -- This change breaks backward compatibility

## Changes Made

`nix/bats.nix`

- `pkgs.rush-parallel` replaces `pkgs.parallel` in the wrapper's PATH
prefix; `--set-default BATS_PARALLEL_BINARY_NAME rush` so callers keep
running plain `bats -j`
- Header comment explains the runner choice and why GNU parallel is out

`tests/test_image.py`

- `TestFileStructure.test_perl_absent_from_image`: `command -v perl`
must fail and `/nix/store` must hold no `^[a-z0-9]{32}-perl5?[-.][0-9]`
entry. Fails on the pre-fix image with `perl is back in the image's
runtime closure: myzwgd3y…-perl-5.42.0`, passes on the post-fix image

`justfile`, `.github/actions/test-project/action.yml`,
`tests/bats/just.bats`

- Comment-only: the sites that said GNU parallel rides with the wrapper
now name rush. The assertion that the justfile carries no `command -v
parallel` branch is unchanged

`CHANGELOG.md`, `assets/workspace/.devcontainer/CHANGELOG.md`

- New `### Fixed` entry under `## Unreleased` (below); the existing
Unreleased #1687 bullet no longer says "GNU parallel" or "incremental
closure under 1 MiB", since both would ship as false in the same release
notes. Mirror edited identically (the sync script skip-lists both
changelogs)

## Changelog Entry

### Fixed

- **`bats --jobs` runs on rush, keeping perl out of the image**
  ([#1708](#1708))
  - The parallel runner that arrived with `bats -j`
([#1687](#1687)) was GNU
parallel,
which is a perl script. The bats wrapper ships in the image env, so perl
    5.42.0 re-entered the image's runtime closure —
    [#1108](#1108) had evicted it
precisely so its CVE exception batch could be retired — carrying three
    findings the register holds no exception for (CVE-2026-4176 9.8,
CVE-2026-13221 9.1, CVE-2026-57432 8.4). The nightly vulnix gate on
`dev`
    caught it; no release carried it.
- The runner is now
[shenwei356/rush](https://github.com/shenwei356/rush),
which bats supports natively via `BATS_PARALLEL_BINARY_NAME` (the
wrapper
sets it, so `bats -j` still needs nothing from the caller). rush is Go:
no
    interpreter behind it, and the image's runtime closure drops 47 MiB.
- A negative image test pins the eviction, which nothing had: no perl on
PATH
**and** no perl derivation anywhere in the image's store. The second
half is
the one that matters — perl was never on PATH even while it sat in the
    closure, which is where the vulnix scan looks.


## Testing

- [x] Tests pass locally (`just test`)
- [x] Manual testing performed (describe below)

### Manual Testing Details

- RED: pre-fix `nix build .#devkitImage` → `podman load` →
`TEST_CONTAINER_TAG=nix-dev uv run pytest tests/test_image.py -k
perl_absent` → **1 failed**
(`myzwgd3ylpl3d8zrl7kl3l97i7zl8mw6-perl-5.42.0` in the closure; the PATH
assertion alone passed)
- GREEN: post-fix image, same command → passes; whole
`tests/test_image.py` → **113 passed**. Inside the container: `perl`
absent, `parallel` absent, `bats -j 3` on a 3-test fixture runs 3/3
- Closure proof: `nix path-info -r $(nix build .#devkitImageEnv
--print-out-paths) | grep -- '-perl-'` → empty; `-rush-parallel-` →
`26ibnf7m…-rush-parallel-0.9.0`. Closure bytes 1718506032 → 1668846688
(−47.36 MiB)
- Suite under the new wrapper (`nix develop`): all files except
`worktree.bats`, `bats -j $(nproc)` → **596 ok, 0 failures**, 60 s wall.
Parallelism is engaged: `just.bats` 5.4 s serial vs 1.9 s at `-j 8`;
`BATS_PARALLEL_BINARY_NAME=nosuchrunner` fails with `command not found`
- `command -v rush` finds nothing in the dev shell: rush rides inside
the wrapper only
- `prek run --all-files` → all 53 hooks passed; `uv run pytest
tests/test_bats_shape.py tests/test_flake_hooks.py` → 96 passed

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have updated the documentation accordingly (edit
`docs/templates/`, then run `just docs`)
- [x] I have updated `CHANGELOG.md` in the `[Unreleased]` section (and
pasted the entry above)
- [x] My changes generate no new warnings or errors
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] Any dependent changes have been merged and published

## Additional Notes

Diagnosis with the `nix why-depends` chain is on the issue. #1708 closes
itself once the next scheduled `security-scan.yml` run passes the gate
on `dev`.

Refs: #1708
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant