@htilabs/platform-common-models 0.19.0 → 0.20.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.
- package/dist/cvcs/index.cjs +4769 -643
- package/dist/cvcs/index.cjs.map +1 -1
- package/dist/cvcs/index.d.cts +5036 -606
- package/dist/cvcs/index.d.ts +5036 -606
- package/dist/cvcs/index.js +4769 -643
- package/dist/cvcs/index.js.map +1 -1
- package/dist/enums/index.cjs +74 -1
- package/dist/enums/index.cjs.map +1 -1
- package/dist/enums/index.d.cts +77 -4
- package/dist/enums/index.d.ts +77 -4
- package/dist/enums/index.js +74 -1
- package/dist/enums/index.js.map +1 -1
- package/dist/index.cjs +5199 -588
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5189 -588
- package/dist/index.js.map +1 -1
- package/dist/information-scope/index.cjs +440 -0
- package/dist/information-scope/index.cjs.map +1 -0
- package/dist/information-scope/index.d.cts +313 -0
- package/dist/information-scope/index.d.ts +313 -0
- package/dist/information-scope/index.js +404 -0
- package/dist/information-scope/index.js.map +1 -0
- package/dist/services/index.cjs +414 -2
- package/dist/services/index.cjs.map +1 -1
- package/dist/services/index.d.cts +1 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +403 -1
- package/dist/services/index.js.map +1 -1
- package/package.json +32 -26
- package/src/__tests__/__snapshots__/cvc-sot.snap +3 -3
- package/src/__tests__/core-information-scope-invariant.test.ts +709 -456
- package/src/__tests__/cvc-sot-snapshot.test.ts +16 -17
- package/src/__tests__/cvc-structural.test.ts +2 -2
- package/src/__tests__/location-type-routing-invariant.test.ts +25 -8
- package/src/cvcs/coreInformationScope.v2.0.0.json +5396 -0
- package/src/cvcs/index.ts +2 -2
- package/src/cvcs/roiScope.v1.3.0.json +360 -0
- package/src/generated/cvc-enums.ts +77 -4
- package/src/services/__tests__/fixtures/infoscope-v4/information_scope_v4.migrations.csv +106 -0
- package/src/services/__tests__/fixtures/infoscope-v4/information_scope_v4.rows.csv +117 -0
- package/src/services/__tests__/fixtures/infoscope-v4/loadInfoscopeV4Fixtures.ts +116 -0
- package/src/services/__tests__/informationScopeResolver.test.ts +964 -0
- package/src/services/index.ts +10 -3
- package/src/services/informationScope.ts +10 -0
- package/src/services/informationScopeResolver.ts +672 -0
- package/src/services/informationScopeSot.ts +161 -0
- package/src/cvcs/coreInformationScope.v1.1.0.json +0 -1290
- package/src/cvcs/roiScope.v1.2.0.json +0 -340
|
@@ -0,0 +1,964 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CVC-236 v4 information-scope resolver.
|
|
3
|
+
*
|
|
4
|
+
* PRIMARY binding: the package SOT (`coreInformationScope.v2.0.0.json`, co-o73.1)
|
|
5
|
+
* through `scopeRowsFromSot` / `scopeMigrationsFromSot`. CROSS-CHECK: the canon's
|
|
6
|
+
* generated CSV pair (prototype @ 6dab8a95, byte-identical at 00179edc) must equal
|
|
7
|
+
* the adapter output row for row.
|
|
8
|
+
*
|
|
9
|
+
* Spec: INFOSCOPE_V4_DEV_HANDOFF_2026-10-09.md § 2 rules 1–7, § 3, § 7 row 6;
|
|
10
|
+
* scenarios from INFOSCOPE_PHASE4_STRESS_TEST_2026-10-09.md § 1 and the runner
|
|
11
|
+
* tools/infoscope/phase4_stress_test.py (the synthetic case: Jane, Dale, Mika,
|
|
12
|
+
* Maria, Tom; record homes from information_scope_v4.fields.csv); defaults from
|
|
13
|
+
* INFOSCOPE_PHASE3_NOTES_2026-10-08.md § 2 (D1, D5, D11).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, expect, it } from "vitest";
|
|
17
|
+
|
|
18
|
+
import { coreInformationScopeSot } from "../../cvcs/index.js";
|
|
19
|
+
import {
|
|
20
|
+
INFORMATION_SCOPE_SYSTEM_INFO as SYS,
|
|
21
|
+
INFORMATION_SCOPE_VERSION,
|
|
22
|
+
createInformationScopeResolver,
|
|
23
|
+
isScopeInstrumentRow,
|
|
24
|
+
isScopeRestRow,
|
|
25
|
+
isSelectableScopeRow,
|
|
26
|
+
kindForPerson,
|
|
27
|
+
type ScopeRow,
|
|
28
|
+
type ScopeSubjectKind,
|
|
29
|
+
} from "../informationScopeResolver.js";
|
|
30
|
+
import {
|
|
31
|
+
scopeMigrationsFromSot,
|
|
32
|
+
scopeRowsFromSot,
|
|
33
|
+
type CoreInformationScopeSot,
|
|
34
|
+
} from "../informationScopeSot.js";
|
|
35
|
+
import {
|
|
36
|
+
INFOSCOPE_V4_CANON_BLOBS,
|
|
37
|
+
INFOSCOPE_V4_CANON_SHA,
|
|
38
|
+
fixtureBodyBlobSha,
|
|
39
|
+
fixtureText,
|
|
40
|
+
loadCsvMigrations,
|
|
41
|
+
loadCsvRows,
|
|
42
|
+
type InfoscopeFixture,
|
|
43
|
+
} from "./fixtures/infoscope-v4/loadInfoscopeV4Fixtures.js";
|
|
44
|
+
|
|
45
|
+
const sot = coreInformationScopeSot as CoreInformationScopeSot & {
|
|
46
|
+
_supersedes: { version: string; keyMap: Record<string, string> };
|
|
47
|
+
};
|
|
48
|
+
const rows = scopeRowsFromSot(sot);
|
|
49
|
+
const migrations = scopeMigrationsFromSot(sot);
|
|
50
|
+
const scope = createInformationScopeResolver({ rows, migrations });
|
|
51
|
+
|
|
52
|
+
const codes = rows.map((r) => r.scopeCode);
|
|
53
|
+
const containers = codes.filter((c) => scope.childrenOf(c).length > 0);
|
|
54
|
+
const descendants = (code: string): string[] =>
|
|
55
|
+
scope.childrenOf(code).flatMap((c) => [c, ...descendants(c)]);
|
|
56
|
+
const chainHas = (code: string, pred: (c: string) => boolean): boolean =>
|
|
57
|
+
scope.ancestorsOf(code).some(pred);
|
|
58
|
+
const isFloor = (c: string): boolean => scope.row(c)?.platformFloor === true;
|
|
59
|
+
const isOff = (c: string): boolean => scope.row(c)?.shareableDefault === false;
|
|
60
|
+
const ENABLED_ALL = codes.filter((c) => isOff(c) && !isFloor(c));
|
|
61
|
+
const KINDS = ["offenders", "family", "others"] as const;
|
|
62
|
+
/** Order-insensitive list equality (output order follows the bound tree's row order). */
|
|
63
|
+
const same = (got: readonly string[], want: readonly string[]): void =>
|
|
64
|
+
expect([...got].sort()).toEqual([...want].sort());
|
|
65
|
+
|
|
66
|
+
// ─── The synthetic case (Phase 4 § 1; homes per fields.csv) ─────────────────
|
|
67
|
+
|
|
68
|
+
interface CaseRecord {
|
|
69
|
+
id: string;
|
|
70
|
+
subject: ScopeSubjectKind;
|
|
71
|
+
home: string;
|
|
72
|
+
}
|
|
73
|
+
const rec = (id: string, subject: ScopeSubjectKind, home: string): CaseRecord => ({
|
|
74
|
+
id,
|
|
75
|
+
subject,
|
|
76
|
+
home,
|
|
77
|
+
});
|
|
78
|
+
const CASE: CaseRecord[] = [
|
|
79
|
+
// Jane — the client
|
|
80
|
+
rec("jane.names", "client", "names"),
|
|
81
|
+
rec("jane.dob", "client", "dob"),
|
|
82
|
+
rec("jane.address", "client", "addresses"),
|
|
83
|
+
rec("jane.encounter", "client", "encounter_location"),
|
|
84
|
+
rec("jane.case_id", "client", "additional_ids"),
|
|
85
|
+
rec("jane.race", "client", "demographics"),
|
|
86
|
+
rec("jane.living_situation", "client", "identifying"),
|
|
87
|
+
rec("jane.vehicle", "client", "identifying"),
|
|
88
|
+
rec("jane.phone", "client", "contact_info"),
|
|
89
|
+
rec("jane.ec_designation_maria", "client", "contact_info"),
|
|
90
|
+
rec("jane.priorities", "client", "priorities_safety"),
|
|
91
|
+
rec("jane.accommodations", "client", "accommodation_needs"),
|
|
92
|
+
rec("jane.mental_health", "client", "health_status"),
|
|
93
|
+
rec("jane.hiv", "client", "health_status"),
|
|
94
|
+
rec("jane.pregnancy", "client", "health_status"),
|
|
95
|
+
rec("jane.immigration_status", "client", "immigration_status"),
|
|
96
|
+
rec("jane.t_visa_application", "client", "immigration_applications"),
|
|
97
|
+
rec("jane.indicator", "client", "screen_indicators"),
|
|
98
|
+
rec("jane.victimization", "client", "victimization"),
|
|
99
|
+
rec("jane.worker_subrole", "client", "victimization"),
|
|
100
|
+
rec("jane.protection_order", "client", "system_involvement"),
|
|
101
|
+
rec("jane.relationship_dale", "client", "relationships_household"),
|
|
102
|
+
rec("jane.household_roster", "client", "relationships_household"),
|
|
103
|
+
rec("jane.pet", "client", "relationships_household"),
|
|
104
|
+
rec("jane.contact_history", "client", "contact_history"),
|
|
105
|
+
rec("jane.services", "client", "service_history"),
|
|
106
|
+
rec("jane.service_plan", "client", "plans_goals"),
|
|
107
|
+
rec("jane.da_summary", "client", "summary_danger_assessment"),
|
|
108
|
+
rec("jane.da_full", "client", "full_danger_assessment"),
|
|
109
|
+
rec("jane.findings", "client", "summary_findings"),
|
|
110
|
+
rec("jane.case_note_pregnancy", "client", "case_notes"),
|
|
111
|
+
rec("jane.session_summary", "client", "session_summary"),
|
|
112
|
+
rec("jane.safe_location", "client", "safe_locations"),
|
|
113
|
+
// Dale — caused harm; lives with Jane
|
|
114
|
+
rec("dale.names", "offenders", "names"),
|
|
115
|
+
rec("dale.dob", "offenders", "dob"),
|
|
116
|
+
rec("dale.address", "offenders", "addresses"),
|
|
117
|
+
rec("dale.phone", "offenders", "contact_info"),
|
|
118
|
+
rec("dale.description", "offenders", "identifying"),
|
|
119
|
+
rec("dale.truck", "offenders", "identifying"),
|
|
120
|
+
rec("dale.offender_status", "offenders", "offenders.risk"),
|
|
121
|
+
rec("dale.facilitator_role", "offenders", "offenders.risk"),
|
|
122
|
+
rec("dale.trafficking_role", "offenders", "victimization"),
|
|
123
|
+
rec("dale.tra_perpetrator_record", "offenders", "offenders.risk"),
|
|
124
|
+
rec("dale.tra_run", "offenders", "summary_tra"),
|
|
125
|
+
rec("dale.immigration_status", "offenders", "immigration_status"),
|
|
126
|
+
rec("dale.record_note", "offenders", "risk"),
|
|
127
|
+
// Mika — eligible family member
|
|
128
|
+
rec("mika.names", "family", "names"),
|
|
129
|
+
rec("mika.dob", "family", "dob"),
|
|
130
|
+
rec("mika.child_profile", "family", "family.identifying"),
|
|
131
|
+
rec("mika.school_phone", "family", "contact_info"),
|
|
132
|
+
rec("mika.health", "family", "health_status"),
|
|
133
|
+
// Maria — the sister (emergency contact); Tom — a witness
|
|
134
|
+
rec("maria.names", "others", "names"),
|
|
135
|
+
rec("maria.address", "others", "addresses"),
|
|
136
|
+
rec("maria.phone", "others", "contact_info"),
|
|
137
|
+
rec("tom.names", "others", "names"),
|
|
138
|
+
rec("tom.tra_cross_person", "others", "victimization"),
|
|
139
|
+
];
|
|
140
|
+
|
|
141
|
+
const deliver = (selection: readonly string[], enabled: readonly string[] = []): Set<string> =>
|
|
142
|
+
new Set(
|
|
143
|
+
CASE.filter((r) =>
|
|
144
|
+
scope.isIncludedOnShare(selection, scope.rowForSubject(r.home, r.subject), {
|
|
145
|
+
enabledOffByDefault: enabled,
|
|
146
|
+
}),
|
|
147
|
+
).map((r) => r.id),
|
|
148
|
+
);
|
|
149
|
+
const ids = (pred: (r: CaseRecord) => boolean): string[] => CASE.filter(pred).map((r) => r.id);
|
|
150
|
+
|
|
151
|
+
// ─── Binding: SOT primary, CSV cross-check ──────────────────────────────────
|
|
152
|
+
|
|
153
|
+
describe("binding — the SOT through the adapters; the canon CSV pair as cross-check", () => {
|
|
154
|
+
it("binds the live v4 tree: 115 rows, 28 instrument rows, one rest row, 12 rows per kind", () => {
|
|
155
|
+
expect(rows).toHaveLength(115);
|
|
156
|
+
expect(rows.filter(isScopeInstrumentRow)).toHaveLength(28);
|
|
157
|
+
expect(rows.filter(isScopeRestRow).map((r) => r.scopeCode)).toEqual(["identifying.other"]);
|
|
158
|
+
for (const kind of KINDS) expect(rows.filter((r) => r.kindBranch === kind)).toHaveLength(12);
|
|
159
|
+
expect(scope.version).toBe(4);
|
|
160
|
+
expect(INFORMATION_SCOPE_VERSION).toBe(4);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("selection codes are canon's dotted codes, never SOT keys or wire codes", () => {
|
|
164
|
+
expect(codes.some((c) => c.includes("__"))).toBe(false);
|
|
165
|
+
expect(codes.some((c) => /^\d{3}-/.test(c))).toBe(false);
|
|
166
|
+
expect(codes).toContain("offenders.risk");
|
|
167
|
+
for (const e of sot.entries) {
|
|
168
|
+
if (e.canonicalCode) expect(e.canonicalCode).toBe(e.key.replace(/__/g, "."));
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("leaves the 27 tombstones and the missingness group out of the tree", () => {
|
|
173
|
+
const left = sot.entries.filter((e) => !scope.row(e.canonicalCode ?? e.key));
|
|
174
|
+
expect(left.filter((e) => e.status === "retired")).toHaveLength(27);
|
|
175
|
+
same(
|
|
176
|
+
left.filter((e) => e.status !== "retired").map((e) => e.key),
|
|
177
|
+
["missingness_root", "unknown", "anonymous", "data_not_collected"],
|
|
178
|
+
);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it.each(Object.entries(INFOSCOPE_V4_CANON_BLOBS))(
|
|
182
|
+
"fixture %s is the canon blob verbatim (%s)",
|
|
183
|
+
(file, blob) => {
|
|
184
|
+
expect(fixtureText(file as InfoscopeFixture).split("\n")[0]).toContain(INFOSCOPE_V4_CANON_SHA);
|
|
185
|
+
expect(fixtureBodyBlobSha(file as InfoscopeFixture)).toBe(blob);
|
|
186
|
+
},
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
it("the adapter's rows equal the canon rows CSV, row for row", () => {
|
|
190
|
+
const csv = loadCsvRows();
|
|
191
|
+
expect(csv).toHaveLength(rows.length);
|
|
192
|
+
const csvBy = new Map(csv.map((r) => [r.scopeCode, r]));
|
|
193
|
+
for (const r of rows) expect(r, r.scopeCode).toEqual(csvBy.get(r.scopeCode));
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("the adapter's migration table equals the canon migrations CSV (one duplicate line aside)", () => {
|
|
197
|
+
const line = (m: { from: string; to: readonly string[]; rule: string }): string =>
|
|
198
|
+
`${m.from}|${m.rule}|${m.to.join(" ")}`;
|
|
199
|
+
const csv = loadCsvMigrations();
|
|
200
|
+
expect(csv).toHaveLength(104);
|
|
201
|
+
expect(migrations).toHaveLength(103);
|
|
202
|
+
same([...new Set(csv.map(line))], migrations.map(line));
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("binding the CSV pair directly gives the same resolver answers", () => {
|
|
206
|
+
const viaCsv = createInformationScopeResolver({
|
|
207
|
+
rows: loadCsvRows(),
|
|
208
|
+
migrations: loadCsvMigrations(),
|
|
209
|
+
});
|
|
210
|
+
const all = [SYS, "primary_client"];
|
|
211
|
+
for (const c of codes) {
|
|
212
|
+
for (const kind of KINDS) {
|
|
213
|
+
expect(viaCsv.rowForSubject(c, kind)).toBe(scope.rowForSubject(c, kind));
|
|
214
|
+
}
|
|
215
|
+
expect(viaCsv.isCovered(all, c)).toBe(scope.isCovered(all, c));
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("a live SOT entry missing a field the resolver needs fails closed (throws)", () => {
|
|
220
|
+
const broken = {
|
|
221
|
+
...sot,
|
|
222
|
+
entries: sot.entries.map((e) => (e.key === "names" ? { ...e, apps: undefined } : e)),
|
|
223
|
+
};
|
|
224
|
+
expect(() => scopeRowsFromSot(broken)).toThrow(/"names" has apps/);
|
|
225
|
+
const noSdt = {
|
|
226
|
+
...sot,
|
|
227
|
+
entries: sot.entries.map((e) => (e.key === "dob" ? { ...e, specialDataType: undefined } : e)),
|
|
228
|
+
};
|
|
229
|
+
expect(() => scopeRowsFromSot(noSdt)).toThrow(/"dob" has specialDataType/);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
// ─── Rule 2: coverage ───────────────────────────────────────────────────────
|
|
234
|
+
|
|
235
|
+
describe("rule 2 — a row is covered when it or any ancestor is in the flat list", () => {
|
|
236
|
+
it.each([
|
|
237
|
+
[["primary_client"], "names", true],
|
|
238
|
+
[["primary_client"], "full_lap", true],
|
|
239
|
+
[["primary_client"], "offenders.identifying", false],
|
|
240
|
+
[["offenders"], "offenders.instrument_full", true],
|
|
241
|
+
[["offenders"], "names", false],
|
|
242
|
+
[["other_named_persons"], "family.contact", true],
|
|
243
|
+
[["identifying"], "dob", true],
|
|
244
|
+
[["names"], "identifying", false],
|
|
245
|
+
[["instrument_summary"], "summary_lap", true],
|
|
246
|
+
[["instrument_summary"], "full_lap", false],
|
|
247
|
+
[["risk"], "offenders.risk", false],
|
|
248
|
+
[[], "names", false],
|
|
249
|
+
[["primary_client"], "not_a_code", false],
|
|
250
|
+
] as const)("%j covers %s → %s", (selection, code, expected) => {
|
|
251
|
+
expect(scope.isCovered(selection, code)).toBe(expected);
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
describe("System metadata is always covered (handoff § 1: always included, never a choice)", () => {
|
|
256
|
+
it.each([SYS, "system"])("%s is covered by every selection, even an empty or null one", (code) => {
|
|
257
|
+
expect(scope.isCovered([], code)).toBe(true);
|
|
258
|
+
expect(scope.isCovered(null, code)).toBe(true);
|
|
259
|
+
expect(scope.isIncludedOnShare([], code)).toBe(true);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("a record homed on `system` (where fields.csv homes the 260 system fields) rides every share", () => {
|
|
263
|
+
for (const kind of ["client", ...KINDS] as const) {
|
|
264
|
+
expect(scope.rowForSubject("system", kind)).toBe("system");
|
|
265
|
+
}
|
|
266
|
+
expect(scope.isIncludedOnShare([SYS, "names"], "system")).toBe(true);
|
|
267
|
+
expect(scope.isCovered([], "notes")).toBe(false);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// ─── Rule 3: the category_rest row ──────────────────────────────────────────
|
|
272
|
+
|
|
273
|
+
describe("rule 3 — identifying.other keeps the category-grain facts", () => {
|
|
274
|
+
it("is not selectable, is covered with its category, and covers a record homed on the category", () => {
|
|
275
|
+
expect(isSelectableScopeRow(scope.row("identifying.other"))).toBe(false);
|
|
276
|
+
expect(isScopeRestRow(scope.row("identifying.other"))).toBe(true);
|
|
277
|
+
expect(scope.isCovered(["identifying"], "identifying.other")).toBe(true);
|
|
278
|
+
expect(scope.isCovered(["identifying.other"], "identifying")).toBe(true);
|
|
279
|
+
expect(scope.isCovered(["identifying.other"], "names")).toBe(false);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("is written when a picker expands the category, so un-ticking Demographics keeps living situation", () => {
|
|
283
|
+
same(scope.expandSelectAll("identifying"), [
|
|
284
|
+
"names",
|
|
285
|
+
"dob",
|
|
286
|
+
"addresses",
|
|
287
|
+
"additional_ids",
|
|
288
|
+
"demographics",
|
|
289
|
+
"identifying.other",
|
|
290
|
+
]);
|
|
291
|
+
const sel = scope.deselectChild([SYS, "identifying"], "demographics");
|
|
292
|
+
expect(sel).toContain("identifying.other");
|
|
293
|
+
expect(sel).not.toContain("demographics");
|
|
294
|
+
const got = deliver(sel);
|
|
295
|
+
expect(got.has("jane.living_situation")).toBe(true);
|
|
296
|
+
expect(got.has("jane.vehicle")).toBe(true);
|
|
297
|
+
expect(got.has("jane.race")).toBe(false);
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
// ─── Rules 4 + 5: off-by-default and the floor ─────────────────────────────
|
|
302
|
+
|
|
303
|
+
describe("rule 4 — off-by-default rows need enabling, not only selecting", () => {
|
|
304
|
+
it("select-all at every container never silently enables an off-by-default row or the floor", () => {
|
|
305
|
+
expect(containers.length).toBeGreaterThan(20);
|
|
306
|
+
for (const c of containers) {
|
|
307
|
+
for (const d of descendants(c)) {
|
|
308
|
+
const included = scope.isIncludedOnShare([SYS, c], d);
|
|
309
|
+
if (chainHas(d, isFloor) || chainHas(d, isOff)) expect(included, `${c} → ${d}`).toBe(false);
|
|
310
|
+
else expect(included, `${c} → ${d}`).toBe(true);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("every off-by-default row in the chain must be enabled (the reference runner's rule)", () => {
|
|
316
|
+
const sel = [SYS, "immigration_legal_status"];
|
|
317
|
+
expect(scope.shareVerdict(sel, "immigration_status")).toEqual({
|
|
318
|
+
included: false,
|
|
319
|
+
reason: "off_by_default",
|
|
320
|
+
notEnabled: ["immigration_status", "immigration_legal_status"],
|
|
321
|
+
});
|
|
322
|
+
const parentOnly = { enabledOffByDefault: ["immigration_legal_status"] };
|
|
323
|
+
expect(scope.isIncludedOnShare(sel, "immigration_status", parentOnly)).toBe(false);
|
|
324
|
+
const both = { enabledOffByDefault: ["immigration_legal_status", "immigration_status"] };
|
|
325
|
+
expect(scope.isIncludedOnShare(sel, "immigration_status", both)).toBe(true);
|
|
326
|
+
const fullOnly = { enabledOffByDefault: new Set(["instrument_full"]) };
|
|
327
|
+
expect(scope.isIncludedOnShare([SYS, "instruments"], "full_lap", fullOnly)).toBe(false);
|
|
328
|
+
const fullAndLap = { enabledOffByDefault: new Set(["instrument_full", "full_lap"]) };
|
|
329
|
+
expect(scope.isIncludedOnShare([SYS, "instruments"], "full_lap", fullAndLap)).toBe(true);
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
describe("rule 5 — the floor never leaves", () => {
|
|
334
|
+
const floors = codes.filter(isFloor);
|
|
335
|
+
it("there are four floor rows (the client's and each kind's safe locations)", () => {
|
|
336
|
+
same(floors, [
|
|
337
|
+
"safe_locations",
|
|
338
|
+
"offenders.safe_locations",
|
|
339
|
+
"family.safe_locations",
|
|
340
|
+
"others.safe_locations",
|
|
341
|
+
]);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it.each(floors)("%s is never included, even named outright with everything enabled", (code) => {
|
|
345
|
+
const v = scope.shareVerdict([SYS, code], code, { enabledOffByDefault: codes });
|
|
346
|
+
expect(v).toEqual({ included: false, reason: "platform_floor" });
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
// ─── Rule 6: select-all / de-select ─────────────────────────────────────────
|
|
351
|
+
|
|
352
|
+
describe("rule 6 — select-all at any level; de-select any child; the store stays flat", () => {
|
|
353
|
+
it.each([
|
|
354
|
+
["primary_client", "health_status"],
|
|
355
|
+
["primary_client", "contact"],
|
|
356
|
+
["primary_client", "demographics"],
|
|
357
|
+
["other_named_persons", "family"],
|
|
358
|
+
["offenders", "offenders.contact"],
|
|
359
|
+
["family", "family.immigration_legal_status"],
|
|
360
|
+
["instruments", "instrument_full"],
|
|
361
|
+
["risk", "system_involvement"],
|
|
362
|
+
["immigration_legal_status", "immigration_applications"],
|
|
363
|
+
["primary_client", "names"],
|
|
364
|
+
])("de-select %s › %s keeps the siblings and drops the child", (parent, child) => {
|
|
365
|
+
const sel = scope.deselectChild([SYS, parent], child);
|
|
366
|
+
expect(sel).toContain(SYS);
|
|
367
|
+
expect(new Set(sel).size).toBe(sel.length);
|
|
368
|
+
const childTree = new Set([child, ...descendants(child)]);
|
|
369
|
+
for (const d of descendants(parent)) {
|
|
370
|
+
if (childTree.has(d)) {
|
|
371
|
+
expect(scope.isCovered(sel, d), `${d} should be gone`).toBe(false);
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
// A container with no rest row holds no facts of its own once expanded.
|
|
375
|
+
const emptyContainer =
|
|
376
|
+
scope.childrenOf(d).length > 0 &&
|
|
377
|
+
!scope.childrenOf(d).some((c) => isScopeRestRow(scope.row(c)));
|
|
378
|
+
if (!emptyContainer) expect(scope.isCovered(sel, d), `${d} should stay`).toBe(true);
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("re-selecting the parent brings the child back (no exclusions in the store)", () => {
|
|
383
|
+
const sel = scope.deselectChild([SYS, "primary_client"], "demographics");
|
|
384
|
+
expect(scope.isCovered(sel, "demographics")).toBe(false);
|
|
385
|
+
const again = scope.selectAll(sel, "primary_client");
|
|
386
|
+
same(again, [SYS, "primary_client"]);
|
|
387
|
+
expect(scope.isCovered(again, "demographics")).toBe(true);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it("system_info is always present and System metadata cannot be de-selected", () => {
|
|
391
|
+
expect(scope.selectAll([], "names")).toContain(SYS);
|
|
392
|
+
expect(scope.deselectChild(["names"], "names")).toEqual([SYS]);
|
|
393
|
+
expect(() => scope.deselectChild([SYS], SYS)).toThrow(RangeError);
|
|
394
|
+
expect(() => scope.deselectChild([SYS, "system"], "system")).toThrow(RangeError);
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it("a picker never writes or de-selects a non-selectable or unknown row", () => {
|
|
398
|
+
expect(() => scope.selectAll([SYS], "full_lap")).toThrow(RangeError);
|
|
399
|
+
expect(() => scope.selectAll([SYS], "identifying.other")).toThrow(RangeError);
|
|
400
|
+
expect(() => scope.deselectChild([SYS, "instruments"], "summary_lap")).toThrow(RangeError);
|
|
401
|
+
expect(() => scope.deselectChild([SYS], "nope")).toThrow(RangeError);
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
it("does not mutate its input and keeps unknown stored codes", () => {
|
|
405
|
+
const input = Object.freeze([SYS, "primary_client", "legacy_code"]);
|
|
406
|
+
const out = scope.deselectChild(input, "contact");
|
|
407
|
+
expect(input).toEqual([SYS, "primary_client", "legacy_code"]);
|
|
408
|
+
expect(out[out.length - 1]).toBe("legacy_code");
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it("returns copies: callers cannot reach the resolver's internal arrays", () => {
|
|
412
|
+
scope.childrenOf("identifying").push("x");
|
|
413
|
+
scope.ancestorsOf("names").push("x");
|
|
414
|
+
expect(scope.childrenOf("identifying")).not.toContain("x");
|
|
415
|
+
expect(scope.ancestorsOf("names")).not.toContain("x");
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
describe("instrument rows — non-selectable, covered by their parents", () => {
|
|
420
|
+
const instrumentRows = rows.filter(isScopeInstrumentRow);
|
|
421
|
+
it.each(instrumentRows.map((r) => [r.scopeCode, r.parentScopeCode as string]))(
|
|
422
|
+
"%s is covered by %s and not selectable",
|
|
423
|
+
(code, parent) => {
|
|
424
|
+
expect(isSelectableScopeRow(scope.row(code))).toBe(false);
|
|
425
|
+
expect(scope.isCovered([parent], code)).toBe(true);
|
|
426
|
+
expect(scope.isCovered(["instruments"], code)).toBe(true);
|
|
427
|
+
},
|
|
428
|
+
);
|
|
429
|
+
it("the guards answer false for an unknown code", () => {
|
|
430
|
+
expect(isSelectableScopeRow(scope.row("nope"))).toBe(false);
|
|
431
|
+
expect(isScopeRestRow(undefined)).toBe(false);
|
|
432
|
+
expect(isScopeInstrumentRow(undefined)).toBe(false);
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
// ─── Rule 7: level_floor (the viewing side) ─────────────────────────────────
|
|
437
|
+
|
|
438
|
+
describe("rule 7 — level_floor is the viewing side; sharing ignores it", () => {
|
|
439
|
+
it.each([
|
|
440
|
+
[1, "names", true],
|
|
441
|
+
[1, "dob", true],
|
|
442
|
+
[1, SYS, true],
|
|
443
|
+
[1, "addresses", false],
|
|
444
|
+
[1, "offenders.identifying", false],
|
|
445
|
+
[1, "family.identifying", false],
|
|
446
|
+
[2, "names", true],
|
|
447
|
+
[2, "additional_ids", false],
|
|
448
|
+
[3, "addresses", true],
|
|
449
|
+
[3, "family.identifying", true],
|
|
450
|
+
[3, "not_a_code", false],
|
|
451
|
+
] as const)("level %i sees %s → %s", (level, code, expected) => {
|
|
452
|
+
expect(scope.isVisibleAtLevel(level, code)).toBe(expected);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it("the level-1 stub never carries another person's name", () => {
|
|
456
|
+
const stub = codes.filter((c) => scope.isVisibleAtLevel(1, c));
|
|
457
|
+
same(stub, ["system", SYS, "primary_client", "names", "dob"]);
|
|
458
|
+
expect(stub.includes(scope.rowForSubject("names", "offenders"))).toBe(false);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it("a floor-3 row is still an ordinary pick for sharing", () => {
|
|
462
|
+
expect(scope.isIncludedOnShare([SYS, "addresses"], "addresses")).toBe(true);
|
|
463
|
+
});
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
// ─── Rule 1: the branch is decided per record ──────────────────────────────
|
|
467
|
+
|
|
468
|
+
describe("rule 1 — rowForSubject: the deepest row the kind defines", () => {
|
|
469
|
+
it.each([
|
|
470
|
+
["names", "client", "names"],
|
|
471
|
+
["names", "family", "family.identifying"],
|
|
472
|
+
["identifying.other", "others", "others.identifying"],
|
|
473
|
+
["risk", "offenders", "offenders.risk"],
|
|
474
|
+
["victimization", "offenders", "offenders.risk"],
|
|
475
|
+
["health_status", "family", "family.health_accommodation"],
|
|
476
|
+
["immigration_status", "offenders", "offenders.immigration_legal_status"],
|
|
477
|
+
["safe_locations", "family", "family.safe_locations"],
|
|
478
|
+
["full_lap", "offenders", "offenders.instrument_full"],
|
|
479
|
+
["instrument_full", "others", "others.instrument_full"],
|
|
480
|
+
["summary_tra", "offenders", "offenders.instrument_summary"],
|
|
481
|
+
["relationships_household", "family", "family.relationships_household"],
|
|
482
|
+
["primary_client", "family", "family"],
|
|
483
|
+
["offenders.risk", "offenders", "offenders.risk"],
|
|
484
|
+
["offenders.risk", "family", "family"],
|
|
485
|
+
["family.identifying", "family", "family.identifying"],
|
|
486
|
+
["family.identifying", "client", "family.identifying"],
|
|
487
|
+
["case_notes", "offenders", "case_notes"],
|
|
488
|
+
["session_summary", "family", "session_summary"],
|
|
489
|
+
[SYS, "others", SYS],
|
|
490
|
+
["derived_risk_signals", "offenders", "derived_risk_signals"],
|
|
491
|
+
["network_membership", "others", "network_membership"],
|
|
492
|
+
["case_attachments", "family", "case_attachments"],
|
|
493
|
+
] as const)("%s about %s → %s", (home, kind, expected) => {
|
|
494
|
+
expect(scope.rowForSubject(home, kind)).toBe(expected);
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
it("every client-branch home resolves under each kind (the CI row stays home)", () => {
|
|
498
|
+
const client = codes.filter((c) => chainHas(c, (a) => a === "primary_client"));
|
|
499
|
+
for (const kind of KINDS) {
|
|
500
|
+
for (const home of client) {
|
|
501
|
+
const got = scope.rowForSubject(home, kind);
|
|
502
|
+
if (home === "derived_risk_signals") expect(got).toBe(home);
|
|
503
|
+
else expect(scope.ancestorsOf(got), `${home} → ${got}`).toContain(kind);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
it("the LEADS carve-out does not read `apps`: missing or lowercased apps change nothing", () => {
|
|
509
|
+
const variants: unknown[] = [undefined, ["leads"], ["LEADS"], {}];
|
|
510
|
+
for (const apps of variants) {
|
|
511
|
+
const bound = createInformationScopeResolver({
|
|
512
|
+
rows: rows.map((r) => ({ ...r, apps }) as unknown as ScopeRow),
|
|
513
|
+
migrations,
|
|
514
|
+
});
|
|
515
|
+
for (const kind of KINDS) {
|
|
516
|
+
expect(bound.rowForSubject("derived_risk_signals", kind)).toBe("derived_risk_signals");
|
|
517
|
+
expect(bound.rowForSubject("risk", kind)).toBe(`${kind}.risk`);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
it("a row with no specialDataType fails closed: the tree refuses to bind", () => {
|
|
523
|
+
const noSdt = rows.map((r) =>
|
|
524
|
+
r.scopeCode === "derived_risk_signals" ? { ...r, specialDataType: undefined } : r,
|
|
525
|
+
) as unknown as ScopeRow[];
|
|
526
|
+
expect(() => createInformationScopeResolver({ rows: noSdt })).toThrow(/specialDataType/);
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
it("an unknown home throws", () => {
|
|
530
|
+
expect(() => scope.rowForSubject("nope", "family")).toThrow(RangeError);
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
describe("kindForPerson (D5) — caused harm wins; EFM is asserted; neither → others", () => {
|
|
535
|
+
it.each([
|
|
536
|
+
[true, false, "offenders"],
|
|
537
|
+
[true, true, "offenders"],
|
|
538
|
+
[false, true, "family"],
|
|
539
|
+
[false, false, "others"],
|
|
540
|
+
] as const)("causedHarm=%s efmAsserted=%s → %s", (causedHarm, efmAsserted, expected) => {
|
|
541
|
+
expect(kindForPerson({ causedHarm, efmAsserted })).toBe(expected);
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
// ─── § 3: migrations, scopeVersion ─────────────────────────────────────────
|
|
546
|
+
|
|
547
|
+
describe("§ 3 — readSelection / readRestriction", () => {
|
|
548
|
+
it("identity: an unchanged code reads the same", () => {
|
|
549
|
+
const r = scope.readSelection([SYS, "names", "contact_info"], 3);
|
|
550
|
+
same(r.informationScope, [SYS, "names", "contact_info"]);
|
|
551
|
+
expect(r.codes.map((c) => c.rule)).toEqual(["identity", "identity", "identity"]);
|
|
552
|
+
expect(r.unsupportedVersion).toBe(false);
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
it("row: retired v3 rows read as their successors", () => {
|
|
556
|
+
const r = scope.readSelection(["hiv_status", "uscis_alien_number", "tvap_enrollment"], 3);
|
|
557
|
+
same(r.informationScope, [
|
|
558
|
+
SYS,
|
|
559
|
+
"health_status",
|
|
560
|
+
"immigration_status",
|
|
561
|
+
"immigration_applications",
|
|
562
|
+
]);
|
|
563
|
+
expect(r.retired).toEqual(["hiv_status", "uscis_alien_number", "tvap_enrollment"]);
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
it("row: offender_facilitator reads as offenders.identifying + offenders.risk, never the whole kind", () => {
|
|
567
|
+
const r = scope.readSelection([SYS, "offender_facilitator"], 3);
|
|
568
|
+
same(r.informationScope, [SYS, "offenders.identifying", "offenders.risk"]);
|
|
569
|
+
expect(scope.isCovered(r.informationScope, "offenders.contact")).toBe(false);
|
|
570
|
+
expect(scope.isCovered(r.informationScope, "offenders.health_accommodation")).toBe(false);
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
it("D11 category: risk → risk only; identifying → identifying only (never widened)", () => {
|
|
574
|
+
const risk = scope.readSelection([SYS, "risk"], 3);
|
|
575
|
+
same(risk.informationScope, [SYS, "risk"]);
|
|
576
|
+
expect(risk.codes[1].rule).toBe("category");
|
|
577
|
+
for (const kind of KINDS) {
|
|
578
|
+
expect(scope.isCovered(risk.informationScope, `${kind}.risk`)).toBe(false);
|
|
579
|
+
}
|
|
580
|
+
const ident = scope.readSelection([SYS, "identifying"], 3);
|
|
581
|
+
same(ident.informationScope, [SYS, "identifying"]);
|
|
582
|
+
for (const kind of KINDS) {
|
|
583
|
+
expect(scope.isCovered(ident.informationScope, `${kind}.identifying`)).toBe(false);
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
it("subtract: an offender_facilitator RESTRICTION restricts the whole offenders kind", () => {
|
|
588
|
+
const r = scope.readRestriction(["offender_facilitator"], 3);
|
|
589
|
+
expect(r.informationScope).toEqual(["offenders"]);
|
|
590
|
+
expect(r.codes[0].rule).toBe("subtract");
|
|
591
|
+
expect(r.retired).toEqual(["offender_facilitator"]);
|
|
592
|
+
for (const c of descendants("offenders")) {
|
|
593
|
+
expect(scope.isCovered(r.informationScope, c)).toBe(true);
|
|
594
|
+
}
|
|
595
|
+
// A restriction reading never names system_info unless it was stored.
|
|
596
|
+
expect(scope.readRestriction(["hiv_status"], 3).informationScope).toEqual(["health_status"]);
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
it("retired before v4: the pre-v3 instrument codes have a stated reading, some read as nothing", () => {
|
|
600
|
+
const r = scope.readSelection(["ida_full", "screen_notes", "background", "assessment_records"], 3);
|
|
601
|
+
same(r.informationScope, [SYS, "summary_ida", "full_ida"]);
|
|
602
|
+
expect(r.codes.map((c) => c.rule)).toEqual(Array(4).fill("retired before v4"));
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
it("a v4 list: live codes read as written; retired codes still read through the table (§ 3 (c))", () => {
|
|
606
|
+
const r = scope.readSelection(
|
|
607
|
+
[SYS, "offenders", "hiv_status", "offender_facilitator", "assessment_records", "nope"],
|
|
608
|
+
4,
|
|
609
|
+
);
|
|
610
|
+
expect(r.codes.map((c) => [c.from, c.rule])).toEqual([
|
|
611
|
+
[SYS, "identity"],
|
|
612
|
+
["offenders", "identity"],
|
|
613
|
+
["hiv_status", "row"],
|
|
614
|
+
["offender_facilitator", "row"],
|
|
615
|
+
["assessment_records", "retired before v4"],
|
|
616
|
+
["nope", "unknown"],
|
|
617
|
+
]);
|
|
618
|
+
same(r.informationScope, [
|
|
619
|
+
SYS,
|
|
620
|
+
"offenders",
|
|
621
|
+
"health_status",
|
|
622
|
+
"offenders.identifying",
|
|
623
|
+
"offenders.risk",
|
|
624
|
+
]);
|
|
625
|
+
expect(r.retired).toEqual(["hiv_status", "offender_facilitator", "assessment_records"]);
|
|
626
|
+
expect(r.unknown).toEqual(["nope"]);
|
|
627
|
+
const restriction = scope.readRestriction(["offender_facilitator"], 4);
|
|
628
|
+
expect(restriction.codes[0].rule).toBe("subtract");
|
|
629
|
+
expect(restriction.informationScope).toEqual(["offenders"]);
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
it("widening lines are surfaced, never hidden (SOT `widens: true`)", () => {
|
|
633
|
+
const r = scope.readSelection(["names", "hiv_status", "immigration_status"], 3);
|
|
634
|
+
expect(r.widened).toEqual(["hiv_status", "immigration_status"]);
|
|
635
|
+
expect(r.codes.map((c) => c.widens)).toEqual([false, true, true]);
|
|
636
|
+
expect(scope.readSelection(["immigration_status"], 4).widened).toEqual([]);
|
|
637
|
+
expect(migrations.filter((m) => m.widens).map((m) => m.from)).toHaveLength(10);
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
it("a v2-era or unstamped list fails closed: this package ships no v2 → v3 table", () => {
|
|
641
|
+
for (const version of [2, undefined]) {
|
|
642
|
+
const r = scope.readSelection(["ida_consid", "names"], version);
|
|
643
|
+
expect(r.unsupportedVersion).toBe(true);
|
|
644
|
+
expect(r.informationScope).toEqual([SYS]);
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
it("each tombstone's restrictionSuccessors equals its table reading as a restriction", () => {
|
|
649
|
+
const withRestriction = sot.entries.filter((e) => e.restrictionSuccessors !== undefined);
|
|
650
|
+
expect(withRestriction.map((e) => e.key)).toEqual(["offender_facilitator"]);
|
|
651
|
+
for (const e of withRestriction) {
|
|
652
|
+
same(
|
|
653
|
+
scope.readRestriction([e.key], 3).informationScope,
|
|
654
|
+
(e.restrictionSuccessors ?? []).map((k) => k.replace(/__/g, ".")),
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
it("a signed list is kept as signed — never mutated, never rewritten", () => {
|
|
660
|
+
const signed = Object.freeze(["names", "hiv_status", "names"]);
|
|
661
|
+
const r = scope.readSelection(signed, 3);
|
|
662
|
+
expect(signed).toEqual(["names", "hiv_status", "names"]);
|
|
663
|
+
expect(r.stored).toEqual(["names", "hiv_status", "names"]);
|
|
664
|
+
expect(r.storedVersion).toBe(3);
|
|
665
|
+
expect(r.version).toBe(4);
|
|
666
|
+
expect(r.codes).toHaveLength(2);
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
it.each([undefined, null, 0, 1, 2, 5, 3.5, Number.NaN, "3"])(
|
|
670
|
+
"reads are total: scopeVersion %j is unsupported, so every code includes nothing",
|
|
671
|
+
(version) => {
|
|
672
|
+
const r = scope.readSelection(["names", "hiv_status"], version as number);
|
|
673
|
+
expect(r.unsupportedVersion).toBe(true);
|
|
674
|
+
expect(r.codes.map((c) => c.rule)).toEqual(["unknown", "unknown"]);
|
|
675
|
+
expect(r.informationScope).toEqual([SYS]);
|
|
676
|
+
expect(r.unknown).toEqual(["names", "hiv_status"]);
|
|
677
|
+
expect(scope.readRestriction(["offender_facilitator"], version as number).informationScope).toEqual([]);
|
|
678
|
+
},
|
|
679
|
+
);
|
|
680
|
+
|
|
681
|
+
it("reads are total: a null or missing list reads as empty", () => {
|
|
682
|
+
for (const list of [null, undefined]) {
|
|
683
|
+
const r = scope.readSelection(list, 3);
|
|
684
|
+
expect(r.stored).toEqual([]);
|
|
685
|
+
expect(r.informationScope).toEqual([SYS]);
|
|
686
|
+
expect(scope.readRestriction(list, 4).informationScope).toEqual([]);
|
|
687
|
+
expect(scope.isCovered(list, "names")).toBe(false);
|
|
688
|
+
expect(scope.shareVerdict(list, "names")).toEqual({ included: false, reason: "not_covered" });
|
|
689
|
+
expect(scope.clampToCeiling(list, ["identifying"])).toEqual([SYS]);
|
|
690
|
+
expect(scope.expandBranchPickToGrain([SYS, "primary_client"], list)).toEqual(
|
|
691
|
+
expect.arrayContaining([SYS, "primary_client"]),
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
it("every v3-era key (the 73 keys of `_supersedes.keyMap`) reads to a live code or a retired reading", () => {
|
|
697
|
+
// The CVC missingness group has no row in the tree and no line in the table.
|
|
698
|
+
const missingness = new Set(["missingness_root", "unknown", "anonymous", "data_not_collected"]);
|
|
699
|
+
const keys = Object.keys(sot._supersedes.keyMap);
|
|
700
|
+
expect(keys).toHaveLength(73);
|
|
701
|
+
for (const key of keys) {
|
|
702
|
+
expect(scope.readSelection([key], 2).unsupportedVersion).toBe(true);
|
|
703
|
+
for (const version of [3]) {
|
|
704
|
+
const [reading] = scope.readSelection([key], version).codes;
|
|
705
|
+
if (missingness.has(key)) {
|
|
706
|
+
expect(reading.rule, key).toBe("unknown");
|
|
707
|
+
expect(reading.reads).toEqual([]);
|
|
708
|
+
continue;
|
|
709
|
+
}
|
|
710
|
+
expect(reading.rule, key).not.toBe("unknown");
|
|
711
|
+
for (const to of reading.reads) expect(scope.row(to)?.status, `${key} → ${to}`).not.toBe("retired");
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
});
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
// ─── § 7 row 6: branch-grain pick vs category-grain ceiling ────────────────
|
|
718
|
+
|
|
719
|
+
describe("§ 7 row 6 — expand a branch pick to the ceiling's grain before clamping", () => {
|
|
720
|
+
const ceiling = ["identifying", "contact", "risk", "services", "instrument_summary", "notes"];
|
|
721
|
+
const pick = [SYS, "primary_client", "notes", "offenders"];
|
|
722
|
+
|
|
723
|
+
it("expands primary_client down to the ceiling's grain", () => {
|
|
724
|
+
same(scope.expandBranchPickToGrain(pick, ceiling), [
|
|
725
|
+
SYS,
|
|
726
|
+
"notes",
|
|
727
|
+
"identifying",
|
|
728
|
+
"contact",
|
|
729
|
+
"health_accommodation",
|
|
730
|
+
"immigration_legal_status",
|
|
731
|
+
"risk",
|
|
732
|
+
"services",
|
|
733
|
+
"instrument_summary",
|
|
734
|
+
"instrument_full",
|
|
735
|
+
"relationships_household",
|
|
736
|
+
"offenders",
|
|
737
|
+
]);
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
it("clamps to the ceiling; a sender can never widen", () => {
|
|
741
|
+
const clamped = scope.clampToCeiling(pick, ceiling);
|
|
742
|
+
same(clamped, [SYS, "notes", "identifying", "contact", "risk", "services", "instrument_summary"]);
|
|
743
|
+
for (const c of codes) {
|
|
744
|
+
if (c === SYS || c === "system" || !scope.isCovered(clamped, c)) continue;
|
|
745
|
+
expect(scope.isCovered(pick, c), `${c} picked`).toBe(true);
|
|
746
|
+
expect(scope.isCovered(ceiling, c), `${c} within the ceiling`).toBe(true);
|
|
747
|
+
}
|
|
748
|
+
// A literal compare would have let the branch code past the ceiling.
|
|
749
|
+
expect(ceiling.includes("primary_client")).toBe(false);
|
|
750
|
+
expect(scope.isCovered(clamped, "health_status")).toBe(false);
|
|
751
|
+
expect(scope.isCovered(clamped, "offenders.identifying")).toBe(false);
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
it("a pick already inside the ceiling is kept as picked", () => {
|
|
755
|
+
same(scope.clampToCeiling([SYS, "names"], ["identifying"]), [SYS, "names"]);
|
|
756
|
+
same(scope.clampToCeiling([SYS, "identifying"], ["names", "dob"]), [SYS, "names", "dob"]);
|
|
757
|
+
});
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
// ─── Phase 4 § 1 — the seven scenarios ─────────────────────────────────────
|
|
761
|
+
|
|
762
|
+
describe("Phase 4 scenarios", () => {
|
|
763
|
+
it("S1 a minimal release (names + service referrals) delivers the name and the services only", () => {
|
|
764
|
+
same([...deliver([SYS, "names", "service_history"])], ["jane.names", "jane.services"]);
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
it("S2 the mandated-report packet: the client, the offender whole, the order; not the child", () => {
|
|
768
|
+
const MANDATED = [
|
|
769
|
+
...["names", "dob", "addresses", "screen_indicators", "victimization", "contact_info"],
|
|
770
|
+
...["priorities_safety", "encounter_location", "summary_initial_screen", "summary_ae_intake"],
|
|
771
|
+
...["summary_ida", "summary_lap", "summary_danger_assessment", "summary_stalking_assessment"],
|
|
772
|
+
...["summary_injury_and_strangulation", "offenders", "system_involvement"],
|
|
773
|
+
...["session_summary", "case_notes", SYS],
|
|
774
|
+
];
|
|
775
|
+
const got = deliver(MANDATED);
|
|
776
|
+
for (const id of ["jane.names", "jane.protection_order", "jane.da_summary", "dale.truck"]) {
|
|
777
|
+
expect(got.has(id), id).toBe(true);
|
|
778
|
+
}
|
|
779
|
+
expect(got.has("dale.immigration_status")).toBe(false);
|
|
780
|
+
expect(
|
|
781
|
+
scope.shareVerdict(MANDATED, scope.rowForSubject("immigration_status", "offenders")).reason,
|
|
782
|
+
).toBe("off_by_default");
|
|
783
|
+
expect(ids((r) => r.subject === "family").some((id) => got.has(id))).toBe(false);
|
|
784
|
+
expect(got.has("jane.hiv")).toBe(false);
|
|
785
|
+
expect(got.has("jane.household_roster")).toBe(false);
|
|
786
|
+
expect(got.has("jane.da_full")).toBe(false);
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
it("S3 case collaboration (the runner's FULL_COLLAB, enabled = {full_ida})", () => {
|
|
790
|
+
// tools/infoscope/phase4_stress_test.py main(): FULL_COLLAB, enabled=frozenset({"full_ida"}).
|
|
791
|
+
const FULL_COLLAB = [
|
|
792
|
+
...["names", "dob", "addresses", "demographics", "screen_indicators", "victimization"],
|
|
793
|
+
...["summary_initial_screen", "summary_ae_intake", "summary_ida", "summary_lap"],
|
|
794
|
+
...["summary_danger_assessment", "summary_stalking_assessment"],
|
|
795
|
+
...["summary_injury_and_strangulation", "summary_tra", "summary_hope_scale"],
|
|
796
|
+
...["summary_needs_assessment", "full_ida", "contact_info", "priorities_safety"],
|
|
797
|
+
...["encounter_location", "contact_history", "service_history", "plans_goals"],
|
|
798
|
+
...["session_summary", "case_notes", "relationships_household", "family", SYS],
|
|
799
|
+
];
|
|
800
|
+
const enabled = ["full_ida"];
|
|
801
|
+
const got = deliver(FULL_COLLAB, enabled);
|
|
802
|
+
for (const id of ids((r) => r.subject === "family")) expect(got.has(id), id).toBe(true);
|
|
803
|
+
for (const id of ids((r) => r.subject === "offenders")) expect(got.has(id), id).toBe(false);
|
|
804
|
+
expect(got.has("jane.household_roster")).toBe(true);
|
|
805
|
+
expect(got.has("jane.immigration_status")).toBe(false);
|
|
806
|
+
// The reference verdict: enabling full_ida alone does not enable its off-by-default parent.
|
|
807
|
+
expect(scope.shareVerdict(FULL_COLLAB, "full_ida", { enabledOffByDefault: enabled })).toEqual({
|
|
808
|
+
included: false,
|
|
809
|
+
reason: "off_by_default",
|
|
810
|
+
notEnabled: ["instrument_full"],
|
|
811
|
+
});
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
it("S4 offender information to law enforcement: Dale's record, nothing of Jane's", () => {
|
|
815
|
+
const got = deliver([SYS, "offenders"]);
|
|
816
|
+
expect(ids((r) => r.subject === "client").filter((id) => got.has(id))).toEqual([]);
|
|
817
|
+
for (const id of ["dale.names", "dale.offender_status", "dale.tra_run", "dale.record_note"]) {
|
|
818
|
+
expect(got.has(id), id).toBe(true);
|
|
819
|
+
}
|
|
820
|
+
expect(got.has("dale.immigration_status")).toBe(false);
|
|
821
|
+
// The cohabiting address is Dale's fact under the tree; holding it back is
|
|
822
|
+
// build rule B-new-1, outside this resolver (handoff § 7 row 4).
|
|
823
|
+
expect(got.has("dale.address")).toBe(true);
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
it("S5 (the level-1 stub part only): the client's name is in the stub, another person's never", () => {
|
|
827
|
+
// Canon S5 is a level-3 viewer whitelisted on two categories; the whitelist is
|
|
828
|
+
// viewing policy outside this resolver. What the tree decides there is the
|
|
829
|
+
// level-1 stub (rule 7) — asserted here per record.
|
|
830
|
+
for (const r of CASE.filter((x) => x.home === "names")) {
|
|
831
|
+
const row = scope.rowForSubject(r.home, r.subject);
|
|
832
|
+
expect(scope.isVisibleAtLevel(1, row), r.id).toBe(r.subject === "client");
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
const EVERYTHING = [SYS, "primary_client", "notes", "other_named_persons"];
|
|
837
|
+
|
|
838
|
+
it("S6a everything except one note: the tree can only drop Session & case notes whole", () => {
|
|
839
|
+
const got = deliver(scope.deselectChild(EVERYTHING, "case_notes"), ENABLED_ALL);
|
|
840
|
+
expect(got.has("jane.case_note_pregnancy")).toBe(false);
|
|
841
|
+
expect(got.has("jane.session_summary")).toBe(true);
|
|
842
|
+
expect(got.has("jane.safe_location")).toBe(false);
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
it("S6b everything except one health fact: Health status leaves whole; Accommodation stays", () => {
|
|
846
|
+
const got = deliver(scope.deselectChild(EVERYTHING, "health_status"), ENABLED_ALL);
|
|
847
|
+
for (const id of ["jane.hiv", "jane.pregnancy", "jane.mental_health"]) {
|
|
848
|
+
expect(got.has(id), id).toBe(false);
|
|
849
|
+
}
|
|
850
|
+
expect(got.has("jane.accommodations")).toBe(true);
|
|
851
|
+
expect(got.has("jane.living_situation")).toBe(true);
|
|
852
|
+
expect(got.has("mika.health")).toBe(true);
|
|
853
|
+
});
|
|
854
|
+
|
|
855
|
+
it("S6c everything except one relative's name: only kinds can be dropped, never a person", () => {
|
|
856
|
+
const sel = scope.deselectChild(
|
|
857
|
+
scope.deselectChild(EVERYTHING, "relationships_household"),
|
|
858
|
+
"others",
|
|
859
|
+
);
|
|
860
|
+
const got = deliver(sel, ENABLED_ALL);
|
|
861
|
+
for (const id of ["maria.names", "tom.names", "jane.household_roster"]) {
|
|
862
|
+
expect(got.has(id), id).toBe(false);
|
|
863
|
+
}
|
|
864
|
+
expect(got.has("jane.ec_designation_maria")).toBe(true);
|
|
865
|
+
expect(got.has("mika.names")).toBe(true);
|
|
866
|
+
});
|
|
867
|
+
|
|
868
|
+
it("S7 to a partner: 'everything' is clamped at the door to the account's ceiling", () => {
|
|
869
|
+
const ceiling = ["identifying", "contact", "risk", "services", "instrument_summary", "notes"];
|
|
870
|
+
const got = deliver(scope.clampToCeiling(EVERYTHING, ceiling), ENABLED_ALL);
|
|
871
|
+
expect(got.has("jane.names")).toBe(true);
|
|
872
|
+
expect(got.has("jane.hiv")).toBe(false);
|
|
873
|
+
expect(got.has("jane.household_roster")).toBe(false);
|
|
874
|
+
expect(got.has("dale.names")).toBe(false);
|
|
875
|
+
expect(got.has("jane.da_full")).toBe(false);
|
|
876
|
+
});
|
|
877
|
+
});
|
|
878
|
+
|
|
879
|
+
// ─── Phase 3 D1 ─────────────────────────────────────────────────────────────
|
|
880
|
+
|
|
881
|
+
describe("D1 — the relationship record is the client's; the person's own record rides their kind", () => {
|
|
882
|
+
it("case 1: Relationships & household alone delivers the roster and no other person's record", () => {
|
|
883
|
+
same([...deliver([SYS, "relationships_household"])], [
|
|
884
|
+
"jane.household_roster",
|
|
885
|
+
"jane.pet",
|
|
886
|
+
"jane.relationship_dale",
|
|
887
|
+
]);
|
|
888
|
+
});
|
|
889
|
+
|
|
890
|
+
it("case 2: Eligible family members alone delivers the child's record, not the roster", () => {
|
|
891
|
+
same([...deliver([SYS, "family"])], ids((r) => r.subject === "family"));
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
it("Risk-related alone sends nobody's name; People who caused harm alone sends nothing of the client's", () => {
|
|
895
|
+
const risk = deliver([SYS, "risk"]);
|
|
896
|
+
expect([...risk].every((id) => id.startsWith("jane."))).toBe(true);
|
|
897
|
+
expect(risk.has("jane.names")).toBe(false);
|
|
898
|
+
const harm = deliver([SYS, "offenders"]);
|
|
899
|
+
expect([...harm].every((id) => id.startsWith("dale."))).toBe(true);
|
|
900
|
+
});
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
// ─── Tree validation and retired rows ──────────────────────────────────────
|
|
904
|
+
|
|
905
|
+
describe("construction", () => {
|
|
906
|
+
const base = rows.filter((r) => r.scopeCode === "system" || r.scopeCode === SYS);
|
|
907
|
+
|
|
908
|
+
it("throws on a malformed tree or table", () => {
|
|
909
|
+
expect(() => createInformationScopeResolver({ rows: [...base, base[1]] })).toThrow(/duplicate/);
|
|
910
|
+
expect(() =>
|
|
911
|
+
createInformationScopeResolver({
|
|
912
|
+
rows: [...base, { ...base[1], scopeCode: "x", parentScopeCode: "y" }],
|
|
913
|
+
}),
|
|
914
|
+
).toThrow(/unknown parent/);
|
|
915
|
+
expect(() =>
|
|
916
|
+
createInformationScopeResolver({ rows: base.filter((r) => r.scopeCode !== SYS) }),
|
|
917
|
+
).toThrow(/system_info/);
|
|
918
|
+
expect(() =>
|
|
919
|
+
createInformationScopeResolver({
|
|
920
|
+
rows: base,
|
|
921
|
+
migrations: [{ from: "old", to: ["missing"], rule: "row" }],
|
|
922
|
+
}),
|
|
923
|
+
).toThrow(/not a live row/);
|
|
924
|
+
expect(() =>
|
|
925
|
+
createInformationScopeResolver({
|
|
926
|
+
rows: base,
|
|
927
|
+
migrations: [
|
|
928
|
+
{ from: "old", to: ["system"], rule: "row" },
|
|
929
|
+
{ from: "old", to: [SYS], rule: "row" },
|
|
930
|
+
],
|
|
931
|
+
}),
|
|
932
|
+
).toThrow(/two "row" readings/);
|
|
933
|
+
const noKindRow = rows.map((r) => {
|
|
934
|
+
if (r.scopeCode !== "family.risk") return r;
|
|
935
|
+
const { kindRow: _drop, ...rest } = r;
|
|
936
|
+
return rest;
|
|
937
|
+
});
|
|
938
|
+
expect(() => createInformationScopeResolver({ rows: noKindRow })).toThrow(/kindRow/);
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
it("a retired tombstone row is never covered, offered, expanded or written", () => {
|
|
942
|
+
const withTombstone = createInformationScopeResolver({
|
|
943
|
+
rows: [
|
|
944
|
+
...rows,
|
|
945
|
+
{
|
|
946
|
+
...(scope.row("health_status") as ScopeRow),
|
|
947
|
+
scopeCode: "hiv_status",
|
|
948
|
+
status: "retired",
|
|
949
|
+
selectable: false,
|
|
950
|
+
},
|
|
951
|
+
],
|
|
952
|
+
migrations,
|
|
953
|
+
});
|
|
954
|
+
same(withTombstone.childrenOf("health_accommodation"), ["health_status", "accommodation_needs"]);
|
|
955
|
+
expect(withTombstone.isCovered([SYS, "primary_client"], "hiv_status")).toBe(false);
|
|
956
|
+
expect(withTombstone.isIncludedOnShare([SYS, "hiv_status"], "hiv_status")).toBe(false);
|
|
957
|
+
expect(withTombstone.isVisibleAtLevel(3, "hiv_status")).toBe(false);
|
|
958
|
+
same(withTombstone.deselectChild([SYS, "health_accommodation"], "accommodation_needs"), [
|
|
959
|
+
SYS,
|
|
960
|
+
"health_status",
|
|
961
|
+
]);
|
|
962
|
+
expect(withTombstone.readSelection(["hiv_status"], 4).codes[0].rule).toBe("row");
|
|
963
|
+
});
|
|
964
|
+
});
|