feat(practice): run practice jobs on the code runner with one stored result per run

This commit is contained in:
shira committed 2026-10-11 19:31:08 +03:00
1 parent 9385b2ddd4
commit 9344228e84
17 files changed
+1010 -35

No files matched your search

@@ -231,7 +231,7 @@ func TestAssessmentPracticeQueue(t *testing.T) {
// The crashed worker coming back late cannot add a second result.
lateStore := postgresadapter.NewPracticeJobStore(newPoolFor(ctx, t, harness.databaseURL))
held, err := lateStore.Complete(ctx, stale, domain.PracticeRunResult{Outcome: domain.PracticeOutcomeWrongAnswer, Groups: []domain.PracticeGroupOutcome{}})
held, err := lateStore.Complete(ctx, stale, uuid.New(), domain.PracticeRunResult{Outcome: domain.PracticeOutcomeWrongAnswer, Groups: []domain.PracticeGroupOutcome{}})
if err != nil || held {
t.Fatalf("late completion held = %v, error %v; want refused", held, err)
}
@@ -275,13 +275,13 @@ func TestAssessmentPracticeQueue(t *testing.T) {
// practiceQueueRig builds workers on the test clock and the fake runner.
type practiceQueueRig struct {
pool *pgxpool.Pool
runner *fakePracticeRunner
runner outbound.CodeRunner
clock *practiceQueueClock
logger *slog.Logger
worker *practicequeue.Worker
}
func newPracticeQueueRig(t *testing.T, pool *pgxpool.Pool, runner *fakePracticeRunner, clock *practiceQueueClock) *practiceQueueRig {
func newPracticeQueueRig(t *testing.T, pool *pgxpool.Pool, runner outbound.CodeRunner, clock *practiceQueueClock) *practiceQueueRig {
t.Helper()
rig := &practiceQueueRig{pool: pool, runner: runner, clock: clock, logger: slog.New(slog.DiscardHandler)}
rig.worker = rig.newWorker(t)
@@ -438,7 +438,7 @@ func (runner *fakePracticeRunner) Poll(_ context.Context, request outbound.CodeR
func (runner *fakePracticeRunner) statusLocked(run *fakePracticeRun) outbound.CodeRunStatus {
if runner.holding && !run.finished {
return outbound.CodeRunStatus{State: outbound.CodeRunRunning, RunID: "fake"}
return outbound.CodeRunStatus{State: outbound.CodeRunRunning, RunID: fakeRunnerRunID(run.request.Key)}
}
run.finished = true
result := outbound.CodeRunResult{Outcome: outbound.CodeOutcomeAccepted, Duration: 10 * time.Millisecond}
@@ -452,7 +452,13 @@ func (runner *fakePracticeRunner) statusLocked(run *fakePracticeRun) outbound.Co
}
result.Groups = append(result.Groups, groupResult)
}
return outbound.CodeRunStatus{State: outbound.CodeRunFinished, RunID: "fake", Result: &result}
return outbound.CodeRunStatus{State: outbound.CodeRunFinished, RunID: fakeRunnerRunID(run.request.Key), Result: &result}
}
// fakeRunnerRunID is a stable run ID per run key, as the real runner client
// derives one.
func fakeRunnerRunID(key outbound.CodeRunKey) string {
return uuid.NewSHA1(key.SubmissionID, []byte{byte(key.Generation)}).String()
}
// hold keeps new and unfinished runs running until it is turned off.