mirror of
https://github.com/garrytan/gstack.git
synced 2026-12-01 04:13:55 +01:00
Stop false phone-number holds on /ship run ids and name interactive /autoplan runs (#4747)
Posting a PR body that lists earlier /ship runs no longer stops for a "phone number" that is really a run id, and an interactive /autoplan approval is imported under its own run id instead of `autoplan`. Every /ship that rewrote a body holding earlier runs waited for a confirmation (#4725; about 1 in 10 run ids also reads as a card number and still asks, fixed in a follow-up), and interactive /autoplan runs could not be cited by run id (#4402). Nothing to do after merge. Co-authored-by: thomsjack <325974127+thomsjack@users.noreply.github.com> 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: p2/red-team#1 reader=red-team Review-Finding: p2/outside-voice#1 reader=outside-voice Review-Finding: p2/outside-voice#2 reader=outside-voice
This commit is contained in:
10 files changed
+254
-18
No files matched your search
@@ -389,6 +389,105 @@ describe('import --autoplan', () => {
|
||||
expect(typed.status).not.toBe(0);
|
||||
});
|
||||
|
||||
// Value: protects=a run id interactive /autoplan minted before #4402 (<branch>-<YYYYMMDD-HHMMSS>) imports on a branch whose name ends in
|
||||
// digits, as the 14-digit minted shape does (GST-2047), while a phone number in the same row, a run id of another shape, a phone number
|
||||
// in the name half of the id, or the same id typed into add --ask still refuses; fails_when=an approval answered before the upgrade cannot
|
||||
// be imported after it, or the exemption reaches past the stamp; why_new=the GST-2047 test covers only the 14-digit stamp; seam=none
|
||||
test('an interactive run id minted before #4402 imports on a numbered branch; a phone number elsewhere still refuses', () => {
|
||||
const importWith = (o: { runId: string; words?: string }) => {
|
||||
const run = tmp('appr-run-');
|
||||
autoplanRun(run, [{ by: 'agent:GSTA-36', words: o.words ?? 'do it', at: '2026-11-22T09:40:00.000Z', p1: 'a' }]);
|
||||
fs.writeFileSync(path.join(run, 'run.json'), JSON.stringify({ run: o.runId, status: 'complete' }));
|
||||
return importAutoplan(run, 'b', 'Garry');
|
||||
};
|
||||
for (const runId of ['fix-4402-20261122-093321', 'gsta-802-20261122-093321', 'fix-12-20261122-093321']) {
|
||||
const rows = importWith({ runId });
|
||||
expect([runId, 'code' in rows ? rows.message : rows[0]!.source]).toEqual([runId, `autoplan:${runId}@gate_rev=1`]);
|
||||
}
|
||||
const refused: Array<[{ runId: string; words?: string }, string]> = [
|
||||
[{ runId: 'fix-4402-20261122-093321', words: 'do it, call 14155552671 if it breaks' }, 'words'],
|
||||
[{ runId: 'fix-4402-20261122-0933' }, 'ask'],
|
||||
[{ runId: 'fix-4402-20261399-093321' }, 'ask'],
|
||||
[{ runId: 'fix-4402-20261122-993321' }, 'ask'],
|
||||
[{ runId: 'call-415-555-2671-20261122-093321' }, 'ask'],
|
||||
[{ runId: '14155552671-20261122-093321' }, 'source'],
|
||||
];
|
||||
for (const [o, field] of refused) {
|
||||
const r = importWith(o);
|
||||
expect([o, 'code' in r && r.code, 'code' in r && r.message.startsWith(`field ${field}: `) && r.message.includes('pii.phone.e164')]).toEqual([o, 'APPROVAL_RECORD_SECRET', true]);
|
||||
}
|
||||
const typed = bin(['add', '--ask', 'Approve the plan (autoplan run fix-4402-20261122-093321, 2 decisions)', '--words', 'do it', '--by', 'Garry', '--scope', 'the plan'], { cwd: repo(), env: { GSTACK_STATE_ROOT: tmp('appr-state-') } });
|
||||
expect(typed.status).not.toBe(0);
|
||||
expect(typed.out + typed.err).toContain('field ask: pii');
|
||||
});
|
||||
|
||||
// Value: protects=an interactive /autoplan run (no run.json; its gate rows carry the run id) imports under that run id,
|
||||
// so the id can be cited and two interactive runs never share one gate state; fails_when=the import falls back to the
|
||||
// shared directory name "autoplan"; why_new=every answered-gate import case wrote run.json (#4402); seam=none
|
||||
test('an interactive run without run.json imports under the run id its gate rows carry', () => {
|
||||
const run = path.join(tmp('appr-run-'), 'autoplan');
|
||||
fs.mkdirSync(run);
|
||||
const id = 'feature-x-20261122-104500';
|
||||
fs.writeFileSync(path.join(run, 'decisions.jsonl'), JSON.stringify({ schema_version: 1, run: id, id: `${id}-p1`, label: 'P1', title: 'Plan approval',
|
||||
options: ['a', 'b'], recommended: 'a', kind: 'approval', status: 'approved', gate_rev: 1, chosen: 'a', answered_at: '2026-11-22T10:50:00.000Z', reply: 'a' }) + '\n');
|
||||
const rows = importAutoplan(run, 'b', 'owner');
|
||||
if ('code' in rows) throw new Error(rows.message);
|
||||
expect(rows.map(r => r.source)).toEqual([`autoplan:${id}@gate_rev=1`]);
|
||||
expect(rows[0]!.ask).toContain(`autoplan run ${id}`);
|
||||
});
|
||||
|
||||
// Value: protects=a second interactive run appended to the same autoplan directory imports under its own run id with only
|
||||
// its own answers; fails_when=mixed run ids fall back to the directory name and pool both runs' answers; why_new=the
|
||||
// interactive case held a single run; seam=none
|
||||
test('a second interactive run appended to the same directory imports under its own run id', () => {
|
||||
const run = path.join(tmp('appr-run-'), 'autoplan');
|
||||
fs.mkdirSync(run);
|
||||
const row = (id: string, at: string) => JSON.stringify({ schema_version: 1, run: id, id: `${id}-p1`, label: 'P1', title: 'Plan approval',
|
||||
options: ['a', 'b'], recommended: 'a', kind: 'approval', status: 'approved', gate_rev: 1, chosen: 'a', answered_at: at, reply: 'a' }) + '\n';
|
||||
const a = 'feature-x-20261122-104500', b = 'feature-y-20261122-114500';
|
||||
fs.writeFileSync(path.join(run, 'decisions.jsonl'), row(a, '2026-11-22T10:50:00.000Z'));
|
||||
const first = importAutoplan(run, 'b', 'owner');
|
||||
if ('code' in first) throw new Error(first.message);
|
||||
expect(first.map(r => r.source)).toEqual([`autoplan:${a}@gate_rev=1`]);
|
||||
fs.appendFileSync(path.join(run, 'decisions.jsonl'), row(b, '2026-11-22T11:50:00.000Z'));
|
||||
const second = importAutoplan(run, 'b', 'owner');
|
||||
if ('code' in second) throw new Error(second.message);
|
||||
expect(second.map(r => r.source)).toEqual([`autoplan:${b}@gate_rev=1`]);
|
||||
});
|
||||
|
||||
// Value: protects=an abandoned older interactive run's pending rows do not mark a newer approved run as unanswered;
|
||||
// fails_when=stillPending counts pending rows from every run in the directory; why_new=the newest-run selection
|
||||
// left the pending count pooled; seam=none
|
||||
test('an abandoned older run leaves no unanswered decisions on the newer approved run', () => {
|
||||
const run = path.join(tmp('appr-run-'), 'autoplan');
|
||||
fs.mkdirSync(run);
|
||||
const a = 'feature-x-20261122-104500', b = 'feature-y-20261122-114500';
|
||||
fs.writeFileSync(path.join(run, 'decisions.jsonl'), JSON.stringify({ schema_version: 1, run: a, id: `${a}-d1`, label: 'D1', title: 'Abandoned decision', status: 'pending', gate_rev: 1 }) + '\n'
|
||||
+ JSON.stringify({ schema_version: 1, run: b, id: `${b}-p1`, label: 'P1', title: 'Plan approval', options: ['a', 'b'], recommended: 'a', kind: 'approval',
|
||||
status: 'approved', gate_rev: 1, chosen: 'a', answered_at: '2026-11-22T11:50:00.000Z', reply: 'a' }) + '\n');
|
||||
const rows = importAutoplan(run, 'b', 'owner');
|
||||
if ('code' in rows) throw new Error(rows.message);
|
||||
expect(rows.map(r => [r.source, r.outcome, r.pending])).toEqual([[`autoplan:${b}@gate_rev=1`, 'approved', 'none']]);
|
||||
});
|
||||
|
||||
// Value: protects=the run id interactive /autoplan mints (autoplan/SKILL.md.tmpl's RUN_ID line) imports on a branch whose name ends in
|
||||
// digits; fails_when=the id puts those digits straight before the date stamp, which pii.phone.e164 and pii.cc read as a phone or card
|
||||
// number, so the import is refused (#4402); why_new=the interactive cases above use branch names without digits; seam=none
|
||||
test('the run id interactive /autoplan mints on a numbered branch imports', () => {
|
||||
const tmpl = fs.readFileSync(path.join(ROOT, 'autoplan', 'SKILL.md.tmpl'), 'utf8');
|
||||
const stamp = /^DATETIME=\$\(date \+([^)]+)\)$/m.exec(tmpl)![1]!.replace(/%([YmdHMS])/g, (_, c: string) => ({ Y: '2026', m: '11', d: '22', H: '09', M: '33', S: '21' } as Record<string, string>)[c]!);
|
||||
const minted = (/^_ID=([^;\s]+);/m.exec(tmpl) ?? /^echo "RUN_ID=([^"]+)"/m.exec(tmpl))![1]!.replace(/\$\{?BRANCH\}?/, '<branch>').replace(/\$\{?DATETIME\}?/, stamp);
|
||||
const run = path.join(tmp('appr-run-'), 'autoplan');
|
||||
fs.mkdirSync(run);
|
||||
for (const branch of ['fix-4402', 'gsta-802', '4402']) {
|
||||
const id = minted.replace('<branch>', branch);
|
||||
fs.writeFileSync(path.join(run, 'decisions.jsonl'), JSON.stringify({ schema_version: 1, run: id, id: `${id}-p1`, label: 'P1', title: 'Plan approval',
|
||||
options: ['a', 'b'], recommended: 'a', kind: 'approval', status: 'approved', gate_rev: 1, chosen: 'a', answered_at: '2026-11-22T10:50:00.000Z', reply: 'a' }) + '\n');
|
||||
const rows = importAutoplan(run, 'b', 'owner');
|
||||
expect([branch, 'code' in rows ? rows.message : rows.map(r => r.source)]).toEqual([branch, [`autoplan:${id}@gate_rev=1`]]);
|
||||
}
|
||||
});
|
||||
|
||||
test('an unanswered gate imports nothing and says why', () => {
|
||||
const run = tmp('appr-run-');
|
||||
fs.writeFileSync(path.join(run, 'decisions.jsonl'), JSON.stringify({ schema_version: 1, run: 'run-1', id: 'run-1-p1', label: 'P1', status: 'pending', gate_rev: 1 }) + '\n');
|
||||
|
||||
@@ -413,6 +413,53 @@ describe("gstack-post owns the redaction scan", () => {
|
||||
}
|
||||
});
|
||||
|
||||
// Value: protects=a gstack-receipt-runs block's session ids (/ship's earlier runs) post through pr-comment and pr-body without a pii.phone.e164
|
||||
// confirmation (gstack#4725), while a phone number in another field of the same line, a phone number, a truncated id or a session id under
|
||||
// another key, a non-canonical line, a line whose head is missing or not a 40-hex sha, an unclosed block and the same id in prose still need
|
||||
// one; fails_when=every /ship that rewrites a PR body holding earlier runs gets a false MEDIUM hold, or the exemption reaches past the exact
|
||||
// run value of a canonical runs line; why_new=the #4480 test covers only the gstack-ship-receipt block; seam=fake gh; no_claim=real gh
|
||||
test("a runs block's session ids are not phone numbers; a phone number anywhere else in or around the block still is", () => {
|
||||
const HEAD_A = "abc123abc123abc123abc123abc123abc123abcd";
|
||||
const HEAD_B = "def456def456def456def456def456def456def0";
|
||||
const RUN_A = "4242424-1700000000-deadbeef";
|
||||
const RUN_B = "3454314-1795338725-c32255b8";
|
||||
const post = (args: string[], text: string, visibility: "public" | "private" = "private") => {
|
||||
const f = fakeEnv({ files: { "/b": text }, visibility });
|
||||
return { code: run([...args, "--body-file", "/b"], f), phones: f.stdout().split("\n").filter(l => l.startsWith("RULE: pii.phone.e164 ")), f };
|
||||
};
|
||||
const runsBlock = (...lines: string[]) => `Body.\n\n\`\`\`gstack-receipt-runs\n${lines.join("\n")}\n\`\`\`\n`;
|
||||
|
||||
const comment = post(["pr-comment", "1"], runsBlock(JSON.stringify({ head: HEAD_A, version: "1.0.0.0", run: RUN_A }), JSON.stringify({ run: RUN_B, head: HEAD_B, mark: "stop" })));
|
||||
expect([comment.phones, comment.code, comment.f.posts().length]).toEqual([[], EXIT.posted, 1]);
|
||||
|
||||
const first = placeReceipt("## What changed\n\nFirst run.\n", orderReceipt({ schema_version: 1, pr: 4725, head: HEAD_A, base: "main", version: "1.0.0.0", run: RUN_A }));
|
||||
const second = placeReceipt(first, orderReceipt({ schema_version: 1, pr: 4725, head: HEAD_B, base: "main", version: "1.0.0.0", run: RUN_B }));
|
||||
expect(second).toContain("```gstack-receipt-runs\n");
|
||||
const body = post(["pr-body", "4725", "--replace"], second, "public");
|
||||
expect([body.phones, body.code, body.f.posts().length]).toEqual([[], EXIT.posted, 1]);
|
||||
|
||||
const holds: Array<[string, string, string]> = [
|
||||
["a phone number in reason on a line with a valid run", runsBlock(JSON.stringify({ head: HEAD_A, run: RUN_A, mark: "abandoned", by: "ops", reason: "call +14155552671" })), "call +14155552671"],
|
||||
["a phone number as the run", runsBlock(JSON.stringify({ head: HEAD_A, run: "+14155552671" })), '"+14155552671"'],
|
||||
["a truncated session id", runsBlock(JSON.stringify({ head: HEAD_A, run: "4242424-1700000000" })), '"4242424-1700000000"'],
|
||||
["a session id under another key", runsBlock(JSON.stringify({ head: HEAD_A, run: "ship-1", grant: RUN_A })), RUN_A],
|
||||
["a session id nested under review_loop", runsBlock(JSON.stringify({ head: HEAD_A, review_loop: { run: RUN_A } })), RUN_A],
|
||||
["a non-canonical spaced line", runsBlock(`{ "head": "${HEAD_A}", "run": "${RUN_A}" }`), RUN_A],
|
||||
["a duplicated run key", runsBlock(`{"head":"${HEAD_A}","run":"${RUN_A}","run":"${RUN_B}"}`), RUN_A],
|
||||
["a line missing head", runsBlock(JSON.stringify({ version: "1.0.0.0", run: RUN_A })), RUN_A],
|
||||
["a head that is not a 40-hex sha", runsBlock(JSON.stringify({ head: "main", run: RUN_A })), RUN_A],
|
||||
["an unclosed runs block", `Body.\n\n\`\`\`gstack-receipt-runs\n${JSON.stringify({ head: HEAD_A, run: RUN_A })}\n`, RUN_A],
|
||||
["a session id in prose after the block", runsBlock(JSON.stringify({ head: HEAD_A, run: RUN_B })) + `\nRun ${RUN_A} failed.\n`, `Run ${RUN_A}`],
|
||||
["a runs block inside another fence", `Body.\n\n\`\`\`\`markdown\n\`\`\`gstack-receipt-runs\n${JSON.stringify({ head: HEAD_A, run: RUN_A })}\n\`\`\`\n\`\`\`\`\n`, RUN_A],
|
||||
["a session id in a json block", `Body.\n\n\`\`\`json\n${JSON.stringify({ head: HEAD_A, run: RUN_A })}\n\`\`\`\n`, RUN_A],
|
||||
];
|
||||
for (const [name, text, needle] of holds) {
|
||||
const { code, phones, f } = post(["pr-comment", "1"], text);
|
||||
const line = text.split("\n").findIndex(l => l.includes(needle)) + 1;
|
||||
expect([name, [...new Set(phones)], code, f.posts()]).toEqual([name, [`RULE: pii.phone.e164 LINE: ${line} PART: body`], EXIT.confirm, []]);
|
||||
}
|
||||
});
|
||||
|
||||
// Value: protects=a private PR's Approvals table (renderRecord, full mode) posts through pr-body without a pii.phone.e164 confirmation when a
|
||||
// fix-check grant row's Covers cell names a run id like 507-7192673 (GST-3246, trail-read row 8), while the same digits in that row's
|
||||
// Asked or Exact words cell, in prose, or in a table no Source footer closes still need one; fails_when=every private /ship body with such a
|
||||
|
||||
@@ -41,6 +41,41 @@ function fixture(files: Record<string, Array<Partial<ApprovalRow> & { ask: strin
|
||||
return { cwd, env, ids };
|
||||
}
|
||||
|
||||
describe('an interactive /autoplan run cited by its directory (#4402)', () => {
|
||||
// Value: protects=a Plan line naming an interactive run's directory (no run.json) resolves through the run id its gate
|
||||
// rows carry, the id the import now records; fails_when=the path token still resolves to the shared directory name
|
||||
// "autoplan" and finds no row; why_new=path tokens were only resolved through run.json or the directory name; seam=none
|
||||
test('a path token resolves through the run its decision rows carry', () => {
|
||||
const id = 'feature-x-20261122-104500';
|
||||
const f = fixture({ b: [{ ask: `Approve the plan (autoplan run ${id}, 1 decisions)`, source: `autoplan:${id}@gate_rev=1` }] });
|
||||
const run = path.join(f.cwd, '.gstack', 'tmp', 'autoplan');
|
||||
fs.mkdirSync(run, { recursive: true });
|
||||
fs.writeFileSync(path.join(run, 'decisions.jsonl'), JSON.stringify({ run: id, id: `${id}-p1`, status: 'approved', gate_rev: 1 }) + '\n');
|
||||
const r = resolvePlan(parsePlanLine('Plan: approved: .gstack/tmp/autoplan'), { cwd: f.cwd, env: f.env });
|
||||
expect(r.ok ? 'resolved' : r.failure.message).toBe('resolved');
|
||||
});
|
||||
|
||||
// Value: protects=a Plan line naming a shared interactive folder that holds more than one run resolves to no run, so a later /autoplan in
|
||||
// the same checkout, or an approval imported before #4402 under the shared id "autoplan", never turns an unchanged PR body's citation into
|
||||
// another plan's approval, while the run id still resolves;
|
||||
// fails_when=the folder token follows whichever run was written last; why_new=the case above holds a single run; seam=none
|
||||
test('a path token whose folder holds several runs resolves to none of them; the run id still does', () => {
|
||||
const a = 'feature-x-autoplan-20261122-104500', b = 'feature-y-autoplan-20261122-114500';
|
||||
const f = fixture({ b: [{ ask: `Approve the plan (autoplan run ${a}, 1 decisions)`, source: `autoplan:${a}@gate_rev=1` }, { ask: `Approve the plan (autoplan run ${b}, 1 decisions)`, source: `autoplan:${b}@gate_rev=1` }],
|
||||
old: [{ ask: 'Approve the plan (autoplan run autoplan, 1 decisions)', source: 'autoplan:autoplan@gate_rev=1' }] });
|
||||
const run = path.join(f.cwd, '.gstack', 'tmp', 'autoplan');
|
||||
fs.mkdirSync(run, { recursive: true });
|
||||
fs.writeFileSync(path.join(run, 'decisions.jsonl'), [a, b].map(id => JSON.stringify({ run: id, id: `${id}-p1`, status: 'approved', gate_rev: 1 })).join('\n') + '\n');
|
||||
const byFolder = resolvePlan(parsePlanLine('Plan: approved: .gstack/tmp/autoplan'), { cwd: f.cwd, env: f.env });
|
||||
expect(byFolder.ok ? 'resolved' : byFolder.failure.code).toBe('PLAN_UNRESOLVED');
|
||||
const byId = resolvePlan(parsePlanLine(`Plan: approved: ${a}`), { cwd: f.cwd, env: f.env });
|
||||
expect(byId.ok ? 'resolved' : byId.failure.message).toBe('resolved');
|
||||
fs.writeFileSync(path.join(run, 'decisions.jsonl'), JSON.stringify({ run: a, id: `${a}-p1`, status: 'approved', gate_rev: 1 }) + '\n{"run": "torn');
|
||||
const torn = resolvePlan(parsePlanLine('Plan: approved: .gstack/tmp/autoplan'), { cwd: f.cwd, env: f.env });
|
||||
expect(torn.ok ? 'resolved' : torn.failure.code).toBe('PLAN_UNRESOLVED');
|
||||
});
|
||||
});
|
||||
|
||||
describe('parsePlanLine', () => {
|
||||
test('reads approved, exempt and required, tolerating spacing and bold, and ignores fenced text', () => {
|
||||
expect(parsePlanLine('x\nPlan: approved: ap-20261107055041\n')).toEqual({ kind: 'approved', line: 'Plan: approved: ap-20261107055041', token: 'ap-20261107055041' });
|
||||
|
||||
Reference in new issue
Block a user