feat(runner): compile Go and check answers per test group

This commit is contained in:
shira committed 2026-10-11 08:59:29 +03:00
1 parent e95c681165
commit afee564bf4
61 files changed
+2592 -143

No files matched your search

+38 -1
View File
@@ -82,7 +82,7 @@ func startServer(t *testing.T) *testServer {
if err != nil {
t.Fatalf("NewManager: %v", err)
}
supports := func(language string) bool { return language == "python3" }
supports := func(language string) bool { return language == "python3" || language == "go" }
handler := NewHandler(manager, supports, func() bool { return !manager.Draining() }, 3*time.Second, logger)
httpHandler, err := New(handler, testToken, maxBody, logger)
if err != nil {
@@ -233,6 +233,29 @@ func TestSubmitRunIsIdempotentAndAnswersBusy(t *testing.T) {
}
}
func TestSubmitRunAcceptsParameterizedCheckers(t *testing.T) {
t.Parallel()
server := startServer(t)
body := runBody(secretSource)
groups := body["groups"].([]any)
numbers := map[string]any{
"id": "hidden-1", "visibility": "hidden", "checker": map[string]any{"kind": "numbers", "abs_tolerance": 1e-6},
"tests": []any{map[string]any{"id": "t1", "input": "1", "expected_output": "0.5"}},
}
custom := map[string]any{
"id": "hidden-2", "visibility": "hidden",
"checker": map[string]any{"kind": "custom", "program": map[string]any{"language": "python3", "source": "raise SystemExit(0)"}},
"tests": []any{map[string]any{"id": "t1", "input": "1", "expected_output": "1"}},
}
body["groups"] = append(groups, numbers, custom)
body["language"] = "go"
response, decoded := server.do(t, http.MethodPut, runPath(uuid.New()), testToken, body)
if response.StatusCode != http.StatusAccepted {
t.Fatalf("PUT = %d %v, want 202", response.StatusCode, decoded)
}
}
func TestSubmitRunValidatesTheRequest(t *testing.T) {
t.Parallel()
@@ -267,6 +290,20 @@ func TestSubmitRunValidatesTheRequest(t *testing.T) {
t.Fatalf("invalid run ID = %d %v, want 400", response.StatusCode, body)
}
for name, checkerValue := range map[string]map[string]any{
"numbers without tolerance": {"kind": "numbers"},
"exact with tolerance": {"kind": "exact", "abs_tolerance": 0.1},
"custom without program": {"kind": "custom"},
"tokens with program": {"kind": "tokens", "program": map[string]any{"language": "python3", "source": "x"}},
} {
invalid := runBody(secretSource)
invalid["groups"].([]any)[0].(map[string]any)["checker"] = checkerValue
response, body = server.do(t, http.MethodPut, runPath(uuid.New()), testToken, invalid)
if response.StatusCode != http.StatusBadRequest || body["errors"].([]any)[0].(map[string]any)["pointer"] != "/groups/0/checker" {
t.Fatalf("%s = %d %v, want 400 at /groups/0/checker", name, response.StatusCode, body)
}
}
response, body = server.do(t, http.MethodGet, runPath(uuid.New()), testToken, nil)
if response.StatusCode != http.StatusNotFound || body["code"] != "not_found" {
t.Fatalf("unknown run = %d %v, want 404", response.StatusCode, body)