fix(anatomy): R5.3 shapes refused as Zod did (struct as array, enum as map), reads bounded to regular files, --check never follows links, plain names in --out
This commit is contained in:
1 parent
314cf04e6a
commit
776c7095b3
9 files changed
+258
-25
No files matched your search
@@ -57,8 +57,21 @@ struct Folder {
|
||||
files: Vec<FolderFile>,
|
||||
}
|
||||
|
||||
/// A bound no source or generated file approaches (the largest, the draft CHANGELOG, is about
|
||||
/// 1.1 MB): a resource cap on what the tool reads.
|
||||
const MAX_FILE_BYTES: u64 = 16 * 1024 * 1024;
|
||||
|
||||
/// A regular file of the seed (never a symbolic link, a device or a pipe), read under the cap.
|
||||
fn read(path: &Path) -> Result<Vec<u8>, String> {
|
||||
fs::read(path).map_err(|error| format!("{}: {error}", path.display()))
|
||||
let refuse = |why: &str| format!("{}: {why}", path.display());
|
||||
let metadata = fs::symlink_metadata(path).map_err(|error| refuse(&error.to_string()))?;
|
||||
if !metadata.file_type().is_file() {
|
||||
return Err(refuse("not a regular file"));
|
||||
}
|
||||
if metadata.len() > MAX_FILE_BYTES {
|
||||
return Err(refuse(&format!("larger than {MAX_FILE_BYTES} bytes")));
|
||||
}
|
||||
fs::read(path).map_err(|error| refuse(&error.to_string()))
|
||||
}
|
||||
|
||||
/// `readFile(path, 'utf8')`: invalid UTF-8 becomes U+FFFD, as the TypeScript read the
|
||||
@@ -145,7 +158,9 @@ fn listed(dir: &Path, prefix: &str, out: &mut Vec<String>) -> Result<(), String>
|
||||
for entry in entries {
|
||||
let entry = entry.map_err(|error| error.to_string())?;
|
||||
let name = format!("{prefix}{}", entry.file_name().to_string_lossy());
|
||||
if entry.path().is_dir() {
|
||||
// `file_type` does not follow a symbolic link: a link is listed, never walked into.
|
||||
let is_dir = entry.file_type().is_ok_and(|kind| kind.is_dir());
|
||||
if is_dir {
|
||||
listed(&entry.path(), &format!("{name}/"), out)?;
|
||||
} else {
|
||||
out.push(name);
|
||||
@@ -160,7 +175,7 @@ fn check(folder: &Folder) -> Result<Vec<String>, String> {
|
||||
let target = Path::new(SEED).join(folder.name);
|
||||
let mut problems = Vec::new();
|
||||
for (name, bytes) in &folder.files {
|
||||
match fs::read(target.join(name)) {
|
||||
match read(&target.join(name)) {
|
||||
Ok(committed) if committed == *bytes => {}
|
||||
Ok(_) => problems.push(format!("{}: differs: {name}", folder.name)),
|
||||
Err(_) => problems.push(format!("{}: missing: {name}", folder.name)),
|
||||
@@ -205,7 +220,7 @@ fn claim_destination(typed: &Path) -> Result<PathBuf, String> {
|
||||
None => return Err(refuse("not a destination folder")),
|
||||
};
|
||||
let seed = fs::canonicalize(SEED).map_err(|error| format!("{SEED}: {error}"))?;
|
||||
if parent.starts_with(&seed) {
|
||||
if inside(&parent, &seed) {
|
||||
return Err(refuse("inside the seed folder"));
|
||||
}
|
||||
let name = out
|
||||
@@ -227,6 +242,11 @@ fn claim_destination(typed: &Path) -> Result<PathBuf, String> {
|
||||
Ok(root)
|
||||
}
|
||||
|
||||
/// Whether a canonical folder is the seed folder or lies under it.
|
||||
fn inside(folder: &Path, seed: &Path) -> bool {
|
||||
folder.starts_with(seed)
|
||||
}
|
||||
|
||||
/// 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).
|
||||
@@ -242,8 +262,18 @@ fn base_dir() -> PathBuf {
|
||||
/// appeared since the claim, file, folder or symbolic link, is refused, never followed or
|
||||
/// truncated (`create_dir`, `create_new`).
|
||||
fn write_exclusive(root: &Path, relative: &Path, bytes: &[u8]) -> Result<(), String> {
|
||||
// The claimed folder is checked again: a swap for a symbolic link since the claim is refused.
|
||||
if !fs::symlink_metadata(root).is_ok_and(|m| m.file_type().is_dir()) {
|
||||
return Err(format!("{}: no longer the claimed folder", root.display()));
|
||||
}
|
||||
let mut folder = root.to_path_buf();
|
||||
let components: Vec<_> = relative.components().collect();
|
||||
if !components.iter().all(|c| matches!(c, Component::Normal(_))) {
|
||||
return Err(format!(
|
||||
"{}: not a plain relative file name",
|
||||
relative.display()
|
||||
));
|
||||
}
|
||||
let (file, folders) = components.split_last().ok_or("an empty file name")?;
|
||||
for component in folders {
|
||||
folder.push(component);
|
||||
@@ -327,3 +357,25 @@ fn main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_folder_under_the_seed_or_the_seed_itself_is_inside_it() {
|
||||
let seed = Path::new("/repo/supabase/seed/anatomical-sheets/equine");
|
||||
assert!(inside(seed, seed));
|
||||
assert!(inside(&seed.join("draft"), seed));
|
||||
assert!(inside(&seed.join("x/y"), seed));
|
||||
assert!(!inside(
|
||||
Path::new("/repo/supabase/seed/anatomical-sheets"),
|
||||
seed
|
||||
));
|
||||
assert!(!inside(
|
||||
Path::new("/repo/supabase/seed/anatomical-sheets/equine-copy"),
|
||||
seed
|
||||
));
|
||||
assert!(!inside(Path::new("/tmp/out"), seed));
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ use serde_json::Value;
|
||||
use super::ops::{apply_op, assert_declared};
|
||||
use super::records::{ChangeRecord, CurationResult, Recorder, strip_marks, touch_order};
|
||||
use super::schema::{Change, ChangeSummary, Op, SetOp};
|
||||
use super::shape::assert_same_shape;
|
||||
use super::targets::{
|
||||
Path, Step, TargetKind, all_findings, at, fail, item_at_mut, list_at, top_collection_path,
|
||||
};
|
||||
@@ -159,6 +160,7 @@ fn describe(issues: &[SheetIssue]) -> String {
|
||||
pub fn curated_issues(doc: &Value) -> Result<Vec<SheetIssue>, PipelineError> {
|
||||
let parsed: AnatomicalSheetDocument = serde_json::from_value(doc.clone())
|
||||
.map_err(|error| fail(format!("curated document is not shape-valid: {error}")))?;
|
||||
assert_same_shape("curated document is not shape-valid", doc, &parsed)?;
|
||||
let issues = validate_sheet_document(&parsed);
|
||||
let errors: Vec<SheetIssue> = issues
|
||||
.iter()
|
||||
|
||||
@@ -13,6 +13,7 @@ pub mod records;
|
||||
pub mod rename;
|
||||
pub mod schema;
|
||||
pub mod seed;
|
||||
pub mod shape;
|
||||
pub mod stats;
|
||||
pub mod targets;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
use super::shape::assert_same_shape;
|
||||
use crate::curation::PipelineError;
|
||||
use crate::domain::js;
|
||||
use crate::domain::sheet::Reference;
|
||||
@@ -246,7 +247,7 @@ pub struct ChangeSummary {
|
||||
}
|
||||
|
||||
/// One authored change: `ChangeSchema` (strict, `priority` defaulted, `ops` non-empty).
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Change {
|
||||
#[serde(deserialize_with = "change_id")]
|
||||
@@ -258,7 +259,11 @@ pub struct Change {
|
||||
pub rationale: String,
|
||||
#[serde(deserialize_with = "non_empty_strings")]
|
||||
pub reference_ids: Vec<String>,
|
||||
#[serde(default, deserialize_with = "optional_non_empty")]
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "optional_non_empty",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
pub question: Option<String>,
|
||||
#[serde(default = "default_priority")]
|
||||
pub priority: ChangePriority,
|
||||
@@ -286,13 +291,13 @@ impl Change {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Changeset {
|
||||
pub changes: Vec<Change>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct ReferencesFile {
|
||||
references: Vec<Reference>,
|
||||
@@ -407,7 +412,8 @@ pub fn parse_changeset(text: &str) -> Result<Changeset, PipelineError> {
|
||||
return Err(refuse("changes.json", format!("reserved key {key:?}")));
|
||||
}
|
||||
let changeset: Changeset =
|
||||
serde_json::from_value(value).map_err(|e| refuse("changes.json", e))?;
|
||||
serde_json::from_value(value.clone()).map_err(|e| refuse("changes.json", e))?;
|
||||
assert_same_shape("changes.json", &value, &changeset)?;
|
||||
for change in &changeset.changes {
|
||||
if change.level == ChangeLevel::C && change.question.is_none() {
|
||||
return Err(refuse(
|
||||
@@ -427,7 +433,8 @@ pub fn parse_changeset(text: &str) -> Result<Changeset, PipelineError> {
|
||||
pub fn parse_references(text: &str) -> Result<Vec<Reference>, PipelineError> {
|
||||
let value = json_parse("references.json", text)?;
|
||||
let file: ReferencesFile =
|
||||
serde_json::from_value(value).map_err(|e| refuse("references.json", e))?;
|
||||
serde_json::from_value(value.clone()).map_err(|e| refuse("references.json", e))?;
|
||||
assert_same_shape("references.json", &value, &file)?;
|
||||
let ids = file
|
||||
.references
|
||||
.iter()
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
//! The JSON shapes Zod refused and serde's derives accept. serde reads a struct from a
|
||||
//! positional array (`"title": ["Titre", "Title"]`) and a unit enum variant from a one-key map
|
||||
//! (`"level": {"A": null}`); Zod refused both (`invalid_type`). The authored files and the
|
||||
//! curated document are therefore compared, by shape, with the typed value serialised back:
|
||||
//! an object must stay an object, an array an array of the same length, a scalar a scalar of
|
||||
//! the same kind. Keys the typed value adds (defaults filled in) are allowed.
|
||||
//!
|
||||
//! The R2 contracts carry the same derives; their readers are outside R5.3 (owner's go).
|
||||
|
||||
use serde::Serialize;
|
||||
use serde_json::Value;
|
||||
|
||||
use super::targets::fail;
|
||||
use crate::curation::PipelineError;
|
||||
|
||||
fn kind(value: &Value) -> &'static str {
|
||||
match value {
|
||||
Value::Null => "null",
|
||||
Value::Bool(_) => "a boolean",
|
||||
Value::Number(_) => "a number",
|
||||
Value::String(_) => "a string",
|
||||
Value::Array(_) => "an array",
|
||||
Value::Object(_) => "an object",
|
||||
}
|
||||
}
|
||||
|
||||
fn mismatch(path: &str, typed: &Value, written: &Value) -> String {
|
||||
let at = if path.is_empty() { "the root" } else { path };
|
||||
format!(
|
||||
"expected {} at {at}, received {}",
|
||||
kind(typed),
|
||||
kind(written)
|
||||
)
|
||||
}
|
||||
|
||||
/// The first place where `written` (as parsed) and `typed` (read and serialised back) differ
|
||||
/// in shape.
|
||||
fn first_mismatch(written: &Value, typed: &Value, path: &str) -> Option<String> {
|
||||
match (written, typed) {
|
||||
(Value::Object(w), Value::Object(t)) => w.iter().find_map(|(key, value)| {
|
||||
let here = format!("{path}.{key}");
|
||||
match t.get(key) {
|
||||
Some(typed) => first_mismatch(value, typed, &here),
|
||||
None => Some(format!("unexpected key at {here}")),
|
||||
}
|
||||
}),
|
||||
(Value::Array(w), Value::Array(t)) if w.len() == t.len() => w
|
||||
.iter()
|
||||
.zip(t)
|
||||
.enumerate()
|
||||
.find_map(|(index, (w, t))| first_mismatch(w, t, &format!("{path}.{index}"))),
|
||||
_ if std::mem::discriminant(written) == std::mem::discriminant(typed) => None,
|
||||
_ => Some(mismatch(path, typed, written)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Refuses `written` when its typed reading `typed` does not keep its shape.
|
||||
pub fn assert_same_shape<T: Serialize>(
|
||||
what: &str,
|
||||
written: &Value,
|
||||
typed: &T,
|
||||
) -> Result<(), PipelineError> {
|
||||
let typed = serde_json::to_value(typed).map_err(|error| fail(format!("{what}: {error}")))?;
|
||||
match first_mismatch(written, &typed, "") {
|
||||
None => Ok(()),
|
||||
Some(why) => Err(fail(format!("{what}: {why}"))),
|
||||
}
|
||||
}
|
||||
@@ -190,9 +190,11 @@ pub fn at_mut<'a>(doc: &'a mut Value, path: &[Step]) -> Result<&'a mut Value, Pi
|
||||
/// `listAt`: the array at a path, or "document has no list".
|
||||
pub fn list_at<'a>(doc: &'a Value, path: &[Step]) -> Result<&'a Vec<Value>, PipelineError> {
|
||||
let last = path.last().map(describe).unwrap_or_default();
|
||||
at(doc, path)?
|
||||
let no_list = || fail(format!("document has no list \"{last}\""));
|
||||
at(doc, path)
|
||||
.map_err(|_| no_list())?
|
||||
.as_array()
|
||||
.ok_or_else(|| fail(format!("document has no list \"{last}\"")))
|
||||
.ok_or_else(no_list)
|
||||
}
|
||||
|
||||
pub fn list_at_mut<'a>(
|
||||
@@ -200,9 +202,11 @@ pub fn list_at_mut<'a>(
|
||||
path: &[Step],
|
||||
) -> Result<&'a mut Vec<Value>, PipelineError> {
|
||||
let last = path.last().map(describe).unwrap_or_default();
|
||||
at_mut(doc, path)?
|
||||
let no_list = || fail(format!("document has no list \"{last}\""));
|
||||
at_mut(doc, path)
|
||||
.map_err(|_| no_list())?
|
||||
.as_array_mut()
|
||||
.ok_or_else(|| fail(format!("document has no list \"{last}\"")))
|
||||
.ok_or_else(no_list)
|
||||
}
|
||||
|
||||
pub fn item_at<'a>(doc: &'a Value, path: &[Step]) -> Result<&'a Item, PipelineError> {
|
||||
|
||||
@@ -422,9 +422,9 @@ fn the_synthetic_cases_match_the_typescript_or_are_refused_alike() {
|
||||
"{name} seed"
|
||||
);
|
||||
}
|
||||
assert_eq!((compared, refused), (11, 52));
|
||||
assert_eq!((compared, refused), (11, 62));
|
||||
let reference_cases = frozen["reference_cases"].as_array().unwrap();
|
||||
assert_eq!(reference_cases.len(), 5);
|
||||
assert_eq!(reference_cases.len(), 7);
|
||||
for case in reference_cases {
|
||||
let name = case["name"].as_str().unwrap();
|
||||
let outcome = parse_references(&to_js_compact(&case["file"]).unwrap());
|
||||
@@ -657,7 +657,8 @@ fn import_equine(args: &[&str]) -> (i32, String) {
|
||||
}
|
||||
|
||||
/// Fixed fixtures under the test target's temporary folder: created once, never deleted, and
|
||||
/// never written by the refusals checked here.
|
||||
/// never written by the refusals checked here. The seed refusal is tested on the pure check
|
||||
/// (`inside`, unit test of the binary): a regression must never write into the real seed.
|
||||
fn out_fixtures() -> std::path::PathBuf {
|
||||
let base = std::path::Path::new(env!("CARGO_TARGET_TMPDIR")).join("import-equine-out");
|
||||
for folder in ["empty", "full"] {
|
||||
@@ -676,11 +677,6 @@ fn out_fixtures() -> std::path::PathBuf {
|
||||
fn out_refuses_every_unsafe_destination_and_writes_nothing() {
|
||||
let base = out_fixtures();
|
||||
let at = |rest: &str| format!("{}/{rest}", base.display());
|
||||
let seed = std::fs::canonicalize(common::repo_path("supabase/seed/anatomical-sheets/equine"))
|
||||
.unwrap()
|
||||
.join("new-folder")
|
||||
.display()
|
||||
.to_string();
|
||||
let cases = [
|
||||
(at("link"), "a symbolic link"),
|
||||
(at("link/"), "a symbolic link"),
|
||||
@@ -689,7 +685,6 @@ fn out_refuses_every_unsafe_destination_and_writes_nothing() {
|
||||
(at("full"), "not empty"),
|
||||
(at("empty/../new"), "`..` is not accepted"),
|
||||
(at("absent/new"), "the parent folder does not exist"),
|
||||
(seed.clone(), "inside the seed folder"),
|
||||
];
|
||||
for (path, why) in &cases {
|
||||
let (code, stderr) = import_equine(&["--out", path]);
|
||||
@@ -698,6 +693,5 @@ fn out_refuses_every_unsafe_destination_and_writes_nothing() {
|
||||
}
|
||||
assert_eq!(std::fs::read_dir(base.join("empty")).unwrap().count(), 0);
|
||||
assert_eq!(std::fs::read_dir(base.join("full")).unwrap().count(), 1);
|
||||
assert!(std::fs::symlink_metadata(&seed).is_err());
|
||||
assert!(std::fs::symlink_metadata(base.join("absent")).is_err());
|
||||
}
|
||||
@@ -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
|
||||
@@ -523,6 +523,103 @@ const ACCEPTED: Case[] = [
|
||||
]
|
||||
|
||||
const REFUSED: Case[] = [
|
||||
// serde's derives read a struct from an array and a unit variant from a one-key map; Zod
|
||||
// refused both (final R5.3 gates, 2026-10-23).
|
||||
{
|
||||
name: 'shape-title-as-array',
|
||||
changes_file: one([{ op: 'remove', target: `${MOBILITY}/flexion` }], {
|
||||
title: ['Essai', 'Test'],
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: 'shape-level-as-map',
|
||||
changes_file: one([{ op: 'remove', target: `${MOBILITY}/flexion` }], {
|
||||
level: { A: null },
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: 'shape-change-as-array',
|
||||
changes_file: {
|
||||
changes: [
|
||||
[
|
||||
'CHG-001',
|
||||
'A',
|
||||
'technical',
|
||||
{ fr: 'a', en: 'a' },
|
||||
'r',
|
||||
[],
|
||||
[{ op: 'remove', target: `${MOBILITY}/flexion` }],
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'shape-scope-as-map',
|
||||
changes_file: one([
|
||||
{
|
||||
op: 'cite',
|
||||
target: MOBILITY,
|
||||
reference_ids: ['atlas'],
|
||||
scope: { subtree: null },
|
||||
},
|
||||
]),
|
||||
},
|
||||
{
|
||||
name: 'shape-gate-name-as-array',
|
||||
changes_file: one([
|
||||
{ op: 'set', target: MOBILITY, field: 'name', value: ['a', 'b'] },
|
||||
]),
|
||||
},
|
||||
{
|
||||
name: 'shape-gate-status-as-map',
|
||||
changes_file: one([
|
||||
{
|
||||
op: 'set',
|
||||
target: MOBILITY,
|
||||
field: 'review_status',
|
||||
value: { reviewed: null },
|
||||
},
|
||||
]),
|
||||
},
|
||||
{
|
||||
name: 'shape-gate-laterality-as-map',
|
||||
changes_file: one([
|
||||
{
|
||||
op: 'set',
|
||||
target: 'annotation:hip',
|
||||
field: 'laterality',
|
||||
value: { bilateral: null },
|
||||
},
|
||||
]),
|
||||
},
|
||||
{
|
||||
name: 'shape-gate-view-box-as-array',
|
||||
changes_file: one([
|
||||
{
|
||||
op: 'set',
|
||||
target: 'view:head',
|
||||
field: 'view_box',
|
||||
value: [0, 0, 5, 5],
|
||||
},
|
||||
]),
|
||||
},
|
||||
{
|
||||
name: 'shape-gate-geometry-as-array',
|
||||
changes_file: one([
|
||||
{
|
||||
op: 'set',
|
||||
target: 'annotation:hip',
|
||||
field: 'geometry',
|
||||
value: ['circle', 1, 2, 3],
|
||||
},
|
||||
]),
|
||||
},
|
||||
{
|
||||
name: 'shape-gate-added-node-name-as-array',
|
||||
changes_file: one([
|
||||
{ op: 'add', target: MOBILITY, value: { id: 'x', name: ['a', 'a'] } },
|
||||
]),
|
||||
},
|
||||
{
|
||||
// TypeScript: readField returns the inherited Object.prototype.constructor, record's
|
||||
// structuredClone throws DataCloneError. The Rust port reads a plain missing key
|
||||
@@ -859,6 +956,14 @@ const REFUSED: Case[] = [
|
||||
]
|
||||
|
||||
const REFERENCE_FILES: Array<{ name: string; file: unknown }> = [
|
||||
{
|
||||
name: 'references-entry-as-array',
|
||||
file: { references: [['atlas', 'book', 'Atlas', null, null]] },
|
||||
},
|
||||
{
|
||||
name: 'references-type-as-map',
|
||||
file: { references: [{ ...MINI_REFERENCES[0], type: { book: null } }] },
|
||||
},
|
||||
{
|
||||
name: 'references-duplicate-id',
|
||||
file: { references: [...MINI_REFERENCES, MINI_REFERENCES[0]] },
|
||||
|
||||
Reference in new issue
Block a user