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:
1 parent
6c0fe88725
commit
07d63076d3
10 files changed
+222
-23
No files matched your search
@@ -181,6 +181,12 @@ fn listed(dir: &Path, prefix: &str, out: &mut Vec<String>) -> Result<(), String>
|
||||
/// draft are reported, not counted.
|
||||
fn check(folder: &Folder) -> Result<Vec<String>, String> {
|
||||
let target = Path::new(SEED).join(folder.name);
|
||||
// The generated folder itself must lie in the seed: a link there is never listed through.
|
||||
let seed = fs::canonicalize(SEED).map_err(|error| format!("{SEED}: {error}"))?;
|
||||
let canonical = fs::canonicalize(&target).map_err(|e| format!("{}: {e}", target.display()))?;
|
||||
if canonical != seed.join(folder.name) {
|
||||
return Ok(vec![format!("{}: not a folder of the seed", folder.name)]);
|
||||
}
|
||||
let mut problems = Vec::new();
|
||||
for (name, bytes) in &folder.files {
|
||||
match read(&target.join(name)) {
|
||||
@@ -227,7 +233,7 @@ fn claim_destination(typed: &Path, seed: &Path) -> Result<PathBuf, String> {
|
||||
}
|
||||
None => return Err(refuse("not a destination folder")),
|
||||
};
|
||||
if inside(&parent, seed) {
|
||||
if inside(&parent, seed) || inside_by_identity(&parent, seed) {
|
||||
return Err(refuse("inside the seed folder"));
|
||||
}
|
||||
let name = out
|
||||
@@ -254,6 +260,18 @@ fn inside(folder: &Path, seed: &Path) -> bool {
|
||||
folder.starts_with(seed)
|
||||
}
|
||||
|
||||
/// Whether the seed folder is `folder` or one of its ancestors, by file identity (device and
|
||||
/// inode): a second path to the seed (a bind mount, a share mounted twice) is caught too.
|
||||
fn inside_by_identity(folder: &Path, seed: &Path) -> bool {
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
let Ok(seed) = fs::metadata(seed) else {
|
||||
return true;
|
||||
};
|
||||
folder.ancestors().any(|ancestor| {
|
||||
fs::metadata(ancestor).is_ok_and(|m| m.dev() == seed.dev() && m.ino() == seed.ino())
|
||||
})
|
||||
}
|
||||
|
||||
/// Where a relative destination is typed from: `INIT_CWD` when pnpm set it to an absolute
|
||||
/// path, else the current folder (the repository root when the script is run directly: it
|
||||
/// moves there first).
|
||||
@@ -377,10 +395,11 @@ fn main() {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Fixed fixtures under the system's temporary folder: created once, never deleted, never
|
||||
/// written by the refusals below.
|
||||
/// Fixed fixtures under the workspace's target folder (private to the checkout): created
|
||||
/// once, never deleted, never written by the refusals below.
|
||||
fn fixture_seed() -> PathBuf {
|
||||
let base = env::temp_dir().join("faunosteo-import-equine-claim");
|
||||
let base = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/../../target/tmp"))
|
||||
.join("import-equine-claim");
|
||||
fs::create_dir_all(base.join("seed/draft")).unwrap_or_else(|e| panic!("{e}"));
|
||||
fs::canonicalize(base.join("seed")).unwrap_or_else(|e| panic!("{e}"))
|
||||
}
|
||||
|
||||
@@ -122,11 +122,21 @@ fn apply_change(
|
||||
/// the document until a recursive walk overflows the stack.
|
||||
pub const MAX_DOCUMENT_DEPTH: usize = 64;
|
||||
|
||||
/// The nesting of `value`, walked with an explicit stack (no recursion).
|
||||
fn depth_of(value: &Value) -> usize {
|
||||
let mut deepest = 0;
|
||||
/// Values a valid sheet document never approaches (the equine document holds 6,374): a
|
||||
/// resource bound checked with the depth, so the document, and the work done after each op,
|
||||
/// cannot grow without limit.
|
||||
pub const MAX_DOCUMENT_VALUES: usize = 200_000;
|
||||
|
||||
/// The nesting and the number of values of `value`, walked with an explicit stack (no
|
||||
/// recursion); the walk stops counting past the value bound.
|
||||
fn measure(value: &Value) -> (usize, usize) {
|
||||
let (mut deepest, mut count) = (0, 0);
|
||||
let mut pending = vec![(value, 1)];
|
||||
while let Some((value, depth)) = pending.pop() {
|
||||
count += 1;
|
||||
if count > MAX_DOCUMENT_VALUES {
|
||||
break;
|
||||
}
|
||||
let children: Box<dyn Iterator<Item = &Value>> = match value {
|
||||
Value::Object(map) => Box::new(map.values()),
|
||||
Value::Array(items) => Box::new(items.iter()),
|
||||
@@ -135,11 +145,17 @@ fn depth_of(value: &Value) -> usize {
|
||||
deepest = deepest.max(depth);
|
||||
pending.extend(children.map(|child| (child, depth + 1)));
|
||||
}
|
||||
deepest
|
||||
(deepest, count)
|
||||
}
|
||||
|
||||
fn assert_depth(doc: &Value) -> Result<(), PipelineError> {
|
||||
if depth_of(doc) > MAX_DOCUMENT_DEPTH {
|
||||
let (depth, count) = measure(doc);
|
||||
if count > MAX_DOCUMENT_VALUES {
|
||||
return Err(fail(format!(
|
||||
"the document holds more than {MAX_DOCUMENT_VALUES} values"
|
||||
)));
|
||||
}
|
||||
if depth > MAX_DOCUMENT_DEPTH {
|
||||
return Err(fail(format!(
|
||||
"the document nests more than {MAX_DOCUMENT_DEPTH} levels"
|
||||
)));
|
||||
|
||||
@@ -6,6 +6,7 @@ use serde_json::{Map, Value};
|
||||
|
||||
use super::targets::{Item, ParsedTarget, TargetKind, fail};
|
||||
use crate::curation::PipelineError;
|
||||
use crate::curation::text::js_insert;
|
||||
|
||||
/// Item kind of the settable table; a finding is a category or a node.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -129,13 +130,13 @@ pub fn write_field(item: &mut Item, field: &str, value: &Value) -> Result<(), Pi
|
||||
let mut holder = item;
|
||||
for key in holders {
|
||||
if !holder.get(*key).is_some_and(Value::is_object) {
|
||||
holder.insert((*key).to_owned(), Value::Object(Map::new()));
|
||||
js_insert(holder, key, Value::Object(Map::new()));
|
||||
}
|
||||
holder = holder
|
||||
.get_mut(*key)
|
||||
.and_then(Value::as_object_mut)
|
||||
.ok_or_else(|| fail("field holder vanished"))?;
|
||||
}
|
||||
holder.insert((*last).to_owned(), value.clone());
|
||||
js_insert(holder, last, value.clone());
|
||||
Ok(())
|
||||
}
|
||||
@@ -238,7 +238,9 @@ fn add_destination(doc: &mut Value, op: &AddOp) -> Result<Destination, PipelineE
|
||||
})
|
||||
}
|
||||
|
||||
/// Every entry of a `children` or `categories` list of an added value must be an object. The
|
||||
/// 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.
|
||||
@@ -249,8 +251,14 @@ fn assert_object_children(value: &Value) -> Result<(), PipelineError> {
|
||||
continue;
|
||||
};
|
||||
for key in ["children", "categories"] {
|
||||
let Some(list) = map.get(key).and_then(Value::as_array) else {
|
||||
continue;
|
||||
let list = match map.get(key) {
|
||||
None => continue,
|
||||
Some(Value::Array(list)) => list,
|
||||
Some(_) => {
|
||||
return Err(fail(format!(
|
||||
"the added item holds a \"{key}\" that is not a list"
|
||||
)));
|
||||
}
|
||||
};
|
||||
if list.iter().any(|entry| !entry.is_object()) {
|
||||
return Err(fail(format!(
|
||||
|
||||
@@ -14,6 +14,7 @@ use serde_json::{Map, Value};
|
||||
|
||||
use super::shape::assert_same_shape;
|
||||
use crate::curation::PipelineError;
|
||||
use crate::curation::text::js_normalize;
|
||||
use crate::domain::js;
|
||||
use crate::domain::sheet::Reference;
|
||||
|
||||
@@ -383,9 +384,12 @@ fn refuse(file: &str, error: impl std::fmt::Display) -> PipelineError {
|
||||
}
|
||||
|
||||
/// `JSON.parse`: a repeated key keeps its first position and its last value (the parsed
|
||||
/// value is read into the typed shape afterwards, so duplicates never reach serde's derive).
|
||||
/// value is read into the typed shape afterwards, so duplicates never reach serde's derive),
|
||||
/// array index keys come first, integers beyond 2^53 are rounded (`js_normalize`).
|
||||
fn json_parse(file: &str, text: &str) -> Result<Value, PipelineError> {
|
||||
js::parse_json(text).map_err(|error| refuse(file, error))
|
||||
let mut value = js::parse_json(text).map_err(|error| refuse(file, error))?;
|
||||
js_normalize(&mut value);
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
/// A key starting with NUL is reserved for the applier's transient touch marks
|
||||
|
||||
@@ -240,11 +240,17 @@ fn with(path: &[Step], step: Step) -> Path {
|
||||
}
|
||||
|
||||
/// `childrenOf`: children of a finding item; a lean leaf gets an empty list on demand (the key
|
||||
/// is appended to the item, as the TypeScript did).
|
||||
/// is appended to the item, as the TypeScript did); a present value that is not a list is
|
||||
/// refused, never replaced.
|
||||
pub fn children_path(doc: &mut Value, item: &[Step]) -> Result<Path, PipelineError> {
|
||||
let holder = item_at_mut(doc, item)?;
|
||||
if !holder.get("children").is_some_and(Value::is_array) {
|
||||
holder.insert("children".into(), Value::Array(Vec::new()));
|
||||
match holder.get("children") {
|
||||
None => {
|
||||
holder.insert("children".into(), Value::Array(Vec::new()));
|
||||
}
|
||||
Some(Value::Array(_)) => {}
|
||||
// Never replaced: the author's value would be lost (refused at the add already).
|
||||
Some(_) => return Err(fail("\"children\" is not a list")),
|
||||
}
|
||||
Ok(with(item, Step::Key("children")))
|
||||
}
|
||||
|
||||
@@ -295,6 +295,50 @@ pub fn js_object<I: IntoIterator<Item = (String, Value)>>(entries: I) -> Map<Str
|
||||
sorted
|
||||
}
|
||||
|
||||
/// `object[key] = value` on an object JavaScript holds: an existing key keeps its place, a new
|
||||
/// array index key goes among the leading index keys in ascending order, any other key last.
|
||||
pub fn js_insert(map: &mut Map<String, Value>, key: &str, value: Value) {
|
||||
if map.contains_key(key) {
|
||||
map.insert(key.to_owned(), value);
|
||||
return;
|
||||
}
|
||||
let Some(index) = array_index(key) else {
|
||||
map.insert(key.to_owned(), value);
|
||||
return;
|
||||
};
|
||||
let position = map
|
||||
.keys()
|
||||
.take_while(|k| array_index(k).is_some_and(|other| other < index))
|
||||
.count();
|
||||
map.shift_insert(position, key.to_owned(), value);
|
||||
}
|
||||
|
||||
/// What `JSON.parse` makes of a parsed value: every object in `Object.keys` order (array index
|
||||
/// keys first), every integer beyond 2^53 rounded to the nearest double, as a JavaScript number
|
||||
/// holds it. Recursion bounded by the parser's depth limit (128).
|
||||
pub fn js_normalize(value: &mut Value) {
|
||||
match value {
|
||||
Value::Object(map) => {
|
||||
let ordered = js_object(std::mem::take(map));
|
||||
*map = ordered;
|
||||
map.values_mut().for_each(js_normalize);
|
||||
}
|
||||
Value::Array(items) => items.iter_mut().for_each(js_normalize),
|
||||
Value::Number(number) if !number.is_f64() => {
|
||||
let exact = number
|
||||
.as_i64()
|
||||
.map(i128::from)
|
||||
.or_else(|| number.as_u64().map(i128::from));
|
||||
if exact.is_some_and(|n| n.unsigned_abs() > 1u128 << 53)
|
||||
&& let Some(rounded) = number.as_f64().and_then(serde_json::Number::from_f64)
|
||||
{
|
||||
*number = rounded;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// `Math.round`: the nearest integer, a half rounding toward +∞; −0 for −0 and for values in
|
||||
/// [−0.5, 0).
|
||||
pub fn js_round(value: f64) -> f64 {
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
@@ -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_file":{"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"}]},"cases":[{"name":"set-fields","changes_file":{"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_range","value":{"min":6,"max":8}},{"op":"set","target":"document","field":"name.en","value":"Mini sheet"},{"op":"set","target":"document","field":"scope_disclaimer.fr","value":"Périmètre"},{"op":"set","target":"annotation:hip","field":"geometry","value":{"type":"circle","cx":1.5,"cy":2,"r":0.25}},{"op":"set","target":"annotation:neck","field":"color","value":"#aabbcc"},{"op":"set","target":"finding:hip/hip-dysfunctions/mobility/flexion","field":"description.en","value":"Flexion described"},{"op":"set","target":"finding:hip/anamnesis","field":"name.fr","value":"Anamnèse complète"},{"op":"set","target":"zone:neck","field":"name","value":{"fr":"Encolure","en":"Neck"}},{"op":"set","target":"view:head","field":"name.en","value":"Skull"},{"op":"set","target":"category:bones","field":"color","value":"#112233"},{"op":"set","target":"reference:paper","field":"doi","value":"10.1/y"},{"op":"set","target":"finding:hip/hip-dysfunctions/mobility/flexion","field":"review_status","value":"reviewed"}]}]},"ok":true,"document":"{\n \"schema_version\": 2,\n \"species_id\": \"equine\",\n \"name\": {\n \"fr\": \"Mini\",\n \"en\": \"Mini sheet\"\n },\n \"description\": {},\n \"scope_disclaimer\": {\n \"fr\": \"Périmètre\"\n },\n \"attribution\": {\n \"authors\": [],\n \"license\": null,\n \"notes\": null\n },\n \"vertebral_config\": {\n \"regions\": [\n {\n \"code\": \"C\",\n \"name\": {\n \"fr\": \"Cervicales\",\n \"en\": \"Cervical\"\n },\n \"count\": 7,\n \"count_range\": {\n \"min\": 6,\n \"max\": 8\n }\n },\n {\n \"code\": \"T\",\n \"name\": {\n \"fr\": \"Thoraciques\",\n \"en\": \"Thoracic\"\n },\n \"count\": 18\n }\n ]\n },\n \"references\": [\n {\n \"id\": \"atlas\",\n \"type\": \"book\",\n \"citation\": \"Atlas of anatomy\",\n \"url\": null,\n \"doi\": null\n },\n {\n \"id\": \"paper\",\n \"type\": \"journal\",\n \"citation\": \"A paper\",\n \"url\": null,\n \"doi\": \"10.1/y\"\n }\n ],\n \"categories\": [\n {\n \"id\": \"joints\",\n \"name\": {\n Line 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_file":{"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"}]},"cases":[{"name":"set-fields","changes_file":{"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_range","value":{"min":6,"max":8}},{"op":"set","target":"document","field":"name.en","value":"Mini sheet"},{"op":"set","target":"document","field":"scope_disclaimer.fr","value":"Périmètre"},{"op":"set","target":"annotation:hip","field":"geometry","value":{"type":"circle","cx":1.5,"cy":2,"r":0.25}},{"op":"set","target":"annotation:neck","field":"color","value":"#aabbcc"},{"op":"set","target":"finding:hip/hip-dysfunctions/mobility/flexion","field":"description.en","value":"Flexion described"},{"op":"set","target":"finding:hip/anamnesis","field":"name.fr","value":"Anamnèse complète"},{"op":"set","target":"zone:neck","field":"name","value":{"fr":"Encolure","en":"Neck"}},{"op":"set","target":"view:head","field":"name.en","value":"Skull"},{"op":"set","target":"category:bones","field":"color","value":"#112233"},{"op":"set","target":"reference:paper","field":"doi","value":"10.1/y"},{"op":"set","target":"finding:hip/hip-dysfunctions/mobility/flexion","field":"review_status","value":"reviewed"}]}]},"ok":true,"document":"{\n \"schema_version\": 2,\n \"species_id\": \"equine\",\n \"name\": {\n \"fr\": \"Mini\",\n \"en\": \"Mini sheet\"\n },\n \"description\": {},\n \"scope_disclaimer\": {\n \"fr\": \"Périmètre\"\n },\n \"attribution\": {\n \"authors\": [],\n \"license\": null,\n \"notes\": null\n },\n \"vertebral_config\": {\n \"regions\": [\n {\n \"code\": \"C\",\n \"name\": {\n \"fr\": \"Cervicales\",\n \"en\": \"Cervical\"\n },\n \"count\": 7,\n \"count_range\": {\n \"min\": 6,\n \"max\": 8\n }\n },\n {\n \"code\": \"T\",\n \"name\": {\n \"fr\": \"Thoraciques\",\n \"en\": \"Thoracic\"\n },\n \"count\": 18\n }\n ]\n },\n \"references\": [\n {\n \"id\": \"atlas\",\n \"type\": \"book\",\n \"citation\": \"Atlas of anatomy\",\n \"url\": null,\n \"doi\": null\n },\n {\n \"id\": \"paper\",\n \"type\": \"journal\",\n \"citation\": \"A paper\",\n \"url\": null,\n \"doi\": \"10.1/y\"\n }\n ],\n \"categories\": [\n {\n \"id\": \"joints\",\n \"name\": {\n Line truncated
|
||||
@@ -505,6 +505,65 @@ const ACCEPTED: Case[] = [
|
||||
{ op: 'remove', target: `${MOBILITY}/n1` },
|
||||
]),
|
||||
},
|
||||
{
|
||||
// JSON.parse semantics on authored values (final R5.3 gates): array index keys first.
|
||||
name: 'js-index-key-in-value-overwritten',
|
||||
changes_file: one([
|
||||
{
|
||||
op: 'set',
|
||||
target: MOBILITY,
|
||||
field: 'name',
|
||||
value: { fr: 'A', en: 'B', 1: 'x' },
|
||||
},
|
||||
{
|
||||
op: 'set',
|
||||
target: MOBILITY,
|
||||
field: 'name',
|
||||
value: { fr: 'Mobilité', en: 'Mobility' },
|
||||
},
|
||||
]),
|
||||
},
|
||||
{
|
||||
name: 'js-index-segment-overwritten',
|
||||
changes_file: one([
|
||||
{ op: 'set', target: MOBILITY, field: 'name.0', value: 'x' },
|
||||
{
|
||||
op: 'set',
|
||||
target: MOBILITY,
|
||||
field: 'name',
|
||||
value: { fr: 'Mobilité', en: 'Mobility' },
|
||||
},
|
||||
]),
|
||||
},
|
||||
{
|
||||
// An integer beyond 2^53, rounded by JSON.parse (written as a raw changes.json text).
|
||||
name: 'js-big-integer-in-value-overwritten',
|
||||
changes_file: one([
|
||||
{
|
||||
op: 'set',
|
||||
target: 'region:C',
|
||||
field: 'count',
|
||||
value: 9007199254740992,
|
||||
},
|
||||
{ op: 'set', target: 'region:C', field: 'count', value: 7 },
|
||||
]),
|
||||
},
|
||||
{
|
||||
// The TypeScript replaced the non-list `children` by [] (childrenOf); the port refuses it.
|
||||
name: 'declared-children-object-then-added-to',
|
||||
changes_file: one([
|
||||
{
|
||||
op: 'add',
|
||||
target: MOBILITY,
|
||||
value: {
|
||||
id: 'n1',
|
||||
name: { fr: 'a', en: 'b' },
|
||||
children: { x: { id: 'x', name: { fr: 'x', en: 'x' } } },
|
||||
},
|
||||
},
|
||||
{ op: 'add', target: `${MOBILITY}/n1`, value: leaf('child') },
|
||||
]),
|
||||
},
|
||||
{
|
||||
name: 'two-changes',
|
||||
changes_file: {
|
||||
|
||||
Reference in new issue
Block a user