Skip to main content

measure

Function measure 

Source
pub fn measure(
    ctx: &Context,
    decl: &Declarations,
    suite: &EconomicsSuite,
    measured_at: &str,
) -> Result<(EconomicsContextRun, Vec<String>), String>
Expand description

Measure a context suite over every seed, as one record. Seeds the compiler refuses are kept in the record’s refused list, each with the compiler’s reason, and returned beside it as well so that the caller can report them: a ratio over the seeds that compiled must never be read as one over every seed the suite names.

The record names the commit it was measured at, the tokenizer, the methodology version and the digest of the suite’s freshness inputs, so a later read can tell whether it still describes the tree. Only a repository without a HEAD commit, or a git that cannot list the inputs, fails the whole measurement.

use majordomus_cli::economics::context::{measure, tokenizer};
use majordomus_cli::synthetic::SyntheticRepository;
let repo = SyntheticRepository::small().unwrap();
std::fs::create_dir(repo.root().join("seeds")).unwrap();
std::fs::write(repo.root().join("seeds/I9001.yaml"), "").unwrap();
let git = |a: &[&str]| Command::new("git").arg("-C").arg(repo.root()).args(a).output();
git(&["init", "-q"]).unwrap();
git(&["add", "-A"]).unwrap();
git(&["-c", "user.email=t@example.com", "-c", "user.name=t", "commit", "-qm", "i"]).unwrap();

let ctx = repo.context().unwrap();
let (run, errors) = measure(&ctx, &decl, &suite, "2026-09-24T00:00:00Z").unwrap();
assert!(run.seeds.is_empty(), "a refused seed is not measured");
assert!(errors.len() == 1 && errors[0].starts_with("I9001: "), "it is reported beside it");
assert_eq!(run.refused, errors, "and named in the record with its reason, never dropped");
assert_eq!((run.suite.as_str(), run.suite_version, run.methodology), ("context", 2, 3));
assert_eq!(run.tokenizer, tokenizer());
assert!(!run.repository.dirty, "measured at the commit it names");