mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-23 16:41:35 +01:00
A used review grant can no longer be claimed again, plus two /ship finish fixes (GST-3560) (#4722)
A grant for one follow-up review of a fix can no longer be claimed again once that review ran, so one grant still buys one round. /ship finish no longer calls the docs audit stale for a file a clean follow-up review read, and the CI-record timeout no longer counts local test runs. Nothing to do: the merge checks only get stricter, and the timeout setting keeps its name and default. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: pass1/outside-voice#1 reader=outside-voice Review-Finding: pass1/outside-voice#2 reader=outside-voice Review-Finding: pass1/outside-voice#3 reader=outside-voice Review-Finding: pass2/outside-voice#2 reader=outside-voice
This commit is contained in:
1 parent
79f3052f35
commit
ccd80de8eb
15 files changed
+198
-36
No files matched your search
@@ -209,6 +209,15 @@ describe('harness-evals#504: a fix-check grant answering a stop after a gate-cla
|
||||
expect(grantSpent([{ ...read('2026-11-21T00:00:00.000Z'), grant: 'a-2' }], g)).toBe(true);
|
||||
});
|
||||
|
||||
// Value: protects=two recorded grants each buy one read: a counted fix-check a claim stamped with grant a-3 was a-3's read, so
|
||||
// it leaves a-2 unspent however late it ran; fails_when=claim refuses a-2 with GRANT_SPENT after a-3's read; seam=grantSpent
|
||||
test('a later read stamped with another grant leaves this grant unspent', () => {
|
||||
const g = { approval: 'a-2', at: '2026-11-21T01:00:00.000Z' };
|
||||
const read = { skill: 'review-fix-check', completed: true, converged: true, status: 'clean', review_binding: { state: 'verified', started_at: '2026-11-21T01:01:00.000Z' } };
|
||||
expect(grantSpent([{ ...read, grant: 'a-3' }], g)).toBe(false);
|
||||
expect(grantSpent([{ ...read, grant: 'a-3' }, read], g)).toBe(true);
|
||||
});
|
||||
|
||||
// Value: protects=the same through the CLI: --round-grant and --stop after --last fix-check with a gate-class fix plan next=fix-check
|
||||
// with the fix-check reader only; fails_when=the plan prints next=stop; seam=gstack-review-plan
|
||||
test('gstack-review-plan plans the granted fix-check after a fix-check that edited a gate-class path', () => {
|
||||
|
||||
@@ -68,6 +68,13 @@ function fixCheck(c: Cap, o: { grant: string; run: string; fixList: string; row?
|
||||
return prompt;
|
||||
}
|
||||
|
||||
/** A fix-check read logged with no claim (the gstack-review-plan --grant path): no claim stamps it, so it names no grant. */
|
||||
function unclaimedFixCheck(c: Cap, row: Record<string, unknown> = {}) {
|
||||
c.f.write({ 'src/x.ts': 'export const x = 3;\n' }); c.f.commit('fix');
|
||||
const start = ok(c.run('gstack-review-log', ['--start', 'review-fix-check'])).trim();
|
||||
ok(c.run('gstack-review-log', [JSON.stringify({ skill: 'review-fix-check', timestamp: new Date().toISOString(), via: 'ship', review_scope: 'frozen', ...CLEAN, ...row }), '--finish', start]));
|
||||
}
|
||||
|
||||
function write(c: Cap, run: string) {
|
||||
const loop = path.join(c.f.root, 'loop.json');
|
||||
ok(c.run('gstack-review-scope', ['summary', '--since', c.since, '--no-ledger', '--out', loop]));
|
||||
@@ -219,6 +226,35 @@ describe('a grant spends only on a counted fix-check (gskills#24, gskills#25)',
|
||||
expect(p.stderr).toContain(`FIX_CHECK_HUNKS: built from git diff ${c.S.slice(0, 12)} HEAD`);
|
||||
expect(p.stdout).toContain('src/y.ts');
|
||||
});
|
||||
|
||||
// Value: protects=a grant buys one round: a fix-check grant an unclaimed fix-check already spent (an owner's review_loop_grant
|
||||
// or a round-grant planned through gstack-review-plan --grant, neither of which leaves a claim in the PR body) cannot be
|
||||
// claimed for a second read; fails_when=claim prints GRANT_CLAIMED; seam=gstack-ship-receipt claim
|
||||
test('claim refuses GRANT_SPENT for a grant an unclaimed counted fix-check already spent', () => {
|
||||
for (const legacy of [true, false]) {
|
||||
const c = atCap([open(ID, FP)]);
|
||||
const id = legacy
|
||||
? JSON.parse(ok(c.run('gstack-approvals', ['add', '--ask', `Owner grant: one scoped fix-check after round 2 (review_loop_grant ${c.S})`, '--words', 'do it', '--by', CAPTAIN, '--scope', 'this /ship invocation', '--owner-ref', 'GSTA-36:2026-11-22T12:00:00Z', '--json']))).added[0] as string
|
||||
: grantId(ok(c.run('gstack-approvals', ['round-grant', '--pr', '7', '--head', c.S, '--kind', 'fix-check', '--reason', 'fix it', '--by', CAPTAIN, '--owner-ref', 'GSTA-36:2026-11-22T12:00:00Z', '--words', 'fix it'])));
|
||||
unclaimedFixCheck(c);
|
||||
expect(rows(c).filter(x => x.skill === 'review-fix-check').at(-1)?.grant).toBeUndefined();
|
||||
const r = c.run('gstack-ship-receipt', ['claim', '--body', c.body, '--pr', '7', '--run', 'r2', '--grant', id]);
|
||||
expect([legacy, r.status, r.stdout]).toEqual([legacy, 3, '']);
|
||||
expect(r.stderr).toContain('GRANT_SPENT');
|
||||
expect(fs.readFileSync(c.body, 'utf8')).not.toContain(id);
|
||||
}
|
||||
});
|
||||
|
||||
// Value: protects=the negative controls: an unspent grant still claims, a malformed row spends nothing, and the run that holds
|
||||
// the claim may claim again after its own read; fails_when=claim refuses any of them; seam=gstack-ship-receipt claim
|
||||
test('claim still takes an unspent grant, one only a malformed row read, and this run\'s own claim again', () => {
|
||||
const c = atCap([open(ID, FP)]);
|
||||
const id = grantId(ok(c.run('gstack-approvals', ['round-grant', '--pr', '7', '--head', c.S, '--kind', 'fix-check', '--reason', 'fix it', '--by', CAPTAIN, '--owner-ref', 'GSTA-36:2026-11-22T12:00:00Z', '--words', 'fix it'])));
|
||||
unclaimedFixCheck(c, { converged: false });
|
||||
ok(c.run('gstack-ship-receipt', ['claim', '--body', c.body, '--pr', '7', '--run', 'r2', '--grant', id]));
|
||||
fixCheck(c, { grant: id, run: 'r2', fixList: 'fix ' + ID + '\n', claim: false });
|
||||
expect(ok(c.run('gstack-ship-receipt', ['claim', '--body', c.body, '--pr', '7', '--run', 'r2', '--grant', id]))).toContain(`GRANT_CLAIMED: grant=${id}`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('a post-review edit with no stop gets a grant (GST-3546, gbrain#10068)', () => {
|
||||
|
||||
@@ -394,3 +394,22 @@ describe('the docs bridge line prints only when the fix-check counts (GST-2294 a
|
||||
expect([r.status, lineOf(r.stdout, 'FIX_CHECK_DOCS_BRIDGE'), lineOf(r.stdout, 'FIX_CHECK')], r.stdout).toEqual([3, '', 'FIX_CHECK: not counted (no approved review_loop_grant names a stop head inside its range_base..commit)']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('a path a counted fix-check read does not stale the docs audit (GST-3560)', () => {
|
||||
// Value: protects=HARN-64: the docs audit ran at the reviewed head, the fix after it changed a path the audit hashed, and a clean
|
||||
// granted fix-check read that fix at the current head; fails_when=finish stops on DOCS: stale (src/x.ts), though stage 2 routes
|
||||
// the path as fix_checked; seam=finish's docsFresh carry
|
||||
test('a fix-checked path carries as fix_checked, and a change no fix-check read still refuses', () => {
|
||||
const { f, t, reviewed, reviewedBase } = reviewedShape();
|
||||
const post = path.join(f.root, 'post.json');
|
||||
expect(run(f, 'gstack-docs-candidate', ['snapshot', '--out', post, '--audit-id', 'a1', '--mode', 'edit', '--base', 'main', '--docs', 'README.md']).status).toBe(0);
|
||||
edit(f, { 'src/x.ts': 'export const x = 3;\n' }, 'fix the round-2 blocker');
|
||||
link(f, t, CLEAN);
|
||||
const args = ['finish', '--base', 'main', '--reviewed-tree', reviewed, '--docs-post', post, '--reviewed-base', reviewedBase, '--lane', LANE];
|
||||
const r = f.run(RELEASE, args);
|
||||
expect([r.status, lineOf(r.stdout, 'ROUTE'), lineOf(r.stdout, 'DOCS')], r.stdout).toEqual([0, expect.stringMatching(/ behavior=0 .* fix_checked=1$/), expect.stringMatching(/^DOCS: fresh .*carried: tests=0 base=0 requested=0 fix_checked=1\)/)]);
|
||||
edit(f, { 'src/y.ts': 'export const y = 2;\n' }, 'an unread change');
|
||||
const s = f.run(RELEASE, args);
|
||||
expect([s.status, stopLine(s.stdout)]).toEqual([3, `${STOP}src/y.ts)`]);
|
||||
});
|
||||
});
|
||||
@@ -6,7 +6,9 @@
|
||||
*/
|
||||
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 { bunIsolationArgs } from '../lib/bun-isolation';
|
||||
import { fakeGhScript, type FakeWorld } from './helpers/fake-gh-runs';
|
||||
import { findFilesBySuffix } from './helpers/scratch-repo';
|
||||
import { lineOf, PREFLIGHT, RELEASE, shipFixture, type ShipFx } from './helpers/ship-bin-fixture';
|
||||
@@ -140,3 +142,45 @@ describe('record-ci reuses its own CI row at the same tree (GST-1795)', () => {
|
||||
expect([again.status, perFileRuns(f), lineOf(again.stderr, 'CI_RECORD_REUSED')], again.stderr).toEqual([0, 2, '']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('the record-ci bound covers finding the CI run, not the local remainder (GST-3560)', () => {
|
||||
const slow = (key: 'inventory' | 'per_file') => {
|
||||
const cfg = JSON.parse(BASE['.gstack/pregate.json']);
|
||||
cfg.ship_lanes_from[FREE][key] = 'sleep 8; ' + cfg.ship_lanes_from[FREE][key];
|
||||
const f = shipFixture({ ...BASE, '.gstack/pregate.json': JSON.stringify(cfg, null, 2) + '\n' });
|
||||
fixtures.push(f);
|
||||
world(f);
|
||||
return f;
|
||||
};
|
||||
const carry = (f: ShipFx, bound: number) => {
|
||||
const code = `const { carryLane } = await import(${JSON.stringify(path.join(import.meta.dir, '..', 'lib', 'ship-bin-common.ts'))}); console.log(JSON.stringify(await carryLane(process.cwd(), 'main', { label: 'free', command: process.env.LANE_CMD }, ${bound})));`;
|
||||
const r = f.run(process.execPath, [...bunIsolationArgs(), '-e', code], { LANE_CMD: FREE });
|
||||
expect(r.status, r.stderr).toBe(0);
|
||||
return JSON.parse(r.stdout.trim().split('\n').at(-1)!);
|
||||
};
|
||||
// Value: protects=HARN-64: record-ci's local per_file remainder ran 879.7 s against ci_record_timeout_s=900, so the bound meant
|
||||
// for finding and verifying the CI run also had to fit local test runs; fails_when=carryLane kills record-ci while the
|
||||
// remainder runs (carryNone record_failed) though the CI phase finished well inside the bound; seam=carryLane, CI_RECORD_PHASE
|
||||
test('a remainder that runs past the bound still carries', () => {
|
||||
const f = slow('per_file');
|
||||
expect([carry(f, 6), perFileRuns(f)]).toEqual([expect.objectContaining({ exit: 0, carried: '7/1', here: expect.any(String) }), 1]);
|
||||
});
|
||||
|
||||
// Value: protects=the bound still holds while the CI run is found and verified: a lookup past it is stopped then, not after it
|
||||
// returns, and runs nothing here; fails_when=the bound is dropped or checked only after the lookup; seam=carryLane
|
||||
test('a CI phase past the bound stops as ci_record_timeout and runs nothing here', () => {
|
||||
const f = slow('inventory');
|
||||
const t0 = Date.now();
|
||||
const got = carry(f, 3);
|
||||
expect([got.carryNone, perFileRuns(f)]).toEqual([expect.stringMatching(/^ci_record_timeout: finding and verifying the CI run took over the 3 s bound/), 0]);
|
||||
expect(Date.now() - t0).toBeLessThan(8_000);
|
||||
});
|
||||
|
||||
// Value: protects=a record-ci that cannot start returns record_failed for its lane, as the synchronous spawn did, so accept,
|
||||
// finish and preflight report it; fails_when=the spawn error is unhandled and the tool crashes; seam=carryLane
|
||||
test('a record-ci that cannot start returns record_failed instead of crashing', async () => {
|
||||
const { carryLane } = await import('../lib/ship-bin-common');
|
||||
const got = await carryLane(path.join(fs.realpathSync(os.tmpdir()), 'gstack-no-such-checkout-' + process.pid), 'main', { label: 'free', command: FREE }, 5);
|
||||
expect([got.exit, got.carryNone]).toEqual([null, expect.stringMatching(/^record_failed: /)]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user