test(domain): R5.7 port the contracts only the TS suites checked
612 leaves and 26 legacy ids (curation_leaves), region inference, R5.1 ledger rows, generated folder lists, migration-map oracle entry by entry, overlay removal, halo filter, CHG-000 and dollar-tag refusals; report-v2 fixtures moved to crates/core/tests (sha256 unchanged).
This commit is contained in:
1 parent
756b7ef34d
commit
0da7d3ab9f
11 files changed
+634
-11
No files matched your search
@@ -154,3 +154,27 @@ fn a_label_xml_cannot_carry_is_refused_never_replaced() {
|
|||||||
}
|
}
|
||||||
assert!(compose_canvas(&draft, "main", &horse).is_err());
|
assert!(compose_canvas(&draft, "main", &horse).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn count(element: &Element, matches: &dyn Fn(&Element) -> bool) -> usize {
|
||||||
|
usize::from(matches(element))
|
||||||
|
+ element
|
||||||
|
.element_children()
|
||||||
|
.map(|c| count(c, matches))
|
||||||
|
.sum::<usize>()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `render.compose.test.ts` "never duplicates the filter on a root that already holds it"
|
||||||
|
/// (R5.7): composing a drawing that already carries the halo filter adds no second filter and no
|
||||||
|
/// second `<defs>` (the TypeScript composed twice on one DOM root; the core takes the root it
|
||||||
|
/// returned).
|
||||||
|
#[test]
|
||||||
|
fn the_halo_filter_is_never_duplicated_on_a_root_that_holds_it() {
|
||||||
|
let draft = draft();
|
||||||
|
let ids: HashSet<&str> = ["hip"].into_iter().collect();
|
||||||
|
let horse = sanitized(&common::repo_file(HORSE));
|
||||||
|
let once = compose_highlight(&draft, "main", horse, &ids, true).unwrap();
|
||||||
|
let twice = compose_highlight(&draft, "main", once, &ids, true).unwrap();
|
||||||
|
let halo = |e: &Element| e.qname == "filter" && e.attr("id") == Some("osteo-halo");
|
||||||
|
assert_eq!(count(&twice, &halo), 1);
|
||||||
|
assert_eq!(count(&twice, &|e: &Element| e.qname == "defs"), 1);
|
||||||
|
}
|
||||||
@@ -201,7 +201,7 @@ fn slice_snapshot() -> Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn draft_full_report(draft: &LoadedSheet) -> Report {
|
fn draft_full_report(draft: &LoadedSheet) -> Report {
|
||||||
let full = json_file("packages/domain/tests/fixtures/report-v2.full.json");
|
let full = json_file("crates/core/tests/fixtures/report-v2.full.json");
|
||||||
read_report_document(&full, &draft.migration_map)
|
read_report_document(&full, &draft.migration_map)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.report
|
.report
|
||||||
@@ -599,9 +599,7 @@ fn envelope_reads_a_bare_v3_as_is() {
|
|||||||
fn envelope_migrates_a_bare_v2_with_the_counts_of_the_migration() {
|
fn envelope_migrates_a_bare_v2_with_the_counts_of_the_migration() {
|
||||||
let f = EnvelopeFixture::new();
|
let f = EnvelopeFixture::new();
|
||||||
let outcome = f
|
let outcome = f
|
||||||
.read(&json_file(
|
.read(&json_file("crates/core/tests/fixtures/report-v2.full.json"))
|
||||||
"packages/domain/tests/fixtures/report-v2.full.json",
|
|
||||||
))
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(outcome.origin, ArchiveOrigin::V2);
|
assert_eq!(outcome.origin, ArchiveOrigin::V2);
|
||||||
assert!(outcome.migrated && outcome.archive.is_none() && outcome.snapshot_rejected.is_none());
|
assert!(outcome.migrated && outcome.archive.is_none() && outcome.snapshot_rejected.is_none());
|
||||||
@@ -798,7 +796,7 @@ fn envelope_migrates_a_wrapped_v2_report_and_still_checks_the_snapshot() {
|
|||||||
let env = with(
|
let env = with(
|
||||||
f.envelope(),
|
f.envelope(),
|
||||||
"report",
|
"report",
|
||||||
json_file("packages/domain/tests/fixtures/report-v2.full.json"),
|
json_file("crates/core/tests/fixtures/report-v2.full.json"),
|
||||||
);
|
);
|
||||||
let outcome = f.read(&env).unwrap();
|
let outcome = f.read(&env).unwrap();
|
||||||
assert_eq!(outcome.origin, ArchiveOrigin::EnvelopeV1);
|
assert_eq!(outcome.origin, ArchiveOrigin::EnvelopeV1);
|
||||||
@@ -817,7 +815,7 @@ fn restore_reads_a_draft_and_keeps_it_when_it_sits_on_the_loaded_sheet() {
|
|||||||
let restored = restore_draft(&f.draft, &text, None).unwrap();
|
let restored = restore_draft(&f.draft, &text, None).unwrap();
|
||||||
assert_eq!(restored.rebase.report, f.report);
|
assert_eq!(restored.rebase.report, f.report);
|
||||||
assert!(!restored.rebase.rebased && restored.archive.is_none() && !restored.archive_rejected);
|
assert!(!restored.rebase.rebased && restored.archive.is_none() && !restored.archive_rejected);
|
||||||
let v2 = common::repo_file("packages/domain/tests/fixtures/report-v2.full.json");
|
let v2 = common::repo_file("crates/core/tests/fixtures/report-v2.full.json");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
restore_draft(&f.draft, &v2, None).unwrap().rebase.report,
|
restore_draft(&f.draft, &v2, None).unwrap().rebase.report,
|
||||||
f.report
|
f.report
|
||||||
@@ -908,7 +906,7 @@ fn a_draft_with_a_lone_surrogate_is_refused_as_content_never_rewritten() {
|
|||||||
"{escape}"
|
"{escape}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let v2 = common::repo_file("packages/domain/tests/fixtures/report-v2.full.json").replace(
|
let v2 = common::repo_file("crates/core/tests/fixtures/report-v2.full.json").replace(
|
||||||
"\"comment\": \"Réagit à la palpation du garrot.\"",
|
"\"comment\": \"Réagit à la palpation du garrot.\"",
|
||||||
"\"comment\": \"Réagit \\udc00\"",
|
"\"comment\": \"Réagit \\udc00\"",
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -78,8 +78,9 @@ pub fn draft_map() -> ReportMigrationMap {
|
|||||||
from(json_file(&format!("{DRAFT_DIR}/report-migration-map.json")))
|
from(json_file(&format!("{DRAFT_DIR}/report-migration-map.json")))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The horse slice of `packages/domain/tests/fixtures/horse-slice.ts`, as Zod parsed it (the
|
/// The horse slice of `packages/domain/tests/fixtures/horse-slice.ts` (deleted at R5.7, kept at
|
||||||
/// characterisation oracle carries it, written by the TypeScript generator).
|
/// 756b7ef), as Zod parsed it (the characterisation oracle carries it, written by the TypeScript
|
||||||
|
/// generator).
|
||||||
pub fn horse_slice() -> Value {
|
pub fn horse_slice() -> Value {
|
||||||
super::common::oracle_file("characterisation.json").1["sheets"]["slice"]["document"].clone()
|
super::common::oracle_file("characterisation.json").1["sheets"]["slice"]["document"].clone()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -588,11 +588,20 @@ fn a_reserved_touch_mark_key_in_an_authored_value_is_refused() {
|
|||||||
|
|
||||||
fn mini_apply(
|
fn mini_apply(
|
||||||
ops: Value,
|
ops: Value,
|
||||||
|
) -> Result<faunosteo_core::curation::draft::records::CurationResult, String> {
|
||||||
|
mini_apply_at("B", ops)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One change of the given level on the mini sheet (`changesetOf` of the TypeScript fixtures
|
||||||
|
/// used level A: no review mark).
|
||||||
|
fn mini_apply_at(
|
||||||
|
level: &str,
|
||||||
|
ops: Value,
|
||||||
) -> Result<faunosteo_core::curation::draft::records::CurationResult, String> {
|
) -> Result<faunosteo_core::curation::draft::records::CurationResult, String> {
|
||||||
let frozen = oracle("curation-synthetic.json");
|
let frozen = oracle("curation-synthetic.json");
|
||||||
let references = parse_references(&to_js_compact(&frozen["references_file"]).unwrap()).unwrap();
|
let references = parse_references(&to_js_compact(&frozen["references_file"]).unwrap()).unwrap();
|
||||||
let file = json!({ "changes": [{
|
let file = json!({ "changes": [{
|
||||||
"id": "CHG-001", "level": "B", "kind": "technical",
|
"id": "CHG-001", "level": level, "kind": "technical",
|
||||||
"title": { "fr": "Essai", "en": "Test" }, "rationale": "Essai",
|
"title": { "fr": "Essai", "en": "Test" }, "rationale": "Essai",
|
||||||
"reference_ids": [], "ops": ops,
|
"reference_ids": [], "ops": ops,
|
||||||
}]});
|
}]});
|
||||||
@@ -954,3 +963,204 @@ fn a_proto_segment_is_refused_at_the_op() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------
|
||||||
|
// R5.7: cases of the deleted TypeScript suites that no oracle carries, ported with their exact
|
||||||
|
// expectations (`crates/core/tests/curation/LEDGER.tsv`).
|
||||||
|
|
||||||
|
/// `curation.apply.test.ts` "adds a zone, an annotation and a reference at document level": a
|
||||||
|
/// `cite` of a reference an earlier op of the same change added is accepted and recorded.
|
||||||
|
#[test]
|
||||||
|
fn a_reference_added_at_document_level_can_be_cited_by_the_same_change() {
|
||||||
|
let ops = json!([
|
||||||
|
{ "op": "add", "target": "document", "field": "finding_zones",
|
||||||
|
"value": { "id": "back", "name": { "fr": "Dos", "en": "Back" }, "categories": [] } },
|
||||||
|
{ "op": "add", "target": "document", "field": "annotations", "position": { "after": "neck" },
|
||||||
|
"value": { "id": "back", "kind": "zone", "view_id": "main", "category_id": "bones",
|
||||||
|
"laterality": "unpaired", "geometry": null, "name": { "fr": "Dos", "en": "Back" },
|
||||||
|
"finding_zone_id": "back", "vertebral_region_code": "T" } },
|
||||||
|
{ "op": "add", "target": "document", "field": "references",
|
||||||
|
"value": { "id": "book", "type": "book", "citation": "Book", "url": null, "doi": null } },
|
||||||
|
{ "op": "cite", "target": "finding:hip/anamnesis", "reference_ids": ["book"] },
|
||||||
|
]);
|
||||||
|
let result = mini_apply_at("A", ops).unwrap();
|
||||||
|
let ids: Vec<&str> = result.document["annotations"]
|
||||||
|
.as_array()
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.map(|a| a["id"].as_str().unwrap())
|
||||||
|
.collect();
|
||||||
|
assert_eq!(ids, ["hip", "neck", "back", "head-trigger"]);
|
||||||
|
let targets: Vec<&str> = result.records.iter().map(|r| r.target.as_str()).collect();
|
||||||
|
assert_eq!(
|
||||||
|
targets,
|
||||||
|
[
|
||||||
|
"zone:back",
|
||||||
|
"annotation:back",
|
||||||
|
"reference:book",
|
||||||
|
"finding:hip/anamnesis"
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `curation.assets.test.ts` "reads a viewBox into a document view_box".
|
||||||
|
#[test]
|
||||||
|
fn a_view_box_of_four_numbers_is_read_and_three_are_refused() {
|
||||||
|
let view_box = parse_view_box(Some("60 100 500 380")).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
(
|
||||||
|
view_box.min_x,
|
||||||
|
view_box.min_y,
|
||||||
|
view_box.width,
|
||||||
|
view_box.height
|
||||||
|
),
|
||||||
|
(60.0, 100.0, 500.0, 380.0)
|
||||||
|
);
|
||||||
|
let error = parse_view_box(Some("1 2 3")).unwrap_err().to_string();
|
||||||
|
assert!(error.contains("invalid viewBox"), "{error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `curation.migration-map.test.ts` "follows a rename, a move and a removal, and a renamed
|
||||||
|
/// annotation": a move addressed through a path renamed by an earlier op of the same change.
|
||||||
|
#[test]
|
||||||
|
fn the_map_follows_a_rename_then_a_move_through_the_renamed_path() {
|
||||||
|
let result = mini_apply_at("A", json!([
|
||||||
|
{ "op": "rename", "target": "finding:hip/hip-dysfunctions/mobility", "id": "motion" },
|
||||||
|
{ "op": "move", "target": "finding:hip/hip-dysfunctions/motion/flexion", "to": "finding:hip/anamnesis" },
|
||||||
|
{ "op": "remove", "target": "finding:neck/neck-dysfunctions/vet" },
|
||||||
|
{ "op": "rename", "target": "annotation:hip", "id": "coxofemoral" },
|
||||||
|
]))
|
||||||
|
.unwrap();
|
||||||
|
let baseline = oracle("curation-synthetic.json")["baseline"].clone();
|
||||||
|
let (map, stats) = synthetic_map(&baseline, &result.document, &result.records);
|
||||||
|
let paths = &map["finding_paths"];
|
||||||
|
assert_eq!(
|
||||||
|
paths["hip/hip-dysfunctions/mobility/extension"],
|
||||||
|
"hip/hip-dysfunctions/motion/extension"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
paths["hip/hip-dysfunctions/mobility/flexion"],
|
||||||
|
"hip/anamnesis/flexion"
|
||||||
|
);
|
||||||
|
assert_eq!(paths["neck/neck-dysfunctions/vet"], Value::Null);
|
||||||
|
assert_eq!(
|
||||||
|
paths["neck/neck-dysfunctions/stiffness"],
|
||||||
|
"neck/neck-dysfunctions/stiffness"
|
||||||
|
);
|
||||||
|
assert_eq!(map["annotations"]["legacy-hip"]["id"], "coxofemoral");
|
||||||
|
assert_eq!(stats["removed"], 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `curation.pipeline.test.ts` "refuses a changeset that reuses the reserved CHG-000".
|
||||||
|
#[test]
|
||||||
|
fn a_changeset_reusing_the_reserved_asset_change_id_is_refused() {
|
||||||
|
let import_result = legacy_result();
|
||||||
|
let reserved = ONE_CHANGE.replace("CHG-001", "CHG-000");
|
||||||
|
let changeset = parse_changeset(&reserved).unwrap();
|
||||||
|
let error = build_equine_draft(&DraftInput {
|
||||||
|
import_result: &import_result,
|
||||||
|
cleaned_svg: &bytes(&format!("{DRAFT}/assets/horse.svg")),
|
||||||
|
head_view_box: parse_view_box(Some("60 100 500 380")).unwrap(),
|
||||||
|
references: &[],
|
||||||
|
changes: &changeset.changes,
|
||||||
|
})
|
||||||
|
.err()
|
||||||
|
.unwrap()
|
||||||
|
.to_string();
|
||||||
|
assert!(error.contains("CHG-000 is reserved"), "{error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `importer.guards.test.ts` "refuses a document that contains the dollar-quote tag".
|
||||||
|
#[test]
|
||||||
|
fn a_document_holding_the_dollar_quote_tag_is_refused_by_the_seed() {
|
||||||
|
let document_json = to_js_compact(&json!({ "note": "$equine_doc$" })).unwrap();
|
||||||
|
let error = render_draft_seed_sql(&DraftSeedParams {
|
||||||
|
sheet_id: "11111111-1111-5111-8111-111111111111",
|
||||||
|
assets: &[],
|
||||||
|
document_json: &document_json,
|
||||||
|
change_note: "x",
|
||||||
|
})
|
||||||
|
.unwrap_err()
|
||||||
|
.to_string();
|
||||||
|
assert!(error.contains("$equine_doc$"), "{error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Every file under `dir`, relative to it, sorted.
|
||||||
|
fn files_under(dir: &str) -> Vec<String> {
|
||||||
|
fn walk(root: &std::path::Path, at: &std::path::Path, out: &mut Vec<String>) {
|
||||||
|
for entry in std::fs::read_dir(at).unwrap() {
|
||||||
|
let path = entry.unwrap().path();
|
||||||
|
if path.is_dir() {
|
||||||
|
walk(root, &path, out);
|
||||||
|
} else {
|
||||||
|
out.push(
|
||||||
|
path.strip_prefix(root)
|
||||||
|
.unwrap()
|
||||||
|
.to_string_lossy()
|
||||||
|
.into_owned(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let root = std::path::PathBuf::from(common::repo_path(dir));
|
||||||
|
let mut out = Vec::new();
|
||||||
|
walk(&root, &root, &mut out);
|
||||||
|
out.sort();
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `r5.pipeline-oracles.test.ts` "the ledger digests are the committed files": each of the 16
|
||||||
|
/// text artifacts the TypeScript recorded at R5.1 is the committed file, byte count included;
|
||||||
|
/// the two fingerprint-bearing draft files are the pre-switch copies (the switch itself is
|
||||||
|
/// `the_switch_changes_only_the_fingerprint_of_the_two_files`).
|
||||||
|
#[test]
|
||||||
|
fn every_ledger_row_of_the_r5_1_run_is_the_committed_file() {
|
||||||
|
let artifacts = oracle("pipeline.json")["artifacts"].clone();
|
||||||
|
let rows = artifacts.as_array().unwrap();
|
||||||
|
assert_eq!(rows.len(), 16);
|
||||||
|
for row in rows {
|
||||||
|
let (folder, file) = (
|
||||||
|
row["folder"].as_str().unwrap(),
|
||||||
|
row["file"].as_str().unwrap(),
|
||||||
|
);
|
||||||
|
let switched = folder.ends_with("/draft")
|
||||||
|
&& ["sheet-ref.json", "report-migration-map.json"].contains(&file);
|
||||||
|
let path = if switched {
|
||||||
|
format!("crates/core/tests/fixtures/r5-6/pre-switch/{file}")
|
||||||
|
} else {
|
||||||
|
format!("{folder}/{file}")
|
||||||
|
};
|
||||||
|
let committed = bytes(&path);
|
||||||
|
assert_eq!(row["sha256"], sha256_hex(&committed), "{folder}/{file}");
|
||||||
|
assert_eq!(row["bytes"], committed.len(), "{folder}/{file}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `seed.golden.test.ts` "holds no file the run does not produce" and the legacy folder's "no
|
||||||
|
/// SQL": the two generated folders hold exactly the ledger's files plus the byte copies.
|
||||||
|
#[test]
|
||||||
|
fn the_generated_folders_hold_exactly_the_files_the_pipeline_writes() {
|
||||||
|
let artifacts = oracle("pipeline.json")["artifacts"].clone();
|
||||||
|
let listed = |suffix: &str| -> Vec<String> {
|
||||||
|
artifacts
|
||||||
|
.as_array()
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.filter(|row| row["folder"].as_str().unwrap().ends_with(suffix))
|
||||||
|
.map(|row| row["file"].as_str().unwrap().to_owned())
|
||||||
|
.collect()
|
||||||
|
};
|
||||||
|
let mut legacy = listed("/legacy-import");
|
||||||
|
legacy.extend([
|
||||||
|
"assets/Horse.svg".to_owned(),
|
||||||
|
"assets/Horse_head.svg".to_owned(),
|
||||||
|
]);
|
||||||
|
legacy.sort();
|
||||||
|
let legacy_dir = "supabase/seed/anatomical-sheets/equine/legacy-import";
|
||||||
|
assert_eq!(files_under(legacy_dir), legacy);
|
||||||
|
assert!(legacy.iter().all(|file| !file.ends_with(".sql")));
|
||||||
|
let mut draft = listed("/draft");
|
||||||
|
draft.sort();
|
||||||
|
assert_eq!(draft.len(), 12);
|
||||||
|
assert_eq!(files_under(DRAFT), draft);
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ mod common;
|
|||||||
use faunosteo_core::anatomy::svg::number::{is_js_space, js_number_of, js_split_list};
|
use faunosteo_core::anatomy::svg::number::{is_js_space, js_number_of, js_split_list};
|
||||||
use faunosteo_core::curation::PipelineError;
|
use faunosteo_core::curation::PipelineError;
|
||||||
use faunosteo_core::curation::ids::deterministic_uuid;
|
use faunosteo_core::curation::ids::deterministic_uuid;
|
||||||
|
use faunosteo_core::curation::legacy::regions::{RegionMatch, infer_region_code};
|
||||||
use faunosteo_core::curation::markdown::format_markdown;
|
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::text::{js_keys, js_round, slugify};
|
use faunosteo_core::curation::text::{js_keys, js_round, slugify};
|
||||||
@@ -187,3 +188,66 @@ fn js_string(value: f64) -> String {
|
|||||||
js_number(value)
|
js_number(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn region(fr: Option<&str>, en: Option<&str>) -> Option<String> {
|
||||||
|
infer_region_code(fr, en).map(|m| m.code)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `inferRegionCode` as Node ran it (`js-semantics.json`, 12 rows: root, label and code) and the
|
||||||
|
/// cases of the deleted `legacy.regions.test.ts` (R5.7): FR roots with and without accents, EN
|
||||||
|
/// roots when FR is absent, FR before EN, the EN fallback when FR names no root.
|
||||||
|
#[test]
|
||||||
|
fn region_inference_follows_the_typescript() {
|
||||||
|
let semantics = oracle("js-semantics.json");
|
||||||
|
let cases = rows(&semantics, "inferRegionCode");
|
||||||
|
assert_eq!(cases.len(), 12);
|
||||||
|
for case in cases {
|
||||||
|
let (fr, en) = (case["fr"].as_str(), case["en"].as_str());
|
||||||
|
let actual = infer_region_code(fr, en).map(|RegionMatch { code, root, label }| {
|
||||||
|
serde_json::json!({ "code": code, "root": root, "label": label })
|
||||||
|
});
|
||||||
|
assert_eq!(
|
||||||
|
actual.unwrap_or(Value::Null),
|
||||||
|
case["match"],
|
||||||
|
"{fr:?} / {en:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for (fr, code) in [
|
||||||
|
("Vertèbres cervicales", "C"),
|
||||||
|
("Vertebres cervicales", "C"),
|
||||||
|
("Vertèbres thoraciques", "T"),
|
||||||
|
("Vertebres thoraciques", "T"),
|
||||||
|
("Vertèbres lombaires", "L"),
|
||||||
|
("Vertèbres sacrales", "S"),
|
||||||
|
("Vertèbres sacrées", "S"),
|
||||||
|
("Vertèbres caudales", "Cd"),
|
||||||
|
("Vertèbres coccygiennes", "Cd"),
|
||||||
|
("Région dorsale", "T"),
|
||||||
|
] {
|
||||||
|
assert_eq!(region(Some(fr), None).as_deref(), Some(code), "{fr}");
|
||||||
|
}
|
||||||
|
for (en, code) in [
|
||||||
|
("Cervical Vertebrae", "C"),
|
||||||
|
("Thoracic Vertebrae", "T"),
|
||||||
|
("Lumbar Vertebrae", "L"),
|
||||||
|
("Sacral Vertebrae", "S"),
|
||||||
|
("Coccygeal Vertebrae", "Cd"),
|
||||||
|
] {
|
||||||
|
assert_eq!(region(None, Some(en)).as_deref(), Some(code), "{en}");
|
||||||
|
}
|
||||||
|
assert_eq!(region(Some("Épaule"), Some("Shoulder")), None);
|
||||||
|
assert_eq!(region(Some(""), Some("")), None);
|
||||||
|
assert_eq!(region(None, None), None);
|
||||||
|
assert_eq!(
|
||||||
|
infer_region_code(Some("Vertèbres lombaires"), Some("Cervical")),
|
||||||
|
Some(RegionMatch {
|
||||||
|
code: "L".into(),
|
||||||
|
root: "lombair".into(),
|
||||||
|
label: "Vertèbres lombaires".into()
|
||||||
|
})
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
region(Some("Épaule"), Some("Cervical Vertebrae")).as_deref(),
|
||||||
|
Some("C")
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,263 @@
|
|||||||
|
//! `packages/anatomy/tests/curation.migration-leaves.test.ts` ported with its exact expectations
|
||||||
|
//! (R5.7): every leaf of the legacy catalog (612) and every legacy annotation (27) travels through
|
||||||
|
//! the Report v2 → v3 migration with the committed map, then is checked against the curated draft
|
||||||
|
//! document itself, not against the map alone. The other 612-leaf tests (`report_rules`, the produced
|
||||||
|
//! map in `curation_draft`, the application's `migration.leaves`) keep their own angles.
|
||||||
|
#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]
|
||||||
|
|
||||||
|
mod archive_support;
|
||||||
|
mod common;
|
||||||
|
|
||||||
|
use archive_support::*;
|
||||||
|
use faunosteo_core::domain::report::v2::ReportV2;
|
||||||
|
use faunosteo_core::domain::report::{
|
||||||
|
Finding, ReportMigrationMap, finding_path_key, migrate_report_v2_to_v3, read_report_document,
|
||||||
|
};
|
||||||
|
use faunosteo_core::domain::sheet::{AnatomicalSheetDocument, Annotation, LoadedSheet};
|
||||||
|
use serde_json::{Value, json};
|
||||||
|
|
||||||
|
struct Fixture {
|
||||||
|
draft: LoadedSheet,
|
||||||
|
map: ReportMigrationMap,
|
||||||
|
leaves: Vec<LegacyLeaf>,
|
||||||
|
findings: Vec<Finding>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fixture() -> Fixture {
|
||||||
|
let map = draft_map();
|
||||||
|
let leaves = legacy_leaves();
|
||||||
|
let v2: ReportV2 = from(leaves_as_v2_report(&leaves));
|
||||||
|
let report = migrate_report_v2_to_v3(&v2, &map).unwrap().report;
|
||||||
|
let findings = report
|
||||||
|
.observations
|
||||||
|
.into_iter()
|
||||||
|
.flat_map(|o| o.findings)
|
||||||
|
.collect();
|
||||||
|
Fixture {
|
||||||
|
draft: draft_sheet(),
|
||||||
|
map,
|
||||||
|
leaves,
|
||||||
|
findings,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn document(f: &Fixture) -> &AnatomicalSheetDocument {
|
||||||
|
&f.draft.document
|
||||||
|
}
|
||||||
|
|
||||||
|
fn joined(path: &[String]) -> String {
|
||||||
|
path.join("/")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An empty v2 report holding one observation with these zones.
|
||||||
|
fn zones_report(zones: Value) -> ReportV2 {
|
||||||
|
let mut v2 = leaves_as_v2_report(&[]);
|
||||||
|
v2["observations"] = json!([{
|
||||||
|
"id": "zones", "zones": zones, "findings": [], "freeTextFindings": [], "comment": ""
|
||||||
|
}]);
|
||||||
|
from(v2)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn migrates_the_612_leaves_442_identical_141_moved_29_removed() {
|
||||||
|
let f = fixture();
|
||||||
|
assert_eq!(f.leaves.len(), 612);
|
||||||
|
assert_eq!(f.findings.len(), 612);
|
||||||
|
let (mut identical, mut moved, mut removed) = (0, 0, 0);
|
||||||
|
for (leaf, out) in f.leaves.iter().zip(&f.findings) {
|
||||||
|
let same = out.finding_zone_id == leaf.zone_id && out.path == leaf.path;
|
||||||
|
if out.unresolved.is_some() {
|
||||||
|
removed += 1;
|
||||||
|
} else if same {
|
||||||
|
identical += 1;
|
||||||
|
} else {
|
||||||
|
moved += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert_eq!((identical, moved, removed), (442, 141, 29));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn lands_every_resolved_leaf_on_a_leaf_of_the_draft_document() {
|
||||||
|
let f = fixture();
|
||||||
|
for out in f.findings.iter().filter(|o| o.unresolved.is_none()) {
|
||||||
|
let where_ = format!("{}/{}", out.finding_zone_id, joined(&out.path));
|
||||||
|
let node = f.draft.indexed().node_at(&out.finding_zone_id, &out.path);
|
||||||
|
assert!(
|
||||||
|
node.as_ref().is_some_and(|n| n.children().is_empty()),
|
||||||
|
"{where_}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn keeps_the_legacy_snapshots_and_the_vet_flag_verbatim_on_every_finding() {
|
||||||
|
let f = fixture();
|
||||||
|
for (leaf, out) in f.leaves.iter().zip(&f.findings) {
|
||||||
|
let en = if leaf.en.is_empty() {
|
||||||
|
&leaf.fr
|
||||||
|
} else {
|
||||||
|
&leaf.en
|
||||||
|
};
|
||||||
|
assert_eq!(out.label_fr_snapshot, leaf.fr);
|
||||||
|
assert_eq!(&out.label_en_snapshot, en);
|
||||||
|
assert_eq!(
|
||||||
|
out.requires_vet_referral.unwrap_or(false),
|
||||||
|
leaf.vet,
|
||||||
|
"{}",
|
||||||
|
joined(&leaf.path)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn flags_exactly_the_leaves_the_curation_removed_with_their_legacy_path_kept() {
|
||||||
|
let f = fixture();
|
||||||
|
let removed: Vec<String> = f
|
||||||
|
.leaves
|
||||||
|
.iter()
|
||||||
|
.map(|leaf| finding_path_key(&leaf.zone_id, &leaf.path))
|
||||||
|
.filter(|key| matches!(f.map.finding_paths.get(key), Some(None)))
|
||||||
|
.collect();
|
||||||
|
assert_eq!(removed.len(), 29);
|
||||||
|
let flagged: Vec<&Finding> = f
|
||||||
|
.findings
|
||||||
|
.iter()
|
||||||
|
.filter(|o| o.unresolved.is_some())
|
||||||
|
.collect();
|
||||||
|
let keys: Vec<String> = flagged
|
||||||
|
.iter()
|
||||||
|
.map(|o| format!("{}/{}", o.finding_zone_id, joined(&o.path)))
|
||||||
|
.collect();
|
||||||
|
assert_eq!(keys, removed);
|
||||||
|
for o in flagged {
|
||||||
|
assert!(
|
||||||
|
f.draft
|
||||||
|
.indexed()
|
||||||
|
.node_at(&o.finding_zone_id, &o.path)
|
||||||
|
.is_none()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn moves_the_141_relocated_leaves_inside_their_zone_134_category_7_leaf() {
|
||||||
|
let f = fixture();
|
||||||
|
let (mut category, mut leaf_renamed) = (0, 0);
|
||||||
|
for (leaf, out) in f.leaves.iter().zip(&f.findings) {
|
||||||
|
if out.unresolved.is_some() || out.path == leaf.path {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
assert_eq!(out.finding_zone_id, leaf.zone_id, "{}", joined(&leaf.path));
|
||||||
|
if out.path.last() == leaf.path.last() {
|
||||||
|
category += 1;
|
||||||
|
} else {
|
||||||
|
leaf_renamed += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert_eq!((category, leaf_renamed), (134, 7));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn reads_the_migrated_report_back_unchanged() {
|
||||||
|
let f = fixture();
|
||||||
|
let v2 = leaves_as_v2_report(&f.leaves);
|
||||||
|
let report = read_report_document(&v2, &f.map).unwrap().report;
|
||||||
|
let again = read_report_document(&report_value(&report), &f.map).unwrap();
|
||||||
|
assert_eq!(again.report, report);
|
||||||
|
assert_eq!((again.unresolved_zones, again.unresolved_findings), (0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn maps_the_26_observable_legacy_ids_to_annotations_of_the_right_view() {
|
||||||
|
let f = fixture();
|
||||||
|
let doc = document(&f);
|
||||||
|
let triggers: Vec<&str> = doc
|
||||||
|
.annotations
|
||||||
|
.iter()
|
||||||
|
.filter_map(Annotation::trigger)
|
||||||
|
.map(|a| a.id.as_str())
|
||||||
|
.collect();
|
||||||
|
let mut legacy_ids: Vec<&String> = f
|
||||||
|
.map
|
||||||
|
.annotations
|
||||||
|
.iter()
|
||||||
|
.filter(|(_, mapped)| !triggers.contains(&mapped.id.as_str()))
|
||||||
|
.map(|(id, _)| id)
|
||||||
|
.collect();
|
||||||
|
legacy_ids.sort();
|
||||||
|
assert_eq!(legacy_ids.len(), 26);
|
||||||
|
let head: Vec<&str> = doc
|
||||||
|
.annotations
|
||||||
|
.iter()
|
||||||
|
.filter(|a| a.view_id() == "head")
|
||||||
|
.map(Annotation::id)
|
||||||
|
.collect();
|
||||||
|
let zones: Vec<Value> = legacy_ids
|
||||||
|
.iter()
|
||||||
|
.map(|id| {
|
||||||
|
if head.contains(&f.map.annotations[*id].id.as_str()) {
|
||||||
|
json!({ "boneId": id, "detailSourceId": "head" })
|
||||||
|
} else {
|
||||||
|
json!({ "boneId": id })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
assert!(zones.iter().any(|z| z.get("detailSourceId").is_some()));
|
||||||
|
let out = migrate_report_v2_to_v3(&zones_report(json!(zones)), &f.map).unwrap();
|
||||||
|
assert_eq!(out.unresolved_zones, 0);
|
||||||
|
for (zone, id) in out.report.observations[0].zones.iter().zip(&legacy_ids) {
|
||||||
|
let anno = doc
|
||||||
|
.annotations
|
||||||
|
.iter()
|
||||||
|
.find(|a| a.id() == zone.annotation_id);
|
||||||
|
let anno = anno.unwrap_or_else(|| panic!("{}", zone.annotation_id));
|
||||||
|
assert_eq!(anno.view_id(), zone.view_id);
|
||||||
|
assert_eq!(
|
||||||
|
zone.label_fr_snapshot.as_deref(),
|
||||||
|
Some(f.map.annotations[*id].name.fr.as_str())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn keeps_vertebrae_on_the_spine_zones_with_region_codes_the_draft_defines() {
|
||||||
|
let f = fixture();
|
||||||
|
let doc = document(&f);
|
||||||
|
let codes: Vec<&str> = doc
|
||||||
|
.vertebral_config
|
||||||
|
.regions
|
||||||
|
.iter()
|
||||||
|
.map(|r| r.code.as_str())
|
||||||
|
.collect();
|
||||||
|
let spine: Vec<&str> = doc
|
||||||
|
.annotations
|
||||||
|
.iter()
|
||||||
|
.filter_map(Annotation::observable)
|
||||||
|
.filter_map(|a| a.vertebral_region_code.as_deref())
|
||||||
|
.collect();
|
||||||
|
assert_eq!(spine.len(), 5);
|
||||||
|
assert!(spine.iter().all(|code| codes.contains(code)));
|
||||||
|
let legacy_id = f
|
||||||
|
.map
|
||||||
|
.annotations
|
||||||
|
.iter()
|
||||||
|
.find(|(_, m)| m.id == "cervical")
|
||||||
|
.unwrap()
|
||||||
|
.0;
|
||||||
|
let report = zones_report(json!([
|
||||||
|
{ "boneId": legacy_id, "vertebrae": [{ "region": "C", "index": 7 }] }
|
||||||
|
]));
|
||||||
|
let zone = &migrate_report_v2_to_v3(&report, &f.map)
|
||||||
|
.unwrap()
|
||||||
|
.report
|
||||||
|
.observations[0]
|
||||||
|
.zones[0];
|
||||||
|
let vertebrae = zone.vertebrae.as_ref().unwrap();
|
||||||
|
assert_eq!(vertebrae.len(), 1);
|
||||||
|
assert_eq!(
|
||||||
|
(vertebrae[0].region.as_str(), vertebrae[0].index),
|
||||||
|
("C", 7.into())
|
||||||
|
);
|
||||||
|
assert!(codes.contains(&vertebrae[0].region.as_str()));
|
||||||
|
}
|
||||||
@@ -568,3 +568,32 @@ fn the_drawings_projection_bounds_what_is_written() {
|
|||||||
draft.baseline["annotations"] = Value::Array(Vec::new());
|
draft.baseline["annotations"] = Value::Array(Vec::new());
|
||||||
assert!(review_drawings_bytes(&draft).unwrap() >= written(&draft, &result.anomalies));
|
assert!(review_drawings_bytes(&draft).unwrap() >= written(&draft, &result.anomalies));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `curation.overlay.test.ts` "reports an annotation dropped by the changeset" (R5.7): an
|
||||||
|
/// annotation of the baseline that the curated document no longer holds is drawn as removed.
|
||||||
|
#[test]
|
||||||
|
fn an_annotation_dropped_by_the_changeset_is_drawn_as_removed() {
|
||||||
|
let frozen = oracle("review-synthetic.json");
|
||||||
|
let before = &frozen["baseline"];
|
||||||
|
let mut after = before.clone();
|
||||||
|
after["annotations"]
|
||||||
|
.as_array_mut()
|
||||||
|
.unwrap()
|
||||||
|
.retain(|a| a["id"] != "hip");
|
||||||
|
let drawing = read_cleaned_drawing(frozen["drawing"].as_str().unwrap().as_bytes()).unwrap();
|
||||||
|
let overlay = render_review_overlay(&OverlayInput {
|
||||||
|
drawing: &drawing,
|
||||||
|
before,
|
||||||
|
after: &after,
|
||||||
|
view_id: "main",
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
let tree = roxmltree::Document::parse(&overlay).unwrap();
|
||||||
|
let status = |id: &str| {
|
||||||
|
tree.descendants()
|
||||||
|
.find(|n| n.attribute("data-review-id") == Some(id))
|
||||||
|
.and_then(|n| n.attribute("data-review-status"))
|
||||||
|
};
|
||||||
|
assert_eq!(status("hip"), Some("removed"));
|
||||||
|
assert_ne!(status("neck"), Some("removed"));
|
||||||
|
}
|
||||||
Vendored
File renamed without changes.
File renamed without changes.
@@ -39,3 +39,37 @@ fn the_frozen_envelopes_parse_and_print_as_their_attachment() {
|
|||||||
assert_eq!(to_js_pretty(&envelope).unwrap(), text, "{name}");
|
assert_eq!(to_js_pretty(&envelope).unwrap(), text, "{name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `r2-oracles.test.ts` on `migration-map.draft.json` (R5.7): what Zod read from the map the
|
||||||
|
/// TypeScript wrote (the pre-switch copy) is what the core reads, entry by entry, nulls
|
||||||
|
/// included; the committed map since R5.6 differs only by the sheet fingerprint.
|
||||||
|
#[test]
|
||||||
|
fn the_draft_migration_map_reads_as_zod_read_it_entry_by_entry() {
|
||||||
|
let (_, oracle) = common::oracle_file("migration-map.draft.json");
|
||||||
|
let frozen: ReportMigrationMap = serde_json::from_value(oracle["output"].clone()).unwrap();
|
||||||
|
let pre_switch =
|
||||||
|
common::repo_file("crates/core/tests/fixtures/r5-6/pre-switch/report-migration-map.json");
|
||||||
|
let read: ReportMigrationMap =
|
||||||
|
serde_json::from_value(parse_json(&pre_switch).unwrap()).unwrap();
|
||||||
|
assert_eq!(read, frozen);
|
||||||
|
assert_eq!(
|
||||||
|
(
|
||||||
|
read.annotations.len(),
|
||||||
|
read.finding_paths.len(),
|
||||||
|
read.views.len()
|
||||||
|
),
|
||||||
|
(27, 792, 1)
|
||||||
|
);
|
||||||
|
let nulls = read.finding_paths.values().filter(|p| p.is_none()).count();
|
||||||
|
assert_eq!(nulls, 34);
|
||||||
|
let committed =
|
||||||
|
common::repo_file("supabase/seed/anatomical-sheets/equine/draft/report-migration-map.json");
|
||||||
|
let mut committed: ReportMigrationMap =
|
||||||
|
serde_json::from_value(parse_json(&committed).unwrap()).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
committed.sheet.document_sha256,
|
||||||
|
"12d788727c1e532641bd5b3a7ecf39dbdd25e70350f8a76be5ca917b262874e2"
|
||||||
|
);
|
||||||
|
committed.sheet.document_sha256 = frozen.sheet.document_sha256.clone();
|
||||||
|
assert_eq!(committed, frozen);
|
||||||
|
}
|
||||||
@@ -139,7 +139,7 @@ fn test_map() -> ReportMigrationMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fixture(name: &str) -> Value {
|
fn fixture(name: &str) -> Value {
|
||||||
json_file(&format!("packages/domain/tests/fixtures/{name}"))
|
json_file(&format!("crates/core/tests/fixtures/{name}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn migrated(
|
fn migrated(
|
||||||
|
|||||||
Reference in new issue
Block a user