Run and lint solutions on the site
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]>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
// Command usacosite serves the USACO practice log at /usaco/: the problems
|
||||
// from adamf/usaco on the site's Gitea, their solutions and tests, and a few
|
||||
// admin edits (problem link, notes, statement, status), Claude-written
|
||||
// explanations and reviews of recorded explanations that it commits back to
|
||||
// git.
|
||||
// admin edits (problem link, notes, statement, status, the solution itself
|
||||
// on the solve page), Claude-written explanations and reviews of recorded
|
||||
// explanations that it commits back to git.
|
||||
//
|
||||
// It is built to sit behind adam-french.co.uk's nginx and borrow its login
|
||||
// (internal/auth), like the job tracker. There is no database: the server
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"adam-french.co.uk/usaco-site/internal/claude"
|
||||
"adam-french.co.uk/usaco-site/internal/handlers"
|
||||
"adam-french.co.uk/usaco-site/internal/repo"
|
||||
"adam-french.co.uk/usaco-site/internal/runner"
|
||||
"adam-french.co.uk/usaco-site/internal/transcribe"
|
||||
)
|
||||
|
||||
@@ -113,6 +114,16 @@ func main() {
|
||||
log.Println("[review] S3_ENDPOINT is not set: recordings are not kept")
|
||||
}
|
||||
|
||||
// RUNNER
|
||||
// Optional: the solve page runs and lints code through the sandboxed
|
||||
// runner service. Without it the page still edits and saves code.
|
||||
if u := os.Getenv("RUNNER_URL"); u != "" {
|
||||
srv.Runner = runner.NewClient(u)
|
||||
log.Printf("[runner] code runs on %s", u)
|
||||
} else {
|
||||
log.Println("[runner] RUNNER_URL is not set: running and linting code are off")
|
||||
}
|
||||
|
||||
rp, err := repo.New(repo.Config{
|
||||
Dir: filepath.Join(dataDir, "repo"),
|
||||
Remote: remote,
|
||||
@@ -126,7 +137,7 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
srv.Repo = rp
|
||||
srv.Repo, srv.Dir = rp, rp.Dir()
|
||||
|
||||
// SYNC LOOP
|
||||
// One goroutine does every pull, so webhook bursts coalesce: a trigger
|
||||
|
||||
Reference in New Issue
Block a user