pub struct TestCase {
pub name: String,
pub skill: PathBuf,
pub input: String,
pub user: Option<SimulatedUser>,
pub mocks: Vec<MockDecl>,
pub spy: bool,
pub evals: Vec<Eval>,
}Expand description
One test case.
This type is the source of truth for the input contract
(schemas/case.schema.json): the shape a --case-json payload — and the
SDKs’ generated case models — must have. Serialization skips
absent/default fields so the canonical JSON form is minimal; the SDK case
builders emit that same form (pinned by the kitchen-sink golden in
tests/fixtures/contract/).
Fields§
§name: StringHuman-readable name (defaults to the file stem when loaded from a file).
skill: PathBufPath to the skill directory under test, relative to the test-case file.
input: StringThe initial data/prompt handed to the skill as the first user message.
user: Option<SimulatedUser>Present for multi-turn cases; absent for single-turn.
mocks: Vec<MockDecl>Mock/spy declarations for this case: a declaration with a stub/deny/
rewrite action intercepts matching tool calls; one without observes
only. called/not_called evals reference these by name.
spy: boolRecord every tool call through the mock/spy channel even with no
mocks declared, so code-level consumers (the SDKs’ spies) get records.
Implied whenever mocks is non-empty.
evals: Vec<Eval>The evals that decide whether this case passes. Must be non-empty.
Implementations§
Source§impl TestCase
impl TestCase
Sourcepub fn load(path: &Path) -> Result<Self>
pub fn load(path: &Path) -> Result<Self>
Load a test case from a YAML file. The name defaults to the file stem
and skill is resolved relative to the file’s directory.
§Errors
Error::Io if the file cannot be read, Error::Yaml on parse
failure, and Error::Invalid if the case is internally inconsistent.
Sourcepub fn from_json(json: &str, base_dir: &Path) -> Result<Vec<Self>>
pub fn from_json(json: &str, base_dir: &Path) -> Result<Vec<Self>>
Parse one or more fully-specified test cases from JSON — a single case
object or an array — the shape the language SDKs emit when a case is
built in code rather than written as YAML (skilltest run --case-json).
Unlike load these cases have no source file, so each is
finalized against base_dir (typically the working directory): a
relative skill resolves there, and an unnamed case defaults to case
(suffixed with its index when several are unnamed, keeping report keys
distinct).
§Errors
Error::Invalid if the JSON does not parse into test cases, or if any
case is internally inconsistent.
Sourcepub fn finalize(&mut self, base_dir: &Path, default_name: &str) -> Result<()>
pub fn finalize(&mut self, base_dir: &Path, default_name: &str) -> Result<()>
Finalize an in-memory case: default name to default_name when unset,
resolve a relative skill against base_dir, and validate. Shared by
load (anchored at the file’s directory) and
from_json (anchored at the working directory, since
a code-defined case has no file).
§Errors
Error::Invalid if the case is internally inconsistent.
Sourcepub fn is_multi_turn(&self) -> bool
pub fn is_multi_turn(&self) -> bool
Whether this is a multi-turn case (has a simulated user).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for TestCase
impl<'de> Deserialize<'de> for TestCase
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for TestCase
impl JsonSchema for TestCase
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more