mise ~/.config/mise/config.toml tools: crush@0.91.0

feat(api): add /admin/solved endpoint and commit source handling
This commit is contained in:
Prad Nukala
2026-08-25 15:43:21 -04:00
parent aba3d9b18b
commit e4de74c935
4 changed files with 99 additions and 12 deletions
+26 -3
View File
@@ -242,16 +242,25 @@ export interface LogOutcome {
/**
* Record an attempt and move the ladder. Ladder semantics live here and only
* here — email one-taps, webhook /done lines, and gate scoring all converge.
* here — email one-taps, webhook /done lines, gate scoring, and solutions
* landing in work/ all converge.
*
* Email idempotency comes from the partial unique index on
* (lc_number, date, kind) WHERE source='email': a replayed link inserts
* nothing and must not touch the ladder. Webhook corrections (pass then fail
* on the same day) remain legal — every webhook attempt appends.
* on the same day) remain legal — every webhook attempt appends. Commit
* idempotency needs no index: a commit records a FIRST solve only, so the
* stage check below turns every re-push into a no-op.
*/
export async function logAttempt(
db: D1Database,
opts: { lc: number; date: string; result: Result; source: "email" | "webhook"; gate?: boolean },
opts: {
lc: number;
date: string;
result: Result;
source: "email" | "webhook" | "commit";
gate?: boolean;
},
): Promise<LogOutcome> {
const p = await getProblem(db, opts.lc);
const nothing: LogOutcome = {
@@ -266,6 +275,20 @@ export async function logAttempt(
duplicate: false,
};
if (!p) return { ...nothing, error: `LC ${opts.lc} is not in the curriculum` };
// A commit only ever reports a first solve: pushing the file again — or the
// reconciler re-sending the whole solved set — must never move the ladder,
// and must never wake a retired problem. Reviews come from the digest tap,
// a /done comment, or a gate.
if (opts.source === "commit" && p.stage !== "new") {
return {
...nothing,
title: p.title,
stage: p.stage,
next_review: p.next_review,
issue: p.issue,
duplicate: true,
};
}
if (p.stage === "retired") {
return { ...nothing, title: p.title, issue: p.issue, error: `LC ${opts.lc} is already retired` };
}