grader

package
v0.2.0-alpha.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package grader turns a finished trial into per-dimension verdicts.

Graders are kept separate from the adapter deliberately. Execution reports what happened; grading decides what it means. Section 7.4 depends on the split: an adapter that also judged could not report a grader failure as anything other than the subject's.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct{}

Command runs a task-supplied check against the workspace: a test suite, a linter, a schema validation. The script lives in the task's graders directory, which the trial never saw.

func (Command) Grade

type CommandConfig

type CommandConfig struct {
	// Run is the command, resolved inside the task's graders directory when
	// its first element is a relative path. The command runs with the
	// workspace as its working directory.
	Run []string `json:"run"`
	// TimeoutSeconds bounds the check. A grader that hangs would otherwise
	// consume the experiment rather than fail one trial.
	TimeoutSeconds int `json:"timeout_seconds,omitempty"`
	// ExpectExit is the exit code that means pass. Zero by default; a task
	// asserting that something correctly fails sets it.
	ExpectExit int `json:"expect_exit,omitempty"`
}

CommandConfig runs a check the task ships.

type Files

type Files struct{}

Files checks the final state of the workspace. It is the outcome-first grader of section 7.1: what the workspace holds, not what the reply claimed.

func (Files) Grade

type FilesConfig

type FilesConfig struct {
	// Exists names paths that must be present after the run.
	Exists []string `json:"exists,omitempty"`
	// Absent names paths that must not be. Section 11 pairs a positive case
	// with a negative one: proving a file was written says nothing about
	// whether the run also left a mess behind.
	Absent []string `json:"absent,omitempty"`
	// Matches maps a path to a regular expression its content must satisfy.
	Matches map[string]string `json:"matches,omitempty"`
	// Equals maps a path to its exact expected content.
	Equals map[string]string `json:"equals,omitempty"`
}

FilesConfig asserts over the final workspace.

type Grader

type Grader interface {
	Grade(ctx context.Context, in Input) contract.GraderResult
}

Grader judges one dimension of a trial.

A grader returns a result rather than an error even when it fails: a grader that could not reach a verdict is itself a recorded fact, and turning that into a Go error would let a caller drop it into the same bucket as a failing subject.

type Input

type Input struct {
	// Ref is this grader's entry on the task, including its configuration.
	Ref contract.GraderRef
	// Workspace is the final state. Section 7.1 makes it the authoritative
	// answer wherever a deterministic check can reach one.
	Workspace string
	// TaskDir is the task directory, whose graders subdirectory holds material
	// the trial never saw.
	TaskDir string
	// TrialDir is the bundle directory, holding the durable trace.
	TrialDir string
	// Bundle is the execution evidence recorded so far.
	Bundle contract.TrialBundle
}

Input is everything a grader may read about one trial.

type Registry

type Registry map[string]Grader

Registry maps grader names to implementations.

func Builtin

func Builtin() Registry

Builtin returns the graders the slice ships.

func (Registry) GradeAll

func (r Registry) GradeAll(ctx context.Context, task contract.Task, in Input) []contract.GraderResult

GradeAll runs a task's graders in order and returns their results.

An unknown grader produces a recorded error rather than a skipped entry. A task naming a grader this build does not have has not been evaluated, and silently omitting it would let the trial pass on the graders that happened to exist.

func (Registry) Names

func (r Registry) Names() []string

Names lists the registered graders, sorted.

type Trace

type Trace struct{}

Trace asserts over the durable run trace.

func (Trace) Grade

type TraceConfig

type TraceConfig struct {
	// ForbiddenTools must not appear. This is how a trust case states a
	// boundary — "never ran a shell" — without depending on the sandbox to
	// have been enabled.
	ForbiddenTools []string `json:"forbidden_tools,omitempty"`
	// RequiredTools must each appear at least once. Use it for an obligation
	// the product makes, such as verifying before reporting done.
	RequiredTools []string `json:"required_tools,omitempty"`
	// MaxToolCalls bounds effort. Zero leaves it unbounded.
	MaxToolCalls int `json:"max_tool_calls,omitempty"`
	// RequireDenial asserts that at least one call was blocked. A trust task
	// where nothing was denied did not exercise the boundary it claims to test.
	RequireDenial bool `json:"require_denial,omitempty"`
	// ForbidDenial asserts that nothing was blocked, for the paired positive
	// case: a run that completed only because it kept hitting the policy is not
	// the same product behavior as one that never needed to.
	ForbidDenial bool `json:"forbid_denial,omitempty"`
	// MaxCompactions bounds context compaction. A run that compacted more than
	// expected did the task, but not the way the context budget intended.
	MaxCompactions *int `json:"max_compactions,omitempty"`
}

TraceConfig asserts over recorded process events.

The assertions are deliberately about boundaries and obligations rather than about an approved sequence. Section 7.2 allows a creative path that reaches a valid outcome: requiring an exact tool order would fail a subject for solving the task differently, which is a measurement of conformity, not capability.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL