pub struct Case {
pub name: String,
pub description: String,
pub severity: Severity,
pub request: Request,
pub response: Option<Response>,
pub context: Context,
pub expected_rule_id: Option<String>,
pub log_path: Option<PathBuf>,
pub fixture_dir: PathBuf,
}Expand description
One bundled (or user-supplied) failure case.
Construct via Case::load; do not deserialise directly because
the loader populates fixture_dir and log_path from the on-disk
layout, which serde alone cannot do.
Fields§
§name: StringStable identifier; matches the fixture directory name.
description: StringOne-sentence description of what the fixture demonstrates.
severity: SeverityCustomer-facing severity tag. Not consumed by rules.
request: RequestHTTP request bytes captured for this case.
response: Option<Response>HTTP response bytes, if any. None means the case captures a
pre-response failure (typical for timeouts).
context: ContextFree-form context the rules consume.
expected_rule_id: Option<String>Ground-truth label: the rule that should fire as primary on
this case, or None if the case must remain unclassified.
Used by tests/calibration.rs and tests/calibration_regression.rs
as the single source of truth. Optional on disk; cases without
a label are excluded from the calibration corpus.
log_path: Option<PathBuf>Path to a sibling server.log, if present. Populated by
Case::load; not part of case.json on disk.
fixture_dir: PathBufDirectory containing the loaded case.json. Populated by
Case::load; used to resolve secret_path and to walk
sibling files (server.log, secret.txt).
Implementations§
Source§impl Case
impl Case
Sourcepub fn load(
name_or_path: &str,
fixtures_root: &Path,
) -> Result<Self, CaseLoadError>
pub fn load( name_or_path: &str, fixtures_root: &Path, ) -> Result<Self, CaseLoadError>
Load a case by name or by path.
The lookup order is:
- If
name_or_pathpoints at an existing file, load that file. - If it points at an existing directory, load
<dir>/case.json. - Otherwise treat it as a name and resolve against
<fixtures_root>/cases/<name>/case.jsonfirst, then<fixtures_root>/cases/_negatives/<name>/case.json.
The third step is what lets api-debug-lab diagnose upstream_401 find a negative fixture without the caller having
to type the underscore-prefix path.
On success, fixture_dir is set to the directory containing
the loaded case.json and log_path is set when a sibling
server.log exists.
§Examples
use api_debug_lab::Case;
use std::path::Path;
let case = Case::load("auth_missing", Path::new("fixtures"))?;
assert_eq!(case.name, "auth_missing");Sourcepub fn load_log(&self) -> Option<String>
pub fn load_log(&self) -> Option<String>
Read the sibling server.log if one is present.
Returns None for cases that do not bundle a log. Reading is
lazy: rules that do not consult logs (e.g. auth_missing) pay
no I/O cost.
Sourcepub fn load_secret(&self) -> Option<Vec<u8>>
pub fn load_secret(&self) -> Option<Vec<u8>>
Read the webhook signing secret (fixture_dir/<secret_path>).
Returns None if the case has no webhook context or if the
file cannot be read. The trailing newline (if any) is stripped
so the secret bytes are exactly what the sender used.