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.cli.info

Requirements index · View definition

evidence Valid

Requirement

habeas info <selection> MUST show the requirements and named examples matched by the definition selection. It MUST print matches in full-name order as Markdown with the same kind-labeled definition, Validation findings, Rationale, and Inputs structure and evidence states as mdBook detail pages, including readable output for missing or invalid evidence. It MUST work without a requirements index directive and report an invalid selection or no matches clearly. Habeas’s bundled agent guidance MUST tell agents they can use this command to inspect a requirement or named example.

Rationale

The reviewed tests cover every clause of requirements.cli.info.

Showing the selected definitions

  • tests/commands.rs#fn[info_renders_exact_and_glob_matches_as_markdown_without_an_index] runs habeas info requirements.ready. It asserts the output starts with the # \requirements.ready`heading and that the similarly namedrequirements.xready` is absent. The exact-name case is therefore tested.
  • The same test runs habeas info requirements.*. It asserts the output contains the xready, case, pending and ready sections. These are the glob matches.
  • status_and_info_accept_a_definition_selection checks the help text for the selection argument. It also checks that info requirements.case returns only that example.

Full-name order

  • The fixture in tests/commands.rs#fn[fixture] declares ready before pending in the source. The glob test asserts that pending comes before ready in the output. That ordering is by full name, not by source order.

Markdown structure and evidence states

  • The exact-match case asserts these elements:
    • the ## Requirement label with a blockquote of the text;
    • ## Rationale with rendered Markdown;
    • ## Inputs with a source range for src/main.rs and a rust code block;
    • the Valid badge.
  • The glob case asserts ## Example for the example definition.
  • A loop over pending, stale and stale_input checks the state badges Determination_false and Invalid. Each also gets a ## Validation findings section with the specific finding text.
  • tests/outcomes.rs#fn[valid_fixme_remains_visible_in_status_info_and_book] covers the FIXME state. It asserts that info shows a ## FIXME references section with the named issue.
  • src/index.rs#fn[detail_pages_and_info_display_redacted_source] checks that info_markdown output matches the redaction of the detail page.

Missing or invalid evidence, readable output

  • For requirements.absent, the test asserts the findings heading, “missing for requirement”, “No rationale recorded.” and “No inputs recorded.”
  • For requirements.malformed, it asserts a ## Unreadable evidence record section containing the raw JSON in a code fence.
  • The missing and malformed cases do not assert a state badge. I treat that as minor, because the badge and detail-page format are covered by the detail-format tests and the other state assertions.

No requirements index directive

  • The fixture contains no requirements-index directive or chapter. Every info run in these tests therefore works without one.

Invalid selection and no matches

  • commands_report_invalid_arguments_and_unmatched_selectors runs info "[". It asserts a failure whose stderr contains “invalid definition glob”.
  • It runs info nothing.*. It asserts a failure whose stderr contains “no definitions match”.
  • It also checks the usage error when the selection argument is missing or extra arguments are given.

Bundled agent guidance

  • tests/authoring_cli.rs#fn[bundled_skills_inspect_definitions_with_habeas_info] calls assert_phrases for three skills: habeas, habeas-requirements and habeas-evidence. assert_phrases searches the bundled skill text. Each skill is required to mention habeas info.

I found no plausible requirement-violating behavior that these tests would accept.

Inputs

Tests

Input 2: outline src/index.rs mod[tests]/fn[detail_pages_and_info_display_redacted_source]
  • File: src/index.rs
  • Selector: mod[tests]/fn[detail_pages_and_info_display_redacted_source]
  • Kind: fn
  • src/index.rs:1341–1461
    // {test}`requirements.authoring.redaction`
    // {test}`requirements.index.detail_format`
    // {test}`requirements.cli.info`
    #[test]
    fn detail_pages_and_info_display_redacted_source() {
        let token = crate::redaction::tests::github_token();
        let temp = tempfile::tempdir().unwrap();
        let root = temp.path();
        fs::create_dir_all(root.join("src")).unwrap();
        fs::create_dir_all(root.join("md")).unwrap();
        fs::create_dir_all(root.join("evidence")).unwrap();
        fs::write(root.join("book.toml"), "[book]\nsrc = 'md'\n").unwrap();
        fs::write(
            root.join("md/requirements.md"),
            format!(":::{{req}} ready\nTokens such as {token} MUST be hidden.\n:::\n"),
        )
        .unwrap();
        fs::write(
            root.join("src/main.rs"),
            format!("fn main() {{\n    println!(\"{token}\");\n}}\n"),
        )
        .unwrap();
        fs::write(
            root.join("habeas.toml"),
            "version = 1\n[authoring.configs.local]\nbackend = 'ollama'\nmodel = 'm'\napi_key = 'plain ollama key'\n",
        )
        .unwrap();
        let record = json!({
            "requirement": format!("Tokens such as {token} MUST be hidden."),
            "determination": true,
            "rationale": "Checked.",
            "inputs": [
                crate::inputs::outline_input(root, "src/main.rs", "fn[main]").unwrap(),
                crate::inputs::outline_input(root, "habeas.toml", "").unwrap(),
                {"requirements": "requirements.ready", "matches": ["requirements.ready"], "text": [format!("Tokens such as {token} MUST be hidden.")]},
            ]
        });
        fs::write(
            root.join("evidence/requirements.ready.json"),
            record.to_string(),
        )
        .unwrap();
        let definition = Definition {
            path: Path::new("requirements.md").to_path_buf(),
            text: format!("Tokens such as {token} MUST be hidden."),
            kind: DefinitionKind::Requirement,
        };
        let record = record.to_string();
        let page = render_detail_page(
            "requirements.ready",
            Path::new("appendix/requirements-index/requirements.ready.md"),
            None,
            &definition,
            DetailEvidence {
                state: EvidenceState::Valid,
                record: Some(&record),
                errors: &[],
                fixme_entries: &[],
            },
            &RenderSources {
                root,
                definitions: &BTreeMap::new(),
                references: &[],
                source_links: None,
                outlines: &crate::inputs::OutlineCache::default(),
            },
        );
        let info = crate::commands::info_markdown(root, "requirements.ready").unwrap();
        for page in [page, info] {
            assert!(!page.contains(&token), "{page}");
            assert!(!page.contains("plain ollama key"), "{page}");
            assert!(
                page.contains("Tokens such as [REDACTED:GitHub Token] MUST be hidden."),
                "{page}"
            );
            assert!(
                page.contains("    println!(\"[REDACTED:GitHub Token]\");"),
                "{page}"
            );
            assert!(page.contains("api_key = '[REDACTED:api_key]'"), "{page}");
        }

        // Validation findings, an unresolved input shown as raw JSON, and an
        // unreadable record are redacted too.
        let unresolved = json!({
            "requirement": "Ready.",
            "determination": true,
            "rationale": "Checked.",
            "inputs": [{"file": "src/gone.rs", "item": "fn[gone]", "hash": token}],
        })
        .to_string();
        let unreadable = format!("{{broken {token}");
        let errors = [format!("evidence/requirements.ready.json: saw {token}")];
        for (record, shown) in [
            (&unresolved, "\"hash\": \"[REDACTED:GitHub Token]\""),
            (&unreadable, "{broken [REDACTED:GitHub Token]"),
        ] {
            let page = render_detail_page(
                "requirements.ready",
                Path::new("appendix/requirements-index/requirements.ready.md"),
                None,
                &definition,
                DetailEvidence {
                    state: EvidenceState::Invalid,
                    record: Some(record),
                    errors: &errors,
                    fixme_entries: &[],
                },
                &RenderSources {
                    root,
                    definitions: &BTreeMap::new(),
                    references: &[],
                    source_links: None,
                    outlines: &crate::inputs::OutlineCache::default(),
                },
            );
            assert!(!page.contains(&token), "{page}");
            assert!(page.contains("saw [REDACTED:GitHub Token]"), "{page}");
            assert!(page.contains(shown), "{page}");
        }
    }
Input 3: outline tests/authoring_cli.rs fn[bundled_skills_inspect_definitions_with_habeas_info]
// {test}`requirements.cli.info`
#[test]
fn bundled_skills_inspect_definitions_with_habeas_info() {
    assert_phrases(
        "habeas",
        &[
            "`habeas info <selection>` prints requirement and example text, evidence state, rationale, inputs, and validation findings",
        ],
    );
    assert_phrases(
        "habeas-requirements",
        &["`habeas info <selection>` prints a requirement's text and state"],
    );
    assert_phrases(
        "habeas-evidence",
        &["`habeas info <name>` shows one definition's judgment, rationale, and findings"],
    );
}
Input 4: outline tests/commands.rs fn[info_renders_exact_and_glob_matches_as_markdown_without_an_index]
  • File: tests/commands.rs
  • Selector: fn[info_renders_exact_and_glob_matches_as_markdown_without_an_index]
  • Kind: fn
  • tests/commands.rs:515–590
// {test}`requirements.cli.info`
// {test}`requirements.cli.definition_glob_search`
// {test}`requirements.index.invalid_detail`
#[test]
fn info_renders_exact_and_glob_matches_as_markdown_without_an_index() {
    let temp = fixture();
    let output = habeas(temp.path(), &["info", "requirements.ready"]);
    assert!(output.status.success(), "{:?}", output);
    let exact = String::from_utf8(output.stdout).unwrap();
    assert!(exact.starts_with("# `requirements.ready`\n"), "{exact}");
    assert!(!exact.contains("# `requirements.xready`"), "{exact}");
    assert!(
        exact.contains("## Requirement\n\n> Ready MUST work."),
        "{exact}"
    );
    assert!(
        exact.contains("## Rationale\n\n**ready** was inspected."),
        "{exact}"
    );
    assert!(exact.contains("## Inputs"), "{exact}");
    assert!(exact.contains("src/main.rs:1–1"), "{exact}");
    assert!(
        exact.contains("```rust,noplayground\nfn main() {}"),
        "{exact}"
    );
    assert!(
        exact.contains("img.shields.io/badge/evidence-Valid-237346"),
        "{exact}"
    );

    let output = habeas(temp.path(), &["info", "requirements.*"]);
    assert!(output.status.success(), "{:?}", output);
    let matches = String::from_utf8(output.stdout).unwrap();
    let pending = matches.find("# `requirements.pending`").unwrap();
    let ready = matches.find("# `requirements.ready`").unwrap();
    assert!(pending < ready, "{matches}");
    assert!(matches.contains("# `requirements.xready`"), "{matches}");
    assert!(
        matches.contains("# `requirements.case`\n\nDefinition:"),
        "{matches}"
    );
    assert!(
        matches.contains("## Example\n\n> Given ready, it works."),
        "{matches}"
    );
    assert!(matches.contains("\n\n---\n\n"), "{matches}");
    for (name, state, finding) in [
        ("pending", "Determination_false", "determination is false"),
        ("stale", "Invalid", "requirement text changed"),
        ("stale_input", "Invalid", "outline input changed"),
    ] {
        let output = habeas(temp.path(), &["info", &format!("requirements.{name}")]);
        assert!(output.status.success(), "{output:?}");
        let text = String::from_utf8(output.stdout).unwrap();
        assert!(text.contains(&format!("evidence-{state}")), "{text}");
        assert!(text.contains("## Validation findings"), "{text}");
        assert!(text.contains(finding), "{text}");
    }

    let missing = habeas(temp.path(), &["info", "requirements.absent"]);
    assert!(missing.status.success(), "{:?}", missing);
    let missing = String::from_utf8(missing.stdout).unwrap();
    assert!(missing.contains("## Validation findings"), "{missing}");
    assert!(missing.contains("missing for requirement"), "{missing}");
    assert!(missing.contains("No rationale recorded."), "{missing}");
    assert!(missing.contains("No inputs recorded."), "{missing}");

    let malformed = habeas(temp.path(), &["info", "requirements.malformed"]);
    assert!(malformed.status.success(), "{:?}", malformed);
    let malformed = String::from_utf8(malformed.stdout).unwrap();
    assert!(
        malformed.contains("## Unreadable evidence record"),
        "{malformed}"
    );
    assert!(malformed.contains("```json\n{broken\n```"), "{malformed}");
}
Input 5: outline tests/commands.rs fn[commands_report_invalid_arguments_and_unmatched_selectors]
// {test}`requirements.cli.status`
// {test}`requirements.cli.info`
// {test}`requirements.references.definition_globs`
#[test]
fn commands_report_invalid_arguments_and_unmatched_selectors() {
    let temp = fixture();
    for args in [
        ["status", "--wrong"].as_slice(),
        ["status", "--all", "extra", "more"].as_slice(),
        ["info"].as_slice(),
        ["info", "ready", "extra"].as_slice(),
    ] {
        let output = habeas(temp.path(), args);
        assert!(!output.status.success(), "{args:?}: {output:?}");
        assert!(
            String::from_utf8_lossy(&output.stderr).contains("Usage: habeas"),
            "{args:?}: {output:?}"
        );
    }
    for command in ["info", "status"] {
        let invalid = habeas(temp.path(), &[command, "["]);
        assert!(!invalid.status.success());
        assert!(
            String::from_utf8_lossy(&invalid.stderr).contains("invalid definition glob"),
            "{command}: {invalid:?}"
        );
    }
    let unmatched = habeas(temp.path(), &["info", "nothing.*"]);
    assert!(!unmatched.status.success());
    assert!(
        String::from_utf8_lossy(&unmatched.stderr).contains("no definitions match"),
        "{unmatched:?}"
    );
    let status = habeas(temp.path(), &["status", "requirements.*ready", "--all"]);
    assert!(status.status.success(), "{status:?}");
    let status = String::from_utf8(status.stdout).unwrap();
    assert!(
        status.contains("`requirements.ready` (requirement)"),
        "{status}"
    );
    assert!(
        status.contains("`requirements.xready` (requirement)"),
        "{status}"
    );
    assert!(!status.contains("| `requirements.pending`"), "{status}");
    let no_status = habeas(temp.path(), &["status", "nothing.*"]);
    assert!(!no_status.status.success());
    assert!(String::from_utf8_lossy(&no_status.stderr).contains("no definitions match"));

    let outside_project = TempDir::new().unwrap();
    let status = habeas(outside_project.path(), &["status"]);
    assert!(!status.status.success(), "{status:?}");
    assert!(
        String::from_utf8_lossy(&status.stderr)
            .contains("cannot find a project with Cargo.toml and book.toml"),
        "{status:?}"
    );
}
Input 6: outline tests/commands.rs fn[status_and_info_accept_a_definition_selection]
// {test}`requirements.cli.status`
// {test}`requirements.cli.info`
// {test}`requirements.cli.definition_glob_search`
#[test]
fn status_and_info_accept_a_definition_selection() {
    let temp = fixture();
    for (command, usage) in [("status", "[SELECTION]"), ("info", "<SELECTION>")] {
        let help = habeas(temp.path(), &[command, "--help"]);
        assert!(help.status.success(), "{help:?}");
        let help = String::from_utf8(help.stdout).unwrap();
        assert!(help.contains(usage), "{help}");
        assert!(
            help.contains("A full requirement or example name, or a definition glob"),
            "{help}"
        );
    }
    let status = habeas(temp.path(), &["status", "requirements.c*", "--all"]);
    assert!(status.status.success(), "{status:?}");
    let status = String::from_utf8(status.stdout).unwrap();
    assert!(
        status.contains("| `requirements.case` (example)"),
        "{status}"
    );
    assert!(!status.contains("| `requirements.ready`"), "{status}");
    let info = habeas(temp.path(), &["info", "requirements.case"]);
    assert!(info.status.success(), "{info:?}");
    let info = String::from_utf8(info.stdout).unwrap();
    assert!(info.starts_with("# `requirements.case`\n"), "{info}");
    assert!(!info.contains("# `requirements.ready`"), "{info}");
}
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"));
}

Referenced definitions

Input 8: definition requirements.references.definition_selection
:::{definition} definition_selection
:phrase: definition selection

A full requirement or example name, or a definition glob, identifying the
requirements and named examples it matches under
{cite}`requirements.references.definition_globs`. A name without `*` selects
exactly that definition.
:::

Other sources

Input 1: requirements selection requirements.cli.info
:::{req} info
`habeas info <selection>` MUST show the requirements and named examples matched by the {term}`requirements.references.definition_selection`. It MUST print matches in full-name order as Markdown with the same kind-labeled definition, Validation findings, Rationale, and Inputs structure and evidence states as mdBook detail pages, including readable output for missing or invalid evidence. It MUST work without a requirements index directive and report an invalid selection or no matches clearly. Habeas's bundled agent guidance MUST tell agents they can use this command to inspect a requirement or named example.
:::