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(clippy::literal_string_with_formatting_args)]
24pub fn render_block(docs_root: &str) -> String {
25 let body = snippet().replace("{docs_root}", docs_root);
26 let body = body.trim_end_matches('\n');
27 format!("{AGENTS_BEGIN}\n{body}\n{AGENTS_END}\n")
28}
29
30#[cfg(test)]
31mod tests {
32 use super::*;
33
34 #[test]
35 fn the_block_carries_the_markers_and_the_root() {
36 let block = render_block("docs");
37 assert!(block.starts_with("<!-- BEGIN spec-driven-docs docs -->\n"));
38 assert!(block.ends_with("<!-- END spec-driven-docs docs -->\n"));
39 assert!(block.contains(
40 "Read the writing style before you author or edit prose: `sdd method writing-style`."
41 ));
42 assert!(!block.contains("{docs_root}"));
43 assert!(!block.contains("simple-english"));
44 }
45
46 #[test]
47 fn the_underscore_root_reaches_the_block() {
48 let block = render_block("_docs");
49 assert!(block.contains(
50 "Read the writing style before you author or edit prose: `sdd method writing-style`."
51 ));
52 assert!(!block.contains("simple-english"));
53 }
54}