spec_driven_docs/services/
agents_render.rs1use crate::domain::marker::{AGENTS_BEGIN, AGENTS_END};
9
10#[must_use]
12pub fn snippet() -> &'static str {
13 crate::embedded::SNIPPETS
14 .get_file("AGENTS-docs.md")
15 .and_then(include_dir::File::contents_utf8)
16 .unwrap_or_default()
17}
18
19#[must_use]
22#[allow(
23 clippy::literal_string_with_formatting_args,
24 reason = "the braces are the block template's placeholder, not a formatting argument"
25)]
26pub fn render_block(docs_root: &str) -> String {
27 let body = snippet().replace("{docs_root}", docs_root);
28 let body = body.trim_end_matches('\n');
29 format!("{AGENTS_BEGIN}\n{body}\n{AGENTS_END}\n")
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35
36 #[test]
37 fn the_block_carries_the_markers_and_the_root() {
38 let block = render_block("docs");
39 assert!(block.starts_with("<!-- BEGIN spec-driven-docs docs -->\n"));
40 assert!(block.ends_with("<!-- END spec-driven-docs docs -->\n"));
41 assert!(block.contains(
42 "Read the writing style before you author or edit prose: `sdd method writing-style`."
43 ));
44 assert!(!block.contains("{docs_root}"));
45 assert!(!block.contains("simple-english"));
46 }
47
48 #[test]
49 fn the_underscore_root_reaches_the_block() {
50 let block = render_block("_docs");
51 assert!(block.contains(
52 "Read the writing style before you author or edit prose: `sdd method writing-style`."
53 ));
54 assert!(!block.contains("simple-english"));
55 }
56}