Keep site jobs across restarts, meter Claude spend, harden admin routes
- internal/jobs replaces explain.Jobs: one registry for every kind of background job, with records in DATA_DIR/jobs. A job's draft is written before its commit, so a failed commit can be saved again (POST /jobs/<kind>/<key>/save) and a restart mid-commit resumes it, without paying Claude twice. - Graceful shutdown: SIGTERM stops new jobs and waits SHUTDOWN_GRACE for running ones while still serving the pages that poll them. - internal/usage records every Claude call's tokens and estimated cost in DATA_DIR/usage.jsonl; CLAUDE_MONTHLY_BUDGET refuses new jobs (429) once a month reaches it. The stats page shows the admin the spend. - auth.SameOrigin refuses cross-origin writes to admin routes. - The LeetCode importer runs the clone's script without the server's secrets in its environment. - A sync that leaves HEAD where it was skips the re-index. - docs_test.go checks README's route table against the routes, and the CLI page against the root README's commands. - The repo is going private: Gitea links on the site are admin-only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
"adam-french.co.uk/usaco-site/internal/claude"
|
||||
"adam-french.co.uk/usaco-site/internal/evaluate"
|
||||
"adam-french.co.uk/usaco-site/internal/explain"
|
||||
"adam-french.co.uk/usaco-site/internal/jobs"
|
||||
)
|
||||
|
||||
// fakeEvaluator flags line 1 of whatever it is shown, or fails.
|
||||
@@ -45,7 +45,7 @@ func waitEvaluate(t *testing.T, r *gin.Engine, name string) evalStatus {
|
||||
for range 400 {
|
||||
var s evalStatus
|
||||
json.Unmarshal(do(r, "GET", "/usaco/api/problems/"+name+"/evaluate", "", true).Body.Bytes(), &s)
|
||||
if s.State != explain.Running {
|
||||
if s.State != jobs.Running {
|
||||
return s
|
||||
}
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
@@ -91,7 +91,7 @@ func TestEvaluateRunsTheTestsAndCommitsNothing(t *testing.T) {
|
||||
t.Fatalf("evaluate = %d %s", rec.Code, rec.Body)
|
||||
}
|
||||
s := waitEvaluate(t, r, "moocast")
|
||||
if s.State != explain.Done || s.Result == nil {
|
||||
if s.State != jobs.Done || s.Result == nil {
|
||||
t.Fatalf("job = %+v", s)
|
||||
}
|
||||
ev := s.Result
|
||||
@@ -124,7 +124,7 @@ func TestEvaluateWithoutARunner(t *testing.T) {
|
||||
// A runner that fails costs the verdicts, not the evaluation.
|
||||
fr.err = errors.New("runner down")
|
||||
do(r, "POST", "/usaco/api/problems/moocast/evaluate", evalBody, true)
|
||||
if s := waitEvaluate(t, r, "moocast"); s.State != explain.Done || s.Result.Tests != "The tests were not run: the code runner failed." {
|
||||
if s := waitEvaluate(t, r, "moocast"); s.State != jobs.Done || s.Result.Tests != "The tests were not run: the code runner failed." {
|
||||
t.Fatalf("with a failing runner = %+v", s)
|
||||
}
|
||||
|
||||
@@ -134,13 +134,13 @@ func TestEvaluateWithoutARunner(t *testing.T) {
|
||||
}
|
||||
do(r, "POST", "/usaco/api/problems/moocast/evaluate", evalBody, true)
|
||||
s := waitEvaluate(t, r, "moocast")
|
||||
if s.State != explain.Done || !strings.Contains(fc.user, "the code runner is not configured") {
|
||||
if s.State != jobs.Done || !strings.Contains(fc.user, "the code runner is not configured") {
|
||||
t.Fatalf("with no runner = %+v\n%s", s, fc.user)
|
||||
}
|
||||
|
||||
fc.fail = true
|
||||
do(r, "POST", "/usaco/api/problems/moocast/evaluate", evalBody, true)
|
||||
if s := waitEvaluate(t, r, "moocast"); s.State != explain.Failed || s.Error != "Claude declined to answer" || s.Result != nil {
|
||||
if s := waitEvaluate(t, r, "moocast"); s.State != jobs.Failed || s.Error != "Claude declined to answer" || s.Result != nil {
|
||||
t.Fatalf("a failed evaluation = %+v", s)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user