feat(runner): compile Go and check answers per test group
This commit is contained in:
1 parent
e95c681165
commit
afee564bf4
61 files changed
+2592
-143
No files matched your search
+2
-1
@@ -109,7 +109,8 @@ The ML service answers its errors with the same `Problem` schema. Its `ProblemCo
|
||||
- Data. `RunRequest` carries only the language, the source code, the limits, and the test groups; each group has a label, a visibility (`public` or `hidden`), a checker kind, and tests with an input and an expected output. It has no candidate, account, attempt, task, or company field; `scripts/test_runner_contract.py` checks this for every request schema, together with `additionalProperties: false` on every request object.
|
||||
- Idempotency. `PUT /v1/runs/{run_id}` (`SubmitRun`) takes a random UUID from the backend. A new ID with a free slot starts the run and answers 202, the same ID with the same body returns the current state with 200 without running again, and the same ID with a different body answers 422 `idempotency_key_reused`. Bodies are compared by a SHA-256 fingerprint of the decoded request. When every slot is busy or the process is stopping, the answer is 503 `runner_busy` with `Retry-After`; nothing is stored, and the backend keeps the queue.
|
||||
- Result. `GetRun` returns `state` (`running` or `finished`) and, per group, the outcome `accepted`, `wrong_answer`, `compile_error`, `time_limit_exceeded`, `memory_limit_exceeded`, `output_limit_exceeded`, `runtime_error`, or `infrastructure_failure`, the number of passed tests, the CPU time, and the peak memory. `limit` names the limit that stopped a test (`cpu_time`, `wall_time`, `memory`, `output`, `processes`). Only public tests carry a stderr diagnostic; hidden tests never carry program output.
|
||||
- Checker. The current kinds are `exact` (comparison after normalizing CRLF, trailing spaces of lines, and trailing empty lines) and `tokens` (token sequences split on ASCII whitespace). The `Checker` object grows with new `kind` values and optional parameters, such as a float tolerance.
|
||||
- Languages: `python3` and `go`. Go is compiled in a separate phase with its own limits; a compile error gives `compile_error` and no test runs.
|
||||
- A checker is set per group: `exact` (comparison after normalizing CRLF, trailing spaces of lines, and trailing empty lines), `tokens` (token sequences split on ASCII whitespace), `numbers` (like `tokens`, but numbers are equal within `abs_tolerance` or `rel_tolerance`), and `custom` (`program` with the language and source of the task family checker; it runs in nsjail, reads the files input, expected, and actual, and answers with exit status 0 or 1). The server rejects parameters that do not fit the checker kind.
|
||||
- Errors use the api/core `Problem` shape with a runner-specific `ProblemCode` enum: `validation_failed`, `unauthenticated`, `not_found`, `method_not_allowed`, `payload_too_large`, `unsupported_media_type`, `idempotency_key_reused`, `internal`, and `runner_busy`. `scripts/test_runner_contract.py` checks that the shape matches api/core.
|
||||
|
||||
### Identity: sessions, cookie, and CSRF
|
||||
|
||||
+2
-1
@@ -109,7 +109,8 @@ ML-сервис отвечает на ошибки той же схемой `Pro
|
||||
- Данные. `RunRequest` содержит только язык, исходный код, лимиты и группы тестов; у каждой группы есть метка, видимость (`public` или `hidden`), вид checker и тесты с входом и ожидаемым выводом. Полей кандидата, аккаунта, попытки, задания или компании нет; `scripts/test_runner_contract.py` проверяет это для всех схем запросов, а также `additionalProperties: false` у каждого объекта запроса.
|
||||
- Идемпотентность. `PUT /v1/runs/{run_id}` (`SubmitRun`) принимает случайный UUID от backend. Новый ID при свободном слоте запускает прогон и отвечает 202, тот же ID с тем же телом возвращает текущее состояние с 200 без повторного запуска, тот же ID с другим телом дает 422 `idempotency_key_reused`. Тела сравниваются по SHA-256 отпечатку разобранного запроса. Когда все слоты заняты или процесс останавливается, ответ - 503 `runner_busy` с `Retry-After`; ничего не сохраняется, очередь держит backend.
|
||||
- Результат. `GetRun` возвращает `state` (`running` или `finished`) и итог по каждой группе: `accepted`, `wrong_answer`, `compile_error`, `time_limit_exceeded`, `memory_limit_exceeded`, `output_limit_exceeded`, `runtime_error` или `infrastructure_failure`, число пройденных тестов, время CPU и пиковую память. `limit` называет сработавший лимит (`cpu_time`, `wall_time`, `memory`, `output`, `processes`). Диагностика stderr есть только у публичных тестов; у скрытых тестов нет вывода программы.
|
||||
- Checker. Сейчас есть `exact` (сравнение после нормализации CRLF, хвостовых пробелов строк и пустых строк в конце) и `tokens` (последовательности токенов по ASCII-пробелам). Объект `Checker` расширяется новыми `kind` и необязательными параметрами, например допуском для чисел.
|
||||
- Языки: `python3` и `go`. Go компилируется отдельной фазой со своими лимитами; ошибка компиляции дает `compile_error` без запуска тестов.
|
||||
- Checker задается для группы: `exact` (сравнение после нормализации CRLF, хвостовых пробелов строк и пустых строк в конце), `tokens` (последовательности токенов по ASCII-пробелам), `numbers` (как `tokens`, но числа равны в пределах `abs_tolerance` или `rel_tolerance`) и `custom` (`program` с языком и исходником checker семейства заданий; он работает в nsjail, читает файлы input, expected и actual и отвечает кодом выхода 0 или 1). Сервер отклоняет параметры, не подходящие виду checker.
|
||||
- Ошибки используют форму `Problem` из api/core; перечисление `ProblemCode` свое: `validation_failed`, `unauthenticated`, `not_found`, `method_not_allowed`, `payload_too_large`, `unsupported_media_type`, `idempotency_key_reused`, `internal` и `runner_busy`. Совпадение формы с api/core проверяет `scripts/test_runner_contract.py`.
|
||||
|
||||
### Identity: сессии, cookie и CSRF
|
||||
|
||||
@@ -168,9 +168,10 @@ RunRequest:
|
||||
$ref: '#/TestGroup'
|
||||
RunLanguage:
|
||||
type: string
|
||||
description: Language and runtime of the source. `python3` runs the Python 3 interpreter of the runner image with isolated mode and no bytecode writes; a syntax check runs first and fails with compile_error.
|
||||
description: Language and runtime of the source. `python3` runs the Python 3 interpreter of the runner image with isolated mode and no bytecode writes; a syntax check runs first and fails with compile_error. `go` compiles one `package main` file with the Go toolchain of the runner image against a prebuilt standard library (no modules, no cgo, no network) in a separate compile phase with its own limits; a compile or link error is compile_error and no test runs.
|
||||
enum:
|
||||
- python3
|
||||
- go
|
||||
RunLimits:
|
||||
type: object
|
||||
description: Limits applied to every test of the run.
|
||||
@@ -234,21 +235,55 @@ TestVisibility:
|
||||
- hidden
|
||||
Checker:
|
||||
type: object
|
||||
description: How the standard output of a test is compared with `expected_output`. Future kinds, such as a float tolerance or a custom checker, add a `kind` value and their own optional parameters to this object.
|
||||
description: How the standard output of a test is compared with `expected_output`. `numbers` requires `abs_tolerance`, `rel_tolerance`, or both; `custom` requires `program`. Other kinds take no parameter. New kinds add a `kind` value and their own optional parameters.
|
||||
additionalProperties: false
|
||||
required:
|
||||
- kind
|
||||
properties:
|
||||
kind:
|
||||
$ref: '#/CheckerKind'
|
||||
abs_tolerance:
|
||||
type: number
|
||||
format: double
|
||||
minimum: 0
|
||||
maximum: 1000000000
|
||||
description: Largest accepted absolute difference of two numeric tokens.
|
||||
rel_tolerance:
|
||||
type: number
|
||||
format: double
|
||||
minimum: 0
|
||||
maximum: 1
|
||||
description: Largest accepted difference of two numeric tokens relative to the expected value.
|
||||
program:
|
||||
$ref: '#/CheckerProgram'
|
||||
CheckerProgram:
|
||||
type: object
|
||||
description: 'Checker program of the task family. It runs in the sandbox with the same isolation as the solution and fixed limits of its own (5 s CPU, 256 MiB). Its arguments are the paths of three read-only files: the test input, the expected output, and the actual output. Exit status 0 accepts, 1 rejects, and anything else, a signal, or a limit is a checker failure, which makes the run infrastructure_failure. Its own output is discarded and never returned.'
|
||||
additionalProperties: false
|
||||
required:
|
||||
- language
|
||||
- source
|
||||
properties:
|
||||
language:
|
||||
$ref: '#/RunLanguage'
|
||||
source:
|
||||
type: string
|
||||
minLength: 1
|
||||
maxLength: 65536
|
||||
CheckerKind:
|
||||
type: string
|
||||
description: '- exact: both texts are equal after replacing CRLF with LF, removing trailing spaces and tabs at the end of each line, and removing trailing empty lines.
|
||||
|
||||
- tokens: both texts split on ASCII whitespace give the same sequence of tokens.'
|
||||
- tokens: both texts split on ASCII whitespace give the same sequence of tokens.
|
||||
|
||||
- numbers: like tokens, but two finite numeric tokens are equal when their difference is within abs_tolerance or within rel_tolerance times the expected value; other tokens must be equal.
|
||||
|
||||
- custom: the checker program of the task family decides in the sandbox.'
|
||||
enum:
|
||||
- exact
|
||||
- tokens
|
||||
- numbers
|
||||
- custom
|
||||
TestCase:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
|
||||
@@ -37,9 +37,14 @@ schemas:
|
||||
description: >-
|
||||
Language and runtime of the source. `python3` runs the Python 3
|
||||
interpreter of the runner image with isolated mode and no bytecode
|
||||
writes; a syntax check runs first and fails with compile_error.
|
||||
writes; a syntax check runs first and fails with compile_error. `go`
|
||||
compiles one `package main` file with the Go toolchain of the runner
|
||||
image against a prebuilt standard library (no modules, no cgo, no
|
||||
network) in a separate compile phase with its own limits; a compile
|
||||
or link error is compile_error and no test runs.
|
||||
enum:
|
||||
- python3
|
||||
- go
|
||||
RunLimits:
|
||||
type: object
|
||||
description: Limits applied to every test of the run.
|
||||
@@ -120,22 +125,64 @@ schemas:
|
||||
type: object
|
||||
description: >-
|
||||
How the standard output of a test is compared with `expected_output`.
|
||||
Future kinds, such as a float tolerance or a custom checker, add a
|
||||
`kind` value and their own optional parameters to this object.
|
||||
`numbers` requires `abs_tolerance`, `rel_tolerance`, or both; `custom`
|
||||
requires `program`. Other kinds take no parameter. New kinds add a
|
||||
`kind` value and their own optional parameters.
|
||||
additionalProperties: false
|
||||
required:
|
||||
- kind
|
||||
properties:
|
||||
kind:
|
||||
$ref: "#/schemas/CheckerKind"
|
||||
abs_tolerance:
|
||||
type: number
|
||||
format: double
|
||||
minimum: 0
|
||||
maximum: 1000000000
|
||||
description: Largest accepted absolute difference of two numeric tokens.
|
||||
rel_tolerance:
|
||||
type: number
|
||||
format: double
|
||||
minimum: 0
|
||||
maximum: 1
|
||||
description: >-
|
||||
Largest accepted difference of two numeric tokens relative to the
|
||||
expected value.
|
||||
program:
|
||||
$ref: "#/schemas/CheckerProgram"
|
||||
CheckerProgram:
|
||||
type: object
|
||||
description: >-
|
||||
Checker program of the task family. It runs in the sandbox with the
|
||||
same isolation as the solution and fixed limits of its own (5 s CPU,
|
||||
256 MiB). Its arguments are the paths of three read-only files: the
|
||||
test input, the expected output, and the actual output. Exit status 0
|
||||
accepts, 1 rejects, and anything else, a signal, or a limit is a
|
||||
checker failure, which makes the run infrastructure_failure. Its own
|
||||
output is discarded and never returned.
|
||||
additionalProperties: false
|
||||
required:
|
||||
- language
|
||||
- source
|
||||
properties:
|
||||
language:
|
||||
$ref: "#/schemas/RunLanguage"
|
||||
source:
|
||||
type: string
|
||||
minLength: 1
|
||||
maxLength: 65536
|
||||
CheckerKind:
|
||||
type: string
|
||||
description: |-
|
||||
- exact: both texts are equal after replacing CRLF with LF, removing trailing spaces and tabs at the end of each line, and removing trailing empty lines.
|
||||
- tokens: both texts split on ASCII whitespace give the same sequence of tokens.
|
||||
- numbers: like tokens, but two finite numeric tokens are equal when their difference is within abs_tolerance or within rel_tolerance times the expected value; other tokens must be equal.
|
||||
- custom: the checker program of the task family decides in the sandbox.
|
||||
enum:
|
||||
- exact
|
||||
- tokens
|
||||
- numbers
|
||||
- custom
|
||||
TestCase:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
|
||||
@@ -93,8 +93,10 @@ paths:
|
||||
Requests above the configured body limit (8 MiB by default) answer 413
|
||||
`payload_too_large`. Semantic rules that the schema cannot express answer
|
||||
400 `validation_failed`: group IDs are unique in a run, test IDs are
|
||||
unique in a group, and the number of tests multiplied by
|
||||
`limits.time_limit_ms` does not exceed 300000.
|
||||
unique in a group, the number of tests multiplied by
|
||||
`limits.time_limit_ms` does not exceed 300000, a `numbers` checker has a
|
||||
positive tolerance, a `custom` checker has a program, and no other kind
|
||||
carries tolerances or a program.
|
||||
tags:
|
||||
- runs
|
||||
requestBody:
|
||||
@@ -518,9 +520,10 @@ components:
|
||||
$ref: '#/components/schemas/RunResult'
|
||||
RunLanguage:
|
||||
type: string
|
||||
description: Language and runtime of the source. `python3` runs the Python 3 interpreter of the runner image with isolated mode and no bytecode writes; a syntax check runs first and fails with compile_error.
|
||||
description: Language and runtime of the source. `python3` runs the Python 3 interpreter of the runner image with isolated mode and no bytecode writes; a syntax check runs first and fails with compile_error. `go` compiles one `package main` file with the Go toolchain of the runner image against a prebuilt standard library (no modules, no cgo, no network) in a separate compile phase with its own limits; a compile or link error is compile_error and no test runs.
|
||||
enum:
|
||||
- python3
|
||||
- go
|
||||
RunLimits:
|
||||
type: object
|
||||
description: Limits applied to every test of the run.
|
||||
@@ -553,18 +556,50 @@ components:
|
||||
description: |-
|
||||
- exact: both texts are equal after replacing CRLF with LF, removing trailing spaces and tabs at the end of each line, and removing trailing empty lines.
|
||||
- tokens: both texts split on ASCII whitespace give the same sequence of tokens.
|
||||
- numbers: like tokens, but two finite numeric tokens are equal when their difference is within abs_tolerance or within rel_tolerance times the expected value; other tokens must be equal.
|
||||
- custom: the checker program of the task family decides in the sandbox.
|
||||
enum:
|
||||
- exact
|
||||
- tokens
|
||||
- numbers
|
||||
- custom
|
||||
CheckerProgram:
|
||||
type: object
|
||||
description: 'Checker program of the task family. It runs in the sandbox with the same isolation as the solution and fixed limits of its own (5 s CPU, 256 MiB). Its arguments are the paths of three read-only files: the test input, the expected output, and the actual output. Exit status 0 accepts, 1 rejects, and anything else, a signal, or a limit is a checker failure, which makes the run infrastructure_failure. Its own output is discarded and never returned.'
|
||||
additionalProperties: false
|
||||
required:
|
||||
- language
|
||||
- source
|
||||
properties:
|
||||
language:
|
||||
$ref: '#/components/schemas/RunLanguage'
|
||||
source:
|
||||
type: string
|
||||
minLength: 1
|
||||
maxLength: 65536
|
||||
Checker:
|
||||
type: object
|
||||
description: How the standard output of a test is compared with `expected_output`. Future kinds, such as a float tolerance or a custom checker, add a `kind` value and their own optional parameters to this object.
|
||||
description: How the standard output of a test is compared with `expected_output`. `numbers` requires `abs_tolerance`, `rel_tolerance`, or both; `custom` requires `program`. Other kinds take no parameter. New kinds add a `kind` value and their own optional parameters.
|
||||
additionalProperties: false
|
||||
required:
|
||||
- kind
|
||||
properties:
|
||||
kind:
|
||||
$ref: '#/components/schemas/CheckerKind'
|
||||
abs_tolerance:
|
||||
type: number
|
||||
format: double
|
||||
minimum: 0
|
||||
maximum: 1000000000
|
||||
description: Largest accepted absolute difference of two numeric tokens.
|
||||
rel_tolerance:
|
||||
type: number
|
||||
format: double
|
||||
minimum: 0
|
||||
maximum: 1
|
||||
description: Largest accepted difference of two numeric tokens relative to the expected value.
|
||||
program:
|
||||
$ref: '#/components/schemas/CheckerProgram'
|
||||
TestCase:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
|
||||
@@ -26,8 +26,10 @@ put:
|
||||
Requests above the configured body limit (8 MiB by default) answer 413
|
||||
`payload_too_large`. Semantic rules that the schema cannot express answer
|
||||
400 `validation_failed`: group IDs are unique in a run, test IDs are
|
||||
unique in a group, and the number of tests multiplied by
|
||||
`limits.time_limit_ms` does not exceed 300000.
|
||||
unique in a group, the number of tests multiplied by
|
||||
`limits.time_limit_ms` does not exceed 300000, a `numbers` checker has a
|
||||
positive tolerance, a `custom` checker has a program, and no other kind
|
||||
carries tolerances or a program.
|
||||
tags:
|
||||
- runs
|
||||
requestBody:
|
||||
|
||||
Reference in new issue
Block a user