@htilabs/platform-common-models 0.12.0 → 0.12.2

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