Keep site jobs across restarts, meter Claude spend, harden admin routes
Test and publish the site / test (push) Successful in 2m15s
Test and publish the site / publish (push) Successful in 9m5s

- 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:
2026-10-23 22:10:01 +01:00
co-authored by Claude Opus 5.5
parent 7638d88570
commit cae5ec8e5a
42 changed files with 1849 additions and 264 deletions
-34
View File
@@ -105,37 +105,3 @@ func TestGenerate(t *testing.T) {
t.Error("System is missing the rules it shares with concepts")
}
}
func TestJobsOneAtATime(t *testing.T) {
var j Jobs
if s := j.Get("a"); s.State != Idle {
t.Fatalf("fresh state = %q, want idle", s.State)
}
release := make(chan struct{})
if !j.Start("a", func() error { <-release; return nil }) {
t.Fatal("first start refused")
}
if j.Start("a", func() error { return nil }) {
t.Fatal("second start while running accepted")
}
if !j.Start("b", func() error { return context.Canceled }) {
t.Fatal("another problem's job refused")
}
close(release)
wait := func(name string) Status {
for range 200 {
if s := j.Get(name); s.State != Running {
return s
}
time.Sleep(5 * time.Millisecond)
}
t.Fatalf("%s still running", name)
return Status{}
}
if s := wait("a"); s.State != Done || s.Finished == nil {
t.Errorf("a = %+v, want done", s)
}
if s := wait("b"); s.State != Failed || s.Error != context.Canceled.Error() {
t.Errorf("b = %+v, want the error", s)
}
}