mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-29 19:34:29 +01:00
Let an owner's ruling ship a small edit made after /ship's final review (GST-3775) (#4818)
An owner can now rule that a small edit made after /ship's read-only final review ships as a disclosed note, and finish accepts exactly that file at exactly the ruled bytes instead of forcing a whole new /ship. This unblocks teams that hit "behavior, tests or build inputs changed since review" over a one-line test change (garrytan/gbrain#10256), while keeping the review stop for every other edit. Nothing to do on merge; the changelog fragment is in changelog.d/edit-ruling-fixes.md. 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/red-team#2 reader=red-team Review-Finding: p2/outside-voice#2 reader=outside-voice
This commit is contained in:
1 parent
e38a1782ae
commit
66b8f84376
9 files changed
+232
-2
No files matched your search
@@ -52,6 +52,8 @@ const HELP = `gstack-approvals — the per-thread approval record (capy/skill/gs
|
||||
words from, and the row, receipt and Ruled note line then say relayed from it (APPROVAL_RULING_RUN_OPEN without);
|
||||
the ref is ${OWNER_REF_SHAPE};
|
||||
--not-security: the owner's call that a red-team finding is not security class, so public text shows it;
|
||||
--finding edit:<path> rules an edit after the final review a note: finish routes that path at the head's bytes
|
||||
as RULED_EDIT instead of stopping (docs/ship-policy.md#ruled-edits);
|
||||
refused while a /ship run is open on this checkout
|
||||
rulings the "Ruled note: …" lines the Pre-Landing Review and the PR body carry
|
||||
gate --finding <the gate finding's fingerprint> --gate-id <its gate_id> --head <the stop head the owner answered at>
|
||||
|
||||
@@ -304,6 +304,16 @@ function main(): number {
|
||||
if (plan.next.reason.startsWith('PR_ROUND_CAP')) plan.next.reason += `: record this stop with gstack-ship-receipt stop --pr ${flag('--pr') ?? '<n>'} --run <this /ship run> --since <REVIEW_SINCE>, which prints the fix-check round grant (gstack-approvals round-grant --kind fix-check) that buys its fix round, in this run or the next; once it is recorded, pass the --round-grant and --stop the PR_REVIEW_FLAGS: line prints: in this run from gstack-ship-receipt history --pr ${flag('--pr') ?? '<n>'} --base <base> --run <this /ship run> (its preflight already ran, and a second one is refused), in a new run from its preflight (docs/troubleshooting.md#pr-round-cap)`;
|
||||
if (carried) plan.next.reason = `the edits after the last fix-check ${fixCheckAt!.slice(0, 12)} are ${carried.paths.length ? `${carried.verdict === 'plain' ? 'plain docs' : `docs (${carried.paths.join(', ')})`}${carried.stamps.length ? ' and release stamps' : ''}` : 'release stamps'} (docsChangeSince), no gate-class edit (GST-1702): ${plan.next.reason}`;
|
||||
else if (postReview && pass > 0) plan.next.reason = `edits after the review bound (Step 16 stage 2.1) plan as a fix to a gate-class path, never a note: ${plan.next.reason}`;
|
||||
if (postReview && plan.next.step === 'stop') {
|
||||
const status = rangeBase ? git(['diff', '-z', '--name-status', '--no-renames', rangeBase, own ?? head])?.split('\0').filter(Boolean) : undefined;
|
||||
const pairs = status ? Array.from({ length: status.length >> 1 }, (_, i) => [status[2 * i]!, status[2 * i + 1]!] as const) : undefined;
|
||||
const edited = pairs?.filter(([s]) => s !== 'D').map(([, p]) => p), deleted = pairs?.filter(([s]) => s === 'D').map(([, p]) => p) ?? [];
|
||||
const spaced = edited?.filter(p => /\s/.test(p)) ?? [];
|
||||
const rulable = edited?.filter(p => !spaced.includes(p));
|
||||
const quote = (s: string) => `'${s.replace(/'/g, `'\\''`)}'`;
|
||||
const rule = (finding: string) => `gstack-approvals rule --finding ${finding} --head ${head} --reason '<why it ships as a note>' --by '<the owner>' --words '<their exact words>' --owner-ref <thread code>:<message id>`;
|
||||
plan.next.reason += `; if the owner rules instead that the edit ships as a disclosed note, record that ruling once per edited path (each path shell-quoted; the owner-ref is the relay this open /ship run needs): ${rulable?.length ? rulable.map(p => rule(quote(`edit:${p}`))).join(' && ') : rule("'edit:<path>'")}, then rerun finish, which routes each ruled path at the ruled bytes as RULED_EDIT${spaced.length ? `; ${spaced.map(quote).join(', ')} cannot be ruled (a finding holds no whitespace), so an edit there keeps the fix and runs /ship again` : ''}${deleted.length ? `; a deletion (${deleted.map(quote).join(', ')}) cannot be ruled, so it keeps the fix and runs /ship again` : ''}`;
|
||||
}
|
||||
const ranArg = flag('--targeted-ran');
|
||||
const delta = plan.next.step !== 'done' || !targeted.classes.length || ran ? null
|
||||
: carried?.verdict === 'claim' ? { state: 'dispatch' as const, range_base: fixCheckAt!, paths: [...carried.paths] }
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
important: blocker
|
||||
---
|
||||
### Fixed
|
||||
|
||||
- **An owner can now let a small edit made after the final review ship as a disclosed note, and /ship honours it.** Before, an edit after the read-only final review stopped `gstack-ship-release finish` with no way to record the owner's "ship it with the note", so the run stayed stuck however the owner ruled. The owner's ruling is now one `gstack-approvals rule --finding edit:<path> --head <stop head>` per edited path, and the `gstack-review-plan --post-review` stop prints that command for each of the PR's own edited paths, shell-quoted so it pastes safely. finish then accepts exactly those paths, at exactly the ruled bytes, prints a `RULED_EDIT:` line for each, and the PR body lists each ruling. It refuses, with a `RULED_EDIT_REFUSED:` line and the reason, a path edited again after its ruling, a deletion, a path git cannot read, and a path whose name reaches finish with a replacement character, so a ruling can never clear an edit to a different file.
|
||||
@@ -292,7 +292,7 @@ the same grant, whichever row records it:
|
||||
| a light pass 1 whose below-floor fixes change no runtime lines | done |
|
||||
| round 2 that fixed anything, blocking or below the floor | one read-only full review of the final head, with no fix round (R51) |
|
||||
| round 2 on a light diff whose below-floor fixes change no runtime lines | done: notes in the PR body |
|
||||
| a fix after that read-only review | stop: the lane's Captain rules it a note, or the fix goes to a new /ship run's read-only full review |
|
||||
| a fix after that read-only review | stop: the lane's Captain rules it a note (one `gstack-approvals rule --finding edit:<path>` per edited path, which finish then routes as `RULED_EDIT`: [ruled edits](ship-policy.md#ruled-edits)), or the fix goes to a new /ship run's read-only full review |
|
||||
| a full pass that leaves a blocking finding open (fixed or not) | stop: name it for the owner |
|
||||
| a fix-check (granted before GST-3562) that found nothing blocking | done |
|
||||
| a fix-check (granted before GST-3562) that found a blocking finding | stop: name it for the owner |
|
||||
|
||||
@@ -1927,6 +1927,47 @@ base to save with the reviewed tree for finish's `--reviewed-base`.
|
||||
An own edit, a conflict resolution, an edit inside a merge, base context moved
|
||||
beside the branch's hunks or an uncommitted change reads `STALE` and says which.
|
||||
|
||||
<a id="ruled-edits"></a>
|
||||
**Ruled edits after the final review (GST-3775).** An edit after the read-only
|
||||
final review stops finish (`behavior, tests or build inputs changed since review`),
|
||||
and `gstack-review-plan --post-review` then stops for the owner: ship the edit as
|
||||
a ruled note, or keep it and run /ship again for one more read-only full review.
|
||||
The owner's "ship it with the note" is a ruling per edited path, with `edit:<path>`
|
||||
as the finding and the stop head as the head; the stop line prints the edited
|
||||
paths and the head:
|
||||
|
||||
```bash
|
||||
gstack-approvals rule --finding 'edit:<path>' --head <stop head> --reason '<why it ships as a note>' \
|
||||
--by '<the owner>' --words '<their exact words>' --owner-ref <thread code>:<message id>
|
||||
```
|
||||
|
||||
The stop line prints one such command per edited path, with each `edit:<path>`
|
||||
shell-quoted, so a path with quotes, `$`, `;` or backticks pastes as one argument.
|
||||
|
||||
finish then routes a changed path as `RULED_EDIT: <path> (ruled at <head12> by <who>,
|
||||
approval <id>)` instead of stopping, when a ruling `edit:<path>` names HEAD or an
|
||||
ancestor of it, the path's entry in the tree finish routes (mode and bytes, untracked
|
||||
files included) equals that head's, and no commit after that head touches the path.
|
||||
Both trees must hold the path as one file under exactly the spelling finish routes:
|
||||
a path git cannot read (`git ls-tree` fails) or holds under another spelling (a
|
||||
filename that is not UTF-8 reaches finish with a replacement character), a path
|
||||
whose spelling holds a replacement character (U+FFFD) at all, since it may name
|
||||
another file than the one git changed, and a deleted path never match, so a
|
||||
ruling cannot clear them. A ruling that does not
|
||||
clear its path prints `RULED_EDIT_REFUSED: <path> (<why>; …)` and finish stops.
|
||||
A gate-class path, and a test the gate scan promotes to a behavior change, can be
|
||||
ruled like any other: the ruling is the owner's call on that exact edit. The stop
|
||||
line lists only the PR's own edits since the final review, never a path only a
|
||||
base merge moved, and names deletions apart, because a deletion cannot be ruled.
|
||||
One ruling never covers another path, and a path edited again after its ruling
|
||||
stops finish again, even when a later commit restores the ruled bytes. A path with
|
||||
whitespace cannot be ruled, so an edit there keeps the fix and runs /ship again.
|
||||
The ruling clears only the review stop: a changed file the documentation audit
|
||||
hashed still needs the stage 3 recovery finish's stop names. The ruling is an ordinary
|
||||
ruled note, so it prints as `RULED_NOTE:`, marked `(no RULED_EDIT at this head; not
|
||||
applied)` when it cleared no path, the receipt records it and the PR body lists its
|
||||
`Ruled note:` line.
|
||||
|
||||
<a id="security-findings-stay-private"></a>
|
||||
**Security findings stay private (GST-3076).** A PR body keeps every earlier
|
||||
version in its edit history, and a ruled, dispositioned, deferred or noted
|
||||
|
||||
+25
-1
@@ -317,7 +317,7 @@ function fixChecked(cwd: string, o: BridgeOpts & { now: string; parent?: string;
|
||||
}
|
||||
const inRange = (l: FixLink, c: string) => !!l.from && !!l.commit && ancestor(l.from, c) && ancestor(c, l.commit);
|
||||
const rulings = readRuledNotes(cwd).map(n => ({ ...n, links: chain.filter(l => inRange(l, n.head)) }));
|
||||
for (const n of rulings) r.add(`RULED_NOTE: ${ruledNoteText(n)}${chain.length && !n.links.length ? ' (outside this fix-check\'s range; not applied)' : ''}`);
|
||||
for (const n of rulings) if (!n.finding.startsWith('edit:')) r.add(`RULED_NOTE: ${ruledNoteText(n)}${chain.length && !n.links.length ? ' (outside this fix-check\'s range; not applied)' : ''}`);
|
||||
const gates = readGateDispositions(cwd);
|
||||
for (const d of gates) r.add(`GATE_DISPOSITION: ${gateDispositionText(d)}${reviewRows.some(v => dispositionedOn(cwd, v, [d]).length) ? '' : ' (no open gate finding at this fingerprint on a review row whose range holds this head; not applied)'}`);
|
||||
const gatedOn = (l: FixLink) => new Set(dispositionedOn(cwd, l.row, gates).map(d => gateKey(d.finding, d.gate_id)));
|
||||
@@ -450,11 +450,35 @@ function route(cwd: string, base: string, reviewed: string, reviewedBase: Review
|
||||
by.behavior = by.behavior.filter(p => !by.accepted.includes(p));
|
||||
by.docs = by.docs.filter(p => !by.accepted.includes(p));
|
||||
}
|
||||
const edits = readRuledNotes(cwd).filter(n => n.finding.startsWith('edit:'));
|
||||
const top = edits.length ? git(cwd, ['rev-parse', '--show-toplevel']).stdout.trim() : '';
|
||||
const entry = (tree: string, p: string) => { const ls = git(cwd, ['--literal-pathspecs', 'ls-tree', '-z', '--full-tree', tree, '--', p]); const rows = ls.stdout.split('\0').filter(Boolean);
|
||||
return ls.status !== 0 || rows.length > 1 || rows.some(e => e.slice(e.indexOf('\t') + 1) !== p) ? null : rows[0] ?? ''; };
|
||||
const untouched = (head: string, p: string) => { const log = git(top, ['--literal-pathspecs', 'log', '--first-parent', '--format=%H', `${head}..HEAD`, '--', p]); return log.status === 0 && !log.stdout.trim(); };
|
||||
const refusal = (n: (typeof edits)[number], p: string) => {
|
||||
if (!ancestor(n.head, 'HEAD')) return `ruled at ${n.head.slice(0, 12)}, which is not HEAD or an ancestor of it`;
|
||||
const [at, cur] = [entry(n.head, p), entry(now, p)], where = (e: string | null) => e === at ? n.head.slice(0, 12) : 'the tree finish routes';
|
||||
if (at === null || cur === null) return `git ls-tree could not read it at ${where(null)}`;
|
||||
if (!at || !cur) return `no file at ${where('')}: a ruling covers a file git holds under this spelling, never a deletion`;
|
||||
if (p.includes('\uFFFD')) return 'its spelling holds a replacement character (U+FFFD), so the file git changed may have another name';
|
||||
if (at !== cur) return `its mode or bytes differ from the ruled head ${n.head.slice(0, 12)}`;
|
||||
return top && untouched(n.head, p) ? '' : `a commit after ${n.head.slice(0, 12)} touches it, or git could not list them`;
|
||||
};
|
||||
const ruled = new Map<string, (typeof edits)[number]>(), refusedEdits: string[] = [];
|
||||
for (const p of by.behavior) {
|
||||
const why = edits.filter(n => n.finding === `edit:${p}`).map(n => [n, refusal(n, p)] as const);
|
||||
const ok = why.filter(([, w]) => !w).at(-1);
|
||||
if (ok) ruled.set(p, ok[0]); else if (why.length) refusedEdits.push(`${p} (${why.at(-1)![1]}; keep the edit and run /ship again, docs/ship-policy.md#ruled-edits)`);
|
||||
}
|
||||
by.behavior = by.behavior.filter(p => !ruled.has(p));
|
||||
const uid = uidSidecars(cwd, { sides, candidates: parent ? [] : by.behavior, accepted: by.accepted, excluded: opts.excluded });
|
||||
by.sidecar = Object.keys(uid.proven).sort();
|
||||
by.behavior = by.behavior.filter(p => !by.sidecar.includes(p));
|
||||
r.add(`ROUTE: reviewed=${reviewed.slice(0, 12)} current=${now.slice(0, 12)} behavior=${by.behavior.length} docs=${by.docs.length} metadata=${by.metadata.length} tests=${by.tests.length} base=${sides ? by.base.length : 'unknown'} context=${by.context.length}${by.bounded.length ? ` bounded=${by.bounded.length}` : ''}${by.mechanical.length ? ` mechanical=${by.mechanical.length}` : ''}${counted ? ` fix_checked=${by.fix_checked.length}` : ''}${loop ? ` accepted=${by.accepted.length}` : ''}${by.sidecar.length ? ` sidecar=${by.sidecar.length}` : ''}`);
|
||||
if (loop) r.add(`REVIEW_LOOP_EXCEPTION: accepted ${by.accepted.length ? short(by.accepted) : 'none'} (changed since fix-check ${loop.fix_check.head.slice(0, 12)}; accepted by ${loop.accepted_by} ${loop.date} via ${loop.via})`);
|
||||
for (const [p, n] of ruled) r.add(`RULED_EDIT: ${p} (ruled at ${n.head.slice(0, 12)} by ${n.by}, approval ${n.approval})`);
|
||||
for (const x of refusedEdits) r.add(`RULED_EDIT_REFUSED: ${x}`);
|
||||
for (const n of edits) r.add(`RULED_NOTE: ${ruledNoteText(n)}${[...ruled.values()].includes(n) ? '' : ' (no RULED_EDIT at this head; not applied)'}`);
|
||||
for (const x of bounded.refused) if (by.behavior.includes(x.path)) r.add(`ROUTE_BOUNDED_REFUSED: ${x.path} ${x.reason} (fix: ${x.fix}; docs/troubleshooting.md#route-bounded-refused)`);
|
||||
for (const p of by.mechanical) r.add(`MECHANICAL: ${p} (${mech.proven[p]})`);
|
||||
for (const x of mech.refused) r.add(`ROUTE_MECHANICAL_REFUSED: ${x.path} ${x.reason} (docs/troubleshooting.md#route-mechanical-refused)`);
|
||||
|
||||
@@ -528,6 +528,10 @@ export const KNOWN_WINDOWS_INCOMPATIBLE: Array<{ file: string; reason: string }>
|
||||
file: 'test/ship-finish-fixed-links.test.ts',
|
||||
reason: 'drives bin/gstack-ship-release, gstack-approvals, gstack-review-log, gstack-docs-candidate and gstack-wtree (shebangs) through test/helpers/ship-bin-fixture.ts like test/ship-finish-ruled-notes.test.ts; windows-latest fails every case at the first bin spawn (windows-free-shard 3, run 42593329215)',
|
||||
},
|
||||
{
|
||||
file: 'test/ship-finish-edit-ruling.test.ts',
|
||||
reason: 'drives bin/gstack-ship-release, gstack-approvals, gstack-docs-candidate and gstack-wtree (shebangs) through test/helpers/ship-bin-fixture.ts like test/ship-finish-ruled-notes.test.ts, whose every case fails on windows-latest at the first bin spawn',
|
||||
},
|
||||
{
|
||||
file: 'test/review-pass-program.test.ts',
|
||||
reason: 'split from test/review-pass.test.ts, which Windows never ran (its POSIX mode-bit check): runs bin/gstack-review-dispatch (a shebang) and bash git fixtures through test/helpers/review-pass-harness.ts',
|
||||
|
||||
@@ -476,3 +476,31 @@ describe('gstack-review-plan: the full round 2 on a small fix range (GSTA-152 D6
|
||||
expect(run(r, [...pass2, '--range-base', rangeBase, '--depth-floor', 'full']).stdout).toMatch(/^NEXT: full \(a blocking finding was fixed and the diff is at full depth/m);
|
||||
});
|
||||
});
|
||||
|
||||
// Value: protects=the stop after an edit that followed the read-only final review names the exact command that records the
|
||||
// owner's ship-with-the-note ruling, with the edited paths and the stop head (GST-3775, GBRA-795); fails_when=the stop
|
||||
// says "ship with it as a ruled note" and names no command finish reads; seam=bin/gstack-review-plan --post-review
|
||||
describe('gstack-review-plan --post-review stop names the edit ruling (GST-3775)', () => {
|
||||
test('a fix after the read-only final review prints gstack-approvals rule --finding edit:<path> at the stop head', () => {
|
||||
const r = repo({ 'src/a.ts': 'export const a = 1;\n', 'src/gone.ts': 'export const g = 0;\n' });
|
||||
const git = (...a: string[]) => spawnSync('git', a, { cwd: r.dir, encoding: 'utf8', timeout: 10_000 }).stdout.trim();
|
||||
const passHead = git('rev-parse', 'HEAD');
|
||||
fs.rmSync(path.join(r.dir, 'src/gone.ts'));
|
||||
const odd = "src/q'$(id)`;x|y.ts";
|
||||
fs.appendFileSync(path.join(r.dir, 'src/a.ts'), 'export const b = 2;\n'); fs.writeFileSync(path.join(r.dir, 'src/a b.ts'), 'export const c = 3;\n');
|
||||
fs.writeFileSync(path.join(r.dir, odd), 'export const d = 4;\n');
|
||||
git('add', '.'); git('commit', '-qm', 'edit after the final review');
|
||||
const head = git('rev-parse', 'HEAD');
|
||||
const p = run(r, ['--pass', '3', '--last', 'full', '--range-base', passHead, '--post-review']);
|
||||
expect(p.status, p.stderr).toBe(0);
|
||||
expect(p.stdout).toContain("a fix followed the read-only final review: the lane's Captain decides (R51)");
|
||||
expect(p.stdout).toContain(`record that ruling once per edited path (each path shell-quoted; the owner-ref is the relay this open /ship run needs): gstack-approvals rule --finding 'edit:src/a.ts' --head ${head} --reason '<why`);
|
||||
expect(p.stdout).toContain("'src/a b.ts' cannot be ruled (a finding holds no whitespace), so an edit there keeps the fix and runs /ship again");
|
||||
expect(p.stdout).toContain("; a deletion ('src/gone.ts') cannot be ruled, so it keeps the fix and runs /ship again");
|
||||
const findings = [...p.stdout.split('\n').find(l => l.startsWith('NEXT: '))!.matchAll(/gstack-approvals rule --finding ('(?:[^']|'\\'')*') --head /g)].map(m => m[1]!);
|
||||
expect(findings).toHaveLength(2);
|
||||
const parsed = spawnSync('sh', ['-c', `printf '%s\\n' ${findings.join(' ')}`], { cwd: r.dir, encoding: 'utf8', timeout: 10_000 });
|
||||
expect(parsed.stdout).toBe(`edit:src/a.ts\nedit:${odd}\n`);
|
||||
expect(run(r, ['--pass', '3', '--last', 'full', '--range-base', passHead, '--fixed-below']).stdout).not.toContain('--finding edit:');
|
||||
}, 30_000);
|
||||
});
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* A ruled edit after the final review (GST-3775, GBRA-795 on garrytan/gbrain#10256): the read-only final review ran, a
|
||||
* one-line edit followed, finish stopped and gstack-review-plan --post-review stopped for the owner. The owner's "ship it
|
||||
* with the note" is recorded as one ruling per changed path, `gstack-approvals rule --finding edit:<path> --head <stop head>`,
|
||||
* and finish routes exactly those paths, at exactly the ruled bytes, as RULED_EDIT instead of stopping again.
|
||||
*/
|
||||
import { afterEach, describe, expect, setDefaultTimeout, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { lineOf, RELEASE, shipFixture, type ShipFx } from './helpers/ship-bin-fixture';
|
||||
|
||||
setDefaultTimeout(90_000);
|
||||
const BIN = path.dirname(RELEASE);
|
||||
const LANE = 'tests=printf " 3 pass\\n 0 fail\\nRan 3 tests across 1 file. [5.00ms]\\n"';
|
||||
const ships: ShipFx[] = [];
|
||||
afterEach(() => { while (ships.length) ships.pop()!.cleanup(); });
|
||||
|
||||
const TEST_V1 = "import { expect, test } from 'bun:test';\ntest('a', () => { expect(2).toBe(2); });\n";
|
||||
const TEST_V2 = "import { expect, test } from 'bun:test';\ntest('a', () => { expect(2).toBe(2); }, 1_000);\n";
|
||||
const TEST_V3 = "import { expect, test } from 'bun:test';\ntest('a', () => { expect(2).toBe(2); }, 2_000);\n";
|
||||
const STOPPED = 'STOP: behavior, tests or build inputs changed since review';
|
||||
|
||||
const run = (f: ShipFx, bin: string, args: string[]) => f.run(path.join(BIN, '..', bin), args, { GSTACK_APPROVALS_MIRROR: '0' });
|
||||
const finish = (f: ShipFx, reviewed: string, post: string) => f.run(RELEASE, ['finish', '--base', 'main', '--reviewed-tree', reviewed, '--docs-post', post, '--lane', LANE]);
|
||||
const rule = (f: ShipFx, file: string, head: string) => run(f, 'bin/gstack-approvals', ['rule', '--finding', `edit:${file}`, '--head', head, '--reason', 'the one-line timeout edit after the final review ships as a disclosed note', '--words', 'ship it with the note', '--by', 'GStack Minder (GSTA-36)']);
|
||||
|
||||
/** GBRA-795's sequence: the read-only final review read passHead, then a one-line edit to a test landed after it. */
|
||||
function editedAfterFinalReview() {
|
||||
const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n' }, { 'src/x.ts': 'export const x = 2;\n', 'test/x.test.ts': TEST_V1 });
|
||||
ships.push(f);
|
||||
const passHead = f.git('rev-parse', 'HEAD').stdout.trim();
|
||||
const reviewed = f.run(path.join(BIN, 'gstack-wtree'), []).stdout.trim();
|
||||
const post = path.join(f.root, 'post.json');
|
||||
expect(f.run(path.join(BIN, 'gstack-docs-candidate'), ['snapshot', '--out', post, '--audit-id', 'a1', '--mode', 'edit', '--base', 'main', '--docs', 'README.md']).status).toBe(0);
|
||||
f.write({ 'test/x.test.ts': TEST_V2 }); f.commit('raise the test timeout');
|
||||
return { f, passHead, stopHead: f.git('rev-parse', 'HEAD').stdout.trim(), reviewed, post };
|
||||
}
|
||||
|
||||
// Value: protects=the owner's ship-with-the-note ruling on an edit after the final review is honoured: finish routes the ruled
|
||||
// path as RULED_EDIT and goes on; fails_when=finish stops on the same edit after the ruling is recorded (GBRA-795, a
|
||||
// gstack-approvals add row a-4f45c3661ca2 that nothing read); seam=finish's route reading the approval record
|
||||
describe('finish honours an edit ruling after the final review (GST-3775)', () => {
|
||||
test('GBRA-795: finish stops, the owner rules the edit a note at the stop head, and finish goes on', () => {
|
||||
const { f, stopHead, reviewed, post } = editedAfterFinalReview();
|
||||
const before = finish(f, reviewed, post);
|
||||
expect([before.status, before.stdout]).toEqual([3, expect.stringContaining(`${STOPPED} (test/x.test.ts)`)]);
|
||||
expect(rule(f, 'test/x.test.ts', stopHead).status).toBe(0);
|
||||
const r = finish(f, reviewed, post);
|
||||
expect(r.stdout).not.toContain(STOPPED);
|
||||
expect(lineOf(r.stdout, 'RULED_EDIT')).toMatch(new RegExp(`^RULED_EDIT: test/x\\.test\\.ts \\(ruled at ${stopHead.slice(0, 12)} by GStack Minder \\(GSTA-36\\), approval a-[0-9a-f]{12}\\)$`));
|
||||
expect(lineOf(r.stdout, 'RULED_NOTE')).toMatch(/^RULED_NOTE: edit:test\/x\.test\.ts at /);
|
||||
expect([r.status, lineOf(r.stdout, 'EVIDENCE')]).toEqual([0, expect.stringMatching(/^EVIDENCE: FRESH label=tests /)]);
|
||||
});
|
||||
|
||||
// Value: protects=a ruling covers only the path it names, at the bytes it was made on; fails_when=one ruling accepts every
|
||||
// edit after review, or a path edited again after the ruling ships unread; seam=finish's route matching edit:<path> rulings
|
||||
test('a ruling covers only its own path at the ruled bytes', () => {
|
||||
const other = editedAfterFinalReview();
|
||||
expect(rule(other.f, 'src/x.ts', other.stopHead).status).toBe(0);
|
||||
expect(finish(other.f, other.reviewed, other.post).stdout).toContain(`${STOPPED} (test/x.test.ts)`);
|
||||
|
||||
const later = editedAfterFinalReview();
|
||||
expect(rule(later.f, 'test/x.test.ts', later.stopHead).status).toBe(0);
|
||||
later.f.write({ 'test/x.test.ts': TEST_V3 }); later.f.commit('edit it again after the ruling');
|
||||
const r = finish(later.f, later.reviewed, later.post);
|
||||
expect([r.status, r.stdout]).toEqual([3, expect.stringContaining(`${STOPPED} (test/x.test.ts)`)]);
|
||||
expect(r.stdout).not.toContain('RULED_EDIT:');
|
||||
expect(lineOf(r.stdout, 'RULED_EDIT_REFUSED')).toStartWith(`RULED_EDIT_REFUSED: test/x.test.ts (its mode or bytes differ from the ruled head ${later.stopHead.slice(0, 12)};`);
|
||||
expect(lineOf(r.stdout, 'RULED_NOTE')).toEndWith('(no RULED_EDIT at this head; not applied)');
|
||||
later.f.write({ 'test/x.test.ts': TEST_V2 }); later.f.commit('restore the ruled bytes');
|
||||
const restored = finish(later.f, later.reviewed, later.post);
|
||||
expect([restored.status, restored.stdout]).toEqual([3, expect.stringContaining(`${STOPPED} (test/x.test.ts)`)]);
|
||||
|
||||
const early = editedAfterFinalReview();
|
||||
expect(rule(early.f, 'test/x.test.ts', early.passHead).status).toBe(0);
|
||||
expect(finish(early.f, early.reviewed, early.post).stdout).toContain(`${STOPPED} (test/x.test.ts)`);
|
||||
});
|
||||
|
||||
// Value: protects=finish fails closed when git cannot hold the ruled path under the spelling it routes: a filename with
|
||||
// invalid UTF-8 reaches finish with a replacement character, both ls-tree lookups find nothing, and that must not read as
|
||||
// equal bytes; fails_when=a ruling on a path neither tree holds clears the stop; seam=finish's route reading each ls-tree
|
||||
test('a ruled path neither tree holds under its routed spelling stops finish (no file, not equal bytes)', () => {
|
||||
const { f, reviewed, post } = editedAfterFinalReview();
|
||||
const raw = Buffer.concat([Buffer.from(path.join(f.work, 'test') + path.sep), Buffer.from([0xff]), Buffer.from('y.test.ts')]);
|
||||
fs.writeFileSync(raw, TEST_V1); f.commit('add a test whose name is not UTF-8');
|
||||
const stopHead = f.git('rev-parse', 'HEAD').stdout.trim();
|
||||
const routed = 'test/\uFFFDy.test.ts';
|
||||
for (const p of ['test/x.test.ts', routed]) expect(rule(f, p, stopHead).status).toBe(0);
|
||||
const r = finish(f, reviewed, post);
|
||||
expect([r.status, r.stdout]).toEqual([3, expect.stringContaining(`${STOPPED} (${routed})`)]);
|
||||
expect(lineOf(r.stdout, 'RULED_EDIT_REFUSED')).toBe(`RULED_EDIT_REFUSED: ${routed} (no file at ${stopHead.slice(0, 12)}: a ruling covers a file git holds under this spelling, never a deletion; keep the edit and run /ship again, docs/ship-policy.md#ruled-edits)`);
|
||||
expect(r.stdout).toContain('RULED_EDIT: test/x.test.ts (');
|
||||
expect(r.stdout).toMatch(new RegExp(`^RULED_NOTE: edit:test/\\uFFFDy\\.test\\.ts at .* \\(no RULED_EDIT at this head; not applied\\)$`, 'm'));
|
||||
});
|
||||
|
||||
// Value: protects=a ruling on a replacement-character spelling never clears an edit to a different file: a filename with
|
||||
// invalid UTF-8 changed after review reaches finish as the spelling of an unchanged file that holds a literal U+FFFD;
|
||||
// fails_when=finish prints RULED_EDIT for the unchanged file and the unreviewed edit ships; seam=finish's route refusal
|
||||
test('a ruled spelling with a replacement character stops finish even when a file of that name exists', () => {
|
||||
const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n', 'test/\uFFFDy.test.ts': TEST_V1 }, { 'src/x.ts': 'export const x = 2;\n' });
|
||||
ships.push(f);
|
||||
const raw = Buffer.concat([Buffer.from(path.join(f.work, 'test') + path.sep), Buffer.from([0xff]), Buffer.from('y.test.ts')]);
|
||||
fs.writeFileSync(raw, TEST_V1); f.commit('add a test whose name is not UTF-8');
|
||||
const reviewed = f.run(path.join(BIN, 'gstack-wtree'), []).stdout.trim();
|
||||
const post = path.join(f.root, 'post.json');
|
||||
expect(f.run(path.join(BIN, 'gstack-docs-candidate'), ['snapshot', '--out', post, '--audit-id', 'a1', '--mode', 'edit', '--base', 'main', '--docs', 'README.md']).status).toBe(0);
|
||||
fs.writeFileSync(raw, TEST_V2); f.commit('edit it after the final review');
|
||||
const routed = 'test/\uFFFDy.test.ts';
|
||||
expect(rule(f, routed, f.git('rev-parse', 'HEAD').stdout.trim()).status).toBe(0);
|
||||
const r = finish(f, reviewed, post);
|
||||
expect([r.status, r.stdout]).toEqual([3, expect.stringContaining(`${STOPPED} (${routed})`)]);
|
||||
expect(r.stdout).not.toContain('RULED_EDIT:');
|
||||
expect(lineOf(r.stdout, 'RULED_EDIT_REFUSED')).toStartWith(`RULED_EDIT_REFUSED: ${routed} (its spelling holds a replacement character (U+FFFD)`);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user