diff --git a/formulas/formulas_test.go b/formulas/formulas_test.go index c277984..b25df5a 100644 --- a/formulas/formulas_test.go +++ b/formulas/formulas_test.go @@ -228,6 +228,38 @@ func TestLibrarianStaleReviewBranchRecoveryStepHasNeedsInvestigationLabelAndGuar } } +// crn-4j0pa: "cairn stale-branches" reports status=error findings (a reviewer +// lookup failure, or ListReviewBranches itself erroring on that branch) with +// the same shape as escalate findings except .reviewer is always empty and +// .error carries the failure text (cmd/branches.go's evaluateBranch never +// sets both). Before this fix the step's jq filter selected only +// status=="escalate", so error findings -- arguably the ones most in need of +// a human's attention, since cairn itself couldn't even evaluate the branch +// -- were silently dropped every cycle instead of filed. +func TestLibrarianStaleReviewBranchRecoveryStepHandlesErrorStatus(t *testing.T) { + f := decodeFormula(t, "mol-cairn-librarian.formula.toml") + s, ok := stepByID(f, "stale-review-branch-recovery") + if !ok { + t.Fatal(`mol-cairn-librarian.formula.toml: no "stale-review-branch-recovery" step found`) + } + + if !strings.Contains(s.Description, `select(.status == "escalate" or .status == "error")`) { + t.Error(`stale-review-branch-recovery: jq filter must widen to select(.status == "escalate" or .status == "error"), or error-status findings are silently dropped and never filed (crn-4j0pa)`) + } + if !strings.Contains(s.Description, `jq -r '.error // empty'`) { + t.Error(`stale-review-branch-recovery: must extract the finding's .error field (error findings have no .reviewer), or the filed bead's body cannot explain what cairn stale-branches itself failed on (crn-4j0pa)`) + } + + notifyIdx := strings.Index(s.Description, `A reminder mail was already sent to`) + guardIdx := strings.Index(s.Description, `if [ -n "$REVIEWER" ]`) + if notifyIdx == -1 { + t.Fatal(`stale-review-branch-recovery: "A reminder mail was already sent to" sentence not found`) + } + if guardIdx == -1 || guardIdx > notifyIdx { + t.Error(`stale-review-branch-recovery: the "A reminder mail was already sent to $REVIEWER" sentence must be guarded behind a non-null-reviewer check (if [ -n "$REVIEWER" ]) placed before it, or error findings (no .reviewer) render "sent to " -- the crn-w4c6-shaped defect this must not reintroduce (crn-4j0pa)`) + } +} + // cairn cull-evict itself is not safely repeatable for the same entry -- // EvictToReviewBranch hard-errors once a proposal is already pending, since // its review branch name is deterministic ("cull/" + entry ID; see diff --git a/formulas/mol-cairn-librarian-rig.formula.toml b/formulas/mol-cairn-librarian-rig.formula.toml index 2c1f303..879863c 100644 --- a/formulas/mol-cairn-librarian-rig.formula.toml +++ b/formulas/mol-cairn-librarian-rig.formula.toml @@ -90,7 +90,8 @@ pass to pass; if it's instead re-cloned fresh every sweep tick, add ENTRY_ID=$(printf '%s' "$finding" | jq -r '.entry_id') TIER=$(printf '%s' "$finding" | jq -r '.tier') AGE_SECONDS=$(printf '%s' "$finding" | jq -r '.age_seconds') - REVIEWER=$(printf '%s' "$finding" | jq -r '.reviewer') + REVIEWER=$(printf '%s' "$finding" | jq -r '.reviewer // empty') + ERROR_TEXT=$(printf '%s' "$finding" | jq -r '.error // empty') EXISTING=$(bd list --label=dim:review-branch,source:cairn-librarian \ --title-contains="on $BRANCH (" --json --no-pager 2>/dev/null | jq -r '.[0].id // empty') @@ -101,20 +102,42 @@ pass to pass; if it's instead re-cloned fresh every sweep tick, add continue fi + # crn-4j0pa: an error-status finding (cairn itself failed to resolve a + # reviewer, or ListReviewBranches errored) never carries .reviewer -- + # cmd/branches.go's evaluateBranch sets exactly one of the two. Guard the + # reviewer-was-already-notified sentence on it instead of interpolating + # unconditionally, or this renders "sent to " for every error finding + # (the crn-w4c6-shaped defect). + if [ -n "$REVIEWER" ]; then + NOTIFY_LINE="A reminder mail was already sent to $REVIEWER on an earlier +cairn stale-branches pass at this same commit, and it is now past the +escalate threshold with no merge and no new commit since." + RESOLVER="$REVIEWER (or another reviewer)" + else + NOTIFY_LINE="cairn stale-branches could not evaluate this branch normally (see error below), so no automatic reviewer reminder was possible." + RESOLVER="a reviewer" + fi + + ERROR_LINE="" + if [ -n "$ERROR_TEXT" ]; then + ERROR_LINE=" + +cairn stale-branches reported an error while evaluating this branch: +$ERROR_TEXT" + fi + NEW_ID=$(bd create \ --title="cairn librarian: stale review branch on $BRANCH ($TIER)" \ --stdin --type=task --priority=3 \ --labels=dim:review-branch,source:cairn-librarian,needs-pm,needs-investigation --silent </dev/null | jq -r '.[0].id // empty') @@ -110,20 +111,42 @@ pass to pass; if it's instead re-cloned fresh every sweep tick, add continue fi + # crn-4j0pa: an error-status finding (cairn itself failed to resolve a + # reviewer, or ListReviewBranches errored) never carries .reviewer -- + # cmd/branches.go's evaluateBranch sets exactly one of the two. Guard the + # reviewer-was-already-notified sentence on it instead of interpolating + # unconditionally, or this renders "sent to " for every error finding + # (the crn-w4c6-shaped defect). + if [ -n "$REVIEWER" ]; then + NOTIFY_LINE="A reminder mail was already sent to $REVIEWER on an earlier +cairn stale-branches pass at this same commit, and it is now past the +escalate threshold with no merge and no new commit since." + RESOLVER="$REVIEWER (or another reviewer)" + else + NOTIFY_LINE="cairn stale-branches could not evaluate this branch normally (see error below), so no automatic reviewer reminder was possible." + RESOLVER="a reviewer" + fi + + ERROR_LINE="" + if [ -n "$ERROR_TEXT" ]; then + ERROR_LINE=" + +cairn stale-branches reported an error while evaluating this branch: +$ERROR_TEXT" + fi + NEW_ID=$(bd create \ --title="cairn librarian: stale review branch on $BRANCH ($TIER)" \ --stdin --type=task --priority=3 \ --labels=dim:review-branch,source:cairn-librarian,needs-pm,needs-investigation --silent <^{commit}"`, not trusted as a transcribed string. | +| 2 | Acceptance criteria met | PASS | Verified directly against crn-4j0pa's full `exit_contract` (5 bullets). Read the actual diff, not just builder/reviewer prose: confirmed jq filter widened in both formula files, `ERROR_TEXT` extraction present, `NOTIFY_LINE`/`RESOLVER` branching guards the reminder sentence on `[ -n "$REVIEWER" ]` in both files identically. Sequencing precondition crn-nc9te (6b45121, PR #126) independently confirmed reachable from origin/main via `git merge-base --is-ancestor` (also visible directly in `git log origin/main`). | +| 3 | Tests pass | PASS | Independently re-run at the deploy commit (detached checkout, clean tree). Pre-flight: this repo's suite has no container/testcontainers dependency (`grep -rl testcontainers\|DOCKER_HOST` empty), so the podman setup step is not applicable here. `go build ./...` exit 0; `go vet ./...` exit 0; `go test ./... -race -count=1` — **7/7 packages ok** (`.`, `cmd`, `formulas`, `internal/cairn`, `internal/critic`, `internal/obslog`, `scripts`), 0 FAIL, 0 SKIP. Diff-owned test mapped by exact name: `TestLibrarianStaleReviewBranchRecoveryStepHandlesErrorStatus` re-run individually (`-run '^...$' -v`) — PASS. 3a (attribute failing tests) not applicable, zero failures anywhere. 3b (policy/lint lane): this repo's only policy lane is the CI `lint` job itself (`golangci-lint run ./...` — confirmed via `.github/workflows/ci.yml`; no separate `ci-pr-policy`-style Makefile target exists here, `Makefile` targets are only `all/build/formulas/test/install/fmt/fmt-check/clean/help`). Run with an isolated `GOLANGCI_LINT_CACHE` (avoiding known cross-session cache contamination on this machine): `golangci-lint run ./...` — 0 issues; `golangci-lint fmt -d ./...` exit 0, no diff; `gofmt -l .` empty. | +| 4 | No open HIGH findings | PASS | crn-lhchy records **no blocking findings** ("No blocking findings. Handing off to deployer."). No open HIGH/blocking finding anywhere in the chain. | +| 5 | Clean tree | PASS | Verified via direct detached checkout of `cacda2f2e3eff9455344abf81a33b4a59aaf17bc^{commit}`; `git status --porcelain` empty. | +| 6 | Clean divergence from main | PASS | `git merge-tree --write-tree origin/main cacda2f2e3eff9455344abf81a33b4a59aaf17bc` → clean merge tree `4b1a3794db0e1c91c0d157a6b967b0f366ff5b49`, exit 0, zero conflicts — **no self-rebase needed**. `origin/main` has advanced by exactly one commit since this branch's fork point (`93c2593`) — the crn-bmy54 merge (`a7f9cdc`, PR #131) — and it does not touch either formula file this diff owns, so the merge stays conflict-free without rebasing. Pre-flight (has the target already merged?): `gh api repos/quad341/cairn/commits/cacda2f2e.../pulls` returned empty — no PR exists for this SHA — and `git merge-base --is-ancestor cacda2f2e... origin/main` confirmed it is NOT already on main. Normal flow applies. | +| 7 | Single feature theme | PASS | `git diff origin/main...cacda2f2e3eff9455344abf81a33b4a59aaf17bc --stat` (correct triple-dot form, symmetric-difference from the merge-base — a plain two-dot diff against current `origin/main` is misleading here since main advanced past the branch's fork point and a two-dot diff spuriously shows those advances "reverted") → exactly 3 files: `formulas/formulas_test.go` (+32), `formulas/mol-cairn-librarian-rig.formula.toml`, `formulas/mol-cairn-librarian.formula.toml` — 94 insertions, 16 deletions, all tightly related to the single fix. Out-of-scope paths (`packs/cairn-loop-orders/orders/cairn-librarian-rig-cooldown.toml`, `TestLibrarianStepsHaveNeedsPmLabelAndGuard`) confirmed untouched. | + +## Verdict: PASS — proceeding to PR. + +## Process notes + +1. **Merge authority — self-merge authorized under the reinstated standing + authorization.** Same basis as `release-gates/crn-bmy54-gate.md` note 1: + mayor ruling `gm-wisp-2yhv7u` (2026-08-19) reinstated deployer self-merge + for quad341/cairn (not covered by `mpr`), and explicitly instructs future + sessions not to re-pause on a bare repeat of the generic "route to + mayor/mpr" boilerplate carried in this formula's own step text. crn-kq7tz's + notes raise nothing beyond that same recycled clause. Proceeding under the + STANDING AUTHORIZATION subject to the reinstatement's four conditions: (1) + gate 7/7 PASS — this table; (2) PR state confirmed via a direct, fresh `gh + pr view --json` read at merge time; (3) CLEAN/MERGEABLE with both required + checks (`build-test`, `lint`) COMPLETED/SUCCESS; (4) no `--auto` arm — + plain `gh pr merge --squash --delete-branch` only (per mayor's + `gm-wisp-fvdoja` addendum), then independently verified. + +2. **Pre-flight (target-already-merged check) run before criterion 6**, per + the formula's own ordering requirement (ga-xykek3 incident). No PR existed + for the deploy SHA and it is not yet an ancestor of `origin/main` — normal + flow, not reconciliation. + +3. **SHA integrity:** the deploy commit was independently re-resolved via + `git rev-parse --verify --quiet "^{commit}"` on both the D (deploy + bead metadata) and R (review bead metadata) sides before comparison, never + trusted as an eyeballed or transcribed string. + +4. **Two-dot vs. triple-dot diff pitfall (recorded for future gate + sessions):** a first pass at criterion 7 used `git diff origin/main + cacda2f2e...` (two-dot) and produced an alarming diffstat showing large + deletions across unrelated files (`internal/cairn/entry.go`, + `release-gates/crn-bmy54-gate.md`, etc.) — these were `origin/main`'s own + advances past this branch's fork point being spuriously shown as + "reverted," not real changes in this diff. Re-run with the triple-dot form + (`origin/main...cacda2f2e...`, symmetric difference from the merge-base) + immediately resolved to the correct, narrow 3-file diffstat matching the + reviewer's own count. Worth a formula-text callout if this recurs.