mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-22 08:01:32 +01:00
READY prints real trial merges and the second-model trail read, plus six small ship-tool fixes (GST-3200) (#4529)
READY now prints each open PR's trial-merge result and the reader of the second-model trail read, or a loud MISSING line, instead of lines left to fill in. Why: agents dropped those lines as noise and skipped the trail read on three gate-class PRs. Six more small ship-tool bugs from 2026-11-19 reports are fixed here too. Nothing to do: pass `--trail ` to `gstack-ship-queue ready` on risk-class PRs. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/outside-voice#1 reader=outside-voice Review-Finding: p1/outside-voice#2 reader=outside-voice Review-Finding: p1/outside-voice#3 reader=outside-voice Review-Finding: p1/outside-voice#4 reader=outside-voice Review-Finding: p1/outside-voice#5 reader=outside-voice Review-Finding: p1/red-team#1 reader=red-team Review-Finding: p1/adversarial-native#4 reader=adversarial-native
This commit is contained in:
1 parent
50cc282273
commit
2714e9f7f3
36 files changed
+503
-68
No files matched your search
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
import { afterEach, describe, expect, setDefaultTimeout, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { placeReceipt } from '../lib/ship-receipt';
|
||||
import { cleanup, makeFixtureRepo, runBin, type FixtureRepo } from './helpers/restamp-fixture';
|
||||
@@ -206,6 +207,10 @@ describe('on Capy, /ship calls no gh write (GST-3183)', () => {
|
||||
expect(out.status, out.stderr).toBe(0);
|
||||
expect(destinations(out.stdout)).toEqual([{ op, target: '7', repo: 'upstream/fx' }]);
|
||||
}
|
||||
const byUrl = r.run('gstack-post', ['pr-comment', 'https://github.com/forker/fx/pull/7', '--body-file', comment]);
|
||||
expect(byUrl.status).toBe(64);
|
||||
expect(byUrl.stdout).not.toContain('HOST_PUBLISH:');
|
||||
expect(byUrl.stderr).toContain('upstream/fx');
|
||||
expect(r.gh.writes()).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -318,3 +323,74 @@ describe('on Capy, gstack-ship-receipt carry calls no gh write (GST-3183)', () =
|
||||
expect(h!.body).toContain(head);
|
||||
});
|
||||
});
|
||||
|
||||
/** The real gh on PATH (on a Capy machine the wrapper's gh.real), pointed at a fake GitHub API on a unix socket it owns. */
|
||||
const REAL_GH = Bun.which('gh.real') ?? Bun.which('gh');
|
||||
async function fakeGithub() {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gh-'));
|
||||
const sock = path.join(dir, 's');
|
||||
const cfg = path.join(dir, 'cfg');
|
||||
fs.mkdirSync(cfg);
|
||||
fs.writeFileSync(path.join(cfg, 'config.yml'), `http_unix_socket: ${sock}\n`);
|
||||
fs.writeFileSync(path.join(dir, 'srv.ts'), [
|
||||
'Bun.serve({ unix: process.argv[2], async fetch(req) {',
|
||||
' let v = {}; try { v = JSON.parse(await req.text()).variables || {}; } catch {}',
|
||||
' const owner = v.owner, name = v.name || v.repo;',
|
||||
" return Response.json({ data: { repository: { id: 'R', name, owner: { login: owner }, nameWithOwner: owner + '/' + name, url: 'https://github.com/' + owner + '/' + name, pullRequest: { id: 'P', number: v.pr_number || 7, body: 'Fixes a thing.\\n' } } } });",
|
||||
'} });', '',
|
||||
].join('\n'));
|
||||
const bin = path.join(dir, 'bin');
|
||||
fs.mkdirSync(bin);
|
||||
fs.symlinkSync(REAL_GH!, path.join(bin, 'gh'));
|
||||
const server = Bun.spawn([process.execPath, path.join(dir, 'srv.ts'), sock], { stdout: 'ignore', stderr: 'ignore' });
|
||||
for (let i = 0; i < 100 && !fs.existsSync(sock); i++) await Bun.sleep(50);
|
||||
const env = { PATH: `${bin}:${process.env.PATH}`, GH_CONFIG_DIR: cfg, GH_TOKEN: 'fake', GH_HOST: 'github.com', GH_ENTERPRISE_TOKEN: '', GH_NO_UPDATE_NOTIFIER: '1', GH_PROMPT_DISABLED: '1' };
|
||||
return { env, stop: () => { server.kill(); fs.rmSync(dir, { recursive: true, force: true }); } };
|
||||
}
|
||||
|
||||
describe('GH_REPO and fork heads on the HOST_PUBLISH hand-off (#4518 follow-up)', () => {
|
||||
// Value: protects=with GH_REPO set, both hand-off paths name the repository gh's own write would have used, as real gh
|
||||
// resolves it (gh repo view ignores GH_REPO; gh pr view and edit honour it); fails_when=the destination read drops GH_REPO
|
||||
// and names origin's repository; seam=bin/gstack-post and bin/gstack-ship-receipt with real gh over a fake API socket
|
||||
test.skipIf(!REAL_GH || process.platform === 'win32')('real gh: gstack-post and stub name GH_REPO, not origin', async () => {
|
||||
const r = capyRepo();
|
||||
r.githubOrigin();
|
||||
r.f.git('remote', 'set-url', 'origin', 'https://github.com/forker/fx.git');
|
||||
const gh = await fakeGithub();
|
||||
try {
|
||||
const comment = path.join(r.f.root, 'c.md');
|
||||
fs.writeFileSync(comment, 'A plain comment.\n');
|
||||
const post = r.run('gstack-post', ['pr-comment', '7', '--body-file', comment], { ...gh.env, GH_REPO: 'upstream/fx' });
|
||||
expect(post.status, post.stderr).toBe(0);
|
||||
expect(destinations(post.stdout)).toEqual([{ op: 'pr-comment', target: '7', repo: 'upstream/fx' }]);
|
||||
const stub = r.run('gstack-ship-receipt', ['stub', '--pr', '7', '--run', 'r1'], { ...gh.env, GH_REPO: 'upstream/fx' });
|
||||
expect(stub.status, stub.stderr).toBe(0);
|
||||
expect(destinations(stub.stdout)).toEqual([{ op: 'pr-body', target: '7', repo: 'upstream/fx' }]);
|
||||
} finally { gh.stop(); }
|
||||
});
|
||||
|
||||
// Value: protects=a pr-create hand-off from a fork checkout names owner:branch, as gh pr create would, and refuses when the
|
||||
// fork is on another host; fails_when=head= is the bare branch, which the base repository reads as its own; seam=bin/gstack-post
|
||||
test('a fork pr-create names the head as origin-owner:branch, or refuses across hosts', () => {
|
||||
const title = (r: ReturnType<typeof capyRepo>) => { const t = path.join(r.f.root, 't.txt'); fs.writeFileSync(t, 'Add a thing for users\n'); return t; };
|
||||
const body = (r: ReturnType<typeof capyRepo>) => { const b = path.join(r.f.root, 'b.md'); fs.writeFileSync(b, 'Adds a thing for users.\n\n## Why\n\nBecause.\n'); return b; };
|
||||
const r = capyRepo({ nameWithOwner: 'upstream/fx', url: 'https://github.com/upstream/fx' });
|
||||
r.githubOrigin();
|
||||
r.f.git('remote', 'set-url', 'origin', 'https://github.com/forker/fx.git');
|
||||
const branch = r.f.git('branch', '--show-current').stdout.trim();
|
||||
const n = r.run('gstack-post', ['pr-create', '--base', 'main', '--title-file', title(r), '--body-file', body(r)]);
|
||||
expect(n.status, n.stderr).toBe(0);
|
||||
expect(destinations(n.stdout)).toEqual([{ op: 'pr-create', target: 'new', repo: 'upstream/fx', base: 'main', head: `forker:${branch}` }]);
|
||||
const named = r.run('gstack-post', ['pr-create', '--base', 'main', '--head', 'someone:topic', '--title-file', title(r), '--body-file', body(r)]);
|
||||
expect(destinations(named.stdout)).toEqual([{ op: 'pr-create', target: 'new', repo: 'upstream/fx', base: 'main', head: 'someone:topic' }]);
|
||||
const far = capyRepo({ nameWithOwner: 'upstream/fx', url: 'https://github.acme.test/upstream/fx' });
|
||||
far.githubOrigin();
|
||||
far.f.git('remote', 'set-url', 'origin', 'https://github.com/forker/fx.git');
|
||||
const refused = far.run('gstack-post', ['pr-create', '--base', 'main', '--title-file', title(far), '--body-file', body(far)]);
|
||||
expect(refused.status).toBe(64);
|
||||
expect(refused.stdout).not.toContain('HOST_PUBLISH:');
|
||||
expect(refused.stderr).toContain('pass --head <owner>:<branch>');
|
||||
expect([...r.gh.writes(), ...far.gh.writes()]).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -789,3 +789,48 @@ describe('printed gate-ahead command (review #3235 P2-1)', () => {
|
||||
expect(line(r.stdout, 'GATE_RECORD:')).toMatch(new RegExp(`^GATE_RECORD: pr=2 attempt=${p.attempt} exit=0 `));
|
||||
}, 180_000);
|
||||
});
|
||||
|
||||
describe('the READY tail ready fills in: TRIAL_MERGES and the cross-family trail read (GST-3200)', () => {
|
||||
// Value: protects=READY carries a computed trial-merge line per open PR sharing a file and a reviewer line read from the trail,
|
||||
// or MISSING, never a template line a lane can cut; fails_when=ready prints the TRIAL_MERGES or reviewed by <model ...>
|
||||
// placeholder (three gate-class PRs skipped the rule 27 read on 11-19); seam=bin/gstack-ship-queue ready with a gh shim
|
||||
test('one line per sibling from git merge-tree, and the reviewer from the trail-read row, else MISSING', () => {
|
||||
const repo = fixture();
|
||||
const sibling = (branch: string, files: Record<string, string>, pr: string) => {
|
||||
repo.git('checkout', '-q', 'origin/main', '-b', branch);
|
||||
for (const [f, text] of Object.entries(files)) fs.writeFileSync(path.join(repo.work, f), text);
|
||||
repo.git('add', '-A'); repo.git('commit', '-q', '-m', branch);
|
||||
publish(repo, pr);
|
||||
return repo.git('rev-parse', 'HEAD');
|
||||
};
|
||||
const conflict = sibling('pr-b', { 'pr-a.txt': 'other\n' }, '2');
|
||||
const clean = sibling('pr-c', { 'pr-a.txt': 'pr-a\n', 'c.txt': 'c\n' }, '3');
|
||||
const apart = sibling('pr-d', { 'd.txt': 'd\n' }, '4');
|
||||
const head = makePr(repo, 'pr-a', { changelog: false });
|
||||
const tree = runBin(repo, 'gstack-wtree', []).out.trim();
|
||||
const pregate = path.join(repo.root, 'pregate.json');
|
||||
fs.writeFileSync(pregate, JSON.stringify({ schema_version: 1, tree, head, verdict: 'pass', checks: FULL_CHECKS }));
|
||||
const files = (...p: string[]) => p.map(f => ({ path: f }));
|
||||
const list = [{ number: 1, headRefOid: head, files: files('pr-a.txt') }, { number: 2, headRefOid: conflict, files: files('pr-a.txt') }, { number: 3, headRefOid: clean, files: files('pr-a.txt', 'c.txt') }, { number: 4, headRefOid: apart, files: files('d.txt') }];
|
||||
const green = { check_runs: [{ status: 'completed', conclusion: 'success' }] };
|
||||
const prs = { '1': { headRefOid: head, body: shippedBody('1', head), headRefName: 'pr-a' } };
|
||||
const trail = path.join(repo.root, 'decisions.tsv');
|
||||
fs.writeFileSync(trail, 'ts\tphase\tdecision\twhy\tevidence\tresult\n2026-11-19T00:00:00Z\tstart\trun x opens this trail\tno earlier rows\trun:x\topen\n2026-11-19T00:01:00Z\ttrail-read\topenai/gpt-6.2-sol (Subagent 4)\trule 27\tflags.md\tNo flags\n');
|
||||
const r = queue(repo, ['ready', '--pr', '1', '--pregate', pregate, '--trail', trail], ghQueueShim(repo, { prs, checks: { [head]: green }, list }));
|
||||
expect(r.status, r.err).toBe(EXIT.ok);
|
||||
const cleanTree = repo.git('merge-tree', '--write-tree', head, clean);
|
||||
expect(r.out.split('\n').filter(l => l.startsWith('TRIAL_MERGES: '))).toEqual([
|
||||
`TRIAL_MERGES: #2 ${conflict.slice(0, 12)} shares pr-a.txt: CONFLICT in pr-a.txt; the lane states the resolution`,
|
||||
`TRIAL_MERGES: #3 ${clean.slice(0, 12)} shares pr-a.txt: merge-tree clean (tree ${cleanTree.slice(0, 12)})`,
|
||||
]);
|
||||
expect(line(r.out, 'Attention:')).toBe('Attention:');
|
||||
expect(r.out).toContain('\nreviewed by openai/gpt-6.2-sol (Subagent 4) (risk class unknown: the receipt records no review_depth; rule 27 cross-family trail read, trail row 2)\n');
|
||||
expect(r.out).not.toContain('<model on another family>');
|
||||
const bare = queue(repo, ['ready', '--pr', '1', '--pregate', pregate], ghQueueShim(repo, { prs, checks: { [head]: green } }));
|
||||
expect(line(bare.out, 'TRIAL_MERGES: ')).toStartWith('TRIAL_MERGES: MISSING: cannot list the open PRs into main through gh');
|
||||
expect(line(bare.out, 'MISSING: cross-family')).toStartWith('MISSING: cross-family trail read (risk class unknown: the receipt records no review_depth; rule 27): ready got no --trail <decisions.tsv>;');
|
||||
const alone = queue(repo, ['ready', '--pr', '1', '--pregate', pregate], ghQueueShim(repo, { prs, checks: { [head]: green }, list: [list[0], list[3]] }));
|
||||
expect(line(alone.out, 'TRIAL_MERGES: ')).toBe('TRIAL_MERGES: none share a file (1 open PRs checked)');
|
||||
}, 240_000);
|
||||
});
|
||||
|
||||
@@ -83,15 +83,16 @@ export function gbrainPairRepo(): { repo: FixtureRepo; pair: GbrainPair; gated:
|
||||
* entry has no commit-status contexts, as on GitHub. A check run marked
|
||||
* earlier_attempt belongs to a superseded workflow-run attempt: like GitHub's
|
||||
* default filter=latest, the shim hides it unless the call asks for filter=all.
|
||||
* workflowRuns answers actions/runs?head_sha=<sha> the same way (none by default).
|
||||
* workflowRuns answers actions/runs?head_sha=<sha> the same way (none by default). list answers gh pr list (a failure when absent).
|
||||
*/
|
||||
export function ghQueueShim(repo: FixtureRepo, data: { prs: Record<string, unknown>; checks: Record<string, unknown>; statuses?: Record<string, unknown>; workflowRuns?: Record<string, unknown> }): { PATH: string } {
|
||||
export function ghQueueShim(repo: FixtureRepo, data: { prs: Record<string, unknown>; checks: Record<string, unknown>; statuses?: Record<string, unknown>; workflowRuns?: Record<string, unknown>; list?: unknown[] }): { PATH: string } {
|
||||
const dir = path.join(repo.root, 'gh-queue-shim');
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
fs.writeFileSync(path.join(dir, 'data.json'), JSON.stringify(data));
|
||||
const js = [
|
||||
"const d = require(process.argv[2]); const a = process.argv.slice(3);",
|
||||
"if (a[0] === 'pr' && a[1] === 'view') { const p = d.prs[a[2]]; if (!p) { console.error('no pull request found'); process.exit(1); } console.log(JSON.stringify(p)); process.exit(0); }",
|
||||
"if (a[0] === 'pr' && a[1] === 'list') { if (!d.list) { console.error('gh shim: no pr list'); process.exit(1); } console.log(JSON.stringify(d.list)); process.exit(0); }",
|
||||
"const paged = (c, key, page) => { if (c.pages) return c.pages[page - 1] || { total_count: c.pages.reduce((n, p) => n + p[key].length, 0), [key]: [] }; const total = c.total_count ?? c[key].length; return page === 1 ? { total_count: total, ...c } : { total_count: total, [key]: [] }; };",
|
||||
"const latestOnly = (c, url) => /[?&]filter=all(&|$)/.test(url) || !c || !Array.isArray(c.check_runs) || !c.check_runs.some(r => r.earlier_attempt) ? c : { check_runs: c.check_runs.filter(r => !r.earlier_attempt) };",
|
||||
"if (a[0] === 'api') { const w = /actions\\/runs\\?head_sha=([0-9a-f]+).*page=(\\d+)/.exec(a[1] || ''); if (w) { console.log(JSON.stringify(paged((d.workflowRuns || {})[w[1]] || { workflow_runs: [] }, 'workflow_runs', Number(w[2])))); process.exit(0); } }",
|
||||
|
||||
@@ -249,7 +249,7 @@ function shimSource(): string {
|
||||
"}",
|
||||
"if (a[0] === 'pr' && a[1] === 'comment') { const p = d.prs[a[2]]; if (!p) fail('no pull request found'); p.comments = [...(p.comments || []), { body: opt('--body') }]; out({}); }",
|
||||
"if (a[0] === 'pr' && a[1] === 'close') { const p = d.prs[a[2]]; if (!p) fail('no pull request found'); p.state = 'CLOSED'; out({}); }",
|
||||
"if (a[0] === 'pr' && a[1] === 'list') { const head = opt('--head'); const st = opt('--state'); out(Object.entries(d.prs).filter(([, p]) => (!head || p.headRefName === head) && (st !== 'open' || p.state === 'OPEN')).map(([n, p]) => ({ number: Number(n), state: p.state, headRefOid: p.headRefOid, baseRefName: p.baseRefName || 'main', mergeCommit: p.mergeCommit || null }))); }",
|
||||
"if (a[0] === 'pr' && a[1] === 'list') { const head = opt('--head'); const st = opt('--state'); out(Object.entries(d.prs).filter(([, p]) => (!head || p.headRefName === head) && (st !== 'open' || p.state === 'OPEN')).map(([n, p]) => ({ number: Number(n), state: p.state, headRefOid: p.headRefOid, baseRefName: p.baseRefName || 'main', mergeCommit: p.mergeCommit || null, files: p.files || [] }))); }",
|
||||
"fail('gh shim: unsupported ' + a.join(' '));",
|
||||
].join('\n') + '\n';
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { buildRow, locate, type ApprovalRow } from '../lib/approval-record';
|
||||
import { exemptReason, finishPlan, landPlan, parsePlanLine, planMode, planRecordId, publicPlanLine, readyPlan, resolvePlan } from '../lib/plan-record';
|
||||
import { exemptReason, finishPlan, finishPlanLine, landPlan, parsePlanLine, planMode, planRecordId, publicPlanLine, readyPlan, recordFinishPlan, resolvePlan } from '../lib/plan-record';
|
||||
import { planBinding } from '../lib/ship-audit';
|
||||
import { loadReady, persist, repoIdentity } from '../crew/lib/ship-queue-train-record';
|
||||
|
||||
@@ -407,3 +407,33 @@ describe('public repos: the record-keyed Plan line and the machine-local key (GS
|
||||
expect(config('get', 'plan_record').stdout.trim()).toBe('warn');
|
||||
});
|
||||
});
|
||||
|
||||
describe('bug-fix exemption wording and the plan finish recorded (GSTA-649, GSTA-617)', () => {
|
||||
// Value: protects=a stated bug-fix exemption resolves whatever its wording, and a PR whose body has no Plan line takes the line
|
||||
// /ship finish resolved on this checkout, which land then accepts; fails_when=ready warns PLAN_EXEMPT_UNKNOWN or
|
||||
// PLAN_RECORD_MISSING after finish recorded Plan: exempt: bug fix; seam=exemptReason, finishPlan, readyPlan, landPlan
|
||||
test('bug fix variants are the bug fix exemption', () => {
|
||||
for (const r of ['bug fix with failing-first tests', 'Bugfix', 'bug-fix: retry backoff', 'bug fixes (R65)']) expect(exemptReason(r)).toBe('bug fix');
|
||||
expect(exemptReason('bugfixing everything')).toBeNull();
|
||||
});
|
||||
test('ready reads the Plan line finish resolved when the body has none, and land accepts it', () => {
|
||||
const f = fixture();
|
||||
const env = { ...f.env, GSTACK_PLAN_RECORD: 'require' };
|
||||
spawnSync('git', ['-c', 'user.name=Fixture', '-c', 'user.email=fixture@example.com', 'commit', '-q', '--allow-empty', '-m', 'seed'], { cwd: f.cwd, timeout: 30_000 });
|
||||
const head = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: f.cwd, encoding: 'utf8', timeout: 30_000 }).stdout.trim();
|
||||
const fin = finishPlan(f.cwd, 'main', 'Plan: exempt: bug fix', env);
|
||||
expect(fin.line).toBe('PLAN: exempt bug fix');
|
||||
recordFinishPlan(f.cwd, fin.record);
|
||||
const ready = readyPlan({ cwd: f.cwd, env, body: 'Fixes a thing.', changed: ['lib/x.ts'], finishLine: finishPlanLine(f.cwd, 'capy/feature', head) });
|
||||
expect(ready.failure).toBeUndefined();
|
||||
expect(ready.record).toMatchObject({ line: 'Plan: exempt: bug fix', state: 'exempt', reason: 'bug fix', from: 'finish' });
|
||||
expect(ready.line).toContain("from /ship finish's plan record");
|
||||
expect(landPlan({ env, record: ready.record, body: 'Fixes a thing.' }).failure).toBeUndefined();
|
||||
expect(finishPlanLine(f.cwd, 'other-branch', head)).toBeUndefined();
|
||||
expect(finishPlanLine(f.cwd, 'capy/feature', '0'.repeat(40))).toBeUndefined();
|
||||
expect(readyPlan({ cwd: f.cwd, env, body: 'Plan: exempt: flaky', changed: ['lib/x.ts'], finishLine: finishPlanLine(f.cwd, 'capy/feature', head) }).record).toMatchObject({ reason: 'flaky' });
|
||||
recordFinishPlan(f.cwd, undefined);
|
||||
expect(finishPlanLine(f.cwd, 'capy/feature', head)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -64,6 +64,15 @@ describe('gstack-approvals round-grant', () => {
|
||||
expect(r.run('gstack-approvals', ['round-grant', '--pr', '5', '--head', r.head, '--kind', 'more', '--reason', 'x', '--by', 'lane']).status).toBe(2);
|
||||
expect(r.run('gstack-approvals', ['add', '--ask', 'a', '--words', 'w', '--by', 'b', '--scope', `review_round_grant ${r.head} pr=5 kind=extra-round`]).status).toBe(2);
|
||||
});
|
||||
|
||||
// Value: protects=a Captain whose crew name starts with gstack can grant a round, while gstack's own names stay refused;
|
||||
// fails_when=the self-grant check matches a prefix (gstack-evals Captain refused, #4518 follow-up); seam=bin/gstack-approvals
|
||||
test('a --by that only starts with gstack is a crew, not gstack: gstack-evals Captain records a grant', () => {
|
||||
const r = repo();
|
||||
for (const by of ['gstack', 'GStack', ' gstack no-stop default (K1) ']) expect(r.run('gstack-approvals', ['round-grant', '--pr', '5', '--head', r.head, '--kind', 'extra-round', '--reason', 'x', '--by', by]).status).toBe(2);
|
||||
const ok = r.run('gstack-approvals', ['round-grant', '--pr', '5', '--head', r.head, '--kind', 'extra-round', '--reason', 'x', '--by', 'gstack-evals Captain']);
|
||||
expect([ok.status, ok.stderr]).toEqual([0, '']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('gstack-ship-receipt history and stub', () => {
|
||||
|
||||
@@ -4,6 +4,8 @@ import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { parseReviewTargeted, plainDocsSince, targetedClassesSince } from '../lib/ship-receipt-depth';
|
||||
import { targetedPatchId } from '../lib/review-targeted';
|
||||
import { targetedDelta } from '../lib/review-targeted-delta';
|
||||
|
||||
const BIN = path.join(import.meta.dir, '..', 'bin');
|
||||
const dirs: string[] = [];
|
||||
@@ -166,3 +168,18 @@ describe('GST-1598: a post-review docs delta that trips a targeted claim gets on
|
||||
expect(rendered.map(e => [e.reader, e.diff_base, e.head, e.classes])).toEqual([['targeted', mergeBase, r.git('rev-parse', 'HEAD'), ['money']]]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('a targeted read on a non-ASCII path (#4520 ruled note)', () => {
|
||||
// Value: protects=the patch-id the targeted record stores and the one targetedDelta recomputes hash the same diff text when a
|
||||
// path is non-ASCII, so a plain-docs follow-up carries the read; fails_when=targetedPatchId quotes the path (core.quotePath
|
||||
// default) while the check does not, and the read never matches; seam=targetedPatchId and targetedDelta over a real git repo
|
||||
test('a plain-docs change after the read carries it instead of refusing --targeted-ran', () => {
|
||||
const r = reviewed({}, { 'src/caf\u00e9/billing.ts': MONEY_CODE });
|
||||
const read = r.git('rev-parse', 'HEAD');
|
||||
const ran = targetedPatchId(r.dir, r.git('merge-base', 'main', 'HEAD'));
|
||||
expect(ran).toMatch(/^[0-9a-f]{40}$/);
|
||||
r.commit({ 'docs/notes.md': '# Notes\n\nA plain paragraph.\n' }, 'docs');
|
||||
expect(targetedDelta(r.dir, 'main', read, ran)).toEqual({ state: 'skip', reason: expect.stringContaining('plain docs'), carried: true });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,6 +20,7 @@ describe('review round grants', () => {
|
||||
test('only an approved row that gstack did not write counts, and it binds only its head and PR', () => {
|
||||
expect(reviewRoundGrants([row({ outcome: 'pending' as any })])).toEqual([]);
|
||||
expect(reviewRoundGrants([row({ by: 'gstack' })])).toEqual([]);
|
||||
expect(reviewRoundGrants([row({ by: 'gstack-evals Captain' })]).map(g => g.by)).toEqual(['gstack-evals Captain']);
|
||||
const gs = reviewRoundGrants([row({})]);
|
||||
expect(grantAt(gs, 12, head)).toBeDefined();
|
||||
expect(grantAt(gs, 13, head)).toBeUndefined();
|
||||
|
||||
@@ -149,3 +149,39 @@ describe('the full approvals table', () => {
|
||||
expect(out).toContain(`ruled_note src/x.ts:1:naming at ${HEAD}: naming ships as a note`);
|
||||
});
|
||||
});
|
||||
|
||||
// Value: protects=a red-team finding the owner ruled not security class (gstack-evals #380: a statistics fix) shows its location
|
||||
// and reason in public text, the receipt validates and the public-text guards pass it, while security, auth and secret
|
||||
// findings cannot take the exemption; fails_when=every red-team ruling prints "security finding, details recorded privately",
|
||||
// or the exemption reaches a security-category finding; seam=gstack-approvals rule|rulings and gstack-ship-receipt write
|
||||
describe('a red-team finding the owner ruled not security class (gstack-evals #380)', () => {
|
||||
test.skipIf(process.platform === 'win32')('rule --not-security prints the finding; a security category refuses the flag', () => {
|
||||
const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n' }, { 'src/x.ts': 'export const x = 2;\n' });
|
||||
ships.push(f);
|
||||
fs.writeFileSync(path.join(f.root, 'stub', 'gh'), '#!/bin/sh\ncase "$*" in *visibility*) echo PUBLIC ;; *) exit 1 ;; esac\n', { mode: 0o755 });
|
||||
const run = (bin: string, args: string[]) => f.run(path.join(BIN, bin), args, { GSTACK_APPROVALS_MIRROR: '0' });
|
||||
const head = f.git('rev-parse', 'HEAD').stdout.trim();
|
||||
const reason = 'the routing pilot picks its four extra tasks before the seed is fixed';
|
||||
const rule = (finding: string, extra: string[]) => run('gstack-approvals', ['rule', '--finding', finding, '--head', head, '--reason', reason, '--words', 'a note, fix it by a dated change', '--by', 'Fixture Owner', ...extra]);
|
||||
expect(rule('src/x.ts:1:security', ['--not-security']).status).toBe(EXIT.usage);
|
||||
const marker = path.resolve(f.work, f.git('rev-parse', '--git-path', 'gstack-ship-run').stdout.trim());
|
||||
fs.writeFileSync(marker, 'ship-run-1\n');
|
||||
const inRun = rule('src/x.ts:2:red-team', ['--not-security', '--owner-ref', 'GSTA-36:2026-11-19T12:29:59Z']);
|
||||
expect(inRun.status).toBe(EXIT.usage);
|
||||
expect(inRun.stderr).toContain('--not-security');
|
||||
fs.rmSync(marker);
|
||||
expect(run('gstack-approvals', ['rulings']).stdout).not.toContain('src/x.ts:2');
|
||||
const ruled = rule('src/x.ts:1:red-team', ['--not-security']);
|
||||
expect(ruled.status, ruled.stderr).toBe(0);
|
||||
const line = run('gstack-approvals', ['rulings']).stdout.trim();
|
||||
expect(line).toStartWith(`Ruled note: src/x.ts:1 (red-team, ruled not security class) at ${head.slice(0, 12)} ruled by Fixture Owner at `);
|
||||
expect(line).toContain(reason);
|
||||
expect(securityFingerprints(line)).toEqual([]);
|
||||
const body = path.join(f.root, 'body.md');
|
||||
fs.writeFileSync(body, `## Pre-Landing Review\n\n${line}\n`);
|
||||
const write = f.run(path.join(BIN, 'gstack-ship-receipt'), ['write', '--pr', '7', '--base', 'main', '--version', '1.0.0', '--session-kind', 'unattended', '--body', body], { GSTACK_APPROVALS_MIRROR: '0' });
|
||||
expect(write.status, write.stderr).toBe(EXIT.ok);
|
||||
expect(fs.readFileSync(body, 'utf8')).toContain('"not_security": true');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -492,3 +492,34 @@ describe('a granted fix-check that found new CRITICALs the owner accepted (harne
|
||||
expect(r.stdout).toContain('STOP: behavior, tests or build inputs changed since review (src/x.ts)');
|
||||
});
|
||||
});
|
||||
|
||||
// Value: protects=a ruling relayed into an open /ship run records the owner's words with a checkable source and says so in the
|
||||
// row, the Ruled note line and the receipt, while a ruling with no owner reference still refuses under its own code;
|
||||
// fails_when=the refusal reads APPROVAL_RECORD_INVALID and points at add (GBRA-108), or a relayed ruling cannot be recorded
|
||||
// or is not marked relayed; seam=gstack-approvals rule|rulings|list and gstack-ship-receipt write
|
||||
describe('a ruling relayed into an open /ship run (GBRA-108, gbrain #9762)', () => {
|
||||
test('without --owner-ref it refuses as APPROVAL_RULING_RUN_OPEN; with one it records and marks the ruling relayed', () => {
|
||||
const { f, passHead } = grantedFixCheck(QM3122);
|
||||
const marker = path.resolve(f.work, f.git('rev-parse', '--git-path', 'gstack-ship-run').stdout.trim());
|
||||
fs.writeFileSync(marker, 'ship-9762-abc\n');
|
||||
const bare = rule(f, RACE, passHead, 'GBrain Minder (GBRA-108)');
|
||||
expect([bare.status, bare.stderr]).toEqual([EXIT.usage, expect.stringContaining('(APPROVAL_RULING_RUN_OPEN)')]);
|
||||
expect(bare.stderr).not.toContain('APPROVAL_RECORD_INVALID');
|
||||
expect(bare.stderr).not.toContain('gstack-approvals add');
|
||||
const relay = (ref: string) => run(f, 'gstack-approvals', ['rule', '--finding', RACE, '--head', passHead, '--reason', 'ships as a disclosed note', '--words', 'B, note it', '--by', 'GBrain Minder (GBRA-108)', '--owner-ref', ref]);
|
||||
expect(relay('just words').status).toBe(EXIT.usage);
|
||||
const ok = relay('GBRA-108:2026-11-19T12:29:59Z');
|
||||
expect(ok.status, ok.stderr).toBe(0);
|
||||
const rows = JSON.parse(run(f, 'gstack-approvals', ['list', '--json']).stdout).rows as Array<{ source: string; words: string }>;
|
||||
expect(rows.find(r => r.source === 'relayed:GBRA-108:2026-11-19T12:29:59Z')?.words).toBe('B, note it');
|
||||
const line = run(f, 'gstack-approvals', ['rulings']).stdout.trim();
|
||||
expect(line).toContain('ruled by GBrain Minder (GBRA-108) (relayed from GBRA-108:2026-11-19T12:29:59Z) at ');
|
||||
fs.rmSync(marker);
|
||||
const body = path.join(f.root, 'relayed-body.md');
|
||||
fs.writeFileSync(body, `## Pre-Landing Review\n\n${line}\n`);
|
||||
const write = f.run(path.join(BIN, 'gstack-ship-receipt'), ['write', '--pr', '7', '--base', 'main', '--version', '1.0.0', '--session-kind', 'unattended', '--body', body], { GSTACK_APPROVALS_MIRROR: '0' });
|
||||
expect(write.status, write.stderr).toBe(0);
|
||||
expect(fs.readFileSync(body, 'utf8')).toContain('"relayed": "GBRA-108:2026-11-19T12:29:59Z"');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,7 +50,8 @@ describe('READY tail (E1: the ready output is the whole READY)', () => {
|
||||
const depth = (cls: 'docs' | 'code' | 'gate', risk?: Array<'money' | 'auth' | 'secret' | 'security' | 'data'>) =>
|
||||
({ depth: 'full' as const, class: cls, runtime_lines: 10, rules: 'r', base: 'b', registry: null, gate_scan: { tagged: 0, head: 'h' }, reasons: [], ...(risk ? { risk } : {}) });
|
||||
test('a risk-class receipt asks for the cross-family read; any other PR is self-audited', () => {
|
||||
expect(readyTailLines({ ...receipt('f'.repeat(40)), review_depth: depth('gate') })[3]).toStartWith('reviewed by <model on another family> (risk class: gate;');
|
||||
expect(readyTailLines({ ...receipt('f'.repeat(40)), review_depth: depth('gate') })[3]).toStartWith('MISSING: cross-family trail read (risk class: gate; rule 27): ready did not look for one;');
|
||||
expect(readyTailLines({ ...receipt('f'.repeat(40)), review_depth: depth('gate') }, { trialMerges: ['TRIAL_MERGES: none share a file (3 open PRs checked)'], trailRead: { row: 7, reader: 'openai/gpt-6.2-sol' } }).slice(1, 4)).toEqual(['TRIAL_MERGES: none share a file (3 open PRs checked)', 'Attention:', 'reviewed by openai/gpt-6.2-sol (risk class: gate; rule 27 cross-family trail read, trail row 7)']);
|
||||
expect(readyTailLines({ ...receipt('f'.repeat(40)), review_depth: depth('code', ['money']) })[3]).toContain('risk class: money');
|
||||
expect(readyTailLines({ ...receipt('f'.repeat(40)), review_depth: depth('docs') })[3]).toBe('self-audited (not a risk class: no cross-family trail read)');
|
||||
});
|
||||
@@ -59,7 +60,7 @@ describe('READY tail (E1: the ready output is the whole READY)', () => {
|
||||
expect(lines[0]).toBe('REVIEW_LOOP: passes=2 blocking_found=3 deferred=0 noted=0 fixed=2 unrecorded=1 unbound=1');
|
||||
expect(lines.slice(1, 3)).toEqual([expect.stringMatching(/^TRIAL_MERGES: /), 'Attention:']);
|
||||
expect(readyTailLines(undefined)[0]).toBe('REVIEW_LOOP: none in the receipt');
|
||||
expect(readyTailLines(receipt('f'.repeat(40)))[3]).toStartWith('reviewed by <model on another family> (risk class unknown: the receipt records no review_depth');
|
||||
expect(readyTailLines(receipt('f'.repeat(40)))[3]).toStartWith('MISSING: cross-family trail read (risk class unknown: the receipt records no review_depth; rule 27)');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import { afterEach, describe, expect, setDefaultTimeout, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { finishPlanLine } from '../lib/plan-record';
|
||||
import { RESULT_CODES } from '../lib/result-codes';
|
||||
import { BUMP_NEVER_KEY_VERSION } from '../lib/ship-policy';
|
||||
import { lineOf, RELEASE, shipFixture, type ShipFx } from './helpers/ship-bin-fixture';
|
||||
@@ -191,6 +192,7 @@ describe('finish (Steps 15-16)', () => {
|
||||
expect(ok.stdout.split('\n')[0]).toBe('PLAN: exempt bug fix');
|
||||
expect(ok.stdout).toMatch(/^COMMIT: /m);
|
||||
expect(ok.status).toBe(0);
|
||||
expect(finishPlanLine(f.work, f.git('branch', '--show-current').stdout.trim(), f.git('rev-parse', 'HEAD').stdout.trim())).toBe('Plan: exempt: bug fix');
|
||||
});
|
||||
|
||||
// Value: protects=under changelog_fragments the branch's own fragment is release metadata: version writes nothing and names it in NEXT, finish commits it as the release commit and the route counts it as metadata, and another fragment is still a feature file; fails_when=finish stops on changelog.d/<slug>.md or routes it to re-review (/ship #3648 fix-check 4, CRITICAL);
|
||||
|
||||
Reference in new issue
Block a user