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

+28 -16
View File
@@ -7,6 +7,7 @@ import (
"context"
"fmt"
"log/slog"
"slices"
"strings"
"time"
"unicode/utf8"
@@ -171,9 +172,11 @@ func (j *Judge) evaluate(ctx context.Context, request Request) Result {
if !ok {
return failedRun(request, compile.Outcome, compile)
}
checkers := newCheckerSet(j)
defer checkers.close(ctx)
result := Result{Outcome: Accepted, Compile: compile, Groups: make([]GroupResult, 0, len(request.Groups))}
for _, group := range request.Groups {
groupResult := j.evaluateGroup(ctx, language, box, request.Limits, group)
groupResult := j.evaluateGroup(ctx, language, box, request.Limits, group, checkers)
if groupResult.Outcome == InfrastructureFailure {
return failedRun(request, InfrastructureFailure, compile)
}
@@ -185,31 +188,39 @@ func (j *Judge) evaluate(ctx context.Context, request Request) Result {
return result
}
// compile runs the language's compile step. ok is false when no test may run.
// compile runs the language's compile steps. ok is false when no test may
// run.
func (j *Judge) compile(ctx context.Context, language Language, box *sandbox.Box) (*CompileResult, bool) {
if len(language.Compile) == 0 {
return nil, true
}
run, err := j.executor.Run(ctx, sandbox.Spec{Argv: language.Compile, BoxDir: box.Dir()}, language.CompileLimits)
if err != nil {
j.logger.ErrorContext(ctx, "compile step failed in the sandbox", slog.Any("error", err))
return &CompileResult{Outcome: InfrastructureFailure}, false
for _, step := range language.Compile {
run, err := j.executor.Run(ctx, sandbox.Spec{
Argv: step.Argv,
Mounts: box.Mounts(true),
Env: language.CompileEnv,
WorkDir: step.WorkDir,
}, language.CompileLimits)
if err != nil {
j.logger.ErrorContext(ctx, "compile step failed in the sandbox", slog.Any("error", err))
return &CompileResult{Outcome: InfrastructureFailure}, false
}
if run.Termination != sandbox.TerminationNone || run.ExitCode != 0 || run.Signal != 0 {
return &CompileResult{Outcome: CompileError, Diagnostic: compileDiagnostic(run)}, false
}
}
if run.Termination == sandbox.TerminationNone && run.ExitCode == 0 && run.Signal == 0 {
return &CompileResult{Outcome: Accepted}, true
}
diagnostic := compileDiagnostic(run)
return &CompileResult{Outcome: CompileError, Diagnostic: diagnostic}, false
return &CompileResult{Outcome: Accepted}, true
}
func compileDiagnostic(run sandbox.Result) string {
if run.Termination != sandbox.TerminationNone {
return "The compile step exceeded its " + strings.ReplaceAll(string(run.Termination), "_", " ") + " limit."
}
return excerpt(run.Stderr, maxCompileDiagnostic)
// The Go compiler reports errors on stdout, the Python check on stderr.
return excerpt(append(slices.Clone(run.Stdout), run.Stderr...), maxCompileDiagnostic)
}
func (j *Judge) evaluateGroup(ctx context.Context, language Language, box *sandbox.Box, limits Limits, group Group) GroupResult {
func (j *Judge) evaluateGroup(ctx context.Context, language Language, box *sandbox.Box, limits Limits, group Group, checkers *checkerSet) GroupResult {
result := GroupResult{
ID: group.ID,
Visibility: group.Visibility,
@@ -217,9 +228,9 @@ func (j *Judge) evaluateGroup(ctx context.Context, language Language, box *sandb
Total: len(group.Tests),
Tests: make([]TestResult, 0, len(group.Tests)),
}
check, err := checker.New(group.Checker)
check, err := checkers.get(ctx, group.Checker)
if err != nil {
j.logger.ErrorContext(ctx, "group has an unknown checker", slog.Any("error", err))
j.logger.ErrorContext(ctx, "group checker is not available", slog.Any("error", err))
result.Outcome = InfrastructureFailure
return result
}
@@ -254,7 +265,8 @@ func (j *Judge) evaluateTest(
run, err := j.executor.Run(ctx, sandbox.Spec{
Argv: language.Run,
Stdin: []byte(test.Input),
BoxDir: box.Dir(),
Mounts: box.Mounts(false),
Env: language.RunEnv,
}, sandbox.Limits{
CPUTime: limits.TimeLimit,
WallTime: wallTimeLimit(limits.TimeLimit),