Skip to content

test(cso): build the git-hardening fixture repo once per file - #3207

Closed
scottgigante-hubflow wants to merge 1 commit into
garrytan:mainfrom
scottgigante-hubflow:fix/cso-git-hardening-timeout
Closed

scottgigante-hubflow wants to merge 1 commit into
garrytan:mainfrom
scottgigante-hubflow:fix/cso-git-hardening-timeout

Conversation

@scottgigante-hubflow

Copy link
Copy Markdown
Contributor

Flake

macos-named-regressions failed in run 38800592772. That failure also turned the free-tests aggregate red on #3201, a PR that doesn't touch CSO. The failing test was:

(fail) CSO Git metadata hardening > reports a bounded operation and exit status without exposing Git argv or paths [5041.54ms]
  ^ this test timed out after 5000ms.
+ [Error: ENOENT: no such file or directory, lstat '.../cso-git-hardening-7EIJKm/repo/.git']

Root cause

The 5 s budget was used up by the fixture, not by the code under test.

  • Where the ENOENT comes from: it is the raw lstatSync(join(repo, '.git')) in gitDirectories(). hardenGit() makes that call synchronously at the very start of readGitMetadata, before the operation spawns its own git child.
  • What that means: when the 5 s ran out, the code under test had done essentially nothing. afterEach was already tearing the fixture down underneath it. The time went into fixture(), which spawns /usr/bin/git five times (init, config ×2, add, commit) inside each test's own budget.
  • Why only on CI: on macOS, /usr/bin/git is the Xcode shim. Its first spawns on a fresh runner are slow and their cost varies from run to run.
  • The slowness was specific to this file's git spawns. Comparing per-test durations in the failing run with the last green main run (38608118319, same job, same file order):
test main failing run
this test (first in file) 1039 ms >5000 ms (timeout)
next test, same fixture shape 150 ms 1335 ms (8.9x)
later tests in this file 136–418 ms 477–686 ms
unrelated tests in the same job (PTY fake-CLI, chromium, codex-probe) — 1.0–1.2x of main
  • The runner as a whole was not slow.
  • The first test also carries about 900 ms of cold-spawn overhead on green main runs, so it was already the closest to the edge.
  • Bun also logged killed 1 dangling process five times at the timeout, once for each fixture git spawn.

Fix

  • beforeAll builds the fixture repo once per file, with an explicit { timeout: 30_000 }. That is the same bound each fixture spawnSync already declares, so the hook adds no new allowance.
  • fixture() now gives each test a fresh fs.cpSync copy of that repo, with no git subprocesses.
  • Tests that change the repo still get the per-test git helper.
  • Each test's 5 s now covers the code under test, not toolchain warm-up. No test timeout was raised.

test/cso-cli.test.ts and test/cso-cli-recheck.test.ts already build their repos once in beforeAll; this follows that precedent. No other file in the macos-named-regressions list builds a git repo per test.

Does it still catch a regression?

  • P(fail | regression), before and after: about 1. The assertions and lib/cso/process.ts are unchanged, and every test still runs the real hardened git path against a real repo. The time budget for the code under test is still bun's default 5 s.
  • Mutation check: I changed 'request rejected' to 'rejected' in git()'s reason mapping. The fixed test fails as expected ((fail) ... reports a bounded operation ... [16.90ms], 9 pass / 1 fail). With the mutation reverted, everything passes.
  • What changes: only P(fail | no regression). The flaky test now spawns one git process inside its budget instead of six.

Evidence

Local results on macOS 15, bun 1.3.11, bun test test/cso-git-hardening.test.ts ×20 each:

runs green first test median first test max
before 20/20 75 ms 453 ms
after 20/20 18 ms 68 ms
  • I couldn't reproduce the 5 s spike locally, even after xcrun --kill-cache. The before-run maximum of 453 ms is the same cold-spawn variance at a smaller scale.
  • bun run typecheck:test passes.

VERSION and CHANGELOG are not bumped. I've left that to the maintainer's release slot.

🤖 Generated with Claude Code

Each test built its fixture repo with five /usr/bin/git spawns inside
its own 5 s budget. On macOS that binary is the Xcode shim, and on a cold
runner those spawns cost far more than the code under test: in run
38800592772 the first test timed out at 5 s before readGitMetadata got
past its first lstat, and afterEach then tore the fixture down under it.

Build the repo once in beforeAll, under the same 30 s bound each fixture
spawn already declares, and give every test a fresh copy. The assertions
and the code under test are unchanged, and each test keeps its full 5 s
for the code under test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trunk-io

trunk-io Bot commented Oct 15, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@capy-ai

capy-ai Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Triage (fix wave 5, GSTA-37): the diagnosis and fix are right. It's cherry-picked with your authorship into #3225. This PR will be closed as superseded once #3225 merges.

capy-ai Bot added a commit that referenced this pull request Oct 17, 2026
…ndows gstack-upgrade, env.kv schema keys (#3208), browse rule 3 (#3216), review summaries (#3219), CSO flake (#3207) (#3225)

* fix(upgrade): accept a Git Bash checkout whose toplevel Git spells C:/…

bin/gstack-upgrade compared `git rev-parse --show-toplevel` (C:/x from Git
for Windows) with `pwd -P` (/c/x in Git Bash) as strings, so every Windows
Git Bash install was refused as "not a gstack checkout", and the doctor's
recovery line points at this command. Compare the two through
gstack_path_same (bin/gstack-path-spelling.sh); a tree nested inside another
repository is still refused.

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

* fix(redact): a catalog field named <schema word>_key is not a credential (#3208)

env.kv accepted every separated name ending in _key, so a catalog entry
`"input_key": "expected_media_rate_bits_per_second_ingress"` failed
pregate's never-downgradable secrets check as MEDIUM env.kv [secret]. The
camelCase twins (cacheKey, sortKey, partitionKey, idempotencyKey) were already
rejected for having no credential prefix; the snake/kebab/dotted forms of
those data-model words now are too. ALL-CAPS env names (INPUT_KEY=) and
credential-word names (signing_key, stripe_key, input_secret) still fire.

Reported by @brentyates-swx.

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

* test(cso): build the git-hardening fixture repo once per file

Each test built its fixture repo with five /usr/bin/git spawns inside
its own 5 s budget. On macOS that binary is the Xcode shim, and on a cold
runner those spawns cost far more than the code under test: in run
38800592772 the first test timed out at 5 s before readGitMetadata got
past its first lstat, and afterEach then tore the fixture down under it.

Build the repo once in beforeAll, under the same 30 s bound each fixture
spawn already declares, and give every test a fresh copy. The assertions
and the code under test are unchanged, and each test keeps its full 5 s
for the code under test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(browse): rule 3 treats wizard steps as writes and reads back sets before saving (#3216)

On a non-local target a wizard or dialog step (Next, Step N, a menu item
that opens a dialog) now counts as mutating until its handler or network
effect shows otherwise, and its Cancel proves nothing. Before any Save or
Submit, every programmatic set is read back and the flow stops on a
mismatch. The cookbook's silent-failures list adds the skip-path
precondition probe. Redundant clauses in rules 2, 3, 7, 8, 9, 10 and
READY are tightened so the shared setup grows by 3 bytes and every
browsing skill stays under its parity cap.

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

* fix(plan-design-review): keep the Completion Summary out of the regenerated report (#3219)

The design review saved its Completion Summary inside the terminal
GSTACK REVIEW REPORT section, which the next plan review deletes from
its heading to the next "## " heading. The summary, deferred list and
unresolved decisions now go in their own "## Design Review Completion
Summary" section above the report, and the template says everything
under the report heading is regenerated by the next review.

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

* fix(redact): exempt a schema field only when its name and value both say so (#3208)

Review (GPT-6.1 Sol outside voice): the name-only exemption also silenced
real secrets, e.g. Azure's cosmosdb_primary_key and any longer name such as
api_cache_key. Now the whole name must be one data-model word plus _key
(primary/secondary dropped) and the value two or more lowercase identifier
words; an entropic value, a longer name or a credential name still fires in
.env, YAML, JSON and TOML.

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

* test(upgrade): the Git shim delegates with the unshimmed PATH

A PATH-searching git wrapper found the shim again and recursed until the
test timed out. The shim now restores the host PATH before running git.

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

* fix(pregate): secrets scans each file with its type and never reads an emptied diff as clean (#3211)

addedLines() flattened every file into one added.txt, so gstack-redact never
saw a .ts path and the #3048 source-expression exemption never ran: TS
properties such as `token: credentials.token,` failed the gate as MEDIUM
env.kv. Two false negatives predate this wave: the `+++` header filter
dropped added content lines that begin with "++", and `git diff` honoured
diff.external/textconv, so an external driver that prints nothing made a
branch carrying a real AWS key pass with "no added lines".

Added lines are now parsed hunk-aware per file (the pre-push hook's rules),
with --no-ext-diff --no-textconv, and each file is scanned as
<tmp>/<i>/<basename> so its type survives; findings name the file.

Reported by @brentyates-swx.

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

* fix(plan-devex-review): keep the DX Scorecard out of the regenerated report (#3219)

The DX Scorecard had the same placement gap as the design Completion
Summary: with no rule, it could land inside GSTACK REVIEW REPORT, which the
next plan review deletes. It now goes in its own "## DX Review Scorecard"
section above the report.

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

* v1.91.109.0 fix: wave 5 — pregate secrets false negatives (#3211), Windows gstack-upgrade, env.kv schema keys (#3208), browse rule 3 (#3216), review summaries (#3219)

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

---------

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: Scott Gigante <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@capy-ai

capy-ai Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Landed in #3225 (v1.91.109.0, 86091dd) as a cherry-pick with your authorship kept. Thanks, Scott, the root-cause write-up made this easy to verify. Closing as superseded.

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