diff --git a/changelog.d/fix-review-exclude-named-config-data.md b/changelog.d/fix-review-exclude-named-config-data.md new file mode 100644 index 000000000..86898ee98 --- /dev/null +++ b/changelog.d/fix-review-exclude-named-config-data.md @@ -0,0 +1,4 @@ +--- +important: blocker +--- +- **A data file with a config-style name, such as a results `manifest.json`, now leaves /ship's review diff when the base branch's `review_exclude_paths` names it by file name.** Files named like tool config (`manifest.json`, `package.json`, `tsconfig*.json`, files under `config/`, dotfiles) were always kept in review as config, even under a pattern written for them, so a large eval results PR whose base policy listed `docs/benchmarks/*/results*/**/manifest.json` still handed every reader its 1.42 MB manifest and stopped at `REVIEW_DIFF_TOO_LARGE`. The kept manifest also counted as code that names files, so every receipt it listed by full path stayed in review as `named-by-code`. Now a matched JSON, CSV, TSV or image file is treated as data when the pattern that matches it ends in its exact file name with no glob character. Such a file is excluded, and its list no longer keeps other files. A config file under a broader pattern (`data/**`, `**/*.json`) is still kept as `config`, config files no pattern matches are unchanged, and every other keep rule (gate paths, executables, secret lines, gate tags, `.gstack/` and `.github/`) still applies first. The policy is still read only from the base branch. diff --git a/docs/ship-policy.md b/docs/ship-policy.md index 6797bcea6..8e85deb19 100644 --- a/docs/ship-policy.md +++ b/docs/ship-policy.md @@ -1475,7 +1475,7 @@ Everything else stays in every reader's diff with one reason code: | `executable` | its old or new mode is executable | | `link` | its old or new mode is a symlink or a submodule commit | | `agent-prose` | it is a skill, section, resolver, template or rule file | -| `config` | it is a data-shaped config file (`package.json`, `tsconfig*.json`, `config/`, dotfiles, `scripts/harness-pins/`) | +| `config` | it is a data-shaped config file (`package.json`, `tsconfig*.json`, `manifest.json`, `config/`, dotfiles, `scripts/harness-pins/`) and no pattern names it by file name: a pattern whose last segment is the file's exact name with no glob character (`docs/benchmarks/*/results*/**/manifest.json`) makes a matched data file content, so it is excluded and names nothing; a broader pattern (`results/**`, `**/*.json`) keeps it | | `gate-tagged` | the gate scan tagged one of its hunks | | `code` | it is code or a test, not content; a binary file outside the content extensions above, or one with executable magic, counts as code | | `secret-line` | an added line names a credential (the targeted pass's secret rule, or a key name given a value such as `OPENAI_API_KEY=`) and carries a value: the credential scan finds a secret on the line, or a run of 20 or more base64 or token characters mixing upper case, lower case and digits follows a name within 200 characters. A line that only names a variable or a credential store (`${OPENAI_API_KEY}`, `$GH_TOKEN`, `process.env.X`, `os.environ["X"]`, a keychain command) keeps nothing (GST-1967: harness-evals #333's captured prompts kept 2,610 files that way). For a file git calls binary only because of its attributes, the added lines come from `git diff --text`, which `.gitattributes` cannot change (readers' own diffs still follow the attributes and show the kept file as binary). When this is the only reason, pass readers get an excerpt, not the whole file ([secret-line excerpts](#secret-line-excerpts)) | diff --git a/lib/review-exclude.ts b/lib/review-exclude.ts index 0be1d9022..e2e469dfc 100644 --- a/lib/review-exclude.ts +++ b/lib/review-exclude.ts @@ -257,9 +257,12 @@ 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'; -function contentKind(i: ExcludeInput, p: string, binary: ReadonlySet): ContentKind | null { +/** 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 }; +const config = (i: Scope, p: string) => isDataConfig(p) && !i.named?.has(p); +function contentKind(i: Scope, p: string, binary: ReadonlySet): ContentKind | null { if (binary.has(p)) return 'binary'; - if (DATA_PATH.test(p) && !isDataConfig(p)) return 'data'; + 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; } @@ -272,7 +275,7 @@ function contentKind(i: ExcludeInput, p: string, binary: ReadonlySet): C const BINARY_CONTENT_EXT = /\.(?:png|jpe?g|gif|webp|bmp|ico|avif|tiff?|heic|heif|woff2?|ttf|otf|eot|mp3|mp4|m4a|wav|ogg|oga|ogv|webm|mov|avi|mkv|flac|aac|opus|pdf|docx|xlsx|pptx|odt|ods|odp|gz|tgz|zip|tar|bz2|xz|zst|7z|bin|dat|parquet|arrow|feather|avro|orc|npy|npz|h5|hdf5|sqlite3?|db|safetensors)$/i; /** Why a matched file is kept by its path, mode and lines alone; null for content the policy may exclude. A binary file readers would only see as "Binary files differ" is content unless its directory, mode, gate tags, extension or magic keep it. */ -function pathReason(i: ExcludeInput, p: string, m: Matched, binary: ReadonlySet, native: ReadonlySet): KeptReason | null { +function pathReason(i: Scope, p: string, m: Matched, binary: ReadonlySet, native: ReadonlySet): KeptReason | null { if (/^\.(gstack|github)\//.test(p)) return 'policy-dir'; if (isGatePath(p) || secretPath(p, i.added[p] ?? [])) return 'gate-path'; if (m.oldMode === '100755' || m.newMode === '100755') return 'executable'; @@ -280,14 +283,14 @@ function pathReason(i: ExcludeInput, p: string, m: Matched, binary: ReadonlySet< if (i.gateTagged?.has(p)) return 'gate-tagged'; if (binary.has(p)) return BINARY_CONTENT_EXT.test(p) && !native.has(p) ? null : 'code'; if (isAgentProse(p)) return 'agent-prose'; - if (isDataConfig(p)) return 'config'; + if (config(i, p)) return 'config'; if (contentKind(i, p, binary) === null) return 'code'; if ((i.added[p] ?? []).some(l => secretValueLine(p, l))) return 'secret-line'; return null; } /** A file whose full-path reference keeps excluded content: a code or test file (not docs, data, a .log or binary) outside the would-be-excluded set. */ -const consumer = (i: ExcludeInput, f: string, candidates: ReadonlySet) => +const consumer = (i: Scope, f: string, candidates: ReadonlySet) => !candidates.has(f) && !f.startsWith('.gstack/tmp/') && contentKind(i, f, new Set()) === null; /** @@ -299,7 +302,7 @@ const consumer = (i: ExcludeInput, f: string, candidates: ReadonlySet) = * (GST-1442: 363 chunked greps over a 192k-file tree ran 132 s). On a live tree, an entry git reads from its blob * (skip-worktree or assume-unchanged) goes into a second index grepped with --cached, as git grep itself would read it. */ -function grepFixed(i: ExcludeInput, strings: readonly string[], candidates: ReadonlySet, revs: readonly string[]): Map> | null { +function grepFixed(i: Scope, strings: readonly string[], candidates: ReadonlySet, revs: readonly string[]): Map> | null { const found = new Map>(); if (!strings.length) return found; const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-exclude-')); @@ -365,14 +368,16 @@ export function reviewExclude(i: ExcludeInput): Exclusion { const native = new Set(); 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 text = { ...i, added: { ...i.added, ...attributeBinaryLines(i, claimed.filter(p => !binary.has(p) && !unread.has(p)), unread) } }; + 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 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)); }; const reasons = new Map(); for (const [p, m] of sel.files) reasons.set(p, unread.has(p) ? 'consumer-scan-unavailable' : pathReason(text, p, m, binary, native) ?? (unseen(p) ? 'consumer-scan-unavailable' : null)); const candidates = new Set([...reasons].filter(([, r]) => r === null).map(([p]) => p)); const secretOnly = [...reasons].filter(([p, r]) => r === 'secret-line' && !p.includes('\n')).map(([p]) => p); - const named = grepFixed(i, [...candidates, ...secretOnly].filter(p => !p.includes('\n')), new Set([...candidates, ...secretOnly]), [i.mergeBase]); + const named = grepFixed(x, [...candidates, ...secretOnly].filter(p => !p.includes('\n')), new Set([...candidates, ...secretOnly]), [i.mergeBase]); for (const p of candidates) { if (i.gateTagged === null) reasons.set(p, 'gate-scan-unavailable'); else if (named === null || p.includes('\n')) reasons.set(p, 'consumer-scan-unavailable'); @@ -396,9 +401,9 @@ export function reviewExclude(i: ExcludeInput): Exclusion { 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 = { binary: 0, data: 0, docs: 0, log: 0 }; - for (const p of sortedExcluded) content[contentKind(i, p, binary)!]++; + for (const p of sortedExcluded) content[contentKind(x, p, binary)!]++; const prefixes = [...new Set(applied.map(literalPrefix).filter(Boolean))]; - const refs = grepFixed(i, prefixes, excluded, []) ?? new Map>(); + const refs = grepFixed(x, prefixes, excluded, []) ?? new Map>(); 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 = { diff --git a/test/review-exclude.test.ts b/test/review-exclude.test.ts index 959aab08f..14c5e585c 100644 --- a/test/review-exclude.test.ts +++ b/test/review-exclude.test.ts @@ -94,6 +94,36 @@ describe('what review_exclude_paths excludes and keeps', () => { for (const f of KEPT) expect(read.has(f)).toBe(true); }, 120_000); + // Value: protects=a results manifest the base policy names by file name leaves the reviewers' diff, and stops keeping the + // receipts it lists, while config files under a broader pattern stay; fails_when=a pattern whose last segment is + // manifest.json keeps the manifest as config, the manifest's full-path list keeps the receipts as named-by-code, or a + // package.json or manifest.json matched only by data/** is excluded; why_new=a large eval results PR stopped at + // REVIEW_DIFF_TOO_LARGE on a 1.42 MB manifest its base policy named; seam=bin/gstack-review-plan and git running the printed commands + test('a config-named data file is excluded when a pattern names its file name, and kept under a broader pattern', () => { + const named = 'docs/bench/run1/results-a/x/manifest.json'; + const repo = makeFixtureRepo({ prefix: 'gstack-exclude-', baseFiles: { '.gstack/ship-policy.json': policyText(['data/**', 'docs/bench/*/results*/**/manifest.json']) } }); + repos.push(repo); + commit(repo, { + [named]: JSON.stringify({ trials: ['data/r1.json', 'data/r2.json'] }) + '\n', + 'data/r1.json': '{"ok": true}\n', + 'data/r2.json': '{"ok": false}\n', + 'data/manifest.json': '{"name": "data"}\n', + 'data/package.json': '{"scripts": {"postinstall": "node x.js"}}\n', + 'docs/bench/run1/package.json': '{"name": "bench"}\n', + }); + const p = JSON.parse(plan(repo, ['--json']).out); + expect(p.review_exclude.kept_files).toEqual([ + { path: 'data/manifest.json', reason: 'config' }, + { path: 'data/package.json', reason: 'config' }, + ]); + expect(p.review_exclude).toMatchObject({ state: 'active', excluded: 3, content: { binary: 0, data: 3, docs: 0, log: 0 } }); + const mb = mergeBase(repo); + const cmds = plan(repo).out.split('\n').filter(l => /^DIFF_(CMD|KEEP): /.test(l)).map(l => l.replace(/^DIFF_(CMD|KEEP): \S+ /, '')); + const read = new Set(cmds.flatMap(c => pathsRead(repo, c, mb))); + for (const f of [named, 'data/r1.json', 'data/r2.json']) expect(read.has(f)).toBe(false); + for (const f of ['data/manifest.json', 'data/package.json', 'docs/bench/run1/package.json']) expect(read.has(f)).toBe(true); + }, 120_000); + // Value: protects=the Red Team, the security specialist, the adversarial pass and the outside voice read the same selection // as the plan, including through the fixture-handling command; fails_when=any brief's git diff command (or the embedded // outside-voice diff) shows an excluded file, or a kept file is unreachable from a brief; why_new=task 8 (the fixture