//! The cost table, swept for totality, and the one rule that lets a Mac's own//! measurement beat it.use std::collections::BTreeSet;usesuper::*;// ── totality ────────────────────────────────────────────────────────────────/// `JOB_KINDS` names EVERY variant.////// The `match` is the proof: adding a variant to [`JobKind`] without adding it/// here fails to compile, and the assertion below catches the other direction —/// a name left in the list after its variant went.#[test]fn every_job_kind_is_in_the_list() {fn seen(kind: JobKind) -> usize {match kind {JobKind::CodingSession => 0,JobKind::McpServer => 1,JobKind::IosSimulator => 2,JobKind::XcodebuildArchive => 3,JobKind::CargoBuild => 4,JobKind::AndroidEmulator => 5, } }let listed: BTreeSet<usize> = JOB_KINDS.iter().copied().map(seen).collect(); assert_eq!( listed.len(), JOB_KINDS.len(),"JOB_KINDS names a kind twice" ); assert_eq!( listed, (0..6).collect::<BTreeSet<usize>>(),"JOB_KINDS must name every JobKind exactly once — a kind with no entry \ is a job the budget would admit for free" );}#[test]fn every_job_costs_something_and_says_what_it_is() {for &kind in JOB_KINDS {let cost = cost(kind); assert!( cost.mem_gb > 0.0,"{kind:?} costs no memory — a free job is one the budget cannot hold back" ); assert!(!cost.label.is_empty(), "{kind:?} has no label to put in a sentence"); assert_eq!( cost.label.trim(), cost.label,"{kind:?}'s label is padded, and it is read inside a sentence" );// It is read as "a <label> needs 1.2", so it carries no article of its// own and no sentence punctuation. assert!( !cost.label.starts_with("a ") && !cost.label.starts_with("the "),"{kind:?}'s label brings its own article into a sentence that already has one" ); assert!( !cost.label.ends_with('.'),"{kind:?}'s label ends a sentence it is only part of" ); }}#[test]fn no_two_jobs_share_a_label() {let labels: BTreeSet<&str> = JOB_KINDS.iter().map(|&kind| label(kind)).collect(); assert_eq!( labels.len(), JOB_KINDS.len(),"two kinds with one label make two different refusals read the same" );}// ── the numbers ─────────────────────────────────────────────────────────────#[test]fn a_coding_session_costs_what_was_measured_of_claude() {// 365–582 MB resident across a working day, September 2026. assert_eq!(cost(JobKind::CodingSession).mem_gb, 0.6); assert_eq!(cost(JobKind::CodingSession).cores, Cores::Fixed(1));}#[test]fn an_archive_wants_every_core_the_mac_has() { assert_eq!(cost(JobKind::XcodebuildArchive).cores, Cores::All); assert_eq!(cores(JobKind::XcodebuildArchive, 1, 10), 10); assert_eq!(cores(JobKind::XcodebuildArchive, 1, 4), 4);}#[test]fn a_cargo_build_costs_per_job() { assert_eq!(mem_gb(JobKind::CargoBuild, 1, None), 3.0); assert_eq!(mem_gb(JobKind::CargoBuild, 4, None), 12.0);}#[test]fn the_mcp_servers_a_session_opens_are_counted() { assert_eq!(mem_gb(JobKind::McpServer, 0, None), 0.0); assert!((mem_gb(JobKind::McpServer, 8, None) - 2.4).abs() < 1e-9);}#[test]fn no_job_wants_more_cores_than_the_mac_has() {for &kind in JOB_KINDS {for cpu_count in [1, 4, 10, 16] {let wanted = cores(kind, 9, cpu_count); assert!( wanted <= cpu_count,"{kind:?} wanted {wanted} of {cpu_count} cores — a cost above the Mac's own \ count refuses every Mac forever instead of saying anything true" ); } }}#[test]fn nothing_costs_anything_when_nothing_is_asked_for() {for &kind in JOB_KINDS { assert_eq!(mem_gb(kind, 0, None), 0.0); assert_eq!(mem_gb(kind, -1, None), 0.0); assert_eq!(cores(kind, 0, 8), 0); }}// ── measurement beats the guess ─────────────────────────────────────────────#[test]fn one_reading_is_an_anecdote_and_does_not_move_the_cost() {let measured = Some(Measured { peak_gb: 0.1, samples: 1, }); assert_eq!(mem_gb(JobKind::CodingSession, 1, measured), 0.6);}#[test]fn two_readings_are_still_not_enough() {let measured = Some(Measured { peak_gb: 0.1, samples: 2, }); assert_eq!(mem_gb(JobKind::CodingSession, 1, measured), 0.6);}#[test]fn three_readings_replace_the_guess() {let measured = Some(Measured { peak_gb: 1.4, samples: MEASURED_MINIMUM_SAMPLES, }); assert!((mem_gb(JobKind::CodingSession, 1, measured) - 1.4).abs() < 1e-9);}#[test]fn a_measurement_wins_downwards_too() {// A Mac whose sessions really are small must not be refused work on the// strength of a number measured on somebody else's machine.let measured = Some(Measured { peak_gb: 0.3, samples: 12, }); assert!((mem_gb(JobKind::CodingSession, 2, measured) - 0.6).abs() < 1e-9);}#[test]fn a_measurement_is_never_blended_with_the_guess() {let measured = Some(Measured { peak_gb: 2.0, samples: MEASURED_MINIMUM_SAMPLES, });let answer = mem_gb(JobKind::CodingSession, 1, measured); assert_eq!( answer, 2.0,"the answer is the measurement or the default, never an average of the two — \ a blend is a third number nobody can point at" );}#[test]fn cores_are_configuration_and_measurement_does_not_correct_them() {// There is deliberately no `measured` argument here: a build that happened// to idle on one core is still a build that will take them all. assert_eq!(cores(JobKind::AndroidEmulator, 1, 16), 4);}// ── the ask ─────────────────────────────────────────────────────────────────#[test]fn a_coding_session_carries_the_servers_it_opens() {let ask = Ask::coding_session(3);// 0.6 for the agent, 0.3 each for three servers. assert!((ask.mem_gb(None) - 1.5).abs() < 1e-9);}#[test]fn a_session_with_no_servers_costs_only_the_agent() { assert!((Ask::coding_session(0).mem_gb(None) - 0.6).abs() < 1e-9);}#[test]fn a_negative_server_count_is_no_servers_rather_than_a_discount() { assert!((Ask::coding_session(-4).mem_gb(None) - 0.6).abs() < 1e-9);}#[test]fn a_measured_peak_already_holds_the_servers_so_they_are_not_added_twice() {// The sampler sums a session's WHOLE process tree, and the servers run in// it — adding the table's guess on top would charge for them again.let measured = Some(Measured { peak_gb: 1.9, samples: 6, }); assert!((Ask::coding_session(5).mem_gb(measured) - 1.9).abs() < 1e-9);}#[test]fn an_unmeasured_mac_still_counts_the_servers() {let measured = Some(Measured { peak_gb: 1.9, samples: 2, }); assert!((Ask::coding_session(2).mem_gb(measured) - 1.2).abs() < 1e-9);}#[test]fn an_ask_is_named_by_what_it_is_for() { assert_eq!(Ask::coding_session(4).label(), "coding_session"); assert_eq!(Ask::one(JobKind::IosSimulator).label(), "ios_simulator"); assert_eq!(Ask { parts: Vec::new() }.label(), "job");}#[test]fn a_session_peak_does_not_correct_a_job_it_never_watched() {// The session host owns session pseudo-terminals and nothing else's, so a// simulator is costed from the table however well sessions are measured.let measured = Some(Measured { peak_gb: 0.2, samples: 40, }); assert_eq!(Ask::one(JobKind::IosSimulator).mem_gb(measured), 2.0);}// ── the budget ──────────────────────────────────────────────────────────────#[test]fn an_ordinary_mac_keeps_two_gigabytes_for_the_person_at_it() { assert_eq!(budget_gb(16.0, false), 14.0); assert_eq!(reserve_gb(false), RESERVE_GB);}#[test]fn the_mac_holding_the_served_file_keeps_four() { assert_eq!(budget_gb(16.0, true), 12.0); assert_eq!(reserve_gb(true), SERVING_RESERVE_GB);}#[test]fn a_mac_smaller_than_its_own_reserve_promises_nothing() { assert_eq!(budget_gb(3.0, true), 0.0); assert_eq!(budget_gb(0.0, false), 0.0);}#[test]fn what_is_free_is_the_budget_less_what_is_promised() { assert_eq!(free_gb(14.0, 5.0), 9.0);}#[test]fn a_mac_over_its_budget_has_zero_free_rather_than_a_negative_number() { assert_eq!(free_gb(14.0, 20.0), 0.0);}#[test]fn a_job_that_exactly_fills_the_budget_is_admitted() { assert!(admits(0.6, 0.6));}#[test]fn a_job_a_hair_over_is_refused() { assert!(!admits(0.6, 0.62));}#[test]fn a_subtraction_that_landed_short_in_the_sixteenth_decimal_still_admits() {// 14.0 - 13.4 is not 0.6 in binary floating point, and a queue stuck on// that is stuck on something nobody can see. assert!(admits(14.0 - 13.4, 0.6));}#[test]fn a_refusal_understates_the_room_and_overstates_the_cost() {// Both to nearest and a Mac with 0.55 free, refused for a 0.6 job, would// print "has 0.6 GB free; a coding session needs 0.6". assert_eq!(free_as_said(0.55), 0.5); assert_eq!(cost_as_said(0.51), 0.6); assert_eq!(free_as_said(14.0 - 13.8), 0.2); assert_eq!(cost_as_said(0.6 + 4.0 * 0.3), 1.8); assert_eq!(free_as_said(0.0), 0.0);}#[test]fn a_mac_with_nothing_free_admits_nothing() {for &kind in JOB_KINDS { assert!( !admits(0.0, Ask::one(kind).mem_gb(None)),"{kind:?} was admitted onto a Mac with no room" ); }}