@htilabs/platform-common-models 0.8.24 → 0.12.0

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 (91) hide show
  1. package/dist/config/index.cjs +81 -0
  2. package/dist/config/index.cjs.map +1 -1
  3. package/dist/config/index.d.cts +79 -4
  4. package/dist/config/index.d.ts +79 -4
  5. package/dist/config/index.js +79 -1
  6. package/dist/config/index.js.map +1 -1
  7. package/dist/constants/index.cjs +2 -18
  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 +2 -18
  12. package/dist/constants/index.js.map +1 -1
  13. package/dist/{cvcEntry-ctHTp2df.d.cts → cvcEntry-BCj1OWqL.d.cts} +44 -44
  14. package/dist/{cvcEntry-ctHTp2df.d.ts → cvcEntry-BCj1OWqL.d.ts} +44 -44
  15. package/dist/cvcs/index.cjs +217 -6674
  16. package/dist/cvcs/index.cjs.map +1 -1
  17. package/dist/cvcs/index.d.cts +8057 -15024
  18. package/dist/cvcs/index.d.ts +8057 -15024
  19. package/dist/cvcs/index.js +217 -6662
  20. package/dist/cvcs/index.js.map +1 -1
  21. package/dist/{index-qreOzXYS.d.cts → index-CoVr1jIV.d.cts} +1 -1
  22. package/dist/{index-4DiJrn7y.d.ts → index-I-DiX9eQ.d.ts} +1 -1
  23. package/dist/index.cjs +230 -7217
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +26 -588
  26. package/dist/index.d.ts +26 -588
  27. package/dist/index.js +230 -7193
  28. package/dist/index.js.map +1 -1
  29. package/dist/models/index.d.cts +2 -2
  30. package/dist/models/index.d.ts +2 -2
  31. package/dist/mongo/index.cjs +1 -0
  32. package/dist/mongo/index.cjs.map +1 -1
  33. package/dist/mongo/index.js +2 -1
  34. package/dist/mongo/index.js.map +1 -1
  35. package/dist/{platform-auth-91Hcl8F8.d.cts → platform-auth-v53r3BhN.d.cts} +3 -4
  36. package/dist/{platform-auth-91Hcl8F8.d.ts → platform-auth-v53r3BhN.d.ts} +3 -4
  37. package/dist/schemas/index.cjs +1 -5
  38. package/dist/schemas/index.cjs.map +1 -1
  39. package/dist/schemas/index.d.cts +35 -35
  40. package/dist/schemas/index.d.ts +35 -35
  41. package/dist/schemas/index.js +1 -5
  42. package/dist/schemas/index.js.map +1 -1
  43. package/dist/types/index.d.cts +2 -2
  44. package/dist/types/index.d.ts +2 -2
  45. package/dist/validation/index.cjs +0 -58
  46. package/dist/validation/index.cjs.map +1 -1
  47. package/dist/validation/index.d.cts +283 -82
  48. package/dist/validation/index.d.ts +283 -82
  49. package/dist/validation/index.js +0 -57
  50. package/dist/validation/index.js.map +1 -1
  51. package/package.json +22 -26
  52. package/src/__sot__/README.md +1 -36
  53. package/src/__sot__/coreIndicators.pin.json +2 -1936
  54. package/src/__sot__/cvcIndex.pin.json +4 -8
  55. package/src/__tests__/__snapshots__/cvc-sot.snap +13 -41
  56. package/src/__tests__/cvc-136-scoring-invariant.test.ts +3 -8
  57. package/src/__tests__/cvc-drift-gate.test.ts +12 -445
  58. package/src/__tests__/cvc-sot-snapshot.test.ts +11 -73
  59. package/src/__tests__/cvc-structural.test.ts +0 -14
  60. package/src/__tests__/runtime-contract-validator.test.ts +325 -1
  61. package/src/config/index.ts +189 -4
  62. package/src/constants/ic.ts +3 -120
  63. package/src/cvcs/assertionDomain.v1.1.0.json +1 -19
  64. package/src/cvcs/coreIndicators.v1.0.0.json +5 -83
  65. package/src/cvcs/incidentParticipationRoles.v1.0.0.json +1 -11
  66. package/src/cvcs/index.ts +0 -32
  67. package/src/cvcs/personRelationships.v1.0.0.json +2 -67
  68. package/src/cvcs/relationshipConcern.v1.0.0.json +19 -28
  69. package/src/cvcs/sessionTemplate.v1.0.0.json +0 -22
  70. package/src/cvcs/sharePurpose.v1.0.0.json +12 -80
  71. package/src/generated/cvc-enums.ts +20 -606
  72. package/src/validation/index.ts +0 -1
  73. package/dist/cvc-C7qdsXYK.d.cts +0 -298
  74. package/dist/cvc-C7qdsXYK.d.ts +0 -298
  75. package/src/__sot__/coreIndicatorFields.ts +0 -331
  76. package/src/__tests__/core-information-scope-invariant.test.ts +0 -134
  77. package/src/__tests__/cvc-181-182-country-parity.test.ts +0 -163
  78. package/src/__tests__/cvc-status-parser.test.ts +0 -150
  79. package/src/cvcs/assertionStatus.v1.0.0.json +0 -80
  80. package/src/cvcs/carCorrectionReason.v1.0.0.json +0 -89
  81. package/src/cvcs/caseShareState.v1.0.0.json +0 -62
  82. package/src/cvcs/coreInformationScope.v1.0.0.json +0 -1165
  83. package/src/cvcs/countries.v1.0.0.json +0 -3077
  84. package/src/cvcs/createdBySystem.v1.0.0.json +0 -89
  85. package/src/cvcs/criminalOrgCategory.v1.0.0.json +0 -116
  86. package/src/cvcs/determinationHelperCategories.v1.0.0.json +0 -1166
  87. package/src/cvcs/minorAdultStatus.v1.0.0.json +0 -80
  88. package/src/cvcs/referralOrigin.v1.0.0.json +0 -26
  89. package/src/cvcs/riskIdentificationMilestone.v1.0.0.json +0 -109
  90. package/src/cvcs/subjectType.v1.0.0.json +0 -80
  91. package/src/validation/cvcStatus.ts +0 -209
@@ -1,331 +0,0 @@
1
- /**
2
- * THE FIELD HALF OF THE coreIndicators PIN
3
- * ========================================
4
- *
5
- * `coreIndicators.pin.json` used to carry ONLY `codes: string[]` — the sorted
6
- * SET of `code:` values in `data/core_indicators.yaml`. That made the pin, and
7
- * therefore BOTH halves of the drift contract, blind to everything else the
8
- * catalog says about an indicator. A code could keep its name while its label,
9
- * definition, family, polarity, severity, alert routing, or alert recency
10
- * window was rewritten upstream, and neither `sot:pins:check` nor `gate:cvc`
11
- * could see it.
12
- *
13
- * That blindness shipped twice, in consecutive refreshes:
14
- *
15
- * 0.8.14 — dropped a definition revision that came with the code delta.
16
- * 0.8.17 — initially dropped a LABEL RENAME and a load-bearing DEPRECATION
17
- * QUALIFIER in a definition. Caught in human review, not by CI.
18
- *
19
- * Both are the same bug: a set-of-codes pin cannot express a field revision, so
20
- * a refresh that copies the code delta and forgets the field delta passes green.
21
- *
22
- * This module is the fix. It defines the PROJECTION — the seven fields of an
23
- * indicator that platform-common actually restates in
24
- * `src/cvcs/coreIndicators.v1.0.0.json` — and the NORMALIZATION that makes a
25
- * YAML scalar and a JSON string comparable. `scripts/sot-pins.ts` uses it to
26
- * widen the pin; `src/__tests__/cvc-drift-gate.test.ts` (GATE H) uses it to
27
- * assert the shipped CVC-136 restates every pinned field faithfully.
28
- *
29
- * It lives in `src/` rather than `scripts/` for one reason: the root tsconfig
30
- * sets `rootDir: ./src`, so a `src/` test cannot import from `scripts/`, while
31
- * `scripts/tsconfig.json` deliberately includes `../src/**`. Putting it here is
32
- * what lets BOTH halves share ONE definition of the projection — the same
33
- * property `scripts/sot-pins.ts` already relies on for the pins themselves:
34
- * a pin can never disagree with the checker that validates it.
35
- *
36
- * (This is a `.ts` source file in `src/__sot__/`, not a pin. The README's
37
- * "do not hand-edit, regenerate with `npm run sot:pins`" rule is about the
38
- * `*.pin.json` snapshots. This file is hand-maintained.)
39
- */
40
-
41
- // ─── The projection ─────────────────────────────────────────────────────────
42
-
43
- /**
44
- * The fields CVC-136 restates from the catalog, and therefore the fields the
45
- * pin must carry. Adding a field here widens the gate: regenerate the pin
46
- * (`npm run sot:pins`) and GATE H starts enforcing it.
47
- */
48
- export const PROJECTED_FIELDS = [
49
- "label",
50
- "definition",
51
- "family",
52
- "polarity",
53
- "severity",
54
- "isAlert",
55
- "alertWhen",
56
- ] as const;
57
-
58
- export type ProjectedField = (typeof PROJECTED_FIELDS)[number];
59
-
60
- /** One indicator's projected fields. `null` means the source omits the field. */
61
- export type ProjectedIndicatorFields = Readonly<Record<ProjectedField, string | null>>;
62
-
63
- /**
64
- * `data/core_indicators.yaml` field name -> projected name. The catalog is
65
- * snake_case; the CVC envelope is camelCase.
66
- */
67
- const CATALOG_TO_PROJECTED: ReadonlyArray<readonly [string, ProjectedField]> = [
68
- ["label", "label"],
69
- ["definition", "definition"],
70
- ["family", "family"],
71
- ["polarity", "polarity"],
72
- ["severity", "severity"],
73
- ["is_alert", "isAlert"],
74
- ["alert_when", "alertWhen"],
75
- ];
76
-
77
- /**
78
- * `coreIndicators.v1.0.0.json` entry field name -> projected name. Note the one
79
- * genuine rename: the CVC envelope calls the catalog's `label` a `title`,
80
- * because `title` is the envelope-wide field for a human-readable value name.
81
- * That rename is structural and deliberate — it is NOT drift.
82
- */
83
- const SOT_TO_PROJECTED: ReadonlyArray<readonly [string, ProjectedField]> = [
84
- ["title", "label"],
85
- ["definition", "definition"],
86
- ["family", "family"],
87
- ["polarity", "polarity"],
88
- ["severity", "severity"],
89
- ["isAlert", "isAlert"],
90
- ["alertWhen", "alertWhen"],
91
- ];
92
-
93
- /**
94
- * Free-prose fields, which get the full text normalization below. The other
95
- * four are machine-consumed enum tokens and are compared as-is apart from
96
- * trimming — a stray space inside `thread_pave` is real drift, not formatting.
97
- */
98
- const PROSE_FIELDS: ReadonlySet<ProjectedField> = new Set<ProjectedField>([
99
- "label",
100
- "definition",
101
- ]);
102
-
103
- // ─── Normalization ──────────────────────────────────────────────────────────
104
-
105
- /**
106
- * WHICH SIDE OF THE COMPARISON A VALUE CAME FROM.
107
- *
108
- * This matters, and it is not decoration. A normalization applied to BOTH sides
109
- * can only ever absorb a difference — it can never CREATE one. That is fine for
110
- * an artifact the emitter inflicts on the catalog and that CVC-136 was always
111
- * free to restate either way (a wrap point, a trailing newline). It is NOT fine
112
- * for an artifact that CVC-136 has an obligation to FIX.
113
- *
114
- * E4 is the second kind. See its entry below.
115
- */
116
- export type NormalizationSide = "catalog" | "sot";
117
-
118
- /**
119
- * THE NORMALIZATION EXEMPTIONS.
120
- *
121
- * A YAML scalar and the JSON string that restates it are not byte-identical
122
- * even when they say exactly the same thing, because the catalog is written and
123
- * rewritten by a YAML emitter that hard-wraps long scalars. Each exemption
124
- * below is a real, enumerated round-trip artifact observed in the pinned
125
- * catalog — NOT a general-purpose fuzzy match.
126
- *
127
- * Each carries:
128
- *
129
- * `codes` — the exact catalog codes that exercise it.
130
- * `fields` — the exact projected fields it covers. SCOPED DELIBERATELY: a
131
- * self-test that spans all seven fields can be satisfied by a
132
- * DIFFERENT exemption's artifact in a different field, so a dead
133
- * exemption would look alive. (Observed: every prose artifact in
134
- * the pinned catalog is in `definition`; E4 and E2 share both a
135
- * code AND that field.)
136
- * `sides` — which side of the comparison the normalization runs on. All but
137
- * E4 are symmetric.
138
- * `detect` — a predicate over the RAW CATALOG value that is true iff the
139
- * underlying artifact is still physically present. Field scoping
140
- * alone is not enough to make a dead exemption fail when two
141
- * exemptions overlap on one code+field (E2/E4 do exactly that);
142
- * this is what makes each one independently falsifiable.
143
- *
144
- * GATE H's exemption self-tests assert all four: the artifact is still detected,
145
- * a RAW comparison of the covered fields genuinely fails, and the normalized
146
- * comparison passes. An exemption that stops being exercised is therefore
147
- * visible, not silently load-bearing forever.
148
- *
149
- * What these CANNOT hide — and this is the point — is any change to what a
150
- * field SAYS: a label rename, a definition revision, a deprecation qualifier, a
151
- * family/polarity/severity reclassification, or an alert-routing change. Those
152
- * are exactly the drift class that shipped twice, and they all survive
153
- * normalization intact.
154
- */
155
- export const NORMALIZATION_EXEMPTIONS = [
156
- {
157
- id: "E1-trailing-newline",
158
- what: "Block and wrapped quoted scalars parse with a trailing newline; the JSON prose does not.",
159
- sides: "both",
160
- codes: [
161
- "intimate_partner_violence_reported_to_law_enforcement",
162
- "sex_acts_in_own_residence",
163
- "payment_routed_through_third_party",
164
- ],
165
- fields: ["definition"],
166
- detect: (raw: string) => /\s$/.test(raw),
167
- },
168
- {
169
- id: "E2-wrap-folding",
170
- what:
171
- "The emitter hard-wraps long scalars, so wrap points parse as newlines. " +
172
- "CVC-136 sometimes preserved them and sometimes folded them to spaces. " +
173
- "Every whitespace run collapses to one space on BOTH sides.",
174
- sides: "both",
175
- codes: [
176
- "depends_on_spouse_or_family_for_immigration_status",
177
- "clients_unaware_of_third_party_coordination",
178
- "trauma_perpetrator_is_current_manager",
179
- ],
180
- fields: ["definition"],
181
- detect: (raw: string) => /\S[ \t]*\r?\n[ \t]*\S/.test(raw),
182
- },
183
- {
184
- id: "E3-wrapped-hyphen",
185
- what:
186
- "When a wrap point falls immediately after a hyphen inside a compound word " +
187
- '("emotional-\\nverbal-stalking"), the join is hyphen-direct with NO space. ' +
188
- "Applied before E2, which would otherwise leave a space behind the hyphen.",
189
- sides: "both",
190
- codes: ["trauma_perpetrator_is_current_manager"],
191
- fields: ["definition"],
192
- detect: (raw: string) => /-[ \t]*\r?\n/.test(raw),
193
- },
194
- {
195
- id: "E4-leaked-hex-escape",
196
- what:
197
- "One upstream scalar was authored SINGLE-QUOTED with Python-style escapes, " +
198
- "so `fianc\\xE9` parses as six literal characters rather than `fiancé`. " +
199
- "CVC-136 carries the real character, and MUST: the escape is an upstream " +
200
- "defect that the restatement is obliged to fix, not a formatting choice it " +
201
- "is free to mirror. So this decode is CATALOG-ONLY — running it on the SOT " +
202
- "side too would make a shipped literal `fianc\\xE9(e)` compare EQUAL to the " +
203
- "catalog and pass, which is the one thing this exemption must never do. " +
204
- "(That symmetry was the real bug: a snapshot test cannot hold the line, " +
205
- "because it is refreshed with UPDATE_SNAPSHOT=1.) GATE H additionally " +
206
- "asserts outright that no shipped CVC-136 value contains `\\xNN`.",
207
- sides: "catalog",
208
- codes: ["depends_on_spouse_or_family_for_immigration_status"],
209
- fields: ["definition"],
210
- detect: (raw: string) => LEAKED_HEX_ESCAPE.test(raw),
211
- },
212
- {
213
- id: "E5-empty-is-alert",
214
- what:
215
- "One catalog entry carries `is_alert: ''`. CVC-136 models 'no alert routing' " +
216
- "as an absent field. An empty string is read as absent on BOTH sides — but " +
217
- "ONLY for `isAlert`, which is the only field that is ever empty on either " +
218
- "side. A blanket empty-reads-as-absent rule would silently excuse an emptied " +
219
- "label or definition, which is drift, not formatting.",
220
- sides: "both",
221
- codes: ["intimate_partner_violence_reported_to_law_enforcement"],
222
- fields: ["isAlert"],
223
- detect: (raw: string) => raw === "",
224
- },
225
- ] as const;
226
-
227
- /** The one field E5 covers. An empty value is read as absent here and nowhere else. */
228
- const EMPTY_READS_AS_ABSENT: ReadonlySet<ProjectedField> = new Set<ProjectedField>(["isAlert"]);
229
-
230
- /** E4's artifact, as a pattern. Also used by GATE H's belt-and-brace assertion. */
231
- export const LEAKED_HEX_ESCAPE = /\\x[0-9A-Fa-f]{2}/;
232
-
233
- /**
234
- * E4. Decode Python-style `\xNN` escapes that leaked into single-quoted scalars.
235
- *
236
- * CATALOG-SIDE ONLY — see the E4 exemption entry. Applying this to the shipped
237
- * CVC-136 value would let a literal escape ship undetected.
238
- */
239
- export function decodeLeakedHexEscapes(value: string): string {
240
- return value.replace(/\\x([0-9A-Fa-f]{2})/g, (_match, hex: string) =>
241
- String.fromCharCode(Number.parseInt(hex, 16)),
242
- );
243
- }
244
-
245
- /**
246
- * E1 + E2 + E3 (symmetric) + E4 (catalog only), in the order they must be
247
- * applied.
248
- */
249
- export function normalizeProse(value: string, side: NormalizationSide): string {
250
- const decoded = side === "catalog" ? decodeLeakedHexEscapes(value) : value; // E4
251
- return decoded
252
- .replace(/-[ \t]*\r?\n[ \t]*/g, "-") // E3 — must precede E2
253
- .replace(/\s+/g, " ") // E2 (and E1's trailing newline)
254
- .trim(); // E1
255
- }
256
-
257
- /**
258
- * Normalize one projected value for comparison. Prose gets the full treatment;
259
- * enum tokens get trimming only. An empty `isAlert` reads as absent (E5); an
260
- * empty anything-else stays empty and will therefore mismatch, which is what we
261
- * want — that is content loss, not formatting.
262
- */
263
- export function normalizeProjectedValue(
264
- field: ProjectedField,
265
- value: string | null,
266
- side: NormalizationSide,
267
- ): string | null {
268
- if (value === null) return null;
269
- const normalized = PROSE_FIELDS.has(field) ? normalizeProse(value, side) : value.trim();
270
- if (normalized === "" && EMPTY_READS_AS_ABSENT.has(field)) return null; // E5
271
- return normalized;
272
- }
273
-
274
- /** Normalize one value that came from `data/core_indicators.yaml`. */
275
- export function normalizeCatalogValue(
276
- field: ProjectedField,
277
- value: string | null,
278
- ): string | null {
279
- return normalizeProjectedValue(field, value, "catalog");
280
- }
281
-
282
- /** Normalize one value that came from `src/cvcs/coreIndicators.v1.0.0.json`. */
283
- export function normalizeSotValue(field: ProjectedField, value: string | null): string | null {
284
- return normalizeProjectedValue(field, value, "sot");
285
- }
286
-
287
- /** Normalize a whole projected record. */
288
- export function normalizeProjectedFields(
289
- fields: ProjectedIndicatorFields,
290
- side: NormalizationSide,
291
- ): ProjectedIndicatorFields {
292
- const out = {} as Record<ProjectedField, string | null>;
293
- for (const field of PROJECTED_FIELDS) {
294
- out[field] = normalizeProjectedValue(field, fields[field], side);
295
- }
296
- return out;
297
- }
298
-
299
- // ─── Projection ─────────────────────────────────────────────────────────────
300
-
301
- function readRaw(source: Record<string, unknown>, key: string): string | null {
302
- const value = source[key];
303
- if (value === undefined || value === null) return null;
304
- return typeof value === "string" ? value : String(value);
305
- }
306
-
307
- function project(
308
- source: Record<string, unknown>,
309
- mapping: ReadonlyArray<readonly [string, ProjectedField]>,
310
- ): ProjectedIndicatorFields {
311
- const out = {} as Record<ProjectedField, string | null>;
312
- for (const [sourceKey, field] of mapping) {
313
- out[field] = readRaw(source, sourceKey);
314
- }
315
- return out;
316
- }
317
-
318
- /**
319
- * Project one `data/core_indicators.yaml` entry. Values are VERBATIM — the pin
320
- * is an honest snapshot of the upstream bytes, exactly like `cvcIndex.pin.json`
321
- * storing exact index-row strings. Normalization is a comparison-time concern,
322
- * which is what lets GATE H prove each exemption is really needed.
323
- */
324
- export function projectCatalogEntry(entry: Record<string, unknown>): ProjectedIndicatorFields {
325
- return project(entry, CATALOG_TO_PROJECTED);
326
- }
327
-
328
- /** Project one `src/cvcs/coreIndicators.v1.0.0.json` entry. */
329
- export function projectSotEntry(entry: Record<string, unknown>): ProjectedIndicatorFields {
330
- return project(entry, SOT_TO_PROJECTED);
331
- }
@@ -1,134 +0,0 @@
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
- });
@@ -1,163 +0,0 @@
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
- });