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.test-coverage.check.exceptions

Requirements index · View definition

evidence Valid

Requirement

An unmet file threshold or an unexecuted or not-measured function MAY satisfy the coverage policy only through current, accepted, independently assessed evidence explaining why its coverage is incomplete. An exception MUST be attached to the source file or function whose incomplete coverage it justifies. A file-threshold exception MUST NOT automatically excuse untested functions. An exception MUST NOT excuse another source item’s incomplete coverage. Changes to the source item, justification, or other inputs of its citation review MUST invalidate the affected exception under cite requirements.references.citation_review.

A source comment or unassessed justification alone MUST NOT count as accepted exception evidence. Function and gap identities MUST remain portable between equivalent local and CI checkouts rather than depend on checkout paths, run identifiers, timestamps, or process identifiers.

Rationale

The four marked tests in src/execution_coverage/check.rs cover each obligation of requirements.test-coverage.check.exceptions. They are accepted_file_and_function_explanations_remain_separate_from_execution, standard_inline_doc_and_fenced_commentary_reviews_track_their_explanations, missing_and_stale_explanations_fail_the_report and function_explanations_never_transfer_to_other_functions_or_the_file. I found no gap. I did not read the implementation.

Obligations mapped to tests

  • A file or function exception may satisfy the policy only through current, accepted, independently assessed evidence.
    • With accepted reviews (reviews(root, json!(true))), accepted_file_and_function_explanations_remain_separate_from_execution passes. It reports “accepted exception” lines under “Accepted exceptions (do not increase execution coverage)”.
    • The same test covers a function with zero execution, an unmeasured function (not measured) and an unmeasured file (code.rs: not measured — accepted exception).
    • It fails the report when the review determination is false (“determination is false”).
    • It also fails when the determination is a {fixme} (“cannot accept a {fixme}”).
  • A comment or unassessed justification alone does not count.
    • missing_and_stale_explanations_fail_the_report uses cite commentary with no review file. The report fails with “missing citation review; run habeas author”.
    • Once a review is added, the same report passes.
    • standard_inline_doc_and_fenced_commentary_reviews_track_their_explanations shows that a /// doc comment and fenced {cite} commentary count only after review.
  • Changes invalidate the exception.
    • Changing the justification text gives “citations changed”. The function then returns to “zero execution”, and the exception is no longer accepted in the direct exceptions() calls.
    • Changing the item body gives “outline input changed”. The function again fails with “zero execution”.
    • The doc-comment case also shows an accepted exception becoming not accepted after “inaccessible” is changed to “reachable”.
  • An exception is attached to the file or function it justifies.
    • Exceptions are keyed as code.rs: file threshold and code.rs#fn[a].
    • The fixture places function rationale as a comment above fn a. That function is waived while the file is judged separately.
  • A file-threshold exception does not excuse untested functions. The first scenario in accepted_file_and_function_explanations_remain_separate_from_execution has only a file exception. It asserts !result.passed and #fn[a]: zero execution.
  • An exception does not excuse another item.
    • function_explanations_never_transfer_to_other_functions_or_the_file runs two cases. An outer-function exception does not waive inner or sibling. An inner-function exception does not waive outer or sibling.
    • It asserts that the waived function appears as an accepted exception and the others still show “zero execution; requires”.
    • A function exception does not satisfy the file threshold: the report shows the file as FAIL.
    • A different file (driver.rs) stays “not measured — FAIL” together with its function.
  • Identities are portable.
    • The review file is copied into a second fixture (a different checkout path). exceptions() still accepts it and reports no errors.
    • Records with different attempt numbers and start values keep the same exception identity in accepted_file_and_function_explanations_remain_separate_from_execution.
    • Changes in platform or config strings (linux, windows) in that test also leave the identity unchanged.

Residual notes

  • Staleness when the cited built-in text changes is governed by requirements.references.citation_review, which is cited context here. It is not assessed here.
  • Checks that exceptions cannot waive invalid measurement belong to other tests that are not part of this subject.

Inputs

Tests

Input 3: outline src/execution_coverage/check.rs mod[tests]/fn[accepted_file_and_function_explanations_remain_separate_from_execution]
    // {test}`requirements.test-coverage.check.exceptions`
    // {test}`requirements.test-coverage.check.exceptions.reviews`
    // {test}`requirements.test-coverage.check.exceptions.binding`
    // {test}`requirements.test-coverage.check.report`
    // {test}`requirements.test-coverage.check.functions`
    // {test}`requirements.test-coverage.check.measurement`
    // {test}`requirements.test-coverage.check.threshold`
    #[test]
    fn accepted_file_and_function_explanations_remain_separate_from_execution() {
        let temp = fixture(
            "//! :::{cite} habeas:coverage\n//! Generated platform glue lacks a harness.\n//! :::\n\nfn a() {}\n",
        );
        let root = temp.path();
        reviews(root, json!(true));
        record(root, "a", 1, "same", vec![process(root, &[(5, 0)], 0)]);
        let result = report(root);
        assert!(!result.passed, "file exception cannot waive its function");
        assert!(
            result
                .text
                .contains("code.rs: 0/1 (0.0%) — accepted exception")
        );
        assert!(result.text.contains("#fn[a]: zero execution"));
        fs::write(root.join("code.rs"),"//! :::{cite} habeas:coverage\n//! File rationale.\n//! :::\n\n// :::{cite} habeas:coverage\n// Function rationale, describing only a Linux condition.\n// :::\nfn a() {}\n").unwrap();
        reviews(root, json!(true));
        record(root, "a", 2, "linux", vec![process(root, &[(8, 0)], 0)]);
        let result = report(root);
        assert!(result.passed, "{}", result.text);
        assert!(result.text.contains("0/1 (0.0%)"));
        let exceptions = result
            .text
            .split_once("\nAccepted exceptions (do not increase execution coverage):\n")
            .unwrap()
            .1;
        assert!(exceptions.contains("- code.rs: file threshold (0/1 (0.0%))"));
        assert!(exceptions.contains("- code.rs#fn[a]: zero execution"));
        let mut absent = process(root, &[(8, 0)], 0);
        absent.functions = Some(vec![]);
        record(root, "a", 3, "windows", vec![absent]);
        let result = report(root);
        assert!(
            result.passed,
            "same accepted citation covers unmeasured functions without conditional matching"
        );
        let exceptions = result
            .text
            .split_once("\nAccepted exceptions (do not increase execution coverage):\n")
            .unwrap()
            .1;
        assert!(exceptions.contains("- code.rs#fn[a]: not measured"));
        record(root, "a", 4, "covered", vec![process(root, &[(8, 1)], 1)]);
        assert!(
            report(root).passed,
            "citation may remain when no exception is needed"
        );
        fs::write(root.join("driver.rs"), "fn driver() {}").unwrap();
        let mut p = process(root, &[], 0);
        p.lines.insert("driver.rs".into(), BTreeMap::from([(1, 1)]));
        p.functions.as_mut().unwrap().push(FunctionExecution {
            file: "driver.rs".into(),
            line: 1,
            column: 1,
            count: 1,
        });
        record(root, "a", 5, "unmeasured-file", vec![p]);
        let result = report(root);
        assert!(result.passed, "{}", result.text);
        assert!(
            result
                .text
                .contains("code.rs: not measured — accepted exception"),
            "{}",
            result.text
        );
        assert!(!result.text.contains("code.rs: 0/"), "{}", result.text);
        reviews(root, json!(false));
        assert!(!report(root).passed);
        assert!(report(root).text.contains("determination is false"));
        reviews(root, json!({"FIXME":["acknowledgment"]}));
        assert!(report(root).text.contains("cannot accept a {fixme}"));
    }
Input 4: outline src/execution_coverage/check.rs mod[tests]/fn[standard_inline_doc_and_fenced_commentary_reviews_track_their_explanations]
    // {test}`requirements.test-coverage.check.exceptions.reviews`
    // {test}`requirements.test-coverage.check.exceptions.author`
    // {test}`requirements.test-coverage.check.exceptions`
    #[test]
    fn standard_inline_doc_and_fenced_commentary_reviews_track_their_explanations() {
        let source = "/// Defensive invariant abort, inaccessible through the API.\n// {cite}`habeas:coverage`\nfn a() {}\n";
        let temp = fixture(source);
        let root = temp.path();
        reviews(root, json!(true));
        let mut errors = Vec::new();
        assert!(
            exceptions(root, &OutlineCache::default(), &mut errors)
                .unwrap()
                .values()
                .all(|exception| exception.accepted)
        );
        assert!(errors.is_empty());
        fs::write(
            root.join("code.rs"),
            source.replace("inaccessible", "reachable"),
        )
        .unwrap();
        let mut errors = Vec::new();
        assert!(
            exceptions(root, &OutlineCache::default(), &mut errors)
                .unwrap()
                .values()
                .all(|exception| !exception.accepted)
        );
        assert!(!errors.is_empty());
        let source = "// :::{cite} habeas:coverage\n// A protected rationale.\n// :::\nfn a() {}\n";
        fs::write(root.join("code.rs"), source).unwrap();
        reviews(root, json!(true));
        fs::write(root.join("code.rs"), source.replace("protected", "changed")).unwrap();
        let mut errors = Vec::new();
        assert!(
            exceptions(root, &OutlineCache::default(), &mut errors)
                .unwrap()
                .values()
                .all(|exception| !exception.accepted)
        );
        assert!(
            errors
                .iter()
                .any(|error| error.contains("citations changed"))
        );
        // Exception evidence uses project-relative identities in another checkout.
        fs::write(root.join("code.rs"), source).unwrap();
        reviews(root, json!(true));
        let other = fixture(source);
        let path = "evidence/citations/code.rs/fn[a].json";
        fs::create_dir_all(other.path().join("evidence/citations/code.rs")).unwrap();
        fs::copy(root.join(path), other.path().join(path)).unwrap();
        let mut errors = Vec::new();
        assert!(
            exceptions(other.path(), &OutlineCache::default(), &mut errors)
                .unwrap()
                .values()
                .all(|exception| exception.accepted)
        );
        assert!(errors.is_empty());
    }
Input 5: outline src/execution_coverage/check.rs mod[tests]/fn[missing_and_stale_explanations_fail_the_report]
    // {test}`requirements.test-coverage.check.exceptions`
    // {test}`requirements.test-coverage.check.exceptions.reviews`
    // {test}`requirements.test-coverage.check.report`
    // {test}`requirements.test-coverage.check.threshold`
    #[test]
    fn missing_and_stale_explanations_fail_the_report() {
        let source = "//! :::{cite} habeas:coverage\n//! File rationale.\n//! :::\n// :::{cite} habeas:coverage\n// Function rationale.\n// :::\nfn a() {}\n";
        let temp = fixture(source);
        let root = temp.path();
        record(root, "a", 1, "same", vec![process(root, &[(7, 0)], 0)]);
        let result = report(root);
        assert!(!result.passed);
        assert!(
            result
                .text
                .contains("missing citation review; run `habeas author"),
            "{}",
            result.text
        );
        reviews(root, json!(true));
        assert!(report(root).passed);
        fs::write(
            root.join("code.rs"),
            source.replace("Function rationale", "Changed rationale"),
        )
        .unwrap();
        record(root, "a", 2, "same", vec![process(root, &[(7, 0)], 0)]);
        let result = report(root);
        assert!(!result.passed);
        assert!(result.text.contains("citations changed"), "{}", result.text);
        assert!(
            result.text.contains("#fn[a]: zero execution"),
            "{}",
            result.text
        );
        fs::write(root.join("code.rs"), source).unwrap();
        reviews(root, json!(true));
        fs::write(
            root.join("code.rs"),
            source.replace("fn a() {}", "fn a() { let changed = 1; }"),
        )
        .unwrap();
        record(root, "a", 3, "same", vec![process(root, &[(7, 0)], 0)]);
        let result = report(root);
        assert!(!result.passed);
        assert!(
            result.text.contains("outline input changed"),
            "{}",
            result.text
        );
        assert!(
            result.text.contains("code.rs:7 #fn[a]: zero execution"),
            "{}",
            result.text
        );
    }
Input 6: outline src/execution_coverage/check.rs mod[tests]/fn[function_explanations_never_transfer_to_other_functions_or_the_file]
    // {test}`requirements.test-coverage.check.exceptions`
    // {test}`requirements.test-coverage.check.exceptions.reviews`
    // {test}`requirements.test-coverage.check.threshold`
    #[test]
    fn function_explanations_never_transfer_to_other_functions_or_the_file() {
        for (source, waived, remaining) in [
            (
                "// :::{cite} habeas:coverage\n// Outer reason.\n// :::\nfn outer() {\n fn inner() {}\n}\nfn sibling() {}\n",
                "fn[outer]",
                ["fn[outer]/fn[inner]", "fn[sibling]"],
            ),
            (
                "fn outer() {\n // :::{cite} habeas:coverage\n // Inner reason.\n // :::\n fn inner() {}\n}\nfn sibling() {}\n",
                "fn[outer]/fn[inner]",
                ["fn[outer]", "fn[sibling]"],
            ),
        ] {
            let temp = fixture(source);
            let root = temp.path();
            reviews(root, json!(true));
            record(root, "a", 1, "same", vec![process(root, &[(1, 1)], 0)]);
            let result = report(root);
            assert!(!result.passed);
            assert!(
                result
                    .text
                    .contains(&format!("- code.rs#{waived}: zero execution")),
                "{}",
                result.text
            );
            for selector in remaining {
                assert!(
                    result
                        .text
                        .contains(&format!("#{selector}: zero execution; requires")),
                    "{}",
                    result.text
                );
            }
            assert!(
                !result
                    .text
                    .contains(&format!("#{waived}: zero execution; requires")),
                "{}",
                result.text
            );
            record(root, "a", 2, "same", vec![process(root, &[(1, 0)], 0)]);
            let result = report(root);
            assert!(
                result.text.contains("code.rs: 0/1 (0.0%) — FAIL"),
                "{}",
                result.text
            );
            fs::write(root.join("driver.rs"), "fn other_file() {}").unwrap();
            record(root, "a", 3, "same", vec![process(root, &[(1, 1)], 0)]);
            let result = report(root);
            assert!(result.text.contains("driver.rs: not measured — FAIL"));
            assert!(result.text.contains("#fn[other_file]: not measured"));
        }
    }

Referenced definitions

Input 2: requirements selection requirements.references.citation_review
:::{req} citation_review
Every source item outside the book that carries at least one `{cite}` reference
other than a citation of `habeas:util` under {cite}`requirements.references.util`
MUST have a citation review: an assessment of that item's citations, recorded at
`evidence/citations/<file>/<selector>.json`, where `<file>` is the item's
project-relative path, `<selector>` is its outline selector with every `/` and
`%` percent-encoded, and the root node uses `_root`. The review MUST use the
prompt defined by {cite}`requirements.authoring.citation_prompt`. For citations
of project requirements and examples, the reviewer MUST assess whether the item
should be re-checked or kept in sync when the cited definition changes, and
whether the reference procedure of
{cite}`requirements.references.procedure` calls for `{impl}` or `{test}` instead.
For citations of built-ins, the reviewer MUST check the permitted reference
roles and forms and any citation-review criteria stated in the built-in's fixed
text, using the item's source and commentary. A permitted citation role alone
MUST NOT suffice when the fixed text states additional criteria. Mandatory inputs,
under {cite}`requirements.authoring.mandatory_inputs`, MUST be the item's outline
node, each cited declaration or built-in text, and the citations' commentary. The record MUST contain the item's file and selector,
its citations by role, name, and commentary, `determination`, `rationale`, and
`inputs`, with determinations under {cite}`requirements.ci.outcomes`. Validation
MUST require a current, accepted review for every such item and report stale,
missing, or orphaned reviews; a review MUST become stale when the item's hash,
a cited declaration, or its citations or their commentary change. Authoring with
`--all` MUST include citation reviews, and `habeas author citations:<file>#<selector>`
MUST author the review of the one item it names, under
{cite}`requirements.authoring.refresh`, where omitting `#<selector>`
names the file's root node. A citation in a requirement or example
declaration is reviewed as part of that definition's own assessment instead.
:::

Other sources

Input 1: requirements selection requirements.test-coverage.check.exceptions
:::{req} check.exceptions
An unmet file threshold or an unexecuted or not-measured function MAY satisfy
the coverage policy only
through current, accepted, independently assessed evidence explaining why its
coverage is incomplete. An exception MUST be attached to the source file or
function whose incomplete coverage it justifies. A file-threshold exception
MUST NOT automatically excuse untested functions.
An exception MUST NOT excuse another source item's incomplete coverage.
Changes to the source item, justification, or other inputs
of its citation review MUST invalidate the affected exception under
{cite}`requirements.references.citation_review`.

A source comment or unassessed justification alone MUST NOT count as accepted
exception evidence. Function and gap identities MUST remain portable between
equivalent local and CI checkouts rather than depend on checkout paths,
run identifiers, timestamps, or process identifiers.
:::
Input 7: outline src/execution_coverage/check.rs mod[tests]/fn[accepted_exceptions_cannot_waive_invalid_measurement_and_checks_still_collect_errors]
    // {test}`requirements.test-coverage.check.measurement`
    // {test}`requirements.ci.errors`
    #[test]
    fn accepted_exceptions_cannot_waive_invalid_measurement_and_checks_still_collect_errors() {
        let source = "//! :::{cite} habeas:coverage\n//! File rationale.\n//! :::\n// :::{cite} habeas:coverage\n// Function rationale.\n// :::\nfn a() {}\n";
        for failure in [
            "absent",
            "missing profile",
            "legacy",
            "corrupt counters",
            "stale",
            "corrupt history",
            "empty lines",
        ] {
            let temp = fixture(source);
            let root = temp.path();
            reviews(root, json!(true));
            if failure != "absent" {
                record(root, "a", 1, "same", vec![process(root, &[(7, 1)], 1)]);
                let mut p = process(root, &[(7, 0)], 0);
                if failure == "legacy" {
                    p.functions = None;
                }
                if failure == "corrupt counters" {
                    p.functions.as_mut().unwrap()[0].line = 0;
                }
                if failure == "empty lines" {
                    p.lines.clear();
                }
                let newest = record(root, "a", 2, "same", vec![p]);
                match failure {
                    "missing profile" => fs::remove_file(newest.join("profile.profraw")).unwrap(),
                    "stale" => fs::write(
                        root.join("code.rs"),
                        format!("{source}\n// changed build input\n"),
                    )
                    .unwrap(),
                    "corrupt history" => fs::write(
                        newest.parent().unwrap().parent().unwrap().join("run.json"),
                        "{",
                    )
                    .unwrap(),
                    _ => {}
                }
            }
            let result = report(root);
            assert!(!result.passed, "{failure}: {}", result.text);
            assert!(
                !result.text.contains("accepted exception"),
                "{failure}: {}",
                result.text
            );
            assert!(
                !result.text.contains("0/1 (0.0%)"),
                "{failure}: {}",
                result.text
            );
            if failure == "legacy" {
                assert!(
                    result
                        .text
                        .contains("recollect coverage with this Habeas version")
                );
            }
            if failure == "corrupt counters" {
                assert!(result.text.contains("corrupt function attribution"));
            }
            if failure == "empty lines" {
                assert!(result.text.contains("No usable instrumented lines"));
            }
            fs::remove_file(root.join("evidence/citations/code.rs/fn[a].json")).unwrap();
            let result = report(root);
            assert!(
                result.text.contains("missing citation review"),
                "{failure}: {}",
                result.text
            );
            let mut seen = std::collections::BTreeSet::new();
            for line in result.text.lines().filter(|line| line.starts_with("- ")) {
                assert!(seen.insert(line), "duplicate finding: {line}");
            }
            fs::write(root.join("broken.rs"), "fn malformed(").unwrap();
            fs::write(root.join("book.toml"), "[book]\nsrc = 7\n").unwrap();
            let result = report(root);
            assert!(
                result
                    .text
                    .to_lowercase()
                    .contains("cannot parse rust source"),
                "{}",
                result.text
            );
            assert!(
                result.text.contains("book.src must be a string"),
                "{}",
                result.text
            );
        }
    }