mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-23 08:31:44 +01:00
/ship counts a clean recheck of granted fixes even when its brief was written just before the review started (GST-3523) (#4698)
When an owner grants one recheck of a fix and it reads the fix clean, /ship now counts it, even when the review pass wrote the recheck's brief a moment before it took the review's start token. Why: /ship only accepted the record of what the reviewer read if it was written after that start, so a clean recheck was not counted and the PR needed an owner's exception to finish (gbrain#10057). Nothing to do. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=red-team
This commit is contained in:
1 parent
44e244d603
commit
f528f5bacc
6 files changed
+103
-3
No files matched your search
@@ -39,6 +39,7 @@ import { effectiveReaders, READERS_POLICY_DEFAULT, type EffectiveReaders } from
|
||||
import { defaultRoots, foundLines, ignoredLines, inventory, quarantineStage, rerunBlocked, sweepResult, type Inventory } from '../lib/review-sweep';
|
||||
import { REVIEW_DIFF_MAX_BYTES, ceilingContext, disclosureDigest, disclosureLine, parseTail, readSelection, tooLargeLine, unreadableLine, type PlanExclude, type ReaderDiff } from '../lib/review-exclude';
|
||||
import { logShipCall } from '../lib/ship-call-log';
|
||||
import { restampFixCheckHunks } from '../lib/review-evidence';
|
||||
|
||||
logShipCall('gstack-review-dispatch');
|
||||
|
||||
@@ -501,9 +502,15 @@ function passStep(cmd: string): number {
|
||||
const token = flag('--token');
|
||||
if (!token) { process.stderr.write('gstack-review-dispatch mark: --log-start <key> --token <t>\n'); return EXIT.usage; }
|
||||
m.log_starts ??= {};
|
||||
const fresh = !m.log_starts[logStart];
|
||||
m.log_starts[logStart] ??= token;
|
||||
writeManifest(file, m);
|
||||
process.stdout.write(`LOG_START: ${logStart} token=${m.log_starts[logStart]}\n`);
|
||||
if (fresh && m.fix_check?.hunks && logStart.includes('review-fix-check')) {
|
||||
let text: string | undefined;
|
||||
try { text = fs.readFileSync(m.fix_check.hunks, 'utf8'); } catch { /* reported below; the start token is already recorded */ }
|
||||
process.stdout.write(`FIX_CHECK_HUNKS: ${text === undefined ? 'not restamped (hunks file unreadable)' : restampFixCheckHunks(process.cwd(), text) ? 'restamped' : 'not restamped (no render record with these hunks)'}\n`);
|
||||
}
|
||||
return EXIT.ok;
|
||||
}
|
||||
const before = flag('--before');
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
**A clean recheck of granted fixes now counts even when its brief was written just before the review started.** The review pass writes the recheck's brief, which records what the reviewer reads, and then takes the review's start token. /ship only accepted that record if it was written after the start, so a clean recheck didn't count and the pull request needed an owner's exception to finish. Taking the start now re-dates the record, but only while it still matches what the reviewer was given. The record also keeps approval ids (`a-…`) the fix list names, so a grant for ruled notes no longer records an empty fix list. (GST-3523)
|
||||
@@ -258,7 +258,7 @@ for this PR; the PR body's first claim of it is this run's; exactly one
|
||||
`review-fix-check` row carries it, and `gstack-review-log` stamped that row from
|
||||
the claim (`fix_check_base`, `run`, `grant`, `pr`) with the digest of the hunks
|
||||
its reader was given, which cover every path the stop-to-fix diff changes, and
|
||||
the ledger ids and fingerprints its fix list named; the row read the stop's head to the receipt head (or a
|
||||
the ledger ids, fingerprints and `a-…` approval ids its fix list named; the row read the stop's head to the receipt head (or a
|
||||
head that only merges the base in) on one committed tree, with nothing open at
|
||||
any severity; and the stop, the claim and the row's start were recorded in that
|
||||
order. Each grant id the fix list named closes the one open blocker carrying
|
||||
|
||||
+13
-2
@@ -496,9 +496,9 @@ const hunksFile = (cwd: string) => {
|
||||
return r.status === 0 && r.stdout.trim() ? resolve(cwd, r.stdout.trim()) : '';
|
||||
};
|
||||
|
||||
/** The ledger ids and path:line:category fingerprints a fix list names: the only grant ids its clean fix-check can close. */
|
||||
/** The ledger ids, path:line:category fingerprints and a-… approval ids a fix list names: the only grant ids its clean fix-check can close. */
|
||||
export function fixListNames(text: string): string[] {
|
||||
return [...new Set(text.split(/[\s`'"(),;]+/).map(t => t.replace(/[.:]+$/, '')).filter(t => t.includes('#') || /:\d+:/.test(t)))].sort();
|
||||
return [...new Set(text.split(/[\s`'"(),;]+/).map(t => t.replace(/[.:]+$/, '')).filter(t => t.includes('#') || /:\d+:/.test(t) || /^a-[0-9a-f]{12}$/.test(t)))].sort();
|
||||
}
|
||||
|
||||
/** gstack-review-plan --fix-check-prompt and the pass program's fix-check render record the hunks and fix list they rendered from; a failed write only leaves the row without hunks, so it closes nothing. */
|
||||
@@ -509,6 +509,17 @@ export function recordFixCheckHunks(cwd: string, text: string, ledger: string |
|
||||
} catch { /* the row carries no hunks and closes nothing */ }
|
||||
}
|
||||
|
||||
/** The pass program renders a fix-check brief before it takes the review-fix-check start (GST-3523): re-date that render's record, only while its digest still matches the hunks the brief carried, so the start's row attaches it. */
|
||||
export function restampFixCheckHunks(cwd: string, text: string): boolean {
|
||||
try {
|
||||
const file = hunksFile(cwd);
|
||||
const o = JSON.parse(readFileSync(file, 'utf8'));
|
||||
if (o.sha256 !== hunksDigest(text).sha256) return false;
|
||||
writeFileSync(file, JSON.stringify({ ...o, at: new Date().toISOString() }) + '\n');
|
||||
return true;
|
||||
} catch { return false; }
|
||||
}
|
||||
|
||||
/** The hunks record gstack-review-log stamps on a granted fix-check row: the newest render at or after the row's start. */
|
||||
export function readFixCheckHunks(cwd: string, since: string): { sha256: string; paths: string[]; fix_list: string[]; ledger?: string } | undefined {
|
||||
try {
|
||||
|
||||
@@ -476,6 +476,10 @@ export const KNOWN_WINDOWS_INCOMPATIBLE: Array<{ file: string; reason: string }>
|
||||
file: 'test/ship-run-record.test.ts',
|
||||
reason: 'drives bin/gstack-ship-preflight, gstack-ship-run, gstack-ship-receipt, gstack-approvals, gstack-review-log, gstack-lease and gstack-skill-end (shebangs) through test/helpers/ship-bin-fixture.ts like test/round-cap-granted-stop.test.ts; a bin spawn fails on windows-latest the same way (first-bin-spawn failure class of test/ship-uid-sidecar.test.ts)',
|
||||
},
|
||||
{
|
||||
file: 'test/fix-check-hunks-restamp.test.ts',
|
||||
reason: 'runs bin/gstack-review-dispatch (a shebang) and a git fixture like test/review-pass-program.test.ts; a bin spawn fails on windows-latest the same way (first-bin-spawn failure class of test/ship-uid-sidecar.test.ts)',
|
||||
},
|
||||
{
|
||||
file: 'test/fix-check-clearing.test.ts',
|
||||
reason: 'drives bin/gstack-ship-receipt, gstack-approvals, gstack-review-log, gstack-review-plan, gstack-review-scope, gstack-review-read and gstack-ship-release (shebangs) through test/helpers/ship-bin-fixture.ts like test/round-cap-granted-stop.test.ts; a bin spawn fails on windows-latest the same way (first-bin-spawn failure class of test/ship-uid-sidecar.test.ts)',
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* GST-3523 (GBRA-741, gbrain#10057 run ship4): the pass program renders a fix-check brief, which records its hunks, and only
|
||||
* then takes the review-fix-check start. readFixCheckHunks attaches records written at or after the start, so the clean granted
|
||||
* fix-check's row carried no hunks and finish did not count it. Recording the start token now re-dates that render's record
|
||||
* while its digest still matches the hunks the brief carried.
|
||||
*/
|
||||
import { afterEach, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { fixListNames, hunksDigest, readFixCheckHunks, recordFixCheckHunks } from '../lib/review-evidence';
|
||||
|
||||
const BIN = path.resolve(import.meta.dir, '..', 'bin', 'gstack-review-dispatch');
|
||||
const HUNKS = 'diff --git a/src/x.ts b/src/x.ts\n--- a/src/x.ts\n+++ b/src/x.ts\n@@ -1 +1 @@\n-a\n+b\n';
|
||||
const dirs: string[] = [];
|
||||
afterEach(() => { while (dirs.length) fs.rmSync(dirs.pop()!, { recursive: true, force: true }); });
|
||||
|
||||
function pass() {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'fc-restamp-'));
|
||||
dirs.push(root);
|
||||
expect(spawnSync('git', ['init', '-q', root], { encoding: 'utf8', timeout: 30_000 }).status).toBe(0);
|
||||
const hunks = path.join(root, 'hunks.txt'), fixList = path.join(root, 'fixes.txt'), manifest = path.join(root, 'pass-manifest.json');
|
||||
fs.writeFileSync(hunks, HUNKS);
|
||||
fs.writeFileSync(fixList, 'fix p2/outside-voice#1\n');
|
||||
fs.writeFileSync(manifest, JSON.stringify({ version: 1, readers: [], ledger: path.join(root, 'merged.jsonl'), fix_check: { fix_list: fixList, hunks, tests: hunks } }));
|
||||
recordFixCheckHunks(root, HUNKS, path.join(root, 'merged.jsonl'), 'fix p2/outside-voice#1\n');
|
||||
const mark = (key: string, token: string) => spawnSync(BIN, ['mark', '--manifest', manifest, '--log-start', key, '--token', token], { cwd: root, encoding: 'utf8', timeout: 60_000 });
|
||||
return { root, hunks, mark };
|
||||
}
|
||||
const later = () => { const t = Date.now(); while (Date.now() <= t + 5) { /* the start follows the render */ } return new Date().toISOString(); };
|
||||
|
||||
// Value: protects=a clean granted fix-check rendered before its start still carries its hunks; fails_when=recording the start leaves the render's record dated before it
|
||||
test('recording the review-fix-check start re-dates the record its render wrote', () => {
|
||||
const p = pass();
|
||||
const since = later();
|
||||
expect(readFixCheckHunks(p.root, since)).toBeUndefined();
|
||||
const r = p.mark('pass:review-fix-check', 't-1');
|
||||
expect(r.status, r.stderr).toBe(0);
|
||||
expect(r.stdout).toContain('FIX_CHECK_HUNKS: restamped');
|
||||
expect(readFixCheckHunks(p.root, since)).toMatchObject({ ...hunksDigest(HUNKS), fix_list: ['p2/outside-voice#1'] });
|
||||
});
|
||||
|
||||
// Value: protects=the record still names only the hunks the reader got; fails_when=a hunks file edited after the render is restamped as read
|
||||
test('hunks edited after the render, a repeated start or another skill restamp nothing', () => {
|
||||
const edited = pass();
|
||||
fs.writeFileSync(edited.hunks, HUNKS + '+c\n');
|
||||
const since = later();
|
||||
expect(edited.mark('pass:review-fix-check', 't-1').stdout).toContain('FIX_CHECK_HUNKS: not restamped');
|
||||
expect(readFixCheckHunks(edited.root, since)).toBeUndefined();
|
||||
|
||||
const other = pass();
|
||||
const s2 = later();
|
||||
expect(other.mark('pass:review', 't-1').stdout).not.toContain('FIX_CHECK_HUNKS');
|
||||
expect(readFixCheckHunks(other.root, s2)).toBeUndefined();
|
||||
expect(other.mark('pass:review-fix-check', 't-2').status).toBe(0);
|
||||
const s3 = later();
|
||||
expect(other.mark('pass:review-fix-check', 't-3').stdout).not.toContain('FIX_CHECK_HUNKS');
|
||||
expect(readFixCheckHunks(other.root, s3)).toBeUndefined();
|
||||
});
|
||||
|
||||
// Value: protects=recording the start never fails over the hunks file; fails_when=a missing hunks file makes mark exit non-zero after
|
||||
// it saved the token, so a retry skips the restamp; seam=gstack-review-dispatch mark --log-start
|
||||
test('a missing hunks file still records the start and says why nothing was restamped', () => {
|
||||
const p = pass();
|
||||
fs.rmSync(p.hunks);
|
||||
const r = p.mark('pass:review-fix-check', 't-1');
|
||||
expect(r.status, r.stderr).toBe(0);
|
||||
expect(r.stdout).toContain('LOG_START: pass:review-fix-check token=t-1');
|
||||
expect(r.stdout).toContain('FIX_CHECK_HUNKS: not restamped (hunks file unreadable)');
|
||||
});
|
||||
|
||||
// Value: protects=a grant whose findings are approval ids (ruled notes) keeps them in the recorded fix list (GST-3523, gbrain#10063,
|
||||
// grant a-b306fda9cc20); fails_when=fixListNames drops a-… ids, so the fix list is empty and clearByGrant closes nothing; seam=recordFixCheckHunks
|
||||
test('the fix list keeps approval ids beside ledger ids and fingerprints, and nothing else', () => {
|
||||
expect(fixListNames('fix a-b306fda9cc20, p2/outside-voice#1 and src/x.ts:3:testing (see a-short, the a-b306fda9cc20 note).')).toEqual(['a-b306fda9cc20', 'p2/outside-voice#1', 'src/x.ts:3:testing']);
|
||||
});
|
||||
Reference in new issue
Block a user