mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-17 18:32:19 +02:00
feat(retro): absorb inline git/awk metrics into bin/gstack-retro-metrics + carve report format
RETRO_METRICS_PROTO: 1 contract, local git reads only (fetch stays in the skill prose), degraded path documented in the skeleton. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
b007814be0
commit
e0250aa128
@@ -2,20 +2,24 @@
|
||||
* Regression tests for #1624 — /retro silently produced empty/misleading
|
||||
* output when "today" anchor was wrong or origin/<default> was stale.
|
||||
*
|
||||
* The fix is Step 0.5 in retro/SKILL.md.tmpl: four ordered pre-check
|
||||
* branches before any window analysis. These tests are static invariants
|
||||
* against the template body — they fail the build if the guard is removed,
|
||||
* weakened, or its ordering broken.
|
||||
* The guard survived the retro token-reduction wave in two halves:
|
||||
* - LOCAL checks (remote present? detached HEAD? newest commit date on the
|
||||
* analyzed ref) live in bin/gstack-retro-metrics, emitted as
|
||||
* GUARD_REMOTE / GUARD_HEAD / GUARD_LATEST_COMMIT lines.
|
||||
* - The FETCH (network op — kept in skill prose, never in the script) and
|
||||
* the ordered skip/BLOCK decision rules live in retro/SKILL.md.tmpl
|
||||
* (Step 0.5 fetch fence + Step 1 guard prose).
|
||||
*
|
||||
* Branches under test:
|
||||
* 1. no-remote skip — git remote returns empty
|
||||
* 2. detached-HEAD skip — git symbolic-ref --quiet HEAD returns empty
|
||||
* 3. fetch-fail warn — git fetch origin <default> exits non-zero
|
||||
* 4. stale-base BLOCK — fetch ok, latest commit older than window
|
||||
* These static invariants fail the build if the guard is removed, weakened,
|
||||
* or its ordering broken:
|
||||
* 1. no-remote skip — script emits GUARD_REMOTE: none
|
||||
* 2. detached-HEAD skip — script emits GUARD_HEAD: detached
|
||||
* 3. fetch-fail warn — Step 0.5 fence discloses and proceeds
|
||||
* 4. stale-base BLOCK — fetch ok + latest commit older than window
|
||||
*
|
||||
* Each branch must short-circuit further checks (only one verdict wins) and
|
||||
* must surface a disclosure line on stderr so the narrative carries the
|
||||
* reason rather than silently misreporting.
|
||||
* Skip paths must carry a disclosure into the narrative; BLOCK must cite the
|
||||
* date and the remediation. Behavioral coverage of the script's guard
|
||||
* emissions lives in test/gstack-retro-metrics.test.ts.
|
||||
*/
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import * as fs from "node:fs";
|
||||
@@ -23,124 +27,120 @@ import * as path from "node:path";
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, "..");
|
||||
const RETRO_TMPL = path.join(ROOT, "retro", "SKILL.md.tmpl");
|
||||
const RETRO_MD = path.join(ROOT, "retro", "SKILL.md");
|
||||
const METRICS_SCRIPT = path.join(ROOT, "bin", "gstack-retro-metrics");
|
||||
|
||||
function readTmpl(): string {
|
||||
return fs.readFileSync(RETRO_TMPL, "utf-8");
|
||||
}
|
||||
|
||||
function readMd(): string {
|
||||
return fs.readFileSync(RETRO_MD, "utf-8");
|
||||
function readScript(): string {
|
||||
return fs.readFileSync(METRICS_SCRIPT, "utf-8");
|
||||
}
|
||||
|
||||
describe("#1624 retro stale-base guard — Step 0.5 exists and is ordered before Step 1", () => {
|
||||
test("Step 0.5 header is present in template", () => {
|
||||
const body = readTmpl();
|
||||
expect(body).toMatch(/### Step 0\.5: Stale-base \+ bad-today-anchor pre-flight guard/);
|
||||
});
|
||||
|
||||
test("Step 0.5 appears before Step 1: Gather Raw Data", () => {
|
||||
describe("#1624 retro stale-base guard — pre-flight ordered before analysis", () => {
|
||||
test("Step 0.5 fetch pre-flight is present and precedes Step 1", () => {
|
||||
const body = readTmpl();
|
||||
const step05 = body.indexOf("### Step 0.5:");
|
||||
const step1 = body.indexOf("### Step 1: Gather Raw Data");
|
||||
const step1 = body.indexOf("### Step 1: Gather");
|
||||
expect(step05).toBeGreaterThan(-1);
|
||||
expect(step1).toBeGreaterThan(-1);
|
||||
expect(step05).toBeLessThan(step1);
|
||||
});
|
||||
|
||||
test("regenerated SKILL.md carries the Step 0.5 guard", () => {
|
||||
const md = readMd();
|
||||
expect(md).toMatch(/Step 0\.5: Stale-base \+ bad-today-anchor pre-flight guard/);
|
||||
test("guard evaluation prose sits in Step 1 before the metric interpretation steps", () => {
|
||||
const body = readTmpl();
|
||||
const guard = body.indexOf("Stale-base + bad-today-anchor guard");
|
||||
const step2 = body.indexOf("### Step 2: Compute Metrics");
|
||||
expect(guard).toBeGreaterThan(-1);
|
||||
expect(step2).toBeGreaterThan(-1);
|
||||
expect(guard).toBeLessThan(step2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#1624 retro guard — branch A: no-remote skip", () => {
|
||||
test("template checks for 'origin' remote absence and skips with disclosure", () => {
|
||||
const body = readTmpl();
|
||||
// Must check git remote for 'origin' and short-circuit
|
||||
expect(body).toMatch(/git remote[^|]*\|\s*grep -c '\^origin\$'/);
|
||||
expect(body).toMatch(/RETRO_GUARD: no 'origin' remote/);
|
||||
test("script checks for 'origin' remote absence and emits GUARD_REMOTE", () => {
|
||||
const script = readScript();
|
||||
expect(script).toMatch(/git remote[^|]*\|\s*grep -c '\^origin\$'/);
|
||||
expect(script).toContain("GUARD_REMOTE: none");
|
||||
expect(script).toContain("GUARD_REMOTE: origin");
|
||||
});
|
||||
|
||||
test("no-remote skip sets a verdict variable that gates later checks", () => {
|
||||
test("template prose treats GUARD_REMOTE: none as proceed-with-disclosure", () => {
|
||||
const body = readTmpl();
|
||||
// The verdict variable must be set so later branches short-circuit
|
||||
expect(body).toMatch(/_RETRO_GUARD_VERDICT="skip-no-remote"/);
|
||||
expect(body).toMatch(/GUARD_REMOTE: none/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#1624 retro guard — branch B: detached-HEAD skip", () => {
|
||||
test("template checks for detached HEAD via git symbolic-ref", () => {
|
||||
const body = readTmpl();
|
||||
expect(body).toMatch(/git symbolic-ref --quiet HEAD/);
|
||||
expect(body).toMatch(/RETRO_GUARD: detached HEAD/);
|
||||
test("script checks for detached HEAD via git symbolic-ref and emits GUARD_HEAD", () => {
|
||||
const script = readScript();
|
||||
expect(script).toMatch(/git symbolic-ref --quiet --short HEAD/);
|
||||
expect(script).toContain("GUARD_HEAD: detached");
|
||||
});
|
||||
|
||||
test("detached-HEAD branch is gated by prior verdict check (ordering)", () => {
|
||||
test("template prose treats GUARD_HEAD: detached as proceed-with-disclosure", () => {
|
||||
const body = readTmpl();
|
||||
// The detached-HEAD block must be guarded by the verdict check so
|
||||
// no-remote always wins if both are true.
|
||||
const branchBStart = body.indexOf("# Pre-check B: detached HEAD");
|
||||
expect(branchBStart).toBeGreaterThan(-1);
|
||||
const branchBSlice = body.slice(branchBStart, branchBStart + 500);
|
||||
expect(branchBSlice).toMatch(/if \[ -z "\$_RETRO_GUARD_VERDICT" \]/);
|
||||
expect(body).toMatch(/GUARD_HEAD: detached/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#1624 retro guard — branch C: fetch-fail warn", () => {
|
||||
test("template warns and proceeds against last-known origin when fetch fails", () => {
|
||||
test("fetch stays in skill prose (never in the script) and warns on failure", () => {
|
||||
const body = readTmpl();
|
||||
// Match either `git fetch ... ||` or `if ! git fetch ...` shape.
|
||||
expect(body).toMatch(/(?:if !\s+|[^\n]*\|\|\s*)git fetch origin <default>|git fetch origin <default>[^\n]*--quiet 2>\/dev\/null; then/);
|
||||
expect(body).toMatch(/fetch[^\n]*failed[^\n]*offline/);
|
||||
expect(body).toMatch(/_RETRO_GUARD_VERDICT="warn-fetch-failed"/);
|
||||
expect(body).toMatch(/git fetch origin <default> --quiet/);
|
||||
expect(body).toMatch(/RETRO_FETCH: failed[^\n]*offline/);
|
||||
// The script must stay local-reads-only: no fetch/pull/push/clone.
|
||||
const script = readScript();
|
||||
expect(script).not.toMatch(/(^|[;|&`($!]|\s)git(\s+-C\s+\S+)?\s+(push|pull|fetch|clone|ls-remote)\b/m);
|
||||
});
|
||||
|
||||
test("fetch-fail warn is gated by prior verdict check (ordering)", () => {
|
||||
test("fetch failure downgrades BLOCK to proceed (ordering)", () => {
|
||||
const body = readTmpl();
|
||||
const branchCStart = body.indexOf("# Pre-check C: fetch origin");
|
||||
expect(branchCStart).toBeGreaterThan(-1);
|
||||
const branchCSlice = body.slice(branchCStart, branchCStart + 500);
|
||||
expect(branchCSlice).toMatch(/if \[ -z "\$_RETRO_GUARD_VERDICT" \]/);
|
||||
// Rule 1 (skip paths incl. fetch-fail) must be evaluated before rule 2
|
||||
// (BLOCK), and BLOCK must be conditioned on the fetch having succeeded.
|
||||
const skipRule = body.indexOf("the Step 0.5 fetch failed");
|
||||
const blockRule = body.indexOf("Retro window is stale");
|
||||
expect(skipRule).toBeGreaterThan(-1);
|
||||
expect(blockRule).toBeGreaterThan(-1);
|
||||
expect(skipRule).toBeLessThan(blockRule);
|
||||
expect(body).toMatch(/fetch succeeded AND/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#1624 retro guard — branch D: stale-base BLOCK", () => {
|
||||
test("template extracts latest origin/<default> commit date via git log -1 --format=%ci", () => {
|
||||
const body = readTmpl();
|
||||
// The BLOCK check must read the actual latest-commit date so the
|
||||
// disclosure is concrete (not generic).
|
||||
expect(body).toMatch(/git log -1 --format=%ci origin\/<default>/);
|
||||
test("script extracts the latest analyzed-ref commit date via git log -1 --format=%ci", () => {
|
||||
const script = readScript();
|
||||
expect(script).toMatch(/git log -1 --format=%ci/);
|
||||
expect(script).toContain("GUARD_LATEST_COMMIT:");
|
||||
});
|
||||
|
||||
test("BLOCK prose names latest-commit date and instructs user remediation", () => {
|
||||
const body = readTmpl();
|
||||
// The BLOCK message must cite the date AND tell the user how to recover.
|
||||
// "Retro window is stale" is the canonical first line.
|
||||
expect(body).toMatch(/Retro window is stale/);
|
||||
expect(body).toMatch(/git fetch origin <default>/);
|
||||
expect(body).toMatch(/Confirm today's date/);
|
||||
});
|
||||
|
||||
test("BLOCK branch is gated by prior verdict checks (ordering)", () => {
|
||||
test("today comes from the session reminder, never the system clock", () => {
|
||||
const body = readTmpl();
|
||||
const branchDStart = body.indexOf("# Pre-check D:");
|
||||
expect(branchDStart).toBeGreaterThan(-1);
|
||||
const branchDSlice = body.slice(branchDStart, branchDStart + 800);
|
||||
expect(branchDSlice).toMatch(/if \[ -z "\$_RETRO_GUARD_VERDICT" \]/);
|
||||
expect(body).toMatch(/session reminder/);
|
||||
expect(body).toMatch(/NEVER from `date`/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#1624 retro guard — disclosure must reach the narrative", () => {
|
||||
test("template names the skip paths that must carry a disclosure line", () => {
|
||||
test("skip paths carry a disclosure line into the retro output", () => {
|
||||
const body = readTmpl();
|
||||
// The post-bash prose must explicitly tell the model to surface
|
||||
// these reasons in the retro output rather than silently dropping them.
|
||||
expect(body).toMatch(/skip-no-remote/);
|
||||
expect(body).toMatch(/skip-detached/);
|
||||
expect(body).toMatch(/warn-fetch-failed/);
|
||||
// The prose names disclosure + narrative together (either order) so the
|
||||
// retro output is never silently confidently-wrong.
|
||||
// The prose ties disclosure + narrative together so the retro output is
|
||||
// never silently confidently-wrong on offline/local-only runs.
|
||||
expect(body).toMatch(/offline run, window not freshness-verified/);
|
||||
expect(body).toMatch(/(?:disclosure[\s\S]{0,200}narrative|narrative[\s\S]{0,200}disclosure)/);
|
||||
});
|
||||
|
||||
test("non-default analyzed ref is disclosed (RETRO_REF)", () => {
|
||||
const body = readTmpl();
|
||||
expect(body).toMatch(/RETRO_REF/);
|
||||
const script = readScript();
|
||||
expect(script).toContain("RETRO_REF:");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user