requirements.cli.shared_status_rendering
Requirements index · View definition
Requirement
habeas statusand the mdBook requirements index MUST generate their Definition/Evidence Markdown tables through the same renderer. That renderer MUST calculate column widths, align the columns, and display the same evidence-state labels in both outputs. Callers MAY select different definitions and supply different kind-labeled name cells so mdBook can link to detail pages.
Rationale
The tests adequately cover requirements.cli.shared_status_rendering.
Obligations derived from the text
habeas statusand the mdBook index generate their tables through the same renderer. This is structural, so tests can only observe it as identical output properties in both outputs.- The renderer calculates column widths.
- The renderer aligns the columns.
- Both outputs display the same evidence-state labels.
- Callers MAY select different definitions and supply different name cells. This is a MAY, so it imposes nothing to check.
Coverage
- Status output (
tests/commands.rs#fn[status_tables_align_each_column_to_its_widest_cell]):- It runs both
statusandstatus --all. - It checks that the pipe positions are identical on every table line, so the columns align.
- It checks that each column’s width equals its widest trimmed cell, so widths are computed.
- It checks that cells have exactly one space of padding and that the separator row is
---. - It checks the labels per requirement:
Valid,Missing,Determination falseandInvalid.
- It runs both
- mdBook index output (
src/index.rs#mod[tests]/fn[index_shows_evidence_states_and_links_generated_chapters]):- It applies the same pipe-position and widest-cell checks to the index table.
- The name cells there are linked cells, such as
[`requirements.core.x`](...). The checks therefore cover the case where callers supply different name cells. - It checks the labels
Valid,Determination false,Invalid(for both the changed and uncovered requirements) andMissing. This is the same label set as the status test.
- Shared renderer: the two tests assert the same width, alignment and label properties on both outputs. A divergent second renderer would likely break at least one of them. Code-level identity cannot be tested more directly than this.
Gaps I found no gaps. The linked-name-cell and different-definition-selection behavior is a MAY, so it needs no test of its own.
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 tests/commands.rs fn[status_tables_align_each_column_to_its_widest_cell]
- File:
tests/commands.rs - Selector:
fn[status_tables_align_each_column_to_its_widest_cell] - Kind:
fn tests/commands.rs:651–712
// {test}`requirements.cli.status_table_alignment`
// {test}`requirements.cli.shared_status_rendering`
#[test]
fn status_tables_align_each_column_to_its_widest_cell() {
let temp = fixture();
for args in [["status"].as_slice(), ["status", "--all"].as_slice()] {
let output = habeas(temp.path(), args);
assert!(output.status.success(), "{args:?}: {output:?}");
let text = String::from_utf8(output.stdout).unwrap();
let table = text
.lines()
.skip_while(|line| !line.starts_with("| "))
.take_while(|line| line.starts_with("| "))
.collect::<Vec<_>>();
assert!(table.len() > 2, "{text}");
let pipes = table[0]
.match_indices('|')
.map(|(index, _)| index)
.collect::<Vec<_>>();
assert_eq!(pipes.len(), 3, "{text}");
for line in &table {
let actual = line
.match_indices('|')
.map(|(index, _)| index)
.collect::<Vec<_>>();
assert_eq!(actual, pipes, "{text}");
for cell in line.split('|').skip(1).take(2) {
assert!(cell.starts_with(' ') && cell.ends_with(' '), "{text}");
assert!(!cell[1..].starts_with(' '), "{text}");
}
}
for column in 0..2 {
let content_width = table
.iter()
.map(|line| line.split('|').nth(column + 1).unwrap().trim().len())
.max()
.unwrap();
assert_eq!(
pipes[column + 1] - pipes[column] - 3,
content_width,
"{text}"
);
}
assert_eq!(table[1].split('|').nth(1).unwrap().trim(), "---");
assert_eq!(table[1].split('|').nth(2).unwrap().trim(), "---");
}
// The labels are the evidence-state labels the mdBook index also shows.
let output = habeas(temp.path(), &["status", "--all"]);
let text = String::from_utf8(output.stdout).unwrap();
for (name, state) in [
("ready", "Valid"),
("absent", "Missing"),
("pending", "Determination false"),
("malformed", "Invalid"),
] {
let row = text
.lines()
.find(|line| line.starts_with(&format!("| `requirements.{name}` ")))
.unwrap_or_else(|| panic!("missing {name} in:\n{text}"));
assert_eq!(row.split('|').nth(2).unwrap().trim(), state, "{text}");
}
}
Other sources
Input 1: requirements selection requirements.cli.shared_status_rendering
requirements.cli.shared_status_rendering:md/requirements/cli.md:56–58
:::{req} shared_status_rendering
`habeas status` and the mdBook requirements index MUST generate their Definition/Evidence Markdown tables through the same renderer. That renderer MUST calculate column widths, align the columns, and display the same evidence-state labels in both outputs. Callers MAY select different definitions and supply different kind-labeled name cells so mdBook can link to detail pages.
:::