@htilabs/platform-common-models 0.12.0 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist/config/index.cjs +0 -81
  2. package/dist/config/index.cjs.map +1 -1
  3. package/dist/config/index.d.cts +4 -79
  4. package/dist/config/index.d.ts +4 -79
  5. package/dist/config/index.js +1 -79
  6. package/dist/config/index.js.map +1 -1
  7. package/dist/constants/index.cjs +18 -2
  8. package/dist/constants/index.cjs.map +1 -1
  9. package/dist/constants/index.d.cts +1 -1
  10. package/dist/constants/index.d.ts +1 -1
  11. package/dist/constants/index.js +18 -2
  12. package/dist/constants/index.js.map +1 -1
  13. package/dist/cvc-Cp4uWnAa.d.cts +298 -0
  14. package/dist/cvc-Cp4uWnAa.d.ts +298 -0
  15. package/dist/{cvcEntry-BCj1OWqL.d.cts → cvcEntry-ctHTp2df.d.cts} +44 -44
  16. package/dist/{cvcEntry-BCj1OWqL.d.ts → cvcEntry-ctHTp2df.d.ts} +44 -44
  17. package/dist/cvcs/index.cjs +8065 -1384
  18. package/dist/cvcs/index.cjs.map +1 -1
  19. package/dist/cvcs/index.d.cts +15287 -8079
  20. package/dist/cvcs/index.d.ts +15287 -8079
  21. package/dist/cvcs/index.js +8052 -1384
  22. package/dist/cvcs/index.js.map +1 -1
  23. package/dist/enums/index.cjs +4573 -0
  24. package/dist/enums/index.cjs.map +1 -0
  25. package/dist/enums/index.d.cts +5277 -0
  26. package/dist/enums/index.d.ts +5277 -0
  27. package/dist/enums/index.js +4369 -0
  28. package/dist/enums/index.js.map +1 -0
  29. package/dist/{index-I-DiX9eQ.d.ts → index-4DiJrn7y.d.ts} +1 -1
  30. package/dist/{index-CoVr1jIV.d.cts → index-qreOzXYS.d.cts} +1 -1
  31. package/dist/index.cjs +8616 -1389
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.cts +7 -4700
  34. package/dist/index.d.ts +7 -4700
  35. package/dist/index.js +8590 -1389
  36. package/dist/index.js.map +1 -1
  37. package/dist/models/index.d.cts +2 -2
  38. package/dist/models/index.d.ts +2 -2
  39. package/dist/mongo/index.cjs +0 -1
  40. package/dist/mongo/index.cjs.map +1 -1
  41. package/dist/mongo/index.js +1 -2
  42. package/dist/mongo/index.js.map +1 -1
  43. package/dist/{platform-auth-v53r3BhN.d.cts → platform-auth-Dv5fu0Fh.d.cts} +5 -4
  44. package/dist/{platform-auth-v53r3BhN.d.ts → platform-auth-Dv5fu0Fh.d.ts} +5 -4
  45. package/dist/schemas/index.cjs +5 -1
  46. package/dist/schemas/index.cjs.map +1 -1
  47. package/dist/schemas/index.d.cts +35 -35
  48. package/dist/schemas/index.d.ts +35 -35
  49. package/dist/schemas/index.js +5 -1
  50. package/dist/schemas/index.js.map +1 -1
  51. package/dist/types/index.d.cts +2 -2
  52. package/dist/types/index.d.ts +2 -2
  53. package/dist/validation/index.cjs +58 -0
  54. package/dist/validation/index.cjs.map +1 -1
  55. package/dist/validation/index.d.cts +82 -283
  56. package/dist/validation/index.d.ts +82 -283
  57. package/dist/validation/index.js +57 -0
  58. package/dist/validation/index.js.map +1 -1
  59. package/package.json +32 -22
  60. package/src/__sot__/README.md +36 -1
  61. package/src/__sot__/coreIndicatorFields.ts +331 -0
  62. package/src/__sot__/coreIndicators.pin.json +1936 -2
  63. package/src/__sot__/cvcIndex.pin.json +8 -4
  64. package/src/__tests__/__snapshots__/cvc-sot.snap +45 -13
  65. package/src/__tests__/core-information-scope-invariant.test.ts +134 -0
  66. package/src/__tests__/cvc-136-scoring-invariant.test.ts +8 -3
  67. package/src/__tests__/cvc-181-182-country-parity.test.ts +163 -0
  68. package/src/__tests__/cvc-drift-gate.test.ts +463 -12
  69. package/src/__tests__/cvc-sot-snapshot.test.ts +81 -11
  70. package/src/__tests__/cvc-status-parser.test.ts +150 -0
  71. package/src/__tests__/cvc-structural.test.ts +16 -0
  72. package/src/__tests__/runtime-contract-validator.test.ts +1 -325
  73. package/src/__tests__/share-response-reason-invariant.test.ts +167 -0
  74. package/src/config/index.ts +4 -189
  75. package/src/constants/ic.ts +120 -3
  76. package/src/cvcs/assertionDomain.v1.1.0.json +19 -1
  77. package/src/cvcs/assertionStatus.v1.0.0.json +80 -0
  78. package/src/cvcs/carCorrectionReason.v1.0.0.json +89 -0
  79. package/src/cvcs/caseShareState.v1.0.0.json +62 -0
  80. package/src/cvcs/coreIndicators.v1.0.0.json +83 -5
  81. package/src/cvcs/coreInformationScope.v1.0.0.json +1165 -0
  82. package/src/cvcs/countries.v1.0.0.json +3077 -0
  83. package/src/cvcs/createdBySystem.v1.0.0.json +89 -0
  84. package/src/cvcs/criminalOrgCategory.v1.0.0.json +116 -0
  85. package/src/cvcs/determinationHelperCategories.v1.0.0.json +1166 -0
  86. package/src/cvcs/incidentParticipationRoles.v1.0.0.json +11 -1
  87. package/src/cvcs/index.ts +36 -0
  88. package/src/cvcs/minorAdultStatus.v1.0.0.json +80 -0
  89. package/src/cvcs/personRelationships.v1.0.0.json +67 -2
  90. package/src/cvcs/referralOrigin.v1.0.0.json +26 -0
  91. package/src/cvcs/relationshipConcern.v1.0.0.json +28 -19
  92. package/src/cvcs/riskIdentificationMilestone.v1.0.0.json +109 -0
  93. package/src/cvcs/sessionTemplate.v1.0.0.json +22 -0
  94. package/src/cvcs/sharePurpose.v1.0.0.json +80 -12
  95. package/src/cvcs/shareResponseReason.v1.0.0.json +220 -0
  96. package/src/cvcs/subjectType.v1.0.0.json +80 -0
  97. package/src/generated/cvc-enums.ts +628 -20
  98. package/src/validation/cvcStatus.ts +209 -0
  99. package/src/validation/index.ts +1 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sourceRepo": "htilabstech/prototype",
3
3
  "sourceFile": "Final CVCs/CVC_INDEX.md",
4
- "sourceSha": "a596eb9",
4
+ "sourceSha": "622410b",
5
5
  "numbers": {
6
6
  "1": [
7
7
  "core - name_type"
@@ -59,6 +59,12 @@
59
59
  "85": [
60
60
  "core - share_cadence"
61
61
  ],
62
+ "93": [
63
+ "core - child_welfare_involvement_status"
64
+ ],
65
+ "95": [
66
+ "core - juvenile_justice_involvement_status"
67
+ ],
62
68
  "96": [
63
69
  "core - homeless_status"
64
70
  ],
@@ -187,7 +193,6 @@
187
193
  "core - frequency : cadence"
188
194
  ],
189
195
  "177": [
190
- "core - administering jurisdiction",
191
196
  "core - administering_jurisdiction"
192
197
  ],
193
198
  "179": [
@@ -219,8 +224,7 @@
219
224
  "core collection context"
220
225
  ],
221
226
  "196": [
222
- "core child welfare cvc",
223
- "core child welfare episode type CVC"
227
+ "core - child_welfare_episode_type"
224
228
  ],
225
229
  "197": [
226
230
  "core - juvenile_justice_episode_type"
@@ -15,8 +15,8 @@
15
15
  "hash": "68c5fee27fb5826ed86ff8e9387ec00ae8813029c87f9d5349c7ce2d5c640eaf"
16
16
  },
17
17
  "incident_participation_roles": {
18
- "count": 19,
19
- "hash": "ccf9a360f09fbf58f93b92bed296d16678ff8c8955088407d2e641d6d9d72ba3"
18
+ "count": 20,
19
+ "hash": "bb891d1159a0e70b19ec485459f9778aa2c86a00009bf5e2259290a8ddf41a10"
20
20
  },
21
21
  "incident_involvement_roles": {
22
22
  "count": 10,
@@ -99,8 +99,8 @@
99
99
  "hash": "c3fcaec7ef08f185748463adc1e73dc6a1ff196601f16a6453f737577f3dfd90"
100
100
  },
101
101
  "share_purpose": {
102
- "count": 8,
103
- "hash": "ccefed1af82759ca59ad45e3850119db87e3411db57d9ce3039d874474498422"
102
+ "count": 12,
103
+ "hash": "a3ecb1ffab4f32c5cd19afbc43278f0de0538c608464ae434595a7ff98552f65"
104
104
  },
105
105
  "facilitator_entity_type": {
106
106
  "count": 14,
@@ -147,8 +147,8 @@
147
147
  "hash": "29fb041c4d1b40260e4a448a0501eb580d29606479628a6807a833b52212f3c3"
148
148
  },
149
149
  "person_relationships": {
150
- "count": 89,
151
- "hash": "f901a60ec1f275e2f003d1f1f2f94f2a3ae07d7badee227d650c28c00a1510bb"
150
+ "count": 94,
151
+ "hash": "15b9d1989b897723881cdb489026fab9c42eb9fe0b809f349ec027e42ca7b154"
152
152
  },
153
153
  "employment_status": {
154
154
  "count": 29,
@@ -500,7 +500,7 @@
500
500
  },
501
501
  "relationship_concern": {
502
502
  "count": 11,
503
- "hash": "03e18352e1ffb13a4e9b63e1f4043923f1da7e0153649db6940d0bb2653917d8"
503
+ "hash": "48e882447e87dd4342afc4c9b56aff3925f10177e7ea214dca5d5f66c09e5668"
504
504
  },
505
505
  "recency_band": {
506
506
  "count": 12,
@@ -511,8 +511,8 @@
511
511
  "hash": "995a3170efe8219c0bfe0a174abb2389c86bf94423a70a5ce2b2feb3d9e6b3fa"
512
512
  },
513
513
  "assertion_domain": {
514
- "count": 68,
515
- "hash": "6076e65b804f6e7d3b8385fecfb5114b710ecf672ca13d1e97e5fe0e412b1041"
514
+ "count": 70,
515
+ "hash": "6b10f093870817757f4dcb45a513b347f0491ae3ca08c518e3c88df52cd48fdb"
516
516
  },
517
517
  "activity_type": {
518
518
  "count": 14,
@@ -599,8 +599,8 @@
599
599
  "hash": "90aec290aa586a9bbc098c0c8a19536e06b705b054e4444ff6461a9913340a5c"
600
600
  },
601
601
  "core_indicators": {
602
- "count": 214,
603
- "hash": "401f8c604a63a94e63569cbed9e1ae2e80bedb5e29ffcff4b40af3ce9f75b7b9"
602
+ "count": 220,
603
+ "hash": "634ba69f31273bace3c3be9509aba41f4c348086210905e42a6f97d393c64fbb"
604
604
  },
605
605
  "risk_severity_band": {
606
606
  "count": 9,
@@ -651,8 +651,8 @@
651
651
  "hash": "53a0ad169d2e5ff34ffa9b246eacbde2efb9b31baf763bfa1d3be53f0fbedd3c"
652
652
  },
653
653
  "session_template": {
654
- "count": 23,
655
- "hash": "c6e7ec45ab8c3d99e938ac55b1007107edee5885bff53f203945ed3a6cba25ac"
654
+ "count": 25,
655
+ "hash": "f8e4b1830fb03f82499c10eb84b2202c7a3258832fec64fc73c17a734de24ece"
656
656
  },
657
657
  "service_delivery_channel": {
658
658
  "count": 11,
@@ -666,9 +666,41 @@
666
666
  "count": 253,
667
667
  "hash": "83962425a6a987b46bd89f596feefe5758f25993137010bb417823b83c4ae31f"
668
668
  },
669
+ "countries": {
670
+ "count": 254,
671
+ "hash": "21525c56d5bac7f218bcb9a5dc048eea4b9132cfaf4a6a7439ebbf7dd34ebcde"
672
+ },
673
+ "determination_helper_categories": {
674
+ "count": 57,
675
+ "hash": "9e296ba8ae3a187171eb8facfd13a5e6824daa0ed7f963e41e31672104aa16c0"
676
+ },
677
+ "share_response_reason": {
678
+ "count": 12,
679
+ "hash": "cf4fc986c61ecf896738374844dda337891fc5c6590cfb219d9472d6cc8cee73"
680
+ },
669
681
  "trafficking_relevant_role": {
670
682
  "count": 8,
671
683
  "hash": "1a4ea2992cc501179adafd192d7a2f1733ffe48c1ba26e1e61a3c757b2d62b32"
684
+ },
685
+ "assertion_status": {
686
+ "count": 7,
687
+ "hash": "a1914348815dabc7171ed4ea632383d39f31764d390c43d6b1d359eae465807f"
688
+ },
689
+ "car_correction_reason": {
690
+ "count": 8,
691
+ "hash": "6ad10301ca7759bbda822b44a251208826b8880dff8d085ce501bc1faedc69d8"
692
+ },
693
+ "created_by_system": {
694
+ "count": 8,
695
+ "hash": "35ea022a704b4eee7b493ea3c9a8a5d2ffa41c4cacbe9f899cc1336e73808fc2"
696
+ },
697
+ "subject_type": {
698
+ "count": 7,
699
+ "hash": "81ad6c7fbb74bbb6d9c6f316df3275fd57a1646dedb4fb47472ee77fb2482f99"
700
+ },
701
+ "minor_adult_status": {
702
+ "count": 7,
703
+ "hash": "9d8972c65373a9981aab6b8749661659ecc632004e67bc9c2b3c88aa76f30977"
672
704
  }
673
705
  }
674
706
  }
@@ -0,0 +1,134 @@
1
+ /**
2
+ * CORE INFORMATION SCOPE (CVC-236) — the invariants adoption depends on
3
+ * ==================================================================
4
+ *
5
+ * Two vocabularies describe the same thing at different grains:
6
+ *
7
+ * `roi_scope` flat item vocabulary, 27 substantive keys, no category axis
8
+ * `core_information_scope` 12 policy-grain CATEGORIES + 54 authorization-grain UNITS
9
+ *
10
+ * PAVE and Thread are both pinned to `roi_scope` today, and both persist stored
11
+ * ROIs against it. Migrating them to this domain is safe for exactly one reason:
12
+ * every substantive `roi_scope` key survives here, spelled identically, so a
13
+ * stored ROI keeps its exact recorded meaning. That is not a nice-to-have — an
14
+ * ROI whose meaning widens is a CONSENT change wearing a data change's clothes,
15
+ * and one already shipped on the CaseShare lane when a coarse->granular table
16
+ * expanded `caseNotes` to include screening notes the survivor never authorized.
17
+ *
18
+ * So the subset property below is the whole basis for calling adoption additive.
19
+ * If it ever fails, adoption stops being a migration and becomes a re-consent.
20
+ *
21
+ * The grain invariants matter for a different reason: canon states that
22
+ * categories are the POLICY grain and units are the AUTHORIZATION grain. A
23
+ * selectable category would let a policy row be cited as if it were consent.
24
+ */
25
+
26
+ import { readFileSync } from "node:fs";
27
+ import path from "node:path";
28
+ import { fileURLToPath } from "node:url";
29
+
30
+ import { describe, it, expect } from "vitest";
31
+
32
+ const here = path.dirname(fileURLToPath(import.meta.url));
33
+ const cvcDir = path.join(here, "..", "cvcs");
34
+
35
+ interface Entry {
36
+ code: string;
37
+ key: string;
38
+ selectable: boolean;
39
+ parentCode: string | null;
40
+ childCodes: string[];
41
+ shareableDefault?: boolean;
42
+ required?: boolean;
43
+ platformFloor?: boolean;
44
+ }
45
+
46
+ const read = (f: string): { entries: Entry[]; levels: Record<string, string> } =>
47
+ JSON.parse(readFileSync(path.join(cvcDir, f), "utf8")) as {
48
+ entries: Entry[];
49
+ levels: Record<string, string>;
50
+ };
51
+
52
+ const scope = read("coreInformationScope.v1.0.0.json");
53
+ const roi = read("roiScope.v1.0.0.json");
54
+
55
+ const byCode = new Map(scope.entries.map((e) => [e.code, e]));
56
+ const MISSINGNESS = new Set([
57
+ "missingness_root",
58
+ "unknown",
59
+ "anonymous",
60
+ "data_not_collected",
61
+ ]);
62
+
63
+ const isMissingness = (e: Entry): boolean =>
64
+ MISSINGNESS.has(e.key) ||
65
+ (e.parentCode !== null && byCode.get(e.parentCode)?.key === "missingness_root");
66
+
67
+ const categories = scope.entries.filter(
68
+ (e) => e.parentCode === null && !isMissingness(e),
69
+ );
70
+ const units = scope.entries.filter(
71
+ (e) => e.parentCode !== null && !isMissingness(e),
72
+ );
73
+
74
+ describe("core_information_scope — adoption invariants", () => {
75
+ it("carries every substantive roi_scope key, spelled identically", () => {
76
+ const roiSubstantive = roi.entries
77
+ .map((e) => e.key)
78
+ .filter((k) => !MISSINGNESS.has(k));
79
+ const unitKeys = new Set(units.map((u) => u.key));
80
+ const missing = roiSubstantive.filter((k) => !unitKeys.has(k));
81
+
82
+ // A failure here means a stored ROI can no longer be expressed in the new
83
+ // vocabulary — re-consent, not migration.
84
+ expect(missing).toEqual([]);
85
+ expect(roiSubstantive.length).toBe(27);
86
+ });
87
+
88
+ it("is a strict superset — the additions are additions, not renames", () => {
89
+ expect(units.length).toBeGreaterThan(27);
90
+ expect(units).toHaveLength(54);
91
+ });
92
+
93
+ it("keeps the two grains distinct: categories decide policy, units carry consent", () => {
94
+ expect(categories).toHaveLength(12);
95
+ expect(categories.every((c) => c.selectable === false)).toBe(true);
96
+ expect(units.every((u) => u.selectable === true)).toBe(true);
97
+ });
98
+
99
+ it("wires every unit to exactly one category, reciprocally", () => {
100
+ for (const u of units) {
101
+ const parent = byCode.get(u.parentCode as string);
102
+ expect(parent, `unit ${u.key} has a dangling parent`).toBeDefined();
103
+ expect(parent?.selectable, `unit ${u.key} hangs off a selectable row`).toBe(
104
+ false,
105
+ );
106
+ expect(parent?.childCodes, `category ${parent?.key} disowns ${u.key}`).toContain(
107
+ u.code,
108
+ );
109
+ }
110
+ expect(categories.flatMap((c) => c.childCodes)).toHaveLength(units.length);
111
+ });
112
+
113
+ it("publishes the posture sets as data, so they stop being literals", () => {
114
+ const of = (p: (u: Entry) => boolean): string[] =>
115
+ units.filter(p).map((u) => u.key).sort();
116
+
117
+ // shareable_default:false — the picker must not pre-check these.
118
+ expect(of((u) => u.shareableDefault === false)).toEqual([
119
+ "federal_protection_applications",
120
+ "hiv_status",
121
+ "immigration_status",
122
+ "le_report_status",
123
+ "safe_locations",
124
+ "tvap_enrollment",
125
+ "uscis_alien_number",
126
+ ]);
127
+
128
+ // The platform safety floor — enforceable BELOW the scope layer.
129
+ expect(of((u) => u.platformFloor === true)).toEqual(["safe_locations"]);
130
+
131
+ // Always included; currently a hardcoded string in both apps.
132
+ expect(of((u) => u.required === true)).toEqual(["system_info"]);
133
+ });
134
+ });
@@ -261,9 +261,14 @@ describe("CVC-136 core_indicators", () => {
261
261
  ]);
262
262
  });
263
263
 
264
- it("has exactly 210 substantive codes (208 canonical + 2 scoring-ahead)", () => {
265
- expect(substantive.length).toBe(210);
266
- expect(envelope.entries.length).toBe(214);
264
+ it("has exactly 216 substantive codes (214 canonical + 2 scoring-ahead)", () => {
265
+ // 0.8.14 refreshed the catalog pin a596eb9 (208) -> 84a1b67 (213):
266
+ // +5 upstream mints, 0 withdrawn.
267
+ // This refresh took it again 84a1b67 (213) -> 622410b (214): +1 upstream
268
+ // mint (`active_protective_order`, minted 2026-08-08), 0 withdrawn. The 2
269
+ // scoring-ahead codes are unchanged and still absent upstream.
270
+ expect(substantive.length).toBe(216);
271
+ expect(envelope.entries.length).toBe(220);
267
272
  });
268
273
 
269
274
  it("has no duplicate keys", () => {
@@ -0,0 +1,163 @@
1
+ /**
2
+ * CVC-181 `countries` <-> CVC-182 `citizenship` — the country-set parity lock
3
+ * ==========================================================================
4
+ *
5
+ * Two canonical codebooks enumerate the SAME 249 ISO 3166-1 countries:
6
+ *
7
+ * `core - countries` (CVC-181) the neutral entity list. Its own `.md` says it is
8
+ * "designed for use across multiple contexts (e.g.
9
+ * country of citizenship, country of origin, or
10
+ * country of residence)".
11
+ * `core - citizenship` (CVC-182) the citizenship-flavoured list, authored first
12
+ * (0.8.13) because CVC-181 was unpublished.
13
+ *
14
+ * Consumers bound to CVC-182 as a DRAFT stand-in for birth country must be able to
15
+ * re-point at CVC-181 as an import swap with **zero key renames** — that is the whole
16
+ * reason CVC-181 was minted from a key derivation identical to CVC-182's rather than a
17
+ * fresh one. This test is that promise, made falsifiable. If it fails, the re-point is
18
+ * a data migration, not an import swap, and every stored birth-country key is suspect.
19
+ *
20
+ * What it does NOT assert: positional-code parity. `181-NNN` and `182-NNN` disagree on
21
+ * 20 countries because the two upstream exports sort under different collations, and
22
+ * each domain is deliberately minted in ITS OWN codebook's row order so each stays
23
+ * reproducible from its own source. The KEY is the reconciliation axis (consumers
24
+ * persist keys, not wire codes). The last assertion below pins that divergence in place
25
+ * so nobody "fixes" it into a silent renumber, and so nobody writes
26
+ * `"181-" + code.slice(4)` believing the two are interchangeable.
27
+ */
28
+
29
+ import { readFileSync } from "node:fs";
30
+ import path from "node:path";
31
+ import { fileURLToPath } from "node:url";
32
+
33
+ import { describe, it, expect } from "vitest";
34
+
35
+ const here = path.dirname(fileURLToPath(import.meta.url));
36
+ const cvcDir = path.join(here, "..", "cvcs");
37
+
38
+ interface Entry {
39
+ code: string;
40
+ key: string;
41
+ title: string;
42
+ selectable: boolean;
43
+ definition: string | null;
44
+ iso31661Alpha2?: string | null;
45
+ priority?: boolean;
46
+ canonicalLabel?: string | null;
47
+ localExtension?: boolean;
48
+ }
49
+
50
+ const read = (f: string): { domain: string; entries: Entry[] } =>
51
+ JSON.parse(readFileSync(path.join(cvcDir, f), "utf8")) as {
52
+ domain: string;
53
+ entries: Entry[];
54
+ };
55
+
56
+ const countries = read("countries.v1.0.0.json");
57
+ const citizenship = read("citizenship.v1.0.0.json");
58
+
59
+ const isMissingness = (e: Entry): boolean => e.code.split("-")[1] === "000";
60
+ const substantive = (d: { entries: Entry[] }): Entry[] =>
61
+ d.entries.filter((e) => !isMissingness(e));
62
+
63
+ /** The 10 PRIORITY_COUNTRIES of the canonical prototype HTML, by ISO alpha-2. */
64
+ const PRIORITY_ISO = ["CN", "CU", "DO", "GT", "IN", "KR", "MX", "PH", "SV", "VN"];
65
+
66
+ describe("CVC-181 / CVC-182 country parity", () => {
67
+ it("both domains carry the identical 249 country key -> ISO map", () => {
68
+ const map = (d: { entries: Entry[] }): Record<string, string> =>
69
+ Object.fromEntries(
70
+ d.entries
71
+ .filter((e) => e.iso31661Alpha2)
72
+ .map((e) => [e.key, e.iso31661Alpha2!]),
73
+ );
74
+ const a = map(countries);
75
+ const b = map(citizenship);
76
+ expect(Object.keys(a).length, "CVC-181 ISO-coded leaves").toBe(249);
77
+ expect(Object.keys(b).length, "CVC-182 ISO-coded leaves").toBe(249);
78
+ expect(a).toEqual(b);
79
+ });
80
+
81
+ it("CVC-181 adds EXACTLY ONE substantive leaf over CVC-182: non_us_unspecified", () => {
82
+ const a = new Set(substantive(countries).map((e) => e.key));
83
+ const b = new Set(substantive(citizenship).map((e) => e.key));
84
+ const added = [...a].filter((k) => !b.has(k)).sort();
85
+ const dropped = [...b].filter((k) => !a.has(k)).sort();
86
+ expect(added, "substantive keys CVC-181 has that CVC-182 does not").toEqual([
87
+ "non_us_unspecified",
88
+ ]);
89
+ expect(dropped, "substantive keys CVC-182 has that CVC-181 does not").toEqual([]);
90
+ });
91
+
92
+ it("non_us_unspecified is a FLAGGED local extension, not a smuggled canonical value", () => {
93
+ // The escape hatch is guarded the way GATE B guards SCORING_AHEAD_OF_CATALOG:
94
+ // a codebook-absent leaf must announce itself, or the next verification run
95
+ // cannot tell an upstream gap from a platform-common invention.
96
+ const e = countries.entries.find((x) => x.key === "non_us_unspecified");
97
+ expect(e, "non_us_unspecified must exist").toBeDefined();
98
+ expect(e!.localExtension, "must carry localExtension: true").toBe(true);
99
+ expect(e!.definition ?? "").toMatch(/^LOCAL EXTENSION \(not in canonical CVC-181\)\./);
100
+ expect(e!.selectable).toBe(true);
101
+ expect(e!.iso31661Alpha2 ?? null, "a non-country leaf carries no ISO code").toBeNull();
102
+ // It is the ONLY local extension in this domain.
103
+ expect(countries.entries.filter((x) => x.localExtension).map((x) => x.key)).toEqual([
104
+ "non_us_unspecified",
105
+ ]);
106
+ });
107
+
108
+ it("CVC-181 priority flags are EXACTLY the canonical PRIORITY_COUNTRIES, and no sentinel", () => {
109
+ const flagged = countries.entries.filter((e) => e.priority);
110
+ expect(flagged.map((e) => e.iso31661Alpha2).sort()).toEqual([...PRIORITY_ISO].sort());
111
+ // CVC-182 additionally flags `unknown` + `anonymous` because ITS codebook has a
112
+ // Priority column that says Yes on those rows. CVC-181's codebook has no Priority
113
+ // column at all, and PRIORITY_COUNTRIES contains countries only — so flagging a
114
+ // sentinel here would be an invention. The COUNTRY flags must still agree.
115
+ expect(flagged.every((e) => !isMissingness(e)), "no missingness sentinel is priority").toBe(
116
+ true,
117
+ );
118
+ const flaggedCountryKeys = (d: { entries: Entry[] }): string[] =>
119
+ d.entries
120
+ .filter((e) => e.priority && e.iso31661Alpha2)
121
+ .map((e) => e.key)
122
+ .sort();
123
+ expect(flaggedCountryKeys(countries)).toEqual(flaggedCountryKeys(citizenship));
124
+ });
125
+
126
+ it("positional ordinals deliberately DIVERGE on 20 countries — reconcile by key, not by code", () => {
127
+ const ordinals = (d: { entries: Entry[] }): Map<string, string> =>
128
+ new Map(
129
+ d.entries.filter((e) => e.iso31661Alpha2).map((e) => [e.key, e.code.split("-")[1]!]),
130
+ );
131
+ const a = ordinals(countries);
132
+ const b = ordinals(citizenship);
133
+ const divergent = [...a.keys()].filter((k) => a.get(k) !== b.get(k)).sort();
134
+ expect(
135
+ divergent.length,
136
+ "if this changes, one of the two domains was renumbered — that is a wire-format " +
137
+ "change and needs its own decision, not a silent regeneration",
138
+ ).toBe(20);
139
+ // All 20 are adjacent-pair swaps between the two upstream sort collations.
140
+ expect(divergent).toEqual([
141
+ "germany",
142
+ "ghana",
143
+ "isle_of_man",
144
+ "israel",
145
+ "japan",
146
+ "jersey",
147
+ "lao_people_s_democratic_republic",
148
+ "latvia",
149
+ "rwanda",
150
+ "saint_barthelemy",
151
+ "seychelles",
152
+ "sierra_leone",
153
+ "south_sudan",
154
+ "spain",
155
+ "sweden",
156
+ "switzerland",
157
+ "tanzania_united_republic_of",
158
+ "thailand",
159
+ "tuvalu",
160
+ "uganda",
161
+ ]);
162
+ });
163
+ });