fix(anatomy): R5.4 report guard as an allowlist (report_guard.rs), sweep of 762 probes incl. seeded random strings, NUL refused in field segments
This commit is contained in:
1 parent
077d91bdff
commit
124d954a0d
10 files changed
+246
-195
No files matched your search
@@ -98,18 +98,18 @@ pub fn split_field(field: &str) -> Result<Vec<&str>, PipelineError> {
|
|||||||
"field \"{field}\" has more than {MAX_FIELD_SEGMENTS} segments"
|
"field \"{field}\" has more than {MAX_FIELD_SEGMENTS} segments"
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
if let Some(key) = path.iter().find(|key| key.starts_with('\0')) {
|
||||||
|
return Err(fail(format!("reserved key {key:?} in field \"{field}\"")));
|
||||||
|
}
|
||||||
// A control character or a backtick would reach the reports' code spans through the record.
|
// A control character or a backtick would reach the reports' code spans through the record.
|
||||||
if path
|
if path
|
||||||
.iter()
|
.iter()
|
||||||
.any(|key| key.chars().any(|c| c.is_control() && c != '\0') || key.contains('`'))
|
.any(|key| key.chars().any(|c| c.is_control()) || key.contains('`'))
|
||||||
{
|
{
|
||||||
return Err(fail(format!(
|
return Err(fail(format!(
|
||||||
"field {field:?} holds a control character or a backtick"
|
"field {field:?} holds a control character or a backtick"
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
if let Some(key) = path.iter().find(|key| key.starts_with('\0')) {
|
|
||||||
return Err(fail(format!("reserved key {key:?} in field \"{field}\"")));
|
|
||||||
}
|
|
||||||
// A JavaScript assignment through `__proto__` never wrote a key: it set a prototype,
|
// A JavaScript assignment through `__proto__` never wrote a key: it set a prototype,
|
||||||
// polluted `Object.prototype` or did nothing. No faithful reading exists, so it is refused.
|
// polluted `Object.prototype` or did nothing. No faithful reading exists, so it is refused.
|
||||||
if path.contains(&"__proto__") {
|
if path.contains(&"__proto__") {
|
||||||
|
|||||||
@@ -242,12 +242,6 @@ fn add_destination(doc: &mut Value, op: &AddOp) -> Result<Destination, PipelineE
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A `children` or `categories` of an added value must be a list (a later add would otherwise
|
|
||||||
/// replace the author's value by `[]`, as the TypeScript's `childrenOf` did), and each entry an
|
|
||||||
/// object. The
|
|
||||||
/// TypeScript met a null or a primitive there inconsistently (a TypeError when it walked it,
|
|
||||||
/// silently skipped when a rename walked past it, refused by the gate when it stayed); the
|
|
||||||
/// port refuses it at the add (RUST.md §11.12). Walked with an explicit stack.
|
|
||||||
/// An id an op writes must already be what the final document requires (a stable id; a region
|
/// An id an op writes must already be what the final document requires (a stable id; a region
|
||||||
/// code for a region): an id that passed only because a later op removed or renamed its item
|
/// code for a region): an id that passed only because a later op removed or renamed its item
|
||||||
/// would still reach the records, and from them the reports' code spans (a line break there
|
/// would still reach the records, and from them the reports' code spans (a line break there
|
||||||
@@ -277,6 +271,11 @@ fn js_string_value(value: &Value) -> String {
|
|||||||
super::records::js_string(Some(value))
|
super::records::js_string(Some(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A `children` or `categories` of an added value must be a list (a later add would otherwise
|
||||||
|
/// replace the author's value by `[]`, as the TypeScript's `childrenOf` did), each entry an
|
||||||
|
/// object with a stable id. The TypeScript met a null or a primitive there inconsistently (a
|
||||||
|
/// TypeError when it walked it, silently skipped when a rename walked past it, refused by the
|
||||||
|
/// gate when it stayed); the port refuses it at the add (RUST.md §11.12). Explicit stack.
|
||||||
fn assert_object_children(value: &Value) -> Result<(), PipelineError> {
|
fn assert_object_children(value: &Value) -> Result<(), PipelineError> {
|
||||||
let mut pending = vec![value];
|
let mut pending = vec![value];
|
||||||
while let Some(item) = pending.pop() {
|
while let Some(item) = pending.pop() {
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ use crate::curation::PipelineError;
|
|||||||
use crate::curation::ids::{asset_id_from_sha256, sha256_hex};
|
use crate::curation::ids::{asset_id_from_sha256, sha256_hex};
|
||||||
use crate::curation::legacy::types::{Anomaly, AssetRecord, ImportResult};
|
use crate::curation::legacy::types::{Anomaly, AssetRecord, ImportResult};
|
||||||
use crate::curation::legacy::{HEAD_VIEW_ID, MAIN_VIEW_ID};
|
use crate::curation::legacy::{HEAD_VIEW_ID, MAIN_VIEW_ID};
|
||||||
use crate::curation::markdown::format_markdown;
|
|
||||||
use crate::curation::prettier_json::format_json;
|
use crate::curation::prettier_json::format_json;
|
||||||
|
use crate::curation::report_guard::format_report;
|
||||||
use crate::domain::sheet::{AnatomicalSheetDocument, Reference, SheetIssue, ViewBox};
|
use crate::domain::sheet::{AnatomicalSheetDocument, Reference, SheetIssue, ViewBox};
|
||||||
|
|
||||||
pub const DRAFT_SEED_SQL_FILE: &str = "equine_draft.sql";
|
pub const DRAFT_SEED_SQL_FILE: &str = "equine_draft.sql";
|
||||||
@@ -270,8 +270,8 @@ pub fn render_draft_artifacts(
|
|||||||
(MIGRATION_MAP_FILE.to_owned(), format_json(&map)?),
|
(MIGRATION_MAP_FILE.to_owned(), format_json(&map)?),
|
||||||
];
|
];
|
||||||
files.extend(review_drawings(draft)?);
|
files.extend(review_drawings(draft)?);
|
||||||
files.push(("CHANGELOG.md".to_owned(), format_markdown(&changelog)?));
|
files.push(("CHANGELOG.md".to_owned(), format_report(&changelog)?));
|
||||||
files.push(("REVIEW-REPORT.md".to_owned(), format_markdown(&review)?));
|
files.push(("REVIEW-REPORT.md".to_owned(), format_report(&review)?));
|
||||||
files.push((DRAFT_SEED_SQL_FILE.to_owned(), seed));
|
files.push((DRAFT_SEED_SQL_FILE.to_owned(), seed));
|
||||||
Ok(files)
|
Ok(files)
|
||||||
}
|
}
|
||||||
@@ -67,158 +67,12 @@ pub fn code(value: Option<&str>) -> String {
|
|||||||
value.map_or_else(|| "-".to_owned(), |text| format!("`{text}`"))
|
value.map_or_else(|| "-".to_owned(), |text| format!("`{text}`"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The plain text of a raw line Prettier would rewrite, found in its parts outside code spans
|
|
||||||
/// (`oracles/r5/markdown-sweep.json`): `*` outside a `**strong**` span; an underscore not between two letters or digits; a
|
|
||||||
/// backslash before a space or at the end, or an authored one before the cell escape `\|`
|
|
||||||
/// (`\"` in a JSON value is kept as written); two spaces in a row, a tab, a carriage return;
|
|
||||||
/// the inline constructs of `rewritten_construct`.
|
|
||||||
/// The parts of plain text outside the `**strong**` spans Prettier keeps as written (the
|
|
||||||
/// opening and closing pairs bounded by a non-word character or the line's edge, the inside
|
|
||||||
/// non-empty, without `*` and without an outer space). `None` when a `*` is left outside
|
|
||||||
/// such a span.
|
|
||||||
fn outside_strong(plain: &str) -> Option<String> {
|
|
||||||
let mut out = String::new();
|
|
||||||
let mut rest = plain;
|
|
||||||
let edge = |c: Option<char>| c.is_none_or(|c| !c.is_alphanumeric());
|
|
||||||
while let Some(open) = rest.find("**") {
|
|
||||||
let inside = &rest[open + 2..];
|
|
||||||
let close = inside.find("**")?;
|
|
||||||
let content = &inside[..close];
|
|
||||||
let after = inside[close + 2..].chars().next();
|
|
||||||
let valid = !content.is_empty()
|
|
||||||
&& !content.contains('*')
|
|
||||||
&& !content.starts_with(' ')
|
|
||||||
&& !content.ends_with(' ')
|
|
||||||
&& edge(rest[..open].chars().next_back())
|
|
||||||
&& edge(after);
|
|
||||||
if !valid {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
out.push_str(&rest[..open]);
|
|
||||||
out.push_str(content);
|
|
||||||
rest = &inside[close + 2..];
|
|
||||||
}
|
|
||||||
out.push_str(rest);
|
|
||||||
(!out.contains('*')).then_some(out)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Inline constructs Prettier re-prints (the sweep's link, wiki-link, autolink and reference
|
|
||||||
/// probes): a link, image or reference (`](`, `][`), a wiki link with inner spaces, an autolink
|
|
||||||
/// (`<scheme:…>`, `<…@…>`), a character reference (`&name;`, `&#n;`). The last three are refused
|
|
||||||
/// whole although Prettier keeps some of them: a loud refusal, never met by the equine data.
|
|
||||||
fn rewritten_construct(plain: &str) -> bool {
|
|
||||||
// `[[ a ]]` loses its inner spaces; `[[a]]` and a polygon's `[[10,10],…]` stay as written.
|
|
||||||
let padded_wiki = plain.split("[[").skip(1).any(|after| {
|
|
||||||
let inside = after.split("]]").next().unwrap_or_default();
|
|
||||||
after.contains("]]")
|
|
||||||
&& (inside.starts_with(char::is_whitespace) || inside.ends_with(char::is_whitespace))
|
|
||||||
});
|
|
||||||
if plain.contains("](") || plain.contains("][") || padded_wiki {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
let autolink = plain.split('<').skip(1).any(|after| {
|
|
||||||
let inside = after.split('>').next().unwrap_or_default();
|
|
||||||
let closed = after.contains('>');
|
|
||||||
let scheme = inside.split(':').next().unwrap_or_default();
|
|
||||||
let is_scheme = inside.contains(':')
|
|
||||||
&& (2..=32).contains(&scheme.len())
|
|
||||||
&& scheme
|
|
||||||
.chars()
|
|
||||||
.next()
|
|
||||||
.is_some_and(|c| c.is_ascii_alphabetic())
|
|
||||||
&& scheme
|
|
||||||
.chars()
|
|
||||||
.all(|c| c.is_ascii_alphanumeric() || "+.-".contains(c));
|
|
||||||
closed && !inside.contains(' ') && (is_scheme || inside.contains('@'))
|
|
||||||
});
|
|
||||||
let reference = plain.split('&').skip(1).any(|after| {
|
|
||||||
let name = after.split(';').next().unwrap_or_default();
|
|
||||||
after.contains(';')
|
|
||||||
&& !name.is_empty()
|
|
||||||
&& name.len() <= 32
|
|
||||||
&& name
|
|
||||||
.trim_start_matches('#')
|
|
||||||
.chars()
|
|
||||||
.all(|c| c.is_ascii_alphanumeric())
|
|
||||||
});
|
|
||||||
autolink || reference
|
|
||||||
}
|
|
||||||
|
|
||||||
fn plain_rewrite(plain: &str) -> bool {
|
|
||||||
if rewritten_construct(plain) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
let Some(plain) = outside_strong(plain) else {
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
let chars: Vec<char> = plain.chars().collect();
|
|
||||||
// An underscore Prettier keeps sits between two ASCII letters or digits: the sweep shows it
|
|
||||||
// escapes one next to an accented letter, a CJK, kana or Hangul character.
|
|
||||||
let word = |i: Option<usize>| {
|
|
||||||
i.and_then(|i| chars.get(i))
|
|
||||||
.is_some_and(char::is_ascii_alphanumeric)
|
|
||||||
};
|
|
||||||
chars.iter().enumerate().any(|(i, &c)| match c {
|
|
||||||
'*' | '\t' | '\r' => true,
|
|
||||||
'_' => !(word(i.checked_sub(1)) && word(Some(i + 1))),
|
|
||||||
'\\' => match chars.get(i + 1) {
|
|
||||||
None | Some(' ') => true,
|
|
||||||
Some('|') => i.checked_sub(1).and_then(|p| chars.get(p)) == Some(&'\\'),
|
|
||||||
Some(_) => false,
|
|
||||||
},
|
|
||||||
' ' => chars.get(i + 1) == Some(&' '),
|
|
||||||
_ => false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Refuses a raw line holding Markdown the port does not reproduce, cell by cell in a table
|
|
||||||
/// row: an odd number of backticks, an empty code span or one with an outer space, or plain
|
|
||||||
/// text Prettier would rewrite (`plain_rewrite`). The report is then not written at all.
|
|
||||||
fn guard_line(line: &str) -> Result<(), PipelineError> {
|
|
||||||
if line.starts_with('|') {
|
|
||||||
// A table row: each cell as GFM reads it (the padding around the pipes is layout).
|
|
||||||
for cell in split_row(line) {
|
|
||||||
guard_text(&cell).map_err(|_| PipelineError::UnsupportedMarkdown(line.to_owned()))?;
|
|
||||||
}
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
guard_text(line)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn guard_text(line: &str) -> Result<(), PipelineError> {
|
|
||||||
let parts: Vec<&str> = line.split('`').collect();
|
|
||||||
let refuse = || Err(PipelineError::UnsupportedMarkdown(line.to_owned()));
|
|
||||||
// No carriage return or tab anywhere, code spans included (a CR there broke a table row;
|
|
||||||
// the other control characters align as Prettier aligns them, `oracles/r5/markdown-tables.json`).
|
|
||||||
if line.contains(['\r', '\t']) {
|
|
||||||
return refuse();
|
|
||||||
}
|
|
||||||
if parts.len().is_multiple_of(2) {
|
|
||||||
return refuse();
|
|
||||||
}
|
|
||||||
for (index, part) in parts.iter().enumerate() {
|
|
||||||
let code = index % 2 == 1;
|
|
||||||
let bad = if code {
|
|
||||||
part.is_empty() || part.starts_with(' ') || part.ends_with(' ')
|
|
||||||
} else {
|
|
||||||
plain_rewrite(part)
|
|
||||||
};
|
|
||||||
if bad {
|
|
||||||
return refuse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// What `formatMarkdown` does to a report written by `table()`: every table aligned (cells
|
/// What `formatMarkdown` does to a report written by `table()`: every table aligned (cells
|
||||||
/// padded to the widest of their column, three at least, separator dashes to the same
|
/// padded to the widest of their column, three at least, separator dashes to the same
|
||||||
/// width), every other line kept. A text with Markdown Prettier would rewrite otherwise is
|
/// width), every other line kept. Prettier's other rewrites of authored text are not
|
||||||
/// refused (`guard_line`).
|
/// reproduced: the draft's reports go through `report_guard::format_report`, which refuses them.
|
||||||
pub fn format_markdown(raw: &str) -> Result<String, PipelineError> {
|
pub fn format_markdown(raw: &str) -> Result<String, PipelineError> {
|
||||||
let lines: Vec<&str> = raw.split('\n').collect();
|
let lines: Vec<&str> = raw.split('\n').collect();
|
||||||
for line in &lines {
|
|
||||||
guard_line(line)?;
|
|
||||||
}
|
|
||||||
let mut out: Vec<String> = Vec::with_capacity(lines.len());
|
let mut out: Vec<String> = Vec::with_capacity(lines.len());
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
while index < lines.len() {
|
while index < lines.len() {
|
||||||
@@ -254,7 +108,7 @@ fn table_end(lines: &[&str], start: usize) -> usize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The cells of a row: split on the pipes no backslash escapes, trimmed as GFM trims them.
|
/// The cells of a row: split on the pipes no backslash escapes, trimmed as GFM trims them.
|
||||||
fn split_row(line: &str) -> Vec<String> {
|
pub(crate) fn split_row(line: &str) -> Vec<String> {
|
||||||
let inner = line.trim_end_matches([' ', '\t']);
|
let inner = line.trim_end_matches([' ', '\t']);
|
||||||
let inner = inner.strip_prefix('|').unwrap_or(inner);
|
let inner = inner.strip_prefix('|').unwrap_or(inner);
|
||||||
let inner = inner.strip_suffix('|').unwrap_or(inner);
|
let inner = inner.strip_suffix('|').unwrap_or(inner);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ pub mod ids;
|
|||||||
pub mod legacy;
|
pub mod legacy;
|
||||||
pub mod markdown;
|
pub mod markdown;
|
||||||
pub mod prettier_json;
|
pub mod prettier_json;
|
||||||
|
pub mod report_guard;
|
||||||
pub mod text;
|
pub mod text;
|
||||||
|
|
||||||
/// Why the pipeline refuses to produce a file. The TypeScript accepted some of these inputs
|
/// Why the pipeline refuses to produce a file. The TypeScript accepted some of these inputs
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
//! The guard of the draft's two Markdown reports (CHANGELOG.md, REVIEW-REPORT.md). The port
|
||||||
|
//! reproduces only Prettier's table alignment (`markdown::format_markdown`); Prettier also
|
||||||
|
//! rewrites Markdown in authored text (escapes, emphasis, whitespace, links). Rather than
|
||||||
|
//! chase every such rewrite, the guard admits an allowlist proven identical by the TypeScript
|
||||||
|
//! sweep (`oracles/r5/markdown-sweep.json`, hand-picked and seeded random probes) and by the
|
||||||
|
//! equine reports, and refuses everything else with `UnsupportedMarkdown`: a report is either
|
||||||
|
//! byte for byte the TypeScript's or not written.
|
||||||
|
//!
|
||||||
|
//! Admitted outside code spans: letters and digits, single spaces (none at a line end), the
|
||||||
|
//! punctuation of `PUNCTUATION`, an underscore between two ASCII letters or digits and not
|
||||||
|
//! glued to a URL, a backslash before `"` or `|` (a JSON quote, the cell escape), `**word**`
|
||||||
|
//! (one run of letters between spaces or line edges, the import report's form), no inline
|
||||||
|
//! construct (`rewritten_construct`). Inside code spans (the generated ids and targets):
|
||||||
|
//! anything but a carriage return or a tab, never empty, no outer space.
|
||||||
|
|
||||||
|
use super::PipelineError;
|
||||||
|
use super::markdown::{format_markdown, split_row};
|
||||||
|
|
||||||
|
/// Punctuation Prettier writes as is in the probed positions (the sweep's characters and the
|
||||||
|
/// equine reports'); any other character outside letters and digits is refused.
|
||||||
|
const PUNCTUATION: &str = ".,;:!?'\"«»()[]{}/-–—…%°≠=+#&<>’‘“”±→×≤≥|";
|
||||||
|
|
||||||
|
/// The starts of a bare URL literal Prettier links.
|
||||||
|
const URL_STARTS: [&str; 3] = ["http://", "https://", "www."];
|
||||||
|
|
||||||
|
fn refuse(line: &str) -> PipelineError {
|
||||||
|
PipelineError::UnsupportedMarkdown(line.to_owned())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Inline constructs Prettier re-prints: a link, image or reference (`](`, `][`), a wiki link
|
||||||
|
/// with inner spaces, an HTML tag or an autolink (`<` before a letter, `/`, `!` or `?`), a
|
||||||
|
/// character reference (`&name;`, `&#n;`).
|
||||||
|
fn rewritten_construct(plain: &str) -> bool {
|
||||||
|
let padded_wiki = plain.split("[[").skip(1).any(|after| {
|
||||||
|
let inside = after.split("]]").next().unwrap_or_default();
|
||||||
|
after.contains("]]")
|
||||||
|
&& (inside.starts_with(char::is_whitespace) || inside.ends_with(char::is_whitespace))
|
||||||
|
});
|
||||||
|
let tag = plain
|
||||||
|
.split('<')
|
||||||
|
.skip(1)
|
||||||
|
.any(|after| after.starts_with(|c: char| c.is_ascii_alphabetic() || "/!?".contains(c)));
|
||||||
|
let reference = plain.split('&').skip(1).any(|after| {
|
||||||
|
let name = after.split(';').next().unwrap_or_default();
|
||||||
|
after.contains(';')
|
||||||
|
&& !name.is_empty()
|
||||||
|
&& name.len() <= 32
|
||||||
|
&& name
|
||||||
|
.trim_start_matches('#')
|
||||||
|
.chars()
|
||||||
|
.all(|c| c.is_ascii_alphanumeric())
|
||||||
|
});
|
||||||
|
plain.contains("](") || plain.contains("][") || padded_wiki || tag || reference
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The `**word**` spans removed (their word kept); `None` when a `*` stays outside one.
|
||||||
|
fn outside_strong(plain: &str) -> Option<String> {
|
||||||
|
let mut out = String::new();
|
||||||
|
let mut rest = plain;
|
||||||
|
while let Some(open) = rest.find("**") {
|
||||||
|
let inside = &rest[open + 2..];
|
||||||
|
let close = inside.find("**")?;
|
||||||
|
let word = &inside[..close];
|
||||||
|
let before = rest[..open].chars().next_back();
|
||||||
|
let after = inside[close + 2..].chars().next();
|
||||||
|
let valid = !word.is_empty()
|
||||||
|
&& word.chars().all(char::is_alphabetic)
|
||||||
|
&& before.is_none_or(|c| c == ' ')
|
||||||
|
&& after.is_none_or(|c| c == ' ');
|
||||||
|
if !valid {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
out.push_str(&rest[..open]);
|
||||||
|
out.push_str(word);
|
||||||
|
rest = &inside[close + 2..];
|
||||||
|
}
|
||||||
|
out.push_str(rest);
|
||||||
|
(!out.contains('*')).then_some(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn admitted_char(chars: &[char], i: usize) -> bool {
|
||||||
|
let at = |k: usize| chars.get(k).copied();
|
||||||
|
let previous = i.checked_sub(1).and_then(at);
|
||||||
|
match chars[i] {
|
||||||
|
c if c.is_alphanumeric() => true,
|
||||||
|
' ' => at(i + 1) != Some(' '),
|
||||||
|
'_' => {
|
||||||
|
let rest: String = chars[i + 1..].iter().collect();
|
||||||
|
previous.is_some_and(|c| c.is_ascii_alphanumeric())
|
||||||
|
&& at(i + 1).is_some_and(|c| c.is_ascii_alphanumeric())
|
||||||
|
&& !URL_STARTS.iter().any(|start| rest.starts_with(start))
|
||||||
|
}
|
||||||
|
'\\' => matches!(at(i + 1), Some('"' | '|')) && previous != Some('\\'),
|
||||||
|
c => PUNCTUATION.contains(c),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn admitted_plain(plain: &str) -> bool {
|
||||||
|
if rewritten_construct(plain) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let Some(plain) = outside_strong(plain) else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
let chars: Vec<char> = plain.chars().collect();
|
||||||
|
(0..chars.len()).all(|i| admitted_char(&chars, i))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A text outside table delimiters: its code spans and its plain parts.
|
||||||
|
fn guard_text(text: &str) -> bool {
|
||||||
|
let parts: Vec<&str> = text.split('`').collect();
|
||||||
|
if parts.len().is_multiple_of(2) || text.contains(['\r', '\t']) || text.ends_with(' ') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
parts.iter().enumerate().all(|(index, part)| {
|
||||||
|
if index % 2 == 1 {
|
||||||
|
!part.is_empty() && !part.starts_with(' ') && !part.ends_with(' ')
|
||||||
|
} else {
|
||||||
|
admitted_plain(part)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Refuses a raw report line outside the allowlist, cell by cell in a table row.
|
||||||
|
fn guard_line(line: &str) -> Result<(), PipelineError> {
|
||||||
|
let admitted = if line.starts_with('|') {
|
||||||
|
split_row(line).iter().all(|cell| guard_text(cell))
|
||||||
|
} else {
|
||||||
|
guard_text(line)
|
||||||
|
};
|
||||||
|
if admitted { Ok(()) } else { Err(refuse(line)) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Every line of a raw report checked, then the tables aligned.
|
||||||
|
pub fn format_report(raw: &str) -> Result<String, PipelineError> {
|
||||||
|
for line in raw.split('\n') {
|
||||||
|
guard_line(line)?;
|
||||||
|
}
|
||||||
|
format_markdown(raw)
|
||||||
|
}
|
||||||
@@ -15,7 +15,8 @@ use faunosteo_core::curation::draft::migration_map::{
|
|||||||
use faunosteo_core::curation::draft::review_report::{ReviewReportInput, render_review_report};
|
use faunosteo_core::curation::draft::review_report::{ReviewReportInput, render_review_report};
|
||||||
use faunosteo_core::curation::draft::stats::document_stats;
|
use faunosteo_core::curation::draft::stats::document_stats;
|
||||||
use faunosteo_core::curation::draft::{apply_changeset, parse_changeset, parse_references};
|
use faunosteo_core::curation::draft::{apply_changeset, parse_changeset, parse_references};
|
||||||
use faunosteo_core::curation::markdown::format_markdown;
|
use faunosteo_core::curation::ids::sha256_hex;
|
||||||
|
use faunosteo_core::curation::report_guard::format_report;
|
||||||
use faunosteo_core::json::to_js_compact;
|
use faunosteo_core::json::to_js_compact;
|
||||||
use serde_json::{Value, json};
|
use serde_json::{Value, json};
|
||||||
|
|
||||||
@@ -69,9 +70,11 @@ const EQUINE_SAFE: &str = "[]&#{}=<>\"':;()/%?-.,«»…≠°—+";
|
|||||||
fn equine_safe(probe: &str) -> bool {
|
fn equine_safe(probe: &str) -> bool {
|
||||||
// A leading or trailing space becomes two spaces once the probe sits in its sentence; the
|
// A leading or trailing space becomes two spaces once the probe sits in its sentence; the
|
||||||
// inline constructs (links, wiki links, autolinks, character references) are probed apart.
|
// inline constructs (links, wiki links, autolinks, character references) are probed apart.
|
||||||
let construct = ["](", "][", "[[", "&", "<h", "<a@"]
|
let tag = probe
|
||||||
.iter()
|
.split('<')
|
||||||
.any(|m| probe.contains(m));
|
.skip(1)
|
||||||
|
.any(|after| after.starts_with(|c: char| c.is_ascii_alphabetic() || "/!?".contains(c)));
|
||||||
|
let construct = tag || ["](", "][", "[[ ", "&"].iter().any(|m| probe.contains(m));
|
||||||
!construct
|
!construct
|
||||||
&& !probe.contains(" ")
|
&& !probe.contains(" ")
|
||||||
&& !probe.starts_with(' ')
|
&& !probe.starts_with(' ')
|
||||||
@@ -88,32 +91,26 @@ fn every_probe_is_formatted_as_the_typescript_or_refused() {
|
|||||||
for case in frozen["cases"].as_array().unwrap() {
|
for case in frozen["cases"].as_array().unwrap() {
|
||||||
let probe = case["probe"].as_str().unwrap();
|
let probe = case["probe"].as_str().unwrap();
|
||||||
let (changelog, review) = raw_reports(&frozen, case);
|
let (changelog, review) = raw_reports(&frozen, case);
|
||||||
|
let digest = |text: &str| sha256_hex(text.as_bytes());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
changelog,
|
digest(&changelog),
|
||||||
case["changelog_raw"].as_str().unwrap(),
|
case["changelog_raw_sha256"],
|
||||||
"{probe:?} raw"
|
"{probe:?} raw"
|
||||||
);
|
);
|
||||||
if let Ok(review) = &review {
|
if let Ok(review) = &review {
|
||||||
assert_eq!(
|
assert_eq!(digest(review), case["review_raw_sha256"], "{probe:?} raw");
|
||||||
review,
|
|
||||||
case["review_raw"].as_str().unwrap(),
|
|
||||||
"{probe:?} raw"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
let outcomes = [
|
let outcomes = [
|
||||||
|
(format_report(&changelog), &case["changelog_sha256"]),
|
||||||
(
|
(
|
||||||
format_markdown(&changelog),
|
review.and_then(|text| format_report(&text)),
|
||||||
case["changelog"].as_str().unwrap(),
|
&case["review_sha256"],
|
||||||
),
|
|
||||||
(
|
|
||||||
review.and_then(|text| format_markdown(&text)),
|
|
||||||
case["review"].as_str().unwrap(),
|
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
let mut case_refused = false;
|
let mut case_refused = false;
|
||||||
for (outcome, expected) in outcomes {
|
for (outcome, expected) in outcomes {
|
||||||
match outcome {
|
match outcome {
|
||||||
Ok(text) if text == expected => {}
|
Ok(text) if digest(&text) == *expected => {}
|
||||||
Ok(_) => silent.push(probe.to_owned()),
|
Ok(_) => silent.push(probe.to_owned()),
|
||||||
Err(PipelineError::UnsupportedMarkdown(_) | PipelineError::UnsupportedWidth(_)) => {
|
Err(PipelineError::UnsupportedMarkdown(_) | PipelineError::UnsupportedWidth(_)) => {
|
||||||
case_refused = true;
|
case_refused = true;
|
||||||
@@ -137,6 +134,6 @@ fn every_probe_is_formatted_as_the_typescript_or_refused() {
|
|||||||
"silent differences for {} probes: {silent:?}",
|
"silent differences for {} probes: {silent:?}",
|
||||||
silent.len()
|
silent.len()
|
||||||
);
|
);
|
||||||
assert_eq!(same + refused, 247);
|
assert_eq!(same + refused, 762);
|
||||||
println!("{same} identical, {refused} refused");
|
println!("{same} identical, {refused} refused");
|
||||||
}
|
}
|
||||||
@@ -27,8 +27,8 @@ use faunosteo_core::curation::legacy::types::Anomaly;
|
|||||||
use faunosteo_core::curation::legacy::{
|
use faunosteo_core::curation::legacy::{
|
||||||
EquineLegacyInput, HEAD_VIEW_ID, ImportResult, SvgSource, import_equine_legacy,
|
EquineLegacyInput, HEAD_VIEW_ID, ImportResult, SvgSource, import_equine_legacy,
|
||||||
};
|
};
|
||||||
use faunosteo_core::curation::markdown::format_markdown;
|
|
||||||
use faunosteo_core::curation::prettier_json::format_json;
|
use faunosteo_core::curation::prettier_json::format_json;
|
||||||
|
use faunosteo_core::curation::report_guard::format_report;
|
||||||
use faunosteo_core::domain::sheet::AnatomicalSheetDocument;
|
use faunosteo_core::domain::sheet::AnatomicalSheetDocument;
|
||||||
use faunosteo_core::json::to_js_compact;
|
use faunosteo_core::json::to_js_compact;
|
||||||
use serde_json::{Map, Value};
|
use serde_json::{Map, Value};
|
||||||
@@ -174,7 +174,7 @@ fn the_raw_reports_are_the_texts_prettier_received() {
|
|||||||
row["before_prettier_sha256"],
|
row["before_prettier_sha256"],
|
||||||
"{file} raw"
|
"{file} raw"
|
||||||
);
|
);
|
||||||
let formatted = format_markdown(&raw).unwrap();
|
let formatted = format_report(&raw).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
sha256_hex(formatted.as_bytes()),
|
sha256_hex(formatted.as_bytes()),
|
||||||
row["sha256"],
|
row["sha256"],
|
||||||
@@ -326,8 +326,8 @@ fn render_case(frozen: &Value, case: &Value) -> Rendered {
|
|||||||
drawings.insert(format!("app-{}", view.id()), Value::from(app));
|
drawings.insert(format!("app-{}", view.id()), Value::from(app));
|
||||||
}
|
}
|
||||||
Rendered {
|
Rendered {
|
||||||
changelog: format_markdown(&changelog_raw),
|
changelog: format_report(&changelog_raw),
|
||||||
review: format_markdown(&review_raw),
|
review: format_report(&review_raw),
|
||||||
changelog_raw,
|
changelog_raw,
|
||||||
review_raw,
|
review_raw,
|
||||||
drawings,
|
drawings,
|
||||||
@@ -355,7 +355,10 @@ fn the_synthetic_review_cases_match_the_typescript_or_are_refused_as_declared()
|
|||||||
if DECLARED_REFUSALS.contains(&name) {
|
if DECLARED_REFUSALS.contains(&name) {
|
||||||
let refused = rendered.changelog.unwrap_err();
|
let refused = rendered.changelog.unwrap_err();
|
||||||
assert!(
|
assert!(
|
||||||
matches!(refused, PipelineError::UnsupportedWidth(_)),
|
matches!(
|
||||||
|
refused,
|
||||||
|
PipelineError::UnsupportedWidth(_) | PipelineError::UnsupportedMarkdown(_)
|
||||||
|
),
|
||||||
"{name}"
|
"{name}"
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"baseline":{"schema_version":2,"species_id":"equine","name":{"fr":"Mini","en":"Mini"},"description":{},"scope_disclaimer":{},"attribution":{"authors":[],"license":null,"notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18}]},"references":[],"categories":[{"id":"joints","name":{"fr":"Articulations","en":"Joints"},"color":null},{"id":"bones","name":{"fr":"Os","en":"Bones"},"color":null}],"views":[{"id":"main","kind":"main","name":{"fr":"Vue","en":"View"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null},{"id":"head","kind":"detail","parent_view_id":"main","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":0,"min_y":0,"width":10,"height":10}}],"annotations":[{"id":"hip","kind":"point","view_id":"main","category_id":"joints","laterality":"bilateral","geometry":{"type":"circle","cx":1,"cy":2,"r":3},"name":{"fr":"Hanche","en":"Hip"},"finding_zone_id":"hip","vertebral_region_code":null},{"id":"neck","kind":"zone","view_id":"main","category_id":"bones","laterality":"unpaired","geometry":null,"name":{"fr":"Cou","en":"Neck"},"finding_zone_id":"neck","vertebral_region_code":"C"},{"id":"head-trigger","kind":"detail_trigger","view_id":"main","category_id":"bones","laterality":"unpaired","geometry":null,"name":null,"opens_view_id":"head"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche","en":"Hip"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions","en":"Dysfunctions"},"children":[{"id":"mobility","name":{"fr":"mobility fr","en":"mobility en"},"children":[{"id":"flexion","name":{"fr":"flexion fr","en":"flexion en"}},{"id":"extension","name":{"fr":"extension fr","en":"extension en"}}]},{"id":"pain","name":{"fr":"pain fr","en":"pain en"}}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse","en":"Anamnesis"},"children":[{"id":"trauma","name":{"fr":"trauma fr","en":"trauma en"}}]}]},{"id":"neck","name":{"fr":"Cou","en":"Neck"},"categories":[{"id":"neck-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions","en":"Dysfunctions"},"children":[{"id":"stiffness","name":{"fr":"stiffness fr","en":"stiffness en"}},{"id":"vet","name":{"fr":"vet fr","en":"vet en"},"requires_vet_referral":true}]}]}]},"references":[{"id":"atlas","type":"book","citation":"Atlas of anatomy","url":null,"doi":null},{"id":"paper","type":"journal","citation":"A paper","url":null,"doi":"10.1/x"}],"legacy_id_map":{"views":{"head":"head"},"annotations":{"legacy-hip":"hip","legacy-neck":"neck"},"categories":{},"finding_nodes":{},"assets":{}},"cases":[{"probe":"*","changes_file":{"changes":[{"id":"CHG-001","level":"C","kind":"correction","title":{"fr":"Titre *","en":"Title"},"rationale":"Raison * fin.","reference_ids":[],"question":"Question * ?","ops":[{"op":"add","target":"document","field":"references","value":{"id":"probe-ref","type":"web","citation":"Citation *","url":null,"doi":null}},{"op":"cite","target":"finding:hip/hip-dysfunctions/mobility","reference_ids":["probe-ref"]},{"op":"set","target":"finding:hip/hip-dysfunctions/mobility","field":"name.en","value":"Label *"}]}]},"changelog_raw":"# Journal des changements : révision de travail\n\nGénéré par `pnpm import:equine` : import historique (`legacy-import/`) puis changements rédigés (`curation/changes.json`). Ne pas modifier à la main : relancer la commande.\n\nNiveaux : A = erreur démontrée, B = amélioration étayée, C = point incertain. Les niveaux B et C demandent une confirmation professionnelle.\n\n## Comparaison quantitative\n\n| Indicateur | Avant | Après |\n| --- | --- | --- |\n| Vues | 2 | 2 |\n| Dessins SVG distincts | 1 | 1 |\n| Annotations | 3 | 3 |\n| Annotations (point) | 1 | 1 |\n| Annotations (zone) | 1 | 1 |\n| Annotations (detail_trigger) | 1 | 1 |\n| Annotations, revue (inherited) | 3 | 3 |\n| Annotations, revue (reviewed) | 0 | 0 |\n| Annotations, revue (to_confirm) | 0 | 0 |\n| Catégories d'annotation | 2 | 2 |\n| Zones de constats | 2 | 2 |\n| Catégories de constats | 3 | 3 |\n| Nœuds (catégories incluses) | 10 | 10 |\n| Feuilles | 6 | 6 |\n| Renvois vétérinaires | 1 | 1 |\n| Nœuds, revue (inherited) | 10 | 9 |\n| Nœuds, revue (reviewed) | 0 | 0 |\n| Nœuds, revue (to_confirm) | 0 | 1 |\n| Descriptions | 0 | 0 |\n| Descriptions en français seulement | 0 | 0 |\n| Références bibliographiques | 0 | 3 |\n| Nœuds cités | 0 | 1 |\n| Régions vertébrales avec plage documentée | 0 | 0 |\n\n## Migration des bilans v2\n\n| Nœuds | Nombre |\n| --- | --- |\n| Nœuds du catalogue historique | 10 |\n| Chemin identique | 10 |\n| Chemin renommé ou déplacé (suivi des renommages) | 0 |\n| Relogé sous une autre catégorie (correspondance unique) | 0 |\n| Retiré : le bilan garde le constat avec ses libellés figés | 0 |\n\n## Niveau A : erreurs démontrées\n\nAucun changement de ce niveau.\n\n## Niveau B : améliorations étayées (confirmatioLine truncated
|
{"baseline":{"schema_version":2,"species_id":"equine","name":{"fr":"Mini","en":"Mini"},"description":{},"scope_disclaimer":{},"attribution":{"authors":[],"license":null,"notes":null},"vertebral_config":{"regions":[{"code":"C","name":{"fr":"Cervicales","en":"Cervical"},"count":7},{"code":"T","name":{"fr":"Thoraciques","en":"Thoracic"},"count":18}]},"references":[],"categories":[{"id":"joints","name":{"fr":"Articulations","en":"Joints"},"color":null},{"id":"bones","name":{"fr":"Os","en":"Bones"},"color":null}],"views":[{"id":"main","kind":"main","name":{"fr":"Vue","en":"View"},"svg_asset_id":"3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8","view_box":null},{"id":"head","kind":"detail","parent_view_id":"main","name":{"fr":"Tête","en":"Head"},"svg_asset_id":null,"view_box":{"min_x":0,"min_y":0,"width":10,"height":10}}],"annotations":[{"id":"hip","kind":"point","view_id":"main","category_id":"joints","laterality":"bilateral","geometry":{"type":"circle","cx":1,"cy":2,"r":3},"name":{"fr":"Hanche","en":"Hip"},"finding_zone_id":"hip","vertebral_region_code":null},{"id":"neck","kind":"zone","view_id":"main","category_id":"bones","laterality":"unpaired","geometry":null,"name":{"fr":"Cou","en":"Neck"},"finding_zone_id":"neck","vertebral_region_code":"C"},{"id":"head-trigger","kind":"detail_trigger","view_id":"main","category_id":"bones","laterality":"unpaired","geometry":null,"name":null,"opens_view_id":"head"}],"finding_zones":[{"id":"hip","name":{"fr":"Hanche","en":"Hip"},"categories":[{"id":"hip-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions","en":"Dysfunctions"},"children":[{"id":"mobility","name":{"fr":"mobility fr","en":"mobility en"},"children":[{"id":"flexion","name":{"fr":"flexion fr","en":"flexion en"}},{"id":"extension","name":{"fr":"extension fr","en":"extension en"}}]},{"id":"pain","name":{"fr":"pain fr","en":"pain en"}}]},{"id":"anamnesis","kind":"anamnesis","name":{"fr":"Anamnèse","en":"Anamnesis"},"children":[{"id":"trauma","name":{"fr":"trauma fr","en":"trauma en"}}]}]},{"id":"neck","name":{"fr":"Cou","en":"Neck"},"categories":[{"id":"neck-dysfunctions","kind":"dysfunction","name":{"fr":"Dysfonctions","en":"Dysfunctions"},"children":[{"id":"stiffness","name":{"fr":"stiffness fr","en":"stiffness en"}},{"id":"vet","name":{"fr":"vet fr","en":"vet en"},"requires_vet_referral":true}]}]}]},"references":[{"id":"atlas","type":"book","citation":"Atlas of anatomy","url":null,"doi":null},{"id":"paper","type":"journal","citation":"A paper","url":null,"doi":"10.1/x"}],"legacy_id_map":{"views":{"head":"head"},"annotations":{"legacy-hip":"hip","legacy-neck":"neck"},"categories":{},"finding_nodes":{},"assets":{}},"cases":[{"probe":"*","changes_file":{"changes":[{"id":"CHG-001","level":"C","kind":"correction","title":{"fr":"Titre *","en":"Title"},"rationale":"Raison * fin.","reference_ids":[],"question":"Question * ?","ops":[{"op":"add","target":"document","field":"references","value":{"id":"probe-ref","type":"web","citation":"Citation *","url":null,"doi":null}},{"op":"cite","target":"finding:hip/hip-dysfunctions/mobility","reference_ids":["probe-ref"]},{"op":"set","target":"finding:hip/hip-dysfunctions/mobility","field":"name.en","value":"Label *"},{"op":"set","target":"finding:hip/hip-dysfunctions/mobility/flexion","field":"name.fr","value":"*"}]}]},"changelog_raw_sha256":"55b992587e03e05c2b98e81e7c644aa852713084183a89cd2651b61f0e922cbb","changelog_sha256":"1e21c6e4509109bba34c869cf8df77f838e69cfdc85df203a71917b1cd25cca7","review_raw_sha256":"3f289d6d2f18fef8f99ea375703603f2b0f1076063f7440a7554ed081b1f63aa","review_sha256":"2fef9ccf08ff9e38ff59e7ca7b6fa4966e8f4ddea9188c666276adb0c59f41db"},{"probe":"*x","changes_file":{"changes":[{"id":"CHG-001","level":"C","kind":"correction","title":{"fr":"Titre *x","en":"Title"},"rationale":"Raison *x fin.","reference_ids":[],"question":"Question *x ?","ops":[{"op":"add","target":"document","field":"references","value":{"id":"probe-ref","type":"web","citation":"Citation *x","url":null,"doi":null}},{"op":"cite","target":"finding:hip/hip-dysfunctions/mobility","reference_ids":["probe-ref"]},{"op":"set","target":"finding:hip/hip-dysfunctions/mobility","field":"name.en","value":"Label *x"},{"op":"set","target":"finding:hip/hip-dysfunctions/mobility/flexion","field":"name.fr","value":"*x"}]}]},"changelog_raw_sha256":"bcb9602df19f1a01322e79fb099fd4031f40c3863ecf904daf6e107ceec9f8a6","changelog_sha256":"23d0c545ce56bc949d88d6ad5d99104aba582f851fc8f8689901cc57d9400399","review_raw_sha256":"cff4115989dd4c411d94893c5b1a19333169b53fd0a6c4dd668ba771f7e97332","review_sha256":"382d3968e4d03960e4cca33109a06b6af0db8cc53b8aec01cf940004ab91755e"},{"probe":"x*","changes_file":{"changes":[{"id":"CHG-001","level":"C","kind":"correction","title":{"fr":"Titre x*","en":"Title"},"rationale":"Raison x* fin.","reference_ids":[],"question":"Question x* ?","ops":[{"op":"add","target":"document","field":"references","value":{"id":"probe-ref","type":"web","citation":"Citation x*","url":null,"doi":null}}Line truncated
|
||||||
@@ -4,9 +4,11 @@
|
|||||||
* Prettier would rewrite; this sweep, written by the TypeScript, holds it to that: every probe
|
* Prettier would rewrite; this sweep, written by the TypeScript, holds it to that: every probe
|
||||||
* (a special character in six positions, whitespace patterns, Markdown constructs) is placed
|
* (a special character in six positions, whitespace patterns, Markdown constructs) is placed
|
||||||
* in a change title, rationale and question, a cited reference and a changed label, and the
|
* in a change title, rationale and question, a cited reference and a changed label, and the
|
||||||
* raw and formatted CHANGELOG and REVIEW-REPORT are frozen. `MAKE_R5_ORACLES=1` writes
|
* sha256 of the raw and formatted CHANGELOG and REVIEW-REPORT are frozen (400 of the probes
|
||||||
|
* come from a seeded generator, so unknown classes surface on their own). `MAKE_R5_ORACLES=1` writes
|
||||||
* crates/core/tests/oracles/r5/markdown-sweep.json.
|
* crates/core/tests/oracles/r5/markdown-sweep.json.
|
||||||
*/
|
*/
|
||||||
|
import { createHash } from 'node:crypto'
|
||||||
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
||||||
import { dirname, resolve } from 'node:path'
|
import { dirname, resolve } from 'node:path'
|
||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from 'node:url'
|
||||||
@@ -24,6 +26,10 @@ import { formatMarkdown } from '../src/format'
|
|||||||
import { MINI_REFERENCES, miniSheet } from './fixtures/mini-sheet'
|
import { MINI_REFERENCES, miniSheet } from './fixtures/mini-sheet'
|
||||||
|
|
||||||
const HERE = dirname(fileURLToPath(import.meta.url))
|
const HERE = dirname(fileURLToPath(import.meta.url))
|
||||||
|
|
||||||
|
function sha256(text: string): string {
|
||||||
|
return createHash('sha256').update(text, 'utf8').digest('hex')
|
||||||
|
}
|
||||||
const OUT = resolve(HERE, '../../../crates/core/tests/oracles/r5')
|
const OUT = resolve(HERE, '../../../crates/core/tests/oracles/r5')
|
||||||
const MAKE = process.env.MAKE_R5_ORACLES === '1'
|
const MAKE = process.env.MAKE_R5_ORACLES === '1'
|
||||||
|
|
||||||
@@ -35,7 +41,7 @@ const LEGACY_ID_MAP = {
|
|||||||
assets: {},
|
assets: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
const CHARACTERS = [...'*_~\\`<>&[]!#$|+=^{}"\'%@:;?/()-.,']
|
const CHARACTERS = [...'*_~\\`<>&[]!#$|+=^{}"\'%@:;?/()-.,’‘“”×≤≥±→–—…«»°≠']
|
||||||
|
|
||||||
function positions(c: string): string[] {
|
function positions(c: string): string[] {
|
||||||
return [c, `${c}x`, `x${c}`, `a ${c} b`, `a${c}b`, `${c}${c}`]
|
return [c, `${c}x`, `x${c}`, `a ${c} b`, `a${c}b`, `${c}${c}`]
|
||||||
@@ -88,6 +94,25 @@ const PATTERNS = [
|
|||||||
'한_한',
|
'한_한',
|
||||||
'é_é',
|
'é_é',
|
||||||
'[a]( https://x.org )',
|
'[a]( https://x.org )',
|
||||||
|
'**a****b**',
|
||||||
|
'\\**a**',
|
||||||
|
'x_**a**',
|
||||||
|
'**a**_x',
|
||||||
|
'** **',
|
||||||
|
'**Total**',
|
||||||
|
'(**a**)',
|
||||||
|
'a **b** c',
|
||||||
|
'Voir_https://example.org/x',
|
||||||
|
'Voir_www.example.org',
|
||||||
|
'https://x.org/**a **',
|
||||||
|
'https://x.org/a_b',
|
||||||
|
'Lien https://x.org/a_b fin',
|
||||||
|
'a\u00a0b',
|
||||||
|
'a\u2003b',
|
||||||
|
'a\u3000b',
|
||||||
|
'中文',
|
||||||
|
'مرحبا',
|
||||||
|
'e\u0301',
|
||||||
'&',
|
'&',
|
||||||
'# titre',
|
'# titre',
|
||||||
'1. item',
|
'1. item',
|
||||||
@@ -99,8 +124,34 @@ const PATTERNS = [
|
|||||||
'é ü ß ø Ω 中',
|
'é ü ß ø Ω 中',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
/** A seeded generator (a 32-bit LCG): the random probes are the same on every run. */
|
||||||
|
function randomProbes(count: number): string[] {
|
||||||
|
const alphabet = [
|
||||||
|
...'ab_*\\`[]()<>&#!~ :/.|"é中',
|
||||||
|
'https://',
|
||||||
|
'www.',
|
||||||
|
'**',
|
||||||
|
'\n',
|
||||||
|
'\u00a0',
|
||||||
|
]
|
||||||
|
let state = 20261023
|
||||||
|
const next = () => {
|
||||||
|
state = (Math.imul(state, 1664525) + 1013904223) >>> 0
|
||||||
|
return state
|
||||||
|
}
|
||||||
|
const out: string[] = []
|
||||||
|
for (let i = 0; i < count; i += 1) {
|
||||||
|
const length = 2 + (next() % 10)
|
||||||
|
let text = ''
|
||||||
|
for (let j = 0; j < length; j += 1)
|
||||||
|
text += alphabet[next() % alphabet.length]
|
||||||
|
out.push(text)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
function probes(): string[] {
|
function probes(): string[] {
|
||||||
return [...CHARACTERS.flatMap(positions), ...PATTERNS]
|
return [...CHARACTERS.flatMap(positions), ...PATTERNS, ...randomProbes(400)]
|
||||||
}
|
}
|
||||||
|
|
||||||
function changesFile(probe: string) {
|
function changesFile(probe: string) {
|
||||||
@@ -138,6 +189,12 @@ function changesFile(probe: string) {
|
|||||||
field: 'name.en',
|
field: 'name.en',
|
||||||
value: `Label ${probe}`,
|
value: `Label ${probe}`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
op: 'set',
|
||||||
|
target: 'finding:hip/hip-dysfunctions/mobility/flexion',
|
||||||
|
field: 'name.fr',
|
||||||
|
value: probe,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -170,10 +227,10 @@ async function run(probe: string) {
|
|||||||
return {
|
return {
|
||||||
probe,
|
probe,
|
||||||
changes_file: file,
|
changes_file: file,
|
||||||
changelog_raw: changelogRaw,
|
changelog_raw_sha256: sha256(changelogRaw),
|
||||||
changelog: await formatMarkdown(changelogRaw),
|
changelog_sha256: sha256(await formatMarkdown(changelogRaw)),
|
||||||
review_raw: reviewRaw,
|
review_raw_sha256: sha256(reviewRaw),
|
||||||
review: await formatMarkdown(reviewRaw),
|
review_sha256: sha256(await formatMarkdown(reviewRaw)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,5 +251,5 @@ describe('R5.4 Markdown sweep oracle', () => {
|
|||||||
writeFileSync(file, text)
|
writeFileSync(file, text)
|
||||||
}
|
}
|
||||||
expect(text).toBe(readFileSync(file, 'utf8'))
|
expect(text).toBe(readFileSync(file, 'utf8'))
|
||||||
})
|
}, 120_000)
|
||||||
})
|
})
|
||||||
Reference in new issue
Block a user