Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

requirements.index.detail_pages

Requirements index · View definition

evidence Valid

Requirement

habeas mdbook MUST generate one evidence detail page for every requirement and named example defined in a rendered chapter. Each page MUST be a subchapter of the index chapter, in definition order, titled by the definition’s full name, at a path derived from the index chapter’s path. Books configured by cite requirements.cli.setup fold these subchapters in the sidebar until a reader expands the index chapter.

Rationale

The reviewed tests cover every obligation in requirements.index.detail_pages. I did not request implementation source.

  • One page per requirement and named example.
    • src/lib.rs#mod[tests]/fn[definitions_without_a_marker_get_a_default_index_and_detail_pages] renders two requirements (zeta, cli.mdbook), one example (alpha) and a requirement in a nested child chapter (nested).
    • It asserts that the index holds exactly those four detail pages plus “Coverage gaps”.
    • The definition chapters keep no detail sub-items of their own, apart from the existing “Child” chapter.
    • src/index.rs#mod[tests]/fn[index_shows_evidence_states_and_links_generated_chapters] covers requirements in every evidence state, including absent (Missing), which gets a page whose source_path points back at the definition chapter.
    • tests/outcomes.rs#fn[valid_fixme_remains_visible_in_status_info_and_book] covers a FIXME-state requirement.
    • tests/repository.rs#fn[mdbook_preprocessor_renders_definitions_between_stdin_and_stdout] covers the real habeas mdbook binary.
    • src/lib.rs#mod[tests]/fn[default_index_exists_even_without_definitions_or_numbered_chapters] covers the case with no definitions, where the index has only “Coverage gaps”.
  • Subchapter of the index chapter. Detail pages are checked as sub_items of the index with parent_names == ["Requirements index"] or ["Index"]. This holds for both the default index and an explicit index placed elsewhere, in src/lib.rs#mod[tests]/fn[index_owns_details_in_book_order_with_badge_icons].
  • Definition order.
    • The name list rules.zeta, rules.alpha, rules.cli.mdbook, rules.child.nested is asserted in order. That order mixes a requirement and an example and puts the nested chapter last.
    • Section numbers [3, offset+2] are asserted in the same test, and [3,4] in the explicit-index test.
    • Across chapters, the explicit-index test asserts the order rules.zeta, more.cli.mdbook.
  • Titled by the full name. The name assertions use full names such as rules.zeta and more.cli.mdbook, and requirements.core.ready in the src/index.rs test.
  • Path derived from the index path.
    • src/index.rs asserts the path appendix/requirements-index/requirements.core.ready.md for an index at appendix/requirements-index.md.
    • The default index at requirements-index.md gets “Coverage gaps” at requirements-index/coverage.md.
    • Links from definitions and the index into requirements-index/...html and appendix/index/more.cli%2Emdbook.html confirm the derivation for other index locations and for names containing dots.
    • I found no direct assertion of the .md path for a cli.mdbook-style name. The link href assertions cover that name’s derived location, so I don’t treat it as a gap.
  • Folding via the cited requirements.cli.setup.
    • tests/setup.rs#fn[setup_is_repeatable] asserts that setup writes output.html.fold.enable = true exactly once, even when run twice.
    • tests/setup.rs#fn[setup_keeps_an_existing_fold_setting] asserts that an existing enable = false is kept, and that enable = true is added when only level is set.
    • Together these cover applying the cited setup requirement in this subject’s case.

I found no unaddressed obligation or missing scenario.

Inputs

Tests

Input 3: outline src/index.rs mod[tests]/fn[index_shows_evidence_states_and_links_generated_chapters]
  • File: src/index.rs
  • Selector: mod[tests]/fn[index_shows_evidence_states_and_links_generated_chapters]
  • Kind: fn
  • src/index.rs:1101–1306
    // {test}`requirements.index.chapter`
    // {test}`requirements.index.state`
    // {test}`requirements.index.navigation`
    // {test}`requirements.index.source_links`
    // {test}`requirements.cli.shared_status_rendering`
    // {test}`requirements.index.detail_format`
    // {test}`requirements.index.invalid_detail`
    // {test}`requirements.test-coverage.index`
    // {test}`requirements.index.detail_pages`
    #[test]
    fn index_shows_evidence_states_and_links_generated_chapters() {
        let temp = TempDir::new().unwrap();
        fs::create_dir_all(temp.path().join("md/requirements")).unwrap();
        fs::create_dir_all(temp.path().join("evidence")).unwrap();
        fs::create_dir_all(temp.path().join("src")).unwrap();
        fs::write(temp.path().join("book.toml"), "[book]\nsrc = \"md\"\n").unwrap();
        let requirements = [
            ("ready", "Ready MUST work."),
            ("pending", "Pending MUST work."),
            ("changed", "Changed MUST work."),
            ("absent", "Absent MUST work."),
            ("uncovered", "Uncovered MUST work."),
        ];
        let mut source = String::from("# Requirements\n\n");
        for (name, body) in requirements {
            source.push_str(&format!(":::{{req}} {name}\n{body}\n:::\n\n"));
        }
        fs::write(temp.path().join("md/requirements/core.md"), &source).unwrap();
        fs::write(
            temp.path().join("src/main.rs"),
            "// {test}`requirements.core.uncovered`\n",
        )
        .unwrap();
        for (name, body, determination) in [
            ("ready", "Ready MUST work.", true),
            ("pending", "Pending MUST work.", false),
            ("changed", "Old requirement.", true),
            ("uncovered", "Uncovered MUST work.", true),
        ] {
            fs::write(
                temp.path()
                    .join(format!("evidence/requirements.core.{name}.json")),
                json!({
                    "requirement": body,
                    "determination": determination,
                    "rationale": "The fixture records the evidence state.",
                    "inputs": []
                })
                .to_string(),
            )
            .unwrap();
        }

        let mut book = Book::new();
        let mut definition_chapter =
            Chapter::new("Requirements", source, "requirements/core.md", Vec::new());
        definition_chapter.number = Some(SectionNumber::new(vec![3]));
        book.push_item(definition_chapter);
        let mut index_chapter = Chapter::new(
            "Requirements index",
            "# Requirements index\n\n:::{requirements-index}\n:::\n".to_owned(),
            "appendix/requirements-index.md",
            Vec::new(),
        );
        index_chapter.number = Some(SectionNumber::new(vec![4]));
        book.push_item(index_chapter);
        crate::evidence::tests::stamp_reference_sets(temp.path());
        preprocess_book(&mut book, temp.path()).unwrap();

        let definition = book.chapters().next().unwrap();
        assert!(definition.content.contains(
            "id=\"habeas-req-requirements.core.ready\" href=\"#habeas-req-requirements.core.ready\""
        ));
        let index = book
            .chapters()
            .find(|chapter| chapter.name == "Requirements index")
            .unwrap();
        assert!(!index.content.contains("{requirements-index}"));
        for (name, state) in [
            ("ready", "Valid"),
            ("pending", "Determination false"),
            ("changed", "Invalid"),
            ("absent", "Missing"),
            ("uncovered", "Invalid"),
        ] {
            let link = format!(
                "| [`requirements.core.{name}`](requirements-index/requirements.core.{name}.html)"
            );
            let row = index
                .content
                .lines()
                .find(|line| line.starts_with(&link))
                .unwrap_or_else(|| panic!("missing {link} in:\n{}", index.content));
            assert_eq!(row.split('|').nth(2).unwrap().trim(), state);
        }
        let table = index
            .content
            .lines()
            .skip_while(|line| !line.starts_with("| "))
            .take_while(|line| line.starts_with("| "))
            .collect::<Vec<_>>();
        let pipes = table[0]
            .match_indices('|')
            .map(|(position, _)| position)
            .collect::<Vec<_>>();
        assert_eq!(pipes.len(), 3);
        assert!(table.iter().all(|line| {
            line.match_indices('|')
                .map(|(position, _)| position)
                .collect::<Vec<_>>()
                == pipes
        }));
        for column in 0..2 {
            let widest = table
                .iter()
                .map(|line| line.split('|').nth(column + 1).unwrap().trim().len())
                .max()
                .unwrap();
            assert_eq!(pipes[column + 1] - pipes[column] - 3, widest);
        }
        assert!(definition.sub_items.is_empty());
        assert_eq!(index.sub_items.len(), 6);
        let coverage = index
            .sub_items
            .iter()
            .filter_map(|item| match item {
                BookItem::Chapter(chapter) if chapter.name == "Coverage gaps" => Some(chapter),
                _ => None,
            })
            .collect::<Vec<_>>();
        assert_eq!(coverage.len(), 1);
        assert_eq!(
            coverage[0].path.as_deref(),
            Some(Path::new("appendix/requirements-index/coverage.md"))
        );
        assert_eq!(coverage[0].parent_names, ["Requirements index"]);
        assert!(
            index
                .content
                .contains("[Coverage gaps](requirements-index/coverage.html)")
        );
        let ready = index
            .sub_items
            .iter()
            .find_map(|item| match item {
                BookItem::Chapter(chapter) if chapter.name == "requirements.core.ready" => {
                    Some(chapter)
                }
                _ => None,
            })
            .unwrap();
        assert_eq!(
            ready.source_path.as_deref(),
            Some(Path::new("../evidence/requirements.core.ready.json"))
        );
        assert_eq!(
            ready.number.as_deref().map(Vec::as_slice),
            Some(&[4, 2][..])
        );
        assert_eq!(
            ready.path.as_deref(),
            Some(Path::new(
                "appendix/requirements-index/requirements.core.ready.md"
            ))
        );
        assert!(ready.content.contains(
            "[View definition](../../requirements/core.html#habeas-req-requirements.core.ready)"
        ));
        assert!(
            ready
                .content
                .contains("[Requirements index](../requirements-index.html) · [View definition]")
        );
        assert!(
            ready
                .content
                .contains("img.shields.io/badge/evidence-Valid-237346")
        );
        assert!(ready.content.contains("> Ready MUST work."));
        assert!(!ready.content.contains("## Evidence record"));
        let changed = index
            .sub_items
            .iter()
            .find_map(|item| match item {
                BookItem::Chapter(chapter) if chapter.name == "requirements.core.changed" => {
                    Some(chapter)
                }
                _ => None,
            })
            .unwrap();
        assert!(changed.content.contains("requirement text changed"));
        let absent = index
            .sub_items
            .iter()
            .find_map(|item| match item {
                BookItem::Chapter(chapter) if chapter.name == "requirements.core.absent" => {
                    Some(chapter)
                }
                _ => None,
            })
            .unwrap();
        assert_eq!(
            absent.source_path.as_deref(),
            Some(Path::new("requirements/core.md"))
        );
    }
Input 4: outline src/lib.rs mod[tests]/fn[definitions_without_a_marker_get_a_default_index_and_detail_pages]
  • File: src/lib.rs
  • Selector: mod[tests]/fn[definitions_without_a_marker_get_a_default_index_and_detail_pages]
  • Kind: fn
  • src/lib.rs:1050–1185
    // {test}`requirements.index.detail_pages`
    // {test}`requirements.index.chapter`
    // {test}`requirements.index.chapter.default`
    // {test}`requirements.index.navigation`
    // {test}`requirements.examples.index`
    // {test}`requirements.test-coverage.index`
    // {test}`requirements.references.anchors`
    #[test]
    fn definitions_without_a_marker_get_a_default_index_and_detail_pages() {
        let mut book = Book::new();
        let mut chapter = Chapter::new(
            "Rules",
            "# Rules\n\n:::{req} zeta\n:impl: notes.txt\nZeta.\n:::\n\n:::{example} alpha\nAlpha case. {cite}`rules.zeta`\n:::\n\n:::{req} cli.mdbook\nMdbook.\n:::\n".to_owned(),
            "rules.md",
            Vec::new(),
        );
        chapter.number = Some(mdbook_preprocessor::book::SectionNumber::new(vec![2]));
        chapter.sub_items.push(BookItem::Chapter(Chapter::new(
            "Child",
            ":::{req} nested\nNested.\n:::\n".to_owned(),
            "rules/child.md",
            vec!["Rules".to_owned()],
        )));
        book.push_item(chapter);
        let root = book_root();
        preprocess_book(&mut book, root.path()).unwrap();

        let rules = book.chapters().next().unwrap();
        let pages = rules
            .sub_items
            .iter()
            .filter_map(|item| match item {
                BookItem::Chapter(chapter) => Some(chapter),
                _ => None,
            })
            .collect::<Vec<_>>();
        assert_eq!(pages.len(), 1);
        assert_eq!(pages[0].name, "Child");
        assert_eq!(book.items.len(), 2);
        assert_eq!(book.chapters().count(), 8);
        assert!(rules.content.contains("habeas-detail-icon"));
        assert!(!rules.content.contains("See evidence"));
        assert!(!rules.content.contains("notes.txt"));
        for (kind, name) in [("req", "zeta"), ("example", "alpha"), ("req", "cli.mdbook")] {
            assert!(rules.content.contains(&format!(
                "id=\"habeas-{kind}-rules.{name}\" href=\"#habeas-{kind}-rules.{}\"",
                name.replace(".md", "%2Emd")
            )));
        }
        assert!(
            rules
                .content
                .contains("href=\"requirements-index/rules.cli%2Emdbook.html\"")
        );
        assert!(
            pages[0]
                .content
                .contains("href=\"../requirements-index/rules.child.nested.html\"")
        );
        let BookItem::Chapter(index) = book.items.last().unwrap() else {
            panic!("the default index must be a top-level chapter");
        };
        assert_eq!(index.name, "Requirements index");
        assert_eq!(
            index.path.as_deref(),
            Some(Path::new("requirements-index.md"))
        );
        assert!(index.source_path.is_none());
        assert!(index.parent_names.is_empty());
        assert_eq!(index.number.as_deref().map(Vec::as_slice), Some(&[3][..]));
        assert!(!index.content.contains("{requirements-index}"));
        assert!(index.content.contains("(requirement)"));
        assert!(index.content.contains("(example)"));
        assert!(index.content.contains("Missing"));
        let coverage = index
            .sub_items
            .iter()
            .filter_map(|item| match item {
                BookItem::Chapter(chapter) if chapter.name == "Coverage gaps" => Some(chapter),
                _ => None,
            })
            .collect::<Vec<_>>();
        assert_eq!(coverage.len(), 1);
        assert_eq!(
            coverage[0].path.as_deref(),
            Some(Path::new("requirements-index/coverage.md"))
        );
        assert_eq!(coverage[0].parent_names, ["Requirements index"]);
        assert!(
            index
                .content
                .contains("[Coverage gaps](requirements-index/coverage.html)")
        );
        let details = index
            .sub_items
            .iter()
            .filter_map(|item| match item {
                BookItem::Chapter(chapter) if chapter.name != "Coverage gaps" => Some(chapter),
                _ => None,
            })
            .collect::<Vec<_>>();
        assert_eq!(
            details
                .iter()
                .map(|page| page.name.as_str())
                .collect::<Vec<_>>(),
            [
                "rules.zeta",
                "rules.alpha",
                "rules.cli.mdbook",
                "rules.child.nested"
            ]
        );
        for (offset, page) in details.iter().enumerate() {
            assert_eq!(page.parent_names, ["Requirements index"]);
            assert_eq!(
                page.number.as_deref().map(Vec::as_slice),
                Some(&[3, offset as u32 + 2][..])
            );
            assert!(
                page.content
                    .contains("[Requirements index](../requirements-index.html)")
            );
        }
        assert!(
            details[2]
                .content
                .contains("[View definition](../rules.html#habeas-req-rules.cli%2Emdbook)")
        );
        assert!(
            details[3]
                .content
                .contains("[View definition](../rules/child.html#habeas-req-rules.child.nested)")
        );
        assert!(!root.path().join("md/requirements-index.md").exists());
    }
Input 5: outline src/lib.rs mod[tests]/fn[default_index_exists_even_without_definitions_or_numbered_chapters]
  • File: src/lib.rs
  • Selector: mod[tests]/fn[default_index_exists_even_without_definitions_or_numbered_chapters]
  • Kind: fn
  • src/lib.rs:1187–1235
    // {test}`requirements.index.chapter`
    // {test}`requirements.index.chapter.default`
    // {test}`requirements.index.detail_pages`
    #[test]
    fn default_index_exists_even_without_definitions_or_numbered_chapters() {
        for with_prose in [false, true] {
            let mut book = Book::new();
            let prose = "An index marker in a code block is literal.\n\n```text\n:::{requirements-index}\n:::\n```\n";
            if with_prose {
                book.push_item(Chapter::new(
                    "Introduction",
                    prose.into(),
                    "intro.md",
                    vec![],
                ));
            }
            let root = book_root();
            preprocess_book(&mut book, root.path()).unwrap();
            assert_eq!(book.items.len(), usize::from(with_prose) + 1);
            if with_prose {
                let BookItem::Chapter(intro) = &book.items[0] else {
                    panic!("the original introduction must remain a chapter");
                };
                assert_eq!(intro.content, prose);
                assert!(intro.number.is_none());
            }
            let BookItem::Chapter(index) = book.items.last().unwrap() else {
                panic!("the default index must be appended");
            };
            assert_eq!(index.name, "Requirements index");
            assert_eq!(
                index.path.as_deref(),
                Some(Path::new("requirements-index.md"))
            );
            assert_eq!(index.number.as_deref().map(Vec::as_slice), Some(&[1][..]));
            assert!(index.source_path.is_none());
            assert_eq!(index.sub_items.len(), 1);
            let BookItem::Chapter(coverage) = &index.sub_items[0] else {
                unreachable!()
            };
            assert_eq!(coverage.name, "Coverage gaps");
            assert!(coverage.source_path.is_none());
            assert!(index.parent_names.is_empty());
            assert!(index.content.starts_with("# Requirements index\n\n"));
            assert!(index.content.contains("| Definition | Evidence |"));
            assert!(!index.content.contains("{requirements-index}"));
            assert!(!root.path().join("md/requirements-index.md").exists());
        }
    }
Input 6: outline src/lib.rs mod[tests]/fn[index_owns_details_in_book_order_with_badge_icons]
  • File: src/lib.rs
  • Selector: mod[tests]/fn[index_owns_details_in_book_order_with_badge_icons]
  • Kind: fn
  • src/lib.rs:1268–1350
    // {test}`requirements.index.chapter`
    // {test}`requirements.index.detail_pages`
    // {test}`requirements.index.navigation`
    #[test]
    fn index_owns_details_in_book_order_with_badge_icons() {
        let mut book = Book::new();
        book.push_item(Chapter::new(
            "Rules",
            ":::{req} zeta\nZeta.\n:::\n".into(),
            "rules.md",
            vec![],
        ));
        book.push_item(Chapter::new(
            "More",
            ":::{example} cli.mdbook\nExample.\n:::\n".into(),
            "more.md",
            vec![],
        ));
        let mut index = Chapter::new(
            "Index",
            ":::{requirements-index}\n:::\n".into(),
            "appendix/index.md",
            vec![],
        );
        index.number = Some(mdbook_preprocessor::book::SectionNumber::new(vec![3]));
        let mut child = Chapter::new(
            "Existing",
            "Existing.".into(),
            "appendix/existing.md",
            vec!["Index".into()],
        );
        child.number = Some(mdbook_preprocessor::book::SectionNumber::new(vec![3, 1]));
        index.sub_items.push(BookItem::Chapter(child));
        book.push_item(index);
        let root = book_root();
        preprocess_book(&mut book, root.path()).unwrap();
        assert_eq!(
            book.items.len(),
            3,
            "the explicit index keeps its placement"
        );
        let chapters = book.chapters().collect::<Vec<_>>();
        for chapter in &chapters[..2] {
            assert!(chapter.sub_items.is_empty());
            assert!(
                chapter
                    .content
                    .contains("title=\"View evidence\" aria-label=\"View evidence for ")
            );
            assert!(chapter.content.contains("stroke=\"#fff\""));
            assert!(!chapter.content.contains("See evidence"));
        }
        assert!(
            chapters[1]
                .content
                .contains("href=\"appendix/index/more.cli%2Emdbook.html\"")
        );
        let pages = chapters[2]
            .sub_items
            .iter()
            .filter_map(|item| match item {
                BookItem::Chapter(chapter) => Some(chapter),
                _ => None,
            })
            .collect::<Vec<_>>();
        assert_eq!(
            pages
                .iter()
                .map(|page| page.name.as_str())
                .collect::<Vec<_>>(),
            ["Coverage gaps", "Existing", "rules.zeta", "more.cli.mdbook"]
        );
        assert_eq!(pages[3].parent_names, ["Index"]);
        assert_eq!(
            pages[3].number.as_deref().map(Vec::as_slice),
            Some(&[3, 4][..])
        );
        assert!(
            pages[3]
                .content
                .contains("[View definition](../../more.html#habeas-example-more.cli%2Emdbook)")
        );
    }
Input 7: outline tests/outcomes.rs fn[valid_fixme_remains_visible_in_status_info_and_book]
// {test}`requirements.cli.status`
// {test}`requirements.cli.fixme_summary`
// {test}`requirements.cli.info`
// {test}`requirements.index.state`
// {test}`requirements.index.detail_format`
// {test}`requirements.index.detail_pages`
// {test}`requirements.examples.index`
#[test]
fn valid_fixme_remains_visible_in_status_info_and_book() {
    let temp = fixture();
    for all in [false, true] {
        let status = habeas::status_markdown(temp.path(), all).unwrap();
        assert_eq!(status.contains("requirements.timeout"), all, "{status}");
        assert!(status.contains("FIXME"));
        assert!(status.contains("example/io#125"));
        assert!(status.contains("rust-lang/rust#123"));
        assert!(status.contains("affects 1 judgment"), "{status}");
        assert!(!status.contains("## Validation findings"));
    }
    let verbose = habeas::status_markdown_with_options(temp.path(), false, None, true).unwrap();
    assert!(verbose.contains("requirements.timeout"), "{verbose}");
    assert!(verbose.contains("example"), "{verbose}");
    let info = habeas::info_markdown(temp.path(), "requirements.timeout").unwrap();
    assert!(info.contains("## FIXME references"));
    assert!(info.contains("rust-lang/rust#123"));

    let mut book = Book::new();
    book.push_item(Chapter::new(
        "Requirements",
        fs::read_to_string(temp.path().join("md/requirements.md")).unwrap(),
        "requirements.md",
        Vec::new(),
    ));
    book.push_item(Chapter::new(
        "Index",
        ":::{requirements-index}\n:::\n".to_owned(),
        "requirements-index.md",
        Vec::new(),
    ));
    habeas::preprocess_book(&mut book, temp.path()).unwrap();
    let index = book
        .chapters()
        .find(|chapter| chapter.name == "Index")
        .unwrap();
    assert!(index.content.contains("FIXME"));
    let detail = index
        .sub_items
        .iter()
        .find_map(|item| match item {
            BookItem::Chapter(chapter) if chapter.name == "requirements.timeout" => Some(chapter),
            _ => None,
        })
        .unwrap();
    assert!(detail.content.contains("evidence-FIXME"));
    assert!(detail.content.contains("## FIXME references"));
    assert!(detail.content.contains("rust-lang/rust#123"));
}
Input 8: outline tests/repository.rs fn[mdbook_preprocessor_renders_definitions_between_stdin_and_stdout]
  • File: tests/repository.rs
  • Selector: fn[mdbook_preprocessor_renders_definitions_between_stdin_and_stdout]
  • Kind: fn
  • tests/repository.rs:160–260
// {test}`requirements.cli.mdbook`
// {test}`requirements.index.chapter.default`
// {test}`requirements.index.detail_pages`
// {test}`requirements.index.navigation`
#[test]
fn mdbook_preprocessor_renders_definitions_between_stdin_and_stdout() {
    let temp = TempDir::new().unwrap();
    let root = temp.path();
    fs::create_dir_all(root.join("md")).unwrap();
    fs::write(root.join("Cargo.toml"), "[package]\nname = \"fixture\"\n").unwrap();
    fs::write(root.join("book.toml"), "[book]\nsrc = \"md\"\n").unwrap();
    let content =
        ":::{req} ready\nReady MUST work.\n:::\n\n:::{req} cites\nSee {cite}`rules.ready`.\n:::\n"
            .to_owned();
    fs::write(root.join("md/rules.md"), &content).unwrap();
    let mut book = Book::new();
    book.push_item(Chapter::new("Rules", content, "rules.md", Vec::new()));
    let context = PreprocessorContext::new(root.to_path_buf(), Config::default(), "html".into());

    let mut child = Command::new(env!("CARGO_BIN_EXE_habeas"))
        .arg("mdbook")
        .current_dir(root)
        .stdin(Stdio::piped())
        .stdout(Stdio::piped())
        .stderr(Stdio::piped())
        .spawn()
        .unwrap();
    child
        .stdin
        .take()
        .unwrap()
        .write_all(&serde_json::to_vec(&(&context, &book)).unwrap())
        .unwrap();
    let output = child.wait_with_output().unwrap();
    assert!(
        output.status.success(),
        "{}",
        String::from_utf8_lossy(&output.stderr)
    );
    let rendered: Book = serde_json::from_slice(&output.stdout).unwrap();
    let BookItem::Chapter(chapter) = &rendered.items[0] else {
        panic!("{rendered:?}");
    };
    assert!(!chapter.content.contains(":::{req}"), "{}", chapter.content);
    assert!(
        chapter.content.contains("https://img.shields.io/badge/"),
        "{}",
        chapter.content
    );
    assert!(
        chapter.content.contains("cite") && chapter.content.contains("rules.ready"),
        "{}",
        chapter.content
    );
    let badge_rows = chapter
        .content
        .split("<span class=\"habeas-definition-badge\">")
        .skip(1)
        .map(|row| row.split("</span>").next().unwrap())
        .collect::<Vec<_>>();
    assert_eq!(badge_rows.len(), 2, "{}", chapter.content);
    for row in badge_rows {
        assert!(row.contains("<img "), "{row}");
        assert!(row.contains("class=\"habeas-detail-icon\""), "{row}");
        assert_eq!(row.matches("</a>").count(), 2, "{row}");
    }
    assert!(chapter.sub_items.is_empty());
    assert!(
        chapter.content.contains("href=\"#habeas-req-rules.ready\""),
        "{}",
        chapter.content
    );
    assert!(
        chapter
            .content
            .contains("href=\"requirements-index/rules.ready.html\""),
        "{}",
        chapter.content
    );
    assert_eq!(rendered.items.len(), 2);
    let BookItem::Chapter(index) = &rendered.items[1] else {
        panic!("{rendered:?}");
    };
    assert_eq!(index.name, "Requirements index");
    assert_eq!(
        index.path.as_deref(),
        Some(Path::new("requirements-index.md"))
    );
    assert!(index.source_path.is_none());
    assert_eq!(
        index
            .sub_items
            .iter()
            .filter_map(|item| match item {
                BookItem::Chapter(detail) => Some(detail.name.as_str()),
                _ => None,
            })
            .collect::<Vec<_>>(),
        ["Coverage gaps", "rules.ready", "rules.cites"]
    );
}
Input 9: outline tests/setup.rs fn[setup_is_repeatable]
// {test}`requirements.cli.setup`
// {test}`requirements.cli.setup_css`
// {test}`requirements.cli.setup_local_path`
// {test}`requirements.cli.mdbook`
// {test}`requirements.index.detail_pages`
#[test]
fn setup_is_repeatable() {
    let temp = fixture();
    let project = temp.path();
    let local_crate = env!("CARGO_MANIFEST_DIR");

    run(project, &["setup", "--path", local_crate]);
    assert!(!project.join(".agents/skills").exists());
    run(project, &["setup", "--path", local_crate]);

    let cargo = fs::read_to_string(project.join("Cargo.toml")).unwrap();
    assert!(cargo.contains("[dev-dependencies]"));
    assert!(cargo.contains("habeas"));
    assert!(cargo.contains("path = "));
    let book = fs::read_to_string(project.join("book.toml")).unwrap();
    assert!(book.contains("command = \"habeas mdbook\""));
    assert!(book.contains("md/habeas.css"));
    assert!(book.contains("md/custom.css"));
    assert_eq!(book.matches("md/habeas.css").count(), 1);
    assert_eq!(
        fs::read_to_string(project.join("tests/habeas.rs")).unwrap(),
        "#[test]\nfn habeas() {\n    habeas::validate();\n}\n"
    );
    assert!(project.join("md/habeas.css").is_file());
    assert!(!project.join(".agents/skills").exists());
    let book: toml_edit::DocumentMut = book.parse().unwrap();
    assert_eq!(
        book["output"]["html"]["fold"]["enable"].as_bool(),
        Some(true)
    );
    assert_eq!(book.to_string().matches("enable").count(), 1, "{book}");
}
Input 10: outline tests/setup.rs fn[setup_keeps_an_existing_fold_setting]
// {test}`requirements.cli.setup`
// {test}`requirements.index.detail_pages`
#[test]
fn setup_keeps_an_existing_fold_setting() {
    for (configuration, expected) in [
        (
            "[output.html.fold]\nenable = false\nlevel = 1\n",
            Some(false),
        ),
        ("[output.html.fold]\nlevel = 1\n", Some(true)),
        ("[output.html]\nfold = { enable = false }\n", Some(false)),
    ] {
        let temp = fixture();
        let project = temp.path();
        fs::write(
            project.join("book.toml"),
            format!("[book]\nsrc = \"md\"\n\n{configuration}"),
        )
        .unwrap();
        run(project, &["setup", "--path", env!("CARGO_MANIFEST_DIR")]);
        let book: toml_edit::DocumentMut = fs::read_to_string(project.join("book.toml"))
            .unwrap()
            .parse()
            .unwrap();
        assert_eq!(
            book["output"]["html"]["fold"]["enable"].as_bool(),
            expected,
            "{configuration}"
        );
        if configuration.contains("level") {
            assert_eq!(
                book["output"]["html"]["fold"]["level"].as_integer(),
                Some(1)
            );
        }
    }
}

Referenced definitions

Input 2: requirements selection requirements.cli.setup
:::{req} setup
Running `habeas setup` in an existing Cargo and mdBook project MUST add Habeas as a dev dependency, configure `habeas mdbook` as its preprocessor, add the badge stylesheet, enable sidebar folding with `output.html.fold.enable` unless the book already sets it, and create `tests/habeas.rs` that calls `habeas::validate()`. Repeating setup MUST avoid duplicate configuration and MUST NOT overwrite a differing test or stylesheet. Setup MUST NOT install or modify agent skills.
:::

Other sources

Input 1: requirements selection requirements.index.detail_pages
:::{req} detail_pages
`habeas mdbook` MUST generate one evidence detail
page for every requirement and named example defined in a rendered chapter.
Each page MUST be a subchapter of the index chapter, in definition order,
titled by the definition's full name, at a path derived from the index chapter's
path.
Books configured by {cite}`requirements.cli.setup` fold these subchapters in the
sidebar until a reader expands the index chapter.
:::