A new admin-only solve page, /p/<name>/solve, edits a problem's code in
C++ or Python (a dropdown switches between them), runs it on custom
input or against the saved tests with per-test verdicts (AC, WA, RE,
TLE, unchecked) and compile errors, marks lint diagnostics in the
editor, and saves the code back as a commit ("Edit <name>"). Drafts
stay in the browser per problem and language until saved. LeetCode
problems are C++ only, since their tests run through driver.h.
Code never runs in the site, which holds the Claude, Gitea and S3
secrets. A separate runner service (cmd/usacorunner, Dockerfile.runner)
does it in a container meant to have no environment, an internal-only
network, a read-only root apart from /tmp, and memory, CPU and pids
limits, with tini to reap orphans. Runs copy the CLI: the same g++
flags with -DLOCAL and the repo's headers, <io>.in on disk and on
stdin, <io>.out or stdout as the output, and usaco test's comparison.
Unlike the CLI they have CPU, memory, file and wall-clock limits.
C++ lint is g++'s warnings plus clang-tidy with a new .clang-tidy
(bugprone, performance and a few readability checks; template.cpp is
clean). Python lint is a syntax check plus ruff. template.py is the
Python starter, with a stdio() helper like template.rs's.
CI builds, smoke-tests and rolls out the runner image before the site.
The web_server stack needs a usaco-runner service before that rollout
can succeed.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
3.1 KiB
CLAUDE.md
Guidance for Claude Code in site/. README.md has the full picture (routes, git sync, deployment).
Commands
make check # go vet ./... && go test ./..., then a vite build of web/ into a temp dir
make dev # docker compose up --build: this checkout's problems, AUTH_MODE=dev, GIT_PUSH=false
cd web && npm run dev # SPA hot reload; proxies /usaco/api to localhost:8080
Architecture
One Go binary (cmd/usacosite) that serves a REST API and the built Vue SPA, all under /usaco. It is deployed as one container inside the web_server stack, behind its nginx. It has the same shape as ../job-tracker, from which internal/auth and handlers.SPA were copied.
-
Git is the only store.
internal/repoowns the clone and serializes every git command. A sync is fetch + hard reset (the remote wins).Mutatedoes sync, edit, commit and push, and replays the edit once if the push is rejected. ItsonChangecallback (Server.Reload) rebuilds the index under the same lock. -
The index is an immutable snapshot, swapped in through an
atomic.Pointer. Handlers reads.Index()once per request. -
Visibility is decided server-side. Non-admins see only
solved/, and an unsolved problem is a 404, not a 403.auth.Forwardreturns false for a request with no cookies without a network call.problem.md(the judge's statement) is admin-only even on solved problems. -
Explanations run in the background.
POST /explainstarts a job inexplain.Jobsand returns 202; the job calls Claude (internal/claude, streamed, JSON schema) and commitsexplain.mdthroughMutate. Tests fake Claude withexplain.Askerand the judges withhandlers.Fetcher; nothing ingo testhits the network. -
Recording reviews are the same shape.
POST /reviewtakes a multipart upload and starts a job in its ownexplain.Jobs: transcribe (internal/transcribe, OpenAI-compatible, raw HTTP), measure (Transcript.Metrics), optionally keep the audio (internal/audiostore, S3), have Claude review it (internal/review) and commitreviews/<id>.md. Reviews are admin-only. Tests fake the transcriber and the store withhandlers.Transcriberandhandlers.AudioStore. -
Code runs in a separate service, never in the site. The solve page's run/lint handlers (
handlers/run.go) read the problem from the clone (Server.Dir, not the index, which truncates) and post tocmd/usacorunnerthroughrunner.Client;internal/runner/types.gois the contract between them. Tests fake it withhandlers.Runner. The runner's own tests run real g++/python3/clang-tidy/ruff and skip whichever is missing.
Conventions
- Comments explain why, not what. Preserve them, and update them when behaviour changes.
- Edits look at the disk. An edit func passed to
Mutatemay run twice, so it must locate the problem withfindOnDisk, never from the index. - Commit subjects match the CLI's (
lib/cmd/done.sh): "Solve " and so on. - The problem layout belongs to the CLI in the repo root (
lib/). When the CLI's layout changes, updateinternal/index.