@htilabs/platform-common-models 0.9.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.
- package/dist/config/index.cjs +4 -0
- package/dist/config/index.cjs.map +1 -1
- package/dist/config/index.d.cts +16 -1
- package/dist/config/index.d.ts +16 -1
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -1
- package/dist/constants/index.cjs +473 -182
- package/dist/constants/index.cjs.map +1 -1
- package/dist/constants/index.d.cts +1 -1
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.js +470 -170
- package/dist/constants/index.js.map +1 -1
- package/dist/cvc-Cp4uWnAa.d.cts +298 -0
- package/dist/cvc-Cp4uWnAa.d.ts +298 -0
- package/dist/cvcs/index.cjs +21798 -811
- package/dist/cvcs/index.cjs.map +1 -1
- package/dist/cvcs/index.d.cts +25138 -2212
- package/dist/cvcs/index.d.ts +25138 -2212
- package/dist/cvcs/index.js +21736 -810
- package/dist/cvcs/index.js.map +1 -1
- package/dist/enums/index.cjs +4557 -0
- package/dist/enums/index.cjs.map +1 -0
- package/dist/enums/index.d.cts +5257 -0
- package/dist/enums/index.d.ts +5257 -0
- package/dist/enums/index.js +4354 -0
- package/dist/enums/index.js.map +1 -0
- package/dist/index.cjs +24053 -1052
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -3072
- package/dist/index.d.ts +5 -3072
- package/dist/index.js +23928 -1039
- package/dist/index.js.map +1 -1
- package/dist/mongo/index.cjs +383 -0
- package/dist/mongo/index.cjs.map +1 -0
- package/dist/mongo/index.d.cts +221 -0
- package/dist/mongo/index.d.ts +221 -0
- package/dist/mongo/index.js +351 -0
- package/dist/mongo/index.js.map +1 -0
- package/dist/{platform-auth-XVB9aHqR.d.cts → platform-auth-Dv5fu0Fh.d.cts} +22 -77
- package/dist/{platform-auth-XVB9aHqR.d.ts → platform-auth-Dv5fu0Fh.d.ts} +22 -77
- package/dist/schemas/index.cjs +30 -157
- package/dist/schemas/index.cjs.map +1 -1
- package/dist/schemas/index.js +30 -157
- package/dist/schemas/index.js.map +1 -1
- package/dist/services/index.cjs +0 -3
- package/dist/services/index.cjs.map +1 -1
- package/dist/services/index.js +0 -3
- package/dist/services/index.js.map +1 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/validation/index.cjs +58 -0
- package/dist/validation/index.cjs.map +1 -1
- package/dist/validation/index.d.cts +82 -283
- package/dist/validation/index.d.ts +82 -283
- package/dist/validation/index.js +57 -0
- package/dist/validation/index.js.map +1 -1
- package/package.json +18 -1
- package/src/__sot__/README.md +91 -0
- package/src/__sot__/coreIndicatorFields.ts +331 -0
- package/src/__sot__/coreIndicators.pin.json +2149 -0
- package/src/__sot__/cvcIndex.pin.json +272 -0
- package/src/__sot__/scoringEmits.pin.json +176 -0
- package/src/__tests__/__snapshots__/cvc-sot.snap +260 -40
- package/src/__tests__/core-information-scope-invariant.test.ts +134 -0
- package/src/__tests__/cvc-136-scoring-invariant.test.ts +328 -0
- package/src/__tests__/cvc-181-182-country-parity.test.ts +163 -0
- package/src/__tests__/cvc-drift-gate.test.ts +1036 -0
- package/src/__tests__/cvc-sot-snapshot.test.ts +191 -18
- package/src/__tests__/cvc-status-parser.test.ts +150 -0
- package/src/__tests__/cvc-structural.test.ts +70 -1
- package/src/__tests__/mongo-verifier.test.ts +502 -0
- package/src/config/index.ts +8 -2
- package/src/constants/ic.ts +629 -206
- package/src/constants/service-catalog.ts +4 -2
- package/src/cvcs/activityType.v1.0.0.json +143 -0
- package/src/cvcs/adminRoles.v1.0.0.json +153 -0
- package/src/cvcs/administeringJurisdiction.v1.0.0.json +40 -40
- package/src/cvcs/ageBinReporting.v1.0.0.json +40 -40
- package/src/cvcs/assertionDomain.v1.1.0.json +647 -0
- package/src/cvcs/assertionStatus.v1.0.0.json +80 -0
- package/src/cvcs/carCorrectionReason.v1.0.0.json +89 -0
- package/src/cvcs/caseShareState.v1.0.0.json +62 -0
- package/src/cvcs/{checkInPhase.v1.0.0.json → checkInPhase.v1.1.0.json} +20 -2
- package/src/cvcs/childChangeType.v1.0.0.json +152 -0
- package/src/cvcs/citizenship.v1.0.0.json +3062 -0
- package/src/cvcs/contactInfoTypes.v1.0.0.json +40 -40
- package/src/cvcs/contactLinkType.v1.0.0.json +89 -0
- package/src/cvcs/coreDhState.v1.0.0.json +113 -0
- package/src/cvcs/coreFunctions.v1.0.0.json +746 -0
- package/src/cvcs/coreIndicators.v1.0.0.json +2918 -0
- package/src/cvcs/coreInformationScope.v1.0.0.json +1165 -0
- package/src/cvcs/coreReferralOutcome.v1.0.0.json +71 -0
- package/src/cvcs/countries.v1.0.0.json +3077 -0
- package/src/cvcs/createdBySystem.v1.0.0.json +89 -0
- package/src/cvcs/criminalOrgCategory.v1.0.0.json +116 -0
- package/src/cvcs/determinationHelperCategories.v1.0.0.json +1166 -0
- package/src/cvcs/employmentStatus.v1.0.0.json +60 -60
- package/src/cvcs/exploitationType.v1.0.0.json +106 -0
- package/src/cvcs/facilitatorEntityType.v1.0.0.json +40 -40
- package/src/cvcs/highestEducationLevelCompleted.v1.0.0.json +55 -46
- package/src/cvcs/hivStatus.v1.0.0.json +71 -0
- package/src/cvcs/hmisCurrentLivingSituation.v1.0.0.json +409 -0
- package/src/cvcs/hmisRelationshipToHoh.v1.0.0.json +104 -0
- package/src/cvcs/homelessStatus.v1.0.0.json +27 -27
- package/src/cvcs/housingSubsidyTypes.v1.0.0.json +161 -0
- package/src/cvcs/htType.v1.0.0.json +87 -0
- package/src/cvcs/identificationStatus.v1.0.0.json +18 -0
- package/src/cvcs/immigrationLegalStatusChangeType.v1.0.0.json +143 -0
- package/src/cvcs/incarcerationEpisodeType.v1.0.0.json +106 -0
- package/src/cvcs/incidentInvolvementRoles.v1.0.0.json +40 -40
- package/src/cvcs/incidentParticipationRoles.v1.0.0.json +47 -37
- package/src/cvcs/incomeBenefitsSources.v1.0.0.json +31 -2
- package/src/cvcs/index.ts +138 -1
- package/src/cvcs/juvenileJusticeEpisodeType.v1.0.0.json +28 -18
- package/src/cvcs/juvenileJusticeInvolvementStatus.v1.0.0.json +32 -32
- package/src/cvcs/livingSituation.v1.0.0.json +213 -0
- package/src/cvcs/mentalHealthStatus.v1.0.0.json +71 -0
- package/src/cvcs/militaryBranch.v1.0.0.json +20 -20
- package/src/cvcs/militaryStatus.v1.0.0.json +20 -20
- package/src/cvcs/minorAdultStatus.v1.0.0.json +80 -0
- package/src/cvcs/nameType.v1.0.0.json +40 -40
- package/src/cvcs/needsAssessmentChangeType.v1.0.0.json +134 -0
- package/src/cvcs/offenderStatus.v1.0.0.json +40 -40
- package/src/cvcs/offenderStatusFamily.v1.0.0.json +36 -36
- package/src/cvcs/personRelationships.v1.0.0.json +67 -2
- package/src/cvcs/poPetitionBasis.v1.0.0.json +96 -0
- package/src/cvcs/poStatus.v1.0.0.json +144 -0
- package/src/cvcs/poViolationStatus.v1.0.0.json +76 -0
- package/src/cvcs/programEnrollmentChangeType.v1.0.0.json +134 -0
- package/src/cvcs/provenanceSourceId.v1.0.0.json +134 -0
- package/src/cvcs/radiusBucket.v1.0.0.json +110 -0
- package/src/cvcs/recencyBand.v1.0.0.json +104 -39
- package/src/cvcs/referralEntityCategory.v1.0.0.json +40 -40
- package/src/cvcs/referralOrigin.v1.0.0.json +26 -0
- package/src/cvcs/relationshipConcern.v1.0.0.json +123 -0
- package/src/cvcs/riskCategory.v1.0.0.json +134 -0
- package/src/cvcs/riskIdentificationMilestone.v1.0.0.json +109 -0
- package/src/cvcs/riskSeverityBand.v1.0.0.json +139 -0
- package/src/cvcs/roiMethod.v1.0.0.json +107 -0
- package/src/cvcs/roiScope.v1.0.0.json +296 -0
- package/src/cvcs/roiStatus.v1.0.0.json +106 -0
- package/src/cvcs/romanticRelationshipChangeType.v1.0.0.json +162 -0
- package/src/cvcs/serviceAudience.v1.0.0.json +96 -0
- package/src/cvcs/serviceCategories.v1.0.0.json +44 -44
- package/src/cvcs/serviceDeliveryChannel.v1.0.0.json +147 -0
- package/src/cvcs/serviceMechanisms.v1.0.0.json +36 -36
- package/src/cvcs/serviceStates.v1.0.0.json +55 -33
- package/src/cvcs/sessionNoteVisibility.v1.0.0.json +80 -0
- package/src/cvcs/sessionTemplate.v1.0.0.json +283 -0
- package/src/cvcs/sexProviderSubrole.v1.0.0.json +35 -28
- package/src/cvcs/sharePurpose.v1.0.0.json +80 -12
- package/src/cvcs/smtType.v1.0.0.json +40 -40
- package/src/cvcs/sourceCategory.v1.1.0.json +8 -1
- package/src/cvcs/sourceInstrument.v1.0.0.json +458 -0
- package/src/cvcs/sourceSubtype.v1.1.0.json +36 -0
- package/src/cvcs/sourceSystem.v1.0.0.json +203 -0
- package/src/cvcs/specialNeedsDisabilities.v1.0.0.json +143 -0
- package/src/cvcs/subjectType.v1.0.0.json +80 -0
- package/src/cvcs/suggestionSource.v1.0.0.json +71 -0
- package/src/cvcs/traffickingRelevantRole.v1.0.0.json +104 -0
- package/src/cvcs/userRoles.v1.0.0.json +203 -0
- package/src/cvcs/verificationMethod.v1.0.0.json +18 -0
- package/src/cvcs/victimAbuseTypes.v1.0.0.json +276 -0
- package/src/cvcs/victimStatusFamily.v1.0.0.json +40 -40
- package/src/cvcs/whyNots.v1.0.0.json +385 -0
- package/src/generated/cvc-enums.ts +2318 -10
- package/src/mongo/catalog.ts +65 -0
- package/src/mongo/contract.ts +157 -0
- package/src/mongo/index.ts +343 -0
- package/src/mongo/similarity.ts +133 -0
- package/src/mongo/uri.ts +53 -0
- package/src/services/cvcRegistryService.ts +1 -1
- package/src/validation/cvcStatus.ts +209 -0
- package/src/validation/index.ts +1 -0
|
@@ -0,0 +1,1036 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE CVC DRIFT GATE
|
|
3
|
+
* ==================
|
|
4
|
+
*
|
|
5
|
+
* platform-common's CVC surface is DOWNSTREAM of three sources of truth:
|
|
6
|
+
*
|
|
7
|
+
* CVC_INDEX.md -> the NUMBER space (which CVC number is whose)
|
|
8
|
+
* core_indicators.yaml -> the indicator CATALOG (what codes legitimately exist)
|
|
9
|
+
* hti-scoring emits_by_code -> what is actually CONSUMED (what must be expressible)
|
|
10
|
+
* Notion -> ratification
|
|
11
|
+
*
|
|
12
|
+
* Before this gate existed, platform-common validated itself against ITSELF. It
|
|
13
|
+
* therefore drifted, silently, in every direction at once. 0.8.13 found:
|
|
14
|
+
*
|
|
15
|
+
* - 66 canonical indicator codes MISSING from CVC-136 — including the entire
|
|
16
|
+
* perpetrator lane, which made facilitator scoring literally unexpressible.
|
|
17
|
+
* - 56 INVENTED codes that existed nowhere upstream and were consumed by nobody.
|
|
18
|
+
* - `housing_subsidy_types` SQUATTING on CVC-233, a number that canonically
|
|
19
|
+
* belongs to `core-DH_state`. The squat did not merely mislabel a domain: it
|
|
20
|
+
* made the slot look OCCUPIED, so the gap analysis never noticed that
|
|
21
|
+
* `dh_state` was missing ENTIRELY. **A wrong number HIDES the absence of the
|
|
22
|
+
* domain that owns that number.** That is the single most valuable thing this
|
|
23
|
+
* gate prevents (assertion C).
|
|
24
|
+
* - A false "CVC-69 is broken" conclusion, caused by comparing an ENTRY count
|
|
25
|
+
* against a SELECTABLE count (assertion F).
|
|
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
|
+
*
|
|
33
|
+
* Every assertion below maps to a real bug that shipped. This test is HERMETIC:
|
|
34
|
+
* it reads only the committed pins in `src/__sot__/`, so it runs on every PR with
|
|
35
|
+
* no cross-repo auth. The pins are refreshed (and upstream drift is detected) by
|
|
36
|
+
* `scripts/sot-pins.ts`, run weekly by `.github/workflows/cvc-sot-drift.yml`.
|
|
37
|
+
*
|
|
38
|
+
* THE TWO HALVES ARE BOTH REQUIRED:
|
|
39
|
+
* - this test = the ENFORCER (does the package match the pins?)
|
|
40
|
+
* - sot-pins = the DETECTOR (have the pins fallen behind upstream?)
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
44
|
+
import path from "node:path";
|
|
45
|
+
import { fileURLToPath } from "node:url";
|
|
46
|
+
|
|
47
|
+
import { describe, it, expect } from "vitest";
|
|
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
|
+
|
|
59
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
60
|
+
const CVCS_DIR = path.resolve(__dirname, "..", "cvcs");
|
|
61
|
+
const SOT_DIR = path.resolve(__dirname, "..", "__sot__");
|
|
62
|
+
|
|
63
|
+
// ─── The committed pins ─────────────────────────────────────────────────────
|
|
64
|
+
|
|
65
|
+
interface Pin {
|
|
66
|
+
sourceRepo: string;
|
|
67
|
+
sourceFile: string;
|
|
68
|
+
sourceSha: string;
|
|
69
|
+
}
|
|
70
|
+
const cvcIndexPin = JSON.parse(
|
|
71
|
+
readFileSync(path.join(SOT_DIR, "cvcIndex.pin.json"), "utf-8"),
|
|
72
|
+
) as Pin & { numbers: Record<string, string[]> };
|
|
73
|
+
const coreIndicatorsPin = JSON.parse(
|
|
74
|
+
readFileSync(path.join(SOT_DIR, "coreIndicators.pin.json"), "utf-8"),
|
|
75
|
+
) as Pin & { codes: string[]; fields: Record<string, ProjectedIndicatorFields> };
|
|
76
|
+
const scoringEmitsPin = JSON.parse(
|
|
77
|
+
readFileSync(path.join(SOT_DIR, "scoringEmits.pin.json"), "utf-8"),
|
|
78
|
+
) as Pin & { codes: string[] };
|
|
79
|
+
|
|
80
|
+
// ─── The package under test ─────────────────────────────────────────────────
|
|
81
|
+
|
|
82
|
+
interface Entry {
|
|
83
|
+
code: string;
|
|
84
|
+
key: string;
|
|
85
|
+
selectable: boolean;
|
|
86
|
+
parentCode: string | null;
|
|
87
|
+
childCodes: string[];
|
|
88
|
+
}
|
|
89
|
+
interface Envelope {
|
|
90
|
+
domain: string;
|
|
91
|
+
entries: Entry[];
|
|
92
|
+
_status?: unknown;
|
|
93
|
+
}
|
|
94
|
+
interface Domain {
|
|
95
|
+
file: string;
|
|
96
|
+
domain: string;
|
|
97
|
+
cvc: number;
|
|
98
|
+
entries: Entry[];
|
|
99
|
+
env: Envelope;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const DOMAINS: Domain[] = readdirSync(CVCS_DIR)
|
|
103
|
+
.filter((f) => f.endsWith(".json"))
|
|
104
|
+
.sort()
|
|
105
|
+
.map((file) => {
|
|
106
|
+
const env = JSON.parse(
|
|
107
|
+
readFileSync(path.join(CVCS_DIR, file), "utf-8"),
|
|
108
|
+
) as Envelope;
|
|
109
|
+
return {
|
|
110
|
+
file,
|
|
111
|
+
domain: env.domain,
|
|
112
|
+
cvc: Number(env.entries[0]!.code.split("-")[0]),
|
|
113
|
+
entries: env.entries,
|
|
114
|
+
env,
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The provisional block. These are net-new vocabularies that Notion has not
|
|
120
|
+
* numbered yet; they are DELIBERATELY parked at 900+ and are exempt from the
|
|
121
|
+
* CVC_INDEX number check (there is nothing to check them against). This is the
|
|
122
|
+
* sanctioned escape hatch — it is what keeps "we needed a vocabulary" from
|
|
123
|
+
* turning into "we squatted on a canonical number".
|
|
124
|
+
*/
|
|
125
|
+
const PROVISIONAL_FLOOR = 900;
|
|
126
|
+
const isProvisional = (d: Domain): boolean => d.cvc >= PROVISIONAL_FLOOR;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Every canonical-block domain that CVC_INDEX.md DOES have a row for, bound to
|
|
130
|
+
* that row by EXACT STRING. No fuzzy matching: adding a domain forces you to
|
|
131
|
+
* state which index row it is, and a typo fails rather than silently "matching".
|
|
132
|
+
*/
|
|
133
|
+
const CANONICAL_BINDING: Record<string, { cvc: number; indexName: string }> = {
|
|
134
|
+
name_type: { cvc: 1, indexName: "core - name_type" },
|
|
135
|
+
orientation_identity: { cvc: 16, indexName: "core - orientation_identity" },
|
|
136
|
+
gender_identity: { cvc: 17, indexName: "core - gender_identity" },
|
|
137
|
+
victim_status_family: { cvc: 20, indexName: "core - victim_status_family" },
|
|
138
|
+
service_mechanisms: { cvc: 25, indexName: "core service mechanism" },
|
|
139
|
+
service_audience: { cvc: 45, indexName: "core service audience beneficiary" },
|
|
140
|
+
service_delivery_channel: { cvc: 47, indexName: "core service delivery channel" },
|
|
141
|
+
referral_entity_category: { cvc: 48, indexName: "core-referral_entity_category" },
|
|
142
|
+
service_states: { cvc: 49, indexName: "core - service state" },
|
|
143
|
+
age_bin_reporting: { cvc: 51, indexName: "core - age_bin_reporting" },
|
|
144
|
+
incident_participation_roles: { cvc: 69, indexName: "core - incident_participation_role" },
|
|
145
|
+
ht_type: { cvc: 72, indexName: "core - ht_type" },
|
|
146
|
+
victim_abuse_types: { cvc: 73, indexName: "core victim abuse types cvc" },
|
|
147
|
+
race_ethnicity: { cvc: 76, indexName: "core_Race:Ethnicity" },
|
|
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
|
+
},
|
|
160
|
+
homeless_status: { cvc: 96, indexName: "core - homeless_status" },
|
|
161
|
+
military_branch: { cvc: 120, indexName: "core - military branch" },
|
|
162
|
+
military_status: { cvc: 121, indexName: "core - military status" },
|
|
163
|
+
person_relationships: { cvc: 126, indexName: "core person relationship CVC" },
|
|
164
|
+
incident_involvement_roles: { cvc: 130, indexName: "core - incident_involvement_role" },
|
|
165
|
+
user_roles: { cvc: 135, indexName: "core - user roles" },
|
|
166
|
+
core_indicators: { cvc: 136, indexName: "core - indicators" },
|
|
167
|
+
recency_band: { cvc: 137, indexName: "recency_band" },
|
|
168
|
+
determination_level: { cvc: 138, indexName: "core - determination_level" },
|
|
169
|
+
support_strength: { cvc: 139, indexName: "core - support_strength" },
|
|
170
|
+
source_category: { cvc: 140, indexName: "core - source_category" },
|
|
171
|
+
source_subtype: { cvc: 141, indexName: "core - source_subtype" },
|
|
172
|
+
inference_type: { cvc: 142, indexName: "core - inference_type" },
|
|
173
|
+
verification_method: { cvc: 143, indexName: "core - verification_method" },
|
|
174
|
+
quality_flags: { cvc: 144, indexName: "core - quality_flags" },
|
|
175
|
+
relationship_dynamics: { cvc: 145, indexName: "core relationship dynamics cvc" },
|
|
176
|
+
pronouns: { cvc: 147, indexName: "core - pronouns" },
|
|
177
|
+
contact_info_types: { cvc: 149, indexName: "core - contact info types" },
|
|
178
|
+
eye_color: { cvc: 150, indexName: "core - eye_color" },
|
|
179
|
+
hair_color: { cvc: 151, indexName: "core - hair_color" },
|
|
180
|
+
has_tattoos: { cvc: 152, indexName: "core - has_tattoos" },
|
|
181
|
+
smt_type: { cvc: 153, indexName: "core - SMT_type" },
|
|
182
|
+
contact_safety_status: { cvc: 155, indexName: "core-contact_safety_status" },
|
|
183
|
+
marital_status_legal: { cvc: 156, indexName: "core - marital status legal" },
|
|
184
|
+
relationship_status_current: { cvc: 157, indexName: "core - relationship status current" },
|
|
185
|
+
relationship_ties: { cvc: 158, indexName: "relationship ties cvc" },
|
|
186
|
+
assertion_domain: { cvc: 159, indexName: "core - assertion_domain" },
|
|
187
|
+
role_context: { cvc: 160, indexName: "core - role_context" },
|
|
188
|
+
sex_provider_subrole: { cvc: 161, indexName: "core - sex_provider_subrole" },
|
|
189
|
+
facilitator_subrole: { cvc: 162, indexName: "core - facilitator_subrole" },
|
|
190
|
+
offender_status: { cvc: 164, indexName: "core - offender_status" },
|
|
191
|
+
facilitator_entity_type: { cvc: 165, indexName: "core facilitator entity type" },
|
|
192
|
+
facilitator_label_used_in_source: {
|
|
193
|
+
cvc: 166,
|
|
194
|
+
indexName: "core - facilitator_label_used_in_source",
|
|
195
|
+
},
|
|
196
|
+
offender_status_family: { cvc: 167, indexName: "core - offender_status_family" },
|
|
197
|
+
income_benefits_sources: { cvc: 171, indexName: "core - income : benefits sources" },
|
|
198
|
+
time_scope: { cvc: 174, indexName: "core - time_scope" },
|
|
199
|
+
enrollment_application_status: { cvc: 175, indexName: "core - enrollment application status" },
|
|
200
|
+
frequency_cadence: { cvc: 176, indexName: "core - frequency : cadence" },
|
|
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" },
|
|
206
|
+
employment_status: { cvc: 179, indexName: "core - employment status" },
|
|
207
|
+
highest_education_level_completed: {
|
|
208
|
+
cvc: 180,
|
|
209
|
+
indexName: "core - highest education level_completed",
|
|
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" },
|
|
226
|
+
citizenship: { cvc: 182, indexName: "core - citizenship" },
|
|
227
|
+
location_type: { cvc: 191, indexName: "core - location_type" },
|
|
228
|
+
living_situation: { cvc: 192, indexName: "core - living situation" },
|
|
229
|
+
hmis_current_living_situation: { cvc: 193, indexName: "HMIS 4.12 - current living situation" },
|
|
230
|
+
housing_subsidy_types: { cvc: 194, indexName: "core - housing subsidy types" },
|
|
231
|
+
collection_context: { cvc: 195, indexName: "core - collection_context" },
|
|
232
|
+
juvenile_justice_episode_type: { cvc: 197, indexName: "core - juvenile_justice_episode_type" },
|
|
233
|
+
incarceration_episode_type: { cvc: 198, indexName: "core - incarceration episode type" },
|
|
234
|
+
source_system: { cvc: 201, indexName: "core - source_system" },
|
|
235
|
+
exploitation_type: { cvc: 203, indexName: "core - exploitation_type" },
|
|
236
|
+
source_instrument: { cvc: 209, indexName: "core - source_instrument" },
|
|
237
|
+
po_petition_basis: { cvc: 213, indexName: "core - PO_petition_basis CVC" },
|
|
238
|
+
po_status: { cvc: 214, indexName: "core - PO_status CVC" },
|
|
239
|
+
po_violation_status: { cvc: 215, indexName: "core PO violation status CVC" },
|
|
240
|
+
session_template: { cvc: 217, indexName: "core - session templates" },
|
|
241
|
+
languages: { cvc: 223, indexName: "core-languages" },
|
|
242
|
+
dh_state: { cvc: 233, indexName: "core-DH_state" },
|
|
243
|
+
risk_severity_band: { cvc: 238, indexName: "core-risk_severity_band" },
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Canonical-block domains that CVC_INDEX.md has NO row for. They are NOT
|
|
248
|
+
* exempt from the squat check (assertion C3) — they are merely unconstrained by
|
|
249
|
+
* a name, because the index says nothing about their number. Listing them here
|
|
250
|
+
* is the point: an index-absent domain must be a DELIBERATE, visible decision,
|
|
251
|
+
* never a silent one. Each is a Notion reconciliation item.
|
|
252
|
+
*/
|
|
253
|
+
const INDEX_ABSENT: Record<string, { cvc: number; reason: string }> = {
|
|
254
|
+
// CVC_INDEX.md is auto-generated by tools/extract_final_cvcs.py, which emits
|
|
255
|
+
// one row per readable `.md`. This CVC's Notion page body exported as PDF
|
|
256
|
+
// only, so the extractor skips it — the SAME documented gap that CVC_INDEX.md
|
|
257
|
+
// itself records at line 20 for core-DH_state/233. Its canonical codebook
|
|
258
|
+
// `.csv` (+ `.zip`, `.pdf`) IS present in Final CVCs/, and both yamls that
|
|
259
|
+
// mention 235 agree this vocabulary owns it.
|
|
260
|
+
trafficking_relevant_role: { cvc: 235, reason: "extractor gap: Notion body is PDF-only" },
|
|
261
|
+
|
|
262
|
+
// Numbered from the domain's own canonical source (a codebook `.csv`, a
|
|
263
|
+
// `data/cvcs/*.yaml` self-declaration, or a prior platform-common release),
|
|
264
|
+
// but CVC_INDEX.md carries no row. Not a squat (nothing else claims these
|
|
265
|
+
// numbers) — but each needs a Notion index row to become verifiable.
|
|
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
|
+
// Trunk-only domain: authored on `kl-develop` (80341e0, "promote CVC-17 +
|
|
293
|
+
// CVC-67 to SOT"), which the canonical 0.8.13 line never saw. Its sibling
|
|
294
|
+
// CVC-17 (gender_identity) IS in CVC_INDEX.md and is bound above; 67 is not
|
|
295
|
+
// — CVC_INDEX.md carries no row, Final CVCs/ carries no codebook, and no
|
|
296
|
+
// other domain claims 67, so it is index-absent rather than a squat. Sourced
|
|
297
|
+
// from the HMIS data standard via `CVC_67_HMIS_SEX` in `../constants/ic.ts`.
|
|
298
|
+
hmis_sex: { cvc: 67, 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.
|
|
303
|
+
primary_language: { cvc: 122, reason: "no CVC_INDEX row" },
|
|
304
|
+
hmis_relationship_to_hoh: { cvc: 129, reason: "no CVC_INDEX row" },
|
|
305
|
+
core_functions: { cvc: 133, reason: "no CVC_INDEX row" },
|
|
306
|
+
admin_roles: { cvc: 134, reason: "no CVC_INDEX row" },
|
|
307
|
+
tribes: { cvc: 148, reason: "no CVC_INDEX row" },
|
|
308
|
+
contact_info_use_type: { cvc: 154, reason: "no CVC_INDEX row" },
|
|
309
|
+
preferred_contact_method: { cvc: 185, reason: "no CVC_INDEX row" },
|
|
310
|
+
session_state: { cvc: 216, reason: "no CVC_INDEX row" },
|
|
311
|
+
why_nots: { cvc: 219, reason: "no CVC_INDEX row" },
|
|
312
|
+
exit_reasons: { cvc: 220, reason: "no CVC_INDEX row" },
|
|
313
|
+
mid_stay_event_type: { cvc: 221, reason: "no CVC_INDEX row" },
|
|
314
|
+
pet_exit_reason: { cvc: 222, reason: "no CVC_INDEX row" },
|
|
315
|
+
hmis_project_type: { cvc: 225, reason: "no CVC_INDEX row" },
|
|
316
|
+
funder: { cvc: 226, reason: "no CVC_INDEX row" },
|
|
317
|
+
da_incident_severity: { cvc: 228, 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
|
+
},
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* The ONLY codes CVC-136 may carry that `core_indicators.yaml` does not.
|
|
356
|
+
* @hti/scoring EMITS these two, so dropping them would break the scoring
|
|
357
|
+
* contract — scoring is genuinely AHEAD of the catalog here. They are flagged
|
|
358
|
+
* `pendingUpstreamAdoption: true` in the SOT JSON. Upstream must adopt or
|
|
359
|
+
* deprecate them; until then this list must stay EXACTLY these two.
|
|
360
|
+
*/
|
|
361
|
+
const SCORING_AHEAD_OF_CATALOG: readonly string[] = [
|
|
362
|
+
"coercive_debt_pressure_youth",
|
|
363
|
+
"debt_terms_deceptive_youth",
|
|
364
|
+
];
|
|
365
|
+
|
|
366
|
+
// ─── Helpers ────────────────────────────────────────────────────────────────
|
|
367
|
+
|
|
368
|
+
const CODE_RE = /^\d{3}(-\d{3}){6}$/;
|
|
369
|
+
const KEY_RE = /^[a-z][a-z0-9_]*$/;
|
|
370
|
+
const isMissingness = (e: Entry): boolean => e.code.split("-")[1] === "000";
|
|
371
|
+
const substantiveOf = (d: Domain): Entry[] => d.entries.filter((e) => !isMissingness(e));
|
|
372
|
+
|
|
373
|
+
const cvc136 = DOMAINS.find((d) => d.domain === "core_indicators")!;
|
|
374
|
+
const cvc136Keys = new Set(substantiveOf(cvc136).map((e) => e.key));
|
|
375
|
+
|
|
376
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
377
|
+
// A. SCORING EXPRESSIBILITY
|
|
378
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
379
|
+
describe("GATE A — every code @hti/scoring emits exists in CVC-136", () => {
|
|
380
|
+
it(`all ${scoringEmitsPin.codes.length} emitted codes are expressible`, () => {
|
|
381
|
+
const missing = scoringEmitsPin.codes.filter((c) => !cvc136Keys.has(c));
|
|
382
|
+
if (missing.length > 0) {
|
|
383
|
+
throw new Error(
|
|
384
|
+
`${missing.length} code(s) that @hti/scoring EMITS do not exist in CVC-136.\n` +
|
|
385
|
+
"The risk pipeline would write assertions against codes that resolve to NOTHING.\n" +
|
|
386
|
+
`(This is how the entire perpetrator lane went missing — facilitator scoring\n` +
|
|
387
|
+
" was unexpressible for an entire release.)\n\n" +
|
|
388
|
+
` MISSING: ${missing.join(", ")}\n\n` +
|
|
389
|
+
"TO FIX: add each code to src/cvcs/coreIndicators.v1.0.0.json (sourced from\n" +
|
|
390
|
+
` ${coreIndicatorsPin.sourceRepo}/${coreIndicatorsPin.sourceFile}` +
|
|
391
|
+
` @ ${coreIndicatorsPin.sourceSha}),\n` +
|
|
392
|
+
" then regenerate CVC_136_CORE_INDICATOR_VALUES in src/constants/ic.ts.\n" +
|
|
393
|
+
`PIN: ${scoringEmitsPin.sourceRepo}/${scoringEmitsPin.sourceFile}` +
|
|
394
|
+
` @ ${scoringEmitsPin.sourceSha}`,
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
expect(missing).toEqual([]);
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
402
|
+
// B. NO INVENTION
|
|
403
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
404
|
+
describe("GATE B — CVC-136 invents nothing", () => {
|
|
405
|
+
const catalog = new Set(coreIndicatorsPin.codes);
|
|
406
|
+
const allowed = new Set(SCORING_AHEAD_OF_CATALOG);
|
|
407
|
+
|
|
408
|
+
it("every CVC-136 code is in core_indicators.yaml or the annotated allowlist", () => {
|
|
409
|
+
const invented = [...cvc136Keys].filter((k) => !catalog.has(k) && !allowed.has(k)).sort();
|
|
410
|
+
if (invented.length > 0) {
|
|
411
|
+
throw new Error(
|
|
412
|
+
`${invented.length} INVENTED code(s) in CVC-136 — they exist in neither\n` +
|
|
413
|
+
` ${coreIndicatorsPin.sourceFile} @ ${coreIndicatorsPin.sourceSha} ` +
|
|
414
|
+
`(${coreIndicatorsPin.codes.length} codes)\n` +
|
|
415
|
+
" nor the SCORING_AHEAD_OF_CATALOG allowlist.\n" +
|
|
416
|
+
"(0.8.12 shipped 56 of these — `vc_*`, `csi_*`, `csctx_*`, `dv_*`, `net_*`,\n" +
|
|
417
|
+
" `auto_*` rollup prefixes consumed by nobody. They are not indicators.)\n\n" +
|
|
418
|
+
` INVENTED: ${invented.join(", ")}\n\n` +
|
|
419
|
+
"TO FIX: remove them from src/cvcs/coreIndicators.v1.0.0.json — OR, if\n" +
|
|
420
|
+
" @hti/scoring genuinely emits them ahead of the catalog, add them to\n" +
|
|
421
|
+
" SCORING_AHEAD_OF_CATALOG in this file WITH `pendingUpstreamAdoption: true`\n" +
|
|
422
|
+
" on the entry, and raise adoption with the codebook owner.",
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
expect(invented).toEqual([]);
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it("the scoring-ahead allowlist is EXACTLY the 2 known codes, each flagged", () => {
|
|
429
|
+
// Guard the escape hatch: it must not quietly become a dumping ground.
|
|
430
|
+
expect([...SCORING_AHEAD_OF_CATALOG].sort()).toEqual([
|
|
431
|
+
"coercive_debt_pressure_youth",
|
|
432
|
+
"debt_terms_deceptive_youth",
|
|
433
|
+
]);
|
|
434
|
+
for (const code of SCORING_AHEAD_OF_CATALOG) {
|
|
435
|
+
expect(scoringEmitsPin.codes, `${code} must actually be emitted by scoring`).toContain(code);
|
|
436
|
+
expect(coreIndicatorsPin.codes, `${code} must still be absent upstream`).not.toContain(code);
|
|
437
|
+
const entry = substantiveOf(cvc136).find((e) => e.key === code) as unknown as
|
|
438
|
+
| Record<string, unknown>
|
|
439
|
+
| undefined;
|
|
440
|
+
expect(entry?.["pendingUpstreamAdoption"], `${code} must be flagged`).toBe(true);
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
446
|
+
// C. NUMBER <-> NAME AGREEMENT — the squat catcher
|
|
447
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
448
|
+
describe("GATE C — every CVC number matches CVC_INDEX.md", () => {
|
|
449
|
+
it("every domain is bound, index-absent, or provisional — nothing is unclassified", () => {
|
|
450
|
+
const unclassified = DOMAINS.filter(
|
|
451
|
+
(d) => !isProvisional(d) && !CANONICAL_BINDING[d.domain] && !INDEX_ABSENT[d.domain],
|
|
452
|
+
).map((d) => `${d.file} (${d.domain} @ CVC-${d.cvc})`);
|
|
453
|
+
if (unclassified.length > 0) {
|
|
454
|
+
throw new Error(
|
|
455
|
+
"Domain(s) with a canonical-block number (<900) that this gate has never seen:\n" +
|
|
456
|
+
unclassified.map((s) => ` ${s}`).join("\n") +
|
|
457
|
+
"\n\nTO FIX: add each to CANONICAL_BINDING (with the EXACT CVC_INDEX.md row name)\n" +
|
|
458
|
+
" or to INDEX_ABSENT (with a reason) in this file — or park it at 900+ if it is\n" +
|
|
459
|
+
" a net-new vocabulary Notion has not numbered yet.",
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
expect(unclassified).toEqual([]);
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
it("each bound domain sits on the number CVC_INDEX.md gives its name", () => {
|
|
466
|
+
const bad: string[] = [];
|
|
467
|
+
for (const d of DOMAINS) {
|
|
468
|
+
const bind = CANONICAL_BINDING[d.domain];
|
|
469
|
+
if (!bind) continue;
|
|
470
|
+
if (d.cvc !== bind.cvc) {
|
|
471
|
+
bad.push(
|
|
472
|
+
`${d.file}: ships CVC-${d.cvc} but CANONICAL_BINDING says CVC-${bind.cvc}`,
|
|
473
|
+
);
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
const names = cvcIndexPin.numbers[String(bind.cvc)];
|
|
477
|
+
if (!names?.includes(bind.indexName)) {
|
|
478
|
+
bad.push(
|
|
479
|
+
`${d.file}: CVC_INDEX.md row for CVC-${bind.cvc} is ` +
|
|
480
|
+
`${JSON.stringify(names ?? null)}, not "${bind.indexName}"`,
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (bad.length > 0) {
|
|
485
|
+
throw new Error(
|
|
486
|
+
"CVC number/name disagreement with CVC_INDEX.md:\n" +
|
|
487
|
+
bad.map((s) => ` ${s}`).join("\n") +
|
|
488
|
+
`\n\nPIN: ${cvcIndexPin.sourceRepo}/${cvcIndexPin.sourceFile}` +
|
|
489
|
+
` @ ${cvcIndexPin.sourceSha}`,
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
expect(bad).toEqual([]);
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* THE ONE THAT MATTERS. A domain may not occupy a number that CVC_INDEX.md
|
|
497
|
+
* assigns to a DIFFERENT domain — because a squat does not just mislabel the
|
|
498
|
+
* squatter, it makes the slot look occupied and thereby HIDES the absence of
|
|
499
|
+
* the domain that actually owns the number. `housing_subsidy_types` sat on
|
|
500
|
+
* CVC-233 and that is precisely why nobody noticed `core-DH_state` had never
|
|
501
|
+
* been authored at all.
|
|
502
|
+
*/
|
|
503
|
+
it("NO domain squats on a number CVC_INDEX.md assigns to someone else", () => {
|
|
504
|
+
const squats: string[] = [];
|
|
505
|
+
for (const d of DOMAINS) {
|
|
506
|
+
if (isProvisional(d)) continue;
|
|
507
|
+
const names = cvcIndexPin.numbers[String(d.cvc)];
|
|
508
|
+
if (!names) continue; // index says nothing about this number — no constraint
|
|
509
|
+
const claimed = CANONICAL_BINDING[d.domain]?.indexName;
|
|
510
|
+
if (!claimed || !names.includes(claimed)) {
|
|
511
|
+
squats.push(
|
|
512
|
+
` ${d.file}\n` +
|
|
513
|
+
` domain "${d.domain}" occupies CVC-${d.cvc},\n` +
|
|
514
|
+
` but CVC_INDEX.md assigns CVC-${d.cvc} to ${JSON.stringify(names)}.`,
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
if (squats.length > 0) {
|
|
519
|
+
throw new Error(
|
|
520
|
+
"CVC NUMBER SQUAT.\n\n" +
|
|
521
|
+
squats.join("\n") +
|
|
522
|
+
"\n\nA wrong number does not merely mislabel a domain — it HIDES THE ABSENCE\n" +
|
|
523
|
+
"of the domain that owns that number. Renumber the squatter to its own\n" +
|
|
524
|
+
"canonical number (or park it at 900+), THEN check whether the rightful\n" +
|
|
525
|
+
"owner of this number has ever been authored at all.\n" +
|
|
526
|
+
`\nPIN: ${cvcIndexPin.sourceRepo}/${cvcIndexPin.sourceFile}` +
|
|
527
|
+
` @ ${cvcIndexPin.sourceSha}`,
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
expect(squats).toEqual([]);
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
535
|
+
// D. NO NUMBER COLLISIONS
|
|
536
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
537
|
+
describe("GATE D — no two domains share a CVC number", () => {
|
|
538
|
+
it("segment-1 numbers are unique across all shipped domains", () => {
|
|
539
|
+
const byNum = new Map<number, string[]>();
|
|
540
|
+
for (const d of DOMAINS) {
|
|
541
|
+
byNum.set(d.cvc, [...(byNum.get(d.cvc) ?? []), d.file]);
|
|
542
|
+
}
|
|
543
|
+
const collisions = [...byNum.entries()].filter(([, files]) => files.length > 1);
|
|
544
|
+
if (collisions.length > 0) {
|
|
545
|
+
throw new Error(
|
|
546
|
+
"CVC number collision — two domains claim the same segment-1 number:\n" +
|
|
547
|
+
collisions
|
|
548
|
+
.map(([n, files]) => ` CVC-${n}: ${files.join(", ")}`)
|
|
549
|
+
.join("\n") +
|
|
550
|
+
"\n\nTO FIX: one of them is wrong. Check CVC_INDEX.md for the rightful owner;\n" +
|
|
551
|
+
" park the other at 900+ if it has no canonical number.",
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
expect(collisions).toEqual([]);
|
|
555
|
+
});
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
559
|
+
// E. MISSINGNESS
|
|
560
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
561
|
+
/**
|
|
562
|
+
* NOTE ON SCOPE — this asserts the missingness BLOCK is well-formed and leads
|
|
563
|
+
* the entry list. It deliberately does NOT demand the full quadruplet
|
|
564
|
+
* (missingness_root / unknown / anonymous / data_not_collected) in every domain,
|
|
565
|
+
* because that is NOT TRUE UPSTREAM and forcing it would INVENT codes — the very
|
|
566
|
+
* thing gate B forbids. Verified against the canonical codebooks:
|
|
567
|
+
*
|
|
568
|
+
* share_purpose (CVC-84) ........ 8 rows, ZERO missingness rows
|
|
569
|
+
* military_status (CVC-121) ..... ZERO missingness rows
|
|
570
|
+
* military_branch (CVC-120) ..... ZERO missingness rows
|
|
571
|
+
* person_relationships (CVC-126) DNC + ANON only — deliberately no UNK
|
|
572
|
+
* juvenile_justice_involvement_status (CVC-95)
|
|
573
|
+
* UNK + "Prefer not to answer" + DNC — no ANON
|
|
574
|
+
*
|
|
575
|
+
* Missingness is a per-domain canonical VARIANT, not a universal constant.
|
|
576
|
+
*/
|
|
577
|
+
describe("GATE E — the missingness block is well-formed and leads every domain", () => {
|
|
578
|
+
const CANON_ORDER = ["missingness_root", "unknown", "anonymous", "data_not_collected"];
|
|
579
|
+
|
|
580
|
+
for (const d of DOMAINS) {
|
|
581
|
+
const block = d.entries.filter(isMissingness);
|
|
582
|
+
const firstSubstantiveIdx = d.entries.findIndex((e) => !isMissingness(e));
|
|
583
|
+
|
|
584
|
+
it(`${d.file}: missingness block is contiguous and FIRST`, () => {
|
|
585
|
+
// Every missingness entry must precede every substantive entry.
|
|
586
|
+
const misplaced = d.entries
|
|
587
|
+
.map((e, i) => ({ e, i }))
|
|
588
|
+
.filter(
|
|
589
|
+
({ e, i }) =>
|
|
590
|
+
isMissingness(e) && firstSubstantiveIdx !== -1 && i > firstSubstantiveIdx,
|
|
591
|
+
)
|
|
592
|
+
.map(({ e }) => e.key);
|
|
593
|
+
if (misplaced.length > 0) {
|
|
594
|
+
throw new Error(
|
|
595
|
+
`${d.file}: missingness entries appear AFTER substantive entries: ` +
|
|
596
|
+
`${misplaced.join(", ")}.\n` +
|
|
597
|
+
"TO FIX: move the whole segment-2 == 000 block to the top of `entries`.",
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
expect(misplaced).toEqual([]);
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
it(`${d.file}: canonical missingness members lead the block, in order`, () => {
|
|
604
|
+
const present = block.map((e) => e.key).filter((k) => CANON_ORDER.includes(k));
|
|
605
|
+
const expected = CANON_ORDER.filter((k) => present.includes(k));
|
|
606
|
+
expect(present, `${d.file}: canonical missingness members out of order`).toEqual(expected);
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
if (block.length > 0) {
|
|
610
|
+
it(`${d.file}: missingness_root.childCodes is the exact inverse of parentCode`, () => {
|
|
611
|
+
const root = block.find((e) => e.key === "missingness_root");
|
|
612
|
+
expect(root, `${d.file} has a missingness block but no missingness_root`).toBeDefined();
|
|
613
|
+
const children = block.filter((e) => e.key !== "missingness_root");
|
|
614
|
+
expect(root!.selectable, `${d.file}: missingness_root must not be selectable`).toBe(false);
|
|
615
|
+
expect([...root!.childCodes].sort()).toEqual(children.map((c) => c.code).sort());
|
|
616
|
+
for (const c of children) {
|
|
617
|
+
expect(c.parentCode, `${d.file}: ${c.key}.parentCode`).toBe(root!.code);
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
625
|
+
// F. SELECTABLE-AWARE COUNTING
|
|
626
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
627
|
+
/**
|
|
628
|
+
* An ENTRY count is not a SELECTABLE count. A hierarchical CVC also carries
|
|
629
|
+
* non-selectable GROUP rows and a non-selectable missingness_root. Comparing an
|
|
630
|
+
* entry count against a selectable count produces a phantom bug — that is
|
|
631
|
+
* exactly how "CVC-69 is broken" was concluded, when CVC-69 was fine all along.
|
|
632
|
+
*/
|
|
633
|
+
describe("GATE F — entry counts and selectable counts are never conflated", () => {
|
|
634
|
+
it("every domain decomposes exactly: entries = selectable + non-selectable", () => {
|
|
635
|
+
for (const d of DOMAINS) {
|
|
636
|
+
const sel = d.entries.filter((e) => e.selectable).length;
|
|
637
|
+
const non = d.entries.filter((e) => !e.selectable).length;
|
|
638
|
+
expect(sel + non, `${d.file}`).toBe(d.entries.length);
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
it("CVC-69 regression: 20 entries = 15 selectable + 4 group rows + missingness_root", () => {
|
|
643
|
+
const d = DOMAINS.find((x) => x.domain === "incident_participation_roles")!;
|
|
644
|
+
const selectable = d.entries.filter((e) => e.selectable);
|
|
645
|
+
const groupRows = d.entries.filter((e) => !e.selectable && !isMissingness(e));
|
|
646
|
+
const missRoot = d.entries.filter((e) => !e.selectable && isMissingness(e));
|
|
647
|
+
|
|
648
|
+
expect(d.entries.length, "total entries").toBe(20);
|
|
649
|
+
expect(selectable.length, "selectable").toBe(15);
|
|
650
|
+
expect(groupRows.length, "non-selectable group rows").toBe(4);
|
|
651
|
+
expect(missRoot.length, "non-selectable missingness_root").toBe(1);
|
|
652
|
+
expect(selectable.length + groupRows.length + missRoot.length).toBe(20);
|
|
653
|
+
// If a consumer's boot-check ever asserts `entries.length === 14`, it is the
|
|
654
|
+
// CONSUMER that is wrong, not CVC-69.
|
|
655
|
+
});
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
659
|
+
// G. CODE / KEY FORMAT
|
|
660
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
661
|
+
describe("GATE G — code and key format", () => {
|
|
662
|
+
for (const d of DOMAINS) {
|
|
663
|
+
it(`${d.file}: codes match ${String(CODE_RE)}, segment 1 == CVC-${d.cvc}, keys are slugs`, () => {
|
|
664
|
+
const errs: string[] = [];
|
|
665
|
+
const seen = new Set<string>();
|
|
666
|
+
for (const e of d.entries) {
|
|
667
|
+
if (!CODE_RE.test(e.code)) errs.push(`bad code format: "${e.code}" (${e.key})`);
|
|
668
|
+
const seg1 = Number(e.code.split("-")[0]);
|
|
669
|
+
if (seg1 !== d.cvc) {
|
|
670
|
+
errs.push(
|
|
671
|
+
`"${e.code}" (${e.key}) has segment 1 = ${seg1}, but the domain is CVC-${d.cvc}`,
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
if (!KEY_RE.test(e.key)) errs.push(`bad key: "${e.key}" must match ${String(KEY_RE)}`);
|
|
675
|
+
if (seen.has(e.key)) errs.push(`duplicate key: "${e.key}"`);
|
|
676
|
+
seen.add(e.key);
|
|
677
|
+
if (seen.has(e.code)) errs.push(`duplicate code: "${e.code}"`);
|
|
678
|
+
}
|
|
679
|
+
if (errs.length > 0) {
|
|
680
|
+
throw new Error(`${d.file}:\n${errs.map((s) => ` ${s}`).join("\n")}`);
|
|
681
|
+
}
|
|
682
|
+
expect(errs).toEqual([]);
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
});
|
|
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
|
+
|
|
948
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
949
|
+
// Pin provenance — the pins must say where they came from.
|
|
950
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
951
|
+
describe("SOT pins carry their provenance", () => {
|
|
952
|
+
it("each pin names its repo, file and SHA", () => {
|
|
953
|
+
for (const [name, pin] of [
|
|
954
|
+
["cvcIndex", cvcIndexPin],
|
|
955
|
+
["coreIndicators", coreIndicatorsPin],
|
|
956
|
+
["scoringEmits", scoringEmitsPin],
|
|
957
|
+
] as const) {
|
|
958
|
+
expect(pin.sourceRepo, `${name}.sourceRepo`).toMatch(/^htilabstech\//);
|
|
959
|
+
expect(pin.sourceFile, `${name}.sourceFile`).toBeTruthy();
|
|
960
|
+
expect(pin.sourceSha, `${name}.sourceSha`).toMatch(/^[0-9a-f]{7,40}$/);
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
|
|
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");
|
|
1031
|
+
expect(scoringEmitsPin.sourceSha).toBe("9b5d654");
|
|
1032
|
+
expect(Object.keys(cvcIndexPin.numbers).length, "cvcIndexPin.numbers rows").toBe(86);
|
|
1033
|
+
expect(coreIndicatorsPin.codes.length).toBe(214);
|
|
1034
|
+
expect(scoringEmitsPin.codes.length).toBe(169);
|
|
1035
|
+
});
|
|
1036
|
+
});
|