use std::path::Path;
const TOOL_LOOP: &str = "src/brain/agent/service/tool_loop.rs";
fn code_occurrences(text: &str, needle: &str) -> Vec<usize> {
text.lines()
.enumerate()
.filter(|(_, line)| line.split("//").next().unwrap_or("").contains(needle))
.map(|(i, _)| i + 1)
.collect()
}
#[test]
fn the_tool_loop_reaches_the_continuation_builder_exactly_once() {
let text = std::fs::read_to_string(Path::new(TOOL_LOOP))
.unwrap_or_else(|e| panic!("{TOOL_LOOP} must be readable ({e}); did the module move?"));
let direct = code_occurrences(&text, "build_continuation(");
assert_eq!(
direct.len(),
1,
"{TOOL_LOOP} calls build_continuation on {} lines ({:?}), but the loop must reach it \
only through continuation_prompt. A site calling it directly builds a valid prompt \
with every rider missing, starting with the #125 skill stamp, and no unit test sees it.",
direct.len(),
direct
);
}
#[test]
fn the_single_path_is_continuation_prompt_and_it_carries_the_stamp() {
let text = std::fs::read_to_string(Path::new(TOOL_LOOP))
.unwrap_or_else(|e| panic!("{TOOL_LOOP} must be readable ({e}); did the module move?"));
assert!(
!code_occurrences(&text, "async fn continuation_prompt(").is_empty(),
"the shared construction path is gone from {TOOL_LOOP}; the guard above is \
measuring nothing"
);
assert!(
!code_occurrences(&text, "append_skill_stamp(").is_empty(),
"the shared path no longer appends the skill stamp, so no compaction carries it"
);
assert!(
!code_occurrences(&text, "active_skills_for_session(").is_empty(),
"the stamp is no longer fed from the session's active-skill registry, so it \
would render empty for every session"
);
}