From 8afddb0632a795eb5bb3feb517eb85e9801bddbc Mon Sep 17 00:00:00 2001 From: dietrich ayala Date: Tue, 22 Sep 2026 15:19:25 +0200 Subject: [PATCH] Unit-test how absolute_real_model_run gets its candidate count The binary reads GENERA_CANDIDATES through a private batch_candidate_count() wrapper over orchestrate::candidate_count(); its test covers unset, 32, 0 and unparsable values, meeting the spec's step 2 test requirement. --- .../src/bin/absolute_real_model_run.rs | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/generation/src/bin/absolute_real_model_run.rs b/crates/generation/src/bin/absolute_real_model_run.rs index d8870a4..ed6c3e1 100644 --- a/crates/generation/src/bin/absolute_real_model_run.rs +++ b/crates/generation/src/bin/absolute_real_model_run.rs @@ -64,9 +64,14 @@ enum Provider { ClaudeCli(ClaudeCliClient), } +/// Reads `GENERA_CANDIDATES` via `generation::orchestrate::candidate_count`, default 8. +fn batch_candidate_count() -> usize { + generation::orchestrate::candidate_count() +} + fn main() -> Result<()> { let repo_root = repo_root(); - let candidate_count = generation::orchestrate::candidate_count(); + let candidate_count = batch_candidate_count(); let (provider, model_label) = if std::env::var("GENERA_PROVIDER").as_deref() == Ok("anthropic") { let client = match AnthropicClient::from_env() { @@ -352,3 +357,28 @@ fn main() -> Result<()> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + /// `GENERA_CANDIDATES` is process-global state, so every case lives in one `#[test]` + /// run sequentially -- two tests each mutating it could otherwise race under cargo's + /// default parallel test runner. + #[test] + fn candidate_count_reads_env_unset_valid_and_invalid() { + std::env::remove_var("GENERA_CANDIDATES"); + assert_eq!(batch_candidate_count(), 8); + + std::env::set_var("GENERA_CANDIDATES", "32"); + assert_eq!(batch_candidate_count(), 32); + + std::env::set_var("GENERA_CANDIDATES", "0"); + assert_eq!(batch_candidate_count(), 8); + + std::env::set_var("GENERA_CANDIDATES", "not-a-number"); + assert_eq!(batch_candidate_count(), 8); + + std::env::remove_var("GENERA_CANDIDATES"); + } +} -- 2.51.2