spec_driven_docs/services/
agents_render.rs1use crate::domain::marker::{AGENTS_BEGIN, AGENTS_END};
10
11#[must_use]
13pub fn snippet() -> &'static str {
14 crate::embedded::SNIPPETS
15 .get_file("AGENTS-docs.md")
16 .and_then(include_dir::File::contents_utf8)
17 .unwrap_or_default()
18}
19
20#[must_use]
23#[allow(clippy::literal_string_with_formatting_args)]
25pub fn render_block(docs_root: &str) -> String {
26 let body = snippet().replace("{docs_root}", docs_root);
27 let body = body.trim_end_matches('\n');
28 format!("{AGENTS_BEGIN}\n{body}\n{AGENTS_END}\n")
29}
30
31#[cfg(test)]
32mod tests {
33 use super::*;
34
35 #[test]
36 fn the_block_carries_the_markers_and_the_root() {
37 let block = render_block("docs");
38 assert!(block.starts_with("<!-- BEGIN spec-driven-docs docs -->\n"));
39 assert!(block.ends_with("<!-- END spec-driven-docs docs -->\n"));
40 assert!(block.contains("docs/specs/SPEC-simple-english.md"));
41 assert!(!block.contains("{docs_root}"));
42 assert!(block.contains("SimpleEnglish `Plain` mode"));
43 }
44
45 #[test]
46 fn the_underscore_root_reaches_the_block() {
47 let block = render_block("_docs");
48 assert!(block.contains("_docs/specs/SPEC-simple-english.md"));
49 }
50}