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
@@ -521,8 +521,9 @@ func (s *Server) handleGetRunnerReadyzRequest(args [0]string, argsEscaped bool,
|
||||
// memory for a bounded time after they finish; an ID that was forgotten or lost in a restart starts a
|
||||
// new run. 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.
|
||||
// in a run, test IDs are 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.
|
||||
//
|
||||
// PUT /v1/runs/{run_id}
|
||||
func (s *Server) handleSubmitRunRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -25,10 +25,31 @@ func (s *Checker) encodeFields(e *jx.Encoder) {
|
||||
e.FieldStart("kind")
|
||||
s.Kind.Encode(e)
|
||||
}
|
||||
{
|
||||
if s.AbsTolerance.Set {
|
||||
e.FieldStart("abs_tolerance")
|
||||
s.AbsTolerance.Encode(e)
|
||||
}
|
||||
}
|
||||
{
|
||||
if s.RelTolerance.Set {
|
||||
e.FieldStart("rel_tolerance")
|
||||
s.RelTolerance.Encode(e)
|
||||
}
|
||||
}
|
||||
{
|
||||
if s.Program.Set {
|
||||
e.FieldStart("program")
|
||||
s.Program.Encode(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var jsonFieldsNameOfChecker = [1]string{
|
||||
var jsonFieldsNameOfChecker = [4]string{
|
||||
0: "kind",
|
||||
1: "abs_tolerance",
|
||||
2: "rel_tolerance",
|
||||
3: "program",
|
||||
}
|
||||
|
||||
// Decode decodes Checker from json.
|
||||
@@ -50,6 +71,36 @@ func (s *Checker) Decode(d *jx.Decoder) error {
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"kind\"")
|
||||
}
|
||||
case "abs_tolerance":
|
||||
if err := func() error {
|
||||
s.AbsTolerance.Reset()
|
||||
if err := s.AbsTolerance.Decode(d); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"abs_tolerance\"")
|
||||
}
|
||||
case "rel_tolerance":
|
||||
if err := func() error {
|
||||
s.RelTolerance.Reset()
|
||||
if err := s.RelTolerance.Decode(d); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"rel_tolerance\"")
|
||||
}
|
||||
case "program":
|
||||
if err := func() error {
|
||||
s.Program.Reset()
|
||||
if err := s.Program.Decode(d); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"program\"")
|
||||
}
|
||||
default:
|
||||
return errors.Errorf("unexpected field %q", k)
|
||||
}
|
||||
@@ -126,6 +177,10 @@ func (s *CheckerKind) Decode(d *jx.Decoder) error {
|
||||
*s = CheckerKindExact
|
||||
case CheckerKindTokens:
|
||||
*s = CheckerKindTokens
|
||||
case CheckerKindNumbers:
|
||||
*s = CheckerKindNumbers
|
||||
case CheckerKindCustom:
|
||||
*s = CheckerKindCustom
|
||||
default:
|
||||
*s = CheckerKind(v)
|
||||
}
|
||||
@@ -146,6 +201,117 @@ func (s *CheckerKind) UnmarshalJSON(data []byte) error {
|
||||
return s.Decode(d)
|
||||
}
|
||||
|
||||
// Encode implements json.Marshaler.
|
||||
func (s *CheckerProgram) Encode(e *jx.Encoder) {
|
||||
e.ObjStart()
|
||||
s.encodeFields(e)
|
||||
e.ObjEnd()
|
||||
}
|
||||
|
||||
// encodeFields encodes fields.
|
||||
func (s *CheckerProgram) encodeFields(e *jx.Encoder) {
|
||||
{
|
||||
e.FieldStart("language")
|
||||
s.Language.Encode(e)
|
||||
}
|
||||
{
|
||||
e.FieldStart("source")
|
||||
e.Str(s.Source)
|
||||
}
|
||||
}
|
||||
|
||||
var jsonFieldsNameOfCheckerProgram = [2]string{
|
||||
0: "language",
|
||||
1: "source",
|
||||
}
|
||||
|
||||
// Decode decodes CheckerProgram from json.
|
||||
func (s *CheckerProgram) Decode(d *jx.Decoder) error {
|
||||
if s == nil {
|
||||
return errors.New("invalid: unable to decode CheckerProgram to nil")
|
||||
}
|
||||
var requiredBitSet [1]uint8
|
||||
|
||||
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
|
||||
switch string(k) {
|
||||
case "language":
|
||||
requiredBitSet[0] |= 1 << 0
|
||||
if err := func() error {
|
||||
if err := s.Language.Decode(d); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"language\"")
|
||||
}
|
||||
case "source":
|
||||
requiredBitSet[0] |= 1 << 1
|
||||
if err := func() error {
|
||||
v, err := d.Str()
|
||||
s.Source = string(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"source\"")
|
||||
}
|
||||
default:
|
||||
return errors.Errorf("unexpected field %q", k)
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "decode CheckerProgram")
|
||||
}
|
||||
// Validate required fields.
|
||||
var failures []validate.FieldError
|
||||
for i, mask := range [1]uint8{
|
||||
0b00000011,
|
||||
} {
|
||||
if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
|
||||
// Mask only required fields and check equality to mask using XOR.
|
||||
//
|
||||
// If XOR result is not zero, result is not equal to expected, so some fields are missed.
|
||||
// Bits of fields which would be set are actually bits of missed fields.
|
||||
missed := bits.OnesCount8(result)
|
||||
for bitN := 0; bitN < missed; bitN++ {
|
||||
bitIdx := bits.TrailingZeros8(result)
|
||||
fieldIdx := i*8 + bitIdx
|
||||
var name string
|
||||
if fieldIdx < len(jsonFieldsNameOfCheckerProgram) {
|
||||
name = jsonFieldsNameOfCheckerProgram[fieldIdx]
|
||||
} else {
|
||||
name = strconv.Itoa(fieldIdx)
|
||||
}
|
||||
failures = append(failures, validate.FieldError{
|
||||
Name: name,
|
||||
Error: validate.ErrFieldRequired,
|
||||
})
|
||||
// Reset bit.
|
||||
result &^= 1 << bitIdx
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(failures) > 0 {
|
||||
return &validate.Error{Fields: failures}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements stdjson.Marshaler.
|
||||
func (s *CheckerProgram) MarshalJSON() ([]byte, error) {
|
||||
e := jx.Encoder{}
|
||||
s.Encode(&e)
|
||||
return e.Bytes(), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements stdjson.Unmarshaler.
|
||||
func (s *CheckerProgram) UnmarshalJSON(data []byte) error {
|
||||
d := jx.DecodeBytes(data)
|
||||
return s.Decode(d)
|
||||
}
|
||||
|
||||
// Encode implements json.Marshaler.
|
||||
func (s *CompileResult) Encode(e *jx.Encoder) {
|
||||
e.ObjStart()
|
||||
@@ -552,6 +718,39 @@ func (s *GroupResult) UnmarshalJSON(data []byte) error {
|
||||
return s.Decode(d)
|
||||
}
|
||||
|
||||
// Encode encodes CheckerProgram as json.
|
||||
func (o OptCheckerProgram) Encode(e *jx.Encoder) {
|
||||
if !o.Set {
|
||||
return
|
||||
}
|
||||
o.Value.Encode(e)
|
||||
}
|
||||
|
||||
// Decode decodes CheckerProgram from json.
|
||||
func (o *OptCheckerProgram) Decode(d *jx.Decoder) error {
|
||||
if o == nil {
|
||||
return errors.New("invalid: unable to decode OptCheckerProgram to nil")
|
||||
}
|
||||
o.Set = true
|
||||
if err := o.Value.Decode(d); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements stdjson.Marshaler.
|
||||
func (s OptCheckerProgram) MarshalJSON() ([]byte, error) {
|
||||
e := jx.Encoder{}
|
||||
s.Encode(&e)
|
||||
return e.Bytes(), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements stdjson.Unmarshaler.
|
||||
func (s *OptCheckerProgram) UnmarshalJSON(data []byte) error {
|
||||
d := jx.DecodeBytes(data)
|
||||
return s.Decode(d)
|
||||
}
|
||||
|
||||
// Encode encodes CompileResult as json.
|
||||
func (o OptCompileResult) Encode(e *jx.Encoder) {
|
||||
if !o.Set {
|
||||
@@ -585,6 +784,41 @@ func (s *OptCompileResult) UnmarshalJSON(data []byte) error {
|
||||
return s.Decode(d)
|
||||
}
|
||||
|
||||
// Encode encodes float64 as json.
|
||||
func (o OptFloat64) Encode(e *jx.Encoder) {
|
||||
if !o.Set {
|
||||
return
|
||||
}
|
||||
e.Float64(float64(o.Value))
|
||||
}
|
||||
|
||||
// Decode decodes float64 from json.
|
||||
func (o *OptFloat64) Decode(d *jx.Decoder) error {
|
||||
if o == nil {
|
||||
return errors.New("invalid: unable to decode OptFloat64 to nil")
|
||||
}
|
||||
o.Set = true
|
||||
v, err := d.Float64()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.Value = float64(v)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements stdjson.Marshaler.
|
||||
func (s OptFloat64) MarshalJSON() ([]byte, error) {
|
||||
e := jx.Encoder{}
|
||||
s.Encode(&e)
|
||||
return e.Bytes(), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements stdjson.Unmarshaler.
|
||||
func (s *OptFloat64) UnmarshalJSON(data []byte) error {
|
||||
d := jx.DecodeBytes(data)
|
||||
return s.Decode(d)
|
||||
}
|
||||
|
||||
// Encode encodes int32 as json.
|
||||
func (o OptInt32) Encode(e *jx.Encoder) {
|
||||
if !o.Set {
|
||||
@@ -1243,6 +1477,8 @@ func (s *RunLanguage) Decode(d *jx.Decoder) error {
|
||||
switch RunLanguage(v) {
|
||||
case RunLanguagePython3:
|
||||
*s = RunLanguagePython3
|
||||
case RunLanguageGo:
|
||||
*s = RunLanguageGo
|
||||
default:
|
||||
*s = RunLanguage(v)
|
||||
}
|
||||
|
||||
@@ -38,11 +38,17 @@ func (s *BearerAuth) SetRoles(val []string) {
|
||||
s.Roles = val
|
||||
}
|
||||
|
||||
// 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.
|
||||
// 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.
|
||||
// Ref: #/components/schemas/Checker
|
||||
type Checker struct {
|
||||
Kind CheckerKind `json:"kind"`
|
||||
// Largest accepted absolute difference of two numeric tokens.
|
||||
AbsTolerance OptFloat64 `json:"abs_tolerance"`
|
||||
// Largest accepted difference of two numeric tokens relative to the expected value.
|
||||
RelTolerance OptFloat64 `json:"rel_tolerance"`
|
||||
Program OptCheckerProgram `json:"program"`
|
||||
}
|
||||
|
||||
// GetKind returns the value of Kind.
|
||||
@@ -50,21 +56,56 @@ func (s *Checker) GetKind() CheckerKind {
|
||||
return s.Kind
|
||||
}
|
||||
|
||||
// GetAbsTolerance returns the value of AbsTolerance.
|
||||
func (s *Checker) GetAbsTolerance() OptFloat64 {
|
||||
return s.AbsTolerance
|
||||
}
|
||||
|
||||
// GetRelTolerance returns the value of RelTolerance.
|
||||
func (s *Checker) GetRelTolerance() OptFloat64 {
|
||||
return s.RelTolerance
|
||||
}
|
||||
|
||||
// GetProgram returns the value of Program.
|
||||
func (s *Checker) GetProgram() OptCheckerProgram {
|
||||
return s.Program
|
||||
}
|
||||
|
||||
// SetKind sets the value of Kind.
|
||||
func (s *Checker) SetKind(val CheckerKind) {
|
||||
s.Kind = val
|
||||
}
|
||||
|
||||
// SetAbsTolerance sets the value of AbsTolerance.
|
||||
func (s *Checker) SetAbsTolerance(val OptFloat64) {
|
||||
s.AbsTolerance = val
|
||||
}
|
||||
|
||||
// SetRelTolerance sets the value of RelTolerance.
|
||||
func (s *Checker) SetRelTolerance(val OptFloat64) {
|
||||
s.RelTolerance = val
|
||||
}
|
||||
|
||||
// SetProgram sets the value of Program.
|
||||
func (s *Checker) SetProgram(val OptCheckerProgram) {
|
||||
s.Program = val
|
||||
}
|
||||
|
||||
// - 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.
|
||||
//
|
||||
// Ref: #/components/schemas/CheckerKind
|
||||
type CheckerKind string
|
||||
|
||||
const (
|
||||
CheckerKindExact CheckerKind = "exact"
|
||||
CheckerKindTokens CheckerKind = "tokens"
|
||||
CheckerKindExact CheckerKind = "exact"
|
||||
CheckerKindTokens CheckerKind = "tokens"
|
||||
CheckerKindNumbers CheckerKind = "numbers"
|
||||
CheckerKindCustom CheckerKind = "custom"
|
||||
)
|
||||
|
||||
// AllValues returns all CheckerKind values.
|
||||
@@ -72,6 +113,8 @@ func (CheckerKind) AllValues() []CheckerKind {
|
||||
return []CheckerKind{
|
||||
CheckerKindExact,
|
||||
CheckerKindTokens,
|
||||
CheckerKindNumbers,
|
||||
CheckerKindCustom,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +125,10 @@ func (s CheckerKind) MarshalText() ([]byte, error) {
|
||||
return []byte(s), nil
|
||||
case CheckerKindTokens:
|
||||
return []byte(s), nil
|
||||
case CheckerKindNumbers:
|
||||
return []byte(s), nil
|
||||
case CheckerKindCustom:
|
||||
return []byte(s), nil
|
||||
default:
|
||||
return nil, errors.Errorf("invalid value: %q", s)
|
||||
}
|
||||
@@ -96,11 +143,48 @@ func (s *CheckerKind) UnmarshalText(data []byte) error {
|
||||
case CheckerKindTokens:
|
||||
*s = CheckerKindTokens
|
||||
return nil
|
||||
case CheckerKindNumbers:
|
||||
*s = CheckerKindNumbers
|
||||
return nil
|
||||
case CheckerKindCustom:
|
||||
*s = CheckerKindCustom
|
||||
return nil
|
||||
default:
|
||||
return errors.Errorf("invalid value: %q", data)
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
// Ref: #/components/schemas/CheckerProgram
|
||||
type CheckerProgram struct {
|
||||
Language RunLanguage `json:"language"`
|
||||
Source string `json:"source"`
|
||||
}
|
||||
|
||||
// GetLanguage returns the value of Language.
|
||||
func (s *CheckerProgram) GetLanguage() RunLanguage {
|
||||
return s.Language
|
||||
}
|
||||
|
||||
// GetSource returns the value of Source.
|
||||
func (s *CheckerProgram) GetSource() string {
|
||||
return s.Source
|
||||
}
|
||||
|
||||
// SetLanguage sets the value of Language.
|
||||
func (s *CheckerProgram) SetLanguage(val RunLanguage) {
|
||||
s.Language = val
|
||||
}
|
||||
|
||||
// SetSource sets the value of Source.
|
||||
func (s *CheckerProgram) SetSource(val string) {
|
||||
s.Source = val
|
||||
}
|
||||
|
||||
// Ref: #/components/schemas/CompileResult
|
||||
type CompileResult struct {
|
||||
Outcome RunOutcome `json:"outcome"`
|
||||
@@ -233,6 +317,52 @@ func (s *GroupResult) SetTests(val []TestResult) {
|
||||
s.Tests = val
|
||||
}
|
||||
|
||||
// NewOptCheckerProgram returns new OptCheckerProgram with value set to v.
|
||||
func NewOptCheckerProgram(v CheckerProgram) OptCheckerProgram {
|
||||
return OptCheckerProgram{
|
||||
Value: v,
|
||||
Set: true,
|
||||
}
|
||||
}
|
||||
|
||||
// OptCheckerProgram is optional CheckerProgram.
|
||||
type OptCheckerProgram struct {
|
||||
Value CheckerProgram
|
||||
Set bool
|
||||
}
|
||||
|
||||
// IsSet returns true if OptCheckerProgram was set.
|
||||
func (o OptCheckerProgram) IsSet() bool { return o.Set }
|
||||
|
||||
// Reset unsets value.
|
||||
func (o *OptCheckerProgram) Reset() {
|
||||
var v CheckerProgram
|
||||
o.Value = v
|
||||
o.Set = false
|
||||
}
|
||||
|
||||
// SetTo sets value to v.
|
||||
func (o *OptCheckerProgram) SetTo(v CheckerProgram) {
|
||||
o.Set = true
|
||||
o.Value = v
|
||||
}
|
||||
|
||||
// Get returns value and boolean that denotes whether value was set.
|
||||
func (o OptCheckerProgram) Get() (v CheckerProgram, ok bool) {
|
||||
if !o.Set {
|
||||
return v, false
|
||||
}
|
||||
return o.Value, true
|
||||
}
|
||||
|
||||
// Or returns value if set, or given parameter if does not.
|
||||
func (o OptCheckerProgram) Or(d CheckerProgram) CheckerProgram {
|
||||
if v, ok := o.Get(); ok {
|
||||
return v
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
// NewOptCompileResult returns new OptCompileResult with value set to v.
|
||||
func NewOptCompileResult(v CompileResult) OptCompileResult {
|
||||
return OptCompileResult{
|
||||
@@ -279,6 +409,52 @@ func (o OptCompileResult) Or(d CompileResult) CompileResult {
|
||||
return d
|
||||
}
|
||||
|
||||
// NewOptFloat64 returns new OptFloat64 with value set to v.
|
||||
func NewOptFloat64(v float64) OptFloat64 {
|
||||
return OptFloat64{
|
||||
Value: v,
|
||||
Set: true,
|
||||
}
|
||||
}
|
||||
|
||||
// OptFloat64 is optional float64.
|
||||
type OptFloat64 struct {
|
||||
Value float64
|
||||
Set bool
|
||||
}
|
||||
|
||||
// IsSet returns true if OptFloat64 was set.
|
||||
func (o OptFloat64) IsSet() bool { return o.Set }
|
||||
|
||||
// Reset unsets value.
|
||||
func (o *OptFloat64) Reset() {
|
||||
var v float64
|
||||
o.Value = v
|
||||
o.Set = false
|
||||
}
|
||||
|
||||
// SetTo sets value to v.
|
||||
func (o *OptFloat64) SetTo(v float64) {
|
||||
o.Set = true
|
||||
o.Value = v
|
||||
}
|
||||
|
||||
// Get returns value and boolean that denotes whether value was set.
|
||||
func (o OptFloat64) Get() (v float64, ok bool) {
|
||||
if !o.Set {
|
||||
return v, false
|
||||
}
|
||||
return o.Value, true
|
||||
}
|
||||
|
||||
// Or returns value if set, or given parameter if does not.
|
||||
func (o OptFloat64) Or(d float64) float64 {
|
||||
if v, ok := o.Get(); ok {
|
||||
return v
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
// NewOptInt32 returns new OptInt32 with value set to v.
|
||||
func NewOptInt32(v int32) OptInt32 {
|
||||
return OptInt32{
|
||||
@@ -868,18 +1044,23 @@ func (s *ProblemStatusCode) SetResponse(val Problem) {
|
||||
}
|
||||
|
||||
// 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.
|
||||
// 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.
|
||||
// Ref: #/components/schemas/RunLanguage
|
||||
type RunLanguage string
|
||||
|
||||
const (
|
||||
RunLanguagePython3 RunLanguage = "python3"
|
||||
RunLanguageGo RunLanguage = "go"
|
||||
)
|
||||
|
||||
// AllValues returns all RunLanguage values.
|
||||
func (RunLanguage) AllValues() []RunLanguage {
|
||||
return []RunLanguage{
|
||||
RunLanguagePython3,
|
||||
RunLanguageGo,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -888,6 +1069,8 @@ func (s RunLanguage) MarshalText() ([]byte, error) {
|
||||
switch s {
|
||||
case RunLanguagePython3:
|
||||
return []byte(s), nil
|
||||
case RunLanguageGo:
|
||||
return []byte(s), nil
|
||||
default:
|
||||
return nil, errors.Errorf("invalid value: %q", s)
|
||||
}
|
||||
@@ -899,6 +1082,9 @@ func (s *RunLanguage) UnmarshalText(data []byte) error {
|
||||
case RunLanguagePython3:
|
||||
*s = RunLanguagePython3
|
||||
return nil
|
||||
case RunLanguageGo:
|
||||
*s = RunLanguageGo
|
||||
return nil
|
||||
default:
|
||||
return errors.Errorf("invalid value: %q", data)
|
||||
}
|
||||
|
||||
@@ -44,8 +44,9 @@ type Handler interface {
|
||||
// memory for a bounded time after they finish; an ID that was forgotten or lost in a restart starts a
|
||||
// new run. 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.
|
||||
// in a run, test IDs are 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.
|
||||
//
|
||||
// PUT /v1/runs/{run_id}
|
||||
SubmitRun(ctx context.Context, req *RunRequest, params SubmitRunParams) (SubmitRunRes, error)
|
||||
|
||||
@@ -58,8 +58,9 @@ func (UnimplementedHandler) GetRunnerReadyz(ctx context.Context) (r GetRunnerRea
|
||||
// memory for a bounded time after they finish; an ID that was forgotten or lost in a restart starts a
|
||||
// new run. 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.
|
||||
// in a run, test IDs are 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.
|
||||
//
|
||||
// PUT /v1/runs/{run_id}
|
||||
func (UnimplementedHandler) SubmitRun(ctx context.Context, req *RunRequest, params SubmitRunParams) (r SubmitRunRes, _ error) {
|
||||
|
||||
@@ -26,6 +26,80 @@ func (s *Checker) Validate() error {
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
if err := func() error {
|
||||
if value, ok := s.AbsTolerance.Get(); ok {
|
||||
if err := func() error {
|
||||
if err := (validate.Float{
|
||||
MinSet: true,
|
||||
Min: 0,
|
||||
MaxSet: true,
|
||||
Max: 1e+09,
|
||||
MinExclusive: false,
|
||||
MaxExclusive: false,
|
||||
MultipleOfSet: false,
|
||||
MultipleOf: nil,
|
||||
Pattern: nil,
|
||||
}).Validate(float64(value)); err != nil {
|
||||
return errors.Wrap(err, "float")
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
failures = append(failures, validate.FieldError{
|
||||
Name: "abs_tolerance",
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
if err := func() error {
|
||||
if value, ok := s.RelTolerance.Get(); ok {
|
||||
if err := func() error {
|
||||
if err := (validate.Float{
|
||||
MinSet: true,
|
||||
Min: 0,
|
||||
MaxSet: true,
|
||||
Max: 1,
|
||||
MinExclusive: false,
|
||||
MaxExclusive: false,
|
||||
MultipleOfSet: false,
|
||||
MultipleOf: nil,
|
||||
Pattern: nil,
|
||||
}).Validate(float64(value)); err != nil {
|
||||
return errors.Wrap(err, "float")
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
failures = append(failures, validate.FieldError{
|
||||
Name: "rel_tolerance",
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
if err := func() error {
|
||||
if value, ok := s.Program.Get(); ok {
|
||||
if err := func() error {
|
||||
if err := value.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
failures = append(failures, validate.FieldError{
|
||||
Name: "program",
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
if len(failures) > 0 {
|
||||
return &validate.Error{Fields: failures}
|
||||
}
|
||||
@@ -38,11 +112,61 @@ func (s CheckerKind) Validate() error {
|
||||
return nil
|
||||
case "tokens":
|
||||
return nil
|
||||
case "numbers":
|
||||
return nil
|
||||
case "custom":
|
||||
return nil
|
||||
default:
|
||||
return errors.Errorf("invalid value: %v", s)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CheckerProgram) Validate() error {
|
||||
if s == nil {
|
||||
return validate.ErrNilPointer
|
||||
}
|
||||
|
||||
var failures []validate.FieldError
|
||||
if err := func() error {
|
||||
if err := s.Language.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
failures = append(failures, validate.FieldError{
|
||||
Name: "language",
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
if err := func() error {
|
||||
if err := (validate.String{
|
||||
MinLength: 1,
|
||||
MinLengthSet: true,
|
||||
MaxLength: 65536,
|
||||
MaxLengthSet: true,
|
||||
Email: false,
|
||||
Hostname: false,
|
||||
Regex: nil,
|
||||
MinNumeric: 0,
|
||||
MinNumericSet: false,
|
||||
MaxNumeric: 0,
|
||||
MaxNumericSet: false,
|
||||
}).Validate(string(s.Source)); err != nil {
|
||||
return errors.Wrap(err, "string")
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
failures = append(failures, validate.FieldError{
|
||||
Name: "source",
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
if len(failures) > 0 {
|
||||
return &validate.Error{Fields: failures}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *CompileResult) Validate() error {
|
||||
if s == nil {
|
||||
return validate.ErrNilPointer
|
||||
@@ -668,6 +792,8 @@ func (s RunLanguage) Validate() error {
|
||||
switch s {
|
||||
case "python3":
|
||||
return nil
|
||||
case "go":
|
||||
return nil
|
||||
default:
|
||||
return errors.Errorf("invalid value: %v", s)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user