requirements.test-coverage.check.exceptions.anchor
Requirements index · View definition
Requirement
Habeas MUST provide the built-in
habeas:coverageunder, 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. The built-in MUST be available in every project without a project requirement, site query, or exception-specific configuration.
Rationale
I found no test-adequacy gap for requirements.test-coverage.check.exceptions.anchor.
Obligations derived from the subject text
- Habeas provides the built-in
habeas:coveragewith the quoted text. - Only
{cite}may reference it, inline or fenced. - It is available in every project without a project requirement, site query or special configuration.
- The book renders it as an unlinked badge whose hover text is the full text. This comes from
requirements.references.builtin_definitions, which the subject cites.
The semantics inside the quoted text, such as file versus function excusal and review acceptance, belong to the coverage-check and review requirements. The subject only requires that the text be provided. That text is context here, not something this requirement’s tests must re-verify.
Test mapping
- Text.
src/builtins.rs#mod[tests]/fn[coverage_builtin_uses_the_documented_text_and_only_the_citation_role]asserts thatcoverage.text()equals the text quoted inmd/reference.md.Builtin::textderives the string from the requirement body itself (md/requirements/test-coverage.md,:::{req} check.exceptions.anchor), so the quoted text cannot drift from the requirement.- The test also asserts the key phrases “difficulty alone”, “file’s 80%” and “without conditional build matching”. The “file’s 80%” phrase spans a source line break, so it checks that the block-quote lines are joined correctly.
- Role restriction. The same test asserts
check(ReferenceKind::Cite)isOk. It assertsErrforImpl,Test,FixmeandTerm, which are all the other roles. - Single provision. It asserts that
BUILTINScontains exactly onehabeas:coverageentry. - Fenced form and rendering.
src/lib.rs#mod[tests]/fn[fenced_references_render_their_badge_and_body_and_built_ins_are_unlinked]fences a{cite}ofhabeas:coveragein a chapter.- It checks the rendered output is an unlinked
habeas-builtinbadge whosetitleequalsescape_html(coverage.text()). - It checks the commentary body is retained and that no
href="habeaslink appears. - It also checks that an unknown name (
habeas:none) stays literal.
- It checks the rendered output is an unlinked
- Availability with no declaration. That render test builds a book from a bare temporary root with no
habeas:coveragedeclaration or configuration.- The built-in is a static table lookup with no per-project setup, so there is no separate configuration path to test.
- Other tests in
src/execution_coverage/check.rsandsrc/authoring/mod.rsalso use inline and fencedhabeas:coveragecitations in fixture projects. They carry no{test}marking for this subject and I did not rely on them.
Residual notes
- Validation reporting of wrong-role references to built-ins is an obligation of
requirements.references.builtin_definitions, not of this subject. The subject’s own “only cite MAY” clause is checked throughBuiltin::check. - The inline form is exercised for
habeas:utilin the render test. It uses the same built-in lookup and role check ashabeas:coverage, which is covered by the role assertions above. I treat that as no separate required scenario.
There is no acknowledged FIXME and no unacknowledged gap.
Inputs
Implementation
Input 6: outline src/builtins.rs (whole file)
- File:
src/builtins.rs - Selector:
(root) - Kind:
file src/builtins.rs:1–169
//! Built-in definitions named `habeas:<name>`, available in every project.
use std::sync::OnceLock;
use crate::ReferenceKind;
/// A built-in definition: fixed text and the roles that may reference it.
// {cite}`habeas:util`
pub(crate) struct Builtin {
pub(crate) name: &'static str,
pub(crate) roles: &'static [ReferenceKind],
}
/// Every built-in definition.
// {impl}`requirements.references.util`
// {impl}`requirements.test-coverage.check.exceptions.anchor`
pub(crate) const BUILTINS: &[Builtin] = &[
Builtin {
name: "habeas:util",
roles: &[ReferenceKind::Cite],
},
Builtin {
name: "habeas:coverage",
roles: &[ReferenceKind::Cite],
},
];
/// Whether a name has the reserved built-in form `habeas:<name>`.
// {cite}`habeas:util`
pub(crate) fn is_builtin_name(name: &str) -> bool {
name.strip_prefix("habeas:").is_some_and(crate::valid_name)
}
/// The built-in definition with a name, if any.
// {cite}`habeas:util`
pub(crate) fn builtin(name: &str) -> Option<&'static Builtin> {
BUILTINS.iter().find(|builtin| builtin.name == name)
}
impl Builtin {
/// The built-in's fixed text, as quoted in its requirement.
// {impl}`requirements.references.util`
// {impl}`requirements.test-coverage.check.exceptions.anchor`
pub(crate) fn text(&self) -> &'static str {
static UTIL: OnceLock<String> = OnceLock::new();
static COVERAGE: OnceLock<String> = OnceLock::new();
// Keep the approved requirement text as the sole source.
let chapter = include_str!("../md/requirements/references.md");
match self.name {
"habeas:util" => UTIL.get_or_init(|| quoted_text(chapter, ":::{req} util")),
"habeas:coverage" => COVERAGE.get_or_init(|| {
quoted_text(
include_str!("../md/requirements/test-coverage.md"),
":::{req} check.exceptions.anchor",
)
}),
_ => unreachable!("every built-in has text"),
}
}
/// Checks a reference to this built-in, returning the problem when its
/// role is not permitted.
// {cite}`habeas:util`
pub(crate) fn check(&self, kind: ReferenceKind) -> Result<(), String> {
if !self.roles.contains(&kind) {
return Err(format!(
"built-in {} may only be referenced with {}",
self.name,
self.roles
.iter()
.map(|role| format!("{{{}}}", role.label()))
.collect::<Vec<_>>()
.join(" or ")
));
}
Ok(())
}
}
/// The first block quote after `marker` in a chapter, without its `> `
/// prefixes, joined as one paragraph.
// {cite}`habeas:util`
fn quoted_text(chapter: &str, marker: &str) -> String {
let start = chapter.find(marker).expect("approved built-in text");
chapter[start..]
.lines()
.skip_while(|line| !line.starts_with('>'))
.take_while(|line| line.starts_with('>'))
.map(|line| line.trim_start_matches('>').trim())
.collect::<Vec<_>>()
.join(" ")
}
#[cfg(test)]
mod tests {
use super::*;
// {test}`requirements.test-coverage.check.exceptions.anchor`
#[test]
fn coverage_builtin_uses_the_documented_text_and_only_the_citation_role() {
let coverage = builtin("habeas:coverage").unwrap();
assert_eq!(
coverage.text(),
quoted_text(
include_str!("../md/reference.md"),
"The built-in `habeas:coverage` has this text:",
)
);
assert!(coverage.text().contains("difficulty alone"));
assert!(coverage.text().contains("file's 80%"));
assert!(
coverage
.text()
.contains("without conditional build matching")
);
assert!(coverage.check(ReferenceKind::Cite).is_ok());
for kind in [
ReferenceKind::Impl,
ReferenceKind::Test,
ReferenceKind::Fixme,
ReferenceKind::Term,
] {
assert!(coverage.check(kind).is_err());
}
assert_eq!(
BUILTINS
.iter()
.filter(|builtin| builtin.name == "habeas:coverage")
.count(),
1
);
}
// {test}`requirements.references.util`
// {test}`requirements.references.builtin_definitions`
#[test]
fn habeas_util_has_its_approved_text_and_permits_inline_or_fenced_citations() {
let util = builtin("habeas:util").unwrap();
assert!(
util.text()
.starts_with("Cite this on an item that serves other code, including code outside")
);
assert!(
util.text()
.ends_with("judges what it does as part of that root.")
);
assert!(util.check(ReferenceKind::Cite).is_ok());
for role in [ReferenceKind::Impl, ReferenceKind::Test] {
assert!(
util.check(role)
.unwrap_err()
.contains("built-in habeas:util may only be referenced with {cite}")
);
}
// The reference documentation quotes the same text.
let documented = quoted_text(
include_str!("../md/reference.md"),
"The built-in `habeas:util` has this text:",
);
assert_eq!(documented, util.text());
// `habeas:none` was removed, so it is an unknown built-in name.
assert!(builtin("habeas:none").is_none());
assert!(builtin("habeas:other").is_none());
assert!(is_builtin_name("habeas:util"));
assert!(is_builtin_name("habeas:none"));
assert!(!is_builtin_name("habeas:"));
assert!(!is_builtin_name("other:util"));
}
}
Tests
Input 4: outline src/builtins.rs mod[tests]/fn[coverage_builtin_uses_the_documented_text_and_only_the_citation_role]
- File:
src/builtins.rs - Selector:
mod[tests]/fn[coverage_builtin_uses_the_documented_text_and_only_the_citation_role] - Kind:
fn src/builtins.rs:98–132
// {test}`requirements.test-coverage.check.exceptions.anchor`
#[test]
fn coverage_builtin_uses_the_documented_text_and_only_the_citation_role() {
let coverage = builtin("habeas:coverage").unwrap();
assert_eq!(
coverage.text(),
quoted_text(
include_str!("../md/reference.md"),
"The built-in `habeas:coverage` has this text:",
)
);
assert!(coverage.text().contains("difficulty alone"));
assert!(coverage.text().contains("file's 80%"));
assert!(
coverage
.text()
.contains("without conditional build matching")
);
assert!(coverage.check(ReferenceKind::Cite).is_ok());
for kind in [
ReferenceKind::Impl,
ReferenceKind::Test,
ReferenceKind::Fixme,
ReferenceKind::Term,
] {
assert!(coverage.check(kind).is_err());
}
assert_eq!(
BUILTINS
.iter()
.filter(|builtin| builtin.name == "habeas:coverage")
.count(),
1
);
}
Input 5: outline src/lib.rs mod[tests]/fn[fenced_references_render_their_badge_and_body_and_built_ins_are_unlinked]
- File:
src/lib.rs - Selector:
mod[tests]/fn[fenced_references_render_their_badge_and_body_and_built_ins_are_unlinked] - Kind:
fn src/lib.rs:915–1004
// {test}`requirements.references.book_badges`
// {test}`requirements.references.builtin_definitions`
// {test}`requirements.test-coverage.check.exceptions.anchor`
#[test]
fn fenced_references_render_their_badge_and_body_and_built_ins_are_unlinked() {
let mut book = Book::new();
let content = [
"::::{req} ready\nReady MUST hold.\n\n:::{cite} rules.other\nThe *other* rule.\n:::\n::::\n\n",
":::{req} other\nOther.\n:::\n\n",
":::{cite} habeas:util\nServes its caller.\n:::\n\n",
":::{cite} habeas:coverage\nA substantive coverage explanation.\n:::\n\n",
":::{cite} habeas:none\nRemoved.\n:::\n\n",
"Inline {cite}`habeas:none` stays literal.\n\n",
"Inline {cite}`habeas:util` is a badge.\n\n",
":::{cite} rules.missing\nUnknown.\n:::\n\n",
"```text\n:::{cite} rules.other\n:::\n```\n",
]
.concat();
book.push_item(Chapter::new("Rules", content, "rules.md", Vec::new()));
let root = book_root();
preprocess_book(&mut book, root.path()).unwrap();
let rendered = book.chapters().next().unwrap().content.clone();
// The project reference links to its definition, then its body.
let mut html = String::new();
pulldown_cmark::html::push_html(&mut html, pulldown_cmark::Parser::new(&rendered));
assert!(html.contains("<p>The <em>other</em> rule.</p>"), "{html}");
assert!(html.contains("alt=\"req rules.ready\""), "{html}");
let linked = "<div class=\"habeas-fenced-ref\">\n\n<p><a class=\"habeas-req-badge habeas-req-ref-cite\" href=\"rules.html#habeas-req-rules.other\">";
let start = rendered.find(linked).expect(&rendered);
let after = &rendered[start..];
assert!(
after.find("alt=\"cite rules.other\"").unwrap()
< after.find("The *other* rule.").unwrap(),
"{rendered}"
);
assert!(
!rendered.contains(":::{cite} rules.other\nThe"),
"{rendered}"
);
// The outer requirement still contains it and closes at its own fence.
assert!(!rendered.contains("See evidence"), "{rendered}");
// A built-in has no link; its hover text is its full text.
let util = crate::builtins::builtin("habeas:util").unwrap();
let coverage = crate::builtins::builtin("habeas:coverage").unwrap();
assert!(rendered.contains(&format!(
"<span class=\"habeas-req-badge habeas-req-ref-cite habeas-builtin\" title=\"{}\"><img",
super::escape_html(coverage.text())
)), "{rendered}");
assert!(
rendered.contains(&format!(
"<span class=\"habeas-req-badge habeas-req-ref-cite habeas-builtin\" title=\"{}\"><img",
super::escape_html(util.text())
)),
"{rendered}"
);
let inline = rendered
.split("Inline ")
.find(|part| part.contains(" is a badge."))
.unwrap();
let inline = inline.split(" is a badge.").next().unwrap();
assert!(inline.starts_with(&format!("<span class=\"habeas-req-badge habeas-req-ref-cite habeas-builtin\" title=\"{}\"><img", super::escape_html(util.text()))), "{inline}");
assert!(
inline.contains("habeas:util") && inline.ends_with("</span>"),
"{inline}"
);
assert!(!inline.contains("<a "), "{inline}");
let badge = "<p><span class=\"habeas-req-badge habeas-req-ref-cite habeas-builtin\"";
let fenced = rendered.find(badge).expect(&rendered);
assert!(
rendered[fenced..].find("Serves its caller.").is_some(),
"{rendered}"
);
assert!(!rendered.contains("href=\"habeas"), "{rendered}");
// Invalid forms, unknown names, and code examples remain literal.
assert!(
rendered.contains(":::{cite} habeas:none\nRemoved.\n:::"),
"{rendered}"
);
assert!(rendered.contains("Inline {cite}`habeas:none` stays literal."));
assert!(
rendered.contains(":::{cite} rules.missing\nUnknown.\n:::"),
"{rendered}"
);
assert!(
rendered.contains("```text\n:::{cite} rules.other\n:::\n```"),
"{rendered}"
);
}
Referenced definitions
Input 2: requirements selection requirements.references.builtin_definitions
requirements.references.builtin_definitions:md/requirements/references.md:126–144
:::{req} builtin_definitions
Habeas MUST provide built-in definitions named `habeas:<name>`, available in
every project without a declaration. Each built-in MUST have fixed text, which
states its obligations and is documented in Habeas's reference documentation, and
MUST state which reference roles may use it. References MUST resolve built-in
names alongside project definitions. So that every book stands alone, the book
MUST render a reference to a built-in as a badge without a link whose hover text
gives the built-in's full text. Built-ins themselves MUST NOT require or permit
definition evidence files and MUST NOT appear as definitions in the requirements
index, `habeas status`, or the missing-evidence check of
{cite}`requirements.ci.coverage`. Per-source citation reviews under
{cite}`requirements.references.citation_review` MAY be required for references
to a built-in. A project definition
MUST NOT use a full name beginning with `habeas:`; validation MUST report one,
and the `:` character already makes such names invalid under
{cite}`requirements.ci.identifiers`. Validation MUST report a reference to a
built-in in a role the built-in does not permit, or that breaks the built-in's
stated form.
:::
Input 3: requirements selection requirements.references.roles
requirements.references.roles:md/requirements/references.md:3–49
:::{req} roles
Project text files MAY use the `{impl}`, `{cite}`, and `{test}` roles with a backtick-delimited full requirement or example name, or with a built-in name under {cite}`requirements.references.builtin_definitions`, and MAY use the `{fixme}` role in fenced form. A reference MAY instead be written in fenced form, `:::{role} name` on one line, a body, and a closing fence, following the fence rules of {cite}`requirements.ci.span` and {cite}`requirements.ci.fence_lengths`; the fenced form is the same edge with attached commentary, and the inline form carries none. In a source comment, fence lines MUST be recognized after removing each line's comment delimiters within one comment run under {cite}`requirements.references.outline_comments`, and a fence that does not close within its comment run MUST be a validation error. Each reference is a directed edge between its source and the named definition. A source is a project source item or a requirement or example declaration. The roles MUST mean:
- `{cite}`: the source relies on, supports, or refers to the definition. It is an
edge from the source to the definition.
- `{impl}`: the source implements part of the definition: it makes a decision,
performs a check, produces an output, or handles a case that the definition
specifies. A requirement MAY implement part of another requirement by refining
one of its obligations. Calling code that implements a definition, or
producing a result a caller uses to meet it, MUST NOT by itself count as
implementing it. A check MUST count only if the definition states it, or the
source could not meet one of the definition's obligations without it; source
that checks it is consistent with a definition, such as recognizing a form the
definition specifies in order to decide whether to run other behavior, relies
on that definition and calls for `{cite}`. A requirement stating a convention
for every output of a kind, such as every validation error, is implemented by
the source that carries out the convention as a whole, such as the step that
collects and reports those outputs.
- `{test}`: the source is designed to verify behavior the definition specifies:
a test through its scenario and the assertions about that scenario's outcome,
or a named example through the concrete case it describes.
- `{fixme}`: the source acknowledges a known gap in fulfilling the definition. It
MUST use the fenced form, and its body MUST describe the gap. The body MAY
begin with option lines naming issues that track the gap, one per line, in the
form `:github: <owner>/<repo>#<number>`, such as
`:github: rust-lang/rust#123`. `github` MUST be the only recognized option.
A named `{fixme}` MAY appear only in sources outside the book. Validation MUST report
any other option line, a `:github:` value not in that form, an inline
`{fixme}`, a `{fixme}` in a requirement or example declaration, and a
`{fixme}` whose body, without option lines and comment delimiters, is empty.
An unnamed `{fixme}`, a fence of `:::{fixme}` with no name, MAY appear in any
project text, including a requirement or example body, to tie that place to
the issues it names. It MUST have at least one `:github:` option line and MAY
have a description; it is not a reference edge, acknowledges no gap, needs no
coverage, and does not count as a reference for Rust item coverage. Its
issues are checked under {cite}`requirements.cli.fixme_issues`.
`{impl}`, `{test}`, and `{fixme}` are edges from the definition to the source.
Only requirements and examples are assessed; code is reviewed as part of the
definitions it implements or tests.
```text
{impl}`requirements.references.roles`
{cite}`requirements.references.roles`
{test}`requirements.references.roles`
```
:::
Other sources
Input 1: requirements selection requirements.test-coverage.check.exceptions.anchor
requirements.test-coverage.check.exceptions.anchor:md/requirements/test-coverage.md:653–679
:::{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 7: outline md/reference.md section[How%20it%20works]/section[References]/section[Built-in%20definitions]
- File:
md/reference.md - Selector:
section[How%20it%20works]/section[References]/section[Built-in%20definitions] - Kind:
section md/reference.md:652–717
### Built-in definitions
Built-in definitions are named `habeas:<name>` and are available in every project without a declaration. Each has fixed text and permits only certain roles. Built-ins have no evidence files and do not appear in the requirements index or `habeas status`. Project definitions cannot use names beginning with `habeas:`. In the book, a reference to a built-in renders as a badge without a link; hovering over it shows the built-in's text.
The built-in `habeas:util` has this text:
> Cite this on an item that serves other code, including code outside the
> project such as a library calling a trait implementation it requires, and
> carries out no requirement or example itself: it has no obligations and no
> end-user-observable behavior of its own. A review that reaches it from a root judges what it does
> as part of that root.
Only `{cite}` may reference it, inline or fenced, with or without commentary:
```rust
// {cite}`habeas:util`
fn split_lines(text: &str) -> Vec<&str> {
text.lines().collect()
}
```
A `habeas:util` citation counts as a reference for Rust item coverage. An item whose only citations are of `habeas:util` needs no citation review; the reviews of the roots that reach it judge what it does.
{cite}`requirements.references.builtin_definitions` {cite}`requirements.references.util`
The built-in `habeas:coverage` has 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.
Use an ordinary citation with a prose explanation. For a file threshold, attach
it to the root with Rust inner doc comments (`//!`); for a function, attach it to
that function. For example:
```rust
// :::{cite} habeas:coverage
// This defensive abort handles an invariant violation that public APIs
// cannot construct; the reviewed callers establish that invariant.
// :::
fn invariant_failure() { std::process::abort(); }
```
An inline citation can instead put its explanation in a Rust doc comment.
Only a current accepted independent citation review permits an exception.
A file exception does not excuse individual functions; a function exception
does not excuse its file's threshold or nested functions. A citation may remain
when coverage improves, and applies across build configurations without parsing
conditions in the explanation. The explanation and evidence belong in Git;
runtime profiles and reports do not. Exceptions never inflate coverage figures.
{impl}`requirements.test-coverage.check.exceptions.setup`
{cite}`requirements.test-coverage.check.exceptions.anchor`