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
@@ -588,11 +588,20 @@ fn a_reserved_touch_mark_key_in_an_authored_value_is_refused() {
|
||||
|
||||
fn mini_apply(
|
||||
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> {
|
||||
let frozen = oracle("curation-synthetic.json");
|
||||
let references = parse_references(&to_js_compact(&frozen["references_file"]).unwrap()).unwrap();
|
||||
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",
|
||||
"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);
|
||||
}
|
||||
Reference in new issue
Block a user