@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,328 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CVC-136 <-> @hti/scoring invariant test (0.8.13)
|
|
3
|
+
*
|
|
4
|
+
* THE INVARIANT
|
|
5
|
+
* -------------
|
|
6
|
+
* Every indicator code that @hti/scoring EMITS must exist in the CVC-136
|
|
7
|
+
* `core_indicators` vocabulary. @hti/scoring is the declared scoring SOT
|
|
8
|
+
* (ADR-CONTRACT-scoring-vocab-model-boundary). If platform-common drops or
|
|
9
|
+
* renames a code that scoring emits, the risk pipeline silently writes
|
|
10
|
+
* assertions against an indicator code that resolves to nothing.
|
|
11
|
+
*
|
|
12
|
+
* That is exactly the class of drift 0.8.13 repaired: 0.8.12 shipped 199
|
|
13
|
+
* hand-coded CVC-136 codes, of which 54 were invented rollup prefixes
|
|
14
|
+
* (`vc_*`, `csi_*`, `csctx_*`, `dv_*`, `net_*`, `auto_*`) that existed nowhere
|
|
15
|
+
* upstream and were consumed by nobody, while 66 real canonical codes were
|
|
16
|
+
* MISSING. This test makes that impossible to reintroduce.
|
|
17
|
+
*
|
|
18
|
+
* THE PIN
|
|
19
|
+
* -------
|
|
20
|
+
* `SCORING_EMITS_BY_CODE` is the key set of `emits_by_code` in
|
|
21
|
+
* `weights/risk.weights.json` at htilabstech/hti-scoring@9b5d654 (169 codes).
|
|
22
|
+
* It is a COMMITTED PIN, not a live read - platform-common must not take a
|
|
23
|
+
* build-time dependency on the scoring repo. When @hti/scoring starts emitting
|
|
24
|
+
* a new code, bumping this list is a deliberate, reviewable commit that forces
|
|
25
|
+
* the matching CVC-136 entry to be authored in the same PR.
|
|
26
|
+
*
|
|
27
|
+
* SCORING IS AHEAD OF THE CODEBOOK ON 2 CODES
|
|
28
|
+
* -------------------------------------------
|
|
29
|
+
* `coercive_debt_pressure_youth` and `debt_terms_deceptive_youth` are emitted
|
|
30
|
+
* by @hti/scoring but are NOT in the prototype's canonical
|
|
31
|
+
* `data/core_indicators.yaml` (208 codes) at HEAD a596eb9. They are KEPT
|
|
32
|
+
* (210 = 208 + 2) and flagged `pendingUpstreamAdoption: true` in the SOT JSON.
|
|
33
|
+
* Dropping them because they are "not in the prototype" would break the
|
|
34
|
+
* scoring contract. That is the trap this test exists to prevent.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
import { readFileSync } from "node:fs";
|
|
38
|
+
import path from "node:path";
|
|
39
|
+
import { fileURLToPath } from "node:url";
|
|
40
|
+
|
|
41
|
+
import { describe, it, expect } from "vitest";
|
|
42
|
+
|
|
43
|
+
import { CVC_136_CORE_INDICATOR_VALUES } from "../constants/ic.js";
|
|
44
|
+
import { CvcEnvelopeSchema } from "../validation/cvc.js";
|
|
45
|
+
|
|
46
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
47
|
+
const __dirname = path.dirname(__filename);
|
|
48
|
+
const SOT_FILE = path.resolve(
|
|
49
|
+
__dirname,
|
|
50
|
+
"..",
|
|
51
|
+
"cvcs",
|
|
52
|
+
"coreIndicators.v1.0.0.json",
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* `Object.keys(RISK_WEIGHTS.emits_by_code)` at
|
|
57
|
+
* htilabstech/hti-scoring@9b5d654 (weights/risk.weights.json). 169 codes.
|
|
58
|
+
* PINNED - see the module header before editing.
|
|
59
|
+
*/
|
|
60
|
+
const SCORING_EMITS_BY_CODE: readonly string[] = [
|
|
61
|
+
"abuser_evading_legal_consequences",
|
|
62
|
+
"abuser_has_weapon",
|
|
63
|
+
"abuser_substance_use",
|
|
64
|
+
"abuser_threatened_suicide",
|
|
65
|
+
"abuser_unemployed",
|
|
66
|
+
"access_to_vulnerable_individuals",
|
|
67
|
+
"acknowledgement_or_report_of_human_trafficking",
|
|
68
|
+
"adverse_childhood_household_challenges",
|
|
69
|
+
"appears_controlling_relationship",
|
|
70
|
+
"association_commercial_sex",
|
|
71
|
+
"atypical_or_high_risk_payment_method",
|
|
72
|
+
"autonomy_choice_in_clients",
|
|
73
|
+
"autonomy_choice_in_services",
|
|
74
|
+
"autonomy_controls_own_finances",
|
|
75
|
+
"autonomy_organizes_own_travel",
|
|
76
|
+
"autonomy_posts_own_ads",
|
|
77
|
+
"autonomy_sets_own_schedule",
|
|
78
|
+
"autonomy_sets_up_own_dates",
|
|
79
|
+
"battered_while_pregnant_history",
|
|
80
|
+
"branding_or_unusual_tattoos_tied_to_control",
|
|
81
|
+
"cannot_stop_working_or_freely_leave",
|
|
82
|
+
"child_not_abusers_in_household",
|
|
83
|
+
"coerced_to_misrepresent_identity_or_activity",
|
|
84
|
+
"coercive_debt_pressure",
|
|
85
|
+
"coercive_debt_pressure_youth",
|
|
86
|
+
"coercive_migration_or_forced_travel",
|
|
87
|
+
"cognitive_or_functional_impairment_affecting_consent",
|
|
88
|
+
"commercial_sex_association_words_or_places",
|
|
89
|
+
"concerning_mannerisms_anxious_fearful_depressed",
|
|
90
|
+
"concerning_sexual_behavior_pattern",
|
|
91
|
+
"control_quota_required",
|
|
92
|
+
"cs_activity_criminal_org_connection",
|
|
93
|
+
"cs_industry_related_criminal_history",
|
|
94
|
+
"current_injuries_from_abuser",
|
|
95
|
+
"currently_minor_in_commercial_sex",
|
|
96
|
+
"debt_terms_deceptive",
|
|
97
|
+
"debt_terms_deceptive_youth",
|
|
98
|
+
"denied_basic_needs",
|
|
99
|
+
"depends_on_employer_for_immigration_status",
|
|
100
|
+
"does_not_control_finances_or_earnings",
|
|
101
|
+
"does_not_control_identity_documents",
|
|
102
|
+
"employer_keeps_pay_or_pays_less_than_expected",
|
|
103
|
+
"engages_in_commercial_sex_act",
|
|
104
|
+
"entered_commercial_sex_industry_as_minor",
|
|
105
|
+
"entered_cs_due_to_survival_needs",
|
|
106
|
+
"entered_into_network_of_sex_providers_early",
|
|
107
|
+
"exploitative_working_conditions",
|
|
108
|
+
"fled_conflict_violence_or_persecution",
|
|
109
|
+
"forced_to_commit_crimes",
|
|
110
|
+
"forced_to_use_false_documents",
|
|
111
|
+
"foreign_born_or_recently_arrived",
|
|
112
|
+
"foreign_born_risk_factors",
|
|
113
|
+
"frequent_changes_in_residence",
|
|
114
|
+
"frequent_travel_or_location_changes",
|
|
115
|
+
"frequently_at_hotels_or_many_hotel_keys",
|
|
116
|
+
"has_ads_on_commercial_sex_site",
|
|
117
|
+
"has_facilitators_involved",
|
|
118
|
+
"has_management_or_representation",
|
|
119
|
+
"has_no_personal_items_or_possessions",
|
|
120
|
+
"head_injury_history",
|
|
121
|
+
"head_injury_loss_of_consciousness",
|
|
122
|
+
"health_related_vulnerability",
|
|
123
|
+
"hierarchical_management_structure_identified",
|
|
124
|
+
"high_risk_sexual_behavior",
|
|
125
|
+
"high_security_measures_at_work_or_living_location",
|
|
126
|
+
"highly_irregular_school_attendance",
|
|
127
|
+
"history_emotional_abuse",
|
|
128
|
+
"history_of_mental_health_issues",
|
|
129
|
+
"history_of_running_away_or_missing_from_care",
|
|
130
|
+
"history_of_strangulation",
|
|
131
|
+
"history_physical_or_sexual_abuse_or_dv",
|
|
132
|
+
"homeless_or_unstably_housed",
|
|
133
|
+
"immigration_related_exploitation_risk",
|
|
134
|
+
"in_commercial_sex_industry_recorded",
|
|
135
|
+
"inability_to_account_for_self",
|
|
136
|
+
"intimate_partner_violence_reported_to_law_enforcement",
|
|
137
|
+
"juvenile_justice_or_child_welfare_involvement",
|
|
138
|
+
"labor_services_activity_recorded",
|
|
139
|
+
"limited_english_proficiency",
|
|
140
|
+
"limited_independence",
|
|
141
|
+
"lives_or_sleeps_at_place_of_work",
|
|
142
|
+
"living_with_abuser",
|
|
143
|
+
"meets_or_has_sex_with_internet_contacts",
|
|
144
|
+
"monitored_or_isolated_by_controlling_party",
|
|
145
|
+
"much_older_intimate_partner",
|
|
146
|
+
"nervous_about_immigration_documentation",
|
|
147
|
+
"network_multiple_sex_providers_named",
|
|
148
|
+
"new_to_commercial_sex_industry",
|
|
149
|
+
"non_consensual_photography_or_recording",
|
|
150
|
+
"not_in_control_of_immigration_documentation",
|
|
151
|
+
"other_instability_or_vulnerability_factors",
|
|
152
|
+
"owes_money_and_cannot_pay_off",
|
|
153
|
+
"paid_or_owes_fee_to_arrange_travel_to_us",
|
|
154
|
+
"paid_or_owes_recruitment_fee_to_employer",
|
|
155
|
+
"payment_routed_through_third_party",
|
|
156
|
+
"pending_federal_protection",
|
|
157
|
+
"performing_different_work_than_promised",
|
|
158
|
+
"physical_violence_increasing",
|
|
159
|
+
"poverty_or_severe_financial_strain",
|
|
160
|
+
"precarious_immigration_status",
|
|
161
|
+
"pressured_or_forced_sex_act",
|
|
162
|
+
"prior_medical_attention_from_abuse",
|
|
163
|
+
"prior_tvap_disconnection",
|
|
164
|
+
"prior_victimization_or_abuse_history",
|
|
165
|
+
"promise_of_work_different_than_current_work",
|
|
166
|
+
"received_things_of_value_while_missing_from_care",
|
|
167
|
+
"recruited_by_third_party_into_cs_industry",
|
|
168
|
+
"relies_on_temporary_resources_for_basic_needs",
|
|
169
|
+
"reports_physical_harm_by_employer_or_partner",
|
|
170
|
+
"reports_physical_harm_to_others_by_employer_or_partner",
|
|
171
|
+
"restrictive_living_or_working_conditions",
|
|
172
|
+
"restrictive_or_not_understood_contract",
|
|
173
|
+
"risk_factors_commercial_sex",
|
|
174
|
+
"serious_substance_use_or_introduced_to_drugs",
|
|
175
|
+
"several_cell_phones_or_frequent_number_changes",
|
|
176
|
+
"sex_acts_in_own_residence",
|
|
177
|
+
"sexual_exploitation",
|
|
178
|
+
"signs_of_physical_abuse_confinement_or_neglect",
|
|
179
|
+
"signs_of_physical_harm_or_abuse",
|
|
180
|
+
"social_isolation_or_no_supportive_relationships",
|
|
181
|
+
"stalking_property_intrusion",
|
|
182
|
+
"stalking_surveillance",
|
|
183
|
+
"stalking_unwanted_contact",
|
|
184
|
+
"strangulation_acute_symptoms",
|
|
185
|
+
"strangulation_loss_of_consciousness",
|
|
186
|
+
"strangulation_repeated",
|
|
187
|
+
"subject_arrested_dv_sv_cs",
|
|
188
|
+
"subject_has_illegal_weapons",
|
|
189
|
+
"subject_is_sex_offender",
|
|
190
|
+
"subject_legally_barred_weapons",
|
|
191
|
+
"subject_perpetrated_abuse_history",
|
|
192
|
+
"subject_perpetrated_emotional_stalking_current",
|
|
193
|
+
"subject_perpetrated_emotional_stalking_past",
|
|
194
|
+
"subject_perpetrated_ipv_current",
|
|
195
|
+
"subject_perpetrated_ipv_past",
|
|
196
|
+
"subject_perpetrated_physical_abuse_current",
|
|
197
|
+
"subject_perpetrated_physical_abuse_past",
|
|
198
|
+
"subject_perpetrated_sexual_abuse_current",
|
|
199
|
+
"subject_perpetrated_sexual_abuse_past",
|
|
200
|
+
"subject_violent_felony",
|
|
201
|
+
"substance_use_while_working",
|
|
202
|
+
"suicidal_ideation_history",
|
|
203
|
+
"suicidal_ideation_recent",
|
|
204
|
+
"third_party_arranged_commercial_sex_acts",
|
|
205
|
+
"threats_by_employer_or_partner",
|
|
206
|
+
"threats_of_harm",
|
|
207
|
+
"threats_of_legal_trouble_or_deportation",
|
|
208
|
+
"threats_related_to_migration_debt",
|
|
209
|
+
"threats_to_family_friends_or_close_associates",
|
|
210
|
+
"threats_to_kill_victim_or_children",
|
|
211
|
+
"trafficking_experience_past_10plusy",
|
|
212
|
+
"trafficking_experience_past_3to10y",
|
|
213
|
+
"trafficking_experience_past_lt3y",
|
|
214
|
+
"travel_organized_by_third_party",
|
|
215
|
+
"tricked_or_pressured_into_unwanted_acts",
|
|
216
|
+
"unexplained_frequent_travel_or_migration",
|
|
217
|
+
"unsafe_working_conditions_long_hours_inadequate_breaks",
|
|
218
|
+
"unusual_cash_or_unexplained_gifts",
|
|
219
|
+
"unusual_work_circumstances",
|
|
220
|
+
"urgent_medical_referral_needed",
|
|
221
|
+
"victim_believes_abuser_capable_of_killing",
|
|
222
|
+
"victimization_history_composite",
|
|
223
|
+
"violence_or_threats_at_work_site",
|
|
224
|
+
"weapon_used_or_threatened_against_victim",
|
|
225
|
+
"work_frequency_high_volume",
|
|
226
|
+
"workplace_emotional_climate_of_fear",
|
|
227
|
+
"works_across_multiple_cities_or_locations",
|
|
228
|
+
"works_for_little_or_no_pay",
|
|
229
|
+
"youth_watched_filmed_or_photographed_sexually_explicit",
|
|
230
|
+
];
|
|
231
|
+
|
|
232
|
+
/** Codes @hti/scoring emits that upstream `core_indicators.yaml` has not yet adopted. */
|
|
233
|
+
const PENDING_UPSTREAM_ADOPTION: readonly string[] = [
|
|
234
|
+
"coercive_debt_pressure_youth",
|
|
235
|
+
"debt_terms_deceptive_youth",
|
|
236
|
+
];
|
|
237
|
+
|
|
238
|
+
const envelope = CvcEnvelopeSchema.parse(
|
|
239
|
+
JSON.parse(readFileSync(SOT_FILE, "utf-8")),
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
/** Substantive (non-missingness) entries: segment 2 of the code is non-zero. */
|
|
243
|
+
const substantive = envelope.entries.filter(
|
|
244
|
+
(e) => e.code.split("-")[1] !== "000",
|
|
245
|
+
);
|
|
246
|
+
const substantiveKeys = new Set(substantive.map((e) => e.key));
|
|
247
|
+
|
|
248
|
+
describe("CVC-136 core_indicators", () => {
|
|
249
|
+
it("is numbered 136 in segment 1 of every code", () => {
|
|
250
|
+
for (const entry of envelope.entries) {
|
|
251
|
+
expect(entry.code.split("-")[0]).toBe("136");
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("opens with the mandatory missingness quadruplet", () => {
|
|
256
|
+
expect(envelope.entries.slice(0, 4).map((e) => e.key)).toEqual([
|
|
257
|
+
"missingness_root",
|
|
258
|
+
"unknown",
|
|
259
|
+
"anonymous",
|
|
260
|
+
"data_not_collected",
|
|
261
|
+
]);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("has exactly 216 substantive codes (214 canonical + 2 scoring-ahead)", () => {
|
|
265
|
+
// 0.8.14 refreshed the catalog pin a596eb9 (208) -> 84a1b67 (213):
|
|
266
|
+
// +5 upstream mints, 0 withdrawn.
|
|
267
|
+
// This refresh took it again 84a1b67 (213) -> 622410b (214): +1 upstream
|
|
268
|
+
// mint (`active_protective_order`, minted 2026-08-08), 0 withdrawn. The 2
|
|
269
|
+
// scoring-ahead codes are unchanged and still absent upstream.
|
|
270
|
+
expect(substantive.length).toBe(216);
|
|
271
|
+
expect(envelope.entries.length).toBe(220);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("has no duplicate keys", () => {
|
|
275
|
+
expect(substantiveKeys.size).toBe(substantive.length);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
describe("CVC-136 <-> @hti/scoring emits_by_code invariant", () => {
|
|
280
|
+
it("pins exactly 169 emitted codes", () => {
|
|
281
|
+
expect(new Set(SCORING_EMITS_BY_CODE).size).toBe(169);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("EVERY code @hti/scoring emits exists in CVC-136", () => {
|
|
285
|
+
const missing = SCORING_EMITS_BY_CODE.filter(
|
|
286
|
+
(code) => !substantiveKeys.has(code),
|
|
287
|
+
);
|
|
288
|
+
if (missing.length > 0) {
|
|
289
|
+
throw new Error(
|
|
290
|
+
"CVC-136 is missing indicator codes that @hti/scoring EMITS. The risk " +
|
|
291
|
+
"pipeline would write assertions against codes that resolve to nothing.\n" +
|
|
292
|
+
`Missing (${missing.length}): ${missing.join(", ")}`,
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
expect(missing).toHaveLength(0);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it("the 2 scoring-ahead codes are present and flagged pendingUpstreamAdoption", () => {
|
|
299
|
+
for (const code of PENDING_UPSTREAM_ADOPTION) {
|
|
300
|
+
const entry = substantive.find((e) => e.key === code);
|
|
301
|
+
expect(entry, `${code} must be present in CVC-136`).toBeDefined();
|
|
302
|
+
expect(
|
|
303
|
+
(entry as unknown as Record<string, unknown>)["pendingUpstreamAdoption"],
|
|
304
|
+
).toBe(true);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("none of the 54 withdrawn invented rollup codes came back", () => {
|
|
309
|
+
const inventedPrefixes = ["vc_", "csi_", "csctx_", "dv_", "net_", "auto_"];
|
|
310
|
+
const resurrected = [...substantiveKeys].filter((key) =>
|
|
311
|
+
inventedPrefixes.some((p) => key.startsWith(p)),
|
|
312
|
+
);
|
|
313
|
+
expect(resurrected).toEqual([]);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it("`unusual_work_circumstances_general` stays withdrawn; the canonical code ships", () => {
|
|
317
|
+
expect(substantiveKeys.has("unusual_work_circumstances_general")).toBe(false);
|
|
318
|
+
expect(substantiveKeys.has("unusual_work_circumstances")).toBe(true);
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
describe("CVC-136 SOT JSON <-> hand-coded ic.ts array", () => {
|
|
323
|
+
it("CVC_136_CORE_INDICATOR_VALUES is exactly the SOT substantive key set", () => {
|
|
324
|
+
expect([...CVC_136_CORE_INDICATOR_VALUES].sort()).toEqual(
|
|
325
|
+
[...substantiveKeys].sort(),
|
|
326
|
+
);
|
|
327
|
+
});
|
|
328
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CVC-181 `countries` <-> CVC-182 `citizenship` — the country-set parity lock
|
|
3
|
+
* ==========================================================================
|
|
4
|
+
*
|
|
5
|
+
* Two canonical codebooks enumerate the SAME 249 ISO 3166-1 countries:
|
|
6
|
+
*
|
|
7
|
+
* `core - countries` (CVC-181) the neutral entity list. Its own `.md` says it is
|
|
8
|
+
* "designed for use across multiple contexts (e.g.
|
|
9
|
+
* country of citizenship, country of origin, or
|
|
10
|
+
* country of residence)".
|
|
11
|
+
* `core - citizenship` (CVC-182) the citizenship-flavoured list, authored first
|
|
12
|
+
* (0.8.13) because CVC-181 was unpublished.
|
|
13
|
+
*
|
|
14
|
+
* Consumers bound to CVC-182 as a DRAFT stand-in for birth country must be able to
|
|
15
|
+
* re-point at CVC-181 as an import swap with **zero key renames** — that is the whole
|
|
16
|
+
* reason CVC-181 was minted from a key derivation identical to CVC-182's rather than a
|
|
17
|
+
* fresh one. This test is that promise, made falsifiable. If it fails, the re-point is
|
|
18
|
+
* a data migration, not an import swap, and every stored birth-country key is suspect.
|
|
19
|
+
*
|
|
20
|
+
* What it does NOT assert: positional-code parity. `181-NNN` and `182-NNN` disagree on
|
|
21
|
+
* 20 countries because the two upstream exports sort under different collations, and
|
|
22
|
+
* each domain is deliberately minted in ITS OWN codebook's row order so each stays
|
|
23
|
+
* reproducible from its own source. The KEY is the reconciliation axis (consumers
|
|
24
|
+
* persist keys, not wire codes). The last assertion below pins that divergence in place
|
|
25
|
+
* so nobody "fixes" it into a silent renumber, and so nobody writes
|
|
26
|
+
* `"181-" + code.slice(4)` believing the two are interchangeable.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { readFileSync } from "node:fs";
|
|
30
|
+
import path from "node:path";
|
|
31
|
+
import { fileURLToPath } from "node:url";
|
|
32
|
+
|
|
33
|
+
import { describe, it, expect } from "vitest";
|
|
34
|
+
|
|
35
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
36
|
+
const cvcDir = path.join(here, "..", "cvcs");
|
|
37
|
+
|
|
38
|
+
interface Entry {
|
|
39
|
+
code: string;
|
|
40
|
+
key: string;
|
|
41
|
+
title: string;
|
|
42
|
+
selectable: boolean;
|
|
43
|
+
definition: string | null;
|
|
44
|
+
iso31661Alpha2?: string | null;
|
|
45
|
+
priority?: boolean;
|
|
46
|
+
canonicalLabel?: string | null;
|
|
47
|
+
localExtension?: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const read = (f: string): { domain: string; entries: Entry[] } =>
|
|
51
|
+
JSON.parse(readFileSync(path.join(cvcDir, f), "utf8")) as {
|
|
52
|
+
domain: string;
|
|
53
|
+
entries: Entry[];
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const countries = read("countries.v1.0.0.json");
|
|
57
|
+
const citizenship = read("citizenship.v1.0.0.json");
|
|
58
|
+
|
|
59
|
+
const isMissingness = (e: Entry): boolean => e.code.split("-")[1] === "000";
|
|
60
|
+
const substantive = (d: { entries: Entry[] }): Entry[] =>
|
|
61
|
+
d.entries.filter((e) => !isMissingness(e));
|
|
62
|
+
|
|
63
|
+
/** The 10 PRIORITY_COUNTRIES of the canonical prototype HTML, by ISO alpha-2. */
|
|
64
|
+
const PRIORITY_ISO = ["CN", "CU", "DO", "GT", "IN", "KR", "MX", "PH", "SV", "VN"];
|
|
65
|
+
|
|
66
|
+
describe("CVC-181 / CVC-182 country parity", () => {
|
|
67
|
+
it("both domains carry the identical 249 country key -> ISO map", () => {
|
|
68
|
+
const map = (d: { entries: Entry[] }): Record<string, string> =>
|
|
69
|
+
Object.fromEntries(
|
|
70
|
+
d.entries
|
|
71
|
+
.filter((e) => e.iso31661Alpha2)
|
|
72
|
+
.map((e) => [e.key, e.iso31661Alpha2!]),
|
|
73
|
+
);
|
|
74
|
+
const a = map(countries);
|
|
75
|
+
const b = map(citizenship);
|
|
76
|
+
expect(Object.keys(a).length, "CVC-181 ISO-coded leaves").toBe(249);
|
|
77
|
+
expect(Object.keys(b).length, "CVC-182 ISO-coded leaves").toBe(249);
|
|
78
|
+
expect(a).toEqual(b);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("CVC-181 adds EXACTLY ONE substantive leaf over CVC-182: non_us_unspecified", () => {
|
|
82
|
+
const a = new Set(substantive(countries).map((e) => e.key));
|
|
83
|
+
const b = new Set(substantive(citizenship).map((e) => e.key));
|
|
84
|
+
const added = [...a].filter((k) => !b.has(k)).sort();
|
|
85
|
+
const dropped = [...b].filter((k) => !a.has(k)).sort();
|
|
86
|
+
expect(added, "substantive keys CVC-181 has that CVC-182 does not").toEqual([
|
|
87
|
+
"non_us_unspecified",
|
|
88
|
+
]);
|
|
89
|
+
expect(dropped, "substantive keys CVC-182 has that CVC-181 does not").toEqual([]);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("non_us_unspecified is a FLAGGED local extension, not a smuggled canonical value", () => {
|
|
93
|
+
// The escape hatch is guarded the way GATE B guards SCORING_AHEAD_OF_CATALOG:
|
|
94
|
+
// a codebook-absent leaf must announce itself, or the next verification run
|
|
95
|
+
// cannot tell an upstream gap from a platform-common invention.
|
|
96
|
+
const e = countries.entries.find((x) => x.key === "non_us_unspecified");
|
|
97
|
+
expect(e, "non_us_unspecified must exist").toBeDefined();
|
|
98
|
+
expect(e!.localExtension, "must carry localExtension: true").toBe(true);
|
|
99
|
+
expect(e!.definition ?? "").toMatch(/^LOCAL EXTENSION \(not in canonical CVC-181\)\./);
|
|
100
|
+
expect(e!.selectable).toBe(true);
|
|
101
|
+
expect(e!.iso31661Alpha2 ?? null, "a non-country leaf carries no ISO code").toBeNull();
|
|
102
|
+
// It is the ONLY local extension in this domain.
|
|
103
|
+
expect(countries.entries.filter((x) => x.localExtension).map((x) => x.key)).toEqual([
|
|
104
|
+
"non_us_unspecified",
|
|
105
|
+
]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("CVC-181 priority flags are EXACTLY the canonical PRIORITY_COUNTRIES, and no sentinel", () => {
|
|
109
|
+
const flagged = countries.entries.filter((e) => e.priority);
|
|
110
|
+
expect(flagged.map((e) => e.iso31661Alpha2).sort()).toEqual([...PRIORITY_ISO].sort());
|
|
111
|
+
// CVC-182 additionally flags `unknown` + `anonymous` because ITS codebook has a
|
|
112
|
+
// Priority column that says Yes on those rows. CVC-181's codebook has no Priority
|
|
113
|
+
// column at all, and PRIORITY_COUNTRIES contains countries only — so flagging a
|
|
114
|
+
// sentinel here would be an invention. The COUNTRY flags must still agree.
|
|
115
|
+
expect(flagged.every((e) => !isMissingness(e)), "no missingness sentinel is priority").toBe(
|
|
116
|
+
true,
|
|
117
|
+
);
|
|
118
|
+
const flaggedCountryKeys = (d: { entries: Entry[] }): string[] =>
|
|
119
|
+
d.entries
|
|
120
|
+
.filter((e) => e.priority && e.iso31661Alpha2)
|
|
121
|
+
.map((e) => e.key)
|
|
122
|
+
.sort();
|
|
123
|
+
expect(flaggedCountryKeys(countries)).toEqual(flaggedCountryKeys(citizenship));
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("positional ordinals deliberately DIVERGE on 20 countries — reconcile by key, not by code", () => {
|
|
127
|
+
const ordinals = (d: { entries: Entry[] }): Map<string, string> =>
|
|
128
|
+
new Map(
|
|
129
|
+
d.entries.filter((e) => e.iso31661Alpha2).map((e) => [e.key, e.code.split("-")[1]!]),
|
|
130
|
+
);
|
|
131
|
+
const a = ordinals(countries);
|
|
132
|
+
const b = ordinals(citizenship);
|
|
133
|
+
const divergent = [...a.keys()].filter((k) => a.get(k) !== b.get(k)).sort();
|
|
134
|
+
expect(
|
|
135
|
+
divergent.length,
|
|
136
|
+
"if this changes, one of the two domains was renumbered — that is a wire-format " +
|
|
137
|
+
"change and needs its own decision, not a silent regeneration",
|
|
138
|
+
).toBe(20);
|
|
139
|
+
// All 20 are adjacent-pair swaps between the two upstream sort collations.
|
|
140
|
+
expect(divergent).toEqual([
|
|
141
|
+
"germany",
|
|
142
|
+
"ghana",
|
|
143
|
+
"isle_of_man",
|
|
144
|
+
"israel",
|
|
145
|
+
"japan",
|
|
146
|
+
"jersey",
|
|
147
|
+
"lao_people_s_democratic_republic",
|
|
148
|
+
"latvia",
|
|
149
|
+
"rwanda",
|
|
150
|
+
"saint_barthelemy",
|
|
151
|
+
"seychelles",
|
|
152
|
+
"sierra_leone",
|
|
153
|
+
"south_sudan",
|
|
154
|
+
"spain",
|
|
155
|
+
"sweden",
|
|
156
|
+
"switzerland",
|
|
157
|
+
"tanzania_united_republic_of",
|
|
158
|
+
"thailand",
|
|
159
|
+
"tuvalu",
|
|
160
|
+
"uganda",
|
|
161
|
+
]);
|
|
162
|
+
});
|
|
163
|
+
});
|