use crate::brain::agent::service::fenced_command::narrates_unrun_shell_block;
const REPORTED: &str = "Queue locked: everything except #933/#1112. That's ten \
issues, fetching all specs fresh before planning:\n\n\
```bash\n\
cd ~/srv/rs/opencrabs && for n in 1176 1181; do gh api repos/o/r/issues/$n; done\n\
```";
#[test]
fn test_reported_turn_is_caught_on_structure_alone() {
assert!(
narrates_unrun_shell_block(REPORTED),
"#1194: a bash fence with a gh call is a command that did not run"
);
}
#[test]
fn test_command_behind_a_cd_prefix_is_found_by_its_real_program() {
assert!(narrates_unrun_shell_block(
"```bash\ncd /tmp && gh issue list --limit 5\n```"
));
assert!(narrates_unrun_shell_block(
"```sh\ncat log.txt | grep -c ERROR\n```"
));
assert!(narrates_unrun_shell_block(
"```console\n$ cargo test --all-features\n```"
));
}
#[test]
fn test_non_shell_fences_are_untouched() {
for block in [
"```rust\nlet out = git_status();\n```",
"```python\nsubprocess.run([\"git\", \"status\"])\n```",
"```json\n{\"cmd\": \"git status --short\"}\n```",
"```\ngit status --short\n```",
"```toml\ncommand = \"cargo build\"\n```",
] {
assert!(
!narrates_unrun_shell_block(block),
"#1194: non-shell fence flagged: {block:?}"
);
}
}
#[test]
fn test_shell_fence_without_a_known_program_is_untouched() {
for block in [
"```bash\nerror: could not compile `opencrabs`\n```",
"```bash\nexport RUST_LOG=debug\n```",
"```console\nhello world\n```",
] {
assert!(
!narrates_unrun_shell_block(block),
"#1194: shell fence with no known command flagged: {block:?}"
);
}
}
#[test]
fn test_bare_program_without_arguments_is_not_a_command_claim() {
assert!(!narrates_unrun_shell_block("```bash\nls\n```"));
assert!(narrates_unrun_shell_block("```bash\nls -la /tmp\n```"));
}
#[test]
fn test_unterminated_block_still_counts() {
assert!(narrates_unrun_shell_block(
"Here is the plan:\n\n```bash\ngit log --oneline -20"
));
}
#[test]
fn test_prose_alone_is_never_flagged() {
assert!(!narrates_unrun_shell_block(
"I ran git status and the tree is clean."
));
assert!(!narrates_unrun_shell_block(""));
}
#[test]
fn test_shell_keywords_do_not_hide_the_program() {
for block in [
"```bash\nfor n in 1 2; do gh api repos/o/r/issues/$n; done\n```",
"```bash\nif [ -f x ]; then cat x --number; fi\n```",
"```bash\nsudo systemctl restart opencrabs\n```",
] {
assert!(
narrates_unrun_shell_block(block),
"#1194: keyword hid the program: {block:?}"
);
}
}
#[test]
fn test_keyword_stripping_does_not_invent_commands() {
assert!(!narrates_unrun_shell_block(
"```bash\nthen else do done\n```"
));
assert!(!narrates_unrun_shell_block(
"```bash\necho \"run git status\" > notes.txt\n```"
));
}