use super::*;
#[test]
fn selection_guidance_explains_checkbox_opt_in() {
assert!(REQUEST_USER_INPUT_LINE.contains("multi_select: true"));
assert!(REQUEST_USER_INPUT_LINE.contains("radio-button"));
}
/// Universal rules have one home in Runtime Guidance (or the shared
/// contract). Compose every static profile with each tool-guidance variant
/// and the Harness Limits section, and check each rule marker lands once.
#[test]
fn universal_rules_have_one_home_across_composed_prompt_sections() {
use crate::config::types::SystemPromptMode;
use crate::prompts::harness_limits::upsert_harness_limits_section;
use crate::prompts::static_prompts::static_profile_prompt;
use crate::prompts::system::PLANNING_WORKFLOW_READ_ONLY_NOTICE_LINE;
let shell = ResolvedShellPromptProfile::UnixLike;
let execution_tools = [
TOOL_EXEC_COMMAND,
TOOL_WRITE_STDIN,
TOOL_APPLY_PATCH,
TOOL_CODE_SEARCH,
TOOL_TASK_TRACKER,
TOOL_START_PLANNING,
TOOL_REQUEST_USER_INPUT,
]
.map(str::to_owned)
.to_vec();
let planning_tools = [
TOOL_EXEC_COMMAND,
TOOL_WRITE_STDIN,
TOOL_CODE_SEARCH,
TOOL_GREP_FILE,
TOOL_TASK_TRACKER,
TOOL_REQUEST_USER_INPUT,
]
.map(str::to_owned)
.to_vec();
let mut minimal_planning =
generate_tool_guidelines_with_capabilities(&planning_tools, None, shell, ToolGuidanceProfile::Minimal, false);
append_minimal_planning_addendum(&mut minimal_planning, &ToolPresence::of(&planning_tools));
let variants = [
("default", generate_tool_guidelines_for_profile(&execution_tools, None, shell, true), false),
(
"minimal",
generate_tool_guidelines_with_capabilities(
&execution_tools,
None,
shell,
ToolGuidanceProfile::Minimal,
true,
),
false,
),
("default planning", generate_runtime_tool_guidelines_for_profile(&planning_tools, true, shell), true),
("minimal planning", minimal_planning, true),
];
// Each marker names one universal rule that lives in Runtime Guidance
// or the shared contract and must not be restated by tool sections.
let markers = [
"Never claim a check passed",
"Diagnose failures and change approach",
"Treat empty searches as evidence",
"check an optional tool once",
"additional_permissions",
"never bypass safeguards",
"Prefer skills and tool search",
"Across compaction",
];
for mode in [
SystemPromptMode::Default,
SystemPromptMode::Minimal,
SystemPromptMode::Lightweight,
SystemPromptMode::Specialized,
] {
for (variant, guidance, planning) in &variants {
let mut prompt = static_profile_prompt(mode).to_owned();
if *planning {
prompt.push_str("\n\n");
prompt.push_str(PLANNING_WORKFLOW_READ_ONLY_NOTICE_LINE);
}
prompt.push_str(guidance);
upsert_harness_limits_section(&mut prompt, 600, 2);
for marker in markers {
assert_eq!(
prompt.matches(marker).count(),
1,
"{mode:?} with {variant} tool guidance should state {marker:?} exactly once"
);
}
let start_planning_mentions = prompt.matches("start_planning").count();
assert_eq!(start_planning_mentions, usize::from(!*planning), "{mode:?} with {variant} tool guidance");
}
}
}
/// The `request_user_input` threshold is stated by the planning notice. A
/// second, weaker threshold in the Active Tools section gives the model two
/// different rules for the same tool in one prompt.
#[test]
fn request_user_input_threshold_has_one_home_in_the_planning_prompt() {
use crate::config::types::SystemPromptMode;
use crate::prompts::static_prompts::static_profile_prompt;
use crate::prompts::{RuntimePromptContract, append_runtime_mode_sections};
let shell = ResolvedShellPromptProfile::UnixLike;
let planning_tools = vec![
TOOL_EXEC_COMMAND.to_owned(),
TOOL_REQUEST_USER_INPUT.to_owned(),
TOOL_TASK_TRACKER.to_owned(),
];
let minimal_planning =
generate_tool_guidelines_with_capabilities(&planning_tools, None, shell, ToolGuidanceProfile::Minimal, true);
for (variant, guidance) in [
("default planning", generate_runtime_tool_guidelines_for_profile(&planning_tools, true, shell)),
("minimal planning", minimal_planning),
] {
// Compose the real planning prompt: the planning notice carries the
// threshold, and the tool section must not restate a competing one.
let mut prompt = static_profile_prompt(SystemPromptMode::Default).to_owned();
append_runtime_mode_sections(
&mut prompt,
RuntimePromptContract {
full_auto: false,
planning_active: true,
request_user_input_enabled: true,
},
);
prompt.push_str(&guidance);
// The tool section must not state a second, competing threshold.
assert!(
!guidance.contains("only for material blockers remaining after repository exploration"),
"{variant} restates the request_user_input threshold"
);
// The planning notice owns the threshold, so exactly one statement of
// it may reach the model. The tool section may narrow it to blockers
// that exploration did not resolve, but must not introduce a second
// rule.
assert_eq!(
prompt.matches("`request_user_input` only for a critical blocker").count(),
1,
"{variant}: the planning notice must own the request_user_input threshold"
);
assert!(
!guidance.contains("`request_user_input` only for a critical blocker"),
"{variant} restates the notice threshold"
);
}
}
#[test]
fn documentation_profile_respects_context_tokens_and_known_cost() {
assert_eq!(ToolGuidanceProfile::resolve(32_000, 100, 1000, None, None), ToolGuidanceProfile::Minimal);
assert_eq!(ToolGuidanceProfile::resolve(1_000_000, 100, 1000, None, Some(0.0)), ToolGuidanceProfile::Default);
assert_eq!(ToolGuidanceProfile::resolve(1_000_000, 1001, 1000, None, None), ToolGuidanceProfile::Minimal);
assert_eq!(
ToolGuidanceProfile::resolve(1_000_000, 1000, 2000, Some(0.00001), Some(0.001)),
ToolGuidanceProfile::Minimal
);
}
#[test]
fn minimal_and_default_tool_guidance_snapshots() {
let tools = vec![TOOL_READ_FILE.to_owned()];
let minimal = generate_tool_guidelines_with_capabilities(
&tools,
None,
ResolvedShellPromptProfile::UnixLike,
ToolGuidanceProfile::Minimal,
false,
);
assert_eq!(
minimal,
"\n\n## Active Tools\n- `verify: [skip Markdown lint if unavailable]`: report skipped; review diff/links without installing tools. Lint errors remain failures.\n- Capabilities: read-only. Analyze and search, but do not modify files or run shell commands.\n- Use available read-only repository tools for browsing; do not modify files."
);
let default = generate_tool_guidelines_with_capabilities(
&tools,
None,
ResolvedShellPromptProfile::UnixLike,
ToolGuidanceProfile::Default,
false,
);
assert_eq!(
default,
"\n\n## Active Tools\n- `verify: [skip Markdown lint if unavailable]`: report skipped; review diff/links without installing tools. Lint errors remain failures.\n- Capabilities: read-only. Analyze and search, but do not modify files or run shell commands.\n- Use available read-only repository tools for browsing; do not modify files.\n- Batch independent read-only calls; use bounded `read_file` ranges, order dependencies, serialize mutations; narrow the range on `line_truncated`; prefer wider windows and reuse evidence over overlapping slices."
);
}