open-standards/jcp/jcp-rs/crates/jcp-cli/tests/demo.rs
Transaction Science 667d75916d jcp-cli: the meter line names the rung and the probe's own grade
The demo printed `meter HwShunt backend → 2388 µJ probe [ModelBased]
(estimated, and says so)` here: the rung's best grade (Meter::provenance)
beside a probe the model graded, because the 20,000-addition probe was
too short for the per-process counter to advance. The module docs and
jcp/README.md called the line "a real reading" / "its one measurement".

The line now names the rung (Meter::rung) and prints only the probe's
figure at the grade the meter gave it, "a hardware reading of the probe"
or "an estimate: no counter read the probe". The probe is a fixed
2,000,000-step loop, long enough for a live counter to read it (here:
`ProcessEnergy rung → 44215 µJ probe [HwShunt]`). The docs say what the
line is.

Test: the_meter_line_names_only_the_probes_grade (exactly one grade
label on the line, and it is the bracketed probe grade) fails on the old
line and passes now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-10 18:08:00 -04:00

37 lines
2.2 KiB
Rust

//! The `jcp` demo, run as a user runs it: the receipt it seals for its last
//! allowed row is over a scripted cost no tool spent, so the line it prints
//! for that receipt must grade it `Estimator`, never `HwShunt`.
use std::process::Command;
#[test]
fn the_demo_receipt_is_graded_an_estimate() {
let out = Command::new(env!("CARGO_BIN_EXE_jcp")).output().expect("run the jcp binary");
assert!(out.status.success(), "jcp failed: {}", String::from_utf8_lossy(&out.stderr));
let stdout = String::from_utf8(out.stdout).expect("utf-8 output");
eprintln!("{stdout}");
let receipt = stdout.lines().find(|l| l.trim_start().starts_with("receipt")).expect("a receipt line");
assert!(receipt.contains("· Estimator ·"), "the scripted cost's receipt is not graded an estimate: {receipt}");
assert!(!receipt.contains("HwShunt"), "the scripted cost's receipt claims a hardware reading: {receipt}");
assert!(receipt.ends_with("verified true"), "{receipt}");
assert!(stdout.contains("budget-exceeded"), "the script no longer runs the budget out:\n{stdout}");
}
/// The `meter` line prints the probe's figure at the grade the meter gave
/// that probe, and no other grade beside it: a hardware rung whose probe came
/// back an estimate must not be labelled with the rung's best grade.
#[test]
fn the_meter_line_names_only_the_probes_grade() {
let out = Command::new(env!("CARGO_BIN_EXE_jcp")).output().expect("run the jcp binary");
assert!(out.status.success(), "jcp failed: {}", String::from_utf8_lossy(&out.stderr));
let stdout = String::from_utf8(out.stdout).expect("utf-8 output");
let line = stdout.lines().find(|l| l.trim_start().starts_with("meter")).expect("a meter line");
eprintln!("{line}");
let grades: Vec<&str> = ["HwShunt", "ModelBased", "Estimator"].into_iter().filter(|g| line.contains(g)).collect();
assert_eq!(grades.len(), 1, "the meter line names {grades:?}: {line}");
let grade = grades[0];
assert!(line.contains(&format!("[{grade}]")), "the grade printed is not the probe's: {line}");
if grade != "HwShunt" {
assert!(!line.contains("hardware-measured") && !line.contains("reading,"), "an estimate called a reading: {line}");
}
}