Skip to main content

run_profile_backtest

Function run_profile_backtest 

Source
pub fn run_profile_backtest(
    corpus: &[BacktestCase],
    profiles: &[AnalyzerProfile],
) -> Result<BacktestReport, BacktestError>
Expand description

Replay historical HAR cases against existing analyzer profiles.

§Errors

Returns BacktestError::EmptyCorpus when no cases are supplied, BacktestError::EmptyProfiles when no profiles are supplied, and BacktestError::Har when any HAR payload cannot be parsed.

§Example

use stygian_charon::AnalyzerProfile;
use stygian_charon::AnalyzerVersion;
use stygian_charon::BacktestCase;
use stygian_charon::run_profile_backtest;

let corpus = vec![BacktestCase {
    case_id: "fixture-a".to_string(),
    har_json: r#"{"log":{"version":"1.2","creator":{"name":"test","version":"0"},"entries":[{"startedDateTime":"2026-01-01T00:00:00Z","time":1,"request":{"method":"GET","url":"https://example.com","httpVersion":"HTTP/1.1","headers":[],"queryString":[],"cookies":[],"headersSize":-1,"bodySize":-1},"response":{"status":403,"statusText":"Forbidden","httpVersion":"HTTP/1.1","headers":[{"name":"cf-ray","value":"abc"}],"cookies":[],"content":{"size":0,"mimeType":"text/html","text":"Attention Required! | Cloudflare"},"redirectURL":"","headersSize":-1,"bodySize":-1},"cache":{},"timings":{"send":0,"wait":1,"receive":0}}]}}"#.to_string(),
}];

let profiles = vec![AnalyzerProfile {
    profile_id: "default".to_string(),
    analyzer_version: AnalyzerVersion::V1,
}];

let report = run_profile_backtest(&corpus, &profiles).unwrap();
assert_eq!(report.samples.len(), 1);