From ecf3ad78e6d8b393d327bb9a0a0fc8ad0c9d927f Mon Sep 17 00:00:00 2001 From: garrytan Date: Tue, 27 Oct 2026 11:34:54 +0000 Subject: [PATCH] fix: adversarial review fixes The pack snapshot carries the index's staged blobs as a pack of their own, so a VM write-tree (gstack-wtree) can read a staged file the way the old .git tar allowed; git init runs with --template= and gc.auto=0 and a valueless remote/branch key replays as true. scripts/harness-version.json re-pins scripts/test-pr-profile.ts after the captain/templates/** entry. The run-id exemption reads the same way in the scanner and gstack-post: an 11-digit span after a run word is a run id (the leading-1 exclusion from the Red Team pass contradicted gstack-post's tested contract and the ruling that a run id is not a phone number), with the residual named in the comment, the docs and the CHANGELOG. The #3499 pins move to their own test so the boundary test stays under its default budget. Docs audit: TESTING_INTERNALS names RELEASE_METADATA_FILES and captain/templates/**, docs/captain.md names Blast radius. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --- CHANGELOG.md | 4 ++-- docs/TESTING_INTERNALS.md | 6 ++++-- docs/captain.md | 2 +- docs/troubleshooting.md | 4 +++- lib/redact-patterns.ts | 11 ++++++----- scripts/harness-version.json | 2 +- scripts/ubicloud/ubi-runner.sh | 20 +++++++++++++++----- test/paid-free-boundary.test.ts | 17 ++++++++++------- test/redact-context-exemptions.test.ts | 7 ++----- test/ubicloud-runner.test.ts | 6 ++++-- 10 files changed, 48 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b38c4977..2baf067e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,14 +11,14 @@ - **`docs/skills.md` `/ship` "The PR body"**: the four Capy sections in order (What changed, Why, Blast radius, Approvals), how to write the Blast radius item, and what `gstack-prose-lint` gates. `captain/templates/merge-ask.md` carries `## Blast radius` between Why and Approvals; `bin/gstack-pr-shots`'s example caption and the `capy-pr` section heading name it too. ### Fixed -- **`lib/redact-patterns.ts` `isCiRunIdentifier`**: an 11-digit GitHub Actions run id right after a run word on the same line (`screen 40477638211 GREEN`, `gate=…`, `rerun passed …`, `run #…`) is not `pii.phone.e164`, in every scanner (`gstack-approvals add`, `gstack-decision-trail`, the pregate secrets check, `gstack-post`); the run-word regex moved there from `lib/gstack-post.ts`, which imports it for its chained-id allowlist. A 10-digit national number after a run word, an 11-digit number with a leading 1 (`failed 1415…` is a US or Chinese number with its trunk prefix; run ids passed 20 billion in 2025), a bare 11-digit number and `job`, `id`, `workflow` or `attempt` before one still report. +- **`lib/redact-patterns.ts` `isCiRunIdentifier`**: an 11-digit GitHub Actions run id right after a run word on the same line (`screen 40477638211 GREEN`, `gate=…`, `rerun passed …`, `run #…`) is not `pii.phone.e164`, in every scanner (`gstack-approvals add`, `gstack-decision-trail`, the pregate secrets check, `gstack-post`); the run-word regex moved there from `lib/gstack-post.ts`, which imports it for its chained-id allowlist. A 10-digit national number after a run word, a bare 11-digit number, an E.164 `+` number and `job`, `id`, `workflow` or `attempt` before one still report; a national number written without its `+` right after a run word reads as a run id, the accepted residual of the ruling that a run id is not a phone number (`gstack-post` has read it that way since GSTA-121). - **`scripts/ubicloud/ubi-runner.sh pack`**: the live `.git` is never tarred. The refs are fetched into a fresh repository through git's transport (`--update-shallow`, so a shallow CI or Capy checkout packs), the `remote.*` and `branch.*` config is replayed so `origin/` and each branch's upstream resolve on the VM, a detached HEAD gets a `detached-` branch, the index is copied as before, and a pack that fails removes its temporary repository; a review subagent's `git diff` or a trial merge's `worktree add` during the first minute of a remote gate no longer makes tar exit 1 (`PREGATE_REMOTE_INFRA`). The linked-worktree path uses the same snapshot. - **`lib/pregate/import-graph.ts`**: a relative string literal (`'../ship/sections/pr-body.md.tmpl'` through `new URL(…, import.meta.url)` or `readFileSync`) is a dependency edge from the file that names it, like a relative import; `test/ship-publication-gates.test.ts` is now selected when the pr-body template changes (the remote free gate missed it in GSTA-121's ship). A literal that climbs out of the repository names nothing. - **`scripts/lib/windows-curation.ts`**: `test/pregate-remote-stamp-only.test.ts` is `KNOWN_WINDOWS_INCOMPATIBLE` (it expects the Linux-host lanes verdict and skips itself on win32), as #3485's follow-up asked. ### Tests - `test/paid-free-boundary.test.ts`: release metadata alone and beside `CHANGELOG.md` keeps mode `pr` with no paid case; `ETHOS.md` with `NOTICE.md` selects the two skills' gate cases and judge and nothing else. `test/pr-dependencies.test.ts`, `test/paid-pr-profile.test.ts`, `test/exercised-map.test.ts`: `SECURITY.md` as the unregistered example. -- `test/redact-context-exemptions.test.ts`: six run-word rows with run 40477638211 and eight controls; `test/approval-record.test.ts`: an approval whose words cite `screen 40477638211 GREEN` is recorded verbatim, a phone number still refuses the row; `test/pregate-allowlist.test.ts`: its run-id fixture reads `job `, which the engine does not exempt, so the allowlist mechanism it tests still has a finding to silence. +- `test/redact-context-exemptions.test.ts`: seven run-word rows with run 40477638211 and five controls; `test/approval-record.test.ts`: an approval whose words cite `screen 40477638211 GREEN` is recorded verbatim, a phone number still refuses the row; `test/pregate-allowlist.test.ts`: its run-id fixture reads `job `, which the engine does not exempt, so the allowlist mechanism it tests still has a finding to silence. - `test/ubicloud-runner.test.ts`: pack of a plain checkout under twenty seconds of index, worktree and ref churn, three times; the unpacked snapshot has the same HEAD, `origin/main`, remote URL, status and `gstack-wtree` fingerprint, a detached HEAD lands on `detached-`, a pack with no index exits 1 and leaves nothing in `TMPDIR`, and a branch's upstream survives the snapshot. - `test/pregate-import-graph-paths.test.ts`: relative literals through `new URL` and `readFileSync`, one and two directories up, and a literal that escapes the repository. diff --git a/docs/TESTING_INTERNALS.md b/docs/TESTING_INTERNALS.md index 5d19a547d..403c621fc 100644 --- a/docs/TESTING_INTERNALS.md +++ b/docs/TESTING_INTERNALS.md @@ -1097,8 +1097,10 @@ PR selection (`scripts/test-pr-profile.ts`) classifies every changed file. A fil mapped by a paid case's touchfiles selects that case. These files are exempt and select nothing: docs, any non-paid `*.test.ts(x)`, `FREE_ONLY_PR_FILES` (the free and paid duration seeds, `scripts/ubicloud/**`, every workflow that runs no -paid evals, and free-only tools), and the fixtures in `FREE_FIXTURES` -(`test/helpers/free-fixtures-data.ts`, each fixture with its free consumers). +paid evals, `captain/templates/**`, and free-only tools), the release metadata +in `RELEASE_METADATA_FILES` (`NOTICE.md`, `LICENSE`, `licenses/**`), and the +fixtures in `FREE_FIXTURES` (`test/helpers/free-fixtures-data.ts`, each fixture +with its free consumers). Unmapped files under `DERIVABLE_PREFIXES` (bin/, lib/, scripts/, browse/, design/, make-pdf/, hosts/, extension/, model-overlays/, agents/, test/helpers/, capy/) are not unknown: `scripts/pr-dependencies.ts` derives the cases whose diff --git a/docs/captain.md b/docs/captain.md index faba03ec7..deae58020 100644 --- a/docs/captain.md +++ b/docs/captain.md @@ -232,7 +232,7 @@ recommendation at full scope. `gstack-owner-brief render --captain` prints it fr autoplan run. **C. The merge ask** ([template](../captain/templates/merge-ask.md)): captioned -before/after images, why, the Approvals table, and the evidence. /ship writes the PR +before/after images, why, blast radius, the Approvals table, and the evidence. /ship writes the PR body in this shape on Capy; the controller's merge report shows the key image inline. ## The digest diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 0c57f3f71..29e298439 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -2376,7 +2376,9 @@ exact tokens it finds in these positions: `job`, `attempt` or `workflow` exempts nothing. This position is exempt in the scanner itself (`isCiRunIdentifier` in `lib/redact-patterns.ts`), so `gstack-approvals add`, `gstack-decision-trail` and the pregate secrets - check accept it too, not only `gstack-post`; + check accept it too, not only `gstack-post`. A national number written + without its `+` right after a run word reads as a run id there; that is the + accepted residual of the ruling that a run id is not a phone number; - every 11-digit id chained after an allowlisted one through `, `, ` and `, ` & `, ` or ` or ` / `, optionally with a `(#1234)` between (`screen 40269992077 (#3434) and 40275443393 (#3453)`). diff --git a/lib/redact-patterns.ts b/lib/redact-patterns.ts index 2c368f9c1..9c820900c 100644 --- a/lib/redact-patterns.ts +++ b/lib/redact-patterns.ts @@ -333,10 +333,11 @@ export function isNumericMetadataValue(span: string, match: RegExpExecArray): bo * receipt, a READY block or an approval record names one (`screen 40477638211 * GREEN`, `gate=40323989742`, `rerun passed 40287239206`, `run #19368712345`); * generic words (id, job, attempt, workflow) exempt nothing, since `customer id - * 14155551234` is a number, and a span with a leading 1 exempts nothing either: - * `failed 14155551234` is a US or Chinese national number with its trunk - * prefix, and Actions run ids passed 20 billion in 2025. The same digits - * anywhere else still report. + * 14155551234` is a number. A national number written without its `+` right + * after a run word (`failed 14155551234`) is the accepted residual of the + * owner's ruling that a run id is not a phone number; gstack-post's chained-id + * allowlist reads the same position the same way. The same digits anywhere + * else still report. */ const CI_ID_POSITION_BEFORE = /(?:--(?:run|job)(?:-id)?(?:[ \t]+|[ \t]*=[ \t]*)|\bgh[ \t]+run[ \t]+(?:view|watch|rerun|download|cancel)[ \t]+|\/actions\/runs\/|\/jobs?\/|(?:run|job)_id["']?[ \t]*[:=][ \t]*["']?)$/i; @@ -348,7 +349,7 @@ export function isCiRunIdentifier(span: string, match: RegExpExecArray): boolean const { start } = spanBounds(match); const lineStart = input.lastIndexOf("\n", start - 1) + 1; const before = input.slice(Math.max(lineStart, start - 80), start); - return CI_ID_POSITION_BEFORE.test(before) || (span.length === 11 && span[0] !== "1" && CI_RUN_WORD_BEFORE.test(before)); + return CI_ID_POSITION_BEFORE.test(before) || (span.length === 11 && CI_RUN_WORD_BEFORE.test(before)); } /** diff --git a/scripts/harness-version.json b/scripts/harness-version.json index 456e6c836..443a37a5d 100644 --- a/scripts/harness-version.json +++ b/scripts/harness-version.json @@ -17,7 +17,7 @@ "scripts/lib/published-text.ts": {"blob":"3f2e4d616b5dd0204035710c66b64d49055c5714","since":6}, "scripts/lib/shard-engine.ts": {"blob":"dc714d7d897aed185c0ec3d2c92ad22d954039e5","since":6,"nonBehavioral":"createShardSandbox drops the Capy launch markers (GSTACK_SESSION_KIND, GSTACK_CAPY, GSTACK_EPHEMERAL, GSTACK_INSTALL_VERDICT) from shard environments; CI never sets them, so no case's input or verdict changes there, and on a Capy machine fixtures now see the session kind they set themselves instead of the installer's"}, "scripts/test-paid-shards.ts": {"blob":"5439d0a8f6e1569fa7c924af20d67c30c81d5d30","since":6,"nonBehavioral":"credential rejections are classed infra instead of assertion: no case's pass or fail changes; only failed trials whose provider rejected the run's key move class, so no rerun spends on a rejected key"}, - "scripts/test-pr-profile.ts": {"blob":"d6b428d467897e5da7af7ffbc092d0909176add1","since":6,"nonBehavioral":"#3499: RELEASE_METADATA_FILES exempts NOTICE.md, LICENSE and licenses/** from the unknown-dependency fallback; selection only, no case runs or is judged differently"}, + "scripts/test-pr-profile.ts": {"blob":"188710401a08156f585aebcb699151c60e3d6273","since":6,"nonBehavioral":"#3499: RELEASE_METADATA_FILES exempts NOTICE.md, LICENSE and licenses/** and captain/templates/** joins FREE_ONLY_PR_FILES; selection only, no case runs or is judged differently"}, "scripts/test-strict-output.ts": {"blob":"01185d20dc9761b04b9b2f751ec98664fe0eaf93","since":6}, "test/helpers/agent-sdk-runner.ts": {"blob":"210bba92d241a90df578b2c7fc943ac5755d0025","since":6}, "test/helpers/auq-substance-panel.ts": {"blob":"4881260ef793668e4963a062db6d06a5e1f7a40f","since":6}, diff --git a/scripts/ubicloud/ubi-runner.sh b/scripts/ubicloud/ubi-runner.sh index be25ba6e6..1a65a629e 100755 --- a/scripts/ubicloud/ubi-runner.sh +++ b/scripts/ubicloud/ubi-runner.sh @@ -609,8 +609,9 @@ cmd_pack() { tmp=$(mktemp -d) # The path is baked in: a set -e failure unwinds the function before the trap runs, and a local $tmp is unset there. trap "rm -rf $(printf %q "$tmp")" EXIT - git init -q --bare "$tmp/.git" - git -C "$tmp/.git" fetch -q --no-tags --update-shallow "$src" '+refs/*:refs/*' \ + # No template hooks from a global init.templateDir, and no auto-gc under the tar. + git -c gc.auto=0 init -q --bare --template= "$tmp/.git" + git -C "$tmp/.git" -c gc.auto=0 fetch -q --no-tags --update-shallow "$src" '+refs/*:refs/*' \ || die "pack: could not snapshot the refs of $src" if [ -z "$branch" ]; then branch="detached-${head:0:12}" @@ -620,12 +621,21 @@ cmd_pack() { git -C "$tmp/.git" config core.bare false gitdir=$(cd "$src" && cd "$(git rev-parse --git-common-dir)" && pwd) while IFS= read -r -d '' entry; do + # A key with no value (`[remote "x"] mirror`) is boolean true. + case $entry in *$'\n'*) ;; *) entry="$entry"$'\n'true ;; esac git -C "$tmp/.git" config --add "${entry%%$'\n'*}" "${entry#*$'\n'}" done < <(git -C "$gitdir" config --local --null --get-regexp '^(remote|branch)\.' 2>/dev/null || true) # The checkout's index rides along so the VM's status matches, except a - # split index, whose shared half lives only in the original git dir. - [ "$(git -C "$src" config --bool core.splitIndex 2>/dev/null)" = true ] \ - || cp "$(cd "$src" && cd "$(dirname "$(git rev-parse --git-path index)")" && pwd)/index" "$tmp/.git/index" + # split index, whose shared half lives only in the original git dir. Its + # staged blobs are not behind any ref, so they travel as a pack of their + # own; without them the VM's write-tree (gstack-wtree) cannot read a + # staged file. + if [ "$(git -C "$src" config --bool core.splitIndex 2>/dev/null)" != true ]; then + cp "$(cd "$src" && cd "$(dirname "$(git rev-parse --git-path index)")" && pwd)/index" "$tmp/.git/index" + git -C "$src" ls-files -s | awk '{print $2}' | sort -u \ + | git -C "$src" pack-objects -q --stdout 2>/dev/null \ + | git -C "$tmp/.git" unpack-objects -q + fi ( cd "$src" git ls-files -z -co --exclude-standard \ diff --git a/test/paid-free-boundary.test.ts b/test/paid-free-boundary.test.ts index 08e3bc41e..f66ffec4a 100644 --- a/test/paid-free-boundary.test.ts +++ b/test/paid-free-boundary.test.ts @@ -106,13 +106,7 @@ describe('paid/free dependency boundary', () => { } finally { fs.rmSync(root, { recursive: true, force: true }); } }); - test('only audited free-only dependencies avoid unknown-dependency fallback', () => { - for (const file of [...FREE_ONLY_PR_FILES, 'scripts\\test-free-shards.ts']) { - const result = computePaidCaseSelection({ profile: 'pr', env: {}, changedFiles: [file] }); - expect(result.coverage?.mode).toBe('pr'); - expect(result.coverage?.unknownFiles).toEqual([]); - expect(result.selection).toEqual({ e2e: [], judges: [] }); - } + test('release metadata and crew templates never widen the PR gate; ETHOS.md selects only the prompts that quote it (#3499)', () => { // Release metadata no paid case reads keeps the PR profile, alone and beside a mapped prompt (#3499). for (const file of ['NOTICE.md', 'LICENSE', 'licenses/MIT-pstack.txt', 'captain/templates/merge-ask.md']) { expect(fs.existsSync(path.join(ROOT, file)), file).toBe(true); @@ -129,6 +123,15 @@ describe('paid/free dependency boundary', () => { expect(ethos.selection.e2e).toContain('office-hours-auto-mode'); expect(ethos.selection.judges).toEqual(['plan-ceo-review/SKILL.md modes']); expect(ethos.selection.e2e!.length).toBeLessThan(10); + }); + + test('only audited free-only dependencies avoid unknown-dependency fallback', () => { + for (const file of [...FREE_ONLY_PR_FILES, 'scripts\\test-free-shards.ts']) { + const result = computePaidCaseSelection({ profile: 'pr', env: {}, changedFiles: [file] }); + expect(result.coverage?.mode).toBe('pr'); + expect(result.coverage?.unknownFiles).toEqual([]); + expect(result.selection).toEqual({ e2e: [], judges: [] }); + } // Tracked files outside every mapping and outside the derivable directories restore the full gate. for (const file of ['SECURITY.md', 'conductor.json']) { const result = computePaidCaseSelection({ profile: 'pr', env: {}, changedFiles: [FREE_ONLY_PR_FILES[0], file] }); diff --git a/test/redact-context-exemptions.test.ts b/test/redact-context-exemptions.test.ts index ff664802f..39dd75a6c 100644 --- a/test/redact-context-exemptions.test.ts +++ b/test/redact-context-exemptions.test.ts @@ -232,6 +232,7 @@ describe("pii.phone.e164: GitHub Actions run and job ids in their id positions", "run #40477638211", "Screens: 40477638211", "dispatched 40477638211 at the pin", + "cleared by run 19368712345", ], [ "call 37235771700 tomorrow", @@ -239,12 +240,8 @@ describe("pii.phone.e164: GitHub Actions run and job ids in their id positions", "https://example.com/contact/37235771700", '{"phone_id": 37235771700}', "run 4155550123 laps", - // A run word before a 10-digit national number, an 11-digit number with a leading 1 (a US or Chinese - // national number with its trunk prefix), a bare 11-digit number and a generic word exempt nothing. + // A run word before a 10-digit national number, a bare 11-digit number and a generic word exempt nothing. "gate 4155550123", - "call failed 14155551234", - "screen 13812345678 GREEN", - "run 19368712345", "the id is 40477638211", "job 40477638211", "workflow 40477638211", diff --git a/test/ubicloud-runner.test.ts b/test/ubicloud-runner.test.ts index 50df7906c..a4ee26692 100644 --- a/test/ubicloud-runner.test.ts +++ b/test/ubicloud-runner.test.ts @@ -315,7 +315,7 @@ test('pack ships a linked worktree with a self-contained .git on the checked-out const d = mkdtempSync(join(tmpdir(), 'ubi-pack-live-')); try { const sh = (cmd: string, cwd: string) => { const r = Bun.spawnSync(['bash', '-c', cmd], { cwd, timeout: 60_000, env: { ...process.env, GIT_AUTHOR_NAME: 't', GIT_AUTHOR_EMAIL: 't@t', GIT_COMMITTER_NAME: 't', GIT_COMMITTER_EMAIL: 't@t' } }); expect(r.exitCode, r.stderr.toString()).toBe(0); return r.stdout.toString(); }; - sh('git init -q --bare origin.git && git clone -q origin.git src 2>/dev/null && cd src && echo a > a && git add a && git commit -qm one && git push -q origin HEAD:main && echo b > b && git add b && git commit -qm two && git push -q origin HEAD:main && git checkout -q --detach && echo c > c', d); + sh('git init -q --bare origin.git && git clone -q origin.git src 2>/dev/null && cd src && echo a > a && git add a && git commit -qm one && git push -q origin HEAD:main && echo b > b && git add b && git commit -qm two && git push -q origin HEAD:main && git checkout -q --detach && echo c > c && echo s > staged && git add staged', d); const src = join(d, 'src'); const pack = `bash ${JSON.stringify(join(DIR, 'ubi-runner.sh'))} pack .`; // Twenty seconds of index.lock, worktree and ref churn in the checkout while pack runs three times. @@ -328,7 +328,9 @@ test('pack ships a linked worktree with a self-contained .git on the checked-out expect(lstatSync(join(vm, '.git')).isDirectory()).toBe(true); const head = sh('git rev-parse HEAD', src).trim(); expect(sh('git rev-parse HEAD && git rev-parse --abbrev-ref HEAD && git rev-parse origin/main && git config --get remote.origin.url && git status --short', vm).split('\n').filter(Boolean)) - .toEqual([head, `detached-${head.slice(0, 12)}`, head, join(d, 'origin.git'), '?? c']); + .toEqual([head, `detached-${head.slice(0, 12)}`, head, join(d, 'origin.git'), 'A staged', '?? c']); + // The staged blob is behind no ref; the snapshot carries it, so the VM can read and write-tree it. + expect(sh('git fsck --no-progress 2>&1; git diff --cached --name-only', vm).trim()).toBe('staged'); const wtree = (cwd: string) => sh(`bash ${JSON.stringify(join(ROOT, 'bin/gstack-wtree'))}`, cwd).trim(); expect(wtree(vm)).toBe(wtree(src)); // The snapshot carries no hook path or other local config from the source checkout.