Skip to main content

record

Function record 

Source
pub fn record(root: &Path, req: &RecordRequest) -> Result<RecordOutcome, Error>
Expand description

Read the runs a request names, stamp each result with provenance, and merge into the ledger of root.

It decides nothing: a case that failed is a case the runner said failed. Every refusal comes before any write: a request naming no report, a tree with no commit, a measurement of a report not given, of another producer, of another commit or of other bytes, a local or release measurement that names no report, a CI report without a measurement, a malformed report (refused rather than partly read), a coverage summary of another schema, and a run-record path that is a directory or a ledger.

Each execution carries its report’s measured tree, or unknown without one, and the recording is returned as an EvidenceRunRecord in RecordOutcome::run_record.

Because it merges, a later partial run updates only what it ran:

use majordomus_cli::evidence::{record, Ledger, Origin, Outcome, RecordRequest};

let reports = tempfile::tempdir().unwrap();
let suite = |name: &str, rows: &str| {
    let p = reports.path().join(name);
    std::fs::write(&p, rows).unwrap();
    RecordRequest { suite: Some(p), crate_output: None, ..RecordRequest::new(Origin::Local) }
};

let both = suite("all.tsv", "07_scope\tok\t1\tparallel\n08_other\tok\t2\tparallel\n");
assert_eq!(record(root.path(), &both).unwrap().recorded, 2);

let again = suite("one.tsv", "07_scope\tFAIL\t9\tserial\n");
assert_eq!(record(root.path(), &again).unwrap().recorded, 1);

let ledger = Ledger::load(root.path()).unwrap();
assert_eq!(ledger.latest("suite:07_scope").unwrap().outcome, Outcome::Fail);
assert_eq!(
    ledger.latest("suite:08_other").unwrap().outcome,
    Outcome::Pass,
    "the second run must not erase evidence it never measured",
);

// a malformed line is refused, not skipped: an under-recorded run would report
// `not run` for a test that ran
let short = suite("bad.tsv", "07_scope\tok\t12\n");
let refused = record(root.path(), &short).unwrap_err().to_string();
assert!(refused.contains("field(s)"), "{refused}");