use std::fs;
use zagens_core::engine::tool_parser;
const ENGINE_SOURCES: &[&str] = &[
include_str!("../../core/src/engine/streaming.rs"),
include_str!("../src/core/engine/streaming.rs"),
include_str!("../src/core/engine/dispatch.rs"),
include_str!("../src/core/engine/tool_setup.rs"),
include_str!("../src/core/engine/tool_execution/mod.rs"),
include_str!("../src/core/engine/tool_execution/exec.rs"),
include_str!("../src/core/engine/tool_catalog.rs"),
include_str!("../src/core/engine/approval.rs"),
include_str!("../src/core/engine/capacity_flow/mod.rs"),
include_str!("../src/core/engine/lsp_hooks.rs"),
include_str!("../src/core/engine/turn_loop/tool_plans_exec.rs"),
];
fn any_engine_source_contains(needle: &str) -> bool {
ENGINE_SOURCES.iter().any(|src| src.contains(needle))
}
const EXPECTED_START_MARKERS: &[&str] = &[
"[TOOL_CALL]",
"<deepseek:tool_call",
"<tool_call",
"<invoke ",
"<function_calls>",
];
const EXPECTED_END_MARKERS: &[&str] = &[
"[/TOOL_CALL]",
"</deepseek:tool_call>",
"</tool_call>",
"</invoke>",
"</function_calls>",
];
#[test]
fn engine_keeps_known_fake_wrapper_start_markers() {
for marker in EXPECTED_START_MARKERS {
let needle = format!("\"{marker}\"");
assert!(
any_engine_source_contains(&needle),
"no engine source file still mentions start marker `{marker}` — \
protocol scrubbing may have regressed. Searched for {needle:?} \
across engine.rs and engine/* submodules."
);
}
}
#[test]
fn engine_keeps_known_fake_wrapper_end_markers() {
for marker in EXPECTED_END_MARKERS {
let needle = format!("\"{marker}\"");
assert!(
any_engine_source_contains(&needle),
"no engine source file still mentions end marker `{marker}` — \
protocol scrubbing may have regressed. Searched for {needle:?} \
across engine.rs and engine/* submodules."
);
}
}
#[test]
fn engine_marker_counts_stay_paired() {
assert_eq!(EXPECTED_START_MARKERS.len(), EXPECTED_END_MARKERS.len());
assert!(any_engine_source_contains("TOOL_CALL_START_MARKERS"));
assert!(any_engine_source_contains("TOOL_CALL_END_MARKERS"));
}
#[test]
fn engine_emits_compact_fake_wrapper_notice() {
assert!(
any_engine_source_contains("FAKE_WRAPPER_NOTICE"),
"no engine source file references the protocol-recovery notice constant"
);
assert!(
any_engine_source_contains("API tool channel"),
"the protocol-recovery notice should mention the API tool channel"
);
}
#[test]
fn legacy_parser_extracts_bracket_tool_call() {
let result = tool_parser::parse_tool_calls(
"intro [TOOL_CALL]\n{\"tool\":\"x\",\"args\":{}}\n[/TOOL_CALL]",
);
assert_eq!(result.tool_calls.len(), 1);
assert_eq!(result.tool_calls[0].name, "x");
assert_eq!(result.clean_text, "intro");
}
#[test]
fn legacy_parser_extracts_invoke_block() {
let result = tool_parser::parse_tool_calls(
"before <invoke name=\"do_thing\"><parameter name=\"k\">v</parameter></invoke> after",
);
assert_eq!(result.tool_calls.len(), 1);
assert_eq!(result.tool_calls[0].name, "do_thing");
}
#[test]
fn legacy_parser_does_not_execute_function_calls_wrapper() {
let raw = "narrative <function_calls>\n{\"name\":\"x\",\"input\":{}}\n</function_calls> end";
let result = tool_parser::parse_tool_calls(raw);
assert!(
result.tool_calls.is_empty(),
"function_calls wrapper must not be parsed as a real tool call: {:?}",
result.tool_calls
);
}
#[test]
fn legacy_parser_has_marker_helper_for_legacy_shapes_only() {
assert!(tool_parser::has_tool_call_markers(
"noise [TOOL_CALL]x[/TOOL_CALL]"
));
assert!(tool_parser::has_tool_call_markers(
"noise <invoke name=\"x\"></invoke>"
));
assert!(!tool_parser::has_tool_call_markers(
"noise <function_calls>{}</function_calls>"
));
}
#[test]
fn engine_source_file_still_exists_and_is_non_trivial() {
let total: u64 = ENGINE_SOURCES.iter().map(|s| s.len() as u64).sum();
assert!(
total > 10_000,
"engine protocol sources are unexpectedly small ({total} bytes); update ENGINE_SOURCES"
);
let metadata = fs::metadata("src/core/engine.rs").expect("engine.rs must exist next to tests");
assert!(metadata.len() > 1_000, "engine.rs shell missing or empty");
}