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

Requirements index · View definition

evidence Valid

Requirement

Exception proposals MUST be {cite} references to habeas:coverage under cite requirements.test-coverage.check.exceptions.anchor. Each proposal MUST have a current, accepted citation review of its source item under cite requirements.references.citation_review. The reviewer MUST assess whether the justification adequately explains the proposed exception, not merely whether the citation has the right role. An acknowledgment of missing coverage without an adequate justification MUST NOT authorize an exception.

File-threshold proposals MUST belong to the source file’s root item. Proposals concerning unexecuted or not-measured functions MUST belong to their explicitly declared function’s item. One accepted function proposal MUST cover both zero execution and absence from otherwise usable measurement, without separate exception kinds. A proposal in a nested function MUST NOT authorize exceptions for its enclosing function, and an enclosing function’s proposal MUST NOT authorize exceptions for nested functions.

Rationale

I judged this from the five supplied tests in src/execution_coverage/check.rs. I did not read the reviews, record, report and fixture helpers or the implementation.

Obligations derived from requirements.test-coverage.check.exceptions.reviews:

  1. A proposal is a {cite} of habeas:coverage, and it needs a current, accepted citation review.
  2. A missing review, a stale review, a false determination, or a {fixme} determination must not authorize an exception. The last two cover an acknowledgment without an adequate justification.
  3. A file-threshold proposal must belong to the file’s root item.
  4. A function proposal must belong to an explicitly declared function item.
  5. One accepted function proposal covers both zero execution and absence from measurement.
  6. A nested function’s proposal and its enclosing function’s proposal must not cover each other.

Mapping to tests:

  • Missing review. missing_and_stale_explanations_fail_the_report runs with no review recorded. The report fails with “missing citation review; run habeas author”. Once reviews are written, the same report passes.
  • Stale review.
    • The same test changes the function commentary. The report fails with “citations changed”, and the function is reported as zero execution.
    • It then changes the function body. The report fails with “outline input changed” and the function is again reported as zero execution.
    • standard_inline_doc_and_fenced_commentary_reviews_track_their_explanations checks that a changed Rust doc comment makes the exception unaccepted. It checks that changed fenced commentary does the same and reports “citations changed”. It also checks that the review evidence stays valid when copied to another checkout, because identities are project-relative.
  • Accepted and rejected determinations. accepted_file_and_function_explanations_remain_separate_from_execution checks that accepted reviews permit the exception. It then sets the determination to false and expects failure with “determination is false”. It then sets a {fixme} determination and expects “cannot accept a {fixme}”. This covers the rule that an acknowledgment without adequate justification must not authorize an exception.
  • File-root ownership.
    • proposals_on_modules_structs_and_impls_waive_neither_files_nor_functions puts the proposal on a mod, a struct, and an impl. The file-threshold and function exceptions are all refused. The report fails with “without a current accepted habeas:coverage citation on the file root” and “requires a current accepted habeas:coverage citation on this function”, and shows no accepted exceptions.
    • The accepted-explanations test shows that a root-level file proposal does not waive the function. It also shows that the function exception leaves the file threshold as a separate “file threshold” line.
    • function_explanations_never_transfer_to_other_functions_or_the_file shows that a function proposal does not waive the file. The file still reports 0/1 (0.0%) — FAIL.
  • Function item ownership and both exception outcomes. The accepted-explanations test uses one function citation. It is accepted for zero execution, then for not measured with the same citation and a different measurement context. It still passes when coverage is fully satisfied. It also covers a file that is not measured at all.
  • Nesting. function_explanations_never_transfer_to_other_functions_or_the_file runs two cases. An outer-function proposal waives only the outer function, while the nested inner and the sibling still require a proposal. An inner-function proposal waives only inner, while outer and sibling still require one. The assertions check both the accepted exception line and the “requires” failure lines. It also checks that a file-level not measured failure still appears for other files.

Not tested here:

  • The reviewer’s judgment of whether a justification is substantive is the review process’s job. The tests cover only the gate that consumes the review’s outcome.
  • The {cite}-only restriction on habeas:coverage belongs to requirements.test-coverage.check.exceptions.anchor, not to the subject.

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

Inputs

Tests

Input 4: outline src/execution_coverage/check.rs mod[tests]/fn[proposals_on_modules_structs_and_impls_waive_neither_files_nor_functions]
    // {test}`requirements.test-coverage.check.exceptions.reviews`
    #[test]
    fn proposals_on_modules_structs_and_impls_waive_neither_files_nor_functions() {
        for source in [
            "// :::{cite} habeas:coverage\n// Container commentary.\n// :::\nmod m { fn work() {} }\n",
            "// :::{cite} habeas:coverage\n// Container commentary.\n// :::\nstruct S; impl S { fn work() {} }\n",
            "struct S;\n// :::{cite} habeas:coverage\n// Container commentary.\n// :::\nimpl S { fn work() {} }\n",
        ] {
            let temp = fixture(source);
            let root = temp.path();
            reviews(root, json!(true));
            record(root, "work", 1, "same", vec![process(root, &[(4, 0)], 0)]);
            let result = report(root);
            assert!(!result.passed);
            assert!(result.text.contains(
                "without a current accepted `habeas:coverage` citation on the file root"
            ));
            assert!(result.text.contains(
                "requires a current accepted `habeas:coverage` citation on this function"
            ));
            assert!(!result.text.contains("Accepted exceptions ("));
        }
    }
Input 5: 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 6: 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 7: 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 8: 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.test-coverage.check.exceptions.anchor
:::{req} check.exceptions.anchor
Habeas MUST provide the built-in `habeas:coverage` under
{cite}`requirements.references.builtin_definitions`, with this text:

> Cite this on a source file or explicitly declared function to propose a
> coverage exception. Explain in prose why the item's incomplete execution
> coverage is acceptable. Put the explanation in fenced citation commentary
> or Rust doc comments included in the source item's assessed input. An ordinary
> non-doc comment alone does not supply a tracked justification. The reason
> must be substantive; difficulty alone is not a justification.
> On a file's root item, the exception excuses only
> that file's 80% instrumented-line threshold, including absent measurement
> of its executable code. On an explicit function with a body, it excuses
> that function's recorded zero execution or absence from otherwise usable
> measurement, without excusing the file's threshold.
> The explanation must agree with the current source and any callers or
> configuration assumptions on which it relies. Only a current accepted
> independent assessment permits the exception. A file exception does not
> excuse unexecuted or not-measured functions in that file.
> The citation applies to its source item without conditional build matching
> and may remain when measured coverage satisfies the item's obligations.

Only `{cite}` MAY reference this built-in, inline or fenced using the standard
reference forms of {cite}`requirements.references.roles`. The built-in MUST be
available in every project without a project requirement, site query, or
exception-specific configuration.
:::
Input 3: 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.reviews
:::{req} check.exceptions.reviews
Exception proposals MUST be `{cite}` references to `habeas:coverage`
under {cite}`requirements.test-coverage.check.exceptions.anchor`. Each proposal
MUST have a current, accepted citation review of its source item under
{cite}`requirements.references.citation_review`. The reviewer MUST assess
whether the justification adequately explains the proposed exception, not merely
whether the citation has the right role. An acknowledgment of missing coverage
without an adequate justification MUST NOT authorize an exception.

File-threshold proposals MUST belong to the source file's root item. Proposals
concerning unexecuted or not-measured functions MUST belong to their explicitly
declared function's item. One accepted function proposal MUST cover both zero execution
and absence from otherwise usable measurement, without separate exception kinds.
A proposal in a nested function MUST NOT authorize exceptions
for its enclosing function, and an enclosing function's proposal MUST NOT
authorize exceptions for nested functions.
:::