Skip to content

Commit 919bcc1

Browse files
committed
fix(review): [R20 S4] fail loud on unknown preset:<name> in riskTierPathTokens (cubic + harness-bot P2)
Two bots on PR #1028 flagged the same silent-failure: a typo in a `preset:<name>` entry (e.g. `preset:finop` instead of `preset:finops`) compiled to an empty token list; then `if (tokens.length === 0) continue` dropped the category with no error. The user's opt-in for a risk-promotion category quietly did nothing — exactly the safety invariant this PR is meant to guarantee. Fix: `compilePathTokenResolver` now throws on an unknown preset name before assembling the resolver. Error message names the offending category, the typo, and the shipped preset list so the reader has a fix pointer: Error: riskTierPathTokens.finops: unknown preset 'finop'. Known presets: finops. Configure a bare token list (e.g. ['card', 'pan']) instead if you want a custom category. The shipped preset list is small and stable, so an unknown name is almost certainly a typo, not a forward reference. Fail at review-start means the misconfiguration is caught immediately, not discovered when a real high-risk PR slips through. Tests: `unknown preset name throws with the known-list in the message` asserts throw on `preset:finop`, throw when a typo is mixed with valid tokens, and that the known preset (`preset:finops`) still resolves promotion correctly on `mrt_cost_daily.sql`. 111/111 tests in review.test.ts pass.
1 parent 9b2c024 commit 919bcc1

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎packages/opencode/src/altimate/review/risk-tier.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,23 @@ export function compilePathTokenResolver(
123123
if (entry.startsWith("preset:")) {
124124
const name = entry.slice("preset:".length)
125125
const preset = RISK_TOKEN_PRESETS[name]
126-
if (preset) tokens.push(...preset)
126+
// Unknown preset name is almost certainly a typo (e.g.
127+
// `preset:finop` instead of `preset:finops`); the shipped list is
128+
// small and stable. Silently dropping the entry means the user's
129+
// opt-in for a risk-promotion category quietly does nothing —
130+
// the exact safety invariant this PR exists to guarantee. Fail
131+
// loud instead so the misconfiguration is caught at review
132+
// start, not discovered when a real high-risk PR slips through
133+
// (cubic-review P2 + altimate-harness-bot on PR #1028).
134+
if (!preset) {
135+
const known = Object.keys(RISK_TOKEN_PRESETS).sort().join(", ") || "(none shipped)"
136+
throw new Error(
137+
`riskTierPathTokens.${category}: unknown preset '${name}'. ` +
138+
`Known presets: ${known}. Configure a bare token list (e.g. ` +
139+
`['card', 'pan']) instead if you want a custom category.`,
140+
)
141+
}
142+
tokens.push(...preset)
127143
} else {
128144
tokens.push(entry)
129145
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,29 @@ describe("risk-tier", () => {
812812
expect(r.reasons.join(" ")).toContain("high-risk token category 'finops'")
813813
})
814814

815+
test("R20 S4: high-risk token — unknown preset name throws with the known-list in the message", () => {
816+
// cubic-review P2 + altimate-harness-bot on PR #1028 — a typo in a
817+
// `preset:<name>` entry (e.g. `preset:finop` instead of `preset:finops`)
818+
// must not silently no-op the category. Fail loud at resolver-build so
819+
// the misconfiguration is caught before any diff is scanned.
820+
expect(() => compilePathTokenResolver({ finops: ["preset:finop"] })).toThrow(/unknown preset 'finop'/)
821+
// The error message lists the known presets so the reader gets a
822+
// fix pointer rather than "unknown, good luck".
823+
try {
824+
compilePathTokenResolver({ finops: ["preset:finop"] })
825+
throw new Error("expected throw")
826+
} catch (e: any) {
827+
expect(String(e.message)).toContain("finops")
828+
}
829+
// A category can mix a typo with valid tokens — the typo still fails,
830+
// and the resolver-build never returns a partially-broken resolver.
831+
expect(() => compilePathTokenResolver({ finops: ["cost", "preset:finop", "billing"] })).toThrow(/preset 'finop'/)
832+
// A known preset still works.
833+
const ok = compilePathTokenResolver({ finops: ["preset:finops"] })
834+
expect(ok).toBeDefined()
835+
expect(ok!("models/marts/mrt_cost_daily.sql")).toBe("finops")
836+
})
837+
815838
test("R20 S4: high-risk token — no promotion when no resolver is configured (core is neutral)", () => {
816839
// Same paths that fire above must stay lite when the caller doesn't
817840
// supply a resolver — the reviewer core has zero opinion about which

0 commit comments

Comments
 (0)