Skip to content

fix-wave 2: Windows script invocation through lib/script-invocation.ts (#3197) - #3204

Closed
garrytan wants to merge 9 commits into
capy/fixwave-1bfrom
capy/fixwave-2
Closed

garrytan wants to merge 9 commits into
capy/fixwave-1bfrom
capy/fixwave-2

Conversation

@garrytan

Copy link
Copy Markdown
Owner

Fix wave 2026-10-15 stack (review per layer; merge only the wave PR capy/fixwave-release → main, which carries the single v1.91.104.0 stamp, the combined CHANGELOG, and runs the paid gate once). Order: capy/fix-wave-2026-10-15 (= main 47d639a) ← 1a ← 1b ← 2 ← 3 ← 4 ← release. This PR: 2. Layer PRs target the layer below, so no paid evals run on them; they get closed with a pointer once the wave PR merges.

Behavior changes

  • On Windows, gstack's TypeScript callers run gstack's own scripts through one resolver, lib/script-invocation.ts. Bun on Windows can't execute an extensionless shebang script, so before this PR gstack-restamp refused with cannot fingerprint the working tree (), gstack-gate-diff and gstack-evidence silently dropped the content fingerprint, and the pregate secrets check couldn't start gstack-redact (On Windows with Bun 1.4.2, gstack-pregate refuses and gstack-restamp fails: spawnSync cannot execute bin/gstack-wtree, and pregate reports a misleading POLICY_SOURCE_UNAVAILABLE #3197, reported by @exGeni). Bash scripts now run through Git Bash and Bun scripts through Bun. The migrated call sites are hosts/claude/hooks/spawn-bin.ts, lib/gbrain-exec.ts, lib/regen.ts, gate-diff (bin/gstack-gate-diff, lib/gate-diff/git.ts), lib/restamp.ts, bin/gstack-evidence, lib/pregate/checks/secrets.ts and lib/pregate/lane-selection.ts.
  • Git Bash is looked up in a fixed order: GSTACK_GIT_BASH; then GSTACK_BASH as a deprecated alias (when both are set and differ, the canonical one wins with a one-line warning, and a value that points nowhere is refused instead of skipped); then the bash.exe next to git --exec-path; then the standard install paths; then a PATH bash only when its uname reports MSYS or MINGW. WSL launchers (System32, WindowsApps) and Cygwin are rejected, and hooks no longer fall back to a bare PATH bash.
  • When no Git Bash is found, the error lists every candidate gstack tried and why each was rejected, and ends with the new result code BASH_UNAVAILABLE. Its troubleshooting entry is docs/troubleshooting.md#bash-unavailable.
  • Hooks resolve bash without spawning. The resolution is cached in <state root>/cache/windows-bash.json, keyed by the git.exe path and mtime.
  • wtreeFingerprint returns {tree} or {error, kind: 'launch' | 'exit'} and always sets GIT_OPTIONAL_LOCKS=0. Each consumer now says why a fingerprint is missing:
    • regen check reports the check as incomplete and names the cause;
    • gate-diff records +nowtree with the cause;
    • restamp refuses with RESTAMP_CONFLICT and the detail (gstack-wtree exited 1: …, gstack-wtree could not start: …);
    • evidence records without wtree and warns once instead of staying silent.
      lib/regen.ts keeps a string-returning wtreeFingerprint(repoRoot) wrapper for the pregate callers until they move to the shared fingerprint in a follow-up release.
  • Repositories with SHA-256 object ids now get a 64-hex evidence fingerprint. gstack-evidence used to accept only 40-hex trees.
  • The pregate selection manifest keeps framework route paths whole ((group), [id], [...slug], @slot, $id, +page). A test in a platform-only lane now keeps its remote receipt obligation instead of quietly running locally. This is the manifest-parser half of @vocodestudios's fix(pregate): map Next.js route paths and tsconfig path aliases to their tests #3176; the tsconfig-alias half ships separately.
  • New .github/workflows/windows-pregate-e2e.yml drives restamp, regen, evidence, gate-diff, a timed hook and the refusal on windows-latest, once under the runner's Git and once under a pinned, checksum-verified PortableGit 2.56.0.2 (sha256 075e158e…). It has no cache step: the secret scanner flagged the cache key's env.kv as a false positive, so the step was dropped instead of allowlisted.
  • test/script-invocation-tripwire.test.ts fails when a file under lib/, under hosts/, or a Bun bin spawns a gstack bin by path or a bare bash. Five known sites outside this change are listed with their owners and may only shrink. The same test keeps the compiled binaries from importing the module.
  • Intentional pin changes:
    • test/gbrain-spawn-windows-shell.test.ts now expects forward-slashed bash paths;
    • the copied-tree adapters in test/timeline-stop-hook-slug.test.ts and test/plan-tune-cathedral.test.ts now list lib/script-invocation.ts and lib/result-codes.ts, which the copied scripts import.
      No other assertion was weakened.
  • setup.ps1 (from layer 1b) now resolves Git Bash by the same table. test/setup-ps1.test.ts drives it through every row of test/fixtures/windows-bash-resolution.json instead of a hand-mirrored copy. Two rows failed and are fixed in setup.ps1: an override and alias that differ only in slash direction no longer print the differ warning, and the root that git --exec-path names is also searched for usr\bin\bash.exe (Git for Windows on arm64).
  • No VERSION, CHANGELOG, package.json or agents-digest change. The wave's release layer carries the single stamp and the combined CHANGELOG; this layer's entry is in ~/.capy/work/changelog-C.md.

Coordinator exception

The coordinator accepted these edits outside Lane C's file list:

  • bin/gstack-doctor-components.sh, which is generated and regenerated by this change;
  • scripts/test-pr-profile.ts and scripts/harness-version.json, which register the new tests with the PR profile and record the harness-version decision (non-behavioral);
  • test/helpers/free-fixtures-data.ts, which registers the new free fixtures;
  • setup.ps1 and test/setup-ps1.test.ts (layer 1b's files), edited at the coordinator's request to wire them to the shared resolver table.

This PR doesn't touch lib/pregate/context.ts, lib/pregate/index.ts (#3190's files) or bin/gstack-upgrade.

Paid checks

This layer targets capy/fixwave-1b, not main, so no paid CI runs on it. The paid PR gate runs once, on the wave PR from the top of the stack to main. Nothing paid was run locally.

Measured against main before the stack rebase, Lane C's changes alone select:

  • profile=pr selected 108 of 245 tests -> running 81 of 81 shards
  • tier=gate: 47/108 files, 81 shards, jobs=8, ordinary default wall=1800s

The selection is broad because this layer changes shared derived references. bin/gstack-doctor-components.sh, lib/pregate/checks/secrets.ts, lib/pregate/lane-selection.ts, lib/regen.ts, lib/restamp.ts, lib/result-codes.ts and lib/script-invocation.ts each select all 244 dependent gate cases, and hosts/claude/hooks/spawn-bin.ts selects 35. test/helpers/free-fixtures-data.ts is a paid-runner input, so it selects every case. 137 of the selected behaviors remain scheduled or release coverage, not PR passes.

Validation

Failing-first, on base 47d639a:

Test On base
test/script-invocation.test.ts Cannot find module '../lib/script-invocation'
test/script-invocation-tripwire.test.ts fails, listing 10 by-path or bare-bash spawn sites in evidence, gate-diff, secrets, lane-selection, regen and restamp
test/pregate-manifest-paths.test.ts (CLI case) requires_remote expected the windows-shard obligation for app/(shop)/[id]/page.test.js, received []
test/wtree-consumers.test.ts 5 fail: regen and gate-diff print (gstack-wtree failed) with no cause, restamp passes raw stderr, the SHA-256 evidence record has no wtree, and the unavailable case prints 0 warnings

After the fix:

  • Focused tests after the rebase onto capy/fixwave-1b (head 5e19e47): 748 pass, 0 fail across 40 files, with pwsh 7.4.6 so the setup.ps1 cases run. The first run of the same set, which ran alongside typecheck, failed 3 test/autoplan-residuals.test.ts cases with RUNTIME_BELOW_MINIMUM (bun 1.3.14). They passed alone, in either half of the set, and in a full rerun of the same order. bun run typecheck reports 0 errors, and the typecheck:test ratchet reports "none new".
  • bun run test on Ubicloud (ubirun-fixwave2c-1792091137-c0056a9f, head 617d3fa51) passed: 17/17 shards, 28,227 tests, 0 failed. The earlier run ubirun-fixwave2c-1792089187-d4dbd99a failed only test/harness-version.test.ts, which the scripts/harness-version.json decision fixed. That run predates the stack rebase; the integrator reruns the suite at freeze.
  • gstack-pregate has not cleared. The last local run (tree 631d035c0f5a, head a476932f99d6, before the harness-version fix) reported PREGATE: fail. Its local-lane failures fail the same way on base: 9 come from the unattended-session launch variables, and gstack-retro-metrics and transcript-scope-brain-sync fail because fixture authors resolve to this machine's git identity. The secrets check warned on 5 MEDIUM PII findings, which don't block.

Coordination

Open in Capy

garrytan and others added 9 commits October 16, 2026 00:31
Windows has no shebangs, and gstack had three conflicting bash lookups:
the hooks fell back to a bare PATH `bash` (often WSL's launcher), the
gbrain sync checked three fixed paths, and setup.ps1 walked up from
git.exe. lib/script-invocation.ts is now the only TypeScript resolver:
GSTACK_GIT_BASH (GSTACK_BASH as a deprecated alias, same precedence,
warning when they differ, a missing value refused), bash next to
`git --exec-path` (scoop, per-user, portable Git), the known install
paths, then a PATH bash only when `uname -s` reports MSYS/MINGW. WSL
launchers are rejected unprobed. A miss is BASH_UNAVAILABLE, listing
every candidate with its rejection reason.

Bun-shebang bins run under Bun (process.execPath, or the PATH bun inside
a compiled binary). Hooks' runBin resolves through a state-root cache
keyed by git.exe path and mtime, written by temp file plus rename, so
the hot path spawns nothing extra; the override is never cached.
wtreeFingerprint({cwd, timeoutMs}) returns {tree} | {error, kind} with
GIT_OPTIONAL_LOCKS=0 and 40-64 hex ids; the consumers move next.

Intentional pin change: test/gbrain-spawn-windows-shell.test.ts expects
forward-slashed bash paths (WIN_BASH and the GSTACK_BASH override), the
form the shared resolver returns because Bun's spawnSync on Windows
returns ENOENT for a backslash exe path containing spaces.
The copied-tree adapters in test/timeline-stop-hook-slug.test.ts and
test/plan-tune-cathedral.test.ts list the two modules spawn-bin.ts now
imports; the new fixture is registered in test/helpers/free-fixtures-data.ts. bin/gstack-doctor-components.sh is
regenerated for the new result-code row.

Reported by @exGeni.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…on (#3197)

bin/gstack-wtree was spawned by path in lib/regen.ts, lib/gate-diff/git.ts,
lib/restamp.ts and bin/gstack-evidence; gstack-slug in restamp, gate-diff
and evidence; gstack-redact in the pregate secrets check; and a bare
`bash -c` in regen, the lane selection manifest and gstack-evidence run.
On Windows each one failed to launch. All now go through
lib/script-invocation.ts, and each fingerprint consumer keeps its fail
direction while saying why:

- gstack-regen check: incomplete, `cannot fingerprint the working tree
  (gstack-wtree exited 1: <helper's own repair>)` instead of
  `(gstack-wtree failed)`; write keeps the registry label as its run id.
- gstack-gate-diff: `+nowtree` candidate, with the cause.
- gstack-restamp: RESTAMP_CONFLICT carrying the launch or exit detail
  (Windows printed `()` before).
- gstack-evidence: records without wtree (grades STALE) and warns once;
  SHA-256 repositories now get a 64-hex fingerprint.

lib/regen.ts keeps a string-returning wtreeFingerprint(repoRoot) wrapper
for lib/pregate/context.ts and lib/pregate/index.ts (files #3190 changes);
item 10b migrates them. test/script-invocation-tripwire.test.ts fails on a
new by-path or bare-bash spawn under lib/, hosts/ or a Bun bin; five sites
outside this change are listed with their owners and may only shrink.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…3176)

laneFileSet parsed manifest output with `[\w.-]+` path segments, so
`app/(shop)/[id]/page.test.ts` came back as `page.test.ts`. The selected
test then matched no platform lane, its remote receipt obligation
vanished and it fell back to a local run. manifestTestPaths keeps route
segments whole (`(group)`, `[id]`, `[...slug]`, `[[lang]]`, `@slot`,
`$param`, `+page`), reads every path-shaped token on a line (JSON
arrays, quoted, `path:line`, parenthesized), and decides what is a test
file with the import graph's own isTestFile, so a test-file rule change
there (bats, #3177) reaches manifests without a second regex. A manifest
that cannot start is "unknown" (widens), like a non-zero exit.

This is the manifest-parser half of #3176 by @vocodestudios; the
import-graph half (tsconfig aliases, Next.js route mapping) ships in a
separate PR. test/pregate-manifest-paths.test.ts drives the CLI with a
bracketed route test in the fixture's Windows-only lane and asserts its
requires-remote obligation; it failed on main (requires_remote was []).

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
A windows-latest job (Bun 1.4.2) builds a fixture repository and runs
gstack-restamp --dry-run, gstack-regen check and write, gstack-evidence
run and gstack-gate-diff from their TypeScript entry points, asserting a
real tree fingerprint each time; times a question-log hook cold and warm
and checks it cached its Git Bash resolution; and checks that a missing
GSTACK_GIT_BASH refuses with BASH_UNAVAILABLE and lists the candidate.
The journey runs twice: under the runner's Git for Windows and under a
pinned PortableGit 2.56.0.2 (SHA-256 verified), found only through
`git --exec-path`. gstack-pregate run joins it with item 10b. The workflow is registered in
scripts/test-pr-profile.ts FREE_ONLY_PR_FILES (no paid case reads it), recorded
as a non-behavioral HARNESS_VERSION decision in scripts/harness-version.json.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
test/setup-ps1.test.ts now drives setup.ps1 through every row of
test/fixtures/windows-bash-resolution.json, the table that pins
lib/script-invocation.ts, instead of a hand-mirrored copy. Two rows
failed and are fixed here:
- an override and alias that differ only in slash direction no longer
  print the differ warning;
- the root git --exec-path names is also searched for usr\bin\bash.exe
  (Git for Windows on arm64).

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…duct does (#3197, #3176)

windows-free-tests run 38813751242 failed two tests this layer added. Both
were fixture defects on a real Windows host, not product defects:
- gbrain-spawn-windows-shell "returns null when Windows has no bash" stubbed
  only `exists`. The resolver's PATH step asks the real Bun.which and found
  the runner's MSYS bash, which is correct. The case now also stubs
  `which` and `gitExecPath`, so it really means "no bash anywhere".
- pregate-manifest-paths spawned the extensionless bin/gstack-pregate
  directly. CreateProcess cannot exec a shebang, so nothing ran and stdout
  was "". It now launches through lib/script-invocation's runScriptSync,
  gstack's own Windows invocation, so the case runs the manifest lane end
  to end on Windows instead of being excluded.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…3197)

GitHub runs `shell: bash` as `bash -eo pipefail`, and the step's own
`set -uo pipefail` does not turn -e off. So when gstack-restamp refused, as
the step expects, `OUT=$(...)` aborted the script before `CODE=$?` and before
any output was printed: exit 1 after 0.5 s with nothing in the log (PR #3209,
job 116729693492). The capture is now `OUT=$(...) && CODE=0 || CODE=$?`.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…anes (#3176)

Once 8b2f297 made the case run on Windows, windows-free-tests run
38824886195 (shard 4) showed the expectation itself was Linux-only. pregate
owes a lane remotely when its runner platform is not the host's
(lib/pregate/workflows.ts). On a Windows host the fixture's Windows lane
runs locally, and the Ubuntu `free-tests.yml/unit` lane is the remote
obligation; that is the record Windows produced.

The case now derives the owed lanes from the host the same way. On Windows
it also requires `ran: node --test 'app/(shop)/[id]/page.test.js'`: there the
route reaches the local run only through the manifest's whole path. With a
cut manifest path (page.test.js) the local set is empty, checked through
buildContext({ platform: 'win32' }) + selectLanes.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…red table drives it

Layer 2 drives setup.ps1 through the 16 shared rows of
test/fixtures/windows-bash-resolution.json; like the 14 existing resolution
rows they run under pwsh on Linux and skip on Windows. The case list is still
asserted exactly (4 pass, 0 fail, 31 skip).

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai

capy-ai Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Merged to main through the wave PR #3209 (squash 3e8b34d, v1.91.106.0), which carried this layer unchanged. Closing the layer PR.

@capy-ai capy-ai Bot closed this Oct 16, 2026
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