Ship policy can mark published data as content, so /ship can review large data PRs (GST-3158) (#4511)

A repo can now list published-data folders under a new
`review_content_patterns` ship-policy key, so /ship leaves `.patch`
diffs, `MANIFEST.sha256` and extension-less licences out of review,
while source files there stay reviewed.

Why: gstack-evals #352 is 13.8 MB, 13.6 MB of it published session data,
and could never pass /ship's 2 MB review limit.

Nothing to do until a repo adds the key to its base-branch policy; a
pattern that keeps too many files now stops with
`REVIEW_EXCLUDE_KEEP_TOO_LARGE` instead of being dropped.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/red-team#2 reader=red-team
Review-Finding: p2full/red-team#1 reader=red-team
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-19 09:02:33 +00:00
1 parent c25390daa2
commit f13dbb0d4a
11 files changed
+340 -48

No files matched your search

+1
View File
@@ -371,6 +371,7 @@ gstack_result_anchor() {
PR_WAIT_REFUSED) printf '%s' 'pr-wait-refused' ;;
PREGATE_HEAD_POLICY_LOOSENS) printf '%s' 'pregate-head-policy-loosens' ;;
REVIEW_DIFF_TOO_LARGE) printf '%s' 'review-diff-too-large' ;;
REVIEW_EXCLUDE_KEEP_TOO_LARGE) printf '%s' 'review-exclude-keep-too-large' ;;
REVIEW_DIFF_UNREADABLE) printf '%s' 'review-diff-unreadable' ;;
REVIEW_PLAN_STOPPED) printf '%s' 'review-plan-stopped' ;;
REVIEW_EXCLUDE_REFERENCE) printf '%s' 'review-exclude-reference' ;;
@@ -0,0 +1,6 @@
---
important: blocker
---
- **/ship can now review results PRs that publish raw session data.** A repo's ship policy can list folders under a new key, `review_content_patterns`, next to `review_exclude_paths`. A file both keys match counts as data whatever its name, so /ship's reviewers leave it out, the same way they already leave out JSON, CSV, logs and images. Source files in that folder (`.ts`, `.py`, `.sh` and the like, in any letter case) still get reviewed. Before this, files such as `.patch` diffs, a `MANIFEST.sha256` and licence texts with no extension always counted as code, so a folder of them could never be left out, and a PR like gstack-evals #352 (13.8 MB, of which 13.6 MB is published session data) could not get under /ship's 2 MB review limit. Nothing is guessed: only a pattern on the base branch counts, a content pattern on its own excludes nothing, and the secrets scan and the sealed-output guard still read every excluded file. Details: docs/ship-policy.md#review-content-patterns.
**Also fixed:** when a `review_exclude_paths` pattern kept too many files for the reviewers' read command (more than 24,000 bytes of file names), /ship quietly dropped the whole pattern and sent the folder to the reviewers anyway. It now stops before review with `REVIEW_EXCLUDE_KEEP_TOO_LARGE`, naming the pattern, how many files it keeps and why, and the fix (docs/troubleshooting.md#review-exclude-keep-too-large).
+56 -2
View File
@@ -74,6 +74,7 @@ branch that changes the policy.
| `full_e2e` | `true` \| `false` | `false` | `true`: every merge needs a passing full-gate result bound to a tree equal to the merging one modulo stamps; `gstack-ship-queue ready`, `stamp` and `verify` refuse without one (`QUEUE_GATE_MISSING`): a gate-ahead record, or the lane's `--gate-exit 0 --gate-log <file>` from its run on the gated head. Needs `min_gstack_version`. |
| `review_scope` | `frozen` \| `diff-plus-blocking` \| `all` | `frozen` | The finding scope of `/ship`'s review loop; see [review_scope](#review-scope). `frozen` fixes the diff on pass 1, lists blocking findings in unchanged code as deferred in the PR body (never as issues), and later passes read only the range since the previous pass. `diff-plus-blocking` is the same but fixes a blocking finding in unchanged code in this PR instead of deferring it. `all` is the earlier loop: every finding is fixed on every pass. Needs `min_gstack_version` when not `frozen`. |
| `review_exclude_paths` | git glob pathspecs | `[]` | Content files `/ship`'s reviewers leave out: data, docs, `.log`, and binaries under a content extension (images, fonts, archives and the like) that do not start with executable magic. Read from the base only. Code (native libraries and every other binary outside the content extensions included), gate paths, agent prose, config, executables, links, `.gstack/` and `.github/` files, gate-tagged, secret-line and named-by-code files stay in review. See [review_exclude_paths](#review-exclude-paths). Needs `min_gstack_version`. |
| `review_content_patterns` | git glob pathspecs | `[]` | Files that `review_exclude_paths` also matches and that count as content whatever their extension (`.patch` files, `MANIFEST.sha256`, extension-less licence texts), so the exclusion leaves them out. Explicit policy only; a pattern here with no `review_exclude_paths` pattern over the same files excludes nothing. Read from the base only. See [review_content_patterns](#review-content-patterns). Needs `min_gstack_version`. |
| `review` | `{ panel?, reader_model?, platform?, risk_paths? }` | `{ all, lane, off, [] }` | Who does `/ship`'s review, read from the base only; see [Who reads](review-policy.md#who-reads-r65-the-base-policys-review-key). `panel`: `all` (today's panel on every class) \| `risk` \| `off` (the opt-in one-reader shapes); `reader_model`: `lane`, `cross-family` or a model id; `platform`: `off` \| `on` (a docs or tests diff with no numeric, results or prereg claims whose PR carries capy-ai[bot]'s review at the exact head skips the readers); `risk_paths`: globs of code paths that count as risk class `policy`. Introduced at 1.94.30.0; needs `min_gstack_version` when set to a non-default value. |
| `readers` | `{ forbid_fetch?, forbid_paths?, brief_note? }` | `{ [], [], null }` | What `/ship`'s readers may not reach beyond the fetch rule every brief carries; see [readers](#readers). Read from the base; the head may add `forbid_fetch` entries, never remove one. Needs `min_gstack_version`. |
| `min_gstack_version` | version or `null` | `null` | The oldest gstack that may read the file; see the compatibility rule above. |
@@ -1518,8 +1519,11 @@ kept files under an applied pattern come back through a second command,
`DIFF_KEEP: <reader> git diff <diff-base> -- ':(top,literal)<path>' …`, which every
brief names. That command is bounded by its argument bytes (24,000 across all
patterns, under Windows' command-line limit): a pattern whose kept files would
pass the bound is not applied, and the plan line says so as
`skipped=<pattern>:kept=<n>:bytes=<b>`. Files that reach readers as
pass the bound stops the plan with
[`REVIEW_EXCLUDE_KEEP_TOO_LARGE`](troubleshooting.md#review-exclude-keep-too-large),
which names the pattern, the kept count and why they are kept. A pattern is
never dropped quietly: before GST-3158 it was left out with only a `skipped=`
note, and the whole folder went to readers. Files that reach readers as
[secret-line excerpts](#secret-line-excerpts) are not on that command, so they
do not count toward the bound, and gstack reads them in git calls of at most
24,000 argument bytes each (GST-1967). Every brief also gets one line:
@@ -1527,6 +1531,56 @@ do not count toward the bound, and gstack reads them in git calls of at most
on this branch matching <patterns>. They are not in your diff; do not report on
their absence.`
<a id="review-content-patterns"></a>
### `review_content_patterns`: published data with code-shaped names
`review_exclude_paths` leaves out only files gstack recognizes as content by
their names. Some published data looks like code to it: a `.patch` file, a
`MANIFEST.sha256`, a licence text with no extension. Those files are kept as
`code`, so a folder full of them can't be excluded however the pattern is
written. `review_content_patterns` is the policy saying "these are data":
```json
{
"review_exclude_paths": ["results/*/sessions/**"],
"review_content_patterns": ["results/*/sessions/**"],
"min_gstack_version": "<the release that introduced review_content_patterns>"
}
```
**Example.** gstack-evals' head-to-head results PR (#352) had a 13.8 MB diff,
13.6 MB of it published session data in one folder: 1,319 `.patch` files, a
`licences/` folder of extension-less files and a `MANIFEST.sha256`. With only
`review_exclude_paths`, all 1,439 files were kept as code and the PR could not
pass the 2 MB review ceiling. With the same folder in `review_content_patterns`
too, `gstack-review-plan` excludes the folder and readers get the ~540 KB of
code the PR actually changes.
How it works:
- **Both keys must match.** A file is declared content only when a
`review_exclude_paths` pattern and a `review_content_patterns` pattern both
match it. A content pattern on its own excludes nothing. Both use the same
git glob dialect (`:(top,glob)` pathspecs).
- **Explicit only.** gstack never guesses that a file is data. The policy PR
that adds the pattern to the base branch is the reviewed act.
- **Read from the base only**, the same way as `review_exclude_paths`: a branch
that adds or widens the key changes nothing until it lands on the base.
- **The other keep rules still apply.** A declared file is still kept when it
is under `.gstack/` or `.github/`, a gate path, executable, a link, agent
prose, a config file, a source file (`.ts`, `.js`, `.py`, `.rb`, `.sh`, `.go`,
`.rs`, `.dart` and the like), gate-tagged, holds a secret line, or is named by full
path from kept code. A binary declared file is content unless its bytes start
with executable magic or it is a source file (the extension check ignores
case). A declared non-source file is never a consumer for the named-by-code
scan; a source file kept there is.
- **Excluded from review, not from the guards.** The secrets scan and the
sealed-output guard read every changed file, excluded ones included
(`test/review-content-patterns.test.ts`).
Excluded declared files count as `declared:<n>` in the `REVIEW_EXCLUDE:` line's
`content=` field.
<a id="secret-line-excerpts"></a>
**Secret-line excerpts (GST-1447).** A kept file whose only reason is
`secret-line` (under an applied pattern, not named by code, with the gate scan
+28 -5
View File
@@ -4077,18 +4077,41 @@ the base policy commit.
the base into the branch and rerun once; if it is still over, split the PR.
- **The branch declares the key but the base does not:** only the base copy
applies; land that hunk on the base first, as above.
- **A pattern was not applied** (`skipped=` on the `REVIEW_EXCLUDE:` line): its kept
files need more than 24,000 argument bytes on the reader's keep command (files
kept only for a secret line are excerpted and do not count). Narrow the
pattern, move the kept files out of it, or split the PR.
- **A pattern keeps too many files** stops the plan with
[`REVIEW_EXCLUDE_KEEP_TOO_LARGE`](#review-exclude-keep-too-large) before any reader runs.
- **Still over after exclusion:** add the printed folders to the base policy, or
split the PR. Files kept only for a secret line already count as their
split the PR. When published data under a pattern is kept as `code`
(`REVIEW_EXCLUDE_KEPT: code …` on `.patch`, `.sha256` or extension-less files),
add [`review_content_patterns`](ship-policy.md#review-content-patterns) for it. Files kept only for a secret line already count as their
excerpts ([secret-line excerpts](ship-policy.md#secret-line-excerpts)); one in
`DIFF_KEEP:` is kept for another reason, and one the excerpt could not be
built for moves to the reader's keep command and counts whole.
There is no override flag. See [the review ceiling](ship-policy.md#review-diff-ceiling).
<a id="review-exclude-keep-too-large"></a>
### `REVIEW_EXCLUDE_KEEP_TOO_LARGE`
**Meaning.** A `review_exclude_paths` pattern on the base matches files review
must keep, and so many of them that the command readers run to read them
(`DIFF_KEEP:`) would pass 24,000 argument bytes, under Windows' command-line
limit. `gstack-review-plan` stops (exit 3, nothing planned) instead of dropping
the pattern and handing readers the whole folder. The line names the pattern,
the base commit, the kept count with each keep reason
(`code:1319,named-by-code:2`) and the bytes.
**Fix.** Look at the reasons:
- **`code` on published data** (`.patch` files, `MANIFEST.sha256`,
extension-less licence texts): add the same folder to
[`review_content_patterns`](ship-policy.md#review-content-patterns) beside the
pattern on the base, as its own PR. Once it merges, bring the base into the
branch and rerun once.
- **Real code or another keep reason:** narrow the pattern so it covers only
the data, or split the PR.
There is no override flag.
<a id="review-diff-unreadable"></a>
### `REVIEW_DIFF_UNREADABLE`
+6 -1
View File
@@ -594,7 +594,12 @@ export const RELEASE_RESULT_CODES = {
REVIEW_DIFF_TOO_LARGE: {
anchor: 'review-diff-too-large',
summary: 'one reviewer\'s diff is over the 2,000,000-byte review ceiling, so /ship stopped before writing a manifest or a brief instead of handing a reader more than it can read',
fix: 'follow the fix the line prints for where the base policy stands: land the printed review_exclude_paths JSON on the base as its own PR, then bring the base into the branch and rerun once; or narrow a pattern the kept-file bound skipped; or split the PR',
fix: 'follow the fix the line prints for where the base policy stands: land the printed review_exclude_paths JSON on the base as its own PR, then bring the base into the branch and rerun once; or split the PR',
},
REVIEW_EXCLUDE_KEEP_TOO_LARGE: {
anchor: 'review-exclude-keep-too-large',
summary: 'a review_exclude_paths pattern keeps so many matched files in review that the command readers run to read them would pass 24,000 argument bytes, so gstack-review-plan stopped instead of silently dropping the pattern; the line names the pattern, the kept count, the reasons they are kept and the bytes',
fix: 'when the kept files are published data (reason code on .patch, MANIFEST.sha256 or extension-less files), land a review_content_patterns entry over them beside the pattern on the base as its own PR, then bring the base into the branch and rerun once; otherwise narrow the pattern or split the PR',
},
REVIEW_DIFF_UNREADABLE: {
anchor: 'review-diff-unreadable',
+55 -20
View File
@@ -11,7 +11,9 @@
* stable reason. Applied patterns become `:(top,exclude,glob)` pathspecs on every reader,
* and kept files under them come back through a second `:(top,literal)` command, because a
* git exclude beats any positive pathspec. That second command is bounded by its argument
* bytes: a pattern whose kept files would pass KEEP_ARG_MAX_BYTES on it is not applied.
* bytes: a pattern whose kept files would pass KEEP_ARG_MAX_BYTES on it refuses the plan
* (REVIEW_EXCLUDE_KEEP_TOO_LARGE) instead of being dropped (GST-3158). A file the base policy's
* review_content_patterns also matches is content whatever its extension, unless it is a source file (SOURCE_EXT, any case): the policy says so.
*
* A file kept only for a secret line (a line that names a credential and carries a value, secretValueLine;
* no other reason, under an applied pattern, gate scan and consumer scan both read) is also listed in `excerpt`: pass readers
@@ -29,6 +31,7 @@ import * as os from 'node:os';
import * as path from 'node:path';
import { collectLive } from './review-collect';
import { DATA_PATH, classifyPath, isAgentProse, isDataConfig, isGatePath, type PathLines } from './review-depth';
import { SOURCE_EXT } from './pregate/import-graph';
import { scan } from './redact-engine';
import { shannonEntropy } from './redact-patterns';
import { KEY_NAME, SECRET_LINE, secretPath } from './review-risk';
@@ -51,7 +54,7 @@ export type KeptReason = (typeof KEPT_REASONS)[number];
/** What the receipt records and the queue and carry compare (by `digest`, never by `source`). */
export interface ExcludeRecord {
source: string; patterns: string[]; applied: string[]; skipped: Array<{ pattern: string; kept: number; bytes: number }>; unmatched: string[];
source: string; patterns: string[]; applied: string[]; unmatched: string[];
excluded: number; excluded_bytes: number; kept: number; gate_tagged: string[]; patterns_sha256: string; list_sha256: string; digest: string;
}
export interface ActiveExclusion {
@@ -63,7 +66,7 @@ export interface ActiveExclusion {
export type Exclusion =
| { state: 'none' }
| { state: 'head-only'; patterns: string[]; source: string }
| { state: 'refused'; code: 'POLICY_SOURCE_UNAVAILABLE' | 'POLICY_INVALID' | 'REVIEW_DIFF_UNREADABLE'; lines: string[] }
| { state: 'refused'; code: 'POLICY_SOURCE_UNAVAILABLE' | 'POLICY_INVALID' | 'REVIEW_DIFF_UNREADABLE' | 'REVIEW_EXCLUDE_KEEP_TOO_LARGE'; lines: string[] }
| ActiveExclusion;
export interface ExcludeInput {
@@ -256,15 +259,44 @@ function attributeBinaryLines(i: ExcludeInput, paths: readonly string[], unread:
}
/** The kind of content a path holds when the policy may exclude it, or null for code (tests included). */
export type ContentKind = 'binary' | 'data' | 'docs' | 'log';
/** One range's input with the matched files a pattern names by their file name (its last segment, with no glob character): a config name there is data. */
type Scope = ExcludeInput & { named?: ReadonlySet<string> };
export type ContentKind = 'binary' | 'data' | 'docs' | 'log' | 'declared';
/**
* One range's input with the matched files a pattern names by their file name (its last segment, with no glob character): a
* config name there is data; and the files a review_exclude_paths and a review_content_patterns pattern both match, which
* the base policy declares content.
*/
type Scope = ExcludeInput & { named?: ReadonlySet<string>; declared?: ReadonlySet<string> };
const config = (i: Scope, p: string) => isDataConfig(p) && !i.named?.has(p);
const SOURCE = new RegExp(SOURCE_EXT.source, 'i');
function contentKind(i: Scope, p: string, binary: ReadonlySet<string>): ContentKind | null {
if (binary.has(p)) return 'binary';
if (DATA_PATH.test(p) && !config(i, p)) return 'data';
if (/\.log$/i.test(p)) return 'log';
return classifyPath(p, i.classRoot) === 'docs' ? 'docs' : null;
if (classifyPath(p, i.classRoot) === 'docs') return 'docs';
return i.declared?.has(p) && !SOURCE.test(p) ? 'declared' : null;
}
/**
* The files at the head (the index on a live tree) and at the merge base that a review_exclude_paths pattern and a
* review_content_patterns pattern both match, listed by git under the same `:(top,glob)` pathspecs; null when git cannot
* list them. Whole trees, not only the range: a declared file the branch did not change is no consumer either.
*/
function declaredContent(i: ExcludeInput, patterns: readonly string[], content: readonly string[]): Set<string> | null {
const out = new Set<string>();
if (!content.length) return out;
const empty = git(i.root, ['hash-object', '-t', 'tree', '--stdin'], '');
if (!empty.ok) return null;
const list = (rev: string, specs: readonly string[]) => {
const r = git(i.root, [...(rev ? ['diff', '--name-only', '-z', '--no-renames', empty.out.trim(), rev] : ['ls-files', '-z']), '--', ...specs.map(p => `:(top,glob)${p}`)]);
return r.ok ? new Set(r.out.split('\0').filter(Boolean)) : null;
};
for (const rev of [i.head ?? '', i.mergeBase]) {
const matched = list(rev, patterns);
const declared = list(rev, content);
if (!matched || !declared) return null;
for (const f of matched) if (declared.has(f)) out.add(f);
}
return out;
}
/**
@@ -281,7 +313,7 @@ function pathReason(i: Scope, p: string, m: Matched, binary: ReadonlySet<string>
if (m.oldMode === '100755' || m.newMode === '100755') return 'executable';
if ([m.oldMode, m.newMode].some(x => x === '120000' || x === '160000')) return 'link';
if (i.gateTagged?.has(p)) return 'gate-tagged';
if (binary.has(p)) return BINARY_CONTENT_EXT.test(p) && !native.has(p) ? null : 'code';
if (binary.has(p)) return (BINARY_CONTENT_EXT.test(p) || (i.declared?.has(p) && !SOURCE.test(p))) && !native.has(p) ? null : 'code';
if (isAgentProse(p)) return 'agent-prose';
if (config(i, p)) return 'config';
if (contentKind(i, p, binary) === null) return 'code';
@@ -364,12 +396,14 @@ export function reviewExclude(i: ExcludeInput): Exclusion {
if (!patterns.length) { const head = headPatterns(i); return head.length ? { state: 'head-only', patterns: head, source } : { state: 'none' }; }
const sel = select(i, patterns);
if ('error' in sel) return { state: 'refused', code: 'REVIEW_DIFF_UNREADABLE', lines: [`${i.context}: git could not list the files review_exclude_paths matches (${sel.error}); fix: git fetch origin ${base}, then rerun once; nothing was planned (REVIEW_DIFF_UNREADABLE)`] };
const declared = declaredContent(i, patterns, load.policy.review_content_patterns);
if (!declared) return { state: 'refused', code: 'REVIEW_DIFF_UNREADABLE', lines: [`${i.context}: git could not list the files review_content_patterns matches; fix: git fetch origin ${base}, then rerun once; nothing was planned (REVIEW_DIFF_UNREADABLE)`] };
const unread = new Set<string>();
const native = new Set<string>();
const claimed = i.perPath.filter(e => e.binary && sel.files.has(e.path)).map(e => e.path);
const binary = binaryContent(i, sel.files, new Set([...claimed, ...(bytesBinary(i, patterns) ?? sel.files.keys())]), unread, native);
const fileName = (s: string) => s.slice(s.lastIndexOf('/') + 1);
const x: Scope = { ...i, named: new Set(patterns.flatMap(q => /[*?[\\]/.test(fileName(q)) ? [] : (sel.byPattern.get(q) ?? []).filter(f => fileName(f) === fileName(q)))) };
const x: Scope = { ...i, declared, named: new Set(patterns.flatMap(q => /[*?[\\]/.test(fileName(q)) ? [] : (sel.byPattern.get(q) ?? []).filter(f => fileName(f) === fileName(q)))) };
const text = { ...x, added: { ...i.added, ...attributeBinaryLines(i, claimed.filter(p => !binary.has(p) && !unread.has(p)), unread) } };
const collected = new Map(i.perPath.map(e => [e.path, e]));
const unseen = (p: string) => { const e = collected.get(p); return !e || (!e.binary && e.lines > 0 && !(p in text.added)); };
@@ -385,14 +419,18 @@ export function reviewExclude(i: ExcludeInput): Exclusion {
}
const excerptable = new Set(i.gateTagged === null || named === null ? [] : secretOnly.filter(p => !named.has(p)));
const applied: string[] = [];
const skipped: ExcludeRecord['skipped'] = [];
const keep = new Set<string>();
for (const p of patterns) {
const hit = sel.byPattern.get(p) ?? [];
if (!hit.some(f => reasons.get(f) === null)) continue;
const kept = hit.filter(f => reasons.get(f) !== null);
const bytes = argBytes([...new Set([...keep, ...kept])].filter(f => !excerptable.has(f)));
if (bytes > KEEP_ARG_MAX_BYTES) { skipped.push({ pattern: p, kept: kept.length, bytes }); continue; }
if (bytes > KEEP_ARG_MAX_BYTES) {
const why = new Map<string, number>();
for (const f of kept) why.set(reasons.get(f)!, (why.get(reasons.get(f)!) ?? 0) + 1);
const top = [...why].sort((a, b) => b[1] - a[1]).map(([r, n]) => `${r}:${n}`).join(',');
return { state: 'refused', code: 'REVIEW_EXCLUDE_KEEP_TOO_LARGE', lines: [`${i.context}: review_exclude_paths pattern ${p} on ${source} keeps ${kept.length} matched files in review (${top}), and the command readers run to read them would need ${bytes} argument bytes (more than ${KEEP_ARG_MAX_BYTES}), so the pattern cannot be applied and is not dropped either; fix: when those files are published data, add a review_content_patterns entry for them beside the pattern on ${base} as its own PR (docs/ship-policy.md#review-content-patterns), else narrow the pattern or split the PR; nothing was planned (REVIEW_EXCLUDE_KEEP_TOO_LARGE)`] };
}
applied.push(p);
for (const f of kept) keep.add(f);
}
@@ -400,14 +438,14 @@ export function reviewExclude(i: ExcludeInput): Exclusion {
const excerpt = [...excerptable].filter(p => keep.has(p)).sort();
const keptList = [...reasons].filter(([, r]) => r !== null).map(([p, r]) => ({ path: p, reason: r! })).sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
const sortedExcluded = [...excluded].sort();
const content: Record<ContentKind, number> = { binary: 0, data: 0, docs: 0, log: 0 };
const content: Record<ContentKind, number> = { binary: 0, data: 0, docs: 0, log: 0, declared: 0 };
for (const p of sortedExcluded) content[contentKind(x, p, binary)!]++;
const prefixes = [...new Set(applied.map(literalPrefix).filter(Boolean))];
const refs = grepFixed(x, prefixes, excluded, []) ?? new Map<string, Set<string>>();
const patterns_sha256 = sha256(JSON.stringify(patterns));
const list_sha256 = sha256(JSON.stringify({ applied, excluded: sortedExcluded, kept: keptList.map(k => [k.path, k.reason]) }));
const record: ExcludeRecord = {
source, patterns: [...patterns], applied, skipped, unmatched: patterns.filter(p => !(sel.byPattern.get(p) ?? []).length),
source, patterns: [...patterns], applied, unmatched: patterns.filter(p => !(sel.byPattern.get(p) ?? []).length),
excluded: excluded.size, excluded_bytes: excludedBytes(i, sortedExcluded, sel.files), kept: keptList.length,
gate_tagged: keptList.filter(k => k.reason === 'gate-tagged').map(k => k.path), patterns_sha256, list_sha256, digest: sha256(`${patterns_sha256}\n${list_sha256}`),
};
@@ -431,8 +469,7 @@ export function excludeLines(x: Exclusion, base: string): string[] {
if (x.state === 'none' || x.state === 'refused') return [];
if (x.state === 'head-only') return [`REVIEW_EXCLUDE: none (head sets review_exclude_paths; it applies after it lands on ${base}) patterns=${x.patterns.length} source=${x.source}`];
const r = x.record;
const skipped = r.skipped.length ? ` skipped=${r.skipped.map(s => `${s.pattern}:kept=${s.kept}:bytes=${s.bytes}`).join(',')} (kept files over ${KEEP_ARG_MAX_BYTES} argument bytes: pattern not applied)` : '';
const out = [`REVIEW_EXCLUDE: patterns=${r.applied.length}/${r.patterns.length} excluded=${r.excluded} bytes=${r.excluded_bytes} kept=${r.kept} content=${Object.entries(x.content).filter(([, n]) => n).map(([k, n]) => `${k}:${n}`).join(',') || 'none'} source=${r.source} digest=${r.digest}${skipped}${r.unmatched.length ? ` unmatched=${r.unmatched.join(',')}` : ''}`];
const out = [`REVIEW_EXCLUDE: patterns=${r.applied.length}/${r.patterns.length} excluded=${r.excluded} bytes=${r.excluded_bytes} kept=${r.kept} content=${Object.entries(x.content).filter(([, n]) => n).map(([k, n]) => `${k}:${n}`).join(',') || 'none'} source=${r.source} digest=${r.digest}${r.unmatched.length ? ` unmatched=${r.unmatched.join(',')}` : ''}`];
for (const k of x.kept.slice(0, 20)) out.push(`REVIEW_EXCLUDE_KEPT: ${k.reason} ${k.path}`);
if (x.kept.length > 20) out.push(`REVIEW_EXCLUDE_KEPT: +${x.kept.length - 20} more (gstack-review-plan --json lists every kept file)`);
if (x.excerpt.length) out.push(`REVIEW_EXCLUDE_EXCERPT: ${x.excerpt.length} kept files hold no keep reason but a secret line; gstack-review-dispatch pass gives readers their matched lines in context, not the whole files, and DIFF_KEEP leaves them out`);
@@ -507,7 +544,7 @@ export function readSelection(root: string, diffBase: string, pathspecs: readonl
export const redact = (s: string) => s.replace(/\b[a-z][a-z0-9+.-]*:\/\/[^\s'"]+/gi, '<url>').replace(/\b[\w.-]+@[\w.-]+:[^\s'"]+/g, '<url>');
/** Where the over-ceiling selection's policy stands: decides the fix the line prints. */
export interface CeilingContext { state: 'none' | 'head-only' | 'active'; base: string; source: string; floor?: string | null; headPatterns?: string[]; record?: Pick<ExcludeRecord, 'patterns' | 'skipped' | 'excluded'> }
export interface CeilingContext { state: 'none' | 'head-only' | 'active'; base: string; source: string; floor?: string | null; headPatterns?: string[]; record?: Pick<ExcludeRecord, 'patterns' | 'excluded'> }
/** The policy hunk to land, as JSON a person can paste: the patterns, and a floor at least this key's version. */
function policyJson(patterns: readonly string[], floor?: string | null): string {
@@ -533,9 +570,7 @@ export function tooLargeLine(context: string, reader: string, d: { bytes: number
const top = d.byDir.slice(0, 5).map(([dir, n]) => `${dir}:${n}`).join(',') || 'none';
const land = (patterns: readonly string[]) => `ask the repo owner to land ${policyJson(patterns, c.floor)} in ${SHIP_POLICY_PATH} on ${c.base} as its own PR (docs/ship-policy.md#review-exclude-paths), then bring ${c.base} into this branch and rerun once; if it is still over, split the PR`;
const dirs = suggest(d.byDir, d.bytes);
const s = c.record?.skipped[0];
const fix = c.state === 'head-only' ? `this branch declares review_exclude_paths, but only the copy on ${c.base} applies: ${land(c.headPatterns ?? [])}`
: s ? `pattern ${s.pattern} was not applied: its ${s.kept} kept files need ${s.bytes} argument bytes (more than ${KEEP_ARG_MAX_BYTES}); narrow the pattern on ${c.base} or move the kept files out of it, or split the PR`
: c.state === 'active' ? `still over after excluding ${c.record?.excluded ?? 0} files; ${dirs.length ? land([...(c.record?.patterns ?? []), ...dirs.filter(p => !c.record?.patterns.includes(p))]) : 'split the PR'}`
: dirs.length ? land(dirs) : 'split the PR';
const line = `${context}: the reader's diff is over the review ceiling (reader=${reader} bytes=${d.bytes} max=${REVIEW_DIFF_MAX_BYTES} top=${top} policy=${c.source}); fix: ${fix}; nothing was written (REVIEW_DIFF_TOO_LARGE)`;
@@ -554,7 +589,7 @@ export function unreadableLine(context: string, reader: string, d: Extract<Reade
}
/** The plan's review_exclude object (gstack-review-plan --json), or null for a repository without the key. */
export type PlanExclude = { state: string; patterns?: string[]; skipped?: ExcludeRecord['skipped']; excluded?: number } | null;
export type PlanExclude = { state: string; patterns?: string[]; excluded?: number } | null;
/**
* Where <base>'s policy stands for a REVIEW_DIFF_TOO_LARGE fix: the source commit, its min_gstack_version, and the exclusion
@@ -576,5 +611,5 @@ export function ceilingContext(root: string, base: string, known?: PlanExclude):
const floor = read?.policy.min_gstack_version ?? null;
if (!x) return { state: 'none', base: b, source, floor };
if (x.state === 'head-only') return { state: 'head-only', base: b, source, floor, headPatterns: x.patterns ?? [] };
return { state: 'active', base: b, source, floor, record: { patterns: x.patterns ?? [], skipped: x.skipped ?? [], excluded: x.excluded ?? 0 } };
return { state: 'active', base: b, source, floor, record: { patterns: x.patterns ?? [], excluded: x.excluded ?? 0 } };
}
+2 -1
View File
@@ -57,6 +57,7 @@ export const LAND_DOCS_ONLY_SKIP_KEY_VERSION = '1.99.0.0';
/** `history: no-rewrite` and `land.merge_commit_paths` are a value and a field of older keys, checked by value like bump: never. */
export const HISTORY_NO_REWRITE_KEY_VERSION = '1.100.0.0';
export const LAND_MERGE_COMMIT_PATHS_KEY_VERSION = '1.100.0.0';
export const REVIEW_CONTENT_KEY_VERSION = '1.102.0.0';
export const POLICY_KEY_INTRODUCED: Record<PolicyKey, string> = {
bump: '1.91.73.0', queue_mode: '1.91.73.0', release_tool: '1.91.73.0', release_outputs: '1.91.73.0', stamp_paths: '1.91.73.0',
changelog: '1.91.73.0', mirror: '1.91.73.0', history: '1.91.73.0', preregistration_shas: '1.91.73.0', stamp_sensitive_gates: '1.91.73.0',
@@ -64,7 +65,7 @@ export const POLICY_KEY_INTRODUCED: Record<PolicyKey, string> = {
migrations: '1.91.98.0', gate_command: SHIP_QUEUE_KEYS_VERSION, full_e2e: SHIP_QUEUE_KEYS_VERSION, min_gstack_version: SHIP_QUEUE_KEYS_VERSION,
train: TRAIN_KEYS_VERSION, review_scope: REVIEW_SCOPE_KEY_VERSION, docs: DOCS_CAPS_KEY_VERSION,
changelog_fragments: CHANGELOG_FRAGMENTS_KEY_VERSION,
base_red: BASE_RED_KEY_VERSION, review_exclude_paths: REVIEW_EXCLUDE_KEY_VERSION, review: REVIEW_POLICY_KEY_VERSION, release_gate: RELEASE_GATE_KEY_VERSION,
base_red: BASE_RED_KEY_VERSION, review_exclude_paths: REVIEW_EXCLUDE_KEY_VERSION, review_content_patterns: REVIEW_CONTENT_KEY_VERSION, review: REVIEW_POLICY_KEY_VERSION, release_gate: RELEASE_GATE_KEY_VERSION,
stamp_placeholders: STAMP_PLACEHOLDERS_KEY_VERSION, merge: MERGE_KEY_VERSION, land: LAND_KEY_VERSION, readers: READERS_KEY_VERSION,
bookkeeping: BOOKKEEPING_KEY_VERSION, mechanical_retake: MECHANICAL_RETAKE_KEY_VERSION, test_code: TEST_CODE_KEY_VERSION, ci_record_timeout_s: CI_RECORD_TIMEOUT_KEY_VERSION,
plan_record: PLAN_RECORD_KEY_VERSION, docs_only: DOCS_ONLY_KEY_VERSION,
+12 -6
View File
@@ -66,6 +66,8 @@ export interface ShipPolicy {
review_scope: ReviewScope;
/** Git glob pathspecs (root-anchored) whose data, docs, binary and log files /ship's reviewers leave out; read from the base only (docs/ship-policy.md#review-exclude-paths). */
review_exclude_paths: string[];
/** Git glob pathspecs (root-anchored) that mark files review_exclude_paths also matches as content, whatever their extension; read from the base only (docs/ship-policy.md#review-content-patterns). */
review_content_patterns: string[];
/** How much review /ship runs (docs/review-policy.md#review-depth): the panel fallback, the risk reader's model, platform review and extra risk paths; read from the base only. */ review: ReviewPolicy;
/** What /ship's readers may not fetch or open beyond the default fetch rule, and the one-line note every brief carries; the base governs, the head may only add (docs/ship-policy.md#readers). */ readers: ReadersPolicy;
/** Consumed by the plan reviews (D1). */
@@ -181,6 +183,7 @@ export const DEFAULT_POLICY: ShipPolicy = {
stamp_sensitive_gates: [],
review_scope: 'frozen',
review_exclude_paths: [],
review_content_patterns: [],
review: { panel: 'all', reader_model: 'lane', platform: 'off', risk_paths: [] },
pr_count: { default_pr_count: 1, split_requires_owner: true },
maintainers: [],
@@ -217,6 +220,7 @@ export const POLICY_EXPLANATIONS: Record<PolicyKey, string> = {
stamp_sensitive_gates: 'Evidence labels (gstack-evidence --label) that read VERSION or generated bytes; the tree receipt never marks them reusable.',
review_scope: 'frozen | diff-plus-blocking | all. frozen (default): /ship Step 9 fixes findings in the diff on pass 1, files blocking findings in code the PR did not change as issues, and later passes read only the range since the previous pass and fix only blocking findings; diff-plus-blocking: the same, but a blocking finding in code the PR did not change is fixed in this PR instead of filed; all: every finding is fixed now (the pre-1.91.249 loop).',
review_exclude_paths: 'Git glob pathspecs, root-anchored and case-sensitive (`receipts/**`, `**/*.jsonl`; at most 64, 256 characters each, no leading `:` or `!`): /ship\'s reviewers leave out the data, docs, binary and .log files they match. Read from the base branch only, so a branch cannot exclude its own files. Code, gate paths, agent prose, config, executables, .gstack/ and .github/ files, gate-tagged or secret-bearing files and files a kept code or test file names by full path stay reviewed (docs/ship-policy.md#review-exclude-paths).',
review_content_patterns: 'Git glob pathspecs in the same dialect as review_exclude_paths (`results/*/raw/**`): a file both keys match is content, so the exclusion leaves it out whatever its extension (.patch files, MANIFEST.sha256, extension-less licence texts). Explicit policy only: nothing is inferred, and a pattern here with no review_exclude_paths pattern over the same files excludes nothing. Read from the base branch only. Gate paths, agent prose, config, source files (.ts, .py, .sh and the like), executables, links, native binaries, .gstack/ and .github/ files, gate-tagged or secret-bearing files and files a kept code or test file names by full path stay reviewed (docs/ship-policy.md#review-content-patterns).',
review: '{ panel?, reader_model?, platform?, risk_paths? }, read from the base branch only. panel: all (default: today\'s panel and loop everywhere) | risk (opt-in: today\'s panel at full depth on risk class, one reader on the rest) | off (one merged reader on risk class too); risk and off run one fix round. Their one-reader shape has not passed a no-loss replay yet (GSTA-258 C: FIX-METHOD). reader_model: the model of the one reader a lean depth runs, `lane` (default: the lane\'s own model, the native adversarial reader), `cross-family` or a model id. platform: off (default) | on: a docs or tests diff with no numeric, results or prereg claims whose PR carries the platform review (capy-ai[bot]) at the exact head skips /ship\'s readers (review_depth platform); never runtime code. risk_paths: globs of code paths that are risk class on top of R51\'s; data, docs and binary files under them stay out (docs/review-policy.md#review-depth).',
readers: READERS_EXPLANATION,
pr_count: '{ default_pr_count, split_requires_owner }: the PR-count row in plan reviews.',
@@ -328,13 +332,13 @@ function listErrors(key: string, value: unknown, out: PolicyError[], check: (ite
});
}
/** `review_exclude_paths`: git glob pathspecs, each one repo-relative line with no pathspec magic of its own; every error is POLICY_INVALID at its index. */
function excludeErrors(value: unknown, out: PolicyError[]): void {
if (!Array.isArray(value)) { out.push({ code: 'POLICY_INVALID', path: 'review_exclude_paths', message: 'must be an array of git glob pathspecs' }); return; }
if (value.length > MAX_LIST) out.push({ code: 'POLICY_INVALID', path: 'review_exclude_paths', message: `more than ${MAX_LIST} patterns` });
/** `review_exclude_paths` and `review_content_patterns`: git glob pathspecs, each one repo-relative line with no pathspec magic of its own; every error is POLICY_INVALID at its index. */
function excludeErrors(key: 'review_exclude_paths' | 'review_content_patterns', value: unknown, out: PolicyError[]): void {
if (!Array.isArray(value)) { out.push({ code: 'POLICY_INVALID', path: key, message: 'must be an array of git glob pathspecs' }); return; }
if (value.length > MAX_LIST) out.push({ code: 'POLICY_INVALID', path: key, message: `more than ${MAX_LIST} patterns` });
value.forEach((p, i) => {
const why = typeof p !== 'string' ? 'must be a string' : containedRelative(p) ?? (/^[:!]/.test(p) ? 'must not start with : or ! (no pathspec magic or negation)' : /[\x00-\x1f\x7f]/.test(p) ? 'contains a control character' : p.replace(/\/+$/, '') === '' || p === '.' ? 'must not name the whole repository' : null);
if (why) out.push({ code: 'POLICY_INVALID', path: `review_exclude_paths[${i}]`, message: `${JSON.stringify(p)} ${why}` });
if (why) out.push({ code: 'POLICY_INVALID', path: `${key}[${i}]`, message: `${JSON.stringify(p)} ${why}` });
});
}
@@ -473,7 +477,8 @@ export function validatePolicy(raw: unknown, opts: { gstackVersion?: string } =
oneOf('history', ['merge-only', 'squash-ok', 'no-rewrite']);
oneOf('review_scope', ['frozen', 'diff-plus-blocking', 'all']);
oneOf('merge', ['direct', 'train']);
if ('review_exclude_paths' in obj) excludeErrors(obj.review_exclude_paths, errors);
if ('review_exclude_paths' in obj) excludeErrors('review_exclude_paths', obj.review_exclude_paths, errors);
if ('review_content_patterns' in obj) excludeErrors('review_content_patterns', obj.review_content_patterns, errors);
if ('review' in obj) reviewErrors(obj.review, errors, (k, v) => listErrors(k, v, errors, globError));
if ('readers' in obj) readersErrors(obj.readers, errors, containedRelative);
if ('release_tool' in obj && obj.release_tool !== null) {
@@ -762,6 +767,7 @@ export function shipConsequences(policy: ShipPolicy, base: string): string[] {
? 'review_scope diff-plus-blocking: Step 9.4 runs `gstack-review-scope classify --policy diff-plus-blocking` each pass; pass 1 fixes the diff and every blocking finding, in unchanged code too, later passes read only the range since the previous pass and fix only blocking findings; notes go to the PR body'
: 'review_scope frozen: Step 9.4 runs `gstack-review-scope classify` each pass; pass 1 fixes the diff and defers blocking findings in unchanged code to the PR body, later passes read only the range since the previous pass and fix only blocking findings; notes go to the PR body');
if (policy.review_exclude_paths.length) out.push(`review_exclude_paths ${policy.review_exclude_paths.join(' ')}: Step 9's reviewers leave out the data, docs, binary and .log files these git globs match on this branch; gstack-review-plan prints REVIEW_EXCLUDE: with the counts and the kept files, and every brief names what was left out (docs/ship-policy.md#review-exclude-paths)`);
if (policy.review_exclude_paths.length && policy.review_content_patterns.length) out.push(`review_content_patterns ${policy.review_content_patterns.join(' ')}: files these globs and review_exclude_paths both match count as content whatever their extension, so Step 9's reviewers leave them out too (docs/ship-policy.md#review-content-patterns)`);
if (policy.preregistration_shas.length) out.push(`preregistration: \`gstack-evidence ancestor --from-policy --base ${base}\` must print only ANCESTOR: ok before push; the ship receipt records the result`);
if (policy.release_tool) out.push(`release_tool: \`${policy.release_tool}\` runs only inside gstack-restamp (staging worktree, outputs confined to release_outputs)`);
return out;
+159
View File
@@ -0,0 +1,159 @@
/**
* review_content_patterns and the kept-file bound (GST-3158, docs/ship-policy.md#review-content-patterns): a results PR shaped
* like gstack-evals #352 (1,300+ .patch files, extension-less licence texts and a MANIFEST.sha256 under one folder, beside
* ordinary code) excludes that folder only when the base policy names it under both keys; a pattern whose kept files pass the
* argument bound stops the plan with a named code instead of being dropped; and the secrets scan and the sealed guard still
* read the excluded files.
*/
import { afterEach, describe, expect, test } from 'bun:test';
import { spawnSync } from 'node:child_process';
import { EXIT } from '../lib/headless-artifacts';
import { REVIEW_CONTENT_KEY_VERSION } from '../lib/ship-policy';
import { BASE_PREGATE, cleanup, commit, makeFixtureRepo, runBin, type FixtureRepo } from './helpers/pregate-fixture';
const repos: FixtureRepo[] = [];
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
const DIR = 'results/h2h-2026-11/sessions';
const AWS = 'AKIA' + 'ZQ3XN7P2LM4RT8WV';
const policy = (exclude: string[], content?: string[]) => JSON.stringify({ review_exclude_paths: exclude, ...(content ? { review_content_patterns: content } : {}), min_gstack_version: REVIEW_CONTENT_KEY_VERSION }) + '\n';
/** A #352-shaped branch: `patches` .patch files, extension-less licence texts and a MANIFEST.sha256 under DIR, plus code and a test. */
function results(basePolicy: string | null, patches: number, extra: Record<string, string> = {}, pregate?: unknown): FixtureRepo {
const baseFiles: Record<string, string> = {};
if (basePolicy) baseFiles['.gstack/ship-policy.json'] = basePolicy;
if (pregate) baseFiles['.gstack/pregate.json'] = JSON.stringify(pregate, null, 2) + '\n';
const repo = makeFixtureRepo({ prefix: 'gstack-content-', baseFiles });
repos.push(repo);
const files: Record<string, string> = {
'lib/report.js': "exports.total = rows => rows.reduce((n, r) => n + r.cost, 0);\n",
'test/report.test.js': "const { total } = require('../lib/report');\nif (total([{ cost: 1 }]) !== 1) throw new Error('total');\n",
[`${DIR}/licences/MIT-task-repo`]: 'MIT License\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\n',
[`${DIR}/licences/Apache-2.0-task-repo`]: 'Apache License\nVersion 2.0, January 2004\n',
...extra,
};
const names: string[] = [];
for (let k = 0; k < patches; k++) {
const name = `${DIR}/task-${String(k).padStart(4, '0')}/arm-gstack.patch`;
names.push(name);
files[name] = `diff --git a/src/parse.ts b/src/parse.ts\n--- a/src/parse.ts\n+++ b/src/parse.ts\n@@ -1 +1 @@\n-export const limit = 1;\n+export const limit = ${k + 2};\n`;
}
files[`${DIR}/MANIFEST.sha256`] = names.map((n, k) => `${String(k).padStart(64, '0')} ${n.slice(DIR.length + 1)}`).join('\n') + '\n';
commit(repo, files);
return repo;
}
const plan = (repo: FixtureRepo) => runBin(repo, 'gstack-review-plan', ['--base', 'main', '--gate-tagged', '0']);
/** The paths a plan's DIFF_CMD reads, run as --name-only in the fixture. */
function diffCmdPaths(repo: FixtureRepo, text: string): string[] {
const cmd = text.split('\n').find(l => l.startsWith('DIFF_CMD: '))!.slice('DIFF_CMD: '.length).replace(/^\S+ /, '');
const named = cmd.replace(/^git diff/, 'git diff --name-only').replace('<diff-base>', '"$DIFF_BASE"');
const r = spawnSync('bash', ['-c', named], { cwd: repo.work, encoding: 'utf8', timeout: 60_000, env: { ...process.env, ...repo.env, DIFF_BASE: repo.git('merge-base', 'origin/main', 'HEAD') } });
expect({ cmd: named, status: r.status, err: r.stderr }).toMatchObject({ cmd: named, status: 0 });
return r.stdout.split('\n').filter(Boolean);
}
describe('review_content_patterns on a #352-shaped results PR', () => {
// Value: protects=a results PR that publishes raw session data (.patch, MANIFEST.sha256, extension-less licences) can be
// reviewed once its base policy names the folder under both keys, and its code stays in every reader's diff;
// fails_when=the folder is kept as code, dropped, or the code leaves the diff; why_new=GST-3158 (gstack-evals #352: 1,439
// files kept as code, patterns=0/5); seam=bin/gstack-review-plan and git running the printed DIFF_CMD; no_claim=a live /ship run
test('the folder is excluded as declared content and the code stays in review', () => {
const repo = results(policy([`${DIR}/**`], [`${DIR}/**`]), 1_320);
const r = plan(repo);
expect(r.err).not.toContain('REVIEW_EXCLUDE_KEEP_TOO_LARGE');
expect(r.status).toBe(EXIT.ok);
expect(r.out).toMatch(/^REVIEW_EXCLUDE: patterns=1\/1 excluded=1323 bytes=\d+ kept=0 content=declared:1323 /m);
expect(r.out).not.toContain('REVIEW_EXCLUDE_KEPT:');
const read = diffCmdPaths(repo, r.out);
expect(read).toContain('lib/report.js');
expect(read).toContain('test/report.test.js');
expect(read.filter(p => p.startsWith(`${DIR}/`))).toEqual([]);
}, 180_000);
// Value: protects=a pattern whose kept files pass the argument bound is never dropped quietly; fails_when=the plan prints
// patterns=0/1 and hands readers the whole folder; why_new=GST-3158 cause (b); seam=bin/gstack-review-plan; no_claim=Windows
test('without the content key the same folder stops the plan with REVIEW_EXCLUDE_KEEP_TOO_LARGE instead of dropping the pattern', () => {
const repo = results(policy([`${DIR}/**`]), 1_320, { [`${DIR}/summary.json`]: '{"tasks": 1320}\n' });
const r = plan(repo);
expect(r.status).toBe(EXIT.refused);
expect(r.out).not.toContain('REVIEW_EXCLUDE:');
expect(r.err).toMatch(new RegExp(`pattern ${DIR}/\\*\\* on origin/main@[0-9a-f]{12} keeps 1323 matched files in review \\(code:1323\\).*\\(more than 24000\\)`));
expect(r.err).toContain('review_content_patterns');
expect(r.err.trim()).toEndWith('nothing was planned (REVIEW_EXCLUDE_KEEP_TOO_LARGE)');
}, 180_000);
});
describe('review_content_patterns negative controls', () => {
// Value: protects=the content key only narrows what review_exclude_paths already names, and only the base's copy counts;
// fails_when=a content pattern excludes on its own or a branch excludes its own files; why_new=GST-3158;
// seam=bin/gstack-review-plan; no_claim=none
test('a content pattern with no matching exclude pattern excludes nothing', () => {
const repo = results(policy(['data/**'], [`${DIR}/**`]), 20, { 'data/rows.json': '[1]\n' });
const r = plan(repo);
expect(r.status).toBe(EXIT.ok);
expect(r.out).toMatch(/^REVIEW_EXCLUDE: patterns=1\/1 excluded=1 .* content=data:1 /m);
const read = diffCmdPaths(repo, r.out);
expect(read.filter(p => p.startsWith(`${DIR}/`)).length).toBe(23);
expect(read).not.toContain('data/rows.json');
}, 120_000);
test('the policy is read from the base: a branch that adds the content key still has the folder kept as code', () => {
const repo = results(policy([`${DIR}/**`]), 20, { [`${DIR}/summary.json`]: '{}\n', '.gstack/ship-policy.json': policy([`${DIR}/**`], [`${DIR}/**`]) });
const r = plan(repo);
expect(r.status).toBe(EXIT.ok);
expect(r.out).toMatch(/^REVIEW_EXCLUDE: patterns=1\/1 excluded=1 bytes=\d+ kept=23 content=data:1 /m);
expect(r.out).toContain(`REVIEW_EXCLUDE_KEPT: code ${DIR}/MANIFEST.sha256`);
const read = diffCmdPaths(repo, r.out);
expect(read).not.toContain(`${DIR}/summary.json`);
expect(r.out).toMatch(new RegExp(`^DIFF_KEEP: .*${DIR}/task-0000/arm-gstack\\.patch`, 'm'));
}, 120_000);
// Value: protects=a declaration reclassifies only names that are not code, so a branch cannot hide a source file inside a
// declared folder; fails_when=a .ts or .sh file under both keys leaves review as declared content; why_new=GST-3158 review
// (red-team p1#2); seam=bin/gstack-review-plan; no_claim=shebang detection in extension-less files
test('a source file inside a declared folder stays in review as code', () => {
const repo = results(policy([`${DIR}/**`], [`${DIR}/**`]), 3, { [`${DIR}/loader.ts`]: 'export const load = () => 1;\n', [`${DIR}/fetch.sh`]: 'curl -s example.invalid\n' });
const r = plan(repo);
expect(r.status).toBe(EXIT.ok);
expect(r.out).toMatch(/^REVIEW_EXCLUDE: patterns=1\/1 excluded=6 bytes=\d+ kept=2 content=declared:6 /m);
expect(r.out).toContain(`REVIEW_EXCLUDE_KEPT: code ${DIR}/loader.ts`);
expect(r.out).toContain(`REVIEW_EXCLUDE_KEPT: code ${DIR}/fetch.sh`);
}, 120_000);
// Value: protects=a NUL byte or an upper-case extension cannot move a source file in a declared folder out of review;
// fails_when=the binary arm or a case-sensitive test treats it as declared content; why_new=GST-3158 review (red-team p2#1);
// seam=bin/gstack-review-plan; no_claim=source languages outside SOURCE_EXT
test('a binary or upper-case source file inside a declared folder stays in review as code', () => {
const repo = results(policy([`${DIR}/**`], [`${DIR}/**`]), 3, { [`${DIR}/hidden.ts`]: 'export const y = 2;\n// \u0000\n', [`${DIR}/Loader.TS`]: 'export const load = () => 1;\n' });
const r = plan(repo);
expect(r.status).toBe(EXIT.ok);
expect(r.out).toMatch(/^REVIEW_EXCLUDE: patterns=1\/1 excluded=6 bytes=\d+ kept=2 content=declared:6 /m);
expect(r.out).toContain(`REVIEW_EXCLUDE_KEPT: code ${DIR}/hidden.ts`);
expect(r.out).toContain(`REVIEW_EXCLUDE_KEPT: code ${DIR}/Loader.TS`);
}, 120_000);
});
describe('excluded from review is not excluded from the guards', () => {
// Value: protects=a credential or a sealed answer inside declared content still stops the push; fails_when=the secrets scan
// or the sealed guard honours review_exclude_paths or review_content_patterns; why_new=GST-3158 (the guards must keep reading
// what review leaves out); seam=bin/gstack-pregate secrets and sealed; no_claim=the managed pre-push hook
test('the secrets scan and the sealed guard both read a .patch file the plan excludes', () => {
const leak = `${DIR}/task-0003/arm-plain.patch`;
const sealed = `${DIR}/task-0004/arm-plain.patch`;
const repo = results(policy([`${DIR}/**`], [`${DIR}/**`]), 20, {
[leak]: `diff --git a/ci.yml b/ci.yml\n+++ b/ci.yml\n@@ -0,0 +1 @@\n+ ${AWS}\n`,
[sealed]: 'diff --git a/notes.md b/notes.md\n+++ b/notes.md\n@@ -0,0 +1 @@\n+SEALED ANSWER: fund-b\n',
}, { ...BASE_PREGATE, sealed: { paths: ['heldout/**'], answer_markers: ['SEALED ANSWER:'] } });
const r = plan(repo);
expect(r.status).toBe(EXIT.ok);
expect(r.out).toMatch(/^REVIEW_EXCLUDE: patterns=1\/1 excluded=25 bytes=\d+ kept=0 /m);
expect(diffCmdPaths(repo, r.out)).not.toContain(leak);
const secrets = runBin(repo, 'gstack-pregate', ['--base', 'main', '--only', 'secrets', '--json']);
const check = JSON.parse(secrets.out).checks.find((c: { id: string }) => c.id === 'secrets');
expect(check.status).toBe('fail');
expect(JSON.stringify(check)).toContain(leak);
const guard = runBin(repo, 'gstack-pregate', ['sealed', '--base', 'main']);
expect(guard.status).toBe(1);
expect(guard.err).toMatch(new RegExp(`sealed\\.answer\\s+${sealed.replace(/[.]/g, '\\.')}:4`));
expect(guard.err).toContain('(SEALED_OUTPUT_REFUSED)');
}, 180_000);
});
+4 -5
View File
@@ -64,7 +64,7 @@ describe('secret-like lines under review_exclude_paths', () => {
const p = JSON.parse(runBin(repo, 'gstack-review-plan', ['--base', 'main', '--gate-tagged', '0', '--json']).out);
expect(p.review_exclude.kept_files).toEqual(Object.keys(VALUE_LINES).sort().map(n => ({ path: `receipts/value/${n}.json`, reason: 'secret-line' })));
expect(p.review_exclude.excluded).toBe(1 + Object.keys(NAME_LINES).length);
expect(p.review_exclude.skipped).toEqual([]);
expect(p.review_exclude.applied).toEqual(['receipts/**']);
}, 120_000);
});
@@ -82,7 +82,6 @@ describe('the argument-byte bound', () => {
const baseSha = repo.git('rev-parse', 'origin/main');
const c = collectCommit(repo.work, baseSha, head);
const x = reviewExclude({ root: repo.work, baseSha, ref: 'origin/main', mergeBase: c.mergeBase!, head, perPath: c.perPath, added: c.added, classRoot: c.root ?? [], gateTagged: new Set(), context: 'test' });
if (x.state !== 'active') throw new Error(`exclusion is ${x.state}`);
return { repo, x, paths, mergeBase: c.mergeBase! };
}
@@ -93,7 +92,7 @@ describe('the argument-byte bound', () => {
// GIT_TRACE; no_claim=what an agent's shell does with a brief's keep command (those files still count)
test('excerpt-only kept files past the bound still apply the pattern, and their read is chunked under it', () => {
const { repo, x, paths, mergeBase } = excerptOnly(false);
expect(x.record.skipped).toEqual([]);
if (x.state !== 'active') throw new Error(`exclusion is ${x.state}`);
expect(x.record.applied).toEqual(['receipts/**']);
expect(x.excerpt.length).toBe(COUNT);
expect(paths.reduce((n, p) => n + Buffer.byteLength(`':(top,literal)${p}' `), 0)).toBeGreaterThan(KEEP_ARG_MAX_BYTES);
@@ -116,8 +115,8 @@ describe('the argument-byte bound', () => {
// bound; fails_when=the bound stops counting kept files that are not excerpted; why_new=GST-1967; seam=reviewExclude
test('kept files a reader runs as a command still count toward the bound', () => {
const { x } = excerptOnly(true);
expect(x.record.applied).toEqual([]);
expect(x.record.skipped).toMatchObject([{ pattern: 'receipts/**', kept: COUNT }]);
expect(x).toMatchObject({ state: 'refused', code: 'REVIEW_EXCLUDE_KEEP_TOO_LARGE' });
if (x.state === 'refused') expect(x.lines[0]).toContain(`keeps ${COUNT} matched files in review (secret-line:${COUNT})`);
}, 120_000);
});
+11 -8
View File
@@ -225,9 +225,9 @@ describe('the base policy read', () => {
describe('the kept-file command is bounded by argument bytes', () => {
// Value: protects=the DIFF_KEEP command stays under the Windows command line however many kept files a pattern has, and a
// disjoint small pattern still applies; fails_when=a pattern whose kept files pass KEEP_ARG_MAX_BYTES is applied, or the plan
// does not say why it was not; why_new=task 10; seam=bin/gstack-review-plan; no_claim=a real Windows launch
test('a pattern whose kept files pass the bound is not applied and the plan says why; a disjoint small pattern applies', () => {
// pattern past the bound is never dropped quietly; fails_when=a pattern whose kept files pass KEEP_ARG_MAX_BYTES is applied,
// or skipped while the plan goes on; why_new=task 10, GST-3158; seam=bin/gstack-review-plan; no_claim=a real Windows launch
test('a pattern whose kept files pass the bound stops the plan with REVIEW_EXCLUDE_KEEP_TOO_LARGE; without it the small pattern applies', () => {
const repo = makeFixtureRepo({ prefix: 'gstack-exclude-', baseFiles: { '.gstack/ship-policy.json': policyText(['big/**', 'small/**']) } }); repos.push(repo);
const long = 'x'.repeat(180);
for (let k = 0; k < 140; k++) {
@@ -235,8 +235,13 @@ describe('the kept-file command is bounded by argument bytes', () => {
fs.chmodSync(path.join(repo.work, `big/${long}-${k}.sh`), 0o755);
}
commit(repo, { 'big/data.json': '{}\n', 'small/data.json': '{}\n', 'lib/a.js': 'exports.a = 1;\n' });
const refused = plan(repo);
expect(refused.status).toBe(EXIT.refused);
expect(refused.out).not.toContain('REVIEW_EXCLUDE:');
expect(refused.err).toMatch(new RegExp(`pattern big/\\*\\* on origin/main@[0-9a-f]{12} keeps 140 matched files in review \\(executable:140\\).*\\(more than ${KEEP_ARG_MAX_BYTES}\\).*\\(REVIEW_EXCLUDE_KEEP_TOO_LARGE\\)`));
onBase(repo, { '.gstack/ship-policy.json': policyText(['small/**']) });
const text = plan(repo).out;
expect(text).toMatch(new RegExp(`REVIEW_EXCLUDE: patterns=1/2 .* skipped=big/\\*\\*:kept=140:bytes=\\d+ \\(kept files over ${KEEP_ARG_MAX_BYTES} argument bytes: pattern not applied\\)`));
expect(text).toMatch(/REVIEW_EXCLUDE: patterns=1\/1 /);
const cmd = text.split('\n').find(l => l.startsWith('DIFF_CMD: '))!;
expect(cmd).toContain("':(top,exclude,glob)small/**'");
expect(cmd).not.toContain('big/**');
@@ -248,16 +253,14 @@ describe('the review ceiling lines', () => {
const d = { bytes: 3_500_000, byDir: [['results', 3_000_000], ['src', 500_000]] as Array<[string, number]> };
// Value: protects=a REVIEW_DIFF_TOO_LARGE stop names the one fix that applies, with JSON a person can paste; fails_when=the
// fix ignores where the policy stands or prints a placeholder version; why_new=task 4; seam=tooLargeLine; no_claim=the bytes git reports
test('the fix branches on no key, head-only, a skipped pattern and still over, with pasteable JSON at the key version', () => {
test('the fix branches on no key, head-only and still over, with pasteable JSON at the key version', () => {
const json = (line: string) => JSON.parse(line.match(/land (\{.*?\}) in /)![1]!);
const none = tooLargeLine('ctx', 'batched', d, { state: 'none', base: 'main', source: 'origin/main@abc' }).line;
expect(json(none)).toEqual({ review_exclude_paths: ['results/**'], min_gstack_version: REVIEW_EXCLUDE_KEY_VERSION });
expect(none).toContain('then bring main into this branch and rerun once; if it is still over, split the PR');
const head = tooLargeLine('ctx', 'batched', d, { state: 'head-only', base: 'main', source: 'origin/main@abc', headPatterns: ['results/**'] }).line;
expect(head).toContain('this branch declares review_exclude_paths, but only the copy on main applies');
const skipped = tooLargeLine('ctx', 'batched', d, { state: 'active', base: 'main', source: 'origin/main@abc', record: { patterns: ['results/**'], skipped: [{ pattern: 'results/**', kept: 900, bytes: 40_000 }], excluded: 0 } }).line;
expect(skipped).toContain('pattern results/** was not applied: its 900 kept files need 40000 argument bytes');
const over = tooLargeLine('ctx', 'batched', d, { state: 'active', base: 'main', source: 'origin/main@abc', floor: '1.300.0.0', record: { patterns: ['receipts/**'], skipped: [], excluded: 12 } }).line;
const over = tooLargeLine('ctx', 'batched', d, { state: 'active', base: 'main', source: 'origin/main@abc', floor: '1.300.0.0', record: { patterns: ['receipts/**'], excluded: 12 } }).line;
expect(over).toContain('still over after excluding 12 files');
expect(json(over)).toEqual({ review_exclude_paths: ['receipts/**', 'results/**'], min_gstack_version: '1.300.0.0' });
expect(over).toEndWith('nothing was written (REVIEW_DIFF_TOO_LARGE)');