Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions bin/gstack-banned-terms
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { spawnSync } from '../lib/spawn-sync';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { BANNED_TERMS_PATH, addedLines, exampleBannedTermsJson, loadBannedTerms, renderBannedTerms, scanBannedTerms, validateBannedTerms, wholeFiles } from '../lib/banned-terms';
import { gitDiffInParts, mergeParts } from '../lib/diff-parts';
import { baseArg } from '../lib/gate-diff/git';
import { EXIT, exitTableHelp } from '../lib/headless-artifacts';
import { resultLine } from '../lib/result-codes';
Expand Down Expand Up @@ -78,9 +79,10 @@ function main(argv: string[]): number {
else {
const diffBase = flag(rest, '--diff-base') ?? (() => { const mb = spawnSync('git', ['merge-base', baseArg('gstack-banned-terms', base, repoRoot), 'HEAD'], { cwd: repoRoot, encoding: 'utf8', timeout: 30_000 }); return mb.status === 0 ? mb.stdout.trim() : undefined; })();
if (!diffBase) { process.stderr.write(`gstack-banned-terms: no merge base with ${base}; pass --diff-base <sha> or --files <csv>\n`); return EXIT.usage; }
const diff = spawnSync('git', ['diff', '--unified=0', '--no-color', diffBase], { cwd: repoRoot, encoding: 'utf8', timeout: 120_000, maxBuffer: 256 * 1024 * 1024 });
if (diff.status !== 0) { process.stderr.write(`gstack-banned-terms: git diff ${diffBase} failed\n`); return EXIT.fail; }
files = addedLines(diff.stdout);
const added = new Map<string, Array<{ line: number; text: string }>>();
const diff = gitDiffInParts(['diff', '--unified=0', '--no-color', diffBase], { cwd: repoRoot, timeout: 120_000 }, part => mergeParts(added, addedLines(part)));
if (!diff.ok) { process.stderr.write(`gstack-banned-terms: git diff ${diffBase} failed\n`); return EXIT.fail; }
files = added;
}
const result = scanBannedTerms(load.config, load.source, files);
if (json) process.stdout.write(JSON.stringify(result) + '\n'); else process.stdout.write(renderBannedTerms(result));
Expand Down
4 changes: 2 additions & 2 deletions bin/gstack-ship-receipt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import { RISK_CLASSES, type RiskClass } from '../lib/review-risk';
import { checkReceiptProse, proseLine } from '../lib/ship-receipt-prose';
import { resolveStateRoot } from '../lib/state-root';
import { readPause, receiptBaseRed } from '../lib/base-red';
import { publicRuledNote, readRuledNotes, ruledNoteText } from '../lib/ruled-notes';
import { bodyListsLine, publicRuledNote, readRuledNotes, ruledNoteText } from '../lib/ruled-notes';
import { appliedGateDispositions, gateDispositionText, publicGateDisposition } from '../lib/gate-dispositions';
import { securityFingerprints } from '../lib/security-findings';
import { laneExceptionBodyLines } from '../lib/test-lane-exception';
Expand Down Expand Up @@ -304,7 +304,7 @@ async function cmdWrite(rest: string[], json: boolean): Promise<number> {
const leaked = securityFingerprints(bodyText);
if (leaked.length) { process.stderr.write(resultLine('gstack-ship-receipt write', 'RECEIPT_INVALID', `${bodyFile} names security finding ${leaked.join(', ')}: a PR body is public, so a security finding appears only as the redacted line gstack-approvals rulings, dispositions or gstack-review-scope render prints, and its location and reason stay in the private record (docs/troubleshooting.md#security-finding-in-body); nothing written`) + '\n'); return EXIT.fail; }
const ruledNotes = readRuledNotes(repoRoot);
const unlisted = bodyFile ? ruledNotes.map(n => `Ruled note: ${ruledNoteText(n)}`).find(l => !bodyText.split(/\r?\n/).some(b => b.trim() === l)) : undefined;
const unlisted = bodyFile ? ruledNotes.map(n => `Ruled note: ${ruledNoteText(n)}`).find(l => !bodyListsLine(bodyText, l)) : undefined;
if (unlisted) { process.stderr.write(resultLine('gstack-ship-receipt write', 'RECEIPT_INVALID', `${bodyFile} does not list ruled note ${JSON.stringify(unlisted)} (gstack-approvals rulings prints each line the body carries); nothing written`) + '\n'); return EXIT.fail; }
let gateDispositions: ReturnType<typeof appliedGateDispositions>['applied'];
try { gateDispositions = appliedGateDispositions(repoRoot, { pin: 'HEAD' }).applied; }
Expand Down
4 changes: 4 additions & 0 deletions changelog.d/large-results-prs-ship-scaling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
important: blocker
---
**`/gstack-ship` now handles very large results PRs.** A repository's `review_exclude_paths` can list up to 256 patterns instead of 64. When a reviewer's diff is still too big, the suggested fix no longer offers to hide `docs/` and never prints a policy gstack would refuse. The pre-merge secrets check and `gstack-banned-terms` read a diff of any size instead of failing past 256 MB. `gstack-review-plan` matches exclusion patterns and searches for files that name excluded paths with a fixed number of git calls, which took a 16,000-file results PR from 180 s to 100 s, and the docs-only check searches for references to every changed doc in one pass instead of one search per file. A PR body may list its `Ruled note:` lines as `- ` or `* ` bullets.
12 changes: 8 additions & 4 deletions docs/ship-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ branch that changes the policy.
| `changelog_fragments` | `{ dir, required_checks? }` or `null` | `null` | PRs carry unversioned [CHANGELOG fragments](#changelog-fragments) in `dir` (one flat, repo-relative directory, no `..`) and the merge step ([`land`](#land)) assigns the version (under `merge: direct`, the [release PR](#release-stamp) does). `required_checks` (up to 50 distinct names) are the checks [`train land`](#stamped-trains-under-changelog_fragments-train-land) requires present and green on a stamp commit. `null` keeps `[Unreleased]` sections and per-PR stamps. Needs `min_gstack_version`. |

Containment, checked by `validate` and again at write time: paths and globs are
repo-relative with no `..` segment, under 256 characters, at most 64 per list,
repo-relative with no `..` segment, under 256 characters, at most 64 per list
(`review_exclude_paths` takes up to 256, as long as their exclude pathspecs fit
in 24,000 argument bytes together, since every reader's one `git diff` carries
all of them; an older gstack reads a list over 64 as invalid, sets the key aside
and reviews every file),
and a glob's regex expansion under 512 characters; `release_tool` is under 512
characters with no newline; a matched file that resolves through a symlink to
outside the repository is refused (`POLICY_CONTAINMENT`). A mirror may start
Expand Down Expand Up @@ -1468,8 +1472,8 @@ the base commit it already resolved (`origin/<base>`, or `<base>`), never
the branch's copy, so a branch cannot exclude its own files. A branch that adds
the key gets `REVIEW_EXCLUDE: none (head sets review_exclude_paths; it applies
after it lands on <base>)` and a normal review. A base policy whose only errors
are in `review_exclude_paths` or `review_content_patterns` (65 patterns, say,
past the limit of 64) does not stop the plan: both keys are set aside, every
are in `review_exclude_paths` or `review_content_patterns` (257 patterns, say,
past the limit of 256) does not stop the plan: both keys are set aside, every
file is reviewed as if the base excluded nothing, and every other key, the
readers' `forbid_paths` included, applies as committed. The plan prints
`REVIEW_EXCLUDE: fallback (WARNING: …)` naming each error and the fix, on
Expand Down Expand Up @@ -1865,7 +1869,7 @@ with the `gate_id` its gate disposition needs, since a ruling never closes one
`gstack-approvals rulings` prints one `Ruled note: …` line per ruling for the
Pre-Landing Review and the PR body, `gstack-ship-receipt write` records them as
`ruled_notes` (each with its `head`) and refuses a `--body` that does not carry each
line word for word, and the READY block prints each as `RULED_NOTE:`.
line word for word (bare, or as a `- ` or `* ` list item), and the READY block prints each as `RULED_NOTE:`.
Step 11.5 reads the same rulings: `gstack-review-read` applies a ruling to a Step 9
or Step 11 row that carries the finding and whose `range_base..commit` holds the
ruling's head (a first pass, with no `range_base`: its own commit), lists its
Expand Down
14 changes: 10 additions & 4 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -3758,8 +3758,9 @@ a typo never silently means "default".
`gstack-ship-policy init --explain` prints each key, its meaning and default.

When the invalid file is the base branch's and its only errors are in
`review_exclude_paths` or `review_content_patterns` (for example `more than 64
patterns`), /gstack-ship does not stop: `gstack-review-plan` prints `REVIEW_EXCLUDE:
`review_exclude_paths` or `review_content_patterns` (for example `more than 256
patterns` in `review_exclude_paths`, or `more than 64 patterns` in
`review_content_patterns`), /gstack-ship does not stop: `gstack-review-plan` prints `REVIEW_EXCLUDE:
fallback (WARNING: …)`, reviews every file and applies the base's other keys,
so open a PR that corrects the list and ship it as usual
([review_exclude_paths](ship-policy.md#review-exclude-paths)). Any other error
Expand Down Expand Up @@ -4011,7 +4012,8 @@ record only when it changes no binary file, adds no numeric claim, touches no
results, prereg or eval path, and names no money, security, secret or auth topic; any other docs change
needs the reader again (GST-1195). With `--body`, write also refuses, writing
nothing, a body that does not carry each line the receipt requires as one line,
word for word: every `Ruled note: …` line `gstack-approvals rulings` prints,
word for word: every `Ruled note: …` line `gstack-approvals rulings` prints
(bare, or as a `- ` or `* ` list item),
every `Gate disposition: …` line `gstack-approvals dispositions` prints (and while
a gate disposition applies at HEAD, write refuses to run without `--body`),
finish's `MECHANICAL:` lines as `Mechanical retake: …`, and accept's
Expand Down Expand Up @@ -4090,7 +4092,11 @@ the base policy commit.
- **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. When published data under a pattern is kept as `code`
split the PR. The fix only suggests data, log and binary folders, never `docs/`
(the report is what the reviewer is there to read), and when the printed folders
would take the base list past 256 patterns or its 24,000-byte pathspec budget it
prints no JSON and asks for the existing patterns to be merged under fewer
folder globs instead. 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)), and so
Expand Down
64 changes: 64 additions & 0 deletions lib/diff-parts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* diff-parts — one `git diff` read with no output buffer to fill (GST-4003).
*
* A pipe read with spawnSync stops at its maxBuffer: harness-evals#616's added lines came to 255.7 MB against the secrets
* scan's 256 MiB, so a slightly larger results PR could not be scanned at all. Here git writes to a private file (mode
* 0600 in a 0700 directory, removed afterwards), and the caller gets it back in parts of about `partBytes`, each ending
* where the next `diff --` header starts. Inside a hunk every line starts with ' ', '+', '-', '\\' or '@@', and git quotes
* a name holding a newline, so a line starting `diff --` is always a file header: each file's section arrives whole in one
* part, and the parts joined are git's output byte for byte. A per-file parser fed every part in order therefore sees
* what it saw on the whole text.
*/
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { spawnSync } from './spawn-sync';

export const DIFF_PART_BYTES = 64 * 1024 * 1024;
const HEADER = Buffer.from('\ndiff --');

export interface DiffRun { cwd: string; timeout: number; env?: NodeJS.ProcessEnv }
export type DiffRead = { ok: true } | { ok: false; why: string };

/** Run `git <args>` and hand each part of its stdout to `each` in order; a git that did not finish (an exit, a kill, a timeout) is not ok. */
export function gitDiffInParts(args: readonly string[], run: DiffRun, each: (part: string) => void, partBytes = DIFF_PART_BYTES): DiffRead {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-diff-'));
try {
fs.chmodSync(dir, 0o700);
const file = path.join(dir, 'out.diff');
const fd = fs.openSync(file, 'w', 0o600);
let r: ReturnType<typeof spawnSync>;
try { r = spawnSync('git', [...args], { cwd: run.cwd, env: run.env, stdio: ['ignore', fd, 'pipe'], encoding: 'utf8', timeout: run.timeout }); } finally { fs.closeSync(fd); }
if (r.error || r.status !== 0) return { ok: false, why: r.error?.message ?? (r.status === null ? `killed by ${r.signal}` : `exit ${r.status}: ${String(r.stderr ?? '').trim().split('\n').pop() ?? ''}`) };
const input = fs.openSync(file, 'r');
try {
const pending: Buffer[] = [];
let held = 0;
let tail = Buffer.alloc(0);
for (;;) {
const chunk = Buffer.alloc(Math.max(1, partBytes));
const n = fs.readSync(input, chunk, 0, chunk.length, null);
if (n <= 0) break;
const read = chunk.subarray(0, n);
const seen = Buffer.concat([tail, read]);
let cut = -1;
for (let at = seen.indexOf(HEADER); at >= 0; at = seen.indexOf(HEADER, at + 1)) cut = held - tail.length + at + 1;
pending.push(read);
held += n;
tail = Buffer.from(seen.subarray(Math.max(0, seen.length - HEADER.length + 1)));
if (cut <= 0) continue;
const all = Buffer.concat(pending, held);
each(all.subarray(0, cut).toString('utf8'));
pending.splice(0, pending.length, Buffer.from(all.subarray(cut)));
held -= cut;
}
if (held) each(Buffer.concat(pending, held).toString('utf8'));
} finally { fs.closeSync(input); }
return { ok: true };
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
}

/** Fold per-part maps from a per-file parser into one, in the order the whole text would have built it. */
export function mergeParts<T>(into: Map<string, T[]>, part: Map<string, T[]>): void {
for (const [k, v] of part) { const have = into.get(k); if (have) for (const x of v) have.push(x); else into.set(k, v); }
}
Loading
Loading