@htilabs/platform-common-models 0.12.0 → 0.12.1

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 (97) hide show
  1. package/dist/config/index.cjs +0 -81
  2. package/dist/config/index.cjs.map +1 -1
  3. package/dist/config/index.d.cts +4 -79
  4. package/dist/config/index.d.ts +4 -79
  5. package/dist/config/index.js +1 -79
  6. package/dist/config/index.js.map +1 -1
  7. package/dist/constants/index.cjs +18 -2
  8. package/dist/constants/index.cjs.map +1 -1
  9. package/dist/constants/index.d.cts +1 -1
  10. package/dist/constants/index.d.ts +1 -1
  11. package/dist/constants/index.js +18 -2
  12. package/dist/constants/index.js.map +1 -1
  13. package/dist/cvc-Cp4uWnAa.d.cts +298 -0
  14. package/dist/cvc-Cp4uWnAa.d.ts +298 -0
  15. package/dist/cvcs/index.cjs +6678 -221
  16. package/dist/cvcs/index.cjs.map +1 -1
  17. package/dist/cvcs/index.d.cts +15019 -8052
  18. package/dist/cvcs/index.d.ts +15019 -8052
  19. package/dist/cvcs/index.js +6666 -221
  20. package/dist/cvcs/index.js.map +1 -1
  21. package/dist/enums/index.cjs +4557 -0
  22. package/dist/enums/index.cjs.map +1 -0
  23. package/dist/enums/index.d.cts +5257 -0
  24. package/dist/enums/index.d.ts +5257 -0
  25. package/dist/enums/index.js +4354 -0
  26. package/dist/enums/index.js.map +1 -0
  27. package/dist/{index-I-DiX9eQ.d.ts → index-CDoqrfc1.d.ts} +1 -1
  28. package/dist/{index-CoVr1jIV.d.cts → index-Zu_mOJRn.d.cts} +1 -1
  29. package/dist/index.cjs +7219 -232
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +7 -4700
  32. package/dist/index.d.ts +7 -4700
  33. package/dist/index.js +7195 -232
  34. package/dist/index.js.map +1 -1
  35. package/dist/models/index.d.cts +2 -2
  36. package/dist/models/index.d.ts +2 -2
  37. package/dist/mongo/index.cjs +0 -1
  38. package/dist/mongo/index.cjs.map +1 -1
  39. package/dist/mongo/index.js +1 -2
  40. package/dist/mongo/index.js.map +1 -1
  41. package/dist/{platform-auth-v53r3BhN.d.cts → platform-auth-Dv5fu0Fh.d.cts} +5 -4
  42. package/dist/{platform-auth-v53r3BhN.d.ts → platform-auth-Dv5fu0Fh.d.ts} +5 -4
  43. package/dist/schemas/index.cjs +5 -1
  44. package/dist/schemas/index.cjs.map +1 -1
  45. package/dist/schemas/index.d.cts +25 -25
  46. package/dist/schemas/index.d.ts +25 -25
  47. package/dist/schemas/index.js +5 -1
  48. package/dist/schemas/index.js.map +1 -1
  49. package/dist/types/index.d.cts +2 -2
  50. package/dist/types/index.d.ts +2 -2
  51. package/dist/validation/index.cjs +58 -0
  52. package/dist/validation/index.cjs.map +1 -1
  53. package/dist/validation/index.d.cts +82 -283
  54. package/dist/validation/index.d.ts +82 -283
  55. package/dist/validation/index.js +57 -0
  56. package/dist/validation/index.js.map +1 -1
  57. package/package.json +10 -1
  58. package/src/__sot__/README.md +36 -1
  59. package/src/__sot__/coreIndicatorFields.ts +331 -0
  60. package/src/__sot__/coreIndicators.pin.json +1936 -2
  61. package/src/__sot__/cvcIndex.pin.json +8 -4
  62. package/src/__tests__/__snapshots__/cvc-sot.snap +41 -13
  63. package/src/__tests__/core-information-scope-invariant.test.ts +134 -0
  64. package/src/__tests__/cvc-136-scoring-invariant.test.ts +8 -3
  65. package/src/__tests__/cvc-181-182-country-parity.test.ts +163 -0
  66. package/src/__tests__/cvc-drift-gate.test.ts +445 -12
  67. package/src/__tests__/cvc-sot-snapshot.test.ts +73 -11
  68. package/src/__tests__/cvc-status-parser.test.ts +150 -0
  69. package/src/__tests__/cvc-structural.test.ts +14 -0
  70. package/src/__tests__/runtime-contract-validator.test.ts +1 -325
  71. package/src/config/index.ts +4 -189
  72. package/src/constants/ic.ts +120 -3
  73. package/src/cvcs/assertionDomain.v1.1.0.json +19 -1
  74. package/src/cvcs/assertionStatus.v1.0.0.json +80 -0
  75. package/src/cvcs/carCorrectionReason.v1.0.0.json +89 -0
  76. package/src/cvcs/caseShareState.v1.0.0.json +62 -0
  77. package/src/cvcs/coreIndicators.v1.0.0.json +83 -5
  78. package/src/cvcs/coreInformationScope.v1.0.0.json +1165 -0
  79. package/src/cvcs/countries.v1.0.0.json +3077 -0
  80. package/src/cvcs/createdBySystem.v1.0.0.json +89 -0
  81. package/src/cvcs/criminalOrgCategory.v1.0.0.json +116 -0
  82. package/src/cvcs/determinationHelperCategories.v1.0.0.json +1166 -0
  83. package/src/cvcs/incidentParticipationRoles.v1.0.0.json +11 -1
  84. package/src/cvcs/index.ts +32 -0
  85. package/src/cvcs/minorAdultStatus.v1.0.0.json +80 -0
  86. package/src/cvcs/personRelationships.v1.0.0.json +67 -2
  87. package/src/cvcs/referralOrigin.v1.0.0.json +26 -0
  88. package/src/cvcs/relationshipConcern.v1.0.0.json +28 -19
  89. package/src/cvcs/riskIdentificationMilestone.v1.0.0.json +109 -0
  90. package/src/cvcs/sessionTemplate.v1.0.0.json +22 -0
  91. package/src/cvcs/sharePurpose.v1.0.0.json +80 -12
  92. package/src/cvcs/subjectType.v1.0.0.json +80 -0
  93. package/src/generated/cvc-enums.ts +606 -20
  94. package/src/validation/cvcStatus.ts +209 -0
  95. package/src/validation/index.ts +1 -0
  96. package/dist/{cvcEntry-BCj1OWqL.d.cts → cvcEntry-0BIB9sen.d.cts} +8 -8
  97. package/dist/{cvcEntry-BCj1OWqL.d.ts → cvcEntry-0BIB9sen.d.ts} +8 -8
@@ -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,31 @@ 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
+ // Ratified in the live Notion CVC-159 codebook 2026-08-29 (Crysta knock-out
268
+ // walk) and mirrored to `data/cvcs/core_assertion_domain_extensions_
269
+ // signal_identification.yaml` (prototype PR #519), but CVC_INDEX.md carries no
270
+ // row: the 2026-08-29 targeted live refresh updated CVC-159's own rows without
271
+ // re-running extract_final_cvcs.py, so no `Final CVCs/` export exists for this
272
+ // slice yet. The number is the domain's own self-declaration (CVC-267) and
273
+ // nothing else claims it. NOT parked at 900+ on purpose — same reasoning as
274
+ // core_information_scope: that block is for vocabularies with no canonical
275
+ // number, and parking a numbered domain there would leave 267 looking free.
276
+ risk_identification_milestone: {
277
+ cvc: 267,
278
+ reason: "no CVC_INDEX row — authored live in Notion 2026-08-29, extractor not re-run",
279
+ },
280
+ // Authored directly in the live Notion inline DB (2026-08-13, restructured
281
+ // 2026-08-14), so no `Final CVCs/` export exists yet and extract_final_cvcs.py
282
+ // emits no row. The number is the domain's own self-declaration —
283
+ // `data/cvcs/core_information_scope.yaml` carries `cvc_id: "CVC-236"` — and
284
+ // nothing else claims 236 (233 and 235 and 238 are bound elsewhere; 236 and
285
+ // 237 are unoccupied), so this is index-absent rather than a squat. NOT parked
286
+ // at 900+ on purpose: that block is for vocabularies with no canonical number,
287
+ // and parking a numbered domain there would leave 236 looking free.
288
+ core_information_scope: {
289
+ cvc: 236,
290
+ reason: "authored in the live Notion inline DB; no Final CVCs/ export yet",
291
+ },
221
292
  // Trunk-only domain: authored on `kl-develop` (80341e0, "promote CVC-17 +
222
293
  // CVC-67 to SOT"), which the canonical 0.8.13 line never saw. Its sibling
223
294
  // CVC-17 (gender_identity) IS in CVC_INDEX.md and is bound above; 67 is not
@@ -225,7 +296,10 @@ const INDEX_ABSENT: Record<string, { cvc: number; reason: string }> = {
225
296
  // other domain claims 67, so it is index-absent rather than a squat. Sourced
226
297
  // from the HMIS data standard via `CVC_67_HMIS_SEX` in `../constants/ic.ts`.
227
298
  hmis_sex: { cvc: 67, reason: "no CVC_INDEX row" },
228
- juvenile_justice_involvement_status: { cvc: 95, reason: "no CVC_INDEX row" },
299
+ // juvenile_justice_involvement_status (95) LEFT this list in the 622410b
300
+ // reconcile — CVC_INDEX.md now carries its row, so it is bound above. This is
301
+ // what the list is FOR: index-absence is a temporary, visible state that gets
302
+ // retired when Notion catches up, not a permanent parking spot.
229
303
  primary_language: { cvc: 122, reason: "no CVC_INDEX row" },
230
304
  hmis_relationship_to_hoh: { cvc: 129, reason: "no CVC_INDEX row" },
231
305
  core_functions: { cvc: 133, reason: "no CVC_INDEX row" },
@@ -241,7 +315,40 @@ const INDEX_ABSENT: Record<string, { cvc: number; reason: string }> = {
241
315
  hmis_project_type: { cvc: 225, reason: "no CVC_INDEX row" },
242
316
  funder: { cvc: 226, reason: "no CVC_INDEX row" },
243
317
  da_incident_severity: { cvc: 228, reason: "no CVC_INDEX row" },
244
- relationship_concern: { cvc: 231, reason: "no CVC_INDEX row" },
318
+ // relationship_concern (231) LEFT this list in the 2026-08-29 renumber — the
319
+ // OTHER way a domain retires from INDEX_ABSENT, and the one that matters.
320
+ // Jevon ratified CVC-231 to the Determination Helper categories on
321
+ // 2026-08-28. This domain had only ever held 231 as a provisional mint taken
322
+ // out of the canonical block, which is exactly why it lived here instead of
323
+ // in CANONICAL_BINDING. Left at 231 it would have become a SQUAT the moment
324
+ // the next cvcIndex pin refresh published the DH row — and per GATE C a squat
325
+ // does not merely mislabel the squatter, it makes the slot look OCCUPIED and
326
+ // hides the absence of the domain that owns it. It is renumbered to the
327
+ // provisional block at CVC-991 (see relationshipConcern.v1.0.0.json
328
+ // `_status.renumber` / `_status.numberChoice`), so `isProvisional()` now
329
+ // exempts it and no entry here is needed. The Determination Helper categories
330
+ // that own 231 are authored directly below — the gap the vacated squat had
331
+ // been hiding, closed in the same branch that vacated it.
332
+ //
333
+ // CVC-231's rightful owner, authored 2026-08-30. This is the SECOND half of the
334
+ // renumber above and the whole point of GATE C: vacating the squat exposed an
335
+ // unauthored canonical vocabulary, and the exposure is only worth anything if
336
+ // the vocabulary then gets authored. `CVC_INDEX.md` @ 622410b has no row for it
337
+ // (grep confirms: the only `determination`-prefixed rows are CVC-138
338
+ // `core - determination_level` and CVC-233 `core-DH_state`), so this is the
339
+ // `core_information_scope` disposition — numbered from the domain's own
340
+ // canonical self-declaration plus a codebook-owner ruling, index-absent until
341
+ // the extractor catches up — and NOT the CVC-181 one, which had a reserved pin
342
+ // row to bind against. NO PIN EDIT: `cvcIndex.pin.json` is machine-derived and
343
+ // `src/__sot__/README.md` forbids hand-editing it; the row arrives on its own
344
+ // refresh cycle and this domain is promoted into CANONICAL_BINDING then.
345
+ determination_helper_categories: {
346
+ cvc: 231,
347
+ reason:
348
+ "no CVC_INDEX row; number self-declared by the canonical " +
349
+ "data/cvcs/core_determination_helper_categories.yaml and ratified to this " +
350
+ "vocabulary by Jevon on 2026-08-28",
351
+ },
245
352
  };
246
353
 
247
354
  /**
@@ -532,17 +639,17 @@ describe("GATE F — entry counts and selectable counts are never conflated", ()
532
639
  }
533
640
  });
534
641
 
535
- it("CVC-69 regression: 19 entries = 14 selectable + 4 group rows + missingness_root", () => {
642
+ it("CVC-69 regression: 20 entries = 15 selectable + 4 group rows + missingness_root", () => {
536
643
  const d = DOMAINS.find((x) => x.domain === "incident_participation_roles")!;
537
644
  const selectable = d.entries.filter((e) => e.selectable);
538
645
  const groupRows = d.entries.filter((e) => !e.selectable && !isMissingness(e));
539
646
  const missRoot = d.entries.filter((e) => !e.selectable && isMissingness(e));
540
647
 
541
- expect(d.entries.length, "total entries").toBe(19);
542
- expect(selectable.length, "selectable").toBe(14);
648
+ expect(d.entries.length, "total entries").toBe(20);
649
+ expect(selectable.length, "selectable").toBe(15);
543
650
  expect(groupRows.length, "non-selectable group rows").toBe(4);
544
651
  expect(missRoot.length, "non-selectable missingness_root").toBe(1);
545
- expect(selectable.length + groupRows.length + missRoot.length).toBe(19);
652
+ expect(selectable.length + groupRows.length + missRoot.length).toBe(20);
546
653
  // If a consumer's boot-check ever asserts `entries.length === 14`, it is the
547
654
  // CONSUMER that is wrong, not CVC-69.
548
655
  });
@@ -577,6 +684,267 @@ describe("GATE G — code and key format", () => {
577
684
  }
578
685
  });
579
686
 
687
+ // ═══════════════════════════════════════════════════════════════════════════
688
+ // H. FIELD FIDELITY — the pin-field-blindness catcher
689
+ // ═══════════════════════════════════════════════════════════════════════════
690
+ /**
691
+ * GATES A and B compare SETS OF CODE NAMES. That is all the pin used to carry,
692
+ * and it is why two consecutive refreshes each shipped half a delta:
693
+ *
694
+ * 0.8.14 — the code delta landed; a DEFINITION REVISION that came with it
695
+ * did not. Green.
696
+ * 0.8.17 — the code delta landed; a LABEL RENAME and a load-bearing
697
+ * DEPRECATION QUALIFIER in a definition did not. Green. Caught by a
698
+ * human reading the diff, which is not a gate.
699
+ *
700
+ * A code can keep its name while everything the catalog SAYS about it is
701
+ * rewritten. `coreIndicators.pin.json` now carries the seven projected fields
702
+ * verbatim (`src/__sot__/coreIndicatorFields.ts`), and this gate asserts
703
+ * CVC-136 restates every one of them faithfully — entry by entry, field by
704
+ * field, naming the code, the field, the catalog value and the shipped value on
705
+ * failure.
706
+ *
707
+ * Normalization is the enumerated exemption list in `coreIndicatorFields.ts`,
708
+ * and H4 below PROVES each exemption is still load-bearing rather than letting
709
+ * it rot into a blanket fuzzy match.
710
+ */
711
+ describe("GATE H — CVC-136 restates every field the catalog states", () => {
712
+ const shipped = new Map<string, ProjectedIndicatorFields>(
713
+ substantiveOf(cvc136).map((e) => [
714
+ e.key,
715
+ projectSotEntry(e as unknown as Record<string, unknown>),
716
+ ]),
717
+ );
718
+ // Defaulted, NOT asserted here, on purpose. A pin regenerated by a
719
+ // pre-field-aware sot-pins.ts has no `fields` at all; reading `Object.keys`
720
+ // off `undefined` throws at COLLECTION time, which collapses the whole file
721
+ // to 0 tests and reports as an import error rather than as the named H1
722
+ // failure that says what to do. Default to empty, then fail loudly in H1.
723
+ const pinFields: Record<string, ProjectedIndicatorFields> = coreIndicatorsPin.fields ?? {};
724
+ const pinnedCodes = Object.keys(pinFields);
725
+
726
+ it("the pin carries projected fields for every pinned code", () => {
727
+ // A pin regenerated by a pre-field-aware sot-pins.ts would be silently
728
+ // field-blind — the exact failure mode this gate exists to end. Refuse it.
729
+ expect(
730
+ Object.keys(pinFields).length,
731
+ "the pin carries no fields — regenerate with npm run sot:pins",
732
+ ).toBeGreaterThan(0);
733
+ expect(pinnedCodes.sort()).toEqual([...coreIndicatorsPin.codes].sort());
734
+ for (const code of pinnedCodes) {
735
+ const fields = pinFields[code]!;
736
+ for (const field of PROJECTED_FIELDS) {
737
+ expect(fields, `${code} is missing projected field "${field}"`).toHaveProperty(field);
738
+ }
739
+ }
740
+ });
741
+
742
+ it("every pinned catalog code is present in CVC-136 (the join is total)", () => {
743
+ // Without this, a code dropped from CVC-136 would make the field comparison
744
+ // below silently SKIP it rather than fail — a gate with a hole in it.
745
+ const absent = pinnedCodes.filter((c) => !shipped.has(c)).sort();
746
+ if (absent.length > 0) {
747
+ throw new Error(
748
+ `${absent.length} code(s) in ${coreIndicatorsPin.sourceFile} ` +
749
+ `@ ${coreIndicatorsPin.sourceSha} are NOT in CVC-136:\n` +
750
+ ` ${absent.join(", ")}\n\n` +
751
+ "GATE B only checks the other direction (CVC-136 invents nothing), so a\n" +
752
+ " catalog code dropped on refresh would otherwise pass unnoticed.\n" +
753
+ "TO FIX: add each to src/cvcs/coreIndicators.v1.0.0.json.",
754
+ );
755
+ }
756
+ expect(absent).toEqual([]);
757
+ });
758
+
759
+ it(`all ${PROJECTED_FIELDS.length} projected fields match, code by code`, () => {
760
+ const mismatches: string[] = [];
761
+
762
+ for (const code of pinnedCodes) {
763
+ const catalog = pinFields[code]!;
764
+ const sot = shipped.get(code);
765
+ if (!sot) continue; // already reported by the join-is-total assertion above
766
+
767
+ for (const field of PROJECTED_FIELDS) {
768
+ // ASYMMETRIC BY DESIGN. E4's `\xNN` decode runs on the CATALOG side
769
+ // only, because CVC-136 is obliged to carry the real character rather
770
+ // than mirror the upstream escape. Decoding both sides would let a
771
+ // shipped literal `fianc\xE9(e)` compare equal and pass. E1/E2/E3/E5
772
+ // are symmetric. See NORMALIZATION_EXEMPTIONS.
773
+ const want = normalizeCatalogValue(field, catalog[field]);
774
+ const got = normalizeSotValue(field, sot[field]);
775
+ if (want === got) continue;
776
+ mismatches.push(
777
+ ` ${code} . ${field}\n` +
778
+ ` catalog: ${want === null ? "(absent)" : JSON.stringify(want)}\n` +
779
+ ` CVC-136: ${got === null ? "(absent)" : JSON.stringify(got)}`,
780
+ );
781
+ }
782
+ }
783
+
784
+ if (mismatches.length > 0) {
785
+ throw new Error(
786
+ `${mismatches.length} field(s) of CVC-136 disagree with the canonical catalog.\n` +
787
+ "The CODE SET is right and the CONTENT is stale — which is precisely what a\n" +
788
+ "code-set-only pin could never see (0.8.14 dropped a definition revision;\n" +
789
+ "0.8.17 dropped a label rename plus a deprecation qualifier).\n\n" +
790
+ `${mismatches.join("\n")}\n\n` +
791
+ "TO FIX: copy the `catalog:` value printed above into the matching entry\n" +
792
+ " of src/cvcs/coreIndicators.v1.0.0.json.\n" +
793
+ " COPY THE PRINTED VALUE, not the raw scalar out of\n" +
794
+ ` ${coreIndicatorsPin.sourceRepo}/${coreIndicatorsPin.sourceFile}` +
795
+ ` @ ${coreIndicatorsPin.sourceSha}.\n` +
796
+ " The printed value is NORMALIZED — wrap points folded, and any leaked\n" +
797
+ " `\\xNN` escape already decoded to the real character. Transcribing the\n" +
798
+ " raw YAML by hand reproduces the escape verbatim (`fianc\\xE9(e)`), which\n" +
799
+ " CVC-136 must NOT carry: the restatement's job is to fix that upstream\n" +
800
+ " defect, and a separate assertion below rejects a shipped `\\xNN`.\n" +
801
+ " Field names differ by design: the catalog's `label` is the envelope's\n" +
802
+ " `title`; `is_alert`/`alert_when` are `isAlert`/`alertWhen`. Then\n" +
803
+ " regenerate CVC_136_CORE_INDICATOR_VALUES in src/constants/ic.ts if the\n" +
804
+ " change touches a name.\n" +
805
+ " If instead the CATALOG moved, run `npm run sot:pins` and restate both.",
806
+ );
807
+ }
808
+ expect(mismatches).toEqual([]);
809
+ });
810
+
811
+ /**
812
+ * BELT AND BRACES FOR E4.
813
+ *
814
+ * The comparison above is already asymmetric, so a shipped `fianc\xE9(e)` now
815
+ * fails it. This asserts the same thing directly, without reference to the
816
+ * catalog, because it is the cheaper and more legible failure: it names E4 and
817
+ * says what a correct restatement looks like, rather than printing two long
818
+ * definitions that differ somewhere in the middle.
819
+ *
820
+ * It also holds if the catalog is ever cleaned up upstream and E4 is deleted:
821
+ * CVC-136 must never carry a Python-style hex escape regardless of why.
822
+ */
823
+ it("no shipped CVC-136 value carries a leaked `\\xNN` escape", () => {
824
+ const offenders: string[] = [];
825
+ for (const [code, fields] of shipped) {
826
+ for (const field of PROJECTED_FIELDS) {
827
+ const value = fields[field];
828
+ if (value !== null && LEAKED_HEX_ESCAPE.test(value)) {
829
+ offenders.push(` ${code} . ${field}: ${JSON.stringify(value)}`);
830
+ }
831
+ }
832
+ }
833
+ expect(
834
+ offenders,
835
+ "These CVC-136 values contain a literal `\\xNN` escape (E4-leaked-hex-escape).\n" +
836
+ "One upstream catalog scalar is authored single-quoted with Python-style\n" +
837
+ "escapes, so `fianc\\xE9` parses as six literal characters. CVC-136's job is to\n" +
838
+ "restate the REAL character (`fiancé`) — copying the raw YAML through\n" +
839
+ "mechanically carries the defect into the shipped codebook.\n" +
840
+ "TO FIX: replace each escape with the character it denotes.\n" +
841
+ `${offenders.join("\n")}`,
842
+ ).toEqual([]);
843
+ });
844
+
845
+ /**
846
+ * H4 — THE EXEMPTIONS ARE PROVEN, NOT ASSUMED.
847
+ *
848
+ * A normalization exemption is a hole in the gate. Each one below is asserted
849
+ * to be (a) still physically present — its `detect` predicate still fires on
850
+ * the raw catalog value — (b) still exercised — a RAW comparison of the fields
851
+ * it covers genuinely fails — and (c) sufficient — the normalized comparison
852
+ * of those fields passes. An exemption that stops being needed fails here and
853
+ * gets deleted, instead of silently widening the gate's blind spot forever.
854
+ *
855
+ * SCOPING, and why both (a) and (b) are needed.
856
+ *
857
+ * The self-tests used to span all seven PROJECTED_FIELDS, so an exemption
858
+ * could look alive on the strength of a DIFFERENT exemption's artifact in a
859
+ * different field. Narrowing to `exemption.fields` fixes most of that — but
860
+ * not all of it, because in the pinned catalog every prose artifact lives in
861
+ * `definition`, and E2 and E4 share BOTH a code and that field. Field scoping
862
+ * alone would still let a dead E4 ride on E2's wrap point.
863
+ *
864
+ * `detect` is what closes it: it asks whether the raw catalog value still
865
+ * contains THIS exemption's artifact — a trailing newline, an interior wrap,
866
+ * a wrapped hyphen, a `\xNN` escape, an empty string — independently of
867
+ * whether some other exemption also fires on the same value.
868
+ */
869
+ describe("the normalization exemptions are each still load-bearing", () => {
870
+ for (const exemption of NORMALIZATION_EXEMPTIONS) {
871
+ it(`${exemption.id} is exercised by ${exemption.codes.join(", ")}`, () => {
872
+ for (const code of exemption.codes) {
873
+ const catalog = pinFields[code];
874
+ const sot = shipped.get(code);
875
+ expect(catalog, `${exemption.id}: ${code} is no longer in the pin`).toBeDefined();
876
+ expect(sot, `${exemption.id}: ${code} is no longer in CVC-136`).toBeDefined();
877
+
878
+ // Scoped to the fields THIS exemption claims to cover.
879
+ const fields = exemption.fields;
880
+
881
+ const detected = fields.some((f) => {
882
+ const raw = catalog![f];
883
+ return raw !== null && exemption.detect(raw);
884
+ });
885
+ const rawDiffers = fields.some((f) => catalog![f] !== sot![f]);
886
+ const normalizedMatches = fields.every(
887
+ (f) => normalizeCatalogValue(f, catalog![f]) === normalizeSotValue(f, sot![f]),
888
+ );
889
+
890
+ expect(
891
+ detected,
892
+ `${exemption.id}: the artifact is GONE from ${code}.${fields.join("/")} — ` +
893
+ "the raw catalog value no longer contains it, so this exemption is dead. " +
894
+ "Delete it from NORMALIZATION_EXEMPTIONS in src/__sot__/coreIndicatorFields.ts " +
895
+ "rather than leaving an unused hole in the gate. (Checked separately from " +
896
+ "the raw-differs assertion below because two exemptions can overlap on one " +
897
+ "code and field — E2 and E4 do — and then a raw difference proves nothing " +
898
+ "about which of them is still needed.)",
899
+ ).toBe(true);
900
+ expect(
901
+ rawDiffers,
902
+ `${exemption.id}: ${code}.${fields.join("/")} now matches VERBATIM — this ` +
903
+ "exemption is dead. Delete it from NORMALIZATION_EXEMPTIONS in " +
904
+ "src/__sot__/coreIndicatorFields.ts rather than leaving an unused hole " +
905
+ "in the gate.",
906
+ ).toBe(true);
907
+ expect(
908
+ normalizedMatches,
909
+ `${exemption.id}: ${code}.${fields.join("/")} still differs AFTER ` +
910
+ "normalization — the exemption no longer covers what it claims to. " +
911
+ "Read the GATE H failure above.",
912
+ ).toBe(true);
913
+ }
914
+ });
915
+ }
916
+
917
+ it("every round-trip artifact in the catalog is an enumerated one", () => {
918
+ // Guard the escape hatch the way GATE B guards SCORING_AHEAD_OF_CATALOG:
919
+ // the list must stay a documented enumeration, not a dumping ground.
920
+ //
921
+ // Scoped to codes whose raw fields differ but whose NORMALIZED fields
922
+ // agree — that is the definition of a round-trip artifact. Codes that
923
+ // differ after normalization are real drift and belong to the GATE H
924
+ // failure above; reporting them here too would just double the noise.
925
+ const named = new Set<string>(NORMALIZATION_EXEMPTIONS.flatMap((e) => [...e.codes]));
926
+ const artifacts = pinnedCodes.filter((code) => {
927
+ const catalog = pinFields[code]!;
928
+ const sot = shipped.get(code);
929
+ if (!sot) return false;
930
+ const rawDiffers = PROJECTED_FIELDS.some((f) => catalog[f] !== sot[f]);
931
+ const normalizedMatches = PROJECTED_FIELDS.every(
932
+ (f) => normalizeCatalogValue(f, catalog[f]) === normalizeSotValue(f, sot[f]),
933
+ );
934
+ return rawDiffers && normalizedMatches;
935
+ });
936
+ const undocumented = artifacts.filter((c) => !named.has(c)).sort();
937
+ expect(
938
+ undocumented,
939
+ "These codes are absorbed by normalization but named by no exemption. Each is a " +
940
+ "NEW round-trip artifact: read it, confirm it is formatting and not content, then " +
941
+ "document it in NORMALIZATION_EXEMPTIONS in src/__sot__/coreIndicatorFields.ts. " +
942
+ "An undocumented one is a hole nobody has looked through.",
943
+ ).toEqual([]);
944
+ });
945
+ });
946
+ });
947
+
580
948
  // ═══════════════════════════════════════════════════════════════════════════
581
949
  // Pin provenance — the pins must say where they came from.
582
950
  // ═══════════════════════════════════════════════════════════════════════════
@@ -593,11 +961,76 @@ describe("SOT pins carry their provenance", () => {
593
961
  }
594
962
  });
595
963
 
596
- it("the pinned SOT is the one 0.8.13 was authored against", () => {
597
- expect(cvcIndexPin.sourceSha).toBe("a596eb9");
598
- expect(coreIndicatorsPin.sourceSha).toBe("a596eb9");
964
+ it("the pinned SOT is the one this release was authored against", () => {
965
+ // cvcIndex advanced a596eb9 -> 622410b (the 2026-08-02 targeted live-Notion
966
+ // refresh of the legal-history arc tails), WITH the conformance it implies —
967
+ // the reconcile the previous release deferred rather than fake. Four row
968
+ // deltas, and what each one actually required:
969
+ //
970
+ // CVC-177 ["core - administering jurisdiction", -> ["core - administering_jurisdiction"]
971
+ // "core - administering_jurisdiction"]
972
+ // The space-named row was a STALE DUPLICATE export and was
973
+ // removed. NOT bookkeeping: CANONICAL_BINDING was bound to the
974
+ // spelling that no longer exists, so the bump alone would have
975
+ // failed GATE C. The binding now names the surviving row.
976
+ //
977
+ // CVC-95 null -> ["core - juvenile_justice_involvement_status"]
978
+ // The domain was already authored and already correct; it sat in
979
+ // INDEX_ABSENT only because no index row existed to bind it to.
980
+ // Now bound. Left in INDEX_ABSENT it would have read as a SQUAT,
981
+ // because a number the index speaks about constrains whoever
982
+ // occupies it. Linkage only — nothing authored.
983
+ //
984
+ // CVC-93 null -> ["core - child_welfare_involvement_status"]
985
+ // CVC-196 ["core child welfare cvc", -> ["core - child_welfare_episode_type"]
986
+ // "core child welfare episode type CVC"]
987
+ // Bookkeeping. platform-common ships NO domain at 93 or 196, so
988
+ // no gate constrains them and nothing here had to change. They
989
+ // are now KNOWN-OCCUPIED numbers, which is the point: authoring
990
+ // either later must land on its own number, and a future domain
991
+ // drifting onto 93/196 is now a detectable squat rather than a
992
+ // silent one. Authoring the vocabularies themselves is clinical
993
+ // content (Crysta-owned) and is deliberately not done here.
994
+ //
995
+ // The three index-name/status-only churns in the same refresh (CVC-159
996
+ // unchanged row, CVC-85 and CVC-145 status promotions) carry no pin delta:
997
+ // the pin captures the NUMBER -> NAMES map, not the status column.
998
+ // coreIndicators advanced to 84a1b67 in 0.8.14 (+5 upstream mints, 0
999
+ // withdrawn) and to 622410b in this refresh (+1: `active_protective_order`,
1000
+ // minted upstream 2026-08-08, `code_status: canonical`, plus the projected-
1001
+ // field revisions on 136-007 / 136-094); scoringEmits is unchanged,
1002
+ // so the 2 SCORING_AHEAD_OF_CATALOG codes remain ahead of the catalog
1003
+ // exactly as before.
1004
+ //
1005
+ // coreIndicators was WIDENED (not bumped) to carry the projected `fields`
1006
+ // that GATE H enforces — same SHA, same 214 codes, more of what the catalog
1007
+ // says about each. The two refreshes that dropped their field delta are why.
1008
+ //
1009
+ // 622410b's CVC_INDEX.md is a HAND-REFRESHED live-Notion state that upstream
1010
+ // marks NON-REPRODUCIBLE by `tools/extract_final_cvcs.py`: its banner says
1011
+ // "Do NOT re-run tools/extract_final_cvcs.py until the next full Notion
1012
+ // re-export lands — it would clobber the refreshed extracts and resurrect
1013
+ // index rows from the stale zips" — i.e. a premature re-run brings the
1014
+ // space-named CVC-177 duplicate back and takes CVC-95's row away again.
1015
+ // GATE C fails loudly on the CVC-95 half (a bound domain sits on it); the
1016
+ // 93/196 half is invisible to every gate, since GATE C only iterates bound
1017
+ // domains and occupied numbers and platform-common ships neither. The row
1018
+ // count below is what makes that half detectable at all — a regenerated pin
1019
+ // that silently drops those deliberately-recorded rows fails here.
1020
+ //
1021
+ // 2026-08-26 — CVC-181 `core - countries` was authored, and its pin row went
1022
+ // from RESERVED (a row the index speaks about that nothing occupied — the
1023
+ // 93/196 category above) to OCCUPIED. NO PIN DELTA: the row already read
1024
+ // ["core - countries"] and upstream did not move, so the pin stays at
1025
+ // 622410b and stays machine-derived. The change is on OUR side of the
1026
+ // contract and is recorded as a CANONICAL_BINDING entry with its disposition
1027
+ // written next to it. This is the shape every reserved-row authoring should
1028
+ // take: bind, do not bump.
1029
+ expect(cvcIndexPin.sourceSha).toBe("622410b");
1030
+ expect(coreIndicatorsPin.sourceSha).toBe("622410b");
599
1031
  expect(scoringEmitsPin.sourceSha).toBe("9b5d654");
600
- expect(coreIndicatorsPin.codes.length).toBe(208);
1032
+ expect(Object.keys(cvcIndexPin.numbers).length, "cvcIndexPin.numbers rows").toBe(86);
1033
+ expect(coreIndicatorsPin.codes.length).toBe(214);
601
1034
  expect(scoringEmitsPin.codes.length).toBe(169);
602
1035
  });
603
1036
  });