@htilabs/platform-common-models 0.8.17 → 0.8.18

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.
@@ -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"
@@ -666,6 +666,10 @@
666
666
  "count": 253,
667
667
  "hash": "83962425a6a987b46bd89f596feefe5758f25993137010bb417823b83c4ae31f"
668
668
  },
669
+ "countries": {
670
+ "count": 254,
671
+ "hash": "21525c56d5bac7f218bcb9a5dc048eea4b9132cfaf4a6a7439ebbf7dd34ebcde"
672
+ },
669
673
  "trafficking_relevant_role": {
670
674
  "count": 8,
671
675
  "hash": "1a4ea2992cc501179adafd192d7a2f1733ffe48c1ba26e1e61a3c757b2d62b32"
@@ -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
+ });
@@ -24,6 +24,12 @@
24
24
  * - A false "CVC-69 is broken" conclusion, caused by comparing an ENTRY count
25
25
  * against a SELECTABLE count (assertion F).
26
26
  *
27
+ * And then the gate itself had a blind spot, because the coreIndicators pin held
28
+ * only a SET OF CODE NAMES. Two consecutive refreshes each shipped half their
29
+ * delta — 0.8.14 dropped a definition revision, 0.8.17 dropped a label rename
30
+ * plus a deprecation qualifier — and both passed green. Assertion H closes it:
31
+ * the pin now carries what the catalog SAYS about each code, field by field.
32
+ *
27
33
  * Every assertion below maps to a real bug that shipped. This test is HERMETIC:
28
34
  * it reads only the committed pins in `src/__sot__/`, so it runs on every PR with
29
35
  * no cross-repo auth. The pins are refreshed (and upstream drift is detected) by
@@ -40,6 +46,16 @@ import { fileURLToPath } from "node:url";
40
46
 
41
47
  import { describe, it, expect } from "vitest";
42
48
 
49
+ import {
50
+ LEAKED_HEX_ESCAPE,
51
+ NORMALIZATION_EXEMPTIONS,
52
+ PROJECTED_FIELDS,
53
+ normalizeCatalogValue,
54
+ normalizeSotValue,
55
+ projectSotEntry,
56
+ } from "../__sot__/coreIndicatorFields.js";
57
+ import type { ProjectedIndicatorFields } from "../__sot__/coreIndicatorFields.js";
58
+
43
59
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
44
60
  const CVCS_DIR = path.resolve(__dirname, "..", "cvcs");
45
61
  const SOT_DIR = path.resolve(__dirname, "..", "__sot__");
@@ -56,7 +72,7 @@ const cvcIndexPin = JSON.parse(
56
72
  ) as Pin & { numbers: Record<string, string[]> };
57
73
  const coreIndicatorsPin = JSON.parse(
58
74
  readFileSync(path.join(SOT_DIR, "coreIndicators.pin.json"), "utf-8"),
59
- ) as Pin & { codes: string[] };
75
+ ) as Pin & { codes: string[]; fields: Record<string, ProjectedIndicatorFields> };
60
76
  const scoringEmitsPin = JSON.parse(
61
77
  readFileSync(path.join(SOT_DIR, "scoringEmits.pin.json"), "utf-8"),
62
78
  ) as Pin & { codes: string[] };
@@ -130,6 +146,17 @@ const CANONICAL_BINDING: Record<string, { cvc: number; indexName: string }> = {
130
146
  victim_abuse_types: { cvc: 73, indexName: "core victim abuse types cvc" },
131
147
  race_ethnicity: { cvc: 76, indexName: "core_Race:Ethnicity" },
132
148
  share_purpose: { cvc: 84, indexName: "core - share_purpose" },
149
+ // PROMOTED OUT OF INDEX_ABSENT by the 2026-08-02 live refresh. This vocabulary
150
+ // previously existed upstream only as a stray pre-08-01 CSV with no machine
151
+ // codes, so extract_final_cvcs.py emitted no index row and the domain was
152
+ // index-absent here. The refresh published the Notion page with codes minted
153
+ // 2026-08-01 (`current` · `previous` · `never` + UNK · ANON · DNC), which is
154
+ // exactly what src/cvcs/juvenileJusticeInvolvementStatus.v1.0.0.json already
155
+ // ships — so this is a linkage, not an authoring.
156
+ juvenile_justice_involvement_status: {
157
+ cvc: 95,
158
+ indexName: "core - juvenile_justice_involvement_status",
159
+ },
133
160
  homeless_status: { cvc: 96, indexName: "core - homeless_status" },
134
161
  military_branch: { cvc: 120, indexName: "core - military branch" },
135
162
  military_status: { cvc: 121, indexName: "core - military status" },
@@ -171,12 +198,31 @@ const CANONICAL_BINDING: Record<string, { cvc: number; indexName: string }> = {
171
198
  time_scope: { cvc: 174, indexName: "core - time_scope" },
172
199
  enrollment_application_status: { cvc: 175, indexName: "core - enrollment application status" },
173
200
  frequency_cadence: { cvc: 176, indexName: "core - frequency : cadence" },
174
- administering_jurisdiction: { cvc: 177, indexName: "core - administering jurisdiction" },
201
+ // Was `core - administering jurisdiction` (space) until the 2026-08-02 live
202
+ // refresh, which removed that row as a STALE DUPLICATE export and kept the
203
+ // underscore spelling. Both spellings pointed at the same vocabulary and the
204
+ // same number; only the surviving one is a legitimate binding target.
205
+ administering_jurisdiction: { cvc: 177, indexName: "core - administering_jurisdiction" },
175
206
  employment_status: { cvc: 179, indexName: "core - employment status" },
176
207
  highest_education_level_completed: {
177
208
  cvc: 180,
178
209
  indexName: "core - highest education level_completed",
179
210
  },
211
+ // PIN-ROW DISPOSITION, 2026-08-26. CVC-181's row has been in the pin since
212
+ // before the 622410b reconcile, but nothing in this package occupied 181 — it
213
+ // was a RESERVED row: a number CVC_INDEX.md speaks about that platform-common
214
+ // had never authored, in exactly the 93/196 category the pin-provenance block
215
+ // at the foot of this file describes. Authoring `countries.v1.0.0.json` flips
216
+ // it from reserved to OCCUPIED, and that flip is what this line records. The
217
+ // pin JSON itself is unchanged and must stay so — the row already says
218
+ // "core - countries" and the pin is machine-derived (`npm run sot:pins`);
219
+ // hand-editing it is forbidden by src/__sot__/README.md. What changed is our
220
+ // side of the contract, not upstream's, so the deliberate, documented edit is
221
+ // THIS binding rather than a pin bump.
222
+ //
223
+ // Note the pin row is what made this authorable at all: it is why CVC-181 was
224
+ // known to be birth-country's vocabulary and not a free number to squat on.
225
+ countries: { cvc: 181, indexName: "core - countries" },
180
226
  citizenship: { cvc: 182, indexName: "core - citizenship" },
181
227
  location_type: { cvc: 191, indexName: "core - location_type" },
182
228
  living_situation: { cvc: 192, indexName: "core - living situation" },
@@ -237,7 +283,10 @@ const INDEX_ABSENT: Record<string, { cvc: number; reason: string }> = {
237
283
  // other domain claims 67, so it is index-absent rather than a squat. Sourced
238
284
  // from the HMIS data standard via `CVC_67_HMIS_SEX` in `../constants/ic.ts`.
239
285
  hmis_sex: { cvc: 67, reason: "no CVC_INDEX row" },
240
- juvenile_justice_involvement_status: { cvc: 95, reason: "no CVC_INDEX row" },
286
+ // juvenile_justice_involvement_status (95) LEFT this list in the 622410b
287
+ // reconcile — CVC_INDEX.md now carries its row, so it is bound above. This is
288
+ // what the list is FOR: index-absence is a temporary, visible state that gets
289
+ // retired when Notion catches up, not a permanent parking spot.
241
290
  primary_language: { cvc: 122, reason: "no CVC_INDEX row" },
242
291
  hmis_relationship_to_hoh: { cvc: 129, reason: "no CVC_INDEX row" },
243
292
  core_functions: { cvc: 133, reason: "no CVC_INDEX row" },
@@ -589,6 +638,267 @@ describe("GATE G — code and key format", () => {
589
638
  }
590
639
  });
591
640
 
641
+ // ═══════════════════════════════════════════════════════════════════════════
642
+ // H. FIELD FIDELITY — the pin-field-blindness catcher
643
+ // ═══════════════════════════════════════════════════════════════════════════
644
+ /**
645
+ * GATES A and B compare SETS OF CODE NAMES. That is all the pin used to carry,
646
+ * and it is why two consecutive refreshes each shipped half a delta:
647
+ *
648
+ * 0.8.14 — the code delta landed; a DEFINITION REVISION that came with it
649
+ * did not. Green.
650
+ * 0.8.17 — the code delta landed; a LABEL RENAME and a load-bearing
651
+ * DEPRECATION QUALIFIER in a definition did not. Green. Caught by a
652
+ * human reading the diff, which is not a gate.
653
+ *
654
+ * A code can keep its name while everything the catalog SAYS about it is
655
+ * rewritten. `coreIndicators.pin.json` now carries the seven projected fields
656
+ * verbatim (`src/__sot__/coreIndicatorFields.ts`), and this gate asserts
657
+ * CVC-136 restates every one of them faithfully — entry by entry, field by
658
+ * field, naming the code, the field, the catalog value and the shipped value on
659
+ * failure.
660
+ *
661
+ * Normalization is the enumerated exemption list in `coreIndicatorFields.ts`,
662
+ * and H4 below PROVES each exemption is still load-bearing rather than letting
663
+ * it rot into a blanket fuzzy match.
664
+ */
665
+ describe("GATE H — CVC-136 restates every field the catalog states", () => {
666
+ const shipped = new Map<string, ProjectedIndicatorFields>(
667
+ substantiveOf(cvc136).map((e) => [
668
+ e.key,
669
+ projectSotEntry(e as unknown as Record<string, unknown>),
670
+ ]),
671
+ );
672
+ // Defaulted, NOT asserted here, on purpose. A pin regenerated by a
673
+ // pre-field-aware sot-pins.ts has no `fields` at all; reading `Object.keys`
674
+ // off `undefined` throws at COLLECTION time, which collapses the whole file
675
+ // to 0 tests and reports as an import error rather than as the named H1
676
+ // failure that says what to do. Default to empty, then fail loudly in H1.
677
+ const pinFields: Record<string, ProjectedIndicatorFields> = coreIndicatorsPin.fields ?? {};
678
+ const pinnedCodes = Object.keys(pinFields);
679
+
680
+ it("the pin carries projected fields for every pinned code", () => {
681
+ // A pin regenerated by a pre-field-aware sot-pins.ts would be silently
682
+ // field-blind — the exact failure mode this gate exists to end. Refuse it.
683
+ expect(
684
+ Object.keys(pinFields).length,
685
+ "the pin carries no fields — regenerate with npm run sot:pins",
686
+ ).toBeGreaterThan(0);
687
+ expect(pinnedCodes.sort()).toEqual([...coreIndicatorsPin.codes].sort());
688
+ for (const code of pinnedCodes) {
689
+ const fields = pinFields[code]!;
690
+ for (const field of PROJECTED_FIELDS) {
691
+ expect(fields, `${code} is missing projected field "${field}"`).toHaveProperty(field);
692
+ }
693
+ }
694
+ });
695
+
696
+ it("every pinned catalog code is present in CVC-136 (the join is total)", () => {
697
+ // Without this, a code dropped from CVC-136 would make the field comparison
698
+ // below silently SKIP it rather than fail — a gate with a hole in it.
699
+ const absent = pinnedCodes.filter((c) => !shipped.has(c)).sort();
700
+ if (absent.length > 0) {
701
+ throw new Error(
702
+ `${absent.length} code(s) in ${coreIndicatorsPin.sourceFile} ` +
703
+ `@ ${coreIndicatorsPin.sourceSha} are NOT in CVC-136:\n` +
704
+ ` ${absent.join(", ")}\n\n` +
705
+ "GATE B only checks the other direction (CVC-136 invents nothing), so a\n" +
706
+ " catalog code dropped on refresh would otherwise pass unnoticed.\n" +
707
+ "TO FIX: add each to src/cvcs/coreIndicators.v1.0.0.json.",
708
+ );
709
+ }
710
+ expect(absent).toEqual([]);
711
+ });
712
+
713
+ it(`all ${PROJECTED_FIELDS.length} projected fields match, code by code`, () => {
714
+ const mismatches: string[] = [];
715
+
716
+ for (const code of pinnedCodes) {
717
+ const catalog = pinFields[code]!;
718
+ const sot = shipped.get(code);
719
+ if (!sot) continue; // already reported by the join-is-total assertion above
720
+
721
+ for (const field of PROJECTED_FIELDS) {
722
+ // ASYMMETRIC BY DESIGN. E4's `\xNN` decode runs on the CATALOG side
723
+ // only, because CVC-136 is obliged to carry the real character rather
724
+ // than mirror the upstream escape. Decoding both sides would let a
725
+ // shipped literal `fianc\xE9(e)` compare equal and pass. E1/E2/E3/E5
726
+ // are symmetric. See NORMALIZATION_EXEMPTIONS.
727
+ const want = normalizeCatalogValue(field, catalog[field]);
728
+ const got = normalizeSotValue(field, sot[field]);
729
+ if (want === got) continue;
730
+ mismatches.push(
731
+ ` ${code} . ${field}\n` +
732
+ ` catalog: ${want === null ? "(absent)" : JSON.stringify(want)}\n` +
733
+ ` CVC-136: ${got === null ? "(absent)" : JSON.stringify(got)}`,
734
+ );
735
+ }
736
+ }
737
+
738
+ if (mismatches.length > 0) {
739
+ throw new Error(
740
+ `${mismatches.length} field(s) of CVC-136 disagree with the canonical catalog.\n` +
741
+ "The CODE SET is right and the CONTENT is stale — which is precisely what a\n" +
742
+ "code-set-only pin could never see (0.8.14 dropped a definition revision;\n" +
743
+ "0.8.17 dropped a label rename plus a deprecation qualifier).\n\n" +
744
+ `${mismatches.join("\n")}\n\n` +
745
+ "TO FIX: copy the `catalog:` value printed above into the matching entry\n" +
746
+ " of src/cvcs/coreIndicators.v1.0.0.json.\n" +
747
+ " COPY THE PRINTED VALUE, not the raw scalar out of\n" +
748
+ ` ${coreIndicatorsPin.sourceRepo}/${coreIndicatorsPin.sourceFile}` +
749
+ ` @ ${coreIndicatorsPin.sourceSha}.\n` +
750
+ " The printed value is NORMALIZED — wrap points folded, and any leaked\n" +
751
+ " `\\xNN` escape already decoded to the real character. Transcribing the\n" +
752
+ " raw YAML by hand reproduces the escape verbatim (`fianc\\xE9(e)`), which\n" +
753
+ " CVC-136 must NOT carry: the restatement's job is to fix that upstream\n" +
754
+ " defect, and a separate assertion below rejects a shipped `\\xNN`.\n" +
755
+ " Field names differ by design: the catalog's `label` is the envelope's\n" +
756
+ " `title`; `is_alert`/`alert_when` are `isAlert`/`alertWhen`. Then\n" +
757
+ " regenerate CVC_136_CORE_INDICATOR_VALUES in src/constants/ic.ts if the\n" +
758
+ " change touches a name.\n" +
759
+ " If instead the CATALOG moved, run `npm run sot:pins` and restate both.",
760
+ );
761
+ }
762
+ expect(mismatches).toEqual([]);
763
+ });
764
+
765
+ /**
766
+ * BELT AND BRACES FOR E4.
767
+ *
768
+ * The comparison above is already asymmetric, so a shipped `fianc\xE9(e)` now
769
+ * fails it. This asserts the same thing directly, without reference to the
770
+ * catalog, because it is the cheaper and more legible failure: it names E4 and
771
+ * says what a correct restatement looks like, rather than printing two long
772
+ * definitions that differ somewhere in the middle.
773
+ *
774
+ * It also holds if the catalog is ever cleaned up upstream and E4 is deleted:
775
+ * CVC-136 must never carry a Python-style hex escape regardless of why.
776
+ */
777
+ it("no shipped CVC-136 value carries a leaked `\\xNN` escape", () => {
778
+ const offenders: string[] = [];
779
+ for (const [code, fields] of shipped) {
780
+ for (const field of PROJECTED_FIELDS) {
781
+ const value = fields[field];
782
+ if (value !== null && LEAKED_HEX_ESCAPE.test(value)) {
783
+ offenders.push(` ${code} . ${field}: ${JSON.stringify(value)}`);
784
+ }
785
+ }
786
+ }
787
+ expect(
788
+ offenders,
789
+ "These CVC-136 values contain a literal `\\xNN` escape (E4-leaked-hex-escape).\n" +
790
+ "One upstream catalog scalar is authored single-quoted with Python-style\n" +
791
+ "escapes, so `fianc\\xE9` parses as six literal characters. CVC-136's job is to\n" +
792
+ "restate the REAL character (`fiancé`) — copying the raw YAML through\n" +
793
+ "mechanically carries the defect into the shipped codebook.\n" +
794
+ "TO FIX: replace each escape with the character it denotes.\n" +
795
+ `${offenders.join("\n")}`,
796
+ ).toEqual([]);
797
+ });
798
+
799
+ /**
800
+ * H4 — THE EXEMPTIONS ARE PROVEN, NOT ASSUMED.
801
+ *
802
+ * A normalization exemption is a hole in the gate. Each one below is asserted
803
+ * to be (a) still physically present — its `detect` predicate still fires on
804
+ * the raw catalog value — (b) still exercised — a RAW comparison of the fields
805
+ * it covers genuinely fails — and (c) sufficient — the normalized comparison
806
+ * of those fields passes. An exemption that stops being needed fails here and
807
+ * gets deleted, instead of silently widening the gate's blind spot forever.
808
+ *
809
+ * SCOPING, and why both (a) and (b) are needed.
810
+ *
811
+ * The self-tests used to span all seven PROJECTED_FIELDS, so an exemption
812
+ * could look alive on the strength of a DIFFERENT exemption's artifact in a
813
+ * different field. Narrowing to `exemption.fields` fixes most of that — but
814
+ * not all of it, because in the pinned catalog every prose artifact lives in
815
+ * `definition`, and E2 and E4 share BOTH a code and that field. Field scoping
816
+ * alone would still let a dead E4 ride on E2's wrap point.
817
+ *
818
+ * `detect` is what closes it: it asks whether the raw catalog value still
819
+ * contains THIS exemption's artifact — a trailing newline, an interior wrap,
820
+ * a wrapped hyphen, a `\xNN` escape, an empty string — independently of
821
+ * whether some other exemption also fires on the same value.
822
+ */
823
+ describe("the normalization exemptions are each still load-bearing", () => {
824
+ for (const exemption of NORMALIZATION_EXEMPTIONS) {
825
+ it(`${exemption.id} is exercised by ${exemption.codes.join(", ")}`, () => {
826
+ for (const code of exemption.codes) {
827
+ const catalog = pinFields[code];
828
+ const sot = shipped.get(code);
829
+ expect(catalog, `${exemption.id}: ${code} is no longer in the pin`).toBeDefined();
830
+ expect(sot, `${exemption.id}: ${code} is no longer in CVC-136`).toBeDefined();
831
+
832
+ // Scoped to the fields THIS exemption claims to cover.
833
+ const fields = exemption.fields;
834
+
835
+ const detected = fields.some((f) => {
836
+ const raw = catalog![f];
837
+ return raw !== null && exemption.detect(raw);
838
+ });
839
+ const rawDiffers = fields.some((f) => catalog![f] !== sot![f]);
840
+ const normalizedMatches = fields.every(
841
+ (f) => normalizeCatalogValue(f, catalog![f]) === normalizeSotValue(f, sot![f]),
842
+ );
843
+
844
+ expect(
845
+ detected,
846
+ `${exemption.id}: the artifact is GONE from ${code}.${fields.join("/")} — ` +
847
+ "the raw catalog value no longer contains it, so this exemption is dead. " +
848
+ "Delete it from NORMALIZATION_EXEMPTIONS in src/__sot__/coreIndicatorFields.ts " +
849
+ "rather than leaving an unused hole in the gate. (Checked separately from " +
850
+ "the raw-differs assertion below because two exemptions can overlap on one " +
851
+ "code and field — E2 and E4 do — and then a raw difference proves nothing " +
852
+ "about which of them is still needed.)",
853
+ ).toBe(true);
854
+ expect(
855
+ rawDiffers,
856
+ `${exemption.id}: ${code}.${fields.join("/")} now matches VERBATIM — this ` +
857
+ "exemption is dead. Delete it from NORMALIZATION_EXEMPTIONS in " +
858
+ "src/__sot__/coreIndicatorFields.ts rather than leaving an unused hole " +
859
+ "in the gate.",
860
+ ).toBe(true);
861
+ expect(
862
+ normalizedMatches,
863
+ `${exemption.id}: ${code}.${fields.join("/")} still differs AFTER ` +
864
+ "normalization — the exemption no longer covers what it claims to. " +
865
+ "Read the GATE H failure above.",
866
+ ).toBe(true);
867
+ }
868
+ });
869
+ }
870
+
871
+ it("every round-trip artifact in the catalog is an enumerated one", () => {
872
+ // Guard the escape hatch the way GATE B guards SCORING_AHEAD_OF_CATALOG:
873
+ // the list must stay a documented enumeration, not a dumping ground.
874
+ //
875
+ // Scoped to codes whose raw fields differ but whose NORMALIZED fields
876
+ // agree — that is the definition of a round-trip artifact. Codes that
877
+ // differ after normalization are real drift and belong to the GATE H
878
+ // failure above; reporting them here too would just double the noise.
879
+ const named = new Set<string>(NORMALIZATION_EXEMPTIONS.flatMap((e) => [...e.codes]));
880
+ const artifacts = pinnedCodes.filter((code) => {
881
+ const catalog = pinFields[code]!;
882
+ const sot = shipped.get(code);
883
+ if (!sot) return false;
884
+ const rawDiffers = PROJECTED_FIELDS.some((f) => catalog[f] !== sot[f]);
885
+ const normalizedMatches = PROJECTED_FIELDS.every(
886
+ (f) => normalizeCatalogValue(f, catalog[f]) === normalizeSotValue(f, sot[f]),
887
+ );
888
+ return rawDiffers && normalizedMatches;
889
+ });
890
+ const undocumented = artifacts.filter((c) => !named.has(c)).sort();
891
+ expect(
892
+ undocumented,
893
+ "These codes are absorbed by normalization but named by no exemption. Each is a " +
894
+ "NEW round-trip artifact: read it, confirm it is formatting and not content, then " +
895
+ "document it in NORMALIZATION_EXEMPTIONS in src/__sot__/coreIndicatorFields.ts. " +
896
+ "An undocumented one is a hole nobody has looked through.",
897
+ ).toEqual([]);
898
+ });
899
+ });
900
+ });
901
+
592
902
  // ═══════════════════════════════════════════════════════════════════════════
593
903
  // Pin provenance — the pins must say where they came from.
594
904
  // ═══════════════════════════════════════════════════════════════════════════
@@ -606,22 +916,74 @@ describe("SOT pins carry their provenance", () => {
606
916
  });
607
917
 
608
918
  it("the pinned SOT is the one this release was authored against", () => {
609
- // cvcIndex stays at a596eb9 — deliberately NOT bumped here. CVC_INDEX.md
610
- // HAS moved upstream (2026-08-02 targeted live refresh: CVC-93/95/159/177/196
611
- // rows), but absorbing it means reconciling INDEX_ABSENT for
612
- // juvenile_justice_involvement_status (95) and the child-welfare rows (93/196),
613
- // which is its own reconcile — a pin bump without conformance is exactly the
614
- // lie sot-pins.ts warns about. Tracked separately; `sot:pins:check` will keep
615
- // reporting cvcIndex drift until it lands.
919
+ // cvcIndex advanced a596eb9 -> 622410b (the 2026-08-02 targeted live-Notion
920
+ // refresh of the legal-history arc tails), WITH the conformance it implies —
921
+ // the reconcile the previous release deferred rather than fake. Four row
922
+ // deltas, and what each one actually required:
923
+ //
924
+ // CVC-177 ["core - administering jurisdiction", -> ["core - administering_jurisdiction"]
925
+ // "core - administering_jurisdiction"]
926
+ // The space-named row was a STALE DUPLICATE export and was
927
+ // removed. NOT bookkeeping: CANONICAL_BINDING was bound to the
928
+ // spelling that no longer exists, so the bump alone would have
929
+ // failed GATE C. The binding now names the surviving row.
930
+ //
931
+ // CVC-95 null -> ["core - juvenile_justice_involvement_status"]
932
+ // The domain was already authored and already correct; it sat in
933
+ // INDEX_ABSENT only because no index row existed to bind it to.
934
+ // Now bound. Left in INDEX_ABSENT it would have read as a SQUAT,
935
+ // because a number the index speaks about constrains whoever
936
+ // occupies it. Linkage only — nothing authored.
937
+ //
938
+ // CVC-93 null -> ["core - child_welfare_involvement_status"]
939
+ // CVC-196 ["core child welfare cvc", -> ["core - child_welfare_episode_type"]
940
+ // "core child welfare episode type CVC"]
941
+ // Bookkeeping. platform-common ships NO domain at 93 or 196, so
942
+ // no gate constrains them and nothing here had to change. They
943
+ // are now KNOWN-OCCUPIED numbers, which is the point: authoring
944
+ // either later must land on its own number, and a future domain
945
+ // drifting onto 93/196 is now a detectable squat rather than a
946
+ // silent one. Authoring the vocabularies themselves is clinical
947
+ // content (Crysta-owned) and is deliberately not done here.
948
+ //
949
+ // The three index-name/status-only churns in the same refresh (CVC-159
950
+ // unchanged row, CVC-85 and CVC-145 status promotions) carry no pin delta:
951
+ // the pin captures the NUMBER -> NAMES map, not the status column.
616
952
  // coreIndicators advanced to 84a1b67 in 0.8.14 (+5 upstream mints, 0
617
953
  // withdrawn) and to 622410b in this refresh (+1: `active_protective_order`,
618
954
  // minted upstream 2026-08-08, `code_status: canonical`, plus the projected-
619
955
  // field revisions on 136-007 / 136-094); scoringEmits is unchanged,
620
956
  // so the 2 SCORING_AHEAD_OF_CATALOG codes remain ahead of the catalog
621
957
  // exactly as before.
622
- expect(cvcIndexPin.sourceSha).toBe("a596eb9");
958
+ //
959
+ // coreIndicators was WIDENED (not bumped) to carry the projected `fields`
960
+ // that GATE H enforces — same SHA, same 214 codes, more of what the catalog
961
+ // says about each. The two refreshes that dropped their field delta are why.
962
+ //
963
+ // 622410b's CVC_INDEX.md is a HAND-REFRESHED live-Notion state that upstream
964
+ // marks NON-REPRODUCIBLE by `tools/extract_final_cvcs.py`: its banner says
965
+ // "Do NOT re-run tools/extract_final_cvcs.py until the next full Notion
966
+ // re-export lands — it would clobber the refreshed extracts and resurrect
967
+ // index rows from the stale zips" — i.e. a premature re-run brings the
968
+ // space-named CVC-177 duplicate back and takes CVC-95's row away again.
969
+ // GATE C fails loudly on the CVC-95 half (a bound domain sits on it); the
970
+ // 93/196 half is invisible to every gate, since GATE C only iterates bound
971
+ // domains and occupied numbers and platform-common ships neither. The row
972
+ // count below is what makes that half detectable at all — a regenerated pin
973
+ // that silently drops those deliberately-recorded rows fails here.
974
+ //
975
+ // 2026-08-26 — CVC-181 `core - countries` was authored, and its pin row went
976
+ // from RESERVED (a row the index speaks about that nothing occupied — the
977
+ // 93/196 category above) to OCCUPIED. NO PIN DELTA: the row already read
978
+ // ["core - countries"] and upstream did not move, so the pin stays at
979
+ // 622410b and stays machine-derived. The change is on OUR side of the
980
+ // contract and is recorded as a CANONICAL_BINDING entry with its disposition
981
+ // written next to it. This is the shape every reserved-row authoring should
982
+ // take: bind, do not bump.
983
+ expect(cvcIndexPin.sourceSha).toBe("622410b");
623
984
  expect(coreIndicatorsPin.sourceSha).toBe("622410b");
624
985
  expect(scoringEmitsPin.sourceSha).toBe("9b5d654");
986
+ expect(Object.keys(cvcIndexPin.numbers).length, "cvcIndexPin.numbers rows").toBe(86);
625
987
  expect(coreIndicatorsPin.codes.length).toBe(214);
626
988
  expect(scoringEmitsPin.codes.length).toBe(169);
627
989
  });