@htilabs/platform-common-models 0.19.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/cvcs/index.cjs +4867 -639
  2. package/dist/cvcs/index.cjs.map +1 -1
  3. package/dist/cvcs/index.d.cts +5145 -609
  4. package/dist/cvcs/index.d.ts +5145 -609
  5. package/dist/cvcs/index.js +4867 -639
  6. package/dist/cvcs/index.js.map +1 -1
  7. package/dist/enums/index.cjs +74 -1
  8. package/dist/enums/index.cjs.map +1 -1
  9. package/dist/enums/index.d.cts +77 -4
  10. package/dist/enums/index.d.ts +77 -4
  11. package/dist/enums/index.js +74 -1
  12. package/dist/enums/index.js.map +1 -1
  13. package/dist/{index-I-DiX9eQ.d.ts → index-CDoqrfc1.d.ts} +1 -1
  14. package/dist/{index-CoVr1jIV.d.cts → index-Zu_mOJRn.d.cts} +1 -1
  15. package/dist/index.cjs +5382 -588
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +3 -2
  18. package/dist/index.d.ts +3 -2
  19. package/dist/index.js +5371 -588
  20. package/dist/index.js.map +1 -1
  21. package/dist/information-scope/index.cjs +521 -0
  22. package/dist/information-scope/index.cjs.map +1 -0
  23. package/dist/information-scope/index.d.cts +442 -0
  24. package/dist/information-scope/index.d.ts +442 -0
  25. package/dist/information-scope/index.js +484 -0
  26. package/dist/information-scope/index.js.map +1 -0
  27. package/dist/models/index.d.cts +2 -2
  28. package/dist/models/index.d.ts +2 -2
  29. package/dist/schemas/index.d.cts +25 -25
  30. package/dist/schemas/index.d.ts +25 -25
  31. package/dist/services/index.cjs +495 -2
  32. package/dist/services/index.cjs.map +1 -1
  33. package/dist/services/index.d.cts +1 -0
  34. package/dist/services/index.d.ts +1 -0
  35. package/dist/services/index.js +483 -1
  36. package/dist/services/index.js.map +1 -1
  37. package/package.json +32 -26
  38. package/src/__tests__/__snapshots__/cvc-sot.snap +3 -3
  39. package/src/__tests__/core-information-scope-invariant.test.ts +835 -456
  40. package/src/__tests__/cvc-sot-snapshot.test.ts +17 -17
  41. package/src/__tests__/cvc-structural.test.ts +2 -2
  42. package/src/__tests__/location-type-routing-invariant.test.ts +25 -8
  43. package/src/cvcs/coreInformationScope.v2.1.0.json +5498 -0
  44. package/src/cvcs/index.ts +2 -2
  45. package/src/cvcs/roiScope.v1.4.0.json +360 -0
  46. package/src/generated/cvc-enums.ts +77 -4
  47. package/src/services/__tests__/fixtures/infoscope-v4/information_scope_v3_placements.projection.csv +12 -0
  48. package/src/services/__tests__/fixtures/infoscope-v4/information_scope_v4.migrations.csv +106 -0
  49. package/src/services/__tests__/fixtures/infoscope-v4/information_scope_v4.rows.csv +117 -0
  50. package/src/services/__tests__/fixtures/infoscope-v4/loadInfoscopeV4Fixtures.ts +187 -0
  51. package/src/services/__tests__/informationScopeResolver.test.ts +1278 -0
  52. package/src/services/index.ts +10 -3
  53. package/src/services/informationScope.ts +10 -0
  54. package/src/services/informationScopeResolver.ts +879 -0
  55. package/src/services/informationScopeSot.ts +203 -0
  56. package/src/cvcs/coreInformationScope.v1.1.0.json +0 -1290
  57. package/src/cvcs/roiScope.v1.2.0.json +0 -340
  58. package/dist/{cvcEntry-BCj1OWqL.d.cts → cvcEntry-0BIB9sen.d.cts} +8 -8
  59. package/dist/{cvcEntry-BCj1OWqL.d.ts → cvcEntry-0BIB9sen.d.ts} +8 -8
@@ -1,29 +1,33 @@
1
1
  /**
2
- * CORE INFORMATION SCOPE (CVC-236) — the invariants adoption depends on
3
- * ==================================================================
2
+ * CORE INFORMATION SCOPE (CVC-236) — the v4 tree and the invariants adoption depends on
3
+ * =====================================================================================
4
4
  *
5
- * Two vocabularies describe the same thing at different grains:
5
+ * SOT v2.0.0 (amended by v2.1.0: Crysta's release-grain ruling, 2026-10-09)
6
+ * absorbs the canonical CVC-236 v4 tree (prototype
7
+ * `core_information_scope.v4.draft.yaml`, signed 2026-10-09; developer handoff
8
+ * `docs/share-roi/INFOSCOPE_V4_DEV_HANDOFF_2026-10-09.md`):
6
9
  *
7
- * `roi_scope` LEGACY flat item vocabulary, 27 substantive keys
8
- * (25 live + 2 RETIRED tombstones), no category axis
9
- * `core_information_scope` 12 policy-grain CATEGORIES + 55 authorization-grain UNITS
10
- * (+ 2 RETIRED tombstones, 2026-10-05)
10
+ * System metadata · Narrative notes · Primary client / case subject
11
+ * (8 categories → sub-categories → 28 instrument rows / 1 rest row) ·
12
+ * Other named persons (3 person types × the same categories) · 4 LEADS
13
+ * categories beside the top layer.
14
+ *
15
+ * Two vocabularies still describe stored consent:
11
16
  *
12
- * PAVE and Thread both hold stored ROIs written against `roi_scope` keys, and
13
- * both now derive their live vocabulary from this domain, keeping `roi_scope`
14
- * only as the stored-data provenance check. That move is safe for exactly one reason:
15
- * every substantive `roi_scope` key survives here, spelled identically, so a
16
- * stored ROI keeps its exact recorded meaning. That is not a nice-to-have — an
17
- * ROI whose meaning widens is a CONSENT change wearing a data change's clothes,
18
- * and one already shipped on the CaseShare lane when a coarse->granular table
19
- * expanded `caseNotes` to include screening notes the survivor never authorized.
17
+ * `roi_scope` LEGACY flat item vocabulary, 27 substantive keys
18
+ * `core_information_scope` the tree above (115 live rows + 27 RETIRED tombstones)
20
19
  *
21
- * So the subset property below is the whole basis for calling adoption additive.
22
- * If it ever fails, adoption stops being a migration and becomes a re-consent.
20
+ * Stored ROIs and shares were written against both. Adoption stays a
21
+ * MIGRATION, not a re-consent, because (a) every published key is still an
22
+ * entry here, at its published code, and (b) a key the tree no longer
23
+ * carries is a tombstone whose v4 reading is canon's from-to table — read at
24
+ * READ time, never by rewriting the stored list (handoff § 3).
23
25
  *
24
- * The grain invariants matter for a different reason: canon states that
25
- * categories are the POLICY grain and units are the AUTHORIZATION grain. A
26
- * selectable category would let a policy row be cited as if it were consent.
26
+ * Codes are identifiers, not tree paths: every v1.1.0 code is byte-identical
27
+ * although six published categories (identifying, risk, contact, services,
28
+ * health_accommodation, immigration_legal_status) now sit under
29
+ * `primary_client`. The
30
+ * tree is `parentCode` / `childCodes`.
27
31
  */
28
32
 
29
33
  import { readFileSync } from "node:fs";
@@ -38,182 +42,124 @@ const cvcDir = path.join(here, "..", "cvcs");
38
42
  interface Entry {
39
43
  code: string;
40
44
  key: string;
45
+ title: string;
46
+ definition: string | null;
41
47
  selectable: boolean;
42
48
  parentCode: string | null;
49
+ parentKey: string | null;
43
50
  childCodes: string[];
51
+ childKeys: string[];
52
+ canonicalCode?: string;
53
+ rowType?: string;
54
+ depth?: number;
55
+ kindBranch?: string | null;
56
+ apps?: { pave: boolean; thread: boolean; leads: boolean };
44
57
  shareableDefault?: boolean;
45
- required?: boolean;
46
58
  platformFloor?: boolean;
47
59
  levelFloor?: number;
48
- appRelevance?: string[];
49
60
  specialDataType?: string;
61
+ status?: string;
62
+ replacesV3?: string[];
63
+ required?: boolean;
64
+ kindRow?: string;
65
+ instrument?: string;
66
+ part?: string;
50
67
  retired?: boolean;
68
+ successors?: string[];
69
+ successorCodes?: string[];
70
+ restrictionSuccessors?: string[];
71
+ restrictionSuccessorCodes?: string[];
72
+ migrationRule?: string;
73
+ v3Fields?: string[];
74
+ v3Domains?: string[];
75
+ v3FieldsNote?: string;
51
76
  }
52
77
 
53
- const read = (f: string): { entries: Entry[]; levels: Record<string, string> } =>
54
- JSON.parse(readFileSync(path.join(cvcDir, f), "utf8")) as {
55
- entries: Entry[];
56
- levels: Record<string, string>;
57
- };
58
-
59
- const scope = read("coreInformationScope.v1.1.0.json");
60
- const roi = read("roiScope.v1.2.0.json");
61
-
62
- const byCode = new Map(scope.entries.map((e) => [e.code, e]));
63
- const MISSINGNESS = new Set([
64
- "missingness_root",
65
- "unknown",
66
- "anonymous",
67
- "data_not_collected",
68
- ]);
69
-
70
- const isMissingness = (e: Entry): boolean =>
71
- MISSINGNESS.has(e.key) ||
72
- (e.parentCode !== null && byCode.get(e.parentCode)?.key === "missingness_root");
73
-
74
- const categories = scope.entries.filter(
75
- (e) => e.parentCode === null && !isMissingness(e),
76
- );
77
- /** Every L2 row: live units AND retired tombstones. */
78
- const allUnits = scope.entries.filter(
79
- (e) => e.parentCode !== null && !isMissingness(e),
80
- );
81
- /** Live, authorizable units — what a picker offers. */
82
- const units = allUnits.filter((e) => e.retired !== true);
83
- /** Retired tombstones — resolvable by code, include nothing, never offered. */
84
- const tombstones = allUnits.filter((e) => e.retired === true);
85
-
86
- describe("core_information_scope — adoption invariants", () => {
87
- const roiSubstantive = roi.entries
88
- .map((e) => e.key)
89
- .filter((k) => !MISSINGNESS.has(k));
90
-
91
- it("resolves every substantive roi_scope key, spelled identically", () => {
92
- const unitKeys = new Set(allUnits.map((u) => u.key));
93
- const missing = roiSubstantive.filter((k) => !unitKeys.has(k));
94
-
95
- // A failure here means a stored ROI can no longer be expressed in the new
96
- // vocabulary — re-consent, not migration.
97
- expect(missing).toEqual([]);
98
- expect(roiSubstantive.length).toBe(27);
99
- });
100
-
101
- it("retires exactly the two roi_scope keys canon retired, and no other", () => {
102
- // NARRATIVE-NOTES 2026-10-05 (signed Spec v2 rule 5): screen_notes and
103
- // background are retired. A stored ROI naming one still RESOLVES (to a
104
- // tombstone that includes nothing) — it narrows, it never widens, and
105
- // canon records that only demo data named them. Any OTHER roi_scope key
106
- // landing on a tombstone would be an unruled narrowing of stored consent.
107
- const live = new Set(units.map((u) => u.key));
108
- expect(roiSubstantive.filter((k) => !live.has(k)).sort()).toEqual([
109
- "background",
110
- "screen_notes",
111
- ]);
112
- });
113
-
114
- it("gives ONE answer to 'is this offerable' across both vocabularies (co-bwc)", () => {
115
- // Until roi_scope v1.2.0 the package answered twice: CVC-236 v1.1.0 had
116
- // retired screen_notes / background while roi_scope still marked them
117
- // selectable. Every shared key must now agree on selectable AND retired,
118
- // so neither vocabulary can re-offer a retired unit as consent.
119
- // Missingness keys included: the four shared sentinels must agree too.
120
- const scopeByKey = new Map(scope.entries.map((u) => [u.key, u]));
121
- const disagreements = roi.entries
122
- .filter((e) => {
123
- const twin = scopeByKey.get(e.key);
124
- return (
125
- twin === undefined ||
126
- twin.selectable !== e.selectable ||
127
- (twin.retired === true) !== (e.retired === true)
128
- );
129
- })
130
- .map((e) => e.key);
131
- expect(disagreements).toEqual([]);
132
-
133
- // Scoped to CVC-236 tombstones whose key roi_scope carries: a future
134
- // CVC-236-only retirement (a unit roi_scope never had) is not a
135
- // divergence of the legacy vocabulary.
136
- const roiKeys = new Set(roi.entries.map((e) => e.key));
137
- const roiTombstones = roi.entries.filter((e) => e.retired === true);
138
- expect(roiTombstones.map((e) => e.key).sort()).toEqual(
139
- tombstones
140
- .filter((t) => roiKeys.has(t.key))
141
- .map((t) => t.key)
142
- .sort(),
143
- );
144
- // A tombstone keeps its published roi_scope code (983-012 / 983-014) —
145
- // codes are never withdrawn or reused.
146
- expect(roiTombstones.map((e) => e.code).sort()).toEqual([
147
- "983-012-000-000-000-000-000",
148
- "983-014-000-000-000-000-000",
149
- ]);
150
- expect(roiTombstones.every((e) => e.selectable === false)).toBe(true);
151
- });
152
-
153
- it("is a strict superset — the additions are additions, not renames", () => {
154
- expect(units.length).toBeGreaterThan(27);
155
- expect(units).toHaveLength(55);
156
- expect(tombstones).toHaveLength(2);
157
- });
158
-
159
- it("keeps the two grains distinct: categories decide policy, units carry consent", () => {
160
- expect(categories).toHaveLength(12);
161
- expect(categories.every((c) => c.selectable === false)).toBe(true);
162
- expect(units.every((u) => u.selectable === true)).toBe(true);
163
- // A tombstone is never authorizable — selectable would let a retired
164
- // code be cited as consent again.
165
- expect(tombstones.every((t) => t.selectable === false)).toBe(true);
166
- });
167
-
168
- it("wires every unit — tombstones included — to exactly one category, reciprocally", () => {
169
- // Tombstones stay in their category's childCodes: the locked spec §4 C4
170
- // invariant makes childCodes the exact inverse of parentCode. Pickers
171
- // offer only selectable children.
172
- for (const u of allUnits) {
173
- const parent = byCode.get(u.parentCode as string);
174
- expect(parent, `unit ${u.key} has a dangling parent`).toBeDefined();
175
- expect(parent?.selectable, `unit ${u.key} hangs off a selectable row`).toBe(
176
- false,
177
- );
178
- expect(parent?.childCodes, `category ${parent?.key} disowns ${u.key}`).toContain(
179
- u.code,
180
- );
181
- }
182
- expect(categories.flatMap((c) => c.childCodes)).toHaveLength(allUnits.length);
183
- });
78
+ interface MigrationLine {
79
+ from: string;
80
+ fromCode: string;
81
+ rule: string;
82
+ to: string[];
83
+ toCodes: string[];
84
+ note: string;
85
+ widens: boolean;
86
+ releaseReading?: string;
87
+ releaseReadingNote?: string;
88
+ policyReading?: string;
89
+ informational?: boolean;
90
+ }
184
91
 
185
- it("publishes the posture sets as data, so they stop being literals", () => {
186
- const of = (p: (u: Entry) => boolean): string[] =>
187
- units.filter(p).map((u) => u.key).sort();
92
+ interface Envelope {
93
+ version: string;
94
+ scopeVersion?: number;
95
+ _status: string;
96
+ _source: string;
97
+ _supersedes: {
98
+ version: string;
99
+ keyMap: Record<string, string>;
100
+ retiredCodes: unknown[];
101
+ notes: Record<string, string>;
102
+ };
103
+ levels: Record<string, string>;
104
+ migrations: {
105
+ stampKey: string;
106
+ fromVersion: number;
107
+ toVersion: number;
108
+ readAt: string;
109
+ unstamped: string;
110
+ rules: Record<string, string>;
111
+ ruling: {
112
+ date: string;
113
+ by: string;
114
+ source: string;
115
+ text: string[];
116
+ applies: string;
117
+ membership: string;
118
+ canon: string;
119
+ };
120
+ table: MigrationLine[];
121
+ };
122
+ entries: Entry[];
123
+ }
188
124
 
189
- // shareable_default:false — the picker must not pre-check these.
190
- expect(of((u) => u.shareableDefault === false)).toEqual([
191
- "federal_protection_applications",
192
- "hiv_status",
193
- "immigration_status",
194
- "le_report_status",
195
- "safe_locations",
196
- "tvap_enrollment",
197
- "uscis_alien_number",
198
- ]);
125
+ const read = (f: string): Envelope =>
126
+ JSON.parse(readFileSync(path.join(cvcDir, f), "utf8")) as Envelope;
199
127
 
200
- // The platform safety floor — enforceable BELOW the scope layer.
201
- expect(of((u) => u.platformFloor === true)).toEqual(["safe_locations"]);
128
+ const scope = read("coreInformationScope.v2.1.0.json");
129
+ const roi = read("roiScope.v1.4.0.json");
202
130
 
203
- // Always included; currently a hardcoded string in both apps.
204
- expect(of((u) => u.required === true)).toEqual(["system_info"]);
205
- });
206
- });
131
+ const byCode = new Map(scope.entries.map((e) => [e.code, e]));
132
+ const byKey = new Map(scope.entries.map((e) => [e.key, e]));
133
+ const MISSINGNESS = new Set(["missingness_root", "unknown", "anonymous", "data_not_collected"]);
134
+ const isMissingness = (e: Entry): boolean => MISSINGNESS.has(e.key);
135
+
136
+ const rows = scope.entries.filter((e) => !isMissingness(e));
137
+ /** The live v4 tree. */
138
+ const live = rows.filter((e) => e.retired !== true);
139
+ /** Retired tombstones — resolvable by code, never offered. */
140
+ const tombstones = rows.filter((e) => e.retired === true);
141
+ const liveKey = (k: string): Entry | undefined => {
142
+ const e = byKey.get(k);
143
+ return e && e.retired !== true ? e : undefined;
144
+ };
145
+ const ancestors = (e: Entry): Entry[] => {
146
+ const out: Entry[] = [];
147
+ let p = e.parentCode;
148
+ while (p !== null) {
149
+ const parent = byCode.get(p);
150
+ if (!parent) break;
151
+ out.push(parent);
152
+ p = parent.parentCode;
153
+ }
154
+ return out;
155
+ };
156
+ const seg = (n: number): string => String(n).padStart(3, "0");
157
+ const codeOf = (...segs: number[]): string =>
158
+ ["236", ...[...segs, 0, 0, 0, 0, 0, 0].slice(0, 6).map(seg)].join("-");
159
+ const sortedKeys = (es: Entry[]): string[] => es.map((e) => e.key).sort();
207
160
 
208
- /**
209
- * Codes are POSITIONAL (category slot, unit slot within it), so a canon
210
- * reorder or mid-list insertion would silently renumber codes already stored
211
- * on ROIs and shares. The generator refuses that (its FROZEN table); this pins
212
- * the same published assignment from the consumer side, so a hand-edit or a
213
- * generator change that renumbers fails here too. New units APPEND inside
214
- * their category; new categories APPEND at the end. Never reorder this table.
215
- */
216
- const PUBLISHED: ReadonlyArray<readonly [string, readonly string[]]> = [
161
+ /** What v1.1.0 published, by category slot, in ordinal order. Never reorder. */
162
+ const PUBLISHED_V1_1_0: ReadonlyArray<readonly [string, readonly string[]]> = [
217
163
  ["identifying", ["names", "dob", "addresses", "additional_ids", "demographics"]],
218
164
  [
219
165
  "risk",
@@ -239,8 +185,6 @@ const PUBLISHED: ReadonlyArray<readonly [string, readonly string[]]> = [
239
185
  ],
240
186
  ["contact", ["contact_info", "safe_locations", "priorities_safety", "encounter_location"]],
241
187
  ["services", ["contact_history", "service_history", "plans_goals"]],
242
- // screen_notes (-001) and background (-003) are RETIRED tombstones since
243
- // 2026-10-05 — they keep their codes; session_summary APPENDED at -004.
244
188
  ["notes", ["screen_notes", "case_notes", "background", "session_summary"]],
245
189
  [
246
190
  "health_accommodation",
@@ -272,209 +216,674 @@ const PUBLISHED: ReadonlyArray<readonly [string, readonly string[]]> = [
272
216
  ["investigative_work_product", ["case_determinations", "case_lifecycle", "case_attachments"]],
273
217
  ["object_identifiers", ["phone_identifiers", "object_identity_attributes"]],
274
218
  ];
219
+ const V1_1_0_KEYS = [
220
+ ...MISSINGNESS,
221
+ ...PUBLISHED_V1_1_0.flatMap(([c, us]) => [c, ...us]),
222
+ ];
275
223
 
276
- const seg = (n: number): string => String(n).padStart(3, "0");
277
- const codeOf = (cat: number, unit = 0): string =>
278
- `236-${seg(cat)}-${seg(unit)}-000-000-000-000`;
279
- const byKey = new Map(scope.entries.map((e) => [e.key, e]));
224
+ /** The v2.0.0 appends: [key, code]. Append-only. */
225
+ const APPENDED_V2_0_0: ReadonlyArray<readonly [string, string]> = [
226
+ ["identifying__other", codeOf(1, 6)],
227
+ ["health_status", codeOf(6, 10)],
228
+ ["immigration_applications", codeOf(7, 6)],
229
+ ["instruments", codeOf(13)],
230
+ ["instrument_summary", codeOf(13, 1)],
231
+ ["instrument_full", codeOf(13, 2)],
232
+ ["relationships_household", codeOf(14)],
233
+ ["primary_client", codeOf(15)],
234
+ ["other_named_persons", codeOf(16)],
235
+ ["offenders", codeOf(16, 1)],
236
+ ["family", codeOf(16, 2)],
237
+ ["others", codeOf(16, 3)],
238
+ ];
239
+ const INSTRUMENTS = [
240
+ "initial_screen",
241
+ "mental_health_screen",
242
+ "behavioral_health_intake",
243
+ "trauma_and_coping_screen",
244
+ "ae_intake",
245
+ "ida",
246
+ "lap",
247
+ "danger_assessment",
248
+ "stalking_assessment",
249
+ "injury_and_strangulation",
250
+ "hope_scale",
251
+ "needs_assessment",
252
+ "tra",
253
+ "findings",
254
+ ];
255
+ const KINDS = ["offenders", "family", "others"] as const;
256
+
257
+ // ═══════════════════════════════════════════════════════════════════════════
258
+ describe("core_information_scope v4 — the tree (handoff § 1, § 8)", () => {
259
+ it("carries every canon row once: 115 live rows, 27 tombstones, 4 missingness", () => {
260
+ expect(live).toHaveLength(115);
261
+ expect(tombstones).toHaveLength(27);
262
+ expect(scope.entries).toHaveLength(146);
263
+ expect(scope.scopeVersion).toBe(4);
264
+ });
280
265
 
281
- describe("core_information_scope — published codes never move", () => {
282
- it("keeps every published category and unit at its frozen positional code", () => {
283
- const actual = [...categories, ...allUnits].map((e): [string, string] => [e.key, e.code]);
284
- const expected = PUBLISHED.flatMap(([cat, us], ci): [string, string][] => [
285
- [cat, codeOf(ci + 1)],
286
- ...us.map((u, ui): [string, string] => [u, codeOf(ci + 1, ui + 1)]),
266
+ it("counts each row type as canon does", () => {
267
+ const counts: Record<string, number> = {};
268
+ for (const e of live) counts[e.rowType as string] = (counts[e.rowType as string] ?? 0) + 1;
269
+ expect(counts).toEqual({
270
+ branch: 2,
271
+ person_type: 3,
272
+ category: 38,
273
+ subcategory: 34,
274
+ // canon's exporter label for a LEADS unit (no row_type in the yaml) — kept as written
275
+ "sub-category": 9,
276
+ category_rest: 1,
277
+ "instrument row": 28,
278
+ });
279
+ });
280
+
281
+ it("roots the tree at the four top-layer groups plus the four LEADS categories", () => {
282
+ expect(sortedKeys(live.filter((e) => e.parentCode === null))).toEqual([
283
+ "commercial_activity",
284
+ "investigative_work_product",
285
+ "network_associations",
286
+ "notes",
287
+ "object_identifiers",
288
+ "other_named_persons",
289
+ "primary_client",
290
+ "system",
291
+ ]);
292
+ expect(sortedKeys(live.filter((e) => e.parentCode === byKey.get("primary_client")?.code))).toEqual([
293
+ "contact",
294
+ "health_accommodation",
295
+ "identifying",
296
+ "immigration_legal_status",
297
+ "instruments",
298
+ "relationships_household",
299
+ "risk",
300
+ "services",
301
+ ]);
302
+ expect(byKey.get("other_named_persons")?.childCodes.map((c) => byCode.get(c)?.key)).toEqual([
303
+ "offenders",
304
+ "family",
305
+ "others",
287
306
  ]);
288
- // Exact equality, both directions: an unlisted addition fails too, so the
289
- // table above is updated (by APPENDING) in the same change that mints it.
290
- expect(new Map(actual)).toEqual(new Map(expected));
291
307
  });
292
- });
293
308
 
294
- /**
295
- * `priorities_safety` — canon CVC-236 amendment 2026-09-29
296
- * (PRIORITIES-SAFETY-SCOPE-UNIT, Crysta R1; prototype `data/cvcs/
297
- * core_information_scope.yaml` @ 285a9f1d). Thread's Priorities & Safety
298
- * answers (immediate danger, safe place, dependents at risk) had NO unit, so
299
- * they were unauthorizable and could not ride a share or an ROI at all.
300
- */
301
- describe("core_information_scope — priorities_safety (2026-09-29)", () => {
302
- const unit = byKey.get("priorities_safety");
303
-
304
- it("is ONE selectable unit under Contact & safety, at the next contact slot", () => {
305
- // R1: one unit for the whole step — not split across contact + services.
306
- expect(unit).toBeDefined();
307
- expect(unit?.code).toBe("236-003-003-000-000-000-000");
308
- expect(unit?.selectable).toBe(true);
309
- expect(unit?.parentCode).toBe(byKey.get("contact")?.code);
310
- expect(byKey.get("contact")?.childCodes).toContain(unit?.code);
311
- expect(
312
- scope.entries.filter((e) => e.key.startsWith("priorities")).map((e) => e.key),
313
- ).toEqual(["priorities_safety"]);
314
- });
315
-
316
- it("carries canon's posture: shareable by default, never the platform floor", () => {
317
- // R1 rejected heightened protection: the most action-relevant answers on
318
- // the record must not be the hardest to pass to the next advocate.
319
- expect(unit?.shareableDefault).toBe(true);
320
- // R2: locations follow the location, never the question — the floor stays
321
- // on safe_locations alone, nothing is carved out of this unit by hand.
322
- expect(unit?.platformFloor).toBeUndefined();
323
- expect(unit?.required).toBeUndefined();
324
- expect(unit?.levelFloor).toBe(3);
325
- expect(unit?.specialDataType).toBe("survivor_confidential");
326
- expect(unit?.appRelevance).toEqual(["PAVE", "Thread"]);
309
+ it("gives every non-top row exactly one live parent, reciprocally", () => {
310
+ for (const e of live) {
311
+ if (e.parentCode === null) continue;
312
+ const parent = byCode.get(e.parentCode);
313
+ expect(parent, `${e.key} has a dangling parent`).toBeDefined();
314
+ expect(parent?.retired, `${e.key} hangs off a tombstone`).toBeUndefined();
315
+ expect(parent?.childCodes, `${parent?.key} disowns ${e.key}`).toContain(e.code);
316
+ expect(
317
+ rows.filter((p) => p.childCodes.includes(e.code)).map((p) => p.key),
318
+ `${e.key} is claimed by more than one parent`,
319
+ ).toHaveLength(1);
320
+ }
327
321
  });
328
- });
329
322
 
330
- /**
331
- * `encounter_location` — canon CVC-236 amendment 2026-10-01
332
- * (LOCATION-TYPE-LOGIC, Crysta R2; prototype `data/cvcs/
333
- * core_information_scope.yaml` @ 55088d44). The session's own location
334
- * entries — where the advocate met the survivor, or where the incident
335
- * happened (CVC-191 reasons MEET_LOC + INCIDENT) — belonged to no person, so no
336
- * share could reach them, and Thread was sending every session location under
337
- * the `addresses` pick. They now ride this one unit.
338
- */
339
- describe("core_information_scope — encounter_location (2026-10-01)", () => {
340
- const unit = byKey.get("encounter_location");
341
-
342
- it("is ONE selectable unit under Contact & safety, appended at the next contact slot", () => {
343
- expect(unit).toBeDefined();
344
- expect(unit?.code).toBe("236-003-004-000-000-000-000");
345
- expect(unit?.selectable).toBe(true);
346
- expect(unit?.parentCode).toBe(byKey.get("contact")?.code);
347
- // Appended after priorities_safety: no published contact code moved.
348
- expect(byKey.get("contact")?.childCodes).toEqual([
349
- "236-003-001-000-000-000-000",
350
- "236-003-002-000-000-000-000",
351
- "236-003-003-000-000-000-000",
352
- "236-003-004-000-000-000-000",
353
- ]);
354
- // R2: one new unit. No second "residence" unit — residence vs. incident
355
- // is already split by the CVC-191 reason.
356
- expect(
357
- scope.entries.filter((e) => e.key.includes("encounter")).map((e) => e.key),
358
- ).toEqual(["encounter_location"]);
359
- });
360
-
361
- it("carries canon's posture: shareable by default, never the platform floor", () => {
362
- // R2: where the survivor was found or met is the safety fact the next
363
- // advocate needs, so the picker pre-checks it.
364
- expect(unit?.shareableDefault).toBe(true);
365
- // The floor stays on safe_locations alone; a shelter address picked as an
366
- // encounter location is still caught by the floor, not by this unit.
367
- expect(unit?.platformFloor).toBeUndefined();
368
- expect(unit?.required).toBeUndefined();
369
- expect(unit?.levelFloor).toBe(3);
370
- expect(unit?.specialDataType).toBe("survivor_confidential");
371
- expect(unit?.appRelevance).toEqual(["PAVE", "Thread"]);
372
- });
373
-
374
- it("leaves addresses where it was: the survivor's own whereabouts keep riding it", () => {
375
- // R3: addresses keeps its code and posture; only its definition gains the
376
- // type-grain routing note.
377
- const addresses = byKey.get("addresses");
378
- expect(addresses?.code).toBe("236-001-003-000-000-000-000");
379
- expect(addresses?.shareableDefault).toBe(true);
380
- expect(addresses?.platformFloor).toBeUndefined();
323
+ it("carries the tree by key as well as by code (parentKey / childKeys)", () => {
324
+ for (const e of scope.entries) {
325
+ expect(e.parentKey, e.key).toBe(e.parentCode === null ? null : byCode.get(e.parentCode)?.key);
326
+ expect(e.childKeys, e.key).toEqual(e.childCodes.map((c) => byCode.get(c)?.key));
327
+ }
328
+ });
329
+
330
+ it("carries canon's depth: the number of ancestors (LEADS rows sit one deeper, beside the top layer)", () => {
331
+ for (const e of live) {
332
+ const extra = e.kindBranch === "leads" ? 1 : 0;
333
+ expect(e.depth, e.key).toBe(ancestors(e).length + extra);
334
+ }
335
+ });
336
+
337
+ it("keeps system_info: present, required, under System metadata", () => {
338
+ const si = liveKey("system_info");
339
+ expect(si?.required).toBe(true);
340
+ expect(si?.parentCode).toBe(byKey.get("system")?.code);
341
+ expect(sortedKeys(live.filter((e) => e.required === true))).toEqual(["system_info"]);
342
+ });
343
+
344
+ it("offers every LIVE row but the 28 instrument rows and the identifying rest row", () => {
345
+ const notSelectable = live.filter((e) => !e.selectable);
346
+ expect(notSelectable).toHaveLength(29);
347
+ expect(sortedKeys(notSelectable)).toEqual(
348
+ [
349
+ ...INSTRUMENTS.flatMap((i) => [`summary_${i}`, `full_${i}`]),
350
+ "identifying__other",
351
+ ].sort(),
352
+ );
353
+ expect(liveKey("identifying__other")?.rowType).toBe("category_rest");
354
+ });
355
+
356
+ it("puts the platform floor on exactly four rows: safe_locations and its three per-kind copies", () => {
357
+ expect(sortedKeys(live.filter((e) => e.platformFloor === true))).toEqual(
358
+ ["safe_locations", ...KINDS.map((k) => `${k}__safe_locations`)].sort(),
359
+ );
360
+ });
361
+
362
+ it("turns exactly 28 rows off by default: Immigration, the Full part, and the floor", () => {
363
+ const off = live.filter((e) => e.shareableDefault === false);
364
+ expect(off).toHaveLength(28);
365
+ expect(sortedKeys(off)).toEqual(
366
+ [
367
+ "immigration_legal_status",
368
+ "immigration_status",
369
+ "immigration_applications",
370
+ "instrument_full",
371
+ ...INSTRUMENTS.map((i) => `full_${i}`),
372
+ "safe_locations",
373
+ ...KINDS.flatMap((k) => [
374
+ `${k}__immigration_legal_status`,
375
+ `${k}__instrument_full`,
376
+ `${k}__safe_locations`,
377
+ ]),
378
+ ].sort(),
379
+ );
380
+ });
381
+
382
+ it("uses only the canon enum values (handoff § 8, plus the three canon uses § 8 omits)", () => {
383
+ for (const e of live) {
384
+ expect(
385
+ [
386
+ "category",
387
+ "subcategory",
388
+ "sub-category",
389
+ "person_type",
390
+ "category_rest",
391
+ "instrument row",
392
+ "branch",
393
+ ],
394
+ e.key,
395
+ ).toContain(e.rowType);
396
+ expect(["none", "survivor_confidential", "criminal_intelligence", "evidence"], e.key).toContain(
397
+ e.specialDataType,
398
+ );
399
+ expect(["as_today", "new"], e.key).toContain(e.status);
400
+ expect(["client", "offenders", "family", "others", "leads", null], e.key).toContain(
401
+ e.kindBranch,
402
+ );
403
+ expect([1, 3], e.key).toContain(e.levelFloor);
404
+ expect(Object.keys(e.apps ?? {}).sort(), e.key).toEqual(["leads", "pave", "thread"]);
405
+ }
406
+ expect(live.filter((e) => e.status === "new")).toHaveLength(42);
407
+ });
408
+
409
+ it("spells a canon `.` as `__` in the key, with the canon code on canonicalCode", () => {
410
+ const dotted = live.filter((e) => e.canonicalCode !== undefined);
411
+ expect(dotted).toHaveLength(34);
412
+ for (const e of live) {
413
+ if (e.key.includes("__")) expect(e.canonicalCode, e.key).toBe(e.key.replace("__", "."));
414
+ else expect(e.canonicalCode, e.key).toBeUndefined();
415
+ }
416
+ });
417
+
418
+ it("places the per-kind rows by person type (handoff § 4: no LEADS column on them)", () => {
419
+ for (const k of KINDS) {
420
+ const kindRows = live.filter((e) => e.kindBranch === k);
421
+ expect(kindRows, k).toHaveLength(12);
422
+ for (const e of kindRows) {
423
+ expect(ancestors(e).map((a) => a.key), e.key).toContain("other_named_persons");
424
+ expect(e.apps?.leads, e.key).toBe(false);
425
+ }
426
+ }
381
427
  });
382
428
  });
383
429
 
384
- /**
385
- * `safe_locations` — RATIFIED 2026-09-08 (CVC236-AUDIT R1, Crysta; prototype
386
- * `data/cvcs/core_information_scope.yaml` @ 46a60114, lines 72-75 + 310-311).
387
- * The id and label are canon and the row is minted in the Notion codebook, so
388
- * the PROVISIONAL marker the package published from 2026-08-18 is retired.
389
- * The code, label and posture did not change: only the wording did.
390
- */
391
- describe("core_information_scope — safe_locations ratified (2026-09-08)", () => {
392
- const raw = JSON.parse(
393
- readFileSync(path.join(cvcDir, "coreInformationScope.v1.1.0.json"), "utf8"),
394
- ) as { _status: string; entries: (Entry & { title: string; definition: string })[] };
395
- const unit = raw.entries.find((e) => e.key === "safe_locations");
430
+ // ═══════════════════════════════════════════════════════════════════════════
431
+ describe("core_information_scope v4 — published codes never move, new codes append", () => {
432
+ it("keeps every v1.1.0 category and unit at its v1.1.0 positional code", () => {
433
+ for (const [ci, [cat, us]] of PUBLISHED_V1_1_0.entries()) {
434
+ expect(byKey.get(cat)?.code, cat).toBe(codeOf(ci + 1));
435
+ for (const [ui, u] of us.entries()) {
436
+ expect(byKey.get(u)?.code, u).toBe(codeOf(ci + 1, ui + 1));
437
+ }
438
+ }
439
+ });
440
+
441
+ it("appends the new category-, unit- and person-type slots at their frozen codes", () => {
442
+ for (const [k, c] of APPENDED_V2_0_0) expect(byKey.get(k)?.code, k).toBe(c);
443
+ });
444
+
445
+ it("codes each instrument row 236-013-00P-NNN, the same NNN for both parts", () => {
446
+ for (const [i, inst] of INSTRUMENTS.entries()) {
447
+ for (const [p, part] of (["summary", "full"] as const).entries()) {
448
+ const e = liveKey(`${part}_${inst}`);
449
+ expect(e?.code, `${part}_${inst}`).toBe(codeOf(13, p + 1, i + 1));
450
+ expect(e?.instrument).toBe(inst);
451
+ expect(e?.part).toBe(part);
452
+ }
453
+ }
454
+ });
396
455
 
397
- it("keeps its published code, label and platform-floor posture", () => {
398
- expect(unit?.code).toBe("236-003-002-000-000-000-000");
399
- expect(unit?.title).toBe("Safe & confidential locations");
400
- expect(unit?.platformFloor).toBe(true);
401
- expect(unit?.shareableDefault).toBe(false);
456
+ it("codes every per-kind row by MIRRORING the kind-tree row it copies", () => {
457
+ const perKind = live.filter((e) => e.kindRow !== undefined);
458
+ expect(perKind).toHaveLength(33);
459
+ for (const e of perKind) {
460
+ const kind = byKey.get(e.kindBranch as string);
461
+ const mirrored = liveKey(e.kindRow as string);
462
+ expect(mirrored, e.key).toBeDefined();
463
+ expect(mirrored?.kindBranch, e.key).toBe("client");
464
+ expect(e.key).toBe(`${e.kindBranch}__${e.kindRow}`);
465
+ const segs = (c: string): string[] => c.split("-").slice(1).filter((s) => s !== "000");
466
+ expect(segs(e.code), e.key).toEqual([
467
+ ...segs(kind?.code as string),
468
+ ...segs(mirrored?.code as string),
469
+ ]);
470
+ }
402
471
  });
403
472
 
404
- it("no longer reads as provisional, in its definition or in the domain status", () => {
405
- expect(unit?.definition).not.toMatch(/PROVISIONAL vocabulary/);
406
- expect(unit?.definition).toContain("RATIFIED 2026-09-08 (CVC236-AUDIT R1, Crysta)");
407
- expect(raw._status).not.toMatch(/`safe_locations` is PROVISIONAL/);
408
- expect(raw._status).toContain("`safe_locations` is CANON");
473
+ it("never reuses a code: unique across live rows and tombstones", () => {
474
+ expect(new Set(scope.entries.map((e) => e.code)).size).toBe(scope.entries.length);
475
+ expect(new Set(scope.entries.map((e) => e.key)).size).toBe(scope.entries.length);
409
476
  });
410
477
  });
411
478
 
412
- /**
413
- * Narrative notes — canon CVC-236 amendment 2026-10-05 (NARRATIVE-NOTES,
414
- * signed Spec v2 rule 5, Crysta; prototype `data/cvcs/
415
- * core_information_scope.yaml` @ 9ef79748, lines 445-467). The category now
416
- * offers two units, Session summary and Session & case notes; `screen_notes`
417
- * and `background` are listed in `retired_units`. Canon lists session_summary
418
- * FIRST, but codes follow the generator's frozen ledger, so no published
419
- * ordinal moves and no retired ordinal is reused.
420
- */
421
- describe("core_information_scope — narrative notes (2026-10-05)", () => {
422
- const raw = JSON.parse(
423
- readFileSync(path.join(cvcDir, "coreInformationScope.v1.1.0.json"), "utf8"),
424
- ) as { entries: (Entry & { title: string; definition: string })[] };
425
- const rawByKey = new Map(raw.entries.map((e) => [e.key, e]));
426
- const notes = byKey.get("notes");
427
-
428
- it("keeps screen_notes and background as RETIRED tombstones at their published codes", () => {
429
- for (const [key, code, title] of [
430
- ["screen_notes", "236-005-001-000-000-000-000", "Screen notes"],
431
- ["background", "236-005-003-000-000-000-000", "Background information"],
432
- ] as const) {
433
- const t = rawByKey.get(key);
434
- expect(t?.code, key).toBe(code);
435
- expect(t?.title, key).toBe(title);
436
- expect(t?.retired, key).toBe(true);
437
- expect(t?.selectable, key).toBe(false);
438
- expect(t?.parentCode, key).toBe(notes?.code);
439
- expect(t?.childCodes, key).toEqual([]);
440
- expect(t?.definition, key).toMatch(/^RETIRED 2026-10-05 /);
441
- expect(t?.definition, key).toContain("includes nothing");
442
- // Nothing left to share or view: no decision attributes a picker or a
443
- // share builder could act on.
479
+ // ═══════════════════════════════════════════════════════════════════════════
480
+ describe("core_information_scope v4 — retirements and the from-to table (handoff § 3)", () => {
481
+ const table = scope.migrations.table;
482
+
483
+ it("tombstones exactly the 27 published units v4 no longer carries", () => {
484
+ expect(sortedKeys(tombstones)).toEqual(
485
+ [
486
+ // Narrative notes (2026-10-05)
487
+ "screen_notes",
488
+ "background",
489
+ // the instrument era (INFOSCOPE-RETIRE 2026-10-08)
490
+ "ida_full",
491
+ "ida_consid",
492
+ "initial_screen",
493
+ "tra",
494
+ "lap",
495
+ "danger_assessment",
496
+ "injury_and_strangulation",
497
+ "stalking_assessment",
498
+ "ae_intake",
499
+ "hope_scale",
500
+ "assessment_records",
501
+ "determinations",
502
+ "mental_health_screen",
503
+ "trauma_and_coping_screen",
504
+ "behavioral_health_intake",
505
+ // v4 (2026-10-08/09)
506
+ "offender_facilitator",
507
+ "disability_subtypes",
508
+ "mental_health_status",
509
+ "substance_use_status",
510
+ "chronic_health_status",
511
+ "hiv_status",
512
+ "uscis_alien_number",
513
+ "federal_protection_applications",
514
+ "tvap_enrollment",
515
+ "le_report_status",
516
+ ].sort(),
517
+ );
518
+ });
519
+
520
+ it("makes every tombstone unofferable, attribute-free, and named by its canon reading", () => {
521
+ for (const t of tombstones) {
522
+ expect(t.selectable, t.key).toBe(false);
523
+ expect(t.status, t.key).toBe("retired");
524
+ expect(t.childCodes, t.key).toEqual([]);
525
+ expect(t.definition, t.key).toMatch(/^RETIRED \d{4}-\d{2}-\d{2} /);
444
526
  for (const attr of [
445
527
  "shareableDefault",
446
528
  "levelFloor",
447
- "appRelevance",
529
+ "apps",
448
530
  "specialDataType",
449
531
  "platformFloor",
450
532
  "required",
533
+ "rowType",
451
534
  ] as const) {
452
- expect(t?.[attr], `${key}.${attr}`).toBeUndefined();
535
+ expect(t[attr], `${t.key}.${attr}`).toBeUndefined();
453
536
  }
537
+ const lines = table.filter(
538
+ (m) => m.from === t.key && (m.rule === "row" || m.rule === "retired before v4"),
539
+ );
540
+ expect(lines, t.key).toHaveLength(1);
541
+ expect(t.successors, t.key).toEqual(lines[0]?.to);
542
+ expect(t.successorCodes, t.key).toEqual(lines[0]?.toCodes);
543
+ expect(t.migrationRule, t.key).toBe(lines[0]?.rule);
544
+ for (const s of t.successors ?? []) expect(liveKey(s), `${t.key} -> ${s}`).toBeDefined();
545
+ // A tombstone stays under the category that published it.
546
+ const home = PUBLISHED_V1_1_0.find(([, us]) => us.includes(t.key))?.[0];
547
+ expect(byCode.get(t.parentCode as string)?.key, t.key).toBe(home);
454
548
  }
455
549
  });
456
550
 
457
- it("keeps case_notes at 236-005-002 under canon's new label", () => {
458
- const u = rawByKey.get("case_notes");
459
- expect(u?.code).toBe("236-005-002-000-000-000-000");
460
- expect(u?.title).toBe("Session & case notes");
461
- expect(u?.selectable).toBe(true);
462
- expect(u?.retired).toBeUndefined();
551
+ it("reads the three include-nothing retirements as nothing", () => {
552
+ expect(sortedKeys(tombstones.filter((t) => (t.successors ?? []).length === 0))).toEqual([
553
+ "assessment_records",
554
+ "background",
555
+ "screen_notes",
556
+ ]);
557
+ expect(byKey.get("offender_facilitator")?.successors).toEqual([
558
+ "offenders__identifying",
559
+ "offenders__risk",
560
+ ]);
561
+ expect(byKey.get("ida_full")?.successors).toEqual(["full_ida", "summary_ida"]);
562
+ });
563
+
564
+ it("maps EVERY v1.1.0 key to a live v4 key or a tombstone", () => {
565
+ for (const k of V1_1_0_KEYS) {
566
+ const e = byKey.get(k);
567
+ expect(e, k).toBeDefined();
568
+ if (MISSINGNESS.has(k)) continue;
569
+ if (e?.retired === true) {
570
+ expect(e.successors, k).toBeDefined();
571
+ } else {
572
+ expect(
573
+ table.some((m) => m.from === k && m.rule === "identity" && m.to[0] === k),
574
+ `${k} is live but has no identity line`,
575
+ ).toBe(true);
576
+ }
577
+ }
578
+ expect(V1_1_0_KEYS).toHaveLength(73);
579
+ });
580
+
581
+ it("exports canon's table whole: 103 lines, every target live, codes resolved", () => {
582
+ const m = scope.migrations;
583
+ expect([m.stampKey, m.fromVersion, m.toVersion]).toEqual(["scopeVersion", 3, 4]);
584
+ expect(m.readAt).toMatch(/never rewrite/);
585
+ const counts: Record<string, number> = {};
586
+ for (const l of table) counts[l.rule] = (counts[l.rule] ?? 0) + 1;
587
+ expect(counts).toEqual({
588
+ identity: 73,
589
+ row: 10,
590
+ category: 2,
591
+ subtract: 1,
592
+ "retired before v4": 17,
593
+ });
594
+ expect(Object.keys(m.rules).sort()).toEqual(
595
+ [...Object.keys(counts), "widens", "releaseReading", "policyReading", "informational"].sort(),
596
+ );
597
+ for (const l of table) {
598
+ expect(byKey.get(l.from)?.code, l.from).toBe(l.fromCode);
599
+ expect(l.toCodes, l.from).toEqual(l.to.map((t) => liveKey(t)?.code));
600
+ if (l.rule === "identity") expect(l.to, l.from).toEqual([l.from]);
601
+ }
602
+ });
603
+
604
+ it("never widens a category-grain selection: each target's live subtree ⊆ what the v1.1.0 category covered", () => {
605
+ // The rows a category covers in v4: its live descendants, walked by
606
+ // parentKey. A `category_rest` row is the category's own grain (the facts
607
+ // v1.1.0 kept on the category itself), so it is not an addition.
608
+ const descendants = (k: string): string[] =>
609
+ live
610
+ .filter((e) => e.rowType !== "category_rest" && ancestors(e).some((a) => a.key === k))
611
+ .map((e) => e.key);
612
+ const covered = new Map(PUBLISHED_V1_1_0.map(([c, us]) => [c, new Set(us)]));
613
+ const cat = table.filter((l) => l.rule === "category");
614
+ expect(cat.length).toBeGreaterThan(0);
615
+ for (const l of cat) {
616
+ const was = covered.get(l.from);
617
+ expect(was, `${l.from} is not a v1.1.0 category`).toBeDefined();
618
+ for (const t of l.to) {
619
+ const wider = descendants(t).filter((d) => !was?.has(d));
620
+ expect(wider, `${l.from} -> ${t} reaches rows the v1.1.0 category did not cover`).toEqual([]);
621
+ }
622
+ }
623
+ });
624
+
625
+ it("keeps a restriction restricting, and names the restriction reading on the tombstone", () => {
626
+ const sub = table.filter((l) => l.rule === "subtract");
627
+ for (const l of sub) {
628
+ const t = byKey.get(l.from);
629
+ expect(t?.retired, l.from).toBe(true);
630
+ expect(t?.restrictionSuccessors, l.from).toEqual(l.to);
631
+ expect(t?.restrictionSuccessorCodes, l.from).toEqual(l.toCodes);
632
+ }
633
+ expect(sortedKeys(tombstones.filter((t) => t.restrictionSuccessors !== undefined))).toEqual(
634
+ sub.map((l) => l.from).sort(),
635
+ );
636
+ expect(byKey.get("offender_facilitator")?.restrictionSuccessors).toEqual(["offenders"]);
637
+ });
638
+
639
+ it("flags exactly the readings that WIDEN: a target shared by more than one v3 code", () => {
640
+ // Computed: an identity/row line widens when its target is also another
641
+ // v3 code's identity/row target. Pinned; consent widening RULED 2026-10-09
642
+ // (Crysta; canon SIGNED-GRAIN): see `releaseReading` below.
643
+ const sel = table.filter((l) => l.rule === "identity" || l.rule === "row");
644
+ const sources = new Map<string, Set<string>>();
645
+ for (const l of sel) {
646
+ for (const t of l.to) sources.set(t, (sources.get(t) ?? new Set()).add(l.from));
647
+ }
648
+ const computed = sel
649
+ .filter((l) => l.to.some((t) => (sources.get(t)?.size ?? 0) > 1))
650
+ .map((l) => l.from)
651
+ .sort();
652
+ const PINNED = [
653
+ "chronic_health_status",
654
+ "disability_subtypes",
655
+ "federal_protection_applications",
656
+ "hiv_status",
657
+ "immigration_status",
658
+ "le_report_status",
659
+ "mental_health_status",
660
+ "substance_use_status",
661
+ "tvap_enrollment",
662
+ "uscis_alien_number",
663
+ ];
664
+ expect(computed).toEqual(PINNED);
665
+ expect(table.filter((l) => l.widens).map((l) => l.from).sort()).toEqual(PINNED);
666
+ expect(
667
+ Object.entries(scope._supersedes.notes)
668
+ .filter(([, v]) => v.includes("reads WIDER"))
669
+ .map(([k]) => k)
670
+ .sort(),
671
+ ).toEqual(PINNED);
672
+ // Only identity and row lines can widen.
673
+ expect(table.filter((l) => l.widens && l.rule !== "identity" && l.rule !== "row")).toEqual([]);
674
+ // RULED 2026-10-09 (Crysta; canon SIGNED-GRAIN): the nine merge folds are
675
+ // retained for a signed release / share; the widening IDENTITY line canon
676
+ // leaves unmarked reads as its successor (itself) for every subject, with
677
+ // a stated reason; every widening line is a policy's successor.
678
+ const identityWidening = table.filter((l) => l.widens && l.rule === "identity").map((l) => l.from);
679
+ expect(identityWidening).toEqual(["immigration_status"]);
680
+ expect(table.filter((l) => l.releaseReading === "retain").map((l) => l.from).sort()).toEqual(
681
+ PINNED.filter((k) => !identityWidening.includes(k)),
682
+ );
683
+ for (const l of table.filter((x) => x.releaseReading === "successor")) {
684
+ expect(identityWidening, l.from).toContain(l.from);
685
+ expect(l.releaseReadingNote, l.from).toMatch(/followed canon/);
686
+ }
687
+ expect(table.filter((l) => l.widens).every((l) => l.releaseReading !== undefined)).toBe(true);
688
+ expect(table.filter((l) => !l.widens).every((l) => l.releaseReading === undefined)).toBe(true);
689
+ expect(table.filter((l) => l.policyReading === "successor").map((l) => l.from).sort()).toEqual(PINNED);
690
+ for (const k of PINNED) {
691
+ expect(scope._supersedes.notes[k], k).toContain("RULED 2026-10-09");
692
+ expect(scope._supersedes.notes[k], k).not.toMatch(/OPEN, owner Crysta/);
693
+ }
694
+ });
695
+
696
+ it("carries the v3 field membership each retained unit keeps (canon placements, never hand-typed)", () => {
697
+ const retained = table.filter((l) => l.releaseReading === "retain");
698
+ // The units carrying membership are exactly the retained lines' sources.
699
+ expect(sortedKeys(rows.filter((e) => e.v3Fields !== undefined))).toEqual(
700
+ retained.map((l) => l.from).sort(),
701
+ );
702
+ const EXPECTED: Record<string, string[]> = {
703
+ mental_health_status: ["capture.mental_health_status"],
704
+ substance_use_status: ["capture.substance_use_status"],
705
+ chronic_health_status: ["capture.chronic_health_severity", "capture.long_term_conditions"],
706
+ disability_subtypes: ["capture.has_disability"],
707
+ hiv_status: ["capture.hiv_status"],
708
+ federal_protection_applications: ["capture.legal_action_type"],
709
+ le_report_status: ["capture.le_report_status"],
710
+ uscis_alien_number: [],
711
+ tvap_enrollment: [],
712
+ };
713
+ for (const l of retained) {
714
+ const e = byKey.get(l.from);
715
+ expect(e?.v3Fields, l.from).toEqual(EXPECTED[l.from]);
716
+ expect(l.to, l.from).toHaveLength(1);
717
+ // v3Domains are the category-grain families of those fields.
718
+ const family = byKey.get(l.from)?.parentKey === "health_accommodation"
719
+ ? "access_accommodations"
720
+ : "immigration_legal_status";
721
+ expect(e?.v3Domains, l.from).toEqual(e?.v3Fields?.length ? [family] : []);
722
+ if (e?.v3Fields?.length === 0) expect(e.v3FieldsNote, l.from).toMatch(/RETAINS NOTHING/);
723
+ }
724
+ // The identity line follows canon (no retain), both facts on its line.
725
+ expect(liveKey("immigration_status")?.v3Fields).toBeUndefined();
726
+ const imm = table.find((l) => l.from === "immigration_status");
727
+ expect(imm?.releaseReadingNote).toContain("v3 control of `capture.immigration_status`");
728
+ expect(imm?.releaseReadingNote).toContain("`replacesV3`");
729
+ expect(scope.migrations.ruling.membership).toContain(
730
+ "INFOSCOPE_FIELD_PLACEMENTS_V4_2026-10-08.csv (`home_unit_today`) @ 00179edc",
731
+ );
732
+ expect(scope._source).toContain("INFOSCOPE_FIELD_PLACEMENTS_V4_2026-10-08.csv");
733
+ });
734
+
735
+ it("marks exactly the retired-before-v4 lines informational (ruling 2), readings unchanged", () => {
736
+ const info = table.filter((l) => l.informational === true);
737
+ expect(info).toHaveLength(17);
738
+ expect(info).toEqual(table.filter((l) => l.rule === "retired before v4"));
739
+ const odd = table.filter((l) => l.informational !== undefined && l.informational !== true);
740
+ expect(odd).toEqual([]);
741
+ });
742
+
743
+ it("records Crysta's ruling verbatim, with what is still pending in canon", () => {
744
+ const r = scope.migrations.ruling;
745
+ expect([r.date, r.by]).toEqual(["2026-10-09", "Crysta"]);
746
+ expect(r.source).toContain("https://htilabs-us.slack.com/archives/D0811D2R6QN/p1791581735053759");
747
+ expect(r.text).toHaveLength(2);
748
+ expect(r.text[0]).toContain("a SIGNED RELEASE keeps the grain it was signed at.");
749
+ expect(r.text[0]).toContain(
750
+ "Policies and presets (agency-authored, not consent) take the merged successor with a dated " +
751
+ "version row.",
752
+ );
753
+ expect(r.text[1]).toContain("The retired_v3 rows are informational");
754
+ expect(r.canon).toMatch(/^Absorbed from canon at [0-9a-f]{8} \(SIGNED-GRAIN, 2026-10-09\)/);
755
+ expect(scope._source).toMatch(/v4\.draft\.yaml @ e86dd89c /);
756
+ expect(scope._status).toContain("RULED 2026-10-09");
757
+ });
758
+
759
+ it("sends a v2-era or unstamped list through canon's pinned v2 -> v3 table first", () => {
760
+ const cite = "data/cvcs/core_information_scope.yaml L539-565 @ 00179edc";
761
+ expect(scope.migrations.unstamped).toContain(cite);
762
+ expect(scope.migrations.readAt).toContain(cite);
763
+ for (const t of tombstones.filter((x) => x.migrationRule === "retired before v4")) {
764
+ if ((t.successors ?? []).length > 0) expect(t.definition, t.key).toContain(cite);
765
+ }
766
+ expect(scope._supersedes.notes["risk"]).toContain(cite);
767
+ });
768
+
769
+ it("pins _source to the last canon commit, never to the ref it was read from", () => {
770
+ expect(scope._source).not.toMatch(/read from/);
771
+ expect(scope._source).toMatch(/v4\.draft\.yaml @ [0-9a-f]{8} /);
772
+ });
773
+ });
774
+
775
+ // ═══════════════════════════════════════════════════════════════════════════
776
+ describe("core_information_scope v4 — which rows apply to which app (handoff § 4)", () => {
777
+ it("makes LEADS the only app on the LEADS categories and on Derived risk signals", () => {
778
+ const leadsOnly = live.filter(
779
+ (e) => e.apps?.leads === true && e.apps.pave === false && e.apps.thread === false,
780
+ );
781
+ expect(sortedKeys(leadsOnly)).toEqual(
782
+ [
783
+ "derived_risk_signals",
784
+ "network_associations",
785
+ "network_membership",
786
+ "persona_links",
787
+ "commercial_activity",
788
+ "ad_content",
789
+ "commercial_patterns",
790
+ "investigative_work_product",
791
+ "case_determinations",
792
+ "case_lifecycle",
793
+ "case_attachments",
794
+ "object_identifiers",
795
+ "object_identity_attributes",
796
+ "phone_identifiers",
797
+ ].sort(),
798
+ );
799
+ });
800
+
801
+ it("marks Thread n/a on the client's Immigration & legal status", () => {
802
+ for (const k of ["immigration_legal_status", "immigration_status", "immigration_applications"]) {
803
+ expect(liveKey(k)?.apps?.thread, k).toBe(false);
804
+ }
805
+ });
806
+ });
807
+
808
+ // ═══════════════════════════════════════════════════════════════════════════
809
+ describe("core_information_scope — adoption from roi_scope", () => {
810
+ const roiSubstantive = roi.entries.map((e) => e.key).filter((k) => !MISSINGNESS.has(k));
811
+
812
+ it("resolves every substantive roi_scope key, spelled identically", () => {
813
+ const keys = new Set(rows.map((u) => u.key));
814
+ expect(roiSubstantive.filter((k) => !keys.has(k))).toEqual([]);
815
+ expect(roiSubstantive.length).toBe(27);
816
+ });
817
+
818
+ it("gives ONE answer to 'is this offerable' across both vocabularies (co-bwc)", () => {
819
+ const disagreements = roi.entries
820
+ .filter((e) => {
821
+ const twin = byKey.get(e.key);
822
+ return (
823
+ twin === undefined ||
824
+ twin.selectable !== e.selectable ||
825
+ (twin.retired === true) !== (e.retired === true)
826
+ );
827
+ })
828
+ .map((e) => e.key);
829
+ expect(disagreements).toEqual([]);
830
+
831
+ // Every CVC-236 tombstone whose key roi_scope carries is a roi_scope
832
+ // tombstone too (a CVC-236-only retirement is not a divergence).
833
+ const roiKeys = new Set(roi.entries.map((e) => e.key));
834
+ const roiTombstones = roi.entries.filter((e) => e.retired === true);
835
+ expect(sortedKeys(roiTombstones)).toEqual(
836
+ sortedKeys(tombstones.filter((t) => roiKeys.has(t.key))),
837
+ );
838
+ expect(roiTombstones).toHaveLength(13);
839
+ // Codes are never withdrawn or reused.
840
+ expect(roiTombstones.map((e) => e.code).sort()).toEqual(
841
+ [8, 9, 12, 14, 18, 19, 20, 21, 22, 24, 25, 26, 27].map(
842
+ (n) => `983-${seg(n)}-000-000-000-000-000`,
843
+ ),
844
+ );
463
845
  });
846
+ });
464
847
 
465
- it("APPENDS session_summary at 236-005-004 — never at a retired slot", () => {
466
- const u = rawByKey.get("session_summary");
467
- expect(u?.code).toBe("236-005-004-000-000-000-000");
468
- expect(u?.title).toBe("Session summary");
848
+ // ═══════════════════════════════════════════════════════════════════════════
849
+ describe("core_information_scope — carried-over rulings", () => {
850
+ it("priorities_safety (2026-09-29, R1): one selectable Contact & safety row, shareable, no floor", () => {
851
+ const u = liveKey("priorities_safety");
852
+ expect(u?.code).toBe("236-003-003-000-000-000-000");
469
853
  expect(u?.selectable).toBe(true);
470
- expect(u?.parentCode).toBe(notes?.code);
854
+ expect(u?.parentCode).toBe(byKey.get("contact")?.code);
471
855
  expect(u?.shareableDefault).toBe(true);
472
- expect(u?.levelFloor).toBe(3);
473
- expect(u?.specialDataType).toBe("survivor_confidential");
474
- expect(u?.appRelevance).toEqual(["PAVE", "Thread"]);
856
+ expect(u?.platformFloor).toBe(false);
857
+ expect(u?.apps).toEqual({ pave: true, thread: true, leads: false });
475
858
  });
476
859
 
477
- it("lists the category's children in code order, tombstones included, two of them live", () => {
860
+ it("encounter_location (2026-10-01, R2): appended after priorities_safety, shareable, no floor", () => {
861
+ const u = liveKey("encounter_location");
862
+ expect(u?.code).toBe("236-003-004-000-000-000-000");
863
+ expect(byKey.get("contact")?.childCodes).toEqual([
864
+ "236-003-001-000-000-000-000",
865
+ "236-003-002-000-000-000-000",
866
+ "236-003-003-000-000-000-000",
867
+ "236-003-004-000-000-000-000",
868
+ ]);
869
+ expect(u?.shareableDefault).toBe(true);
870
+ expect(u?.platformFloor).toBe(false);
871
+ expect(liveKey("addresses")?.code).toBe("236-001-003-000-000-000-000");
872
+ });
873
+
874
+ it("safe_locations (ratified 2026-09-08): code, label and floor posture kept; canon, not provisional", () => {
875
+ const u = liveKey("safe_locations");
876
+ expect(u?.code).toBe("236-003-002-000-000-000-000");
877
+ expect(u?.title).toBe("Safe & confidential locations");
878
+ expect(u?.platformFloor).toBe(true);
879
+ expect(u?.shareableDefault).toBe(false);
880
+ expect(u?.definition).not.toMatch(/PROVISIONAL/);
881
+ expect(scope._status).toContain("`safe_locations` is CANON");
882
+ });
883
+
884
+ it("narrative notes (2026-10-05): two live rows, both retired rows kept as tombstones", () => {
885
+ const notes = byKey.get("notes");
886
+ expect(notes?.parentCode).toBeNull();
478
887
  expect(notes?.childCodes).toEqual([
479
888
  "236-005-001-000-000-000-000",
480
889
  "236-005-002-000-000-000-000",
@@ -483,136 +892,106 @@ describe("core_information_scope — narrative notes (2026-10-05)", () => {
483
892
  ]);
484
893
  const liveKids = (notes?.childCodes ?? [])
485
894
  .map((c) => byCode.get(c))
486
- .filter((e) => e?.selectable === true)
895
+ .filter((e) => e?.selectable)
487
896
  .map((e) => e?.key);
488
897
  expect(liveKids).toEqual(["case_notes", "session_summary"]);
898
+ expect(byKey.get("screen_notes")?.title).toBe("Screen notes");
899
+ expect(byKey.get("background")?.title).toBe("Background information");
489
900
  });
490
901
 
491
- it("tombstones only what canon retired — no other unit in the domain is retired", () => {
492
- expect(tombstones.map((t) => t.key).sort()).toEqual(["background", "screen_notes"]);
902
+ it("Thread on System involvement (2026-10-01); the offender's record now rides its person type", () => {
903
+ expect(liveKey("system_involvement")?.apps?.thread).toBe(true);
904
+ expect(byKey.get("offender_facilitator")?.retired).toBe(true);
905
+ expect(liveKey("offenders")?.rowType).toBe("person_type");
493
906
  });
494
907
  });
495
908
 
496
- /**
497
- * OFFENDER-SYSTEM-UNITS-THREAD — canon CVC-236 amendment 2026-10-01 (Crysta
498
- * R1; prototype `data/cvcs/core_information_scope.yaml` @ 0247b654, carried
499
- * by the 9ef79748 regeneration at lines 407-410). Thread captures perpetrator
500
- * records and protection orders, so both risk units now list Thread. Codes
501
- * and posture are unchanged; only app relevance and wording moved.
502
- */
503
- describe("core_information_scope — Thread joins offender + system units (2026-10-01)", () => {
504
- it("lists Thread on offender_facilitator and system_involvement, codes unchanged", () => {
505
- const off = byKey.get("offender_facilitator");
506
- const sys = byKey.get("system_involvement");
507
- expect(off?.code).toBe("236-002-015-000-000-000-000");
508
- expect(off?.appRelevance).toEqual(["PAVE", "Thread", "LEADS"]);
509
- expect(sys?.code).toBe("236-002-016-000-000-000-000");
510
- expect(sys?.appRelevance).toEqual(["PAVE", "Thread"]);
511
- });
512
- });
909
+ // ═══════════════════════════════════════════════════════════════════════════
910
+ describe("core_information_scope — v2.1.0 (amends 2.0.0) supersedes v1.1.0", () => {
911
+ const sup = scope._supersedes;
513
912
 
514
- /**
515
- * SOT v1.1.0 supersedes v1.0.0 (ADR-CVC-0.8.13 Addendum 2026-10-05): the
516
- * narrative-notes change is not additive — two published units lost
517
- * `selectable` and `case_notes` was narrowed — so it cannot reuse 1.0.0
518
- * under the seeder's §9.1.2 content-drift guard. `_supersedes` is the house
519
- * shape (victimAbuseTypes / incidentParticipationRoles v1.1.0).
520
- */
521
- describe("core_information_scope — v1.1.0 supersedes v1.0.0", () => {
522
- const env = JSON.parse(
523
- readFileSync(path.join(cvcDir, "coreInformationScope.v1.1.0.json"), "utf8"),
524
- ) as {
525
- version: string;
526
- _supersedes: {
527
- version: string;
528
- keyMap: Record<string, string>;
529
- retiredCodes: unknown[];
530
- notes: Record<string, string>;
531
- };
532
- entries: Entry[];
533
- };
534
- const sup = env._supersedes;
535
-
536
- it("is version 1.1.0, superseding 1.0.0, with no code withdrawn", () => {
537
- expect(env.version).toBe("1.1.0");
538
- expect(sup.version).toBe("1.0.0");
539
- // Tombstones keep their codes, so nothing is withdrawn.
913
+ it("is version 2.1.0, superseding 1.1.0, with no code withdrawn", () => {
914
+ expect(scope.version).toBe("2.1.0");
915
+ expect(scope._status).toContain("VERSION 2.1.0 amends 2.0.0 (MINOR, additive");
916
+ expect(sup.version).toBe("1.1.0");
540
917
  expect(sup.retiredCodes).toEqual([]);
541
918
  });
542
919
 
543
- it("maps every v1.0.0 key to itself — every key but the one added", () => {
544
- const keys = env.entries.map((e) => e.key);
545
- expect(Object.keys(sup.keyMap)).toEqual(keys.filter((k) => k !== "session_summary"));
546
- expect(Object.keys(sup.keyMap)).toHaveLength(72);
920
+ it("maps every v1.1.0 key to itself", () => {
921
+ expect(Object.keys(sup.keyMap).sort()).toEqual([...V1_1_0_KEYS].sort());
547
922
  for (const [from, to] of Object.entries(sup.keyMap)) expect(to, from).toBe(from);
548
923
  });
549
924
 
550
- it("notes each retirement and the case_notes narrowing", () => {
551
- expect(Object.keys(sup.notes).sort()).toEqual([
552
- "background",
553
- "case_notes",
554
- "screen_notes",
555
- "summary",
556
- ]);
557
- for (const k of ["screen_notes", "background"]) {
558
- expect(sup.notes[k], k).toContain("NO successor key");
559
- expect(sup.notes[k], k).toContain("includes nothing");
560
- }
561
- expect(sup.notes["case_notes"]).toContain("reads NARROWER");
562
- expect(sup.notes["case_notes"]).toContain("no longer includes the session summary");
563
- expect(sup.notes["summary"]).toContain("`session_summary` (236-005-004)");
925
+ it("notes each new retirement, the two category narrowings and the identity widening", () => {
926
+ const newlyRetired = sortedKeys(
927
+ tombstones.filter((t) => t.key !== "screen_notes" && t.key !== "background"),
928
+ );
929
+ expect(Object.keys(sup.notes).sort()).toEqual(
930
+ [...newlyRetired, "identifying", "immigration_status", "risk", "summary"].sort(),
931
+ );
932
+ expect(sup.notes["risk"]).toContain("reads NARROWER");
933
+ expect(sup.notes["identifying"]).toContain("reads NARROWER");
934
+ expect(sup.notes["hiv_status"]).toContain("reads WIDER");
564
935
  });
565
936
 
566
- it("leaves no v1.0.0 file behind for the registry to resolve", () => {
567
- expect(() => readFileSync(path.join(cvcDir, "coreInformationScope.v1.0.0.json"))).toThrow();
937
+ it("leaves no superseded file behind for the registry to resolve", () => {
938
+ for (const v of ["1.0.0", "1.1.0", "2.0.0"]) {
939
+ expect(() => readFileSync(path.join(cvcDir, `coreInformationScope.v${v}.json`))).toThrow();
940
+ }
568
941
  });
569
942
  });
570
943
 
571
- /**
572
- * roi_scope v1.2.0 supersedes v1.1.0 (co-bwc; ADR-CVC-0.8.13 Addendum
573
- * 2026-10-05): tombstoning screen_notes / background to match CVC-236 v1.1.0
574
- * takes `selectable` away from two published items, which is not additive.
575
- * The superseded file was named `roiScope.v1.0.0.json` but declared 1.1.0;
576
- * the declared version is the one superseded.
577
- */
578
- describe("roi_scope — v1.2.0 supersedes v1.1.0", () => {
579
- const env = JSON.parse(
580
- readFileSync(path.join(cvcDir, "roiScope.v1.2.0.json"), "utf8"),
581
- ) as {
582
- version: string;
583
- _supersedes: {
584
- version: string;
585
- keyMap: Record<string, string>;
586
- retiredCodes: unknown[];
587
- notes: Record<string, string>;
588
- };
589
- entries: Entry[];
590
- };
591
- const sup = env._supersedes;
944
+ describe("roi_scope — v1.4.0 (amends 1.3.0) supersedes v1.2.0", () => {
945
+ const sup = roi._supersedes;
592
946
 
593
- it("is version 1.2.0, superseding 1.1.0, with no code withdrawn", () => {
594
- expect(env.version).toBe("1.2.0");
595
- expect(sup.version).toBe("1.1.0");
947
+ it("is version 1.4.0, superseding 1.2.0, identity keyMap, nothing withdrawn", () => {
948
+ expect(roi.version).toBe("1.4.0");
949
+ expect(roi._status).toContain("VERSION 1.4.0 amends 1.3.0 (MINOR: readings only");
950
+ expect(sup.version).toBe("1.2.0");
596
951
  expect(sup.retiredCodes).toEqual([]);
597
- });
598
-
599
- it("maps every v1.1.0 key to itself — nothing added, nothing renamed", () => {
600
- expect(Object.keys(sup.keyMap)).toEqual(env.entries.map((e) => e.key));
952
+ expect(Object.keys(sup.keyMap)).toEqual(roi.entries.map((e) => e.key));
601
953
  expect(Object.keys(sup.keyMap)).toHaveLength(31);
602
954
  for (const [from, to] of Object.entries(sup.keyMap)) expect(to, from).toBe(from);
603
955
  });
604
956
 
605
- it("notes each retirement, citing the CVC-236 twin", () => {
606
- expect(Object.keys(sup.notes).sort()).toEqual(["background", "screen_notes", "summary"]);
607
- for (const k of ["screen_notes", "background"]) {
608
- expect(sup.notes[k], k).toContain("NO successor key");
609
- expect(sup.notes[k], k).toContain("includes nothing");
610
- expect(sup.notes[k], k).toContain("CVC-236 v1.1.0 retired the same key");
957
+ it("notes each new retirement with its CVC-236 twin's reading (release grain for a signed ROI)", () => {
958
+ const newly = roi.entries
959
+ .filter((e) => e.retired === true && !["screen_notes", "background"].includes(e.key))
960
+ .map((e) => e.key);
961
+ expect(newly).toHaveLength(11);
962
+ expect(Object.keys(sup.notes).sort()).toEqual([...newly, "summary"].sort());
963
+ for (const k of newly) {
964
+ const twin = byKey.get(k);
965
+ for (const s of twin?.successors ?? []) expect(sup.notes[k], k).toContain(`\`${s}\``);
966
+ expect(sup.notes[k], k).toContain("CVC-236 retired the same key");
967
+ expect(sup.notes[k], k).toContain("unstamped and v2-era");
968
+ const def = roi.entries.find((e) => e.key === k)?.definition ?? "";
969
+ const line = scope.migrations.table.find(
970
+ (l) => l.from === k && l.rule !== "subtract" && l.rule !== "identity",
971
+ );
972
+ expect(def, k).toContain(`CVC-236 v${scope.version}'s \`migrations\``);
973
+ expect(def, k).not.toMatch(/v2\.0\.0/);
974
+ if (line?.releaseReading === "retain") {
975
+ // A stored ROI is a SIGNED RELEASE: it keeps the twin's v3 grain.
976
+ for (const text of [def, sup.notes[k]]) {
977
+ expect(text, k).toContain("An ROI is a SIGNED RELEASE");
978
+ expect(text, k).toContain("a policy or preset naming the same code takes");
979
+ const fields = twin?.v3Fields ?? [];
980
+ if (fields.length === 0) expect(text, k).toContain("RETAINS NOTHING");
981
+ for (const f of fields) expect(text, k).toContain(`\`${f}\``);
982
+ }
983
+ } else {
984
+ expect(line?.informational, k).toBe(true);
985
+ expect(def, k).toContain("`informational`");
986
+ }
611
987
  }
988
+ expect(roi._source).toContain(`coreInformationScope.v${scope.version}.json`);
989
+ expect(roi._source).not.toMatch(/coreInformationScope\.v2\.0\.0/);
612
990
  });
613
991
 
614
- it("leaves no superseded file behind for the registry to resolve", () => {
615
- expect(() => readFileSync(path.join(cvcDir, "roiScope.v1.0.0.json"))).toThrow();
616
- expect(() => readFileSync(path.join(cvcDir, "roiScope.v1.1.0.json"))).toThrow();
992
+ it("leaves no superseded file behind", () => {
993
+ for (const v of ["1.0.0", "1.1.0", "1.2.0", "1.3.0"]) {
994
+ expect(() => readFileSync(path.join(cvcDir, `roiScope.v${v}.json`))).toThrow();
995
+ }
617
996
  });
618
997
  });