use crate::brain::prompt_builder::{compiled_features, push_compiled_features};
#[test]
fn telegram_feature_is_compiled_in_test_build() {
let features = compiled_features();
assert!(
features.contains(&"telegram"),
"telegram should be in compiled features under --all-features; got {features:?}"
);
}
#[cfg(all(feature = "local-stt", feature = "local-tts"))]
#[test]
fn local_stt_and_tts_are_default_features_in_test_build() {
let features = compiled_features();
assert!(
features.contains(&"local-stt"),
"local-stt should surface so the agent knows STT is built in; got {features:?}"
);
assert!(
features.contains(&"local-tts"),
"local-tts should surface so the agent knows TTS is built in; got {features:?}"
);
}
#[test]
fn all_cargo_features_are_listed() {
use std::collections::BTreeSet;
use std::fs;
let cargo_toml = fs::read_to_string(concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml"))
.expect("Cargo.toml must be readable");
let features_block = cargo_toml
.split("[features]")
.nth(1)
.expect("Cargo.toml must have a [features] section")
.split("\n[")
.next()
.unwrap_or("");
let mut cargo_features: BTreeSet<String> = BTreeSet::new();
for line in features_block.lines() {
let line = line.trim();
if line.starts_with('#') || line.is_empty() {
continue;
}
if let Some((name, _)) = line.split_once('=') {
let name = name.trim();
if name.is_empty() || name == "default" {
continue;
}
cargo_features.insert(name.to_string());
}
}
let source = fs::read_to_string(concat!(
env!("CARGO_MANIFEST_DIR"),
"/src/brain/prompt_builder.rs"
))
.expect("prompt_builder.rs must be readable");
let fn_start = source
.find("fn compiled_features()")
.expect("compiled_features function must exist");
let fn_body = &source[fn_start..];
let fn_end = fn_body
.find("\n}\n")
.or_else(|| fn_body.find("\n}"))
.unwrap_or(fn_body.len());
let fn_body = &fn_body[..fn_end];
let mut source_features: BTreeSet<String> = BTreeSet::new();
for line in fn_body.lines() {
let trimmed = line.trim();
if trimmed.contains("cfg!(feature")
&& let Some(start) = trimmed.find('"')
&& let Some(end) = trimmed[start + 1..].find('"')
{
let name = &trimmed[start + 1..start + 1 + end];
source_features.insert(name.to_string());
}
}
let missing: Vec<&String> = cargo_features.difference(&source_features).collect();
assert!(
missing.is_empty(),
"compiled_features() source is missing cfg! branches for Cargo.toml [features]: {missing:?}. \
Add `if cfg!(feature = \"<name>\") {{ out.push(\"<name>\"); }}` to \
`compiled_features` in src/brain/prompt_builder.rs."
);
}
#[test]
fn push_compiled_features_lists_each_active_feature() {
let mut s = String::new();
push_compiled_features(&mut s);
for f in compiled_features() {
assert!(
s.contains(f),
"feature `{f}` is compiled in but missing from prompt output: {s}"
);
}
}
#[test]
fn push_compiled_features_tells_agent_to_use_built_ins() {
let mut s = String::new();
push_compiled_features(&mut s);
let lower = s.to_lowercase();
assert!(
lower.contains("use the built-in") || lower.contains("already works"),
"prompt must tell the agent to use built-ins, not re-implement; got: {s}"
);
assert!(
lower.contains("don't re-build") || lower.contains("don't re-implement"),
"prompt must explicitly forbid re-building; got: {s}"
);
}
#[test]
fn push_compiled_features_mentions_cargo_features_flag() {
let mut s = String::new();
push_compiled_features(&mut s);
assert!(
s.contains("--features"),
"prompt must mention the cargo --features flag so the agent \
routes 'feature not enabled' to a rebuild instead of new \
code; got: {s}"
);
}
#[test]
fn push_compiled_features_emits_nothing_when_no_features() {
if compiled_features().is_empty() {
let mut s = String::new();
push_compiled_features(&mut s);
assert!(s.is_empty(), "no features → no output; got: {s}");
}
}
#[test]
fn brain_preamble_has_self_awareness_directive() {
use crate::brain::prompt_builder::BRAIN_PREAMBLE;
assert!(
BRAIN_PREAMBLE.contains("SELF-AWARENESS"),
"preamble must include the SELF-AWARENESS section header so \
the agent treats the check-first rule as load-bearing, not \
buried prose"
);
}
#[test]
fn brain_preamble_tells_agent_to_check_tool_list_first() {
use crate::brain::prompt_builder::BRAIN_PREAMBLE;
let lower = BRAIN_PREAMBLE.to_lowercase();
assert!(
lower.contains("check your tool list") || lower.contains("check what you already have"),
"preamble must explicitly tell the agent to check available \
tools before proposing new implementations"
);
}
#[test]
fn brain_preamble_references_compiled_features_line() {
use crate::brain::prompt_builder::BRAIN_PREAMBLE;
assert!(
BRAIN_PREAMBLE.contains("Built-in features"),
"preamble must reference the Runtime Info line that lists \
compiled features so the agent knows where to look"
);
}
#[test]
fn brain_preamble_names_concrete_capabilities_users_might_ask_to_reimplement() {
use crate::brain::prompt_builder::BRAIN_PREAMBLE;
let lower = BRAIN_PREAMBLE.to_lowercase();
assert!(
lower.contains("stt"),
"STT must be named as a check-first example"
);
assert!(
lower.contains("tts"),
"TTS must be named as a check-first example"
);
}