fix(anatomy): R5.4 aligned report tables bounded before they are built, declared case fully held, docs
This commit is contained in:
1 parent
aeb5050502
commit
777c8000b8
8 files changed
+215
-21
No files matched your search
@@ -1,8 +1,8 @@
|
||||
//! The draft side of the pipeline (R5.3): the authored changeset applied on the legacy
|
||||
//! baseline, the report migration map, the document statistics and the seed SQL
|
||||
//! (`packages/anatomy/src/curation`, without the review drawings and the Markdown reports of
|
||||
//! R5.4). Parity with the TypeScript is proven by `tests/curation_draft.rs` against the
|
||||
//! committed `draft/` folder, `oracles/r5/pipeline.json` and `oracles/r5/curation-synthetic.json`.
|
||||
//! The draft side of the pipeline (`packages/anatomy/src/curation`): the authored changeset
|
||||
//! applied on the legacy baseline, the report migration map, the document statistics and the
|
||||
//! seed SQL (R5.3), the CHANGELOG, the review report and the review drawings (R5.4). Parity with
|
||||
//! the TypeScript is proven by `tests/curation_draft.rs` and `tests/curation_review.rs` against
|
||||
//! the committed `draft/` folder and the `oracles/r5` files.
|
||||
|
||||
pub mod app_review;
|
||||
pub mod apply;
|
||||
|
||||
@@ -130,6 +130,12 @@ pub(crate) fn split_row(line: &str) -> Vec<String> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The largest aligned table written, in display columns (rows × padded row width): every row
|
||||
/// is padded to the widest cell of each column, so one long authored cell multiplies by the row
|
||||
/// count (an 80 KB rationale over 14,000 records asked for 1 GB). The equine CHANGELOG's widest
|
||||
/// table holds about 0.5 MB.
|
||||
pub const MAX_TABLE_COLUMNS_TOTAL: usize = 32 * 1024 * 1024;
|
||||
|
||||
fn align(lines: &[&str]) -> Result<Vec<String>, PipelineError> {
|
||||
let rows: Vec<Vec<String>> = lines.iter().map(|line| split_row(line)).collect();
|
||||
let columns = rows.first().map_or(0, Vec::len);
|
||||
@@ -144,6 +150,13 @@ fn align(lines: &[&str]) -> Result<Vec<String>, PipelineError> {
|
||||
widths[column] = widths[column].max(display_width(text)?);
|
||||
}
|
||||
}
|
||||
let row_width = widths.iter().sum::<usize>() + 3 * columns + 1;
|
||||
if row_width.saturating_mul(rows.len()) > MAX_TABLE_COLUMNS_TOTAL {
|
||||
return Err(PipelineError::Guard(format!(
|
||||
"an aligned table of {} rows × {row_width} columns exceeds the {MAX_TABLE_COLUMNS_TOTAL} bound",
|
||||
rows.len()
|
||||
)));
|
||||
}
|
||||
let mut out = Vec::with_capacity(rows.len());
|
||||
for (index, row) in rows.iter().enumerate() {
|
||||
out.push(if index == 1 {
|
||||
|
||||
@@ -77,6 +77,20 @@ fn tables_align_as_prettier_aligns_them() {
|
||||
assert_eq!(refused, vec![5], "only the emoji table is refused");
|
||||
}
|
||||
|
||||
/// One long cell pads every row of its column: the aligned table is bounded before any row is
|
||||
/// built (security gate R5.4 round 6: an 80 KB rationale over 14,000 records asked for 1 GB).
|
||||
#[test]
|
||||
fn an_aligned_table_past_the_bound_is_refused_before_it_is_built() {
|
||||
let mut raw = vec!["| a | b |".to_owned(), "| --- | --- |".to_owned()];
|
||||
raw.push(format!("| {} | x |", "w".repeat(2_000)));
|
||||
raw.extend((0..20_000).map(|_| "| a | b |".to_owned()));
|
||||
let error = format_markdown(&raw.join("\n")).unwrap_err();
|
||||
assert!(
|
||||
matches!(&error, PipelineError::Guard(message) if message.contains("exceeds the")),
|
||||
"{error}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slugs_and_uuids_match_the_typescript() {
|
||||
let semantics = oracle("js-semantics.json");
|
||||
|
||||
@@ -361,18 +361,21 @@ fn the_synthetic_review_cases_match_the_typescript_or_are_refused_as_declared()
|
||||
),
|
||||
"{name}"
|
||||
);
|
||||
continue;
|
||||
} else {
|
||||
assert_eq!(
|
||||
rendered.changelog.unwrap(),
|
||||
case["changelog"].as_str().unwrap(),
|
||||
"{name}"
|
||||
);
|
||||
}
|
||||
// The review report and the drawings of a declared case are held too: the same text
|
||||
// or a declared refusal, never another text.
|
||||
match rendered.review {
|
||||
Ok(review) => assert_eq!(review, case["review"].as_str().unwrap(), "{name}"),
|
||||
Err(PipelineError::UnsupportedWidth(_) | PipelineError::UnsupportedMarkdown(_))
|
||||
if DECLARED_REFUSALS.contains(&name) => {}
|
||||
Err(other) => panic!("{name}: {other}"),
|
||||
}
|
||||
assert_eq!(
|
||||
rendered.changelog.unwrap(),
|
||||
case["changelog"].as_str().unwrap(),
|
||||
"{name}"
|
||||
);
|
||||
assert_eq!(
|
||||
rendered.review.unwrap(),
|
||||
case["review"].as_str().unwrap(),
|
||||
"{name}"
|
||||
);
|
||||
let views = typed(&case_document(&frozen, case)).views.len();
|
||||
assert_eq!(rendered.drawings.len(), 2 * views, "{name}");
|
||||
let rule = TriggerNames::of(&typed(&case_document(&frozen, case)));
|
||||
|
||||
Reference in new issue
Block a user