use crate::domain::marker::{AGENTS_BEGIN, AGENTS_END};
#[must_use]
pub fn snippet() -> &'static str {
crate::embedded::SNIPPETS
.get_file("AGENTS-docs.md")
.and_then(include_dir::File::contents_utf8)
.unwrap_or_default()
}
#[must_use]
#[allow(
clippy::literal_string_with_formatting_args,
reason = "the braces are the block template's placeholder, not a formatting argument"
)]
pub fn render_block(docs_root: &str) -> String {
let body = snippet().replace("{docs_root}", docs_root);
let body = body.trim_end_matches('\n');
format!("{AGENTS_BEGIN}\n{body}\n{AGENTS_END}\n")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_block_carries_the_markers_and_the_root() {
let block = render_block("docs");
assert!(block.starts_with("<!-- BEGIN spec-driven-docs docs -->\n"));
assert!(block.ends_with("<!-- END spec-driven-docs docs -->\n"));
assert!(block.contains(
"Read the writing style before you author or edit prose: `sdd method writing-style`."
));
assert!(!block.contains("{docs_root}"));
assert!(!block.contains("simple-english"));
}
#[test]
fn the_underscore_root_reaches_the_block() {
let block = render_block("_docs");
assert!(block.contains(
"Read the writing style before you author or edit prose: `sdd method writing-style`."
));
assert!(!block.contains("simple-english"));
}
}