mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-25 17:41:35 +01:00
* fix(ship): base merges, adjacent base edits, test-only and audit-requested fixes no longer force a second review loop (GST-407, GST-384, GST-391) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * ship driver: trim two phrases for headroom with #3662 Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * ship driver: keep the Next steps heading phrase the handoff check reads; trim elsewhere Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test: regenerate ship goldens Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: pre-landing review fixes comparePath returns same only when every hunk sits where the base change puts it (patch-ids ignore positions) and treats a file-mode change as changed; the scoped-review packet says when a fence is truncated; --docs-result must be the posted audit's result; the --context-reviewed record goes beside the packet, outside the worktree. Negative controls for each. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: pass-2 review fixes A test edit routes as tests= only when it adds lines with no gate tag; a removed or changed line or an unreadable test diff goes through the full loop. Diffs skip textconv. A hunkless patch (binary, empty, mode-only) is same when its patch-id matches. Without --reviewed-base test files route as before. finish's packet path and attempt's state directory have fallbacks. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: Step 11 review fixes; a version-only stamp_files edit after review is release metadata (GBRA-251) gateEditedPaths reads removed lines only inside hunks; carry refuses when a path listing fails; docs freshness stops on a failed listing; attempt counts an unreadable state file. releasePaths includes stamp_files paths whose edit is a version swap under stamp_patterns. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: no test edit skips review; guard packet writes; exclusive attempt state A test-only edit with no gate tag gets the scoped fix-check of its test hunks instead of a lanes-only rerun. Packet write failures print a STOP or RECEIPT_CARRY_REFUSED. attempt's allowance uses an exclusive create. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: attempt prints gstack's install command; carry checks the product diff outside context paths The attempt STOP no longer echoes the audit child's fix text. A scoped-review carry now requires the product patch-id without the context paths to match at both heads. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: oversized packets take the full loop; exact --docs-requested match; name-only test globs only in test dirs A scoped-review packet section over 200 lines sends that path to the full loop instead of a truncated packet. The docs-result path match is exact. test_*.py, *Test.java and similar count as test code only under a test directory. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs(unattended): carry's scoped-review refusal and what it keeps Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs: carry's scoped-review route in ship-policy, review-policy and troubleshooting (docs-a-1) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test(windows): curate ship-rereview-triggers out of the Windows lane like ship-release (run 41193336209) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(review-log): record a notes-only /ship pass clean; name the cause and repair when a pass's tree moved (GST-430) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(receipt): carry and write handle PRs with thousands of files; tree receipt fails closed on a failed diff (GST-448) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(ship): preflight routes RECEIPT_CARRY_SCOPED_REVIEW to the scoped review; carry --dry-run writes no packet (GST-442) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs(ship): Step 1.4 and Step 16 route the scoped-review refusal and the --docs-requested fix; trims keep the cap (GST-442, GST-444) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: /ship review pass 1: notes-only floor, scoped carry order, named temp and diff refusals - A notes-only pass is recorded clean only when every finding is fixed, or noted or deferred below the blocking floor (never CRITICAL or blocking), by its logger-stamped action, and the findings account for the claimed issue and critical counts (GST-430). - The preflight scoped carry route commits and pushes the base-merge fix before writing the packet (GST-442). - patchId refuses by name on an unwritable TMPDIR; the tree receipt names why its diff failed (GST-448). - Step 16 stage 3 spells out --docs-requested with its --docs-result (GST-444). Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test: pin the Step 16 --docs-requested route with its --docs-result Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: a claimed clean review row with a logger-stamped open gate finding reads UNVERIFIED (red-team, pass 1) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: Step 11 findings: gate rows from --findings are stamped, one open rule, stale patch-id dirs swept - deriveFromFindings stamps gate rows with the session kind before deriving status, so a findings file cannot dispose of a gate finding the unattended logger forces open (outside-voice#1). - reviewFreshness reads a claimed row's findings with isOpenByAction, the rule the notes-only rewrite uses; noted and deferred clear a finding only when it is marked blocking: false and is not CRITICAL. - patchId sweeps gstack-patch-id-* directories over an hour old that a killed carry left in TMPDIR. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: Step 11 round 2: stamped-open gates win over status and disposition; resolved gate, skipped and below-floor actions stay CURRENT - isOpenFinding treats action 'open' (the logger's forced-open stamp) as open before a row's status or disposition. - reviewFreshness flags a claimed clean row only for an 'open' action or a CRITICAL or blocking deferral or note, so interactive kept and restored gates, skipped advisories and INFORMATIONAL deferrals read CURRENT as before. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: carry dry run offers the scoped route last; patch-id diff under the git dir; changelog matches the review-log floor Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: a claimed clean review row with any unresolved non-gate CRITICAL finding reads UNVERIFIED (pass 2 red-team) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs: carry dry-run scoped route, patch-id directory, tree-receipt refusal (docs-d-1 audit) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(ship): Step 3 names merge conflicts in its STOP sentence again (ship-workflow-clarity pin) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(tree-receipt): keep the gated-to-current diff at the file helper timeout (60 s); pregate literals check Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test(carry): large-diff fixture sets core.longpaths so Git for Windows can add its long receipt paths (windows-free-shard 1, run 41210080055) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(review): a stale local base branch yields to its origin twin in gate-diff and diff-scope (GST-462) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(ship): Step 11 saves the targeted record and the receipt writes carry it; Step 9 clears it (GST-464) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * changelog: GST-464 and GST-462 Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(review): pass 1: ahead and diverged labels, diff-scope needs shared history; preflight refreshes origin/<base> and stops on a diff far beyond the PR (GST-462, HARN-15) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: pass-2 review fixes for base twin, prSized stop and targeted record Resolve the tracking twin by refs/remotes/<remote>/<ref> and only for a bare branch name, keep a local base that is ahead or diverged, quote the prSized stop's base and name the fork case, and have every Step 9 entry create, exclude and clear .gstack/tmp/targeted.json. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: origin's tracking base wins whenever related; prSized lower bound The fix-check found that keeping a local base ahead of origin left unpushed base commits out of the gate scan while review-plan listed them. The tracking branch now wins whenever it shares history with HEAD, an explicit origin/main reads refs/remotes/origin/main, the preflight also stops when the diff lists fewer files than the PR, and the Step 9 exclude line survives a missing .git/info and an exclude file without a final newline. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * changelog: the tracking-ref claim holds while the tracking branch exists Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test: repin the two ship section briefs under no-loss replay GST-464 GST-464 brief-identity check: every reviewer brief lib/review-brief.ts cuts from ship/sections/review-army.md and adversarial.md stays byte-identical to the bodies the L and GST-257 replays admitted; only lead instructions outside the cut spans changed. The check is a test CI runs. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * ship: keep Step 9's PASS_HEAD sentence whole; repin review-army under GST-464 The targeted-record line follows the PASS_HEAD/RANGE_BASE sentence instead of splitting it (test/review-fix-range.test.ts pins that sentence). The brief-body check still holds: every reviewer brief is byte-identical. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: restore bin/gstack-ship-receipt after the main merge The merge commitb10e2dbwrote a truncated copy of the file. This is the three-way merge of both sides with the refused() union: main's codes plus RECEIPT_CARRY_SCOPED_REVIEW. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * review-collect: narrow the consumer scan and give it one 300 s deadline (GST-544) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * review-collect: keep the consumer scan deadline under the 180 s plan timeout (review fix) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * review-collect: plain paths under --literal-pathspecs; whole-millisecond timeout override (review fix) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * review-collect: whole-tree grep for non-UTF-8 names, no argument spread, name spawn errors (review fix) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * review-collect: cap the consumer grep output at 256 MB across calls; per-scan deadline wording (review fix, cycle 4) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * review-collect: read a missing spawn status as null (Bun 1.4.2 returns undefined on ENOENT) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test: review-collect whole-tree helper reads a null status as -1 (typecheck:test ratchet) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * review-bots: /review and /ship triage every configured review bot, not only Greptile (#3122) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: pre-landing review fixes (gh before 2.48 pages without --slurp; driver routes Step 10; tests for guards, review-bot fence, REMOTE_SLUG owner) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: drop the review-bot fence test that could not fail (the tool-fence WARN degrade is unreachable: placeholder spans are skipped first) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: Step 11 review fixes (record by comment id so a filename never reaches a shell; lookup failures are errors; tojson pages; longest bot prefix wins) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: pass-2 review fixes (record refuses * paths, colliding ids and a missing fetch dir; parent requires id and dir; botOwning doc) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * review: classify the PR type and always check repo conventions (#356) The checklist now opens with a PR-type line (application, CI/infra, scripts/tooling, docs-only or mixed). Application and mixed diffs run every category; other types always run five categories, including the new Repo Conventions & Platform Fit, and report the rest as not applicable in one line instead of skipping silently. No-loss replay: GSTA-224 H1 preregistered no-loss run (run id gsta224-h1-20261031, Opus 5.5, 81 calls, $9.53) against main's checklist with a no-gstack arm; every preregistered bar passed. The review/checklist.md pin in test/review-packets-removed.test.ts moves to a32963ef with replay 'GSTA-224 H1'. Refs GSTA-224 Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * review-bots: allowlist the record placeholders and match Step 10's id rule in tests The record fence uses <comment-id>, <fix|fp|already-fixed> and <category>, each with an enum or numeric grammar; <greptile-dir> becomes <bot-dir>. review/greptile-triage.md also lists every REVIEW_BOTS skip reason. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs: review-bot triage covers every configured bot (#3122) README, CONTRIBUTING, the contributor reference and standalone-binaries name gstack-review-bots and the review-bot fence; TODOS drops the #3122 item; the changelog fragment covers record-by-id and lookup errors. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test: the PR-type test also pins the compose, Terraform and README/CHANGELOG phrases Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test: follow the review-bot rename in the remote free tier's three reds The cross-skill consistency judge describes review-bot-history.md and its record helper; the tracker-guard exemption for the removed raw Greptile fetch in review/greptile-triage.md is dropped (the fetch now lives in gstack-review-bots, whose bodies still reach context only through gstack-issue-guard); the Step 10 PR-check test expects 'Review bots: not run'. HARNESS_VERSION stays 6: skill-fixture.ts and llm-judge.ts are recorded non-behavioral for every other case. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test: keep the cross-skill judge's rubric to one renamed bullet Name review-bot-history.md beside the older greptile-history.md so the calibration corpus still matches, and keep the REMOTE_SLUG bullet. One live 3-sample panel at this tree: consistent 3/3, scores 4/4/4. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * changelog: H1 fragment passes prose lint Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * changelog: name the H1 fragment after its branch; TODOS drops #356 Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs: /review's PR type step in docs/skills.md (#356) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * ship-policy: review_exclude_paths key and loadPolicyAt (GST-508) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * review: apply the base policy's review_exclude_paths and the reviewer diff ceiling (GST-508) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * receipt: bind review_exclude in write, carry and the queue (GST-508) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs, tests and changelog for review_exclude_paths (GST-508) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: pre-landing review fixes (binary by bytes, links kept, untracked files out of the selection) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: keep binary files at code paths under review_exclude_paths Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs: name the reasons that keep a binary file under review_exclude_paths Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: keep every review_exclude_paths candidate when the gate scan is unknown; docs example names its version Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test: keep the NUL fixture clear of the sync-spawn tripwire Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * changelog: split the ceiling sentence Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: keep a live binary file whose bytes cannot be read; tests render outside voices from a clean checkout and read the ship fixture text Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test(review-exclude): explicit +x for the census script; skip the chmod-000 read case on Windows and root Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * refactor: move loadPolicyAt to lib/ship-policy-at.ts so lib/ship-policy.ts stays under the 800-line module cap Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: refuse a base that contains HEAD; skip a self-pointing origin/HEAD (GST-774) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * chore: regenerate gstack-doctor-components.sh for BASE_CONTAINS_HEAD Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: land resumes a merged merge-only PR instead of refusing BASE_CONTAINS_HEAD (GST-774 review) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs: changelog fragment for GST-774 Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs: troubleshooting names diff-scope base_contains_head and the self-pointing no_base case (GST-774 docs audit) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test: repin the reviewer briefs to GST-508's no-loss-tested bytes ship/sections/review-army.md, ship/sections/adversarial.md and lib/review-depth.ts now pin the bytes the GST-508 preregistered no-loss replay ran atef2760f(handoffs/GSTA-202/noloss-results.md in the GStack Minder drive): Arm V 33/41 vs R 33/41, delta 4, exact sign flip, p_NI 0.0279 (pass). The merge of main83ae96eleaves these three files byte-identical toef2760f, and an Arm P unit (3593) renders byte-identical briefs atef2760fand at the merge. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: GST-774 review round 1 — merged resume depth, aliased and detached PR checkouts, develop/trunk defaults Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * ship: Step 20 says a metrics row, keeping DRIVER.md at 12 KB after the main merge Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test: ship-parts resend case leaves room for the first phase-3 part after the Step 9 targeted-record sentence Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: /ship delivers review/checklist.md in two parts so checklist v1 fits the 24576-byte part cap (#3670) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * changelog: drop the GST-407 and GST-430 fragments, already released on main (stacked history) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * wave review-53cfb5bfe011: lib/ship-policy.ts back to 800 lines (module-size ratchet after merging #3744 and #3795) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * wave review-53cfb5bfe011: /ship pass 1 fixes - lib/ship-receipt-depth.ts: a merged resume (land after a true merge) no longer recomputes the review_exclude digest over the emptied range, so it lands instead of RECEIPT_INVALID (failing-first land test with review_exclude_paths active). - bin/gstack-review-dispatch render: a standalone targeted render under an active review_exclude_paths refuses and points at the pass manifest voices stage, instead of writing a brief with no selection that leaves verify dirty (failing-first test). - test/default-base.test.ts: #3795 expectations follow main R51 depth (light for an 80-line code diff; runtime_lines=80 still proves the real base). - test/review-dispatch.test.ts: the GST-897 fingerprint test renders from the clean checkout, like its neighbor, because CI rebuilds the tracked lib/diagram-render/dist/diagram-render.html and the reviewer diff ceiling refused the ROOT render. * wave review-53cfb5bfe011: /ship pass 2 fixes - lib/review-exclude.ts: binaryContent reads each blob's first 8,000 bytes (git cat-file blob, 8 KB buffer) instead of one --batch read capped at 256 MB, so head mode (receipt, carry, queue) and the plan agree past 256 MB of blobs; an unreadable blob is kept, as in live mode. Failing-first test with two 270 MB blobs. - lib/review-bots.ts: a file-level bot review comment (subject_type file, no line position) is triaged instead of read as outdated. Failing-first test. - test/ship-queue-land.test.ts: the merged-resume exclusion test runs its gate scan under the fixture state root, not the real home (CI free-suite 6 home containment). * fix: merge follow-ups for main3d99c22: origin/* stays qualified in diff-scope's twin step, retro skeleton back under its cap, combined no-loss pin GST-508+R51+GST-911 * fix(review): receipt write gate-scans whenever the base declares review_exclude_paths; collectLive never re-qualifies origin/<base> (#3852 /ship red-team#1, outside-voice#1) * test: the docs-only receipt digest test keeps its gate scan out of the real home (free-suite shard 5 FREE_SUBSHARD_REJECTED) * fix(mergefc292e22f): tentative REVIEW_EXCLUDE_KEY_VERSION, classify targeted.json, render main's new outside-voice test from a clean checkout - lib/ship-policy.ts: REVIEW_EXCLUDE_KEY_VERSION 1.93.0.0 -> 1.94.0.0, the next-minor tentative form stamp_paths moves (docs/ship-policy.md, #3512); 1.93.0.0 is a released heading that never names the key. - test/gstack-clean-producers.test.ts (new from main): KEPT gains targeted.json, the wave's --review-targeted input. - test/review-dispatch.test.ts: main's wrong-tree test rendered the outside voice from ROOT; a CI build that dirties ROOT pushes that diff past the wave's REVIEW_DIFF_MAX_BYTES ceiling, so render refused and verify saw no brief (exit 3). It now runs in cleanCheckout like the wave's other outside-voice tests. * test(merge68410828f): GST-967's brief-body pin carries the wave's GST-508 placeholders The merged sectionTexts differ from main's by exactly the wave's GST-508 exclude-pathspec lines (merged minus main equals wave minusfc292e22f); the 1,440-case plan grid still hashes to main's MAIN_PLANS. Checks: GStack Minder drive handoffs/GSTA-202/merge-6841-checks.md. * fix(mergee85005482): targeted classes since the read accept an empty range; the wave's receipt tests pass main's targeted record - lib/ship-receipt-depth.ts targetedClassesSince (main, GST-986) reads the range from the commit the targeted reader read to HEAD through headInputs, which since #3795 runs gstack-diff-scope's BASE_CONTAINS_HEAD check. When the reader read HEAD itself the range is empty, diff-scope reported base_contains_head, and every write with --review-targeted was refused (the product patch matched). It now passes merged=true (--merged), which skips only that check; an ancestor check already guards the range. - test/review-exclude.test.ts and test/review-targeted.test.ts: since #3887 write refuses a money head with no targeted record and requires the record's head, so the wave's two writes that must succeed pass one, as main's own tests do (targetedAtHead in test/ship-receipt-depth.test.ts). * test(mergee85005482): drop the wave's duplicate targeted.json KEPT entry Main (#3887) classified .gstack/tmp/targeted.json in KEPT too; the auto-merge kept both keys, which typecheck:test rejects (TS1117). Main's entry stays. * test(mergee85005482): ship size ledger entry for the merged tree (-232 B) Main's ship size ledger plus the wave's entries summed to 345,334 B; the merged tree measures 345,102 B because DRIVER.md takes main's shorter Step 19 line. Recorded with scripts/size-ledger.ts record ship. --------- Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
702 lines
47 KiB
TypeScript
702 lines
47 KiB
TypeScript
import { expect, test } from 'bun:test';
|
||
import { spawnSync } from 'node:child_process';
|
||
import { mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
|
||
import { tmpdir } from 'node:os';
|
||
import { join } from 'node:path';
|
||
import { generateReviewArmy } from '../scripts/resolvers/review-army';
|
||
import { generateCrossReviewDedup, generateSharedCodeReuse, generateScopeDrift } from '../scripts/resolvers/review-scope';
|
||
import { generatePlanCompletionAuditReview, generatePlanCompletionAuditShip, generatePlanCompletionGateShip, PLAN_AUDIT_NOT_RUN } from '../scripts/resolvers/plan-gates';
|
||
import { generateQAReview } from '../scripts/resolvers/qa';
|
||
import { generateConfidenceCalibration } from '../scripts/resolvers/confidence';
|
||
import { HOST_PATHS, type TemplateContext } from '../scripts/resolvers/types';
|
||
import { between, compact, expectAbsent, expectMentions, expectOrdered, expectTokens } from './helpers/prompt-structure';
|
||
|
||
const root = join(import.meta.dir, '..');
|
||
const skill = readFileSync(join(root, 'review/SKILL.md.tmpl'), 'utf8');
|
||
const adversarial = readFileSync(join(root, 'review/sections/adversarial.md.tmpl'), 'utf8');
|
||
|
||
test('review audits deliverables before deferring behavioral plan checks to the QA preflight', () => {
|
||
const ctx: TemplateContext = { skillName: 'review', tmplPath: '', host: 'claude', paths: HOST_PATHS.claude };
|
||
const audit = generatePlanCompletionAuditReview(ctx).replace(/\s+/g, ' ');
|
||
for (const rule of [
|
||
/separate static audit evidence from behavioral checks/i,
|
||
/never DONE from a diff/,
|
||
/zero audited deliverables do not waive these checks/i,
|
||
/for each audited deliverable/i,
|
||
/leave the item UNVERIFIABLE and defer the command to Step 4\.7/,
|
||
/do not start applications, exercise APIs or mutate state during this audit/i,
|
||
]) expect(audit).toMatch(rule);
|
||
const inspect = audit.search(/inspect the validator and its hooks before running it/i);
|
||
expect(inspect).toBeGreaterThan(-1);
|
||
expect(inspect).toBeLessThan(audit.search(/if found and verified safe above, invoke it/i));
|
||
});
|
||
|
||
test('review prior-Skip matching includes adversarial and Greptile findings without relaxing eligibility', () => {
|
||
const dedup = generateCrossReviewDedup({ skillName: 'review', tmplPath: '', host: 'claude', paths: HOST_PATHS.claude });
|
||
expectMentions(dedup, [['only', 'conditions', 'unchanged']], 'dedup');
|
||
expectMentions(dedup, [['never', 'advisory', 'suppress']], 'dedup');
|
||
expect(dedup).toMatch(/only suppress `skipped` findings — never `fixed` or `auto-fixed`/i);
|
||
expect(skill).toContain('Step 5.0 severity/prior-skip dedup');
|
||
});
|
||
|
||
test('Review audit and prior-Skip clarifications do not route Ship through Review steps', () => {
|
||
for (const host of Object.keys(HOST_PATHS) as TemplateContext['host'][]) {
|
||
const ctx: TemplateContext = { skillName: 'ship', tmplPath: '', host, paths: HOST_PATHS[host] };
|
||
const audit = generatePlanCompletionAuditShip(ctx);
|
||
expect(audit).toContain('Step 8.1/9');
|
||
expect(audit).not.toContain('Step 4.7');
|
||
const dedup = generateCrossReviewDedup(ctx);
|
||
expect(dedup).toContain('Step 9.3: Cross-review finding dedup');
|
||
expect(dedup).not.toContain('Step 5.0');
|
||
expect(dedup).not.toContain('For every combined finding');
|
||
}
|
||
});
|
||
|
||
test('review collects every source before its single parent fix phase', () => {
|
||
const markers = [
|
||
'## Step 4: Critical pass', '### TODOS cross-reference',
|
||
'### Documentation staleness check', '{{SECTION:review-army}}',
|
||
'{{QA_REVIEW}}', '{{SECTION:adversarial}}',
|
||
'## Step 5: Fix-First Review', '{{CROSS_REVIEW_DEDUP}}',
|
||
'### Step 5a:', '### Step 5b:', '### Step 5c:', '### Step 5d:',
|
||
'## Step 5.8: Persist Eng Review result',
|
||
];
|
||
const positions = markers.map(marker => skill.indexOf(marker));
|
||
expect(positions.every(position => position >= 0)).toBe(true);
|
||
expect(positions).toEqual([...positions].sort((a, b) => a - b));
|
||
expect(skill.match(/## Step 5: Fix-First Review/g)).toHaveLength(1);
|
||
expectMentions(skill.replace(/\s+/g, ' '), [['do not', 'reviewed', 'source']], 'skill.replace(/\s+/g, )');
|
||
});
|
||
|
||
test('review settles adversarial attempts before fixing and has one full-pass back edge', () => {
|
||
const generated = readFileSync(join(root, 'review/sections/adversarial.md'), 'utf8');
|
||
const decision = skill.slice(skill.indexOf('## Step 5.8: Persist Eng Review result')).replace(/\s+/g, ' ');
|
||
expect(generated).toContain('## Step 4.8: Adversarial review');
|
||
expectMentions(generated, [['do not', 'during', 'edit']], 'generated');
|
||
expect(decision).toMatch(/a pass covers Steps 3–5/i);
|
||
expect(decision).toContain('Below 3, repeat Steps 3–5 with a new REVIEW_START');
|
||
expect(decision).not.toContain('Route Step');
|
||
expect(decision).not.toContain('Steps 5.0–5d');
|
||
expectMentions(decision, [['without', 'summary', 'fourth']], 'decision');
|
||
});
|
||
|
||
test('review small-diff and failed-reader paths retain QA and the required adversarial pass', () => {
|
||
const army = generateReviewArmy({ skillName: 'review', tmplPath: 'review/SKILL.md.tmpl',
|
||
host: 'claude', paths: HOST_PATHS.claude });
|
||
expect(army).not.toContain('design-lite');
|
||
expectMentions(army.replace(/\s+/g, ' '), [['never', 'dispatched', 'incomplete']], 'review army');
|
||
expect(army).not.toContain('skip silently');
|
||
});
|
||
|
||
test('review defines QA confidence, severity, impact selection and numeric version comparison', () => {
|
||
const flat = skill.replace(/\s+/g, ' ');
|
||
expect(flat).toContain('confidence (1–10)');
|
||
expect(flat).toMatch(/retain Step 4\.7's severity/i);
|
||
});
|
||
|
||
test('review emits scope check after the plan audit and before the checklist', () => {
|
||
const markers = [
|
||
'{{SCOPE_DRIFT}}', '{{SECTION:plan-completion}}',
|
||
'## Step 2: Read the checklist',
|
||
];
|
||
const positions = markers.map(marker => skill.indexOf(marker));
|
||
expect(positions.every(position => position >= 0)).toBe(true);
|
||
expect(positions).toEqual([...positions].sort((a, b) => a - b));
|
||
const audit = readFileSync(join(root, 'review/sections/plan-completion.md'), 'utf8').replace(/\s+/g, ' ');
|
||
expect(skill).not.toContain('Finish Step 1.5 here');
|
||
});
|
||
|
||
test('review composes confidence-tagged findings into one final report with explicit incomplete coverage', () => {
|
||
const flat = skill.replace(/\s+/g, ' ');
|
||
expect(flat).toContain('CRITICAL/INFORMATIONAL');
|
||
const report = flat.slice(flat.indexOf('### Report the final review'), flat.indexOf('{{LEARNINGS_LOG}}'));
|
||
expect(report).toMatch(/one final report/i);
|
||
expect(report).toMatch(/unresolved non-advisory defects/i);
|
||
expect(report).toMatch(/[Ss]tate INCOMPLETE if `COMPLETED` is false/);
|
||
expect(report).toContain('`## Exploratory QA and Verification Results`');
|
||
});
|
||
|
||
test('small-diff persistence uses an empty specialist map without manufacturing skipped coverage', () => {
|
||
const army = generateReviewArmy({ skillName: 'review', tmplPath: 'review/SKILL.md.tmpl',
|
||
host: 'claude', paths: HOST_PATHS.claude });
|
||
expect(army).toContain('DIFF_LINES < 50, keep `specialists: {}`');
|
||
expect(skill.replace(/\s+/g, ' ')).toMatch(/Step 4\.6's `specialists` object unchanged/i);
|
||
const ship = readFileSync(join(root, 'ship/sections/review-army.md.tmpl'), 'utf8');
|
||
expect(ship).toContain('`specialists`: `{}` for a small-diff skip');
|
||
expect(ship.replace(/\s+/g, ' ')).toMatch(/all required probes pass/i);
|
||
// Value: protects=the small-diff instruction and the specialist record agree that State Machines is the one specialist a
|
||
// small diff may still dispatch (item 9 decides), so the record never contradicts the dispatch (gate 40454750574 judged
|
||
// "skip all except State Machines" beside an unconditional `{}` record); fails_when=either sentence drops the State
|
||
// Machines allowance while the other keeps it, another specialist joins the exemption, or the small-diff line stops keeping
|
||
// the parent-owned probes and core shared-code checks; why_new=the `{}` pin above matches both the old and the new record
|
||
// wording; seam=none; no_claim=the ship persist line, which still says `{}` for every small-diff skip.
|
||
for (const skillName of ['review', 'ship']) {
|
||
const section = generateReviewArmy({ skillName, tmplPath: `${skillName}/SKILL.md.tmpl`, host: 'claude', paths: HOST_PATHS.claude });
|
||
const small = section.match(/^\*\*If DIFF_LINES < 50:\*\*[^\n]*/m)![0];
|
||
expect(small, skillName).toContain('Skip all specialists except State Machines (item 9 decides it).');
|
||
expect(small, skillName).toContain('an empty or State Machines-only specialist list');
|
||
expect(small, skillName).toContain('never the parent-owned smoke probes or core shared-code checks');
|
||
expect(small.replace(/State Machines/g, ''), skillName).not.toMatch(/Testing|Maintainability|Security|Performance|Data Migration|API Contract|Design|Simplification|Red Team/);
|
||
expect(section, skillName).toContain('9. **State Machines** — if SCOPE_STATE_MACHINE is true or unknown');
|
||
}
|
||
expect(army).toContain('For DIFF_LINES < 50, keep `specialists: {}` (or `state-machines` alone when it dispatched); do not manufacture per-specialist scope records.');
|
||
});
|
||
|
||
test('caller QA runs charter and setup after resource loading and has a severity for unmatched functional failures', () => {
|
||
for (const skillName of ['review', 'ship']) {
|
||
const body = generateQAReview({ skillName, tmplPath: '', host: 'claude', paths: HOST_PATHS.claude });
|
||
const preparation = body.indexOf(skillName === 'review'
|
||
? '**1. Set the charter and isolation.**'
|
||
: 'Run the shared preflight;');
|
||
const probes = body.indexOf('**3. Run smoke and plan checks.**');
|
||
expect(preparation).toBeGreaterThan(-1);
|
||
if (skillName === 'review') {
|
||
const readiness = body.indexOf('**2. Check readiness and list required checks.**');
|
||
expect(readiness).toBeGreaterThan(preparation);
|
||
expect(probes).toBeGreaterThan(readiness);
|
||
expect(body.slice(preparation, readiness).replace(/\s+/g, ' ')).toMatch(/isolation\/permission preflight before setup/i);
|
||
} else expect(preparation).toBeGreaterThan(body.indexOf('**2. List required checks.**'));
|
||
expect(probes).toBeGreaterThan(preparation);
|
||
expect(body.replace(/\s+/g, ' ')).toContain('`functional-contract`, `CRITICAL`');
|
||
expectMentions(body, [['not', 'setup/permission', 'blockers']], 'body');
|
||
expectMentions(body, [['approval', 'creation', 'needs']], 'body');
|
||
expect(body).not.toContain('for parent approval');
|
||
}
|
||
});
|
||
|
||
test('review prepares context and deduplicates before classifying findings', () => {
|
||
const positions = [
|
||
'## Step 3.5: Diff scans', '## Step 3.6: Gather review context',
|
||
'{{LEARNINGS_SEARCH}}', '{{ASIDE_RESEARCH}}', '## Step 4: Critical pass',
|
||
'## Step 5: Fix-First Review', '{{CROSS_REVIEW_DEDUP}}',
|
||
'**Keep decisions through fix cycles:**', '### Step 5a: Classify each finding',
|
||
].map(marker => skill.indexOf(marker));
|
||
expect(positions.every(position => position >= 0)).toBe(true);
|
||
expect(positions).toEqual([...positions].sort((a, b) => a - b));
|
||
expect(skill).toMatch(/before Step 5a classification/i);
|
||
});
|
||
|
||
test('review owns the complete persistence contract after the adversarial read', () => {
|
||
const step = skill.slice(skill.indexOf('## Step 5.8: Persist Eng Review result'));
|
||
expect(skill.indexOf('{{SECTION:adversarial}}')).toBeLessThan(skill.indexOf('## Step 5.8: Persist Eng Review result'));
|
||
expect(adversarial).not.toContain('### Before persisting Eng Review (Step 5.8)');
|
||
for (const token of [
|
||
'repeat Steps 3–5', 'at most 3 fix cycles', 'original `evidence_paths`/`helper_target`',
|
||
'snapshot_covered_paths', 'REVIEW_START', 'COMPLETED', 'CONVERGED', 'CYCLES', 'Step 4.7',
|
||
'native Step 4.8 adversarial pass', 'named-risk', 'zero counts', '`completed:false`',
|
||
'`specialists`', '`findings`', 'explicit Skip', 'sharedLibsFingerprint', '`review_binding`',
|
||
]) expect(step.toLowerCase().replace(/\s+/g, ' ')).toContain(token.toLowerCase());
|
||
expect(step.indexOf('### 1. Re-review after edits'))
|
||
.toBeLessThan(step.indexOf('### 2. Fill the record'));
|
||
expect(step.indexOf('### 2. Fill the record'))
|
||
.toBeLessThan(step.indexOf('~/.claude/skills/gstack/bin/gstack-review-log'));
|
||
expect(step).toContain('`quality_score`');
|
||
expect(step.indexOf('Pre-Landing Review: N issues (X critical, Y informational)'))
|
||
.toBeGreaterThan(step.indexOf('~/.claude/skills/gstack/bin/gstack-review-log'));
|
||
expect(step).toContain('`## Exploratory QA and Verification Results`');
|
||
});
|
||
|
||
test('review distinguishes required native coverage from optional outside coverage', () => {
|
||
const section = readFileSync(join(root, 'review/sections/adversarial.md'), 'utf8');
|
||
expectMentions(section, [['only', 'non-blocking', 'adversarial']], 'section');
|
||
expect(section).not.toContain('All errors are non-blocking');
|
||
});
|
||
|
||
test('review identifies probe selection, report assets and the detected diff base', () => {
|
||
const generated = generateQAReview({ skillName: 'review', tmplPath: 'review/SKILL.md.tmpl',
|
||
host: 'claude', paths: HOST_PATHS.claude });
|
||
const checklist = readFileSync(join(root, 'review/checklist.md'), 'utf8');
|
||
expect(generated).toContain('5 minutes/12 probes');
|
||
expect(generated).toContain("Read QA\'s `templates/functional-report-template.md`");
|
||
expect(generated).toMatch(/link every checkpoint/i);
|
||
expect(generated).toMatch(/no second report/i);
|
||
expect(checklist).not.toContain('git diff origin/main');
|
||
});
|
||
|
||
test('caller QA defines execution, evidence ownership and report adaptation before handoff', () => {
|
||
for (const skillName of ['review', 'ship']) {
|
||
const generated = generateQAReview({ skillName, tmplPath: `${skillName}/SKILL.md.tmpl`,
|
||
host: 'claude', paths: HOST_PATHS.claude }).replace(/\s+/g, ' ');
|
||
expect(generated).toMatch(/never overwrite another run/i);
|
||
expectMentions(generated, [['without', 'current', 'updates']], 'generated');
|
||
expect(generated).toContain('Use checklist severity');
|
||
if (skillName === 'review') {
|
||
expect(generated).toContain('`## Exploratory QA and Verification Results`');
|
||
expect(generated).toContain('`### Browser results`');
|
||
} else {
|
||
expect(generated).toContain('`## Exploratory QA`');
|
||
}
|
||
}
|
||
});
|
||
|
||
test('review section index follows the actual pre-fix execution order', () => {
|
||
const manifest = JSON.parse(readFileSync(join(root, 'review/sections/manifest.json'), 'utf8'));
|
||
expect(manifest.sections.map((section: { id: string }) => section.id)).toEqual([
|
||
'plan-completion', 'review-army', 'adversarial', 'shared-code-reuse',
|
||
]);
|
||
});
|
||
|
||
test('review finalization ownership: initialize invocation state and capture the core token before reading', () => {
|
||
const start = skill.slice(skill.indexOf('## Step 3: Get the diff'), skill.indexOf('## Step 3.4:'));
|
||
expect(start).toContain('CYCLES=0');
|
||
expect(skill.match(/CYCLES=0/g)).toHaveLength(1);
|
||
expect(start).toContain('gstack-review-log --start review\ngit diff "$DIFF_BASE"');
|
||
const flat = start.replace(/\s+/g, ' ');
|
||
expect(flat).toMatch(/REVIEW_START for this core candidate before reading its diff/i);
|
||
expectMentions(flat, [['never', 'reading', 'before']], 'flat');
|
||
expect(flat).toMatch(/separate PASS_START tokens, not REVIEW_START/);
|
||
expect(flat).toContain('After an edited pass, start the next with `--start review --fix-range`');
|
||
expect(flat).toContain('On refusal, start a full pass.');
|
||
});
|
||
|
||
test('review finalization ownership: late findings use Fix-First before the bounded parent transition', () => {
|
||
const flat = skill.replace(/\s+/g, ' ');
|
||
const markers = [
|
||
'{{SECTION:adversarial}}',
|
||
'## Step 5: Fix-First Review',
|
||
'Structured approval does not waive advisory/test_stub ASK gates',
|
||
'## Step 5.8: Persist Eng Review result',
|
||
'Edited: increment CYCLES once',
|
||
'No edits: after a full pass, fill the record below',
|
||
'### 2. Fill the record',
|
||
'--finish REVIEW_START',
|
||
];
|
||
const positions = markers.map(marker => flat.indexOf(marker));
|
||
expect(positions.every(position => position >= 0)).toBe(true);
|
||
expect(positions).toEqual([...positions].sort((a, b) => a - b));
|
||
expect(flat).toContain('at most 3 fix cycles');
|
||
expect(flat).toContain('Edited: increment CYCLES once, then fill and save the record below with `converged:false`.');
|
||
const limit = flat.slice(flat.indexOf('At 3,'), flat.indexOf('No edits:'));
|
||
expect(limit).toMatch(/then stop this invocation/i);
|
||
expectMentions(limit, [['without', 'summary', 'fourth']], 'limit');
|
||
});
|
||
|
||
test('review finalization ownership: affected QA reuse cannot replace a full review or erase decisions', () => {
|
||
const step = skill.slice(skill.indexOf('## Step 5.8: Persist Eng Review result'));
|
||
const flat = step.replace(/\s+/g, ' ');
|
||
expect(flat).toContain('execute Steps 3–5 in order');
|
||
expectMentions(flat, [['only', 'unchanged-input', 'evidence']], 'flat');
|
||
// Value: protects=an edited pass reruns every probe its verdict relies on instead of reusing QA captured before the edit,
|
||
// and only a zero-edit pass may reuse unchanged-input evidence (gate 40454750574 read the old sentence as one reuse rule
|
||
// for both); fails_when=the edited-pass rule disappears, reuse is offered to an edited pass, or the two rules swap order;
|
||
// why_new=the only+unchanged-input+evidence pin above also matched the old single-rule wording; seam=none;
|
||
// no_claim=the judged clarity of the sentence.
|
||
const repeat = flat.slice(flat.indexOf('2. On a repeat, execute Steps 3–5 in order.'), flat.indexOf('3. **Verify completed actions.**'));
|
||
expect(repeat).toMatch(/an edited pass supersedes every earlier QA capture \(exploratory §4\): rerun each probe the verdict relies on\./);
|
||
expect(repeat).toMatch(/A zero-edit pass reuses only this invocation's unchanged-input QA evidence, rerunning any probe whose inputs changed or are uncertain\./);
|
||
expect(repeat.indexOf('an edited pass supersedes')).toBeLessThan(repeat.indexOf('A zero-edit pass reuses'));
|
||
expect(repeat).not.toMatch(/reuse only this invocation's unchanged-input QA evidence; rerun a probe if/);
|
||
expectMentions(flat, [['never', 'reusing', 'review']], 'flat');
|
||
expectMentions(flat, [['do not', 'suppress', 'earlier']], 'flat');
|
||
expect(flat).toContain('logger computes `snapshot_covered_paths`');
|
||
expectMentions(flat, [['never', 'prior-record', 'prior-cycle']], 'flat');
|
||
});
|
||
|
||
test('review finalization ownership: required native completion and optional outside records stay separate', () => {
|
||
const step = skill.slice(skill.indexOf('### 2. Fill the record'));
|
||
const flat = step.replace(/\s+/g, ' ');
|
||
expectMentions(flat, [['not', 'inconclusive', 'required']], 'flat');
|
||
expect(flat).toMatch(/`\/ship` named-risk acceptance cannot complete `\/review`/i);
|
||
expectMentions(flat, [['cannot', 'substitute', 'native']], 'flat');
|
||
expect(flat).toMatch(/structured-review gate still applies/i);
|
||
expect(flat).toContain('zero counts and `completed:false`');
|
||
expect(flat).toContain('`CONVERGED`: true only for a completed zero-edit pass');
|
||
});
|
||
|
||
test('review finalization ownership: each logged pass finishes its own core token without log-time capture', () => {
|
||
const step = skill.slice(skill.indexOf('## Step 5.8: Persist Eng Review result'));
|
||
const flat = step.replace(/\s+/g, ' ');
|
||
expect(step.match(/--finish REVIEW_START/g)).toHaveLength(1);
|
||
expect(step).not.toContain('--start review');
|
||
expect(step).not.toContain('--finish PASS_START');
|
||
expect(flat).toMatch(/never invent a binding or replace REVIEW_START at log time/i);
|
||
expect(flat).toContain("finish only this pass's own token");
|
||
expect(step).toContain('"completed":COMPLETED,"converged":CONVERGED,"cycles":CYCLES');
|
||
});
|
||
|
||
test('review finalization ownership: the plan audit retains its high-impact gate before the final scope check', () => {
|
||
const plan = readFileSync(join(root, 'review/sections/plan-completion.md.tmpl'), 'utf8');
|
||
expect(plan).toContain('HIGH-impact discrepancy question');
|
||
expectMentions(plan, [['before', 'resolve', 'final']], 'plan');
|
||
expect(plan).not.toContain('never blocks the review');
|
||
expect(plan).toContain('{{PLAN_COMPLETION_AUDIT_REVIEW}}');
|
||
const audit = readFileSync(join(root, 'review/sections/plan-completion.md'), 'utf8');
|
||
const gate = audit.indexOf('**HIGH-impact plan-file discrepancies** trigger AskUserQuestion');
|
||
expect(gate).toBeGreaterThan(-1);
|
||
expect(gate).toBeLessThan(audit.indexOf('When continuing after the audit (no HIGH-impact gate, or option B/C)'));
|
||
const flatAudit = audit.replace(/\s+/g, ' ');
|
||
expectMentions(flatAudit, [['before', 'implementation', 'invocation']], 'flatAudit');
|
||
expect(flatAudit).toMatch(/not this read-only audit/i);
|
||
// C2: a spawned or non-interactive review cannot answer the question; its default writes and drops nothing.
|
||
expect(flatAudit).toContain('Spawned or non-interactive: report REQUIREMENTS MISSING, continue; record nothing.');
|
||
expect(flatAudit.indexOf('Spawned or non-interactive: report')).toBeLessThan(flatAudit.indexOf('When continuing after the audit'));
|
||
});
|
||
|
||
test('review scope notes remain provisional until the plan section emits the only final scope check', () => {
|
||
const scope = generateScopeDrift({ skillName: 'review', tmplPath: 'review/SKILL.md.tmpl',
|
||
host: 'claude', paths: HOST_PATHS.claude }).replace(/\s+/g, ' ');
|
||
expect(scope).toMatch(/keep these notes provisional/i);
|
||
expectMentions(scope, [['before', 'single', 'final']], 'scope');
|
||
expect(scope).not.toContain('Scope Check: [CLEAN');
|
||
expect(scope).not.toContain('available plan-audit results');
|
||
});
|
||
|
||
// Value: protects=the single final Scope Check is emitted in Step 3 after the full diff read, and the three owners of that
|
||
// rule (the Step 3 skeleton, the plan-completion audit and the Step 1.5 scope notes) name the same point, so `Diff read: full`
|
||
// is recordable when the check is emitted (gate 40454750574: the audit emitted the check before Step 2 while its own rule
|
||
// required Step 3's diff read, a circular prerequisite); fails_when=any owner moves the emission before Step 2, Step 3 loses
|
||
// its emit instruction, the B/C route resurrects "the final Scope Check and Step 2", or the fence is emitted from more than one
|
||
// place; why_new=the provisional-notes test above checks three words in one sentence and the ordering test checks placeholder
|
||
// order, neither pins where the check is emitted; seam=none; no_claim=the judged clarity of the sentences.
|
||
test('the final Scope Check is emitted once, in Step 3 after the full diff read, and every owner names that point', () => {
|
||
const ctx: TemplateContext = { skillName: 'review', tmplPath: 'review/SKILL.md.tmpl', host: 'claude', paths: HOST_PATHS.claude };
|
||
const step3 = between(skill, '## Step 3: Get the diff', '## Step 3.4:');
|
||
expectOrdered(step3, ['git diff "$DIFF_BASE"', "5. First pass only: emit Step 1.5's final Scope Check; `Diff read` records this read."], 'step3');
|
||
expect(skill.split("emit Step 1.5's final Scope Check")).toHaveLength(2);
|
||
const audit = generatePlanCompletionAuditReview(ctx);
|
||
const flatAudit = audit.replace(/\s+/g, ' ');
|
||
expect(flatAudit).toContain('B/C continue to Step 2. None of these choices authorizes shipping');
|
||
expect(flatAudit).not.toContain('continue to the final Scope Check and Step 2');
|
||
expect(flatAudit).toContain("emit the single final Scope Check in Step 3, after its full diff read, from Step 1.5's provisional notes and this plan context:");
|
||
expect(flatAudit).toContain("`Diff read` records Step 3's full-diff read; `Scope Check: CLEAN`, and options B and C above, count as approved only with `Diff read: full` recorded.");
|
||
expect(audit.split('Scope Check: [CLEAN / DRIFT DETECTED / REQUIREMENTS MISSING]')).toHaveLength(2);
|
||
// The no-plan path and the section's STOP trigger name the same point; neither may say the check is emitted or finished in Step 1.5.
|
||
expect(flatAudit).toContain('**No plan file found:** Use commit messages and TODOS.md as fallback sources (see above). Step 3 emits the Scope Check once without plan fields.');
|
||
expect(audit).not.toMatch(/Emit Step 1\.5's/);
|
||
const rendered = readFileSync(join(root, 'review/SKILL.md'), 'utf8');
|
||
expect(rendered).toContain('> **STOP.** Before leaving Step 1.5, Read');
|
||
expect(rendered).not.toContain("finishing Step 1.5's Scope Check");
|
||
const scope = generateScopeDrift(ctx).replace(/\s+/g, ' ');
|
||
expect(scope).toContain('it resolves the HIGH-impact decision before Step 2; Step 3 emits the single final Scope Check after its full diff read.');
|
||
expect(scope).not.toMatch(/emits the single final Scope Check before Step 2/);
|
||
expect(scope).not.toContain('Scope Check: [CLEAN');
|
||
expect(skill).not.toContain('Scope Check: [CLEAN');
|
||
});
|
||
|
||
test('review confidence uses its severity labels without an undefined P0 exception', () => {
|
||
const ctx: TemplateContext = { skillName: 'review', tmplPath: 'review/SKILL.md.tmpl',
|
||
host: 'claude', paths: HOST_PATHS.claude };
|
||
const confidence = generateConfidenceCalibration(ctx);
|
||
expect(confidence).toContain('[CRITICAL]');
|
||
expect(confidence).toContain('[CRITICAL|INFORMATIONAL]');
|
||
expect(confidence).not.toMatch(/\bP[012]\b/);
|
||
const flat = confidence.replace(/\s+/g, ' ');
|
||
for (const row of [
|
||
/\| 9-10 \|[^|]*\| Show normally \|/, /\| 7-8 \|[^|]*\| Show normally \|/,
|
||
/\| 5-6 \|[^|]*\| Show with caveat/, /\| 3-4 \|[^|]*\| Suppress from main report/,
|
||
/\| 1-2 \|[^|]*\| Only report a suspected release-blocking catastrophe/,
|
||
]) expect(flat).toMatch(row);
|
||
expect(flat).toMatch(/explicitly speculative/i);
|
||
expect(flat).toMatch(/the finding is unverified/i);
|
||
expect(flat).toContain('file:line');
|
||
expect(flat).toMatch(/force its confidence to 4-5/i);
|
||
expect(flat).toMatch(/never invent speculative confidence 7\+/i);
|
||
expect(confidence.indexOf('Pre-emit verification gate')).toBeLessThan(confidence.indexOf('| Score |'));
|
||
expect(confidence).not.toContain('FP classes the gate kills');
|
||
expect(confidence).not.toContain('1539-framework-aware-review.md');
|
||
expectMentions(generateConfidenceCalibration({ ...ctx, skillName: 'ship' }), [['only', 'severity', 'report']], 'section');
|
||
});
|
||
|
||
test('review names the lifecycle and record owners before using their persistence rules', () => {
|
||
const start = skill.slice(skill.indexOf('## Step 3: Get the diff'), skill.indexOf('## Step 3.4:')).replace(/\s+/g, ' ');
|
||
expect(start).toContain('REVIEW_START / PASS_START |');
|
||
expect(start).toContain('`review_binding` |');
|
||
expect(start).toContain('`snapshot_covered_paths` |');
|
||
expectMentions(start, [['never', 'matching', 'reusable']], 'start');
|
||
expectMentions(start, [['never', 'supplied', 'reviewer']], 'start');
|
||
});
|
||
|
||
test('review invocation-local advice reuse keeps raw-source and changed-decision gates', () => {
|
||
const decisions = skill.slice(skill.indexOf('**Keep decisions through fix cycles:**'),
|
||
skill.indexOf('### Step 5a:')).replace(/\s+/g, ' ');
|
||
expect(decisions).toMatch(/save completed AUTO-FIX\/fix and explicit Skip actions/i);
|
||
expect(decisions).toContain("`advisory`, `evidence_paths` and `helper_target`");
|
||
expect(decisions).toMatch(/require a new question/i);
|
||
expect(decisions).toMatch(/cannot suppress new\/recurring defects/i);
|
||
});
|
||
|
||
for (const skillName of ['review', 'ship']) {
|
||
const ctx: TemplateContext = { skillName, tmplPath: `${skillName}/SKILL.md.tmpl`,
|
||
host: 'claude', paths: HOST_PATHS.claude };
|
||
const army = generateReviewArmy(ctx);
|
||
const flat = army.replace(/\s+/g, ' ');
|
||
|
||
// PR gate run 38981523623 (ship-exploratory-plan-checks): the block sourced the scope signals
|
||
// without printing them, so the agent appended its own echo to see SCOPE_FRONTEND.
|
||
test(`${skillName} clarity: the scope block prints every signal specialist selection reads`, () => {
|
||
const block = between(army, '### Detect stack and scope', '### Read specialist hit rates');
|
||
expect(block).toContain("/gstack-diff-scope <base> 2>/dev/null) || true\nset | grep '^SCOPE_'\n");
|
||
const selection = between(army, '### Select specialists', '### Adaptive gating');
|
||
const used = [...new Set(selection.match(/SCOPE_[A-Z_]+/g))];
|
||
expect(used.length).toBeGreaterThan(0);
|
||
const flags = between(readFileSync(join(root, 'bin/gstack-diff-scope'), 'utf8'), '_print_flags() {', '}');
|
||
for (const signal of used) {
|
||
if (flags.includes(`echo "${signal}=`)) continue;
|
||
// PR gate run 39002269281: a signal gstack-diff-scope does not print comes from a detect helper the scope
|
||
// block itself runs, never from a command named only in selection prose.
|
||
const helper = /bin\/(gstack-[a-z-]+) detect\b/.exec(block.split('\n').find(line => line.includes(signal))!)?.[1];
|
||
expect(helper, signal).toBeDefined();
|
||
expect(readFileSync(join(root, 'bin', helper!), 'utf8'), signal).toContain(`${signal}=\${`);
|
||
expect(selection, signal).not.toMatch(/\bdetect\b/);
|
||
}
|
||
});
|
||
|
||
test(`${skillName} clarity: the state-machine signal checks the detector's exit status and fails toward dispatch`, () => {
|
||
const block = between(army, '### Detect stack and scope', '### Read specialist hit rates');
|
||
expect(block).toContain(`_SM=$(${HOST_PATHS.claude.binDir}/gstack-state-matrix detect --base <base>) || _SM=SCOPE_STATE_MACHINE=unknown; source <(echo "$_SM")\n`);
|
||
expect(block.indexOf('SCOPE_STATE_MACHINE=unknown')).toBeLessThan(block.indexOf("set | grep '^SCOPE_'"));
|
||
const selection = between(army, '### Select specialists', '### Adaptive gating').replace(/\s+/g, ' ');
|
||
expect(selection).toContain('9. **State Machines** — if SCOPE_STATE_MACHINE is true or unknown: read');
|
||
// /review delta on 51f1e02: a fixed .gstack/tmp/state-machines.md let a second review check the previous run's
|
||
// output (Write refuses an unread existing file) and commit it; each run now checks the new file outfile prints.
|
||
expect(selection).toContain('/gstack-state-matrix outfile`, Read the file it prints, write the full output there, then run `');
|
||
expect(selection).toContain('/gstack-state-matrix check <file>` on it.');
|
||
expect(selection).not.toContain('.gstack/tmp/state-machines.md');
|
||
expect(selection).not.toContain('<<');
|
||
expect(selection).not.toContain('pipe output');
|
||
});
|
||
|
||
test(`${skillName} clarity: the scope block run against a failing detector prints unknown and keeps its stderr`, () => {
|
||
const stubs = mkdtempSync(join(realpathSync(tmpdir()), 'scope-block-'));
|
||
try {
|
||
const block = /\`\`\`bash\n([\s\S]*?)\n\`\`\`/.exec(between(generateReviewArmy({ ...ctx, paths: { ...ctx.paths, binDir: stubs } }),
|
||
'### Detect stack and scope', '### Read specialist hit rates'))![1].replaceAll('<base>', 'main');
|
||
writeFileSync(join(stubs, 'gstack-diff-scope'), '#!/bin/sh\necho SCOPE_FRONTEND=false\n', { mode: 0o755 });
|
||
const run = (detector: string) => {
|
||
writeFileSync(join(stubs, 'gstack-state-matrix'), `#!/bin/sh\n${detector}\n`, { mode: 0o755 });
|
||
return spawnSync('bash', ['-c', block], { cwd: stubs, encoding: 'utf8', timeout: 10_000 });
|
||
};
|
||
const failed = run("echo SCOPE_STATE_MACHINE=false; echo '# no merge base with origin/main; run: git fetch origin main'; echo 'detector crashed' >&2; exit 2");
|
||
expect(failed.stdout).toMatch(/^SCOPE_STATE_MACHINE=unknown$/m);
|
||
expect(failed.stdout).not.toMatch(/^SCOPE_STATE_MACHINE=false$/m);
|
||
expect(failed.stderr).toContain('detector crashed');
|
||
expect(run('exit 127').stdout).toMatch(/^SCOPE_STATE_MACHINE=unknown$/m);
|
||
const silent = run("echo 'detector found no git' >&2; exit 3");
|
||
expect(silent.stdout).toMatch(/^SCOPE_STATE_MACHINE=unknown$/m);
|
||
expect(silent.stderr).toContain('detector found no git');
|
||
const lateFail = run("echo SCOPE_STATE_MACHINE=true; echo SCOPE_LEAK=1; exit 1");
|
||
expect(lateFail.stdout).toMatch(/^SCOPE_STATE_MACHINE=unknown$/m);
|
||
expect(lateFail.stdout).not.toContain('SCOPE_LEAK');
|
||
const detected = run("echo SCOPE_STATE_MACHINE=true; echo '# state-machine: src/takes.ts:4 proposal,accept'");
|
||
expect(detected.stdout).toMatch(/^SCOPE_STATE_MACHINE=true$/m);
|
||
expect(detected.stdout).toMatch(/^SCOPE_FRONTEND=false$/m);
|
||
expect(run('echo SCOPE_STATE_MACHINE=false').stdout).toMatch(/^SCOPE_STATE_MACHINE=false$/m);
|
||
expect(block).toContain("DIFF_LINES=$(git diff \"$DIFF_BASE\" --numstat | awk '{n+=$1+$2} END {print n+0}')");
|
||
} finally { rmSync(stubs, { recursive: true, force: true }); }
|
||
});
|
||
|
||
test(`${skillName} clarity: terminal failure permits independent work but never certifies coverage`, () => {
|
||
expectMentions(flat, [['confirm', 'finished', 'stopped']], 'flat');
|
||
expectMentions(flat, [['does not', 'termination', 'timeout']], 'flat');
|
||
expect(flat).toMatch(/stop path without edits/i);
|
||
expectMentions(flat, [['never', 'dispatched', 'incomplete']], 'flat');
|
||
const redTeam = flat.slice(flat.indexOf('### Red Team dispatch'));
|
||
expectMentions(redTeam, [['confirm', 'incomplete', 'stopped']], 'redTeam');
|
||
expect(redTeam).toContain('stages 1–8');
|
||
});
|
||
|
||
test(`${skillName} clarity: ordered specialist merge separates validation from scoring and provenance`, () => {
|
||
const markers = ['#### 1. Parse outputs', '#### 2. Validate severity',
|
||
'#### 3. Identify and merge', '#### 4. Lead judgment', '#### 5. Apply specialist confidence gates',
|
||
'#### 6. Score and present specialists', '#### 7. Save specialist activity',
|
||
'#### 8. Hand off to Fix-First'];
|
||
const positions = markers.map(marker => army.indexOf(marker));
|
||
expect(positions.every(position => position >= 0)).toBe(true);
|
||
expect(positions).toEqual([...positions].sort((a, b) => a - b));
|
||
const validation = flat.slice(flat.indexOf('#### 2.'), flat.indexOf('#### 3.'));
|
||
expect(validation).toContain('remove `advisory` and retain its `CRITICAL` severity');
|
||
expect(validation).toMatch(/never downgrade severity/i);
|
||
const merge = flat.slice(flat.indexOf('#### 3.'), flat.indexOf('#### 4.'));
|
||
expect(merge.indexOf('Partition defects and advisories')).toBeLessThan(merge.indexOf('grouping by fingerprint'));
|
||
for (const token of ['sharedLibsFingerprint', 'literal JSON on stdin', '+1 (cap at 10)']) expect(merge).toContain(token);
|
||
for (const rule of [/never trust a supplied hash/i, /missing\/malformed metadata cannot deduplicate/i,
|
||
/core findings never earn a specialist confidence boost/i]) expect(merge).toMatch(rule);
|
||
for (const gate of ['Confidence 7+', 'Confidence 5-6', 'Confidence 3-4', 'Confidence 1-2']) expect(army).toContain(gate);
|
||
const judgment = flat.slice(flat.indexOf('#### 4.'), flat.indexOf('#### 5.'));
|
||
for (const filter of [/nit gravity/i, /hypothetical, not actual/i, /case that does not exist/i, /different design is not a defect/i, /missing context/i]) expect(judgment).toMatch(filter);
|
||
expect(judgment).toContain('returned `NO FINDINGS` was right');
|
||
const scoring = flat.slice(flat.indexOf('#### 6.'), flat.indexOf('#### 7.'));
|
||
expect(scoring).toMatch(/only specialist findings enter this header and `quality_score`/i);
|
||
expect(scoring).toMatch(/non-advisory/i);
|
||
expect(scoring).toContain('quality_score = max(0, 10 - (critical_count * 2 + informational_count * 0.5))');
|
||
expect(flat).toMatch(/advisory findings count in the stats `findings` field/i);
|
||
expectMentions(flat, [['only', 'specialist', 'findings']], 'flat');
|
||
expectMentions(flat, [['not', 'specialist', 'core-only']], 'flat');
|
||
expect(flat).toContain('ASK-only');
|
||
});
|
||
|
||
test(`${skillName} clarity: shared-code reuse gives executable decisions and retains checker safeguards`, () => {
|
||
const reuse = generateSharedCodeReuse(ctx).replace(/\s+/g, ' ');
|
||
const markers = ['1. **Read the evidence.**', '2. **Run the checker.**',
|
||
'3. **Act on its result.**', '4. **Persist through the logger.**'];
|
||
const positions = markers.map(marker => reuse.indexOf(marker));
|
||
expect(positions.every(position => position >= 0)).toBe(true);
|
||
expect(positions).toEqual([...positions].sort((a, b) => a - b));
|
||
for (const token of ['--check-shared-libs REVIEW_START', "<<'GSTACK_SHARED_LIBS_REUSE_JSON'", 'literal JSON on stdin',
|
||
'`reusable: true`', 'sharedLibsFingerprint', 'explicit Skip', 'logger-versioned `snapshot_covered_paths`',
|
||
'canReuseSharedLibsAdvisory']) expect(reuse).toContain(token);
|
||
for (const rule of [/false, command failure or unreadable output[^.]*never suppression/i,
|
||
/do not supply your own snapshot, prior record or coverage/i, /unknown evidence fails closed/i,
|
||
/real defects retain normal Fix-First handling/i]) expect(reuse).toMatch(rule);
|
||
});
|
||
}
|
||
|
||
test('review clarity: settlement gates edits separately from incomplete required coverage', () => {
|
||
const fix = skill.slice(skill.indexOf('## Step 5: Fix-First Review'), skill.indexOf('{{CROSS_REVIEW_DEDUP}}')).replace(/\s+/g, ' ');
|
||
expectMentions(fix, [['stop', 'without', 'edits']], 'fix');
|
||
});
|
||
|
||
test('review clarity: review bot reply choices never substitute for Fix-First approval', () => {
|
||
const fix = skill.slice(skill.indexOf('## Step 5: Fix-First Review'), skill.indexOf('{{CROSS_REVIEW_DEDUP}}'));
|
||
expect(fix).toContain('VALID & ACTIONABLE review bot findings');
|
||
const greptile = skill.slice(skill.indexOf('### Review bot comment resolution'), skill.indexOf('## Step 5.8:'));
|
||
const flat = greptile.replace(/\s+/g, ' ');
|
||
expectMentions(flat, [['not', 'decisions', 'approval']], 'flat');
|
||
expect(flat).toContain('B) Propose a code change');
|
||
expect(flat).toContain('Steps 5c–5d');
|
||
expectMentions(flat, [['wait', 'approval', 'editing']], 'flat');
|
||
expect(flat).toMatch(/no new fix permission/i);
|
||
});
|
||
|
||
test('ship review clarity: parent settlement gate precedes classification and cannot waive coverage', () => {
|
||
const ship = readFileSync(join(root, 'ship/sections/review-army.md.tmpl'), 'utf8');
|
||
const gate = ship.slice(ship.indexOf('## Step 9.4:'), ship.indexOf('1. **Classify')).replace(/\s+/g, ' ');
|
||
expectMentions(gate, [['wait', 'termination', 'confirm']], 'gate');
|
||
expectMentions(gate, [['stop', 'incomplete', 'through']], 'gate');
|
||
expectMentions(gate, [['blocks', 'continuation', 'dispatched']], 'gate');
|
||
});
|
||
|
||
test('review keeps its smoke-clock, setup-authority, plan-gate and findings-source rules', () => {
|
||
const ctx = { skillName: 'review', tmplPath: 'review/SKILL.md.tmpl', host: 'claude', paths: HOST_PATHS.claude } as TemplateContext;
|
||
const qa = generateQAReview(ctx).replace(/\s+/g, ' ');
|
||
expect(qa).toMatch(/\/review sets none; only an invoker-supplied EARLIER_UTC counts/);
|
||
expectMentions(qa, [['never', 'report-only', 'installs']], 'qa');
|
||
expect(qa).toMatch(/otherwise they stay blocked/i);
|
||
expect(qa).not.toContain('Ask for setup/permission');
|
||
expect(generateQAReview({ ...ctx, skillName: 'ship', tmplPath: 'ship/SKILL.md.tmpl' })).not.toContain('/review sets none');
|
||
const audit = generatePlanCompletionAuditReview(ctx).replace(/\s+/g, ' ');
|
||
// F1 (#2768): no bound plan prints the exact not-run line instead of the old notice.
|
||
expect(audit).toContain(PLAN_AUDIT_NOT_RUN);
|
||
expect(audit).not.toMatch(/skip dispatch/);
|
||
expect(audit).toContain('**HIGH-impact plan-file discrepancies** trigger AskUserQuestion');
|
||
expectMentions(audit, [['never', 'fallback', 'question']], 'audit');
|
||
const shipCtx = { ...ctx, skillName: 'ship', tmplPath: 'ship/SKILL.md.tmpl' };
|
||
expectMentions(generatePlanCompletionAuditShip(shipCtx), [['do not', 'another', 'search']], 'generatePlanCompletionAuditShip(shipCtx)');
|
||
const persist = skill.slice(skill.indexOf('### 2. Fill the record')).replace(/\s+/g, ' ');
|
||
});
|
||
|
||
// INV-1 consumers: an outside review that reports `unverified` or
|
||
// `unavailable` is missing coverage in /ship's readiness note, its PR body
|
||
// and /review's completion, never a pass.
|
||
test('ship and review count unverified or unavailable outside reviews as missing coverage', () => {
|
||
const read = (rel: string) => readFileSync(join(import.meta.dir, '..', rel), 'utf-8').replace(/\s+/g, ' ');
|
||
for (const rel of ['ship/SKILL.md', 'ship/sections/pr-body.md', 'review/SKILL.md']) {
|
||
expect(read(rel)).toMatch(/`unverified` or `unavailable` is (listed as )?missing coverage[^.]*never (as )?(a )?pass/i);
|
||
}
|
||
});
|
||
|
||
test('testing specialist treats negative assertions as decisions and catches ones a rename emptied', () => {
|
||
const specialist = between(readFileSync(join(root, 'review/specialists/testing.md'), 'utf8'), '### Negative Assertions', '\n### ');
|
||
expectTokens(specialist, ['not.toContain', 'assertNotIn'], 'testing specialist');
|
||
expectMentions(compact(specialist), [
|
||
['new', 'absent', 'removal', 'not coverage'],
|
||
['authorizes', 'removal'],
|
||
['rename', 'negative assertion', 'passes forever'],
|
||
['grep', 'negative assertions', 'old value'],
|
||
], 'testing specialist');
|
||
});
|
||
|
||
test('security specialist checks authorization paths a route-guard read misses', () => {
|
||
const auth = compact(between(readFileSync(join(root, 'review/specialists/security.md'), 'utf8'), '### Auth & Authorization Bypass', '\n### '));
|
||
expectMentions(auth, [
|
||
['error', 'renderer', 'outside', 'guard'],
|
||
['ownership', 'role', 'downgrade'],
|
||
['list', 'detail', 'download', 'separately'],
|
||
['session', 'before', 'validating', 'callback'],
|
||
], 'security specialist');
|
||
});
|
||
|
||
// Gate Integrity (docs/designs/HONEST_WORK_GATE_INTEGRITY.md W2): the category
|
||
// sits in the core CRITICAL pass every diff size gets, its findings reach a
|
||
// human through one four-option question, and the record carries identity
|
||
// fields a later reader can act on. Tokens and order only; the prose is free.
|
||
test('Gate Integrity is a Pass 1 category that is ASK-only and keeps the three levels apart', () => {
|
||
const checklist = readFileSync(join(root, 'review/checklist.md'), 'utf8');
|
||
const pass1 = between(checklist, '### Pass 1 — CRITICAL', '### Pass 2 — INFORMATIONAL');
|
||
expect(pass1).toContain('#### Gate Integrity');
|
||
expect(between(checklist, '**Two-pass review:**', '**Output format:**')).toMatch(/Pass 1 \(CRITICAL\):[^\n]*Gate Integrity/);
|
||
const category = compact(between(pass1, '#### Gate Integrity'));
|
||
expectTokens(category, ['GATE_SUMMARY:', 'RH-1', 'RH-3', 'RH-4', 'RH-12', 'RH-13', 'RH-14', 'RH-15', 'RH-16', 'RH-2', 'RH-5',
|
||
'**Listed**', '**Read**', '**Finding**', 'gstack-decision-search --query "<dec-id>"'], 'Gate Integrity category');
|
||
expectMentions(category, [
|
||
['ask', 'never', 'auto-fix'],
|
||
['groups', 'one decision'],
|
||
['confidence', 'identification', 'not justification'],
|
||
['citations', 'never', 'remove', 'finding'],
|
||
['data', 'never', 'instructions', 'actor', 'reason'],
|
||
], 'Gate Integrity category');
|
||
const heuristic = between(checklist, '## Fix-First Heuristic', '## Suppressions');
|
||
const askColumn = heuristic.slice(heuristic.indexOf('ASK (needs human judgment):'));
|
||
expect(askColumn).toContain('Gate Integrity');
|
||
expect(between(checklist, '## Severity Classification', '## Fix-First Heuristic')).toMatch(/└─ Gate Integrity/);
|
||
});
|
||
|
||
test('the eval-threshold suppression no longer removes a relaxed gate from the human question', () => {
|
||
const suppressions = compact(between(readFileSync(join(root, 'review/checklist.md'), 'utf8'), '## Suppressions'));
|
||
expect(suppressions).toContain('Eval threshold changes');
|
||
const line = suppressions.slice(suppressions.indexOf('Eval threshold changes'), suppressions.indexOf('Harmless no-ops'));
|
||
expectMentions(line, [['not', 'suppress', 'gate integrity'], ['citation', 'never', 'removes', 'finding']], 'threshold suppression');
|
||
expectTokens(line, ['verified', 'unverified'], 'threshold suppression');
|
||
});
|
||
|
||
test('review runs the gate scan before slop, carries the listing into Step 4 and asks the four gate options in order', () => {
|
||
expectOrdered(skill, ['## Step 3.5: Diff scans', '{{GATE_SCAN_BLOCK}}', 'bun run slop:diff', '## Step 3.6:',
|
||
'## Step 4: Critical pass', '### Step 5c:', 'review-gate-disposition',
|
||
'A) Restore the gate', 'B) Keep — justified', 'C) Keep — other reason', 'D) Leave open for a later human',
|
||
'### Step 5d:', '## Step 5.8:'], 'review skill');
|
||
expect(skill.match(/\{\{GATE_SCAN_BLOCK\}\}/g)).toHaveLength(1);
|
||
expectTokens(between(skill, '## Step 4: Critical pass', '### Shared-code opportunities'), ['GATE_SUMMARY:', '`gate`', '`gate_id`'], 'Step 4 gate carry');
|
||
const ask = compact(between(skill, '### Step 5c:', '### Step 5d:'));
|
||
expect(ask).toContain('<gstack-qid:review-gate-disposition>');
|
||
expectMentions(ask, [
|
||
['spawned', 'headless', 'd', 'recommended'],
|
||
['auto-chosen', 'never', 'disposition'],
|
||
], 'Step 5c gate question');
|
||
for (const action of ['`restored`', '`kept`', '`open`']) expect(ask).toContain(action);
|
||
});
|
||
|
||
test('review persists gate identity fields, counts open findings and reports one Gate edits line', () => {
|
||
const record = compact(between(skill, '### 2. Fill the record', '### Report the final review'));
|
||
expectTokens(record, ['`gate`', '`gate_id`', '`reason`', '`kept`', '`restored`', '`open`', '`actor`', 'gstack-session-kind'], 'review record');
|
||
expectMentions(record, [
|
||
['never', 'hunk text'],
|
||
['`open`', 'count', '`issues_found`'],
|
||
['logger', 'stamps', '`actor`'],
|
||
], 'review record');
|
||
const report = compact(between(skill, '### Report the final review', '{{LEARNINGS_LOG}}'));
|
||
expectOrdered(report, ['`Gate edits: none detected (', '`Gate edits: N listed, M read, K findings —', '`Gate edits: partial (', '`Gate edits: UNAVAILABLE —'], 'final report');
|
||
expectMentions(report, [['unavailable', 'never', 'none detected']], 'final report');
|
||
});
|
||
|
||
test('review suppressions allow a clean result and skip common false positives but never suppress missing validation or a missing await', () => {
|
||
const suppressions = between(readFileSync(join(root, 'review/checklist.md'), 'utf8'), '## Suppressions');
|
||
expectMentions(compact(suppressions), [['zero findings', 'valid']], 'suppressions');
|
||
expectTokens(suppressions, ['"Function too long"', '"Possible null dereference"', '"N+1 query"', '"Hardcoded value"', '`Math.random()`'], 'suppressions');
|
||
expectAbsent(suppressions, [/missing input validation/i, /missing await/i], 'suppressions');
|
||
});
|
||
|
||
test('judged repeat-pass QA reruns and unresolved record actions each have one rule (paid screen 40617200857)', () => {
|
||
// Every sample of the red panel and its rerun named one of these: "post-expiry smoke rechecks are not-run" vs
|
||
// Step 5.8's rerun of superseded probes, materialize's once-per-PROBE_DIR limit vs reruns into the same report,
|
||
// and no record action for an unresolved non-gate defect (an unanswered question or an unproven repair).
|
||
// fails_when=the rerun stops being revalidation, materialize may run per pass, or such a defect has no action.
|
||
const flat = skill.replace(/\s+/g, ' ');
|
||
const repeat = flat.slice(flat.indexOf('2. On a repeat, execute Steps 3–5 in order.'), flat.indexOf('3. **Verify completed actions.**'));
|
||
expect(repeat).toContain('These reruns are revalidation, so they run even after smoke expiry; keep the PROBE_DIR. Earlier provisional sections link checkpoints; only the final pass runs its once-only `materialize`.');
|
||
expect(repeat.indexOf('rerun each probe the verdict relies on')).toBeLessThan(repeat.indexOf('These reruns are revalidation'));
|
||
const actions = flat.slice(flat.indexOf('Actions: `auto-fixed` (Step 5b)'), flat.indexOf('Advice is never `auto-fixed`'));
|
||
expect(actions).toContain('`fixed` (approved **and completed** in Step 5d)');
|
||
expect(actions).toContain('`skipped` (explicit Skip in Step 5c), `open` (any other defect, e.g. unanswered).');
|
||
expect(flat).toContain('Do not record an unanswered question as skipped');
|
||
});
|