fix(anatomy): R5.3 authored values read as JSON.parse does (key order, big integers), non-list children refused, document value bound, --check and seed guard by identity

This commit is contained in:
bchanot committed 2026-10-23 10:32:44 +02:00
1 parent 6c0fe88725
commit 07d63076d3
10 files changed
+222 -23

No files matched your search

+45 -3
View File
@@ -309,9 +309,10 @@ fn synthetic_seed(document_json: &str) -> String {
}
/// Cases the TypeScript accepted and the port refuses, declared in RUST.md §11.12.
const DECLARED_REFUSALS: [&str; 2] = [
const DECLARED_REFUSALS: [&str; 3] = [
"declared-set-without-value-drops-key",
"declared-children-string-renamed-then-removed",
"declared-children-object-then-added-to",
];
/// Cases the TypeScript refused and the port accepts, declared in RUST.md §11.12 (checked by
@@ -385,7 +386,9 @@ fn the_synthetic_cases_match_the_typescript_or_are_refused_alike() {
let error = outcome
.err()
.unwrap_or_else(|| panic!("{name}: the TypeScript refused, the port accepted"));
if name == "declared-children-string-renamed-then-removed" {
if name == "declared-children-object-then-added-to" {
assert!(error.to_string().contains("that is not a list"), "{name}");
} else if name == "declared-children-string-renamed-then-removed" {
assert!(
error.to_string().contains("that is not an object"),
"{name}"
@@ -438,7 +441,7 @@ fn the_synthetic_cases_match_the_typescript_or_are_refused_alike() {
"{name} seed"
);
}
assert_eq!((compared, refused), (11, 65));
assert_eq!((compared, refused), (14, 66));
let reference_cases = frozen["reference_cases"].as_array().unwrap();
assert_eq!(reference_cases.len(), 7);
for case in reference_cases {
@@ -711,3 +714,42 @@ fn out_refuses_every_unsafe_destination_and_writes_nothing() {
assert_eq!(std::fs::read_dir(base.join("full")).unwrap().count(), 1);
assert!(std::fs::symlink_metadata(base.join("absent")).is_err());
}
/// `JSON.parse` keeps no integer beyond 2^53: the record holds the double the document holds.
#[test]
fn an_integer_beyond_2_53_is_read_as_the_double_json_parse_gives() {
let text = |count: &str| {
format!(
r#"{{"changes":[{{"id":"CHG-001","level":"A","kind":"technical",
"title":{{"fr":"Essai","en":"Test"}},"rationale":"Essai","reference_ids":[],
"ops":[{{"op":"set","target":"region:C","field":"count","value":{count}}}]}}]}}"#
)
};
let exact = parse_changeset(&text("9007199254740993")).unwrap();
let rounded = parse_changeset(&text("9007199254740992")).unwrap();
let print = |set: &Changeset| to_js_compact(&serde_json::to_value(set).unwrap()).unwrap();
assert_eq!(print(&exact), print(&rounded));
let frozen = oracle("curation-synthetic.json");
let references = parse_references(&to_js_compact(&frozen["references_file"]).unwrap()).unwrap();
let result = apply_changeset(&frozen["baseline"], &references, &exact.changes).unwrap();
assert_eq!(
to_js_compact(&result.records[0].after).unwrap(),
"9007199254740992"
);
assert!(
format_json(&result.document)
.unwrap()
.contains("9007199254740992")
);
}
#[test]
fn the_document_cannot_hold_more_values_than_the_bound() {
let children: Vec<Value> = (0..70_000)
.map(|i| json!({ "id": format!("n{i}"), "name": { "fr": "a", "en": "a" } }))
.collect();
let value = json!({ "id": "many", "name": { "fr": "a", "en": "a" }, "children": children });
let op = json!({ "op": "add", "target": MOBILITY, "value": value });
let error = mini_apply(json!([op])).unwrap_err();
assert!(error.contains("more than 200000 values"), "{error}");
}