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.state

Requirements index · View definition

evidence Valid

Requirement

The requirements index MUST show each requirement’s evidence state as Valid, Missing, Determination false, FIXME, or Invalid. Valid MUST mean its determination is true and its record passes the same evidence and reference coverage checks as habeas::validate(). A false or FIXME determination MUST have its distinct state when the record passes all other checks. The FIXME state MUST pass validation while retaining its distinct label. Malformed or stale evidence MUST remain Invalid regardless of its determination. Each detail page MUST show any validation findings.

Rationale

The reviewed tests cover every obligation in requirements.index.state.

Obligations derived from the text

  1. The index shows one of five states per requirement: Valid, Missing, Determination false, FIXME or Invalid.
  2. Valid means the determination is true and the record passes the same evidence and reference-coverage checks as habeas::validate().
  3. A false or FIXME determination keeps its own state when the record passes all other checks.
  4. The FIXME state passes validation but keeps its own label.
  5. Malformed or stale evidence is Invalid whatever its determination.
  6. Each detail page shows any validation findings.

Coverage in src/index.rs

  • mod[tests]/fn[index_shows_evidence_states_and_links_generated_chapters] builds five requirements and asserts each row’s state cell:
    • ready (true, clean) is Valid.
    • pending (false, clean) is Determination false.
    • changed (true, stale requirement text) is Invalid.
    • absent (no record) is Missing.
    • uncovered (true, record clean but a {test} reference is not covered by any input) is Invalid. This is the reference-coverage half of the Valid condition.
    • The changed detail page contains “requirement text changed”, so findings reach the page.
    • The ready detail page has the Valid badge and no “## Evidence record” heading.
  • mod[tests]/fn[findings_make_false_and_fixme_records_invalid] is a determination-by-condition matrix, and for every row it asserts the state and whether the detail page contains “Validation findings”:
    • false and clean gives Determination false.
    • false and stale gives Invalid.
    • false and malformed (unknown field) gives Invalid.
    • false and uncovered reference gives Invalid.
    • FIXME and clean gives FIXME, with no findings on its page.
    • FIXME and stale gives Invalid, with findings shown.
    • The clean FIXME row shows the FIXME state with no findings, so FIXME passes validation and keeps its label.

Coverage in tests/outcomes.rs, through the shared status rendering

  • fn[malformed_fixme_is_invalid_and_reports_the_required_shape] asserts that a malformed FIXME gives Invalid, a validate error containing “nonempty array”, and that finding in the status output.
  • fn[fixme_does_not_hide_stale_inputs_or_uncovered_references] asserts that a FIXME with a stale input is Invalid and shows the finding. It also asserts that an uncovered reference produces a validate error.
  • fn[valid_fixme_remains_visible_in_status_info_and_book] asserts that a valid FIXME shows as FIXME in the index and detail page, with no “## Validation findings” in the status output.
  • fn[fixme_examples_pass_without_test_references_but_true_examples_do_not] is not marked for this requirement. It does show that validate_repository returns no errors for the fixture FIXME record.

Remaining observations

  • No index test combines a true determination with malformed JSON. The malformed-evidence → Invalid obligation is exercised with false and FIXME determinations, and true-determination records are covered for stale and uncovered cases. A true-and-malformed row would only repeat a distinction the tests already make, so I don’t count it as a gap.
  • The tests assert both the state labels and the presence or absence of findings, so a wrong state or missing findings would fail them.

I found no gaps and no marking gaps.

Inputs

Tests

Input 2: 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 3: outline src/index.rs mod[tests]/fn[findings_make_false_and_fixme_records_invalid]
  • File: src/index.rs
  • Selector: mod[tests]/fn[findings_make_false_and_fixme_records_invalid]
  • Kind: fn
  • src/index.rs:1815–1917
    // {test}`requirements.index.state`
    #[test]
    fn findings_make_false_and_fixme_records_invalid() {
        let temp = TempDir::new().unwrap();
        let root = temp.path();
        for dir in ["md", "evidence", "src"] {
            fs::create_dir_all(root.join(dir)).unwrap();
        }
        fs::write(root.join("book.toml"), "[book]\nsrc = \"md\"\n").unwrap();
        let names = [
            "false_clean",
            "false_stale",
            "false_malformed",
            "false_uncovered",
            "fixme_clean",
            "fixme_stale",
        ];
        let mut source = String::new();
        for name in names {
            source.push_str(&format!(":::{{req}} {name}\nThe {name} rule.\n:::\n\n"));
        }
        fs::write(root.join("md/rules.md"), &source).unwrap();
        fs::write(
            root.join("src/lib.rs"),
            "// {test}`rules.false_uncovered`\nfn uncovered() {}\n\n// :::{fixme} rules.fixme_clean\n// :github: example/rules#9\n// The gap.\n// :::\nfn gap() {}\n",
        )
        .unwrap();
        let gap = crate::inputs::outline_input(root, "src/lib.rs", "fn[gap]").unwrap();
        for name in names {
            let determination = if name.starts_with("fixme") {
                json!({"FIXME": ["example/rules#9"]})
            } else {
                json!(false)
            };
            let text = if name.ends_with("stale") {
                "An older rule.".to_owned()
            } else {
                format!("The {name} rule.")
            };
            let mut record = json!({
                "requirement": text,
                "determination": determination,
                "rationale": format!("The {name} fixture."),
                "inputs": if name == "fixme_clean" { json!([gap]) } else { json!([]) },
            });
            if name == "false_malformed" {
                record["unexpected"] = json!(true);
            }
            fs::write(
                root.join(format!("evidence/rules.{name}.json")),
                record.to_string(),
            )
            .unwrap();
        }

        let mut book = Book::new();
        book.push_item(Chapter::new("Rules", source, "rules.md", Vec::new()));
        book.push_item(Chapter::new(
            "Index",
            ":::{requirements-index}\n:::\n".to_owned(),
            "requirements-index.md",
            Vec::new(),
        ));
        crate::evidence::tests::stamp_reference_sets(root);
        preprocess_book(&mut book, root).unwrap();
        let index = book
            .chapters()
            .find(|chapter| chapter.name == "Index")
            .unwrap();
        for (name, state) in [
            ("false_clean", "Determination false"),
            ("false_stale", "Invalid"),
            ("false_malformed", "Invalid"),
            ("false_uncovered", "Invalid"),
            ("fixme_clean", "FIXME"),
            ("fixme_stale", "Invalid"),
        ] {
            let link = format!("| [`rules.{name}`](requirements-index/rules.{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, "{row}");
            let page = index
                .sub_items
                .iter()
                .find_map(|item| match item {
                    BookItem::Chapter(chapter) if chapter.name == format!("rules.{name}") => {
                        Some(chapter)
                    }
                    _ => None,
                })
                .unwrap();
            // Every page with findings shows them, whatever the determination.
            assert_eq!(
                page.content.contains("Validation findings"),
                state != "FIXME",
                "{name}: {}",
                page.content
            );
        }
    }
Input 4: outline tests/outcomes.rs fn[malformed_fixme_is_invalid_and_reports_the_required_shape]
// {test}`requirements.ci.schema`
// {test}`requirements.ci.outcomes`
// {test}`requirements.index.state`
// {test}`requirements.cli.fixme_summary`
// {test}`requirements.ci.determination`
// {test}`requirements.examples.evidence`
#[test]
fn malformed_fixme_is_invalid_and_reports_the_required_shape() {
    let temp = fixture();
    replace_judgment(temp.path(), "timeout", json!({ "FIXME": [] }));
    let report = habeas::validate_repository(temp.path()).unwrap();
    assert!(
        report
            .errors
            .iter()
            .any(|error| error.contains("nonempty array"))
    );
    let status = habeas::status_markdown(temp.path(), false).unwrap();
    let row = status
        .lines()
        .find(|line| line.starts_with("| `requirements.timeout`"))
        .unwrap();
    assert!(row.contains("Invalid"), "{row}");
    assert!(status.contains("nonempty array"), "{status}");
    assert!(!status.contains("affects"), "{status}");
}
Input 5: outline tests/outcomes.rs fn[fixme_does_not_hide_stale_inputs_or_uncovered_references]
// {test}`requirements.ci.outline_inputs`
// {test}`requirements.ci.determination`
// {test}`requirements.references.evidence_coverage`
// {test}`requirements.ci.fixme_stale_input`
// {test}`requirements.index.state`
// {test}`requirements.cli.fixme_summary`
#[test]
fn fixme_does_not_hide_stale_inputs_or_uncovered_references() {
    let temp = fixture();
    let observed = temp.path().join("observed.rs");
    let source = fs::read_to_string(&observed).unwrap();
    fs::write(&observed, source.replace("= 1;", "= 2;")).unwrap();
    let report = habeas::validate_repository(temp.path()).unwrap();
    assert!(
        report
            .errors
            .iter()
            .any(|error| error.contains("outline input changed: observed.rs <root>")),
        "{:?}",
        report.errors
    );
    let status = habeas::status_markdown(temp.path(), false).unwrap();
    let row = status
        .lines()
        .find(|line| line.starts_with("| `requirements.timeout`"))
        .unwrap();
    assert!(row.contains("Invalid"), "{row}");
    assert!(status.contains("example/io#125"), "{status}");
    assert!(status.contains("outline input changed"), "{status}");
    fs::write(
        temp.path().join("other.txt"),
        "{test}`requirements.timeout`",
    )
    .unwrap();
    let report = habeas::validate_repository(temp.path()).unwrap();
    assert!(
        report
            .errors
            .iter()
            .any(|error| error.contains("no input covers") && error.contains("other.txt:1"))
    );
}
Input 6: 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"));
}

Other sources

Input 1: requirements selection requirements.index.state
:::{req} state
The requirements index MUST show each requirement's evidence state as Valid, Missing, Determination false, FIXME, or Invalid. Valid MUST mean its determination is true and its record passes the same evidence and reference coverage checks as `habeas::validate()`. A false or FIXME determination MUST have its distinct state when the record passes all other checks. The FIXME state MUST pass validation while retaining its distinct label. Malformed or stale evidence MUST remain Invalid regardless of its determination. Each detail page MUST show any validation findings.
:::
Input 7: outline tests/outcomes.rs fn[fixme_examples_pass_without_test_references_but_true_examples_do_not]
  • File: tests/outcomes.rs
  • Selector: fn[fixme_examples_pass_without_test_references_but_true_examples_do_not]
  • Kind: fn
  • tests/outcomes.rs:144–168
// {test}`requirements.ci.determination`
// {test}`requirements.examples.evidence`
// {test}`requirements.ci.fixme_example_test_gaps`
#[test]
fn fixme_examples_pass_without_test_references_but_true_examples_do_not() {
    let temp = fixture();
    let report = habeas::validate_repository(temp.path()).unwrap();
    assert!(report.errors.is_empty(), "{:?}", report.errors);
    replace_judgment(temp.path(), "timeout", json!(true));
    let report = habeas::validate_repository(temp.path()).unwrap();
    assert!(
        report
            .errors
            .iter()
            .any(|error| error.contains("no {test} reference"))
    );
    replace_judgment(temp.path(), "timeout", json!(false));
    let report = habeas::validate_repository(temp.path()).unwrap();
    assert!(
        report
            .errors
            .iter()
            .any(|error| error.contains("determination is false"))
    );
}
Input 8: outline tests/outcomes.rs fn[fixme_does_not_excuse_missing_or_malformed_evidence]
// {test}`requirements.ci.determination`
#[test]
fn fixme_does_not_excuse_missing_or_malformed_evidence() {
    let temp = fixture();
    let errors = |root: &Path| habeas::validate_repository(root).unwrap().errors;
    assert!(errors(temp.path()).is_empty(), "{:?}", errors(temp.path()));
    let path = temp.path().join("evidence/requirements.timeout.json");
    let original: Value = serde_json::from_str(&fs::read_to_string(&path).unwrap()).unwrap();

    // A malformed record judged FIXME: an unknown field and a wrong example
    // text are each still reported.
    let mut malformed = original.clone();
    malformed["extra"] = json!(1);
    malformed["example"] = json!("Timeout handling does not retry.");
    fs::write(&path, serde_json::to_string_pretty(&malformed).unwrap()).unwrap();
    let found = errors(temp.path());
    for expected in ["unexpected field \"extra\"", "example text changed"] {
        assert!(
            found.iter().any(
                |error| error.starts_with("evidence/requirements.timeout.json")
                    && error.contains(expected)
            ),
            "missing {expected:?}: {found:#?}"
        );
    }

    // A definition whose gap a {fixme} acknowledges still needs evidence.
    fs::remove_file(&path).unwrap();
    let found = errors(temp.path());
    assert!(
        found
            .iter()
            .any(|error| error
                .starts_with("evidence/requirements.timeout.json: missing for example")),
        "{found:#?}"
    );
}