mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-23 08:31:44 +01:00
A base branch with too many review_exclude_paths patterns no longer stops every /ship (GST-3399) (#4637)
When the base branch's ship policy fails only because of its `review_exclude_paths` or `review_content_patterns` list (for example 65 patterns, one over the limit of 64), /ship now reviews every file instead of stopping. Why: harness-evals main went to 65 patterns, and every /ship there stopped with POLICY_INVALID, including the PR that shortens the list. Nothing to do: the plan prints a `REVIEW_EXCLUDE: fallback (WARNING: ...)` line naming the error and the fix, and `gstack-ship-policy validate` still reports the list. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/red-team#1 reader=red-team Review-Finding: p1/specialist-batched#1 reader=testing Review-Finding: lib/ship-receipt-depth.ts:69:stale-comment reader=core
This commit is contained in:
1 parent
2887261a47
commit
dd611038ca
15 files changed
+211
-19
No files matched your search
@@ -36,7 +36,7 @@ describe('pass names the plan step and its limit when the plan does not finish (
|
||||
const out = path.join(root, 'run');
|
||||
const r = spawnSync(DISPATCH, ['pass', '--base', 'main', '--out', out, '--pass', 'timeout-p1'], { cwd: work, env: { ...env, GSTACK_REVIEW_PLAN_TIMEOUT_MS: '1' }, encoding: 'utf8', timeout: 120_000 });
|
||||
expect(r.status, r.stdout + r.stderr).toBe(1);
|
||||
expect(r.stderr).toContain('gstack-review-dispatch pass: gstack-review-plan did not finish inside the pass');
|
||||
expect(r.stderr).toContain('gstack-review-dispatch pass: gstack-review-plan did not finish inside its limit');
|
||||
expect(r.stderr).toContain('step="gstack-review-plan --base main" reason=timeout timeout_ms=1 signal=SIGTERM');
|
||||
expect(r.stderr.trimEnd().endsWith('(REVIEW_PLAN_STOPPED)')).toBe(true);
|
||||
expect(r.stdout).not.toContain('MANIFEST:');
|
||||
@@ -89,7 +89,7 @@ describe('render reads the plan limit from GSTACK_REVIEW_PLAN_TIMEOUT_MS too (GS
|
||||
};
|
||||
const stopped = render('o-stopped', '1');
|
||||
expect(stopped.status, stopped.err).toBe(EXIT.fail);
|
||||
expect(stopped.err).toContain('gstack-review-dispatch render: gstack-review-plan did not finish inside the pass');
|
||||
expect(stopped.err).toContain('gstack-review-dispatch render: gstack-review-plan did not finish inside its limit');
|
||||
expect(stopped.err).toContain('step="gstack-review-plan --base main --json" reason=timeout timeout_ms=1 signal=SIGTERM');
|
||||
expect(stopped.err).toContain('(REVIEW_PLAN_STOPPED)');
|
||||
expect(fs.existsSync(stopped.diff)).toBe(false);
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* A base policy that fails only on its review_exclude_paths or review_content_patterns sets those keys aside instead of
|
||||
* stopping every /ship (GST-3399): harness-evals main went to 65 patterns, past the schema's 64, and every plan there refused
|
||||
* POLICY_INVALID, the PR that shortens the list included. The keys' removal only widens review, every other base key still
|
||||
* applies, the head's copy still never counts, and any other error still refuses.
|
||||
*/
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import { EXIT } from '../lib/headless-artifacts';
|
||||
import { receiptExcludeFallback } from '../lib/ship-receipt-depth';
|
||||
import { loadBasePolicy } from '../lib/ship-queue';
|
||||
import { READERS_KEY_VERSION } from '../lib/ship-policy-keys';
|
||||
import { cleanup, commit, makeFixtureRepo, runBin, type FixtureRepo } from './helpers/pregate-fixture';
|
||||
|
||||
const repos: FixtureRepo[] = [];
|
||||
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
|
||||
|
||||
const patterns = (n: number) => Array.from({ length: n }, (_, i) => `data/p${i}/**`);
|
||||
const policyText = (p: Record<string, unknown>) => JSON.stringify({ min_gstack_version: READERS_KEY_VERSION, readers: { forbid_paths: ['private/**'] }, ...p }) + '\n';
|
||||
/** A repository whose main holds `policy`, and a branch that changes a data file, a code file and `head` (extra files, the policy included). */
|
||||
function repoWith(policy: Record<string, unknown>, head: Record<string, string> = {}) {
|
||||
const repo = makeFixtureRepo({ prefix: 'gstack-xfb-', baseFiles: { '.gstack/ship-policy.json': policyText(policy), 'data/p0/keep.json': '{}\n' } });
|
||||
repos.push(repo);
|
||||
commit(repo, { 'data/p0/r.json': '{"n": 1}\n', 'lib/a.ts': 'export const a = 1;\n', ...head });
|
||||
return repo;
|
||||
}
|
||||
const plan = (repo: FixtureRepo) => runBin(repo, 'gstack-review-plan', ['--base', 'main']);
|
||||
const planJson = (repo: FixtureRepo) => { const r = runBin(repo, 'gstack-review-plan', ['--base', 'main', '--json']); expect(r.status, r.err).toBe(EXIT.ok); return JSON.parse(r.out); };
|
||||
|
||||
describe('an invalid exclusion list on the base is set aside, never loosened (GST-3399)', () => {
|
||||
// Value: protects=a base whose only error is review_exclude_paths' length plans with every file reviewed and its other keys
|
||||
// applied, with a loud line on stdout and stderr and the record in --json; fails_when=the plan refuses POLICY_INVALID (the
|
||||
// harness-evals deadlock), applies some of the 65 patterns, or drops the base's readers.forbid_paths with the bad key;
|
||||
// why_new=GST-3399; seam=gstack-review-plan on a real repository; no_claim=what reviewers do with the files
|
||||
test('65 patterns on the base: the plan reviews every file, keeps forbid_paths and says why', () => {
|
||||
const repo = repoWith({ review_exclude_paths: patterns(65) });
|
||||
const r = plan(repo);
|
||||
expect(r.status, r.err).toBe(EXIT.ok);
|
||||
expect(r.out).toContain('REVIEW_EXCLUDE: fallback (WARNING: the base policy origin/main@');
|
||||
expect(r.out).toContain('review_exclude_paths: more than 64 patterns');
|
||||
expect(r.out).toContain('every file is reviewed');
|
||||
expect(r.err).toContain('gstack-review-plan: REVIEW_EXCLUDE: fallback (WARNING');
|
||||
expect(r.out).toMatch(/READERS: forbid_fetch=0 forbid_paths=1 /);
|
||||
const j = planJson(repo);
|
||||
expect(j.review_exclude.state).toBe('fallback');
|
||||
expect(j.review_exclude.errors).toEqual(['review_exclude_paths: more than 64 patterns']);
|
||||
expect(j.paths).toContain('data/p0/r.json');
|
||||
expect(j.readers.forbid_paths).toEqual(['private/**']);
|
||||
expect(receiptExcludeFallback(j.review_exclude)).toEqual({ source: j.review_exclude.source, errors: ['review_exclude_paths: more than 64 patterns'] });
|
||||
}, 120_000);
|
||||
|
||||
// Value: protects=the PR that fixes the list is planned under the base's (set-aside) list, not its own valid one; fails_when=
|
||||
// the head's 61 patterns are applied before they land; seam=gstack-review-plan --json; no_claim=the land step
|
||||
test('the PR that shortens the list is still planned with nothing excluded', () => {
|
||||
const repo = repoWith({ review_exclude_paths: patterns(65) }, { '.gstack/ship-policy.json': policyText({ review_exclude_paths: patterns(61) }) });
|
||||
const j = planJson(repo);
|
||||
expect(j.review_exclude.state).toBe('fallback');
|
||||
expect(j.paths).toContain('data/p0/r.json');
|
||||
}, 120_000);
|
||||
|
||||
// Value: protects=a valid base list plans exactly as before (negative control); fails_when=a valid list falls back or stops
|
||||
// excluding; seam=gstack-review-plan; no_claim=the excluded file count beyond this fixture
|
||||
test('a valid base list still excludes its files', () => {
|
||||
const repo = repoWith({ review_exclude_paths: patterns(64) });
|
||||
const r = plan(repo);
|
||||
expect(r.status, r.err).toBe(EXIT.ok);
|
||||
expect(r.out).not.toContain('fallback');
|
||||
expect(r.out).toMatch(/REVIEW_EXCLUDE: patterns=1\/64 excluded=1 /);
|
||||
expect(planJson(repo).review_exclude.state).toBe('active');
|
||||
}, 120_000);
|
||||
|
||||
// Value: protects=a branch that adds a list still gets the head-only notice and a normal review (negative control); fails_when=
|
||||
// the head's policy is read; seam=gstack-review-plan; no_claim=other head-only keys
|
||||
test('a list only the head declares is still ignored', () => {
|
||||
const repo = repoWith({}, { '.gstack/ship-policy.json': policyText({ review_exclude_paths: patterns(3) }) });
|
||||
const r = plan(repo);
|
||||
expect(r.status, r.err).toBe(EXIT.ok);
|
||||
expect(r.out).toContain('REVIEW_EXCLUDE: none (head sets review_exclude_paths; it applies after it lands on main) patterns=3');
|
||||
expect(r.out).not.toContain('fallback');
|
||||
}, 120_000);
|
||||
|
||||
// Value: protects=only exclusion errors are set aside: a base with any other invalid key still refuses before any reader;
|
||||
// fails_when=the fallback swallows an error in a key whose default would loosen review or readers; seam=gstack-review-plan
|
||||
// and gstack-ship-queue's loadBasePolicy; no_claim=the wording of the refusal
|
||||
test('a base with another invalid key still refuses, in the plan and in the queue', () => {
|
||||
const repo = repoWith({ review_exclude_paths: patterns(65), review: { panel: 'some' } });
|
||||
const r = plan(repo);
|
||||
expect(r.status).toBe(EXIT.refused);
|
||||
expect(r.err).toContain('POLICY_INVALID');
|
||||
expect(r.out).not.toContain('REVIEW_EXCLUDE: fallback');
|
||||
const q = loadBasePolicy({ repoRoot: repo.work, base: 'main', gh: () => ({ ok: false, out: '' }) });
|
||||
expect('code' in q && q.code).toBe('POLICY_INVALID');
|
||||
}, 120_000);
|
||||
|
||||
// Value: protects=the merge step reads a base that fails only on its exclusion list, with its other keys, so the PR that fixes
|
||||
// the list can land; fails_when=gstack-ship-queue refuses POLICY_INVALID on it; seam=loadBasePolicy; no_claim=land's checks
|
||||
test('the queue reads such a base with its other keys', () => {
|
||||
const repo = repoWith({ review_exclude_paths: patterns(65) });
|
||||
const q = loadBasePolicy({ repoRoot: repo.work, base: 'main', gh: () => ({ ok: false, out: '' }) });
|
||||
expect('code' in q ? q : null).toBeNull();
|
||||
expect('policy' in q && q.policy.review_exclude_paths).toEqual([]);
|
||||
expect('policy' in q && q.policy.readers?.forbid_paths).toEqual(['private/**']);
|
||||
}, 120_000);
|
||||
|
||||
// Value: protects=the setting aside is for reading the base, never for checking it: validate still names the bad list so the
|
||||
// owner fixes it; fails_when=gstack-ship-policy validate --policy-from base reports such a base valid; seam=the validate CLI;
|
||||
// no_claim=validate's other output
|
||||
test('validate still reports the base list as invalid', () => {
|
||||
const repo = repoWith({ review_exclude_paths: patterns(65) });
|
||||
const r = runBin(repo, 'gstack-ship-policy', ['validate', '--policy-from', 'base', '--base', 'main']);
|
||||
expect(r.status).toBe(EXIT.fail);
|
||||
expect(r.out).toContain('POLICY_INVALID: 1 error(s)');
|
||||
expect(r.err).toContain('more than 64 patterns at review_exclude_paths');
|
||||
}, 120_000);
|
||||
|
||||
// Value: protects=show-effective, which /ship's POLICY line and /land-and-deploy's stamp check read, reports such a base valid
|
||||
// with its other keys and the loud fallback line; fails_when=it exits 1 with valid:false (land-and-deploy then reads no
|
||||
// queue_mode) or drops the warning; seam=the show-effective CLI; no_claim=renderEffective's other lines
|
||||
test('show-effective reads the base with its other keys and warns', () => {
|
||||
const repo = repoWith({ review_exclude_paths: patterns(65), queue_mode: 'stamp-at-merge' });
|
||||
const r = runBin(repo, 'gstack-ship-policy', ['show-effective', '--base', 'main', '--json']);
|
||||
expect(r.status, r.err).toBe(EXIT.ok);
|
||||
const j = JSON.parse(r.out);
|
||||
expect({ valid: j.valid, queue_mode: j.policy.queue_mode, excluded: j.policy.review_exclude_paths }).toEqual({ valid: true, queue_mode: 'stamp-at-merge', excluded: [] });
|
||||
expect(r.err).toContain('gstack-ship-policy: REVIEW_EXCLUDE: fallback (WARNING');
|
||||
expect(r.err).not.toContain('POLICY_INVALID');
|
||||
}, 120_000);
|
||||
});
|
||||
@@ -215,6 +215,7 @@ describe('the base policy read', () => {
|
||||
expect(r.err).toContain('POLICY_SOURCE_UNAVAILABLE');
|
||||
|
||||
const bad = census([':(icase)receipts/**']);
|
||||
onBase(bad, { '.gstack/ship-policy.json': JSON.stringify({ review_exclude_paths: [':(icase)receipts/**'], review: { panel: 'some' }, min_gstack_version: REVIEW_EXCLUDE_KEY_VERSION }) + '\n' });
|
||||
const b = plan(bad);
|
||||
expect(b.status).toBe(EXIT.refused);
|
||||
expect(b.err).toContain('review_exclude_paths[0]');
|
||||
@@ -472,7 +473,7 @@ describe('the receipt binds the selection the reviewers read', () => {
|
||||
test('an unreadable base policy still refuses a receipt with no digest or an older one', () => {
|
||||
for (const basePolicy of [null, ['receipts/**']]) {
|
||||
const { repo, body } = shipped(CODE, basePolicy);
|
||||
policyOnBaseOnly(repo, '{ "review_exclude_paths": "receipts/**" }\n');
|
||||
policyOnBaseOnly(repo, '{ "review_exclude_paths": "receipts/**", "review": { "panel": "some" } }\n');
|
||||
const b = bind(repo, body);
|
||||
expect({ basePolicy, ok: b.ok, code: b.ok ? '' : b.code }).toEqual({ basePolicy, ok: false, code: 'POLICY_INVALID' });
|
||||
}
|
||||
@@ -541,7 +542,7 @@ describe('the receipt binds the selection the reviewers read', () => {
|
||||
}, 240_000);
|
||||
|
||||
test('an unreadable or malformed base policy still refuses carry', () => {
|
||||
for (const text of [JSON.stringify({ review_exclude_paths: 'receipts/**', min_gstack_version: REVIEW_EXCLUDE_KEY_VERSION }) + '\n', '{ not json\n']) {
|
||||
for (const text of [JSON.stringify({ review_exclude_paths: 'receipts/**', review: { panel: 'some' }, min_gstack_version: REVIEW_EXCLUDE_KEY_VERSION }) + '\n', '{ not json\n']) {
|
||||
const { repo, body } = shipped(CODE, null);
|
||||
onBase(repo, { '.gstack/ship-policy.json': text });
|
||||
const refused = carry(repo, body);
|
||||
@@ -600,6 +601,23 @@ describe('the receipt binds the selection the reviewers read', () => {
|
||||
expect(receiptIn(body).review_exclude!.digest).toBe(now);
|
||||
}, 240_000);
|
||||
|
||||
// Value: protects=a base whose list no longer validates writes the fallback record and never carries a receipt whose review
|
||||
// left a PR file out; fails_when=write drops review_exclude_fallback or carry accepts the narrower review (GST-3399);
|
||||
// seam=gstack-ship-receipt write and carry; no_claim=the queue's reading of the field
|
||||
test('a base list that is set aside writes the fallback record and refuses carry of the narrower review', () => {
|
||||
const { repo, body } = reviewed();
|
||||
policyOnBaseOnly(repo, policyText(Array.from({ length: 65 }, (_, i) => `data/p${i}/**`)));
|
||||
const w = writeWith(repo, []);
|
||||
expect({ status: w.status, err: w.status === EXIT.ok ? '' : w.err }).toEqual({ status: EXIT.ok, err: '' });
|
||||
const written = receiptIn(path.join(repo.root, 'body-w.md'));
|
||||
expect(written.review_exclude).toBeUndefined();
|
||||
expect(written.review_exclude_fallback!.errors).toEqual(['review_exclude_paths: more than 64 patterns']);
|
||||
repo.git('merge', '-q', '--no-edit', 'origin/main');
|
||||
const refused = carry(repo, body);
|
||||
expect(refused.status).toBe(EXIT.refused);
|
||||
expect(refused.err).toContain('review_exclude changed: recorded=');
|
||||
}, 240_000);
|
||||
|
||||
test('a policy edit that changes the selection over the PR files still refuses write, ready and carry', () => {
|
||||
const changes: Array<{ name: string; after: string[] }> = [
|
||||
{ name: 'a new pattern keeps a PR file', after: ['receipts/**', 'lib/**'] },
|
||||
@@ -630,7 +648,7 @@ describe('the receipt binds the selection the reviewers read', () => {
|
||||
expect({ extra, status: w.status }).toEqual({ extra, status: EXIT.fail });
|
||||
expect(w.err).toContain('field=review_exclude expected=');
|
||||
}
|
||||
policyOnBaseOnly(repo, '{ "review_exclude_paths": "receipts/**" }\n');
|
||||
policyOnBaseOnly(repo, '{ "review_exclude_paths": "receipts/**", "review": { "panel": "some" } }\n');
|
||||
const unreadable = writeWith(repo, ['--review-exclude', digest]);
|
||||
expect(unreadable.status).toBe(EXIT.refused);
|
||||
expect(unreadable.err).toContain('so its review_exclude_paths cannot be read');
|
||||
|
||||
Reference in new issue
Block a user