mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-29 19:34:29 +01:00
A file deleted or renamed after the final review can now ship as a ruled note (GST-4139) (#4884)
The owner's `edit:` ruling now covers a file deleted after the final review, and a rename takes two rulings (old path and new), so folding or renaming a `changelog.d` fragment no longer fails /gstack-ship with `RULED_EDIT_REFUSED` and `RECEIPT_INVALID` (garrytan/gbrain#10623). Why: shipping a small post-review cleanup should not force another full review, but git has to prove the deletion is real and untouched since the ruling. Nothing to do: the ruling command is unchanged, and `gstack-review-plan --post-review` now prints it for deleted paths too. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/outside-voice#2 reader=outside-voice Review-Finding: p1/outside-voice#3 reader=outside-voice
This commit is contained in:
1 parent
bde36bd266
commit
adba58aa28
9 files changed
+322
-44
No files matched your search
@@ -251,12 +251,12 @@ function main(): number {
|
||||
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) && !routed?.ruled.has(p) && !stamps.has(p));
|
||||
const changed = pairs?.map(([, p]) => p);
|
||||
const spaced = changed?.filter(p => /\s/.test(p)) ?? [];
|
||||
const rulable = changed?.filter(p => !spaced.includes(p) && !routed?.ruled.has(p) && !stamps.has(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 /gstack-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 /gstack-ship again` : ''}${deleted.length ? `; a deletion (${deleted.map(quote).join(', ')}) cannot be ruled, so it keeps the fix and runs /gstack-ship again` : ''}`;
|
||||
plan.next.reason += `; if the owner rules instead that the edit ships as a disclosed note, record that ruling once per changed path, a deleted path too and both paths of a rename (each path shell-quoted; the owner-ref is the relay this open /gstack-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 a change there keeps the fix and runs /gstack-ship again` : ''}`;
|
||||
}
|
||||
const ranArg = flag('--targeted-ran');
|
||||
const delta = plan.next.step !== 'done' || !targeted.classes.length || ran ? null
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
**A file deleted or renamed after the final review can now ship as a ruled note, like an edit.** The owner's `edit:<path>` ruling covers a deleted path, and a rename takes two rulings, one for the old path and one for the new, so folding or renaming a `changelog.d` fragment after review no longer stops /gstack-ship with `RULED_EDIT_REFUSED` and `RECEIPT_INVALID` (garrytan/gbrain#10623). `gstack-review-plan --post-review` now prints the ruling command for deleted paths too. A ruling still never covers a path no commit deleted (a typo), a file deleted after its edit was ruled, or a file re-created or touched again after its deletion was ruled, and deleting money, auth, secret or gate code, or a docs claim, still gets its targeted read (GST-4139).
|
||||
@@ -245,7 +245,7 @@ rows, `claim`) was removed in GST-3562 part 4.
|
||||
| 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 (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 /gstack-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 changed path, deletions included, which finish then routes as `RULED_EDIT`: [ruled edits](ship-policy.md#ruled-edits)), or the fix goes to a new /gstack-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 stop (any row above) on gate class before Step 11's voices ran | Step 11's voices (adversarial, outside, targeted), then ask again with `--adversarial-ran` |
|
||||
|
||||
|
||||
+29
-15
@@ -1923,16 +1923,16 @@ beside the branch's hunks or an uncommitted change reads `STALE` and says which.
|
||||
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 /gstack-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:
|
||||
The owner's "ship it with the note" is a ruling per changed path (a deleted path
|
||||
and both paths of a rename included), with `edit:<path>` as the finding and the stop
|
||||
head as the head; the stop line prints the changed 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>`
|
||||
The stop line prints one such command per changed 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>,
|
||||
@@ -1941,18 +1941,32 @@ ancestor of it, the path's entry in the tree finish routes (mode and bytes, untr
|
||||
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
|
||||
filename that is not UTF-8 reaches finish with a replacement character), and 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 /gstack-ship again.
|
||||
another file than the one git changed, never match, so a ruling cannot clear them.
|
||||
|
||||
A deletion is ruled the same way, with `edit:<the deleted path>` at the stop head.
|
||||
The ruling clears it only when neither the ruled head nor the tree finish routes
|
||||
holds the path, a commit in the ruled head's first-parent history deleted a file (or
|
||||
a submodule) git held under exactly that spelling, and no commit after the ruled head
|
||||
touches the path.
|
||||
So a ruling on a path no commit deleted (a typo, or a directory) never clears, a
|
||||
file deleted after its edit was ruled stops finish (rule the deletion at the head
|
||||
that deleted it), and a file re-created after its deletion was ruled, or re-created
|
||||
and deleted again, stops finish too. A rename is a deletion and an addition (git
|
||||
compares with `--no-renames`), so it takes two rulings, one for the old path and one
|
||||
for the new. A ruled deletion still counts toward the targeted read: deleting money, auth, secret
|
||||
or gate code, or a docs claim, gets one targeted reader on HEAD before the receipt
|
||||
carries, as a ruled edit to it would.
|
||||
|
||||
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 and deletions since the final
|
||||
review, never a path only a base merge moved. 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 a change there
|
||||
keeps the fix and runs /gstack-ship again.
|
||||
A ruled path the documentation audit hashed also stays fresh at stage 3
|
||||
(`DOCS: fresh … ruled=<n>`, GBRA-108); an unruled doc edit still needs the
|
||||
stage 3 recovery finish's stop names. The ruling is an ordinary
|
||||
|
||||
+12
-5
@@ -118,7 +118,9 @@ export const ruledEditLine = (p: string, n: RuledNote) => `RULED_EDIT: ${p} (rul
|
||||
/**
|
||||
* Which of `paths` an owner's `edit:<path>` ruling clears at `now` (a commit or tree; docs/ship-policy.md#ruled-edits): the ruling
|
||||
* names HEAD or an ancestor of it, both trees hold the path as one file under exactly this spelling with the same mode and bytes,
|
||||
* and no first-parent commit after the ruled head touches it. finish routes the cleared paths as RULED_EDIT and gstack-review-plan
|
||||
* or neither holds it and a first-parent commit up to the ruled head deleted a file (or submodule) git held under exactly this spelling (a
|
||||
* deletion, and each side of a rename, which git's --no-renames diff splits into a deletion and an addition), and no first-parent
|
||||
* commit after the ruled head touches it. finish routes the cleared paths as RULED_EDIT and gstack-review-plan
|
||||
* leaves them out of the fix range (GST-3814), so both read a ruling the same way; `refused` names each ruled path that did not
|
||||
* clear, with why.
|
||||
*/
|
||||
@@ -129,11 +131,16 @@ export function ruledEdits(cwd: string, paths: readonly string[], now: string, e
|
||||
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 deleted = (head: string, p: string) => { const log = git(top, ['--literal-pathspecs', 'log', '--no-show-signature', '--first-parent', '--no-renames', '--diff-filter=D', '-1', '--format=%H', head, '--', p]); const c = log.stdout.trim();
|
||||
return log.status === 0 && /^[0-9a-f]{40,64}$/.test(c) && entry(c, p) === '' && /^\d{6} (?:blob|commit) /.test(entry(`${c}^1`, p) ?? ''); };
|
||||
const refusal = (n: RuledNote, 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`;
|
||||
const h = n.head.slice(0, 12);
|
||||
if (!ancestor(n.head, 'HEAD')) return `ruled at ${h}, which is not HEAD or an ancestor of it`;
|
||||
const [at, cur] = [entry(n.head, p), entry(now, p)];
|
||||
if (at === null || cur === null) return `git ls-tree could not read it at ${at === null ? h : 'the tree finish routes'}`;
|
||||
if (!at && !cur && !(top && deleted(n.head, p))) return `no file at ${h} or in the tree finish routes, and no commit up to ${h} deleted a file git held under this spelling: a ruling covers a file git holds or deleted under exactly this spelling`;
|
||||
if (!at && cur) return `no file at ${h}, but the tree finish routes holds one: a ruling on a deletion never covers re-creating the file`;
|
||||
if (at && !cur) return `no file in the tree finish routes: a ruling on an edit never covers deleting the file; rule the deletion at the head that deleted it`;
|
||||
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`;
|
||||
|
||||
@@ -616,8 +616,8 @@ export const plainDocsSince = (root: string, from: string, head: string, base: s
|
||||
|
||||
/**
|
||||
* The owner's `edit:<path>` rulings (docs/ship-policy.md#ruled-edits) that clear every path the PR's own change moved from `from`
|
||||
* to `head`, release stamps aside (productChangeSince), each at its ruled bytes as finish and gstack-review-plan read them
|
||||
* (ruledEdits); null when a path has no clearing ruling, is deleted, the change cannot be built, or it is a docs claim
|
||||
* to `head`, release stamps aside (productChangeSince), each at its ruled bytes, or as a ruled deletion, as finish and
|
||||
* gstack-review-plan read them (ruledEdits); null when a path has no clearing ruling, the change cannot be built, or it is a docs claim
|
||||
* (docsChangeSince), which gstack-review-plan's targeted-only read still reads fresh (lib/review-targeted-delta.ts), so a ruling
|
||||
* never carries the record past it. A targeted record carries across such a change only when nothing in it carries a targeted
|
||||
* class (parseReviewTargeted, HARN-1 #638).
|
||||
|
||||
@@ -307,10 +307,10 @@ describe('gstack-review-plan: the full round 2 on a small fix range (GSTA-152 D6
|
||||
// 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 r = repo({ 'src/a.ts': 'export const a = 1;\n', 'src/gone.ts': 'export const g = 0;\n', 'src/old b.ts': 'export const s = 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'));
|
||||
fs.rmSync(path.join(r.dir, 'src/gone.ts')); fs.rmSync(path.join(r.dir, 'src/old b.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');
|
||||
@@ -319,13 +319,13 @@ describe('gstack-review-plan --post-review stop names the edit ruling (GST-3775)
|
||||
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 /gstack-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 /gstack-ship again");
|
||||
expect(p.stdout).toContain("; a deletion ('src/gone.ts') cannot be ruled, so it keeps the fix and runs /gstack-ship again");
|
||||
expect(p.stdout).toContain(`record that ruling once per changed path, a deleted path too and both paths of a rename (each path shell-quoted; the owner-ref is the relay this open /gstack-ship run needs): gstack-approvals rule --finding 'edit:src/a.ts' --head ${head} --reason '<why`);
|
||||
expect(p.stdout).toContain("'src/a b.ts', 'src/old b.ts' cannot be ruled (a finding holds no whitespace), so a change there keeps the fix and runs /gstack-ship again");
|
||||
expect(p.stdout).not.toContain('a deletion (');
|
||||
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);
|
||||
expect(findings).toHaveLength(3);
|
||||
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(parsed.stdout).toBe(`edit:src/a.ts\nedit:src/gone.ts\nedit:${odd}\n`);
|
||||
expect(run(r, ['--pass', '3', '--last', 'full', '--range-base', passHead, '--fixed-below']).stdout).not.toContain('--finding edit:');
|
||||
}, 30_000);
|
||||
});
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
*/
|
||||
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 { ruledEdits, type RuledNote } from '../lib/ruled-notes';
|
||||
import { spawnSync } from '../lib/spawn-sync';
|
||||
import { DOCS_CAPS_KEY_VERSION } from '../lib/ship-policy';
|
||||
import { lineOf, RELEASE, shipFixture, type ShipFx } from './helpers/ship-bin-fixture';
|
||||
|
||||
@@ -14,7 +17,8 @@ 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 dirs: string[] = [];
|
||||
afterEach(() => { while (ships.length) ships.pop()!.cleanup(); while (dirs.length) fs.rmSync(dirs.pop()!, { recursive: true, force: true }); });
|
||||
|
||||
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";
|
||||
@@ -22,7 +26,7 @@ const TEST_V3 = "import { expect, test } from 'bun:test';\ntest('a', () => { exp
|
||||
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 finish = (f: ShipFx, reviewed: string, post: string, more: string[] = []) => f.run(RELEASE, ['finish', '--base', 'main', '--reviewed-tree', reviewed, '--docs-post', post, ...more, '--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. */
|
||||
@@ -89,7 +93,7 @@ describe('finish honours an edit ruling after the final review (GST-3775)', () =
|
||||
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 /gstack-ship again, docs/ship-policy.md#ruled-edits)`);
|
||||
expect(lineOf(r.stdout, 'RULED_EDIT_REFUSED')).toBe(`RULED_EDIT_REFUSED: ${routed} (no file at ${stopHead.slice(0, 12)} or in the tree finish routes, and no commit up to ${stopHead.slice(0, 12)} deleted a file git held under this spelling: a ruling covers a file git holds or deleted under exactly this spelling; keep the edit and run /gstack-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'));
|
||||
});
|
||||
@@ -163,3 +167,184 @@ describe('a ruled edit to an audited doc keeps the docs audit fresh (GBRA-108)',
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/** A file the final review read is deleted (or renamed: git's --no-renames diff is a deletion plus an addition) after it. */
|
||||
function deletedAfterFinalReview(rename: boolean, mergeBase = false) {
|
||||
const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n' }, { 'src/x.ts': 'export const x = 2;\n', 'src/old.ts': 'export const o = 1;\n' });
|
||||
ships.push(f);
|
||||
const reviewed = f.run(path.join(BIN, 'gstack-wtree'), []).stdout.trim();
|
||||
const reviewedBase = f.git('merge-base', 'origin/main', 'HEAD').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);
|
||||
if (mergeBase) { f.advanceBase({ 'src/base.ts': 'export const base = 1;\n' }); expect(f.git('fetch', '-q', 'origin').status).toBe(0); expect(f.git('merge', '-q', '--no-edit', 'origin/main').status).toBe(0); }
|
||||
if (rename) fs.renameSync(path.join(f.work, 'src/old.ts'), path.join(f.work, 'src/new.ts')); else fs.rmSync(path.join(f.work, 'src/old.ts'));
|
||||
f.commit(rename ? 'rename a file after the final review' : 'delete a file after the final review');
|
||||
return { f, stopHead: f.git('rev-parse', 'HEAD').stdout.trim(), reviewed, reviewedBase, post };
|
||||
}
|
||||
|
||||
// Value: protects=the owner can rule a deletion after the final review, and a rename as its two paths, so folding or renaming a
|
||||
// file (a changelog.d fragment, gbrain#10623) ships as a disclosed note; fails_when=finish refuses every deleted path
|
||||
// (`RULED_EDIT_REFUSED: … never a deletion`), or one ruling on a rename's new path clears its old one; seam=finish's route
|
||||
// reading edit:<path> rulings through ruledEdits
|
||||
describe('finish honours a ruled deletion or rename after the final review (GST-4139)', () => {
|
||||
test('a deleted file: finish stops, the owner rules it at the stop head, and finish routes it as RULED_EDIT', () => {
|
||||
const { f, stopHead, reviewed, post } = deletedAfterFinalReview(false);
|
||||
expect(finish(f, reviewed, post).stdout).toContain(`${STOPPED} (src/old.ts)`);
|
||||
expect(rule(f, 'src/old.ts', stopHead).status).toBe(0);
|
||||
const r = finish(f, reviewed, post);
|
||||
expect(r.stdout).not.toContain(STOPPED);
|
||||
expect(r.stdout).not.toContain('RULED_EDIT_REFUSED');
|
||||
expect(lineOf(r.stdout, 'RULED_EDIT')).toStartWith(`RULED_EDIT: src/old.ts (ruled at ${stopHead.slice(0, 12)} by GStack Minder (GSTA-36), approval a-`);
|
||||
expect(r.status).toBe(0);
|
||||
});
|
||||
|
||||
test('a rename needs both rulings: the new path alone still stops on the old one', () => {
|
||||
const { f, stopHead, reviewed, post } = deletedAfterFinalReview(true);
|
||||
expect(rule(f, 'src/new.ts', stopHead).status).toBe(0);
|
||||
const one = finish(f, reviewed, post);
|
||||
expect([one.status, one.stdout]).toEqual([3, expect.stringContaining(`${STOPPED} (src/old.ts)`)]);
|
||||
expect(rule(f, 'src/old.ts', stopHead).status).toBe(0);
|
||||
const r = finish(f, reviewed, post);
|
||||
expect(r.stdout).not.toContain(STOPPED);
|
||||
expect(r.stdout.split('\n').filter(l => l.startsWith('RULED_EDIT: ')).map(l => l.split(' (')[0])).toEqual(['RULED_EDIT: src/new.ts', 'RULED_EDIT: src/old.ts']);
|
||||
expect(r.status).toBe(0);
|
||||
});
|
||||
|
||||
test('a base merge after the review, then the deletion: the ruling clears only the PR\'s own deletion', () => {
|
||||
const { f, stopHead, reviewed, reviewedBase, post } = deletedAfterFinalReview(false, true);
|
||||
expect(rule(f, 'src/old.ts', stopHead).status).toBe(0);
|
||||
const r = finish(f, reviewed, post, ['--reviewed-base', reviewedBase]);
|
||||
expect(r.stdout).not.toContain(STOPPED);
|
||||
expect(r.stdout.split('\n').filter(l => l.startsWith('RULED_EDIT: ')).map(l => l.split(' (')[0])).toEqual(['RULED_EDIT: src/old.ts']);
|
||||
expect(r.status).toBe(0);
|
||||
});
|
||||
|
||||
test('a file deleted after its edit was ruled stops finish', () => {
|
||||
const { f, stopHead, reviewed, post } = editedAfterFinalReview();
|
||||
expect(rule(f, 'test/x.test.ts', stopHead).status).toBe(0);
|
||||
fs.rmSync(path.join(f.work, 'test/x.test.ts')); f.commit('delete the ruled file');
|
||||
const r = finish(f, reviewed, post);
|
||||
expect([r.status, r.stdout]).toEqual([3, expect.stringContaining(`${STOPPED} (test/x.test.ts)`)]);
|
||||
expect(lineOf(r.stdout, 'RULED_EDIT_REFUSED')).toStartWith('RULED_EDIT_REFUSED: test/x.test.ts (no file in the tree finish routes: a ruling on an edit never covers deleting the file');
|
||||
});
|
||||
});
|
||||
|
||||
/** A doc the Step 14.5 audit hashed is deleted after the final review. */
|
||||
function docDeletedAfterAudit(file: string) {
|
||||
const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n', [file]: '# Notes\n\nOne line.\n' }, { 'src/x.ts': 'export const x = 2;\n' });
|
||||
ships.push(f);
|
||||
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', file]).status).toBe(0);
|
||||
fs.rmSync(path.join(f.work, file)); f.commit('fold the doc away after the final review');
|
||||
return { f, stopHead: f.git('rev-parse', 'HEAD').stdout.trim(), reviewed, post };
|
||||
}
|
||||
|
||||
// Value: protects=a ruled deletion of a doc the docs audit hashed keeps stage 3 fresh, and an unruled one stays stale;
|
||||
// fails_when=stage 3 reads the deleted file (ENOENT) or calls the ruled deletion stale; seam=lib/ship-release.ts docsFresh
|
||||
describe('a ruled deletion of an audited doc keeps the docs audit fresh (GST-4139)', () => {
|
||||
test('ruled: DOCS fresh with ruled=1; unruled: DOCS stale', () => {
|
||||
const ruled = docDeletedAfterAudit('guide/notes.md');
|
||||
expect(rule(ruled.f, 'guide/notes.md', ruled.stopHead).status).toBe(0);
|
||||
const r = finishRechecked(ruled.f, ruled.reviewed, ruled.post);
|
||||
expect(lineOf(r.stdout, 'RULED_EDIT')).toStartWith('RULED_EDIT: guide/notes.md (');
|
||||
expect(lineOf(r.stdout, 'DOCS')).toBe('DOCS: fresh against the Step 14.5 post-audit snapshot (carried: tests=0 base=0 requested=0 ruled=1)');
|
||||
const plain = docDeletedAfterAudit('guide/notes.md');
|
||||
expect(lineOf(finishRechecked(plain.f, plain.reviewed, plain.post).stdout, 'DOCS')).toBe('DOCS: stale (guide/notes.md)');
|
||||
});
|
||||
});
|
||||
|
||||
/** A plain git repository outside this checkout for ruledEdits itself; `commit` takes null to delete a file. */
|
||||
function gitRepo() {
|
||||
const dir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'ruled-deletion-')));
|
||||
dirs.push(dir);
|
||||
const git = (...args: string[]) => {
|
||||
const r = spawnSync('git', ['-c', 'user.email=fixture@example.com', '-c', 'user.name=Fixture', '-c', 'commit.gpgsign=false', ...args], { cwd: dir, encoding: 'utf8', timeout: 30_000 });
|
||||
if (r.status !== 0) throw new Error(`git ${args.join(' ')}: ${r.stderr}`);
|
||||
return String(r.stdout).trim();
|
||||
};
|
||||
const commit = (files: Record<string, string | null>, msg: string) => {
|
||||
for (const [p, t] of Object.entries(files)) {
|
||||
const at = path.join(dir, p);
|
||||
if (t === null) fs.rmSync(at); else { fs.mkdirSync(path.dirname(at), { recursive: true }); fs.writeFileSync(at, t); }
|
||||
}
|
||||
git('add', '-A'); git('commit', '-qm', msg);
|
||||
return git('rev-parse', 'HEAD');
|
||||
};
|
||||
git('init', '-q', '-b', 'main');
|
||||
commit({ 'src/a.ts': 'export const a = 1;\n', 'src/gone.ts': 'export const g = 1;\n', 'dir/inner.ts': 'export const i = 1;\n' }, 'base');
|
||||
return { dir, git, commit };
|
||||
}
|
||||
const note = (p: string, head: string): RuledNote => ({ finding: `edit:${p}`, head, by: 'GStack Minder (GSTA-36)', reason: 'ships as a note', at: '2026-11-28T00:00:00Z', approval: 'a-000000000001' });
|
||||
const ruledAt = (dir: string, paths: string[], notes: RuledNote[], now = 'HEAD') => { const r = ruledEdits(dir, paths, now, notes); return { ruled: [...r.ruled.keys()].sort(), refused: r.refused }; };
|
||||
|
||||
// Value: protects=ruledEdits clears a deletion only when git proves it: the ruled head and the routed tree both lack the path, a
|
||||
// commit up to the ruled head deleted a file under exactly that spelling, and nothing after the ruling touched it; every other
|
||||
// case still refuses; fails_when=a typo, a directory, a re-created or re-deleted file, a non-ancestor head or an unreadable tree
|
||||
// clears; seam=lib/ruled-notes.ts ruledEdits
|
||||
describe('ruledEdits on deleted paths (GST-4139)', () => {
|
||||
test('a deletion and both paths of a rename clear; a rename ruled on one path clears only that path', () => {
|
||||
const r = gitRepo();
|
||||
const head = r.commit({ 'src/gone.ts': null, 'src/a.ts': null, 'src/b.ts': 'export const a = 1;\n' }, 'delete gone, rename a to b');
|
||||
expect(ruledAt(r.dir, ['src/a.ts', 'src/b.ts', 'src/gone.ts'], [note('src/gone.ts', head), note('src/a.ts', head), note('src/b.ts', head)])).toEqual({ ruled: ['src/a.ts', 'src/b.ts', 'src/gone.ts'], refused: [] });
|
||||
expect(ruledAt(r.dir, ['src/a.ts', 'src/b.ts'], [note('src/b.ts', head)])).toEqual({ ruled: ['src/b.ts'], refused: [] });
|
||||
});
|
||||
|
||||
test('a path no commit deleted (a typo, or a directory whose files were deleted) refuses', () => {
|
||||
const r = gitRepo();
|
||||
const head = r.commit({ 'dir/inner.ts': null, 'src/gone.ts': null }, 'delete');
|
||||
const out = ruledAt(r.dir, ['src/gonee.ts', 'dir'], [note('src/gonee.ts', head), note('dir', head)]);
|
||||
expect(out.ruled).toEqual([]);
|
||||
expect(out.refused).toEqual(['src/gonee.ts', 'dir'].map(p => `${p} (no file at ${head.slice(0, 12)} or in the tree finish routes, and no commit up to ${head.slice(0, 12)} deleted a file git held under this spelling: a ruling covers a file git holds or deleted under exactly this spelling; keep the edit and run /gstack-ship again, docs/ship-policy.md#ruled-edits)`));
|
||||
});
|
||||
|
||||
test('deleting after an edit ruling, re-creating after a deletion ruling, and re-creating then re-deleting all refuse', () => {
|
||||
const del = gitRepo();
|
||||
const edited = del.commit({ 'src/a.ts': 'export const a = 2;\n' }, 'edit');
|
||||
del.commit({ 'src/a.ts': null }, 'delete after the ruling');
|
||||
expect(ruledAt(del.dir, ['src/a.ts'], [note('src/a.ts', edited)]).refused[0]).toStartWith('src/a.ts (no file in the tree finish routes: a ruling on an edit never covers deleting the file');
|
||||
|
||||
const back = gitRepo();
|
||||
const gone = back.commit({ 'src/gone.ts': null }, 'delete');
|
||||
back.commit({ 'src/gone.ts': 'export const g = 1;\n' }, 're-create it after the ruling');
|
||||
expect(ruledAt(back.dir, ['src/gone.ts'], [note('src/gone.ts', gone)]).refused[0]).toStartWith(`src/gone.ts (no file at ${gone.slice(0, 12)}, but the tree finish routes holds one: a ruling on a deletion never covers re-creating the file`);
|
||||
back.commit({ 'src/gone.ts': null }, 'and delete it again');
|
||||
expect(ruledAt(back.dir, ['src/gone.ts'], [note('src/gone.ts', gone)]).refused[0]).toStartWith(`src/gone.ts (a commit after ${gone.slice(0, 12)} touches it`);
|
||||
});
|
||||
|
||||
test('a replacement character, a head off this branch, or an unreadable tree refuses a deletion', () => {
|
||||
const r = gitRepo();
|
||||
const odd = 'src/x\uFFFDy.ts';
|
||||
r.commit({ [odd]: 'export const x = 1;\n' }, 'a file whose name holds U+FFFD');
|
||||
r.git('checkout', '-q', '-b', 'side');
|
||||
const side = r.commit({ 'src/gone.ts': null }, 'delete on a side branch');
|
||||
r.git('checkout', '-q', 'main');
|
||||
const head = r.commit({ [odd]: null, 'src/gone.ts': null }, 'delete');
|
||||
expect(ruledAt(r.dir, [odd], [note(odd, head)]).refused[0]).toStartWith(`${odd} (its spelling holds a replacement character (U+FFFD)`);
|
||||
expect(ruledAt(r.dir, ['src/gone.ts'], [note('src/gone.ts', side)]).refused[0]).toStartWith(`src/gone.ts (ruled at ${side.slice(0, 12)}, which is not HEAD or an ancestor of it`);
|
||||
expect(ruledAt(r.dir, ['src/gone.ts'], [note('src/gone.ts', head)], '0'.repeat(40)).refused[0]).toStartWith('src/gone.ts (git ls-tree could not read it at the tree finish routes');
|
||||
});
|
||||
|
||||
test('a deleted submodule clears like a file, even with log.showSignature on', () => {
|
||||
const r = gitRepo();
|
||||
r.git('config', 'log.showSignature', 'true');
|
||||
r.git('update-index', '--add', '--cacheinfo', `160000,${r.git('rev-parse', 'HEAD')},vendor/sub`);
|
||||
r.git('commit', '-qm', 'add a submodule');
|
||||
r.git('rm', '-q', '--cached', 'vendor/sub');
|
||||
r.git('commit', '-qm', 'remove the submodule');
|
||||
const head = r.git('rev-parse', 'HEAD');
|
||||
expect(ruledAt(r.dir, ['vendor/sub'], [note('vendor/sub', head)])).toEqual({ ruled: ['vendor/sub'], refused: [] });
|
||||
});
|
||||
|
||||
test('a base merge between the review and the deletion: the deletion still clears', () => {
|
||||
const r = gitRepo();
|
||||
r.git('checkout', '-q', '-b', 'feat');
|
||||
r.commit({ 'src/a.ts': 'export const a = 2;\n' }, 'feat');
|
||||
r.git('checkout', '-q', 'main');
|
||||
r.commit({ 'src/base.ts': 'export const b = 1;\n' }, 'base moves');
|
||||
r.git('checkout', '-q', 'feat');
|
||||
r.git('merge', '-q', '--no-edit', 'main');
|
||||
const head = r.commit({ 'src/gone.ts': null }, 'delete after the review');
|
||||
expect(ruledAt(r.dir, ['src/gone.ts'], [note('src/gone.ts', head)])).toEqual({ ruled: ['src/gone.ts'], refused: [] });
|
||||
});
|
||||
});
|
||||
@@ -11,7 +11,7 @@ import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { ledgerPass, summarizeReviewLoop } from '../lib/review-scope';
|
||||
import { parseReviewTargeted, plainDocsSince, ruledChangeSince, targetedClassesSince } from '../lib/ship-receipt-depth';
|
||||
import { docsChangeSince, parseReviewTargeted, plainDocsSince, ruledChangeSince, targetedClassesSince } from '../lib/ship-receipt-depth';
|
||||
import { spawnSync } from '../lib/spawn-sync';
|
||||
import { BASE_POLICY, cleanup, makeFixtureRepo, runBin, type FixtureRepo } from './helpers/restamp-fixture';
|
||||
|
||||
@@ -27,17 +27,17 @@ const ENV = { GSTACK_APPROVALS_MIRROR: '0' };
|
||||
const run = (repo: FixtureRepo, name: string, args: string[]) => { const r = runBin(repo, name, args, ENV); return { status: r.status, stdout: r.out, stderr: r.err }; };
|
||||
|
||||
/** A money-class PR whose final review (and its targeted reader) read `passHead`, then Step 12's stamps, then one more edit. */
|
||||
function shipped(edit: Record<string, string>) {
|
||||
function shipped(edit: Record<string, string | null>, atPass: Record<string, string> = {}) {
|
||||
const repo = makeFixtureRepo({ policy: BASE_POLICY });
|
||||
repos.push(repo);
|
||||
const write = (files: Record<string, string>, msg: string) => {
|
||||
for (const [p, text] of Object.entries(files)) { fs.mkdirSync(path.dirname(path.join(repo.work, p)), { recursive: true }); fs.writeFileSync(path.join(repo.work, p), text); }
|
||||
const write = (files: Record<string, string | null>, msg: string) => {
|
||||
for (const [p, text] of Object.entries(files)) { if (text === null) { fs.rmSync(path.join(repo.work, p)); continue; } fs.mkdirSync(path.dirname(path.join(repo.work, p)), { recursive: true }); fs.writeFileSync(path.join(repo.work, p), text); }
|
||||
repo.git('add', '-A'); repo.git('commit', '-q', '-m', msg);
|
||||
return repo.git('rev-parse', 'HEAD');
|
||||
};
|
||||
const log = fs.readFileSync(path.join(repo.work, 'CHANGELOG.md'), 'utf8');
|
||||
repo.git('checkout', '-q', '-b', 'feat');
|
||||
const passHead = write({ 'src/billing.ts': MONEY_CODE, 'src/util.ts': UTIL, 'CHANGELOG.md': log.replace('## [1.2.3.0]', '## [Unreleased]\n\n- charge() caps spend\n\n## [1.2.3.0]') }, 'feat');
|
||||
const passHead = write({ ...atPass, 'src/billing.ts': MONEY_CODE, 'src/util.ts': UTIL, 'CHANGELOG.md': log.replace('## [1.2.3.0]', '## [Unreleased]\n\n- charge() caps spend\n\n## [1.2.3.0]') }, 'feat');
|
||||
write({ VERSION: '1.2.4.0\n', 'CHANGELOG.md': log.replace('## [1.2.3.0]', '## [1.2.4.0] - 2026-11-27\n\n- charge() caps spend\n\n## [1.2.3.0]') }, 'release stamps');
|
||||
const head = write(edit, 'edit after the read-only final review');
|
||||
return { repo, passHead, head };
|
||||
@@ -52,9 +52,9 @@ const next = (stdout: string) => stdout.split('\n').find(l => l.startsWith('NEXT
|
||||
const dispatches = (stdout: string) => stdout.split('\n').filter(l => l.startsWith('DISPATCH: '));
|
||||
|
||||
/** parseReviewTargeted with the receipt's own predicates (bin/gstack-ship-receipt write), for a record the reader made at `read`. */
|
||||
const useRepo = (repo: FixtureRepo) => { Object.assign(process.env, repo.env, ENV); delete process.env.GSTACK_APPROVALS_DIR; };
|
||||
function bind(repo: FixtureRepo, read: string, head: string) {
|
||||
Object.assign(process.env, repo.env, ENV);
|
||||
delete process.env.GSTACK_APPROVALS_DIR;
|
||||
useRepo(repo);
|
||||
const productOf = (c: string) => spawnSync('git', ['patch-id', '--verbatim'], { input: spawnSync('git', ['diff', 'main', c, '--', '.', ':(exclude)VERSION', ':(exclude)CHANGELOG.md'], { cwd: repo.work, encoding: 'utf8', timeout: 10_000 }).stdout, cwd: repo.work, encoding: 'utf8', timeout: 10_000 }).stdout.split(' ')[0];
|
||||
const record = { classes: ['money'], rules: 'r', brief_sha: 'a'.repeat(64), status: 'done', findings: 0, raised_by: 'targeted', head: read };
|
||||
return parseReviewTargeted(record, productOf(head)!, productOf, from => targetedClassesSince(repo.work, from, head, 'main'), from => plainDocsSince(repo.work, from, head, 'main'), undefined, from => ruledChangeSince(repo.work, from, head, 'main'));
|
||||
@@ -128,6 +128,77 @@ describe('a Captain-ruled edit after the read-only final review (HARN-1)', () =>
|
||||
});
|
||||
});
|
||||
|
||||
const FRAGMENT = '- Ruled edits now cover a file deleted or renamed after the final review.\n';
|
||||
const LEGACY_BILLING = 'export const legacyCapUsd = 50;\nexport function legacyCharge(amountUsd: number) { if (amountUsd > legacyCapUsd) throw new Error("over cap"); return amountUsd; }\n';
|
||||
|
||||
// Value: protects=a deletion or rename after the read-only final review rules like an edit (gbrain#10623: a changelog.d fragment
|
||||
// renamed after review failed RULED_EDIT_REFUSED and RECEIPT_INVALID), and a deletion that removes money code or a docs claim
|
||||
// still gets its targeted reader; fails_when=the plan refuses deleted paths as unrulable, the receipt refuses the record across a
|
||||
// ruled rename, or a ruled deletion of targeted-class code or a claim carries the old record; seam=bin/gstack-review-plan
|
||||
// --range-base, ruledChangeSince, targetedClassesSince and docsChangeSince
|
||||
describe('a ruled deletion or rename after the read-only final review (GST-4139)', () => {
|
||||
test('a ruled code edit and a renamed changelog fragment: the stop prints every ruling, and with all three the plan is done and the receipt carries', () => {
|
||||
const { repo, passHead, head } = shipped({ 'src/util.ts': UTIL.replace('trim()', 'trim().toLowerCase()'), 'changelog.d/feat.md': null, 'changelog.d/ruled-deletions.md': FRAGMENT }, { 'changelog.d/feat.md': FRAGMENT });
|
||||
useRepo(repo);
|
||||
const ran = patchAt(repo, passHead);
|
||||
const stop = plan(repo, ['--range-base', passHead, '--targeted-ran', ran]);
|
||||
expect(next(stop.stdout)).toStartWith('NEXT: stop (');
|
||||
for (const p of ['src/util.ts', 'changelog.d/feat.md', 'changelog.d/ruled-deletions.md']) expect(stop.stdout).toContain(`--finding 'edit:${p}' --head ${head}`);
|
||||
expect(stop.stdout).not.toContain('cannot be ruled');
|
||||
for (const p of ['src/util.ts', 'changelog.d/ruled-deletions.md']) expect(rule(repo, p, head).status).toBe(0);
|
||||
expect(next(plan(repo, ['--range-base', passHead, '--targeted-ran', ran]).stdout)).toStartWith('NEXT: stop (');
|
||||
expect(bind(repo, passHead, head).ok).toBe(false);
|
||||
expect(ruledChangeSince(repo.work, passHead, head, 'main')).toBeNull();
|
||||
expect(rule(repo, 'changelog.d/feat.md', head).status).toBe(0);
|
||||
const p = plan(repo, ['--range-base', passHead, '--targeted-ran', ran]);
|
||||
expect(p.status, p.stderr).toBe(0);
|
||||
expect(p.stdout).toContain(`FIX_RANGE: runtime_lines=0 base=${passHead} ruled=3`);
|
||||
expect(next(p.stdout)).toStartWith('NEXT: done (every edit since --range-base is ruled a note (RULED_EDIT)');
|
||||
expect(dispatches(p.stdout)).toEqual([]);
|
||||
expect(targetedClassesSince(repo.work, passHead, head, 'main')).toEqual([]);
|
||||
expect(ruledChangeSince(repo.work, passHead, head, 'main')?.map(n => n.finding).sort()).toEqual(['edit:changelog.d/feat.md', 'edit:changelog.d/ruled-deletions.md', 'edit:src/util.ts']);
|
||||
expect(bind(repo, passHead, head)).toMatchObject({ ok: true, targeted: { read: passHead, ruled_edits: [{ path: 'changelog.d/feat.md' }, { path: 'changelog.d/ruled-deletions.md' }, { path: 'src/util.ts' }] } });
|
||||
});
|
||||
|
||||
test('a ruled plain doc deletion: the plan is done and the record carries', () => {
|
||||
const { repo, passHead, head } = shipped({ 'guide/notes.md': null }, { 'guide/notes.md': '# Notes\n\nHow the label helper trims.\n' });
|
||||
useRepo(repo);
|
||||
const ran = patchAt(repo, passHead);
|
||||
expect(rule(repo, 'guide/notes.md', head).status).toBe(0);
|
||||
const p = plan(repo, ['--range-base', passHead, '--targeted-ran', ran]);
|
||||
expect(next(p.stdout)).toStartWith('NEXT: done (every edit since --range-base is ruled a note (RULED_EDIT)');
|
||||
expect(bind(repo, passHead, head).ok).toBe(true);
|
||||
expect(ruledChangeSince(repo.work, passHead, head, 'main')?.map(n => n.finding)).toEqual(['edit:guide/notes.md']);
|
||||
});
|
||||
|
||||
test('a ruled deletion of money code names money: one targeted reader on HEAD, and the old record does not carry', () => {
|
||||
const { repo, passHead, head } = shipped({ 'src/legacy-billing.ts': null }, { 'src/legacy-billing.ts': LEGACY_BILLING });
|
||||
useRepo(repo);
|
||||
const ran = patchAt(repo, passHead);
|
||||
expect(rule(repo, 'src/legacy-billing.ts', head).status).toBe(0);
|
||||
expect(targetedClassesSince(repo.work, passHead, head, 'main')).toEqual(['money']);
|
||||
const p = plan(repo, ['--range-base', passHead, '--targeted-ran', ran]);
|
||||
expect(p.stdout).toContain(`FIX_RANGE: runtime_lines=0 base=${passHead} ruled=1`);
|
||||
expect(next(p.stdout)).toStartWith('NEXT: targeted (the loop is done and every edit since --range-base is ruled a note');
|
||||
expect(dispatches(p.stdout)).toEqual(['DISPATCH: targeted targeted effort=full classes=money']);
|
||||
expect(bind(repo, passHead, head)).toMatchObject({ ok: false, message: expect.stringContaining('the product changed after the read') });
|
||||
expect(bind(repo, head, head).ok).toBe(true);
|
||||
});
|
||||
|
||||
test('a ruled deletion of a docs claim is read fresh: the receipt refuses the old record', () => {
|
||||
const { repo, passHead, head } = shipped({ 'guide/pricing.md': null }, { 'guide/pricing.md': '# Pricing\n\ncharge() caps spend at 25 USD per run.\n' });
|
||||
useRepo(repo);
|
||||
const ran = patchAt(repo, passHead);
|
||||
expect(rule(repo, 'guide/pricing.md', head).status).toBe(0);
|
||||
const p = plan(repo, ['--range-base', passHead, '--targeted-ran', ran]);
|
||||
expect(next(p.stdout)).toStartWith('NEXT: targeted (');
|
||||
expect(dispatches(p.stdout)).toEqual(['DISPATCH: targeted targeted effort=full classes=money']);
|
||||
expect(bind(repo, passHead, head)).toMatchObject({ ok: false, message: expect.stringContaining('the product changed after the read') });
|
||||
expect(docsChangeSince(repo.work, passHead, head, 'main')?.verdict).toBe('claim');
|
||||
expect(ruledChangeSince(repo.work, passHead, head, 'main')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
// Value: protects=the targeted-only read (one targeted reader on HEAD after a ruled edit, not a review round) counts as bound;
|
||||
// fails_when=review-scope prints REVIEW_SCOPE_UNBOUND: pass 3 (ledger p3) for it (GSTA-876 on #4853), or a real pass 3 with
|
||||
// no review row stops being named; seam=lib/review-scope.ts ledgerPass and summarizeReviewLoop
|
||||
|
||||
Reference in new issue
Block a user