Skip to content

Commit 3c2c03c

Browse files
committed
fix(review): [R20 S4] surface pathTokenConfigError in envelope even without --explain-tier (coderabbit review)
Follow-up to `9435bc6f9` (the try/catch around `compilePathTokenResolver` that surfaces a config typo in `tierResult.reasons` instead of crashing). The envelope's `tierReasons` field was gated on `input.explainTier || tierForced` — both default false in a normal `comment`/`gate` run — so the config error I prepended to `tierResult.reasons` was silently stripped when the envelope was built. Net effect on a typoed `.altimate/review.yml`: review ran, no promotion fired, no error appeared in the PR comment. Only a stderr trace no customer ever sees. Exact silent-failure mode the fail-loud fix was supposed to close. Fix: expand the gate to include the config-error case. tierReasons: input.explainTier || tierForced || pathTokenConfigError ? tierReasons : undefined Regression test: `config error surfaces in envelope even WITHOUT --explain-tier` builds a config with `finops: [preset:finop]`, calls `runReview` with `explainTier` unset (default), and asserts `env.tierReasons` still contains both `riskTierPathTokens config invalid` and `unknown preset 'finop'`. 113/113 tests in review.test.ts pass (was 112).
1 parent 9bdd6aa commit 3c2c03c

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

‎packages/opencode/src/altimate/review/orchestrate.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,13 @@ export async function runReview(input: OrchestrateInput): Promise<VerdictEnvelop
14271427
manifestHash: input.manifestHash,
14281428
generatedAt: input.generatedAt,
14291429
degraded,
1430-
tierReasons: input.explainTier || tierForced ? tierReasons : undefined,
1430+
// Include tierReasons whenever `--explain-tier` / `--force-tier` is set,
1431+
// OR when a riskTierPathTokens config error was caught above — the error
1432+
// must surface in the envelope (and downstream PR comment) even in a
1433+
// normal `comment`/`gate` run, otherwise a config typo silently kills
1434+
// the user's opt-in with only a stderr trace they'll never see
1435+
// (coderabbit review, PR #1028 orchestrate.ts:1129).
1436+
tierReasons: input.explainTier || tierForced || pathTokenConfigError ? tierReasons : undefined,
14311437
tierForced: tierForced ? true : undefined,
14321438
tierClassified: tierForced ? classifiedTier : undefined,
14331439
})

‎packages/opencode/test/altimate/review.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,47 @@ describe("risk-tier", () => {
885885
}
886886
})
887887

888+
test("R20 S4: config error surfaces in envelope even WITHOUT --explain-tier (coderabbit review)", async () => {
889+
// coderabbit review on PR #1028 orchestrate.ts:1129 — a normal
890+
// `comment` / `gate` run does NOT set `explainTier`, so the envelope's
891+
// `tierReasons` field is dropped. That silently strips the config
892+
// error, and a user with a typoed `.altimate/review.yml` sees no
893+
// reason WHY their opt-in didn't fire in the PR comment — the whole
894+
// point of the earlier fail-loud fix. The envelope gate now includes
895+
// tierReasons whenever a config error was caught, regardless of
896+
// explain-tier.
897+
const files: ChangedFile[] = [{ path: "models/marts/m.sql", status: "modified", diff: "+select 1\n" }]
898+
const runner: ReviewRunner = {
899+
async check() { return { issues: [], ran: false } },
900+
async detectPii() { return { columns: [] } },
901+
async impact() { return { hasManifest: false, severity: "SAFE", directCount: 0, transitiveCount: 0, testCount: 0 } },
902+
async equivalence() { return { decided: true, equivalent: true } as EquivalenceResult },
903+
async grade() { return { grade: "A", decided: true } },
904+
}
905+
const origWrite = process.stderr.write.bind(process.stderr)
906+
process.stderr.write = (() => true) as typeof process.stderr.write
907+
try {
908+
// NOTE: explainTier is intentionally NOT set here (default false).
909+
const env = await runReview({
910+
changedFiles: files,
911+
config: { ...DEFAULT_REVIEW_CONFIG, riskTierPathTokens: { finops: ["preset:finop"] } } as any,
912+
rubric: DEFAULT_RUBRIC,
913+
mode: "comment",
914+
runner,
915+
getContent: async () => "select 1",
916+
generatedAt: "2026-05-29T00:00:00Z",
917+
})
918+
// Envelope was still produced.
919+
expect(env.verdict).toBeDefined()
920+
// Config error surfaces in tierReasons DESPITE explainTier being unset.
921+
const reasons = (env.tierReasons ?? []).join(" ")
922+
expect(reasons).toContain("riskTierPathTokens config invalid")
923+
expect(reasons).toContain("unknown preset 'finop'")
924+
} finally {
925+
process.stderr.write = origWrite
926+
}
927+
})
928+
888929
test("R20 S4: high-risk token — no promotion when no resolver is configured (core is neutral)", () => {
889930
// Same paths that fire above must stay lite when the caller doesn't
890931
// supply a resolver — the reviewer core has zero opinion about which

0 commit comments

Comments
 (0)