Documentation
¶
Overview ¶
Package challenge owns the immutable, schema-versioned definition of a guided SQL challenge and its deterministic grading primitives.
A challenge definition is a project asset (see AssetPath) whose revision pins the visible schema, the fixture-suite byte hashes, the answer parts, the result/final-state oracles, the grading semantics and the execution engine. Opening a definition verifies every pin before any execution is allowed; there is no partially trusted manifest.
Grading here is deliberately passive: the browser runtime executes the learner's SQL against a disposable fixture and hands the resulting typed rows or final table state back to this package. Nothing in this package opens a database, executes SQL, performs authorization, calls a model or records completion.
Index ¶
- Constants
- Variables
- func AssetPath(challengeID string, revision int) (string, error)
- func FixtureAssetPath(challengeID, fixtureID string) (string, error)
- func GuidedRouteSuffix(challengeID string, revision int) (string, error)
- type AttemptOutcome
- type CheckCase
- type CheckCaseResult
- type CheckDefinitionAnswer
- type CheckDefinitionPart
- type CheckDefinitionResult
- type Code
- type Engine
- type Error
- type FieldOutcome
- type FinalStateOracle
- type FinalStateResult
- type Fixture
- type FixtureSuite
- type Hint
- type Invariant
- type InvariantResult
- type Manifest
- type Observation
- type Opened
- type Oracle
- type Part
- type PartOutcome
- type ReferenceAnswer
- type ReferenceSolution
- type ResultOracle
- type RowDiff
- type RowOptions
- type SQLCase
- type SQLCaseResult
- type SQLPart
- type SQLPartResult
- type StructuredAnswer
- type StructuredField
- type StructuredOption
- type StructuredPart
- type StructuredResult
- type TableExpectation
- type TableResult
- type TableState
- type TimingMode
- type VisibleColumn
- type VisibleSchema
- type VisibleTable
Constants ¶
const ( ProblemUnknownQuery = "unknown-query" ProblemUnsupportedExpectation = "unsupported-expectation" ProblemExpectationMismatch = "expectation-mismatch" ProblemMissingObservation = "missing-observation" ProblemCaseOutcome = "case-outcome" )
Stable check-definition problem codes.
const ( OrderUnordered = "unordered" OrderOrdered = "ordered" )
Row ordering modes. Unordered comparison is the default contract for result sets; ordered comparison is asserted only when the manifest declares it.
const ( ProblemColumnCount = "column-count" ProblemColumnName = "column-name" // ProblemColumnType is reserved. Column metadata types describe a column, // not a graded cell; SQLite storage class is compared per typed cell. ProblemColumnType = "column-type" ProblemRowShape = "row-shape" ProblemRowValueType = "row-value-type" ProblemRowOrder = "row-order" ProblemRowContent = "row-content" ProblemInvalidOptions = "invalid-options" ProblemInvariant = "invariant" )
Stable comparison problem codes. They are wire values used in feedback.
const ( OutcomePass = "pass" OutcomeFail = "fail" OutcomeUnknown = "unknown" StatusCompleted = "completed" StatusError = "error" )
Outcome and execution-status vocabulary shared with Detective results.
const ( ProblemSQLBytes = "sql-bytes" ProblemSQLEmpty = "sql-empty" ProblemExecutionError = "execution-error" ProblemObservation = "observation-missing" ProblemOracleInvalid = "invalid-oracle" ProblemFinalState = "final-state" )
SQL grading problem codes.
const ( SchemaVersion = 1 GradingVersion = "challenge-grading-v1" )
SchemaVersion and GradingVersion are part of the wire contract. A manifest is graded only by the exact semantics it pins: changing a predicate without changing these values is a contract violation, and changing them requires a new revision.
const ( MaxDefinitionBytes = 4 << 20 MaxFixtureBytes = 10 << 20 MaxSQLBytes = 64 << 10 MaxResultRows = 1000 MaxResultColumns = 40 )
Limits are the approved execution limits. A manifest cannot relax them, and definition values are validated against them while the asset is opened.
const ( AnswerSQL = "sql" AnswerStructured = "structured" AnswerCheckDefinition = "check-definition" )
Answer kinds. Each part has exactly one kind and one matching answer body.
const ( CardinalitySingle = "single" CardinalityMulti = "multi" )
Field cardinalities for closed structured answers.
const ( DifficultyIntro = "intro" DifficultyIntermediate = "intermediate" DifficultyAdvanced = "advanced" )
Difficulty values exposed by discovery.
const ( OracleResult = "result" OracleFinalState = "final-state" )
Oracle kinds for a SQL answer part. Exactly one oracle is attached to each SQL case.
const ( ProblemUnknownField = "unknown-field" ProblemUnknownOption = "unknown-option" ProblemDuplicateOption = "duplicate-option" ProblemMissingSelection = "missing-selection" ProblemSingleCardinality = "single-cardinality" ProblemSelectionCount = "selection-cardinality" ProblemSelectionMismatch = "selection-mismatch" )
Stable structured-grading problem codes.
const InvariantGroupMin = "group-min"
Invariant kinds are deliberately small and deterministic. A future rule needs a new grading version instead of an open-ended predicate language.
Variables ¶
var SupportedEngine = Engine{
Package: "@sqlite.org/sqlite-wasm",
Version: "3.54.1-build1",
SQLiteVersion: "3.54.1",
}
SupportedEngine is the browser challenge runtime pinned by the approved execution foundation. A revision declaring any other engine is refused rather than silently graded by different SQLite behaviour.
Functions ¶
func FixtureAssetPath ¶
FixtureAssetPath is the conventional project-relative path of a fixture inside the challenge asset directory. Fixture identity is always the pinned SHA-256, not this path.
func GuidedRouteSuffix ¶
GuidedRouteSuffix is the project-scoped route suffix that opens the existing query page in guided mode: /project/<projectRef>/challenge/<id>/v/<revision>. Core deliberately does not parse the project reference; the caller owns its exact spelling and pins the returned revision.
Types ¶
type AttemptOutcome ¶
type AttemptOutcome struct {
Complete bool `json:"complete"`
Parts []PartOutcome `json:"parts"`
BlockingParts []string `json:"blockingParts,omitempty"`
}
AttemptOutcome is the only place completion is derived. It is true only when every required part passed with a completed execution.
func GradeAttempt ¶
func GradeAttempt(manifest Manifest, outcomes []PartOutcome) (AttemptOutcome, error)
GradeAttempt validates that the provided outcomes correspond exactly to the manifest's parts and derives completion. It never accepts a caller-supplied completion boolean.
type CheckCase ¶
type CheckCase struct {
Fixture string `json:"fixture"`
ExpectedOutcome string `json:"expectedOutcome"`
}
CheckCase pins one fixture to the outcome a correct Check must produce.
type CheckCaseResult ¶
type CheckCaseResult struct {
Fixture string `json:"fixture"`
ExpectedOutcome string `json:"expectedOutcome"`
ObservedOutcome string `json:"observedOutcome,omitempty"`
Outcome string `json:"outcome"`
Problem string `json:"problem,omitempty"`
Message string `json:"message,omitempty"`
}
CheckCaseResult reports one fixture's expected versus observed outcome.
type CheckDefinitionAnswer ¶
type CheckDefinitionAnswer struct {
QueryID string `json:"queryId"`
Expectation detective.Validator `json:"expectation"`
}
CheckDefinitionAnswer is a learner's saved-query selection plus expectation.
type CheckDefinitionPart ¶
type CheckDefinitionPart struct {
QueryIDs []string `json:"queryIds"`
Expectation detective.Validator `json:"expectation"`
Cases []CheckCase `json:"cases"`
}
CheckDefinitionPart asks the learner to select one saved training query and one typed supported expectation. Outcomes are validated deterministically on broken, repaired and mutated fixtures; no model judgement is involved.
type CheckDefinitionResult ¶
type CheckDefinitionResult struct {
Outcome string `json:"outcome"`
ExecutionStatus string `json:"executionStatus"`
Problem string `json:"problem,omitempty"`
Message string `json:"message,omitempty"`
Cases []CheckCaseResult `json:"cases"`
}
CheckDefinitionResult is the outcome of a Check-definition answer.
func EvaluateCheckDefinition ¶
func EvaluateCheckDefinition(part CheckDefinitionPart, answer CheckDefinitionAnswer, observations map[string]Observation) CheckDefinitionResult
EvaluateCheckDefinition grades a submitted Check definition. Observation rows must come from the disposable runtime executing the selected saved query against each pristine fixture.
func (CheckDefinitionResult) AsOutcome ¶
func (r CheckDefinitionResult) AsOutcome(part Part) PartOutcome
AsOutcome projects the result onto the attempt contract.
type Code ¶
type Code string
Code is a stable refusal code for a definition or answer problem.
const ( // CodeInvalidManifest covers structural, range and reference violations. CodeInvalidManifest Code = "invalid_manifest" // CodeUnsupportedSchema refuses a schema version this package cannot grade. CodeUnsupportedSchema Code = "unsupported_schema" // CodeUnsupportedGradingVersion refuses changed predicate semantics. CodeUnsupportedGradingVersion Code = "unsupported_grading_version" // CodeUnsupportedDialect refuses a dialect the browser runtime cannot host. CodeUnsupportedDialect Code = "unsupported_dialect" // CodeUnsupportedEngine refuses a revision pinned to another engine. CodeUnsupportedEngine Code = "unsupported_engine" // CodeFixtureMissing refuses a pin without bytes. CodeFixtureMissing Code = "fixture_missing" // CodeFixtureUnknown refuses bytes that no revision pins. CodeFixtureUnknown Code = "fixture_unknown" // CodeFixtureBytes refuses a byte length that differs from its pin. CodeFixtureBytes Code = "fixture_bytes" // CodeFixtureHash refuses bytes whose SHA-256 differs from the pin. CodeFixtureHash Code = "fixture_hash" // CodeInvalidAnswer covers an answer that cannot be graded at all. CodeInvalidAnswer Code = "invalid_answer" )
type Engine ¶
type Engine struct {
Package string `json:"package"`
Version string `json:"version"`
SQLiteVersion string `json:"sqliteVersion"`
}
Engine is the exact execution engine a revision is graded on. The fields are pinned in the manifest and must match the runtime that opens it.
type Error ¶
type Error struct {
Code Code `json:"code"`
Field string `json:"field,omitempty"`
Message string `json:"message"`
}
Error is a definition or answer refusal. Definition refusals are recoverable: reloading a supported revision or its original bytes resolves them, and no completion may be recorded from a refused open.
func (*Error) Recoverable ¶
Recoverable reports whether retrying with a supported revision or the pinned bytes can succeed. Every refusal produced here is recoverable.
type FieldOutcome ¶
type FieldOutcome struct {
FieldID string `json:"fieldId"`
Outcome string `json:"outcome"`
Problem string `json:"problem,omitempty"`
Message string `json:"message,omitempty"`
}
FieldOutcome reports one field's deterministic result.
type FinalStateOracle ¶
type FinalStateOracle struct {
Tables []TableExpectation `json:"tables"`
Invariants []Invariant `json:"invariants,omitempty"`
}
FinalStateOracle declares expected table contents plus named invariants that explain a violation. Exact row comparison already covers expected survivors and unrelated rows; invariants add the violated retention rule to feedback.
func (FinalStateOracle) Validate ¶
func (f FinalStateOracle) Validate() error
type FinalStateResult ¶
type FinalStateResult struct {
Pass bool `json:"pass"`
Problem string `json:"problem,omitempty"`
Message string `json:"message,omitempty"`
Tables []TableResult `json:"tables"`
Invariants []InvariantResult `json:"invariants,omitempty"`
}
FinalStateResult is the deterministic outcome of a write answer. Every declared table and every invariant must pass.
func EvaluateFinalState ¶
func EvaluateFinalState(oracle FinalStateOracle, actual []TableState) FinalStateResult
EvaluateFinalState compares observed tables with the declared expected contents and evaluates each named invariant. It never guesses an expected value: the manifest's expected table is the single answer key.
func (FinalStateResult) ViolatedInvariant ¶
func (r FinalStateResult) ViolatedInvariant() string
ViolatedInvariant returns the first failed invariant ID, if any.
type Fixture ¶
type Fixture struct {
ID string `json:"id"`
Label string `json:"label"`
SHA256 string `json:"sha256"`
Bytes int `json:"bytes"`
Runs int `json:"runs"`
}
Fixture is one immutable SHA-256/byte-length pin. Runs is the number of times the submitted SQL is applied (2 proves idempotency).
type FixtureSuite ¶
FixtureSuite pins every byte the graded answer is executed against.
type Invariant ¶
type Invariant struct {
ID string `json:"id"`
Kind string `json:"kind"`
Table string `json:"table"`
GroupBy []string `json:"groupBy"`
Column string `json:"column"`
Description string `json:"description"`
}
Invariant names a retention rule the final state must satisfy. GroupMin requires exactly one surviving row per declared group and requires that row's Column to equal the lowest value in the expected table.
type InvariantResult ¶
type InvariantResult struct {
ID string `json:"id"`
Pass bool `json:"pass"`
Problem string `json:"problem,omitempty"`
Message string `json:"message,omitempty"`
}
InvariantResult reports one named retention invariant.
type Manifest ¶
type Manifest struct {
SchemaVersion int `json:"schemaVersion"`
GradingVersion string `json:"gradingVersion"`
ChallengeID string `json:"challengeId"`
Revision int `json:"revision"`
Title string `json:"title"`
Objective string `json:"objective"`
Difficulty string `json:"difficulty"`
Dialect string `json:"dialect"`
AllowedOperation string `json:"allowedOperation"`
Timing TimingMode `json:"timing"`
Engine Engine `json:"engine"`
FixtureSuite FixtureSuite `json:"fixtureSuite"`
VisibleSchema VisibleSchema `json:"visibleSchema"`
Parts []Part `json:"parts"`
Hints []Hint `json:"hints"`
ReferenceSolutions []ReferenceSolution `json:"referenceSolutions"`
}
Manifest is one immutable published challenge revision.
func LoadManifest ¶
LoadManifest strictly decodes and validates manifest bytes. Unknown fields, duplicate keys, unsupported versions, range violations and broken internal references are refused before execution.
type Observation ¶
type Observation struct {
Rows *apicontract.Recordset `json:"rows,omitempty"`
Tables []TableState `json:"tables,omitempty"`
ErrorCode string `json:"errorCode,omitempty"`
}
Observation is one pristine-fixture run supplied by the disposable runtime. It is not learner input and carries no authorization claim.
type Opened ¶
type Opened struct {
Manifest Manifest
DefinitionDigest string
// contains filtered or unexported fields
}
Opened is a manifest whose schema, references and fixture pins have all been verified. It holds its own fixture snapshots; later mutation of caller buffers cannot change what an attempt executes.
func Open ¶
Open verifies the manifest and every pinned fixture byte before returning a definition. A refused open returns no Opened value, so no attempt or completion can be created from it.
func (*Opened) FixtureBytesEqual ¶
FixtureBytesEqual is used by inspection receipts that need to prove two opens used identical pristine bytes.
func (*Opened) FixtureIDs ¶
FixtureIDs returns the pinned fixture IDs in deterministic order.
func (*Opened) HasFixture ¶
HasFixture reports whether a fixture ID is part of the verified suite.
func (*Opened) RequireEngine ¶
RequireEngine refuses a runtime whose exact engine differs from the manifest pin. Grading semantics and engine version travel together.
type Oracle ¶
type Oracle struct {
Kind string
Result *ResultOracle
FinalState *FinalStateOracle
}
Oracle is a closed union. It names either the typed rows a read answer must return or the final table state a write answer must leave behind.
func (Oracle) MarshalJSON ¶
func (*Oracle) UnmarshalJSON ¶
type Part ¶
type Part struct {
ID string `json:"id"`
Title string `json:"title"`
Required bool `json:"required"`
AnswerKind string `json:"answerKind"`
SQL *SQLPart `json:"sql,omitempty"`
Structured *StructuredPart `json:"structured,omitempty"`
CheckDefinition *CheckDefinitionPart `json:"checkDefinition,omitempty"`
}
Part is one named, required-by-default answer required to complete a challenge.
type PartOutcome ¶
type PartOutcome struct {
PartID string `json:"partId"`
AnswerKind string `json:"answerKind"`
Required bool `json:"required"`
Outcome string `json:"outcome"`
ExecutionStatus string `json:"executionStatus"`
Problem string `json:"problem,omitempty"`
Message string `json:"message,omitempty"`
}
PartOutcome is the normalized, untrusted-input-resistant result of one part.
type ReferenceAnswer ¶
type ReferenceAnswer struct {
SQL string `json:"sql,omitempty"`
Structured *StructuredAnswer `json:"structured,omitempty"`
CheckDefinition *CheckDefinitionAnswer `json:"checkDefinition,omitempty"`
}
ReferenceAnswer is a closed union matching the part's answer kind.
type ReferenceSolution ¶
type ReferenceSolution struct {
PartID string `json:"partId"`
Answer ReferenceAnswer `json:"answer"`
}
ReferenceSolution declares an assisted answer. Consuming UI must tag it as assistance; a reference answer never awards completion by itself.
type ResultOracle ¶
type ResultOracle struct {
Columns []apicontract.Column `json:"columns"`
Rows [][]apicontract.TypedValue `json:"rows"`
Ordering string `json:"ordering"`
RequireColumnNames bool `json:"requireColumnNames,omitempty"`
NumericTolerance string `json:"numericTolerance,omitempty"`
}
ResultOracle declares the typed recordset a read answer must produce.
func (ResultOracle) Validate ¶
func (r ResultOracle) Validate() error
type RowDiff ¶
type RowDiff struct {
Match bool `json:"match"`
Problem string `json:"problem,omitempty"`
Message string `json:"message,omitempty"`
Missing int `json:"missing,omitempty"`
Unexpected int `json:"unexpected,omitempty"`
Examples []string `json:"examples,omitempty"`
}
RowDiff is a bounded, deterministic description of why two typed row sets differ. Missing and Unexpected count whole rows in an unordered comparison; ordered comparisons report the first differing position instead.
func CompareTypedRows ¶
func CompareTypedRows(expectedColumns, actualColumns []apicontract.Column, expectedRows, actualRows [][]apicontract.TypedValue, options RowOptions) RowDiff
CompareTypedRows compares a declared expected recordset with an observed one. Column metadata is validated for supported shape, but a column's declared type is descriptive and is not compared with the observed metadata or the cells in it: SQLite storage class participates in equality per typed cell. Values are matched by declared column position; column count is exact; column aliases are ignored unless RequireColumnNames is set. Storage classes remain distinct (INTEGER 2 differs from REAL 2.0) unless an explicit non-negative numeric tolerance is declared.
type RowOptions ¶
type RowOptions struct {
Ordering string `json:"ordering"`
RequireColumnNames bool `json:"requireColumnNames,omitempty"`
NumericTolerance string `json:"numericTolerance,omitempty"`
}
RowOptions controls typed row comparison.
type SQLCaseResult ¶
type SQLCaseResult struct {
Fixture string `json:"fixture"`
Outcome string `json:"outcome"`
ExecutionStatus string `json:"executionStatus"`
Problem string `json:"problem,omitempty"`
InvariantID string `json:"invariantId,omitempty"`
Message string `json:"message,omitempty"`
Missing int `json:"missing,omitempty"`
Unexpected int `json:"unexpected,omitempty"`
Examples []string `json:"examples,omitempty"`
}
SQLCaseResult reports one fixture's graded outcome. Missing, Unexpected and Examples are present only for a same-shape unordered row-content mismatch; they carry bounded, deterministic feedback and never affect the verdict.
type SQLPart ¶
type SQLPart struct {
Cases []SQLCase `json:"cases"`
}
SQLPart declares the fixture cases and their expected oracles.
type SQLPartResult ¶
type SQLPartResult struct {
Outcome string `json:"outcome"`
ExecutionStatus string `json:"executionStatus"`
Problem string `json:"problem,omitempty"`
Message string `json:"message,omitempty"`
Cases []SQLCaseResult `json:"cases"`
}
SQLPartResult reports every fixture case for one SQL answer.
func GradeSQLPart ¶
func GradeSQLPart(part SQLPart, sql string, observations map[string]Observation) SQLPartResult
GradeSQLPart grades one SQL text against every declared case. The runtime executes it on independent, pristine fixture copies; this function only compares typed evidence.
func (SQLPartResult) AsOutcome ¶
func (r SQLPartResult) AsOutcome(part Part) PartOutcome
AsOutcome projects the result onto the attempt contract.
type StructuredAnswer ¶
StructuredAnswer is both the expected answer and a learner submission.
type StructuredField ¶
type StructuredField struct {
ID string `json:"id"`
Label string `json:"label"`
Cardinality string `json:"cardinality"`
Required bool `json:"required"`
MinSelections int `json:"minSelections,omitempty"`
MaxSelections int `json:"maxSelections,omitempty"`
Options []StructuredOption `json:"options"`
}
StructuredField declares one closed field. Single fields always require exactly one option; multi fields declare an inclusive min/max selection count.
type StructuredOption ¶
StructuredOption is one closed option ID and its learner-facing label.
type StructuredPart ¶
type StructuredPart struct {
Fields []StructuredField `json:"fields"`
Expected StructuredAnswer `json:"expected"`
}
StructuredPart is a closed selection answer: every field and option is declared, and grading is exact value/set equality. No free text, model or fuzzy matching is involved.
func (StructuredPart) Validate ¶
func (s StructuredPart) Validate() error
Validate checks the closed field/option space and the expected answer.
type StructuredResult ¶
type StructuredResult struct {
Outcome string `json:"outcome"`
ExecutionStatus string `json:"executionStatus"`
Problem string `json:"problem,omitempty"`
Message string `json:"message,omitempty"`
Fields []FieldOutcome `json:"fields"`
}
StructuredResult is the outcome of a closed-selection answer.
func EvaluateStructured ¶
func EvaluateStructured(part StructuredPart, answer StructuredAnswer) StructuredResult
EvaluateStructured grades a closed selection without AI judgement.
func (StructuredResult) AsOutcome ¶
func (r StructuredResult) AsOutcome(part Part) PartOutcome
AsOutcome projects the result onto the attempt contract.
type TableExpectation ¶
type TableExpectation struct {
Name string `json:"name"`
Columns []apicontract.Column `json:"columns"`
Rows [][]apicontract.TypedValue `json:"rows"`
}
TableExpectation is the exact expected final content of one table.
func (TableExpectation) Validate ¶
func (t TableExpectation) Validate() error
type TableResult ¶
type TableResult struct {
Table string `json:"table"`
Pass bool `json:"pass"`
Problem string `json:"problem,omitempty"`
Message string `json:"message,omitempty"`
}
TableResult reports one declared table's exact final-state comparison.
type TableState ¶
type TableState struct {
Name string `json:"name"`
Columns []apicontract.Column `json:"columns"`
Rows [][]apicontract.TypedValue `json:"rows"`
}
TableState is an observed final table supplied by the disposable runtime.
type TimingMode ¶
type TimingMode string
TimingMode is the attempt timing policy pinned by a revision.
const ( TimingOff TimingMode = "off" TimingOptional TimingMode = "optional" TimingRequired TimingMode = "required" )
type VisibleColumn ¶
type VisibleColumn struct {
Name string `json:"name"`
Type string `json:"type"`
PrimaryKey bool `json:"primaryKey,omitempty"`
NotNull bool `json:"notNull,omitempty"`
Collation string `json:"collation,omitempty"`
}
VisibleColumn is one visible column, including the SQLite collation that participates in equality.
type VisibleSchema ¶
type VisibleSchema struct {
Tables []VisibleTable `json:"tables"`
}
VisibleSchema is the schema shown to the learner.
type VisibleTable ¶
type VisibleTable struct {
Name string `json:"name"`
Columns []VisibleColumn `json:"columns"`
}
VisibleTable is one table in the visible schema.