r/codereview • u/SAIIDZ1 • 8h ago
javascript Review my verdict logic: when should a verification check be allowed to block a merge?
Context, honestly stated: I'm the founder of a small dev-tool (SolveLang) and this is the verdict module from the GitHub check we just shipped to production. It decides whether a pull request gets a red or green verification check. I'm posting the code for review, not pitching — no links. I want the design attacked.
The check grades evidence about a PR (policy evaluation, the head's own CI state, required checks) into verified / failed / unverified. This module turns that into a blocking decision. The design rule I started from: only *failed* evidence may block — "unverified" means "not established," and blocking on it would block nearly every PR.
```js
// What blocks (each is a *failed* evidence state, never a mere
// unverified one):
// 1. the PR Gate policy evaluation failed;
// 2. the PR Gate route failed or did not run (blast-radius evidence
// unusable — the receipt records the route as a failed finding);
// 3. the head's own CI has failing or timed-out check runs;
// 4. a config-named required check is absent, unfinished, or not
// successful on the head.
export function computeBlocking({ gateRoute, checkRuns, requiredChecks, ownCheckName }) {
const reasons = [];
if (gateRoute?.status === "failed") {
reasons.push(
"PR Gate route failed — blast-radius and policy evidence is unusable (the receipt records this as a failed finding)."
);
} else if (gateRoute?.status === "not-run") {
reasons.push("PR Gate route was not run — blast-radius evidence was not produced.");
} else if (gateRoute?.status === "ran") {
const summary = gateRoute.summary;
const failedRules = (summary?.policyVerdicts ?? [])
.filter((verdict) => verdict.status === "fail")
.map((verdict) => verdict.rule);
if (summary && summary.policyPassed === false && failedRules.length > 0) {
reasons.push(`PR Gate policy failed: ${failedRules.join(", ")}.`);
}
if (summary && summary.integrityVerified === false) {
reasons.push("Solve Graph integrity did not verify — the blast-radius output is not relied on.");
}
}
const others = (checkRuns ?? []).filter((run) => run.name !== ownCheckName);
const failing = others.filter(
(run) => run.conclusion === "failure" || run.conclusion === "timed_out"
);
if (failing.length > 0) {
reasons.push(
`Head CI has failing check run(s): ${failing.map((run) => `${run.name} (${run.conclusion})`).join(", ")}.`
);
}
for (const name of requiredChecks ?? []) {
const run = others.find((candidate) => candidate.name === name);
if (!run) {
reasons.push(`Required check not present on the head: ${name}.`);
} else if (run.status !== "completed") {
reasons.push(`Required check not completed: ${name} (${run.status}).`);
} else if (run.conclusion !== "success") {
reasons.push(`Required check not successful: ${name} (${run.conclusion ?? "no conclusion"}).`);
}
}
return { blocked: reasons.length > 0, reasons };
}
```
Three decisions I specifically want challenged:
- **Case 2 bothers me.** If *our* gate route fails to run, the PR blocks in enforce mode — that's the author's PR going red because our tool broke, not because their code failed. I kept it because silently passing when evidence is missing felt dishonest. Is fail-closed right here, or should tool failure be neutral-with-a-loud-warning?
- **In report-only mode the check concludes "success" even when blocking evidence exists** (the title and summary state the evidence plainly). That mirrors how our PR Gate Action behaves, but is a green check with "blocking evidence found" in the title honest — or is it exactly the kind of green-washing that makes people distrust checks?
- **A malformed repo config falls back to defaults (report-only) and just says so in the summary.** A typo can silently downgrade a team's enforce mode to advisory. Should config defects themselves block?
Roast away — especially if the whole "only failed evidence blocks" premise is wrong.