//! The merge DECISION, exhaustively. //! //! These tests are the reason the server's `merge_people` can be a plain //! executor: everything that could be argued about — what is refused, what the //! survivor ends up with, what happens to the iPhone card, what gets repointed //! — is settled here, on rows. use serde_json::json; use cotton_store::protocol::js::parse_date_ms; use super::*; use crate::definitions::ColumnType; /// `new Date("2026-09-05T10:30:00.000Z")`, as the milliseconds this crate takes. fn now() -> i64 { parse_date_ms("2026-09-05T10:30:00.000Z").expect("an ISO instant") } fn no_claims() -> PersonMergeClaims { PersonMergeClaims::default() } fn claims(survivor: &[&str], duplicate: &[&str]) -> PersonMergeClaims { PersonMergeClaims { survivor: survivor.iter().map(|s| (*s).to_string()).collect(), duplicate: duplicate.iter().map(|s| (*s).to_string()).collect(), } } fn person() -> PersonMergeInput { PersonMergeInput { id: "p_1".into(), full_name: "Meera Sharma".into(), contact_source: "manual".into(), created_at: "2026-01-01T00:00:00.000Z".into(), ..Default::default() } } fn survivor_of() -> PersonMergeInput { PersonMergeInput { id: "p_survivor".into(), ..person() } } fn duplicate_of() -> PersonMergeInput { PersonMergeInput { id: "p_duplicate".into(), full_name: "Dr. Meera".into(), ..person() } } fn plan(survivor: PersonMergeInput, duplicate: PersonMergeInput) -> PersonMergePlan { plan_person_merge(&survivor, &duplicate, now(), &no_claims()).expect("a renderable instant") } fn patch_of(plan: &PersonMergePlan) -> Value { Value::Object(plan.survivor_patch.clone()) } /// The card the preserving comment carries, parsed back out of the body — the /// TypeScript test reads it the same way. fn card_json(plan: &PersonMergePlan) -> Value { let body = plan.preserving_comment.as_ref().expect("a comment").body.say(&[]); let start = body.find('{').expect("a card in the body"); serde_json::from_str(&body[start..]).expect("valid JSON") } fn text(strings: &[&str]) -> Vec { strings.iter().map(|s| (*s).to_string()).collect() } // ── refusals ───────────────────────────────────────────────────────────────── #[test] fn refuses_an_archived_survivor_and_plans_nothing_at_all() { let plan = plan( PersonMergeInput { archived_at: Some("2026-08-01T00:00:00.000Z".into()), ..survivor_of() }, PersonMergeInput { phones: text(&["919900112233"]), device_contact_id: Some("AB12:ZZ".into()), ..duplicate_of() }, ); assert_eq!( plan.refusal.as_ref().map(|refusal| refusal.say(&[])).as_deref(), Some(PersonMergeRefusal::ArchivedSurvivor.say(&[]).as_str()) ); assert!(plan .refusal .as_ref() .unwrap() .say(&[]) .contains("unarchive_person")); // A refusal is inert: an executor that forgot to check it still cannot // half-merge anything. assert!(plan.survivor_patch.is_empty()); assert!(plan.preserving_comment.is_none()); assert_eq!(plan.device_card, PersonMergeDeviceCard::None); assert!(plan.archive_duplicate.is_none()); } #[test] fn refuses_when_both_hold_the_same_money_claim_subtype_naming_it() { let plan = plan_person_merge( &survivor_of(), &duplicate_of(), now(), &claims(&["receivable", "payable"], &["receivable"]), ) .expect("a renderable instant"); assert_eq!( plan.refusal.as_ref().map(|refusal| refusal.say(&[])).as_deref(), Some( "both people hold a receivable money account — merge is refused until the owner resolves the money side in the app" ) ); assert!(plan.preserving_comment.is_none()); } #[test] fn names_every_colliding_subtype_when_there_is_more_than_one() { let plan = plan_person_merge( &survivor_of(), &duplicate_of(), now(), &claims(&["receivable", "loan"], &["loan", "receivable"]), ) .expect("a renderable instant"); assert_eq!( plan.refusal.as_ref().map(|refusal| refusal.say(&[])).as_deref(), Some( "both people hold a loan and a receivable money account — merge is refused until the owner resolves the money side in the app" ) ); } #[test] fn allows_different_claim_subtypes_on_the_two_people() { let plan = plan_person_merge( &survivor_of(), &duplicate_of(), now(), &claims(&["receivable"], &["payable"]), ) .expect("a renderable instant"); assert!(plan.refusal.is_none()); } #[test] fn checks_the_archived_survivor_before_the_money_claim() { let plan = plan_person_merge( &PersonMergeInput { archived_at: Some("2026-08-01T00:00:00.000Z".into()), ..survivor_of() }, &duplicate_of(), now(), &claims(&["receivable"], &["receivable"]), ) .expect("a renderable instant"); assert_eq!( plan.refusal.as_ref().map(|refusal| refusal.say(&[])).as_deref(), Some(PersonMergeRefusal::ArchivedSurvivor.say(&[]).as_str()) ); } // ── the additive union ─────────────────────────────────────────────────────── /// RULE: since v90 the union patch never writes phones or emails — a handle moves to the survivor as its own row (merge_people repoints cotton_person_handles), so the patch would write columns that no longer exist. #[test] fn the_union_patch_never_writes_phones_or_emails() { let plan = plan( PersonMergeInput { phones: text(&["919900112233"]), emails: text(&["meera@example.com"]), ..survivor_of() }, PersonMergeInput { phones: text(&["918888777666"]), emails: text(&["dr.meera@clinic.example"]), ..duplicate_of() }, ); assert_eq!(plan.survivor_patch.get("phones"), None); assert_eq!(plan.survivor_patch.get("emails"), None); } #[test] fn leaves_an_array_out_of_the_patch_when_the_duplicate_adds_nothing() { let plan = plan( PersonMergeInput { phones: text(&["919900112233"]), emails: text(&["meera@example.com"]), ..survivor_of() }, PersonMergeInput { phones: text(&["919900112233"]), emails: text(&["Meera@Example.com"]), ..duplicate_of() }, ); assert!(plan.survivor_patch.is_empty()); } #[test] fn fills_every_empty_scalar_and_never_overwrites_one_the_survivor_holds() { let plan = plan( PersonMergeInput { org: Some("Cotton".into()), ..survivor_of() }, PersonMergeInput { org: Some("The Clinic".into()), role_title: Some("Doctor".into()), city: Some("Pune".into()), timezone: Some("Asia/Kolkata".into()), ..duplicate_of() }, ); assert_eq!( patch_of(&plan), json!({ "role_title": "Doctor", "city": "Pune", "timezone": "Asia/Kolkata" }) ); assert!(plan.survivor_patch.get("org").is_none()); } #[test] fn moves_the_birthday_as_a_triple_year_included_only_when_the_survivor_has_none() { let with_birthday = plan( survivor_of(), PersonMergeInput { birth_month: Some(3), birth_day: Some(14), birth_year: Some(1984), ..duplicate_of() }, ); assert_eq!( patch_of(&with_birthday), json!({ "birth_month": 3, "birth_day": 14, "birth_year": 1984 }) ); // A yearless birthday still moves as a triple — the null is the fact. let yearless = plan( survivor_of(), PersonMergeInput { birth_month: Some(3), birth_day: Some(14), ..duplicate_of() }, ); assert_eq!( patch_of(&yearless), json!({ "birth_month": 3, "birth_day": 14, "birth_year": null }) ); // The survivor's own month wins, and the duplicate's year does NOT sneak in. let held = plan( PersonMergeInput { birth_month: Some(1), birth_day: Some(2), ..survivor_of() }, PersonMergeInput { birth_month: Some(3), birth_day: Some(14), birth_year: Some(1984), ..duplicate_of() }, ); assert!(held.survivor_patch.is_empty()); } #[test] fn moves_the_summary_with_its_provenance_or_not_at_all() { let taken = plan( survivor_of(), PersonMergeInput { summary: Some("Runs the clinic.".into()), summary_by: Some("server".into()), summary_updated_at: Some("2026-08-30T00:00:00.000Z".into()), ..duplicate_of() }, ); assert_eq!( patch_of(&taken), json!({ "summary": "Runs the clinic.", "summary_by": "server", "summary_updated_at": "2026-08-30T00:00:00.000Z" }) ); let held = plan( PersonMergeInput { summary: Some("Mine.".into()), summary_by: Some("user".into()), ..survivor_of() }, PersonMergeInput { summary: Some("Theirs.".into()), summary_by: Some("server".into()), ..duplicate_of() }, ); assert!(held.survivor_patch.is_empty()); } // RULE: A merge transfers only an object key; obsolete remote URLs do not claim or carry a photo. #[test] fn takes_the_avatar_only_when_the_survivor_has_no_key() { let taken = plan( survivor_of(), PersonMergeInput { avatar_key: Some("ws/a.jpg".into()), ..duplicate_of() }, ); assert_eq!( patch_of(&taken), json!({ "avatar_key": "ws/a.jpg" }) ); let held_by_key = plan( PersonMergeInput { avatar_key: Some("ws/chosen.jpg".into()), ..survivor_of() }, PersonMergeInput { avatar_key: Some("ws/a.jpg".into()), ..duplicate_of() }, ); assert!(held_by_key.survivor_patch.is_empty()); } // ── the preserving comment ─────────────────────────────────────────────────── #[test] fn writes_the_duplicates_whole_card_onto_the_survivor_as_an_agent_comment() { let plan = plan( survivor_of(), PersonMergeInput { phones: text(&["918888777666"]), emails: text(&["dr.meera@clinic.example"]), org: Some("The Clinic".into()), role_title: Some("Doctor".into()), city: Some("Pune".into()), timezone: Some("Asia/Kolkata".into()), birth_month: Some(3), birth_day: Some(14), birth_year: Some(1984), summary: Some("Runs the clinic.".into()), ..duplicate_of() }, ); let comment = plan.preserving_comment.as_ref().expect("a comment"); assert_eq!(comment.record_kind, PersonMergeCommentRecordKind::Person); assert_eq!(comment.record_id, "p_survivor"); assert_eq!(comment.parent_id, ()); assert_eq!(comment.author_kind, PersonMergeCommentAuthorKind::Agent); assert_eq!(comment.anchor, ()); assert!(comment .body .say(&[]) .contains("Merged in the duplicate person \"Dr. Meera\".")); assert_eq!( card_json(&plan), json!({ "id": "p_duplicate", "name": "Dr. Meera", "phones": ["918888777666"], "emails": ["dr.meera@clinic.example"], "org": "The Clinic", "roleTitle": "Doctor", "city": "Pune", "timezone": "Asia/Kolkata", "birthday": { "month": 3, "day": 14, "year": 1984 }, "summary": "Runs the clinic." }) ); } #[test] fn omits_every_empty_field_and_the_birthday_year_when_there_is_none() { let plan = plan( survivor_of(), PersonMergeInput { birth_month: Some(3), birth_day: Some(14), ..duplicate_of() }, ); assert_eq!( card_json(&plan), json!({ "id": "p_duplicate", "name": "Dr. Meera", "birthday": { "month": 3, "day": 14 } }) ); } // ── the device card ────────────────────────────────────────────────────────── #[test] fn the_device_card_is_none_when_neither_person_is_linked() { let plan = plan(survivor_of(), duplicate_of()); assert_eq!(plan.device_card, PersonMergeDeviceCard::None); assert_eq!(plan.device_card.outcome(), "none"); } #[test] fn the_device_card_is_kept_when_only_the_survivor_is_linked_and_nothing_is_written() { let plan = plan( PersonMergeInput { device_contact_id: Some("SURV:1".into()), device_contact_snapshot: json!({ "fullName": "Meera" }), ..survivor_of() }, duplicate_of(), ); assert_eq!(plan.device_card, PersonMergeDeviceCard::Kept); // The two patches are not merely absent — the variant has no room for them. assert!(plan.device_card.duplicate_patch().is_none()); } #[test] fn the_device_card_is_moved_when_only_the_duplicate_is_linked() { let snapshot = json!({ "fullName": "Dr. Meera", "phones": ["918888777666"] }); let plan = plan( survivor_of(), PersonMergeInput { device_contact_id: Some("AB12:ZZ".into()), device_contact_snapshot: snapshot.clone(), ..duplicate_of() }, ); assert_eq!( plan.device_card, PersonMergeDeviceCard::Moved { duplicate_patch: ClearDeviceCard::default(), survivor_patch: ClaimDeviceCard { device_contact_id: "AB12:ZZ".into(), device_contact_snapshot: snapshot, }, } ); assert_eq!( serde_json::to_value(&plan.device_card).expect("serialisable"), json!({ "outcome": "moved", "duplicatePatch": { "device_contact_id": null, "device_contact_snapshot": null }, "survivorPatch": { "device_contact_id": "AB12:ZZ", "device_contact_snapshot": { "fullName": "Dr. Meera", "phones": ["918888777666"] } } }) ); } #[test] fn the_device_card_is_orphaned_when_both_are_linked() { let plan = plan( PersonMergeInput { device_contact_id: Some("SURV:1".into()), device_contact_snapshot: json!({ "fullName": "Meera" }), ..survivor_of() }, PersonMergeInput { device_contact_id: Some("DUP:2".into()), device_contact_snapshot: json!({ "fullName": "Dr. Meera" }), ..duplicate_of() }, ); assert_eq!( plan.device_card, PersonMergeDeviceCard::Orphaned { duplicate_patch: ClearDeviceCard::default(), orphaned_device_contact_id: "DUP:2".into(), } ); assert_eq!( serde_json::to_value(&plan.device_card).expect("serialisable"), json!({ "outcome": "orphaned", "duplicatePatch": { "device_contact_id": null, "device_contact_snapshot": null }, "orphanedDeviceContactId": "DUP:2" }) ); } // ── the archive ────────────────────────────────────────────────────────────── #[test] fn stamps_the_duplicate_with_the_callers_clock_never_the_wall_clock() { let plan = plan(survivor_of(), duplicate_of()); assert_eq!( plan.archive_duplicate, Some(PersonMergeArchive { archived_at: "2026-09-05T10:30:00.000Z".into() }) ); } #[test] fn has_nothing_to_stamp_when_the_duplicate_is_already_archived() { let plan = plan( survivor_of(), PersonMergeInput { archived_at: Some("2026-08-01T00:00:00.000Z".into()), ..duplicate_of() }, ); assert!(plan.refusal.is_none()); assert!(plan.archive_duplicate.is_none()); } /// The TypeScript throws `RangeError: Invalid time value` here; a pure library /// may not panic on caller-supplied data, so the port refuses instead. It is /// only reachable past the outer limit of an ECMAScript Date. #[test] fn refuses_an_instant_javascript_itself_could_not_render() { let err = plan_person_merge( &survivor_of(), &duplicate_of(), 8_640_000_000_000_001, &no_claims(), ) .expect_err("out of range"); assert_eq!(err.to_string(), "Invalid time value"); } // ── person_repoints ────────────────────────────────────────────────────────── fn shipped_repoints() -> Vec { person_repoints(crate::definitions::builtin_table_definitions()) .expect("every shipped person link has storage") } fn keys(repoints: &[PersonRepoint]) -> Vec { repoints.iter().map(|r| format!("{}.{}", r.table, r.column)).collect() } /// GUARD (data safety): every person link a shipped definition declares is /// either moved by a merge or listed in PERSON_LINKS_NOT_REPOINTED with why. /// A link that is neither would leave records pointing at an archived card. #[test] fn every_shipped_person_link_is_moved_or_listed_with_a_reason() { let repoints = shipped_repoints(); for definition in crate::definitions::builtin_table_definitions() { let shapes = cotton_store::schema::package_tables::compiled_shape(&definition.id).unwrap_or_default(); for column in &definition.columns { if column.column_type != ColumnType::Link || column.link_to.as_deref() != Some("person") || column.computed.is_some() || column.edges == Some(true) || column.multiple == Some(true) { continue; } let listed = PERSON_LINKS_NOT_REPOINTED .iter() .any(|(table, key, _)| *table == definition.id && *key == column.key); let moved = shapes.iter().any(|table| { repoints.iter().any(|r| r.table == table.name && r.column == column.key) }); assert!( listed ^ moved, "{}.{}: moved={moved} listed={listed} — a person link is moved or listed, exactly one", definition.id, column.key ); } } } #[test] fn the_shipped_links_are_moved_as_columns_beside_the_storage_links() { let repoints = shipped_repoints(); let keys = keys(&repoints); for expected in [ "cotton_person_handles.person_id", "cotton_stories.person_id", "cotton_media_faces.suggested_person_id", "cotton_media_faces.person_id", "cotton_msg_contacts.person_id", ] { assert!(keys.iter().any(|k| k == expected), "{expected} is not moved: {keys:?}"); } // Who the owner is, the object says (apps/business/src/owner.ts): a merge on a device never moves it. for refused in ["cotton_workspaces.owner_person_id"] { assert!(!keys.iter().any(|k| k == refused), "{refused} is the object's to say"); } // The storage links come last, in their own order: the executor moves // edges and memberships after every column. let tail: Vec = keys[keys.len() - PERSON_STORAGE_REPOINTS.len()..].to_vec(); let storage: Vec = keys_of_storage(); assert_eq!(tail, storage); } fn keys_of_storage() -> Vec { PERSON_STORAGE_REPOINTS.iter().map(|r| format!("{}.{}", r.table, r.column)).collect() } #[test] fn every_shipped_link_is_moved_within_its_workspace() { let unscoped: Vec = shipped_repoints() .into_iter() .filter(|r| !r.workspace_scoped) .map(|r| r.table.into_owned()) .collect(); assert!(unscoped.is_empty(), "{unscoped:?}"); } fn imported(columns: serde_json::Value) -> TableDefinition { serde_json::from_value(json!({ "id": "clinic_patient", "name": "Patient", "plural": "Patients", "picture": null, "builtin": false, "engine": null, "columns": columns, "title": "name", "date": null, "project": null, "order": null, "slip": { "title": "name" }, "tile": { "face": "list" }, "page": [], })) .expect("a synthetic definition") } /// GUARD (architect, T8): a tool a person imports with a person link is /// moved by a merge with no code change — its storage is `cotton_`. #[test] fn an_imported_tables_person_link_is_moved_with_no_code_change() { let definition = imported(json!([ { "key": "name", "type": "text" }, { "key": "patient", "type": "link", "link_to": "person" }, { "key": "referrer", "type": "link", "link_to": "person" }, { "key": "ward", "type": "link", "link_to": "ward" }, ])); let repoints = person_repoints(&[definition]).expect("derives"); let first: Vec<(String, PersonRepointKind, bool)> = repoints .iter() .take(2) .map(|r| (format!("{}.{}", r.table, r.column), r.kind, r.workspace_scoped)) .collect(); assert_eq!( first, [ ("cotton_clinic_patient.patient".to_string(), PersonRepointKind::Column, true), ("cotton_clinic_patient.referrer".to_string(), PersonRepointKind::Column, true), ] ); assert_eq!(repoints.len(), 2 + PERSON_STORAGE_REPOINTS.len()); } /// A repoint nobody can explain is a repoint nobody can review. #[test] fn carries_a_written_reason_for_every_entry() { for repoint in shipped_repoints() { assert!(repoint.reason.len() > 20, "{}.{} has no reason", repoint.table, repoint.column); } for (table, key, reason) in PERSON_LINKS_NOT_REPOINTED { assert!(reason.len() > 20, "{table}.{key} has no reason"); } } #[test] fn never_names_the_same_table_column_twice() { let keys = keys(&shipped_repoints()); let unique: std::collections::BTreeSet<&String> = keys.iter().collect(); assert_eq!(unique.len(), keys.len()); } /// The four kinds' wire strings, which the executor branches on. #[test] fn the_repoint_kinds_carry_the_typescripts_own_strings() { assert_eq!( serde_json::to_value(PersonRepointKind::Column).expect("serialisable"), json!("column") ); assert_eq!( serde_json::to_value(PersonRepointKind::ProjectLinks).expect("serialisable"), json!("project_links") ); assert_eq!( serde_json::to_value(PersonRepointKind::Links).expect("serialisable"), json!("links") ); assert_eq!( serde_json::to_value(PersonRepointKind::Comments).expect("serialisable"), json!("comments") ); } // ── Node vectors ───────────────────────────────────────────────────────────── // // Generated by running the TypeScript itself: // cd packages/core && npx tsx /vec_person_merge.ts // Every expected string below is what Node printed. /// Nine comment bodies. The interesting half is the ESCAPING: the sentence's /// own interpolation of `full_name` is raw (a quote in a name lands unescaped /// in the prose), while the card that follows it is `JSON.stringify`d — so one /// body can carry the same name spelled both ways. #[test] fn the_comment_body_matches_node_vectors() { let cases: Vec<(PersonMergeInput, &str)> = vec![ ( PersonMergeInput { id: "p_dup".into(), full_name: "Dr. Meera".into(), ..person() }, "Merged in the duplicate person \"Dr. Meera\". Their card before the merge: {\"id\":\"p_dup\",\"name\":\"Dr. Meera\"}", ), ( PersonMergeInput { id: "p_dup".into(), full_name: "Meera \"Mimi\"\nSharma".into(), summary: Some("Line one\tLine two".into()), ..person() }, "Merged in the duplicate person \"Meera \"Mimi\"\nSharma\". Their card before the merge: {\"id\":\"p_dup\",\"name\":\"Meera \\\"Mimi\\\"\\nSharma\",\"summary\":\"Line one\\tLine two\"}", ), ( PersonMergeInput { id: "p_dup".into(), full_name: "Meera \u{1f389}".into(), city: Some("Pune".into()), ..person() }, "Merged in the duplicate person \"Meera \u{1f389}\". Their card before the merge: {\"id\":\"p_dup\",\"name\":\"Meera \u{1f389}\",\"city\":\"Pune\"}", ), ( PersonMergeInput { id: "p_dup".into(), full_name: "\u{738b}\u{5c0f}\u{660e}".into(), org: Some("\u{6771}\u{4eac}".into()), ..person() }, "Merged in the duplicate person \"\u{738b}\u{5c0f}\u{660e}\". Their card before the merge: {\"id\":\"p_dup\",\"name\":\"\u{738b}\u{5c0f}\u{660e}\",\"org\":\"\u{6771}\u{4eac}\"}", ), ( PersonMergeInput { id: "p_dup".into(), full_name: "Dr. Meera".into(), phones: text(&["918888777666", "919900112233"]), emails: text(&["dr.meera@clinic.example"]), org: Some("The Clinic".into()), role_title: Some("Doctor".into()), city: Some("Pune".into()), timezone: Some("Asia/Kolkata".into()), birth_month: Some(3), birth_day: Some(14), birth_year: Some(1984), summary: Some("Runs the clinic.".into()), ..person() }, "Merged in the duplicate person \"Dr. Meera\". Their card before the merge: {\"id\":\"p_dup\",\"name\":\"Dr. Meera\",\"phones\":[\"918888777666\",\"919900112233\"],\"emails\":[\"dr.meera@clinic.example\"],\"org\":\"The Clinic\",\"roleTitle\":\"Doctor\",\"city\":\"Pune\",\"timezone\":\"Asia/Kolkata\",\"birthday\":{\"month\":3,\"day\":14,\"year\":1984},\"summary\":\"Runs the clinic.\"}", ), ( PersonMergeInput { id: "p_dup".into(), full_name: "Meera".into(), birth_month: Some(3), birth_day: Some(14), ..person() }, "Merged in the duplicate person \"Meera\". Their card before the merge: {\"id\":\"p_dup\",\"name\":\"Meera\",\"birthday\":{\"month\":3,\"day\":14}}", ), // Every empty string is FALSY in JavaScript, so a blank org, city or // summary is omitted exactly as a null one is. ( PersonMergeInput { id: "p_dup".into(), full_name: "Meera".into(), org: Some(String::new()), city: Some(String::new()), summary: Some(String::new()), ..person() }, "Merged in the duplicate person \"Meera\". Their card before the merge: {\"id\":\"p_dup\",\"name\":\"Meera\"}", ), // The MONTH gates the trio, so a null day rides along as null. ( PersonMergeInput { id: "p_dup".into(), full_name: "Meera".into(), birth_month: Some(3), ..person() }, "Merged in the duplicate person \"Meera\". Their card before the merge: {\"id\":\"p_dup\",\"name\":\"Meera\",\"birthday\":{\"month\":3,\"day\":null}}", ), ( PersonMergeInput { id: "p_dup".into(), full_name: "Meera \\ Sharma <&>".into(), role_title: Some("A/B".into()), ..person() }, "Merged in the duplicate person \"Meera \\ Sharma <&>\". Their card before the merge: {\"id\":\"p_dup\",\"name\":\"Meera \\\\ Sharma <&>\",\"roleTitle\":\"A/B\"}", ), ]; for (duplicate, expected) in cases { let got = plan(survivor_of(), duplicate.clone()); assert_eq!( got.preserving_comment.expect("a comment").body.say(&[]), expected, "for {:?}", duplicate.full_name ); } } /// Four refusal sentences. Note the ungrammatical "a advance" — the TypeScript /// writes "a" unconditionally and the port keeps the wart rather than /// improving a message the tests and the app both compare against. #[test] fn the_claim_refusal_matches_node_vectors() { let cases: [(&[&str], &str); 4] = [ ( &["receivable"], "both people hold a receivable money account — merge is refused until the owner resolves the money side in the app", ), ( &["loan", "receivable"], "both people hold a loan and a receivable money account — merge is refused until the owner resolves the money side in the app", ), ( &["receivable", "payable", "loan"], "both people hold a receivable and a payable and a loan money account — merge is refused until the owner resolves the money side in the app", ), ( &["advance"], "both people hold a advance money account — merge is refused until the owner resolves the money side in the app", ), ]; for (colliding, expected) in cases { assert_eq!(PersonMergeRefusal::SharedClaims { subtypes: text(colliding) }.say(&[]), expected); } } /// Four archive stamps, each read back out of Node's `toISOString`. #[test] fn the_archive_stamp_matches_node_vectors() { for iso in [ "2026-09-05T10:30:00.000Z", "1970-01-01T00:00:00.000Z", "2026-12-31T23:59:59.999Z", "1999-06-30T12:00:00.500Z", ] { let ms = parse_date_ms(iso).expect("an ISO instant"); let got = plan_person_merge(&survivor_of(), &duplicate_of(), ms, &no_claims()) .expect("a renderable instant"); assert_eq!( got.archive_duplicate, Some(PersonMergeArchive { archived_at: iso.to_string() }) ); } } /// The patch is stored as JSON, so its KEY ORDER is observable. This is the /// order `Object.keys` reported for a duplicate that fills every field. #[test] fn the_union_patch_key_order_matches_node() { let got = plan( survivor_of(), PersonMergeInput { phones: text(&["1"]), emails: text(&["a@b.c"]), org: Some("O".into()), role_title: Some("R".into()), city: Some("C".into()), timezone: Some("T".into()), birth_month: Some(1), birth_day: Some(2), birth_year: Some(3), summary: Some("S".into()), summary_by: Some("server".into()), summary_updated_at: Some("2026-01-01T00:00:00.000Z".into()), avatar_key: Some("k".into()), ..duplicate_of() }, ); assert_eq!( got.survivor_patch.keys().collect::>(), [ "org", "role_title", "city", "timezone", "birth_month", "birth_day", "birth_year", "summary", "summary_by", "summary_updated_at", "avatar_key", ] ); }