@htilabs/platform-common-models 0.8.16 → 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.
Files changed (51) hide show
  1. package/dist/constants/index.cjs +3 -1
  2. package/dist/constants/index.cjs.map +1 -1
  3. package/dist/constants/index.d.cts +1 -1
  4. package/dist/constants/index.d.ts +1 -1
  5. package/dist/constants/index.js +3 -1
  6. package/dist/constants/index.js.map +1 -1
  7. package/dist/{cvcEntry-0BIB9sen.d.cts → cvcEntry-DaDrEuTa.d.cts} +44 -44
  8. package/dist/{cvcEntry-0BIB9sen.d.ts → cvcEntry-DaDrEuTa.d.ts} +44 -44
  9. package/dist/cvcs/index.cjs +4348 -17
  10. package/dist/cvcs/index.cjs.map +1 -1
  11. package/dist/cvcs/index.d.cts +10835 -6179
  12. package/dist/cvcs/index.d.ts +10835 -6179
  13. package/dist/cvcs/index.js +8776 -4447
  14. package/dist/cvcs/index.js.map +1 -1
  15. package/dist/{index-CDoqrfc1.d.ts → index-C0J3f169.d.ts} +1 -1
  16. package/dist/{index-Zu_mOJRn.d.cts → index-EPjPjR0z.d.cts} +1 -1
  17. package/dist/index.cjs +4690 -20
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +353 -8
  20. package/dist/index.d.ts +353 -8
  21. package/dist/index.js +4686 -20
  22. package/dist/index.js.map +1 -1
  23. package/dist/models/index.d.cts +2 -2
  24. package/dist/models/index.d.ts +2 -2
  25. package/dist/{platform-auth-AsfnIXfK.d.cts → platform-auth-CvQkzOy1.d.cts} +1 -1
  26. package/dist/{platform-auth-AsfnIXfK.d.ts → platform-auth-CvQkzOy1.d.ts} +1 -1
  27. package/dist/schemas/index.cjs.map +1 -1
  28. package/dist/schemas/index.d.cts +35 -35
  29. package/dist/schemas/index.d.ts +35 -35
  30. package/dist/schemas/index.js.map +1 -1
  31. package/dist/types/index.d.cts +2 -2
  32. package/dist/types/index.d.ts +2 -2
  33. package/package.json +26 -25
  34. package/src/__sot__/README.md +36 -1
  35. package/src/__sot__/coreIndicatorFields.ts +331 -0
  36. package/src/__sot__/coreIndicators.pin.json +1931 -2
  37. package/src/__sot__/cvcIndex.pin.json +8 -4
  38. package/src/__tests__/__snapshots__/cvc-sot.snap +8 -4
  39. package/src/__tests__/core-information-scope-invariant.test.ts +134 -0
  40. package/src/__tests__/cvc-136-scoring-invariant.test.ts +7 -5
  41. package/src/__tests__/cvc-181-182-country-parity.test.ts +163 -0
  42. package/src/__tests__/cvc-drift-gate.test.ts +392 -9
  43. package/src/__tests__/cvc-sot-snapshot.test.ts +17 -4
  44. package/src/__tests__/cvc-structural.test.ts +2 -0
  45. package/src/constants/ic.ts +88 -4
  46. package/src/cvcs/coreIndicators.v1.0.0.json +18 -5
  47. package/src/cvcs/coreInformationScope.v1.0.0.json +1165 -0
  48. package/src/cvcs/countries.v1.0.0.json +3077 -0
  49. package/src/cvcs/index.ts +4 -0
  50. package/src/cvcs/sharePurpose.v1.0.0.json +80 -12
  51. package/src/generated/cvc-enums.ts +352 -3
@@ -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" },
@@ -218,6 +264,18 @@ const INDEX_ABSENT: Record<string, { cvc: number; reason: string }> = {
218
264
  // but CVC_INDEX.md carries no row. Not a squat (nothing else claims these
219
265
  // numbers) — but each needs a Notion index row to become verifiable.
220
266
  service_categories: { cvc: 22, reason: "no CVC_INDEX row" },
267
+ // Authored directly in the live Notion inline DB (2026-08-13, restructured
268
+ // 2026-08-14), so no `Final CVCs/` export exists yet and extract_final_cvcs.py
269
+ // emits no row. The number is the domain's own self-declaration —
270
+ // `data/cvcs/core_information_scope.yaml` carries `cvc_id: "CVC-236"` — and
271
+ // nothing else claims 236 (233 and 235 and 238 are bound elsewhere; 236 and
272
+ // 237 are unoccupied), so this is index-absent rather than a squat. NOT parked
273
+ // at 900+ on purpose: that block is for vocabularies with no canonical number,
274
+ // and parking a numbered domain there would leave 236 looking free.
275
+ core_information_scope: {
276
+ cvc: 236,
277
+ reason: "authored in the live Notion inline DB; no Final CVCs/ export yet",
278
+ },
221
279
  // Trunk-only domain: authored on `kl-develop` (80341e0, "promote CVC-17 +
222
280
  // CVC-67 to SOT"), which the canonical 0.8.13 line never saw. Its sibling
223
281
  // CVC-17 (gender_identity) IS in CVC_INDEX.md and is bound above; 67 is not
@@ -225,7 +283,10 @@ const INDEX_ABSENT: Record<string, { cvc: number; reason: string }> = {
225
283
  // other domain claims 67, so it is index-absent rather than a squat. Sourced
226
284
  // from the HMIS data standard via `CVC_67_HMIS_SEX` in `../constants/ic.ts`.
227
285
  hmis_sex: { cvc: 67, reason: "no CVC_INDEX row" },
228
- 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.
229
290
  primary_language: { cvc: 122, reason: "no CVC_INDEX row" },
230
291
  hmis_relationship_to_hoh: { cvc: 129, reason: "no CVC_INDEX row" },
231
292
  core_functions: { cvc: 133, reason: "no CVC_INDEX row" },
@@ -577,6 +638,267 @@ describe("GATE G — code and key format", () => {
577
638
  }
578
639
  });
579
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
+
580
902
  // ═══════════════════════════════════════════════════════════════════════════
581
903
  // Pin provenance — the pins must say where they came from.
582
904
  // ═══════════════════════════════════════════════════════════════════════════
@@ -594,14 +916,75 @@ describe("SOT pins carry their provenance", () => {
594
916
  });
595
917
 
596
918
  it("the pinned SOT is the one this release was authored against", () => {
597
- // cvcIndex stays at a596eb9 — the CVC NUMBER<->NAME registry did not move.
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.
598
952
  // coreIndicators advanced to 84a1b67 in 0.8.14 (+5 upstream mints, 0
599
- // withdrawn); scoringEmits is unchanged, so the 2 SCORING_AHEAD_OF_CATALOG
600
- // codes remain ahead of the catalog exactly as before.
601
- expect(cvcIndexPin.sourceSha).toBe("a596eb9");
602
- expect(coreIndicatorsPin.sourceSha).toBe("84a1b67");
953
+ // withdrawn) and to 622410b in this refresh (+1: `active_protective_order`,
954
+ // minted upstream 2026-08-08, `code_status: canonical`, plus the projected-
955
+ // field revisions on 136-007 / 136-094); scoringEmits is unchanged,
956
+ // so the 2 SCORING_AHEAD_OF_CATALOG codes remain ahead of the catalog
957
+ // exactly as before.
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");
984
+ expect(coreIndicatorsPin.sourceSha).toBe("622410b");
603
985
  expect(scoringEmitsPin.sourceSha).toBe("9b5d654");
604
- expect(coreIndicatorsPin.codes.length).toBe(213);
986
+ expect(Object.keys(cvcIndexPin.numbers).length, "cvcIndexPin.numbers rows").toBe(86);
987
+ expect(coreIndicatorsPin.codes.length).toBe(214);
605
988
  expect(scoringEmitsPin.codes.length).toBe(169);
606
989
  });
607
990
  });
@@ -242,12 +242,18 @@ const SOT_SPECS: readonly SotSpec[] = [
242
242
  domain: "preferred_contact_method",
243
243
  expectedCount: 4,
244
244
  },
245
- // CVC-84 — 8 flat Level-1 intent-based share purposes. No missingness
246
- // sentinels (variant 0, share_purpose is always known at sharing time) = 8.
245
+ // CVC-84 — 12 flat Level-1 intent-based share purposes: the 8 `wing: core`
246
+ // rows from `core_share_purpose.yaml` + the 4 `wing: leads` rows from
247
+ // `core_share_purpose_extensions_leads.yaml`, which canon's own
248
+ // `build_sharing_purpose_catalog.py` joins into one 12-row catalog. The wing
249
+ // rows were RATIFIED 2026-07-03 and live-synced 2026-08-19, so they are canon,
250
+ // not proposals. This count was 8 while only the core file had been ported.
251
+ // No missingness sentinels (variant 0, share_purpose is always known at
252
+ // sharing time) = 12.
247
253
  {
248
254
  file: "sharePurpose.v1.0.0.json",
249
255
  domain: "share_purpose",
250
- expectedCount: 8,
256
+ expectedCount: 12,
251
257
  },
252
258
  // CVC-165 — 10 flat Level-1 entity/establishment types (Notion codebook DB,
253
259
  // v1.0) + 1 missingness root + 3 canonical missingness children (no PNA;
@@ -628,7 +634,8 @@ const SOT_SPECS: readonly SotSpec[] = [
628
634
  // ─── 0.8.13 canonical CVC batch ───
629
635
  { file: "coreDhState.v1.0.0.json", domain: "dh_state", expectedCount: 9 },
630
636
  // 0.8.14: 214 -> 219 (catalog refresh a596eb9 -> 84a1b67; +5 mints, 0 withdrawn).
631
- { file: "coreIndicators.v1.0.0.json", domain: "core_indicators", expectedCount: 219 },
637
+ // 622410b refresh: 219 -> 220 (catalog refresh 84a1b67 -> 622410b; +1 mint, 0 withdrawn).
638
+ { file: "coreIndicators.v1.0.0.json", domain: "core_indicators", expectedCount: 220 },
632
639
  { file: "riskSeverityBand.v1.0.0.json", domain: "risk_severity_band", expectedCount: 9 },
633
640
  { file: "adminRoles.v1.0.0.json", domain: "admin_roles", expectedCount: 14 },
634
641
  { file: "userRoles.v1.0.0.json", domain: "user_roles", expectedCount: 19 },
@@ -648,6 +655,12 @@ const SOT_SPECS: readonly SotSpec[] = [
648
655
  // missingness root + 3 canonical missingness children (Unknown / Declined to
649
656
  // asnwer / Not collected, carried verbatim from the codebook) = 253.
650
657
  { file: "citizenship.v1.0.0.json", domain: "citizenship", expectedCount: 253 },
658
+ // CVC-181 — the SAME 249 countries (identical keys + ISO codes; asserted by
659
+ // cvc-181-182-country-parity.test.ts) + 1 missingness root + 3 workspace-
660
+ // standard missingness children (this codebook carries none of its own) + the
661
+ // 1 authored `non_us_unspecified` local extension = 254. The +1 over CVC-182
662
+ // is that local extension, and nothing else.
663
+ { file: "countries.v1.0.0.json", domain: "countries", expectedCount: 254 },
651
664
  // CVC-235 — 4 L1 trafficking-relevant roles + 1 missingness root + 3 canonical
652
665
  // missingness children = 8.
653
666
  {
@@ -206,6 +206,8 @@ const SOT_FILES: readonly SotFile[] = [
206
206
  { file: "whyNots.v1.0.0.json", expectedDomain: "why_nots" },
207
207
  // ─── 0.8.13 held-item resolutions (Job A) ───
208
208
  { file: "citizenship.v1.0.0.json", expectedDomain: "citizenship" },
209
+ // CVC-181 — the country list CVC-182 shares. Authored 2026-08-26.
210
+ { file: "countries.v1.0.0.json", expectedDomain: "countries" },
209
211
  { file: "traffickingRelevantRole.v1.0.0.json", expectedDomain: "trafficking_relevant_role" },
210
212
  // ─── Domains the hand-maintained list previously OMITTED (found by the
211
213
  // CVC drift gate, which scans the directory instead of a list). ───