use super::{fake_litany, model, prepared, signed, world};
use crate::boundary::Action;
use crate::cli_outbound::Cli;
use crate::opslog;
use crate::test_support::engine;
use std::fs;
use tempfile::tempdir;
#[test]
fn the_spend_ceiling_refuses_the_fire_and_says_so_on_the_trail() {
let bin = tempdir().unwrap();
let w = world();
fs::create_dir_all(&w.roots.yog_state).unwrap();
fs::write(
w.roots.ui_json(),
r#"{"v":1,"prices":{"anthropic":{"opus":{"input":1}}},"ceiling":0}"#,
)
.unwrap();
let (_c, m) = model(&w);
let litany = fake_litany(bin.path());
let deps = signed(m.boundary_deps(&litany, &Cli::new("/no/bl")));
let action = Action::Prompt {
prepared: prepared(&w),
goal: "go".into(),
seed: Some(7),
};
let err = engine::act(&m, &deps, "T3", &action).unwrap_err();
assert!(err.contains("spend ceiling reached"), "{err}");
let ops = opslog::tail(&w.roots.yog_state, 4);
let last = ops.last().expect("the refusal is on the trail");
assert_eq!(last.ts, "T3");
assert_eq!(last.argv.first().map(String::as_str), Some("yog-step"));
assert!(
last.argv.iter().any(|a| a == "ceiling"),
"the row names the gate: {:?}",
last.argv
);
assert!(
!last.argv.iter().any(|a| a == "prompt"),
"nothing was spawned: {:?}",
last.argv
);
}
#[test]
fn spend_in_another_workspace_refuses_a_fire_into_an_idle_one() {
let bin = tempdir().unwrap();
let w = world();
let step = w
.ws_spare
.join("steps")
.join("20260101T000000Z-x")
.join("001");
fs::create_dir_all(&step).unwrap();
fs::write(
step.join("response.json"),
r#"{"type":"usage","input_tokens":3000000}"#,
)
.unwrap();
fs::write(step.join("request.json"), r#"{"model":"opus"}"#).unwrap();
fs::write(
w.roots.ui_json(),
r#"{"v":1,"prices":{"anthropic":{"opus":{"input":1}}},"ceiling":2}"#,
)
.unwrap();
let (_c, m) = model(&w);
let deps = signed(m.boundary_deps(&fake_litany(bin.path()), &Cli::new("/no/bl")));
let action = Action::Prompt {
prepared: prepared(&w),
goal: "go".into(),
seed: Some(7),
};
let err = engine::act(&m, &deps, "T3", &action).unwrap_err();
assert!(
err.contains("$3.00"),
"the sibling's spend is the figure: {err}"
);
}