diff --git a/bin/gstack-review-read b/bin/gstack-review-read index a030203cb..1c6dcb698 100755 --- a/bin/gstack-review-read +++ b/bin/gstack-review-read @@ -9,7 +9,9 @@ # rows using review_freshness; legacy or uncaptured diff evidence cannot fall # back to HEAD equality. Plan rows are unchanged. A gate finding the owner's gstack-approvals # gate row closes reads `kept` with its `disposition`, and the row's `gate_dispositions` lists -# those approval ids (lib/gate-dispositions.ts); values the row itself carried are discarded. +# those approval ids (lib/gate-dispositions.ts). review_freshness counts the owner's +# gstack-approvals rule rows at a head in the row's range (ruledOn), and the row's `ruled_notes` +# lists their approval ids; values the row itself carried are discarded. set -euo pipefail GSTACK_BUN_CONFIG=/dev/null; case "${OSTYPE:-}" in msys*|cygwin*) if command -v cygpath >/dev/null 2>&1; then GSTACK_BUN_CONFIG=NUL; fi ;; esac SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" @@ -23,21 +25,28 @@ gstack_state_root_select GSTACK_HOME="$_gstack_sr_root" WTREE=$("$SCRIPT_DIR/gstack-wtree" --review 2>/dev/null || echo "unknown") if [ -f "$GSTACK_HOME/projects/$SLUG/$BRANCH-reviews.jsonl" ]; then - GSTACK_REVIEW_LIB="$SCRIPT_DIR/../lib/review-evidence.ts" GSTACK_GATE_LIB="$SCRIPT_DIR/../lib/gate-dispositions.ts" GSTACK_REVIEW_WTREE="$WTREE" bun --no-env-file --config="${GSTACK_BUN_CONFIG:-/dev/null}" -e ' + GSTACK_REVIEW_LIB="$SCRIPT_DIR/../lib/review-evidence.ts" GSTACK_GATE_LIB="$SCRIPT_DIR/../lib/gate-dispositions.ts" GSTACK_RULED_LIB="$SCRIPT_DIR/../lib/ruled-notes.ts" GSTACK_REVIEW_WTREE="$WTREE" bun --no-env-file --config="${GSTACK_BUN_CONFIG:-/dev/null}" -e ' const { reviewFreshness } = await import(process.env.GSTACK_REVIEW_LIB); - const { dispositionedOn, gateKey, readGateDispositions, showDispositioned } = await import(process.env.GSTACK_GATE_LIB); + const { dispositionedOn, gateKey, readGateDispositions, ruledOn, showDispositioned } = await import(process.env.GSTACK_GATE_LIB); + const { readRuledNotes } = await import(process.env.GSTACK_RULED_LIB); let dispositions = []; try { dispositions = readGateDispositions(process.cwd()); } catch (e) { console.error("gstack-review-read: gate dispositions unreadable, none applied: " + e.message); } + let rulings = []; + try { rulings = readRuledNotes(process.cwd()); } + catch (e) { console.error("gstack-review-read: rulings unreadable, none applied: " + e.message); } for (const line of (await Bun.stdin.text()).split("\n").filter(Boolean)) { try { const rec = JSON.parse(line); delete rec.review_freshness; delete rec.gate_dispositions; + delete rec.ruled_notes; for (const f of Array.isArray(rec.findings) ? rec.findings : []) if (f && typeof f === "object") delete f.disposition; const closed = dispositionedOn(process.cwd(), rec, dispositions); - const freshness = reviewFreshness(rec, process.env.GSTACK_REVIEW_WTREE, new Set(), new Set(closed.map(d => gateKey(d.finding, d.gate_id)))); + const ruled = ruledOn(process.cwd(), rec, rulings); + const freshness = reviewFreshness(rec, process.env.GSTACK_REVIEW_WTREE, new Set(ruled.map(n => n.finding)), new Set(closed.map(d => gateKey(d.finding, d.gate_id)))); if (freshness) rec.review_freshness = freshness; + if (ruled.length) rec.ruled_notes = ruled.map(n => n.approval); showDispositioned(rec, closed); console.log(JSON.stringify(rec)); } catch { console.error("gstack-review-read: skipping malformed review row"); } diff --git a/changelog.d/ruled-notes-bind-step-11-5.md b/changelog.d/ruled-notes-bind-step-11-5.md new file mode 100644 index 000000000..9dfc8cf45 --- /dev/null +++ b/changelog.d/ruled-notes-bind-step-11-5.md @@ -0,0 +1 @@ +- **/ship can write a receipt after the owner accepts a stopped review's findings as open notes.** When the final review or the native reader stopped on findings and the owner recorded each one with `gstack-approvals rule` at that head, `gstack-review-read` now counts those rulings, so Step 11.5 binds both reviews at the tree they read instead of reading them unverified. A ruling for another branch, another head or another finding, or one gstack wrote for itself, still counts for nothing (harness-evals#498). diff --git a/docs/ship-policy.md b/docs/ship-policy.md index d439be466..d3dc96ac2 100644 --- a/docs/ship-policy.md +++ b/docs/ship-policy.md @@ -1800,6 +1800,14 @@ findings. Nothing ruled is hidden: Pre-Landing Review and the PR body, `gstack-ship-receipt write` records them as `ruled_notes` (each with its `head`) and refuses a `--body` that does not carry each line word for word, and the READY block prints each as `RULED_NOTE:`. +Step 11.5 reads the same rulings: `gstack-review-read` applies a ruling to a Step 9 +or Step 11 row that carries the finding and whose `range_base..commit` holds the +ruling's head (a first pass, with no `range_base`: its own commit), lists its +approval id in the row's `ruled_notes`, and grades the row with those findings +closed. So a final review or native reader that stopped on findings the owner then +ruled reads `CURRENT` at the one tree its `incomplete` binding names, while a ruling +on another branch, at another head, for another finding or by gstack itself +closes nothing (harness-evals#498). **Security findings stay private (GST-3076).** A PR body keeps every earlier diff --git a/lib/gate-dispositions.ts b/lib/gate-dispositions.ts index f423d1fe8..fab8b2770 100644 --- a/lib/gate-dispositions.ts +++ b/lib/gate-dispositions.ts @@ -19,7 +19,7 @@ import * as path from 'node:path'; import { appendRows, locate, readRecord, type ApprovalRow, type Env, type RecordError, type StoreLocation } from './approval-record'; import type { ShipReceipt } from './headless-artifacts'; import type { ResultCodeName } from './result-codes'; -import { isGstackActor } from './ruled-notes'; +import { isGstackActor, type RuledNote } from './ruled-notes'; import { isSecurityFinding, REDACTED_FINDING, REDACTED_REASON, REDACTED_WORDS } from './security-findings'; import { BIN_DIR, runScriptSync } from './script-invocation'; @@ -203,12 +203,29 @@ export function dispositionedOn(cwd: string, row: Record, dispositi .filter((f: any) => !!f && typeof f.gate === 'string' && f.gate && typeof f.fingerprint === 'string' && validGateId(f.gate_id) && (f.action === 'open' || (f.action === 'kept' && f.actor !== 'interactive'))) .map((f: any) => gateKey(f.fingerprint, f.gate_id))); const mine = dispositions.filter(d => open.has(gateKey(d.finding, d.gate_id))); - if (!mine.length) return []; + const holds = mine.length ? rowRange(cwd, row) : null; + return holds ? mine.filter(d => holds(d.head)) : []; +} + +/** + * The owner's rulings that apply to a review row, as gstack-review-read reads it for Step 11.5 (harness-evals#498, HARN-1): a + * ruling for a finding the row carries that is not a gate finding (a ruling never closes one), recorded at a head inside the + * row's range by the same test dispositions use. + */ +export function ruledOn(cwd: string, row: Record, notes: readonly RuledNote[]): RuledNote[] { + const fingerprints = new Set((Array.isArray(row?.findings) ? row.findings : []).flatMap((f: any) => f && !f.gate && typeof f.fingerprint === 'string' ? [f.fingerprint] : [])); + const mine = notes.filter(n => fingerprints.has(n.finding)); + const holds = mine.length ? rowRange(cwd, row) : null; + return holds ? mine.filter(n => holds(n.head)) : []; +} + +/** Whether an owner's answer at `head` lies inside a review row's `range_base..commit_full` (both ends), or is the row's own commit when it has no range_base; null when those commits do not resolve. */ +function rowRange(cwd: string, row: Record): ((head: string) => boolean) | null { const commitOf = (c: unknown) => typeof c === 'string' && /^[0-9a-f]{7,40}$/.test(c) ? spawnSync('git', ['rev-parse', '--verify', '--quiet', `${c}^{commit}`], { cwd, encoding: 'utf8', timeout: 10_000 }).stdout?.trim() ?? '' : ''; const ancestor = (a: string, d: string) => spawnSync('git', ['merge-base', '--is-ancestor', a, d], { cwd, timeout: 10_000 }).status === 0; const to = commitOf(row.commit_full), from = row.range_base == null ? '' : commitOf(row.range_base); - if (!to || (row.range_base != null && !from)) return []; - return mine.filter(d => from ? ancestor(from, d.head) && ancestor(d.head, to) : d.head === to); + if (!to || (row.range_base != null && !from)) return null; + return head => from ? ancestor(from, head) && ancestor(head, to) : head === to; } /** diff --git a/ship/SKILL.md b/ship/SKILL.md index 4fabb920a..884378d69 100644 --- a/ship/SKILL.md +++ b/ship/SKILL.md @@ -505,18 +505,18 @@ repeat Step 2 (decisions included) on the merged content, then Step 4. none after `ADVERSARIAL: skipped`). Match each to its saved handle, original token and source; reject outside-provider or older records. 2. **Compare their content.** All three snapshots must match: the native record's - `wtree` (its `review_binding.state` `verified`), the Step 9 record's - `review_binding.start_wtree` and `review_binding.end_wtree`; after a planned skip, the - last two with `review_freshness` `CURRENT`. A mismatch or a missing required - record/field blocks release preparation: report **Review records missing or mismatched** - and insert `9 → 10 → 11 → 11.5` before Step 12. Bind the new records at 11.5. - Never attach new tokens to old work. + `wtree` (`review_binding.state` `verified`; `end_wtree` if `ruled_notes` read + `CURRENT`), the Step 9 record's `review_binding.start_wtree` and + `review_binding.end_wtree`; after a planned skip, the last two with + `review_freshness` `CURRENT`. A mismatch or missing record/field blocks release: + report **Review records missing or mismatched** and insert `9 → 10 → 11 → 11.5` + before Step 12. Bind new records at 11.5. Never attach new tokens to old work. 3. **Preserve any QA exception.** A named probe-risk exception may leave Step 9.4's root `wtree` absent; item 2 still compares its start/end snapshots. Matching content does not mean failed or unrun probes passed. Keep Step 9.4's incomplete flags and the user's exception. 4. **Save the evidence.** Save both records and matching **reviewed tree** for - Step 16, with its merge base. Continue to Step 12. + Step 16, with its merge base. ## Step 12: Version bump (auto-decide) diff --git a/ship/SKILL.md.tmpl b/ship/SKILL.md.tmpl index bcd26eaa4..5d9ccf55a 100644 --- a/ship/SKILL.md.tmpl +++ b/ship/SKILL.md.tmpl @@ -221,18 +221,18 @@ repeat Step 2 (decisions included) on the merged content, then Step 4. none after `ADVERSARIAL: skipped`). Match each to its saved handle, original token and source; reject outside-provider or older records. 2. **Compare their content.** All three snapshots must match: the native record's - `wtree` (its `review_binding.state` `verified`), the Step 9 record's - `review_binding.start_wtree` and `review_binding.end_wtree`; after a planned skip, the - last two with `review_freshness` `CURRENT`. A mismatch or a missing required - record/field blocks release preparation: report **Review records missing or mismatched** - and insert `9 → 10 → 11 → 11.5` before Step 12. Bind the new records at 11.5. - Never attach new tokens to old work. + `wtree` (`review_binding.state` `verified`; `end_wtree` if `ruled_notes` read + `CURRENT`), the Step 9 record's `review_binding.start_wtree` and + `review_binding.end_wtree`; after a planned skip, the last two with + `review_freshness` `CURRENT`. A mismatch or missing record/field blocks release: + report **Review records missing or mismatched** and insert `9 → 10 → 11 → 11.5` + before Step 12. Bind new records at 11.5. Never attach new tokens to old work. 3. **Preserve any QA exception.** A named probe-risk exception may leave Step 9.4's root `wtree` absent; item 2 still compares its start/end snapshots. Matching content does not mean failed or unrun probes passed. Keep Step 9.4's incomplete flags and the user's exception. 4. **Save the evidence.** Save both records and matching **reviewed tree** for - Step 16, with its merge base. Continue to Step 12. + Step 16, with its merge base. ## Step 12: Version bump (auto-decide) diff --git a/test/fixtures/golden/agy-ship-SKILL.md b/test/fixtures/golden/agy-ship-SKILL.md index 6487b8172..5d8f1e631 100644 --- a/test/fixtures/golden/agy-ship-SKILL.md +++ b/test/fixtures/golden/agy-ship-SKILL.md @@ -500,18 +500,18 @@ repeat Step 2 (decisions included) on the merged content, then Step 4. none after `ADVERSARIAL: skipped`). Match each to its saved handle, original token and source; reject outside-provider or older records. 2. **Compare their content.** All three snapshots must match: the native record's - `wtree` (its `review_binding.state` `verified`), the Step 9 record's - `review_binding.start_wtree` and `review_binding.end_wtree`; after a planned skip, the - last two with `review_freshness` `CURRENT`. A mismatch or a missing required - record/field blocks release preparation: report **Review records missing or mismatched** - and insert `9 → 10 → 11 → 11.5` before Step 12. Bind the new records at 11.5. - Never attach new tokens to old work. + `wtree` (`review_binding.state` `verified`; `end_wtree` if `ruled_notes` read + `CURRENT`), the Step 9 record's `review_binding.start_wtree` and + `review_binding.end_wtree`; after a planned skip, the last two with + `review_freshness` `CURRENT`. A mismatch or missing record/field blocks release: + report **Review records missing or mismatched** and insert `9 → 10 → 11 → 11.5` + before Step 12. Bind new records at 11.5. Never attach new tokens to old work. 3. **Preserve any QA exception.** A named probe-risk exception may leave Step 9.4's root `wtree` absent; item 2 still compares its start/end snapshots. Matching content does not mean failed or unrun probes passed. Keep Step 9.4's incomplete flags and the user's exception. 4. **Save the evidence.** Save both records and matching **reviewed tree** for - Step 16, with its merge base. Continue to Step 12. + Step 16, with its merge base. ## Step 12: Version bump (auto-decide) diff --git a/test/fixtures/golden/claude-ship-SKILL.md b/test/fixtures/golden/claude-ship-SKILL.md index 4fabb920a..884378d69 100644 --- a/test/fixtures/golden/claude-ship-SKILL.md +++ b/test/fixtures/golden/claude-ship-SKILL.md @@ -505,18 +505,18 @@ repeat Step 2 (decisions included) on the merged content, then Step 4. none after `ADVERSARIAL: skipped`). Match each to its saved handle, original token and source; reject outside-provider or older records. 2. **Compare their content.** All three snapshots must match: the native record's - `wtree` (its `review_binding.state` `verified`), the Step 9 record's - `review_binding.start_wtree` and `review_binding.end_wtree`; after a planned skip, the - last two with `review_freshness` `CURRENT`. A mismatch or a missing required - record/field blocks release preparation: report **Review records missing or mismatched** - and insert `9 → 10 → 11 → 11.5` before Step 12. Bind the new records at 11.5. - Never attach new tokens to old work. + `wtree` (`review_binding.state` `verified`; `end_wtree` if `ruled_notes` read + `CURRENT`), the Step 9 record's `review_binding.start_wtree` and + `review_binding.end_wtree`; after a planned skip, the last two with + `review_freshness` `CURRENT`. A mismatch or missing record/field blocks release: + report **Review records missing or mismatched** and insert `9 → 10 → 11 → 11.5` + before Step 12. Bind new records at 11.5. Never attach new tokens to old work. 3. **Preserve any QA exception.** A named probe-risk exception may leave Step 9.4's root `wtree` absent; item 2 still compares its start/end snapshots. Matching content does not mean failed or unrun probes passed. Keep Step 9.4's incomplete flags and the user's exception. 4. **Save the evidence.** Save both records and matching **reviewed tree** for - Step 16, with its merge base. Continue to Step 12. + Step 16, with its merge base. ## Step 12: Version bump (auto-decide) diff --git a/test/fixtures/golden/codex-ship-SKILL.md b/test/fixtures/golden/codex-ship-SKILL.md index e2188acbe..d55bf6fc5 100644 --- a/test/fixtures/golden/codex-ship-SKILL.md +++ b/test/fixtures/golden/codex-ship-SKILL.md @@ -499,18 +499,18 @@ repeat Step 2 (decisions included) on the merged content, then Step 4. none after `ADVERSARIAL: skipped`). Match each to its saved handle, original token and source; reject outside-provider or older records. 2. **Compare their content.** All three snapshots must match: the native record's - `wtree` (its `review_binding.state` `verified`), the Step 9 record's - `review_binding.start_wtree` and `review_binding.end_wtree`; after a planned skip, the - last two with `review_freshness` `CURRENT`. A mismatch or a missing required - record/field blocks release preparation: report **Review records missing or mismatched** - and insert `9 → 10 → 11 → 11.5` before Step 12. Bind the new records at 11.5. - Never attach new tokens to old work. + `wtree` (`review_binding.state` `verified`; `end_wtree` if `ruled_notes` read + `CURRENT`), the Step 9 record's `review_binding.start_wtree` and + `review_binding.end_wtree`; after a planned skip, the last two with + `review_freshness` `CURRENT`. A mismatch or missing record/field blocks release: + report **Review records missing or mismatched** and insert `9 → 10 → 11 → 11.5` + before Step 12. Bind new records at 11.5. Never attach new tokens to old work. 3. **Preserve any QA exception.** A named probe-risk exception may leave Step 9.4's root `wtree` absent; item 2 still compares its start/end snapshots. Matching content does not mean failed or unrun probes passed. Keep Step 9.4's incomplete flags and the user's exception. 4. **Save the evidence.** Save both records and matching **reviewed tree** for - Step 16, with its merge base. Continue to Step 12. + Step 16, with its merge base. ## Step 12: Version bump (auto-decide) diff --git a/test/fixtures/golden/factory-ship-SKILL.md b/test/fixtures/golden/factory-ship-SKILL.md index 0e03a65f4..4ee829cec 100644 --- a/test/fixtures/golden/factory-ship-SKILL.md +++ b/test/fixtures/golden/factory-ship-SKILL.md @@ -501,18 +501,18 @@ repeat Step 2 (decisions included) on the merged content, then Step 4. none after `ADVERSARIAL: skipped`). Match each to its saved handle, original token and source; reject outside-provider or older records. 2. **Compare their content.** All three snapshots must match: the native record's - `wtree` (its `review_binding.state` `verified`), the Step 9 record's - `review_binding.start_wtree` and `review_binding.end_wtree`; after a planned skip, the - last two with `review_freshness` `CURRENT`. A mismatch or a missing required - record/field blocks release preparation: report **Review records missing or mismatched** - and insert `9 → 10 → 11 → 11.5` before Step 12. Bind the new records at 11.5. - Never attach new tokens to old work. + `wtree` (`review_binding.state` `verified`; `end_wtree` if `ruled_notes` read + `CURRENT`), the Step 9 record's `review_binding.start_wtree` and + `review_binding.end_wtree`; after a planned skip, the last two with + `review_freshness` `CURRENT`. A mismatch or missing record/field blocks release: + report **Review records missing or mismatched** and insert `9 → 10 → 11 → 11.5` + before Step 12. Bind new records at 11.5. Never attach new tokens to old work. 3. **Preserve any QA exception.** A named probe-risk exception may leave Step 9.4's root `wtree` absent; item 2 still compares its start/end snapshots. Matching content does not mean failed or unrun probes passed. Keep Step 9.4's incomplete flags and the user's exception. 4. **Save the evidence.** Save both records and matching **reviewed tree** for - Step 16, with its merge base. Continue to Step 12. + Step 16, with its merge base. ## Step 12: Version bump (auto-decide) diff --git a/test/ship-finish-ruled-notes.test.ts b/test/ship-finish-ruled-notes.test.ts index 93988a759..e3cf7fbba 100644 --- a/test/ship-finish-ruled-notes.test.ts +++ b/test/ship-finish-ruled-notes.test.ts @@ -523,3 +523,86 @@ describe('a ruling relayed into an open /ship run (GBRA-108, gbrain #9762)', () }); }); + +// harness-evals#498 (HARN-1, 2026-11-20, b48a1c11bc5a): round 2 of 2 stopped on 22 blocking findings across the final full +// review and the native reader, each logged open with converged:false, so both rows bind `incomplete` on the tree they read. +// The owner accepted every one as an open note with gstack-approvals rule at that head, yet gstack-review-read applied no +// ruling, so Step 11.5 read both rows UNVERIFIED and no supported command could clear them. +const HE498_REVIEW = { + pass: 1, range_base: null, completed: true, converged: false, status: 'issues_found', issues_found: 3, critical: 1, informational: 1, + findings: [ + { fingerprint: RACE, severity: 'CRITICAL', action: 'open', locus: 'diff', blocking: true, raised_by: 'red-team' }, + { fingerprint: AMBIENT, severity: 'HIGH', action: 'open', locus: 'diff', blocking: true, raised_by: 'specialist' }, + { fingerprint: 'src/x.ts:1:naming', severity: 'INFORMATIONAL', action: 'noted', locus: 'diff', blocking: false, raised_by: 'targeted' }, + ], +}; +const PARTIAL = 'src/x.ts:1:partial-interim-input'; +const HE498_NATIVE = { + completed: true, converged: false, status: 'issues_found', issues_found: 1, critical: 0, informational: 0, + findings: [{ fingerprint: PARTIAL, severity: 'HIGH', action: 'open', locus: 'diff', blocking: true, raised_by: 'native' }], +}; +const logRow = (f: ShipFx, skill: string, row: Record) => { + const start = run(f, 'gstack-review-log', ['--start', skill]); + expect(start.status, start.stderr).toBe(0); + const logged = run(f, 'gstack-review-log', [JSON.stringify({ skill, timestamp: '2026-11-20T05:58:00Z', via: 'ship', review_scope: 'frozen', ...row }), '--finish', start.stdout.trim()]); + expect(logged.status, logged.stderr).toBe(0); +}; +/** The newest row of a skill as gstack-review-read prints it. */ +const readRow = (f: ShipFx, skill: string) => run(f, 'gstack-review-read', []).stdout.split('\n---CONFIG---')[0]!.split('\n') + .flatMap(l => { try { const v = JSON.parse(l); return v?.skill === skill ? [v] : []; } catch { return []; } }).at(-1); +function stoppedRound2() { + const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n' }, { 'src/x.ts': 'export const x = 2;\n' }); + ships.push(f); + logRow(f, 'review', HE498_REVIEW); + logRow(f, 'adversarial-review', HE498_NATIVE); + return { f, head: f.git('rev-parse', 'HEAD').stdout.trim(), tree: f.git('rev-parse', 'HEAD^{tree}').stdout.trim() }; +} +const BLOCKING = [RACE, AMBIENT, PARTIAL]; +const bound = (f: ShipFx) => ['review', 'adversarial-review'].map(s => readRow(f, s)).map(r => [r.review_freshness.status, r.review_binding.state]); + +// Value: protects=harness-evals#498: Step 11.5 binds the stopped final review and native reader once the owner's rulings at +// that head cover every blocking finding on them, and only then; fails_when=gstack-review-read reads either row UNVERIFIED +// after every ruling, or CURRENT with a finding unruled, or applies a ruling for another branch, head or finding, or one +// the approvals reader rejects; seam=gstack-approvals rule and gstack-review-read on the stored rows; no_claim=finish's +// fix-check chain (the cases above) and the receipt write +describe('Step 11.5 binds a stopped review the owner ruled at its head (harness-evals#498, HARN-1)', () => { + test('#498: both rows read UNVERIFIED on an incomplete binding, then CURRENT on the tree they read once every blocking finding is ruled', () => { + const { f, head, tree } = stoppedRound2(); + expect(bound(f)).toEqual([['UNVERIFIED', 'incomplete'], ['UNVERIFIED', 'incomplete']]); + const approvals = BLOCKING.map(x => { const r = rule(f, x, head, 'harness minder (HARN-1)'); expect(r.status, r.stderr).toBe(0); return JSON.parse(r.stdout).added[0] as string; }); + expect(bound(f)).toEqual([['CURRENT', 'incomplete'], ['CURRENT', 'incomplete']]); + const [review, native] = [readRow(f, 'review'), readRow(f, 'adversarial-review')]; + expect([review.ruled_notes, native.ruled_notes]).toEqual([approvals.slice(0, 2), approvals.slice(2)]); + expect([review.review_binding.start_wtree, review.review_binding.end_wtree, native.review_binding.end_wtree, review.tree, native.tree]) + .toEqual([review.review_binding.end_wtree, native.review_binding.start_wtree, native.review_binding.start_wtree, tree, tree]); + expect(review.findings.map((x: any) => x.action)).toEqual(['open', 'open', 'noted']); + }); + + test('one blocking finding left unruled keeps its row UNVERIFIED and binds the other', () => { + const { f, head } = stoppedRound2(); + for (const x of [RACE, PARTIAL]) expect(rule(f, x, head, 'harness minder (HARN-1)').status).toBe(0); + expect(bound(f)).toEqual([['UNVERIFIED', 'incomplete'], ['CURRENT', 'incomplete']]); + expect(readRow(f, 'review').ruled_notes).toEqual([expect.stringMatching(/^a-[0-9a-f]{12}$/)]); + }); + + test('a ruling for another branch, another head or another finding, or one the approvals reader rejects, binds nothing', () => { + const { f, head } = stoppedRound2(); + const none = () => { expect(bound(f)).toEqual([['UNVERIFIED', 'incomplete'], ['UNVERIFIED', 'incomplete']]); expect(readRow(f, 'review').ruled_notes).toBeUndefined(); }; + expect(f.git('branch', 'other-pr', 'HEAD').status).toBe(0); + for (const x of BLOCKING) expect(run(f, 'gstack-approvals', ['rule', '--branch', 'other-pr', '--finding', x, '--head', head, '--reason', 'ships as a note', '--words', 'accept as open notes', '--by', 'harness minder (HARN-1)']).status).toBe(0); + none(); + const mergeBase = f.git('merge-base', 'main', 'HEAD').stdout.trim(); + for (const x of BLOCKING) expect(rule(f, x, mergeBase, 'harness minder (HARN-1)').status).toBe(0); + none(); + for (const x of BLOCKING) expect(rule(f, x.replace(':1:', ':2:'), head, 'harness minder (HARN-1)').status).toBe(0); + none(); + const store = path.join(f.state, 'projects'); + const files = fs.readdirSync(store, { recursive: true }).map(String).filter(p => p.endsWith('.jsonl') && p.includes('approvals') && !p.includes('other-pr')); + expect(files.length).toBe(1); + const file = path.join(store, files[0]!); + const gstackRows = BLOCKING.map(x => buildRow({ ask: `ruled_note ${x} at ${head}: ships as a note`, scope: `ruled_note ${x} ${head}`, words: 'accept as open notes', by: 'gstack no-stop default (K1)' }, 'feat')); + for (const r of gstackRows) { if ('code' in r) throw new Error(r.message); fs.appendFileSync(file, JSON.stringify(r) + '\n'); } + none(); + expect(run(f, 'gstack-approvals', ['rulings']).stdout).not.toContain('ruled by gstack'); + }); +}); diff --git a/test/size-ledger/ship/fix-ruled-notes-bind-step-11-5.json b/test/size-ledger/ship/fix-ruled-notes-bind-step-11-5.json new file mode 100644 index 000000000..81a13d05e --- /dev/null +++ b/test/size-ledger/ship/fix-ruled-notes-bind-step-11-5.json @@ -0,0 +1,4 @@ +{ + "bytes": -7, + "why": "Step 11.5 reads a native record the owner's rulings clear at its review_binding.end_wtree (harness-evals#498), tightened to stay under the skeleton cap" +}