requirements.ci.identifiers
Requirements index · View definition
Requirement
Requirement and reference names MUST have nonempty dot-separated segments containing only ASCII letters, digits, underscores, or hyphens. A
{req}directive whose full name is invalid, including one whose chapter path gives an invalid namespace, and a role with an invalid name MUST remain literal and MUST NOT define or reference a requirement. For nested chapter paths, a leadingreqs/and a finalindexorREADMEsegment MUST be omitted from the requirement namespace.
Rationale
The reviewed tests cover every obligation in requirements.ci.identifiers, and their assertions enforce the expected outcomes. I did not request implementation source.
Valid and invalid name grammar (nonempty dot-separated segments of ASCII letters, digits, _ or -):
src/lib.rs#mod[tests]/fn[invalid_names_remain_literal]callsvalid_nameon invalid names: the empty string,a..b,.a,a., a name with a space, non-ASCIIcafé,a/b,a&banda`b. It also calls it on valid names,a,a_b.c-d,A1.b2andx.-_.y, which cover digits, uppercase, underscore and hyphen, including hyphen and underscore as whole segments.
An invalid {req} directive stays literal and defines nothing:
invalid_names_remain_literalrenders:::{req} bad namewithreplace_definitions. The text stays literal, while the validgooddirective next to it is rendered asrules.good.- The same test checks that
definition_blocksreturns nothing for invalidreq,exampleanddefinitionopeners. examples_are_distinct_definitions_and_tests_link_to_themchecks that:::{example} bad namestays literal and is not a definition block.
An invalid namespace from the chapter path gives an invalid full name, so the directive stays literal and defines nothing:
invalid_names_remain_literaluses namespacea&band asserts the rendered output equals the source.chapters_with_invalid_namespaces_define_nothing_in_the_bookrunspreprocess_bookon chapterbad dir/rules.md. It asserts the content is unchanged, with no badge, and that a{impl}reference to the would-be name stays literal.src/evidence.rs#mod[tests]/fn[invalid_full_names_from_chapter_paths_are_reported_and_not_defined]checks end to end that an invalid full name is reported and not defined, so no evidence is expected for it.
A role with an invalid name stays literal and does not reference:
invalid_names_remain_literalloops over the rolesimpl,cite,testandterm. It uses invalid names (bad name,a..b, empty,a.) and assertsreference_rolesis empty in both modes (falseandtrue). It also asserts that a valid name yields exactly one reference.src/fenced.rs#mod[tests]/fn[opening_fences_take_a_role_and_one_valid_or_built_in_name]checks that fenced role openings with invalid names (a b,a..b,.a,a.,a/b,café.b) returnNone, while valid names are recognised.
Namespace derivation for nested paths:
src/lib.rs#mod[tests]/fn[chapter_path_prefixes_the_requirement_name]checkschapter_namespace:reqs/foo/bar.mdgivesfoo.bar.reqs/foo/README.mdandreqs/foo/index.mdgivefoo.foo/index.mdgivesfoo.reqs/index.mdgives the empty namespace, andreqs/bar.mdgivesbar.- Non-nested
index.mdandreqs.mdkeep their segment, and a non-leadingother/reqs/a.mdkeepsreqs.
src/evidence.rs#fn[validates_full_names_requirement_text_and_input_lines]showsmd/reqs/foo/bar.mdmapping tofoo.bar.ready. The evidence test forreqs/index.mdshowstopwith an empty namespace.
I found no requirement-violating behavior that these tests would accept.
Inputs
Tests
Input 2: outline src/evidence.rs mod[tests]/fn[validates_full_names_requirement_text_and_input_lines]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[validates_full_names_requirement_text_and_input_lines] - Kind:
fn src/evidence.rs:2533–2564
// {test}`requirements.integration.report_api`
// {test}`requirements.ci.book_source`
// {test}`requirements.ci.coverage`
// {test}`requirements.ci.requirement_text`
// {test}`requirements.ci.outline_inputs`
// {test}`requirements.ci.identifiers`
// {test}`requirements.ci.span`
#[test]
fn validates_full_names_requirement_text_and_input_lines() {
let temp = fixture();
fs::write(
temp.path().join("md/reqs/foo/bar.md"),
"# Requirements\n\n:::{req} ready\n\n The check MUST pass.\n\n```text\n{req}`example`\n```\n:::\n",
)
.unwrap();
fs::write(
temp.path().join("evidence/foo.bar.ready.json"),
json!({
"requirement": "The check MUST pass.\n\n```text\n{req}`example`\n```",
"determination": true,
"rationale": "The inspected file has the expected lines.",
"inputs": [outline(temp.path(), "src/main.rs", "")]
})
.to_string(),
)
.unwrap();
let report = validate_repository(temp.path()).unwrap();
assert_eq!(report.requirements, 1);
assert_eq!(report.evidence_files, 1);
assert!(report.errors.is_empty(), "{:?}", report.errors);
}
Input 3: outline src/evidence.rs mod[tests]/fn[invalid_full_names_from_chapter_paths_are_reported_and_not_defined]
- File:
src/evidence.rs - Selector:
mod[tests]/fn[invalid_full_names_from_chapter_paths_are_reported_and_not_defined] - Kind:
fn src/evidence.rs:3299–3329
// {test}`requirements.ci.identifiers`
#[test]
fn invalid_full_names_from_chapter_paths_are_reported_and_not_defined() {
let temp = fixture();
fs::create_dir_all(temp.path().join("md/bad dir")).unwrap();
fs::write(
temp.path().join("md/bad dir/rules.md"),
"# Rules\n\n:::{req} good\nGood.\n:::\n",
)
.unwrap();
fs::write(
temp.path().join("md/reqs/index.md"),
"# Top\n\n:::{req} top\nTop.\n:::\n",
)
.unwrap();
let report = validate_repository(temp.path()).unwrap();
let errors = report.errors.join("\n");
assert!(
errors
.contains("md/bad dir/rules.md:3: invalid requirement name \"bad dir.rules.good\""),
"{errors}"
);
// The invalid name is not defined, so no evidence is expected for it,
// while `reqs/index.md` contributes an empty namespace.
assert!(!errors.contains("evidence/bad dir"), "{errors}");
assert!(
errors.contains("evidence/top.json: missing for requirement at md/reqs/index.md:3"),
"{errors}"
);
assert_eq!(report.errors.len(), 2, "{errors}");
}
Input 4: outline src/fenced.rs mod[tests]/fn[opening_fences_take_a_role_and_one_valid_or_built_in_name]
- File:
src/fenced.rs - Selector:
mod[tests]/fn[opening_fences_take_a_role_and_one_valid_or_built_in_name] - Kind:
fn src/fenced.rs:291–330
// {test}`requirements.references.roles`
// {test}`requirements.ci.identifiers`
// {test}`requirements.references.builtin_definitions`
#[test]
fn opening_fences_take_a_role_and_one_valid_or_built_in_name() {
let role = |name: &str| format!(":::{{{name}}}");
assert_eq!(
opening_fence(&format!("{} requirements.ready", role("impl"))),
Some((ReferenceKind::Impl, "requirements.ready", 3))
);
assert_eq!(
opening_fence("::::{cite} habeas:util"),
Some((ReferenceKind::Cite, "habeas:util", 4))
);
// A syntactically built-in name is recognized so validation can report
// an unknown built-in rather than leaving it literal.
assert_eq!(
opening_fence(&format!("{} habeas:unknown", role("impl"))),
Some((ReferenceKind::Impl, "habeas:unknown", 3))
);
assert_eq!(
opening_fence(&format!(" {} a.b", role("test"))),
Some((ReferenceKind::Test, "a.b", 3))
);
for literal in [
format!(" {} a.b", role("test")),
format!("{}a.b", role("cite")),
format!("{} a b", role("cite")),
format!("{} a..b", role("cite")),
format!("{} .a", role("cite")),
format!("{} a.", role("cite")),
format!("{} a/b", role("impl")),
format!("{} caf\u{e9}.b", role("impl")),
format!("{} other:none", role("cite")),
format!("{} a.b", role("term")),
"::{cite} a.b".to_owned(),
] {
assert_eq!(opening_fence(&literal), None, "{literal}");
}
}
Input 5: outline src/lib.rs mod[tests]/fn[chapter_path_prefixes_the_requirement_name]
- File:
src/lib.rs - Selector:
mod[tests]/fn[chapter_path_prefixes_the_requirement_name] - Kind:
fn src/lib.rs:1429–1459
// {test}`requirements.ci.identifiers`
#[test]
fn chapter_path_prefixes_the_requirement_name() {
assert_eq!(
chapter_namespace(Path::new("requirements.md")),
"requirements"
);
assert_eq!(chapter_namespace(Path::new("reqs/foo/bar.md")), "foo.bar");
assert_eq!(chapter_namespace(Path::new("reqs/foo/README.md")), "foo");
assert_eq!(chapter_namespace(Path::new("reqs/foo/index.md")), "foo");
assert_eq!(chapter_namespace(Path::new("foo/index.md")), "foo");
assert_eq!(chapter_namespace(Path::new("reqs/index.md")), "");
assert_eq!(chapter_namespace(Path::new("reqs/bar.md")), "bar");
// Only nested paths drop these segments.
assert_eq!(chapter_namespace(Path::new("index.md")), "index");
assert_eq!(chapter_namespace(Path::new("reqs.md")), "reqs");
assert_eq!(
chapter_namespace(Path::new("other/reqs/a.md")),
"other.reqs.a"
);
let rendered = replace_definitions(
":::{req} tui.table\nThe table MUST be visible.\n:::",
"requirements",
None,
None,
);
assert!(rendered.contains("habeas-req-badge"));
assert!(rendered.contains("alt=\"req requirements.tui.table\""));
assert!(!rendered.contains("{req}"));
}
Input 6: outline src/lib.rs mod[tests]/fn[invalid_names_remain_literal]
- File:
src/lib.rs - Selector:
mod[tests]/fn[invalid_names_remain_literal] - Kind:
fn src/lib.rs:1493–1536
// {test}`requirements.ci.identifiers`
#[test]
fn invalid_names_remain_literal() {
let source = ":::{req} bad name\nInvalid.\n:::\n\n:::{req} good\nGood.\n:::";
let rendered = replace_definitions(source, "rules", None, None);
assert!(rendered.contains(":::{req} bad name"));
assert!(rendered.contains("alt=\"req rules.good\""));
// A valid local name in a chapter whose namespace is invalid gives an
// invalid full name, so the directive stays literal too.
let rendered = replace_definitions(source, "a&b", None, None);
assert_eq!(rendered, source);
for name in [
"",
"a..b",
".a",
"a.",
"a b",
"caf\u{e9}",
"a/b",
"a&b",
"a`b",
] {
assert!(!super::valid_name(name), "{name:?} is invalid");
}
for name in ["a", "a_b.c-d", "A1.b2", "x.-_.y"] {
assert!(super::valid_name(name), "{name:?} is valid");
}
for role in ["impl", "cite", "test", "term"] {
for name in ["bad name", "a..b", "", "a."] {
let text = format!("{{{role}}}`{name}`");
assert!(reference_roles(&text, false).is_empty(), "{text}");
assert!(reference_roles(&text, true).is_empty(), "{text}");
}
assert_eq!(
reference_roles(&format!("{{{role}}}`a_b.c-d`"), false).len(),
1
);
}
for opener in [":::{req} a..b", ":::{example} .x", ":::{definition} a b"] {
let source = format!("{opener}\n:phrase: p\n\nBody.\n:::\n");
assert!(definition_blocks(&source).is_empty(), "{opener}");
}
}
Input 7: outline src/lib.rs mod[tests]/fn[chapters_with_invalid_namespaces_define_nothing_in_the_book]
- File:
src/lib.rs - Selector:
mod[tests]/fn[chapters_with_invalid_namespaces_define_nothing_in_the_book] - Kind:
fn src/lib.rs:1538–1565
// {test}`requirements.ci.identifiers`
#[test]
fn chapters_with_invalid_namespaces_define_nothing_in_the_book() {
let mut book = Book::new();
book.push_item(Chapter::new(
"Bad",
":::{req} good\nGood.\n:::".to_owned(),
"bad dir/rules.md",
Vec::new(),
));
book.push_item(Chapter::new(
"Guide",
"See {impl}`bad dir.rules.good`.".to_owned(),
"guide.md",
Vec::new(),
));
let root = book_root();
preprocess_book(&mut book, root.path()).unwrap();
let chapters = book.chapters().collect::<Vec<_>>();
assert_eq!(
chapters.len(),
4,
"an empty index and its coverage child are generated"
);
assert_eq!(chapters[0].content, ":::{req} good\nGood.\n:::");
assert!(!chapters[0].content.contains("habeas-req-badge"));
assert_eq!(chapters[1].content, "See {impl}`bad dir.rules.good`.");
}
Input 8: outline src/lib.rs mod[tests]/fn[examples_are_distinct_definitions_and_tests_link_to_them]
- File:
src/lib.rs - Selector:
mod[tests]/fn[examples_are_distinct_definitions_and_tests_link_to_them] - Kind:
fn src/lib.rs:1941–1995
// {test}`requirements.examples.definition`
// {test}`requirements.references.book_badges`
// {test}`requirements.ci.identifiers`
// {test}`requirements.examples.index`
#[test]
fn examples_are_distinct_definitions_and_tests_link_to_them() {
let source = "::::{req} ready\nReady.\n\n:::{example} something.foo\nGiven ready, it succeeds. {cite}`requirements.ready`\n:::\n::::\n\n:::{example} bad name\nInvalid.\n:::\n\n```text\n:::{example} hidden\nLiteral.\n:::\n```".to_owned();
let blocks = definition_blocks(&source);
assert_eq!(blocks.len(), 2);
assert_eq!(blocks[0].kind, DefinitionKind::Requirement);
assert_eq!(blocks[1].kind, DefinitionKind::Example);
let mut book = Book::new();
book.push_item(Chapter::new(
"Requirements",
source,
"requirements.md",
Vec::new(),
));
book.push_item(Chapter::new(
"Guide",
"{test}`requirements.something.foo`".to_owned(),
"guides/deep.md",
Vec::new(),
));
let root = book_root();
preprocess_book(&mut book, root.path()).unwrap();
// Generated detail pages are titled by full name.
let chapters = book
.chapters()
.filter(|chapter| !chapter.name.contains('.'))
.collect::<Vec<_>>();
assert!(
chapters[0]
.content
.contains("id=\"habeas-req-requirements.ready\"")
);
assert!(
chapters[0]
.content
.contains("id=\"habeas-example-requirements.something.foo\"")
);
assert!(
chapters[0]
.content
.contains("alt=\"example requirements.something.foo\"")
);
assert!(chapters[0].content.contains(":::{example} bad name"));
assert!(chapters[0].content.contains(":::{example} hidden"));
assert!(
chapters[1].content.contains(
"href=\"../requirements.html#habeas-example-requirements.something.foo\""
)
);
}
Other sources
Input 1: requirements selection requirements.ci.identifiers
requirements.ci.identifiers:md/requirements/ci.md:329–331
:::{req} identifiers
Requirement and reference names MUST have nonempty dot-separated segments containing only ASCII letters, digits, underscores, or hyphens. A `{req}` directive whose full name is invalid, including one whose chapter path gives an invalid namespace, and a role with an invalid name MUST remain literal and MUST NOT define or reference a requirement. For nested chapter paths, a leading `reqs/` and a final `index` or `README` segment MUST be omitted from the requirement namespace.
:::