@htilabs/platform-common-models 0.40.0 → 0.42.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/README.md +149 -0
- package/dist/index.cjs +677 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +658 -0
- package/dist/index.js.map +1 -1
- package/dist/share-rules/index.cjs +822 -0
- package/dist/share-rules/index.cjs.map +1 -0
- package/dist/share-rules/index.d.cts +804 -0
- package/dist/share-rules/index.d.ts +804 -0
- package/dist/share-rules/index.js +736 -0
- package/dist/share-rules/index.js.map +1 -0
- package/dist/sharing-ceiling/index.cjs +679 -2
- package/dist/sharing-ceiling/index.cjs.map +1 -1
- package/dist/sharing-ceiling/index.d.cts +461 -1
- package/dist/sharing-ceiling/index.d.ts +461 -1
- package/dist/sharing-ceiling/index.js +659 -1
- package/dist/sharing-ceiling/index.js.map +1 -1
- package/package.json +6 -1
- package/src/shareRules/__tests__/caseShareLane.test.ts +259 -0
- package/src/shareRules/__tests__/magicLinkAddresses.test.ts +107 -0
- package/src/shareRules/__tests__/platformApps.test.ts +133 -0
- package/src/shareRules/__tests__/releaseTerms.test.ts +358 -0
- package/src/shareRules/__tests__/senderRoiPosture.test.ts +284 -0
- package/src/shareRules/__tests__/sharingMethods.test.ts +105 -0
- package/src/shareRules/caseShareLane.ts +289 -0
- package/src/shareRules/index.ts +31 -0
- package/src/shareRules/magicLinkAddresses.ts +185 -0
- package/src/shareRules/platformApps.ts +168 -0
- package/src/shareRules/releaseTerms.ts +359 -0
- package/src/shareRules/reportPurposes.ts +50 -0
- package/src/shareRules/senderRoiPosture.ts +296 -0
- package/src/shareRules/sharingMethods.ts +204 -0
- package/src/sharingCeiling/__tests__/resolveShare.test.ts +1305 -0
- package/src/sharingCeiling/__tests__/threadLift.test.ts +353 -0
- package/src/sharingCeiling/coverage.ts +63 -0
- package/src/sharingCeiling/defaults.ts +106 -0
- package/src/sharingCeiling/index.ts +13 -1
- package/src/sharingCeiling/resolve.ts +1278 -0
|
@@ -0,0 +1,1305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE share resolver (Kickoff 13, GDR § 5.79): the vectors of the prototype's
|
|
3
|
+
* behavioural specs `tools/smoke/flows/one-resolver-k13.js` (A–G) and
|
|
4
|
+
* `sharing-four-state-k13.js` (A–C), on the real v4 tree.
|
|
5
|
+
*
|
|
6
|
+
* Contract of record: platform-prototype `src/data.js` @ becfab4 —
|
|
7
|
+
* `governingPolicyFor` L54533ff, `effectiveCeiling` L54879ff,
|
|
8
|
+
* `platformStarterScope` L53719ff, `scopeListCovers` L54696-L54706.
|
|
9
|
+
*/
|
|
10
|
+
import { describe, expect, it } from "vitest";
|
|
11
|
+
|
|
12
|
+
import { coreInformationScopeSot } from "../../cvcs/index.js";
|
|
13
|
+
import {
|
|
14
|
+
createInformationScopeResolver,
|
|
15
|
+
scopeMigrationsFromSot,
|
|
16
|
+
scopeRowsFromSot,
|
|
17
|
+
type CoreInformationScopeSot,
|
|
18
|
+
} from "../../services/informationScope.js";
|
|
19
|
+
import {
|
|
20
|
+
HTI_SHARE_PLATFORM_REQUIRED_BY_PURPOSE,
|
|
21
|
+
HTI_SHARE_PLATFORM_STARTER,
|
|
22
|
+
SHARE_LEVEL_LABEL,
|
|
23
|
+
SHARE_REPORTING_PURPOSES,
|
|
24
|
+
attachmentIndexFromPolicies,
|
|
25
|
+
derivePlatformDefault,
|
|
26
|
+
liveCategories,
|
|
27
|
+
matchTeamRow,
|
|
28
|
+
platformDefaultFor,
|
|
29
|
+
resolveShare,
|
|
30
|
+
scopeListCovers,
|
|
31
|
+
shareRowCeiling,
|
|
32
|
+
systemCategoryOf,
|
|
33
|
+
type SharePlatformDefault,
|
|
34
|
+
type SharePolicyDoc,
|
|
35
|
+
type ShareResolveInput,
|
|
36
|
+
} from "../index.js";
|
|
37
|
+
|
|
38
|
+
const sot = coreInformationScopeSot as CoreInformationScopeSot;
|
|
39
|
+
const scope = createInformationScopeResolver({
|
|
40
|
+
rows: scopeRowsFromSot(sot),
|
|
41
|
+
migrations: scopeMigrationsFromSot(sot),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const A = "agency-htilabs";
|
|
45
|
+
const T = "team-htilabs-inv-analysts";
|
|
46
|
+
const T2 = "team-htilabs-impl-support";
|
|
47
|
+
const REQUIRED_BY_PURPOSE: Record<string, string[]> = {
|
|
48
|
+
mandatory_reporting: ["identifying"],
|
|
49
|
+
authority_reporting: ["identifying"],
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const pdFor = (
|
|
53
|
+
purpose: string,
|
|
54
|
+
extra: Parameters<typeof derivePlatformDefault>[3] = {},
|
|
55
|
+
): SharePlatformDefault =>
|
|
56
|
+
derivePlatformDefault(
|
|
57
|
+
scope,
|
|
58
|
+
purpose,
|
|
59
|
+
HTI_SHARE_PLATFORM_STARTER.scopeByPurpose[purpose] ?? null,
|
|
60
|
+
{
|
|
61
|
+
required: REQUIRED_BY_PURPOSE[purpose] ?? [],
|
|
62
|
+
...extra,
|
|
63
|
+
},
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
/** The one-resolver flow's seed (L47–72) + the account's day-one defaults (data.js policySeeds L41007–41079). */
|
|
67
|
+
const seeds = (): SharePolicyDoc[] => [
|
|
68
|
+
{
|
|
69
|
+
id: "pol-referral-agency-standard",
|
|
70
|
+
name: "Referral — agency standard",
|
|
71
|
+
purpose: "referral",
|
|
72
|
+
posture: "open",
|
|
73
|
+
edited: false,
|
|
74
|
+
infoScope: ["identifying", "contact", "services", "risk", "notes"],
|
|
75
|
+
assignments: [{ scope: "account" }],
|
|
76
|
+
origin: { kind: "agency" },
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: "pol-mandatory-reporting-agency-standard",
|
|
80
|
+
name: "Mandatory reporting — agency standard",
|
|
81
|
+
purpose: "mandatory_reporting",
|
|
82
|
+
posture: "open",
|
|
83
|
+
edited: false,
|
|
84
|
+
infoScope: ["identifying", "contact", "risk"],
|
|
85
|
+
assignments: [{ scope: "account" }],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: "pol-case-collaboration-agency-standard",
|
|
89
|
+
name: "Case collaboration — agency standard",
|
|
90
|
+
purpose: "case_collaboration",
|
|
91
|
+
posture: "open",
|
|
92
|
+
edited: false,
|
|
93
|
+
infoScope: ["identifying", "contact", "services", "risk"],
|
|
94
|
+
assignments: [{ scope: "account" }],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: "pol-discretionary-supervisor-approval",
|
|
98
|
+
name: "Discretionary — supervisor approval",
|
|
99
|
+
purpose: "discretionary_share",
|
|
100
|
+
posture: "approval",
|
|
101
|
+
edited: true,
|
|
102
|
+
infoScope: ["identifying", "contact"],
|
|
103
|
+
assignments: [{ scope: "account" }],
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: "pol-zz8-palomar",
|
|
107
|
+
familyId: "pol-zz8-palomar",
|
|
108
|
+
name: "ZZ8 Referral — Palomar",
|
|
109
|
+
version: 4,
|
|
110
|
+
purpose: "referral",
|
|
111
|
+
posture: "open",
|
|
112
|
+
species: "purpose",
|
|
113
|
+
edited: true,
|
|
114
|
+
infoScope: ["identifying", "contact", "services", "risk"],
|
|
115
|
+
assignments: [{ scope: "account_partner", partnerId: "palomar" }],
|
|
116
|
+
origin: { kind: "fork", parentId: "pol-referral-agency-standard" },
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: "pol-zz8-team",
|
|
120
|
+
name: "ZZ8 Referral — Investigative Analysts",
|
|
121
|
+
version: 2,
|
|
122
|
+
purpose: "referral",
|
|
123
|
+
posture: "approval",
|
|
124
|
+
species: "team",
|
|
125
|
+
edited: true,
|
|
126
|
+
infoScope: ["identifying", "services", "notes"],
|
|
127
|
+
assignments: [{ scope: "team", teamId: T }],
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
id: "pol-zz8-team-mand",
|
|
131
|
+
name: "ZZ8 Mandatory — Investigative Analysts",
|
|
132
|
+
version: 1,
|
|
133
|
+
purpose: "mandatory_reporting",
|
|
134
|
+
posture: "blocked",
|
|
135
|
+
species: "team",
|
|
136
|
+
edited: true,
|
|
137
|
+
infoScope: null,
|
|
138
|
+
assignments: [{ scope: "team", teamId: T }],
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
id: "pol-zz8-team-disc",
|
|
142
|
+
name: "ZZ8 Discretionary — Investigative Analysts",
|
|
143
|
+
version: 1,
|
|
144
|
+
purpose: "discretionary_share",
|
|
145
|
+
posture: "blocked",
|
|
146
|
+
species: "team",
|
|
147
|
+
edited: true,
|
|
148
|
+
infoScope: null,
|
|
149
|
+
assignments: [{ scope: "team", teamId: T }],
|
|
150
|
+
},
|
|
151
|
+
];
|
|
152
|
+
|
|
153
|
+
const read = (
|
|
154
|
+
over: Partial<ShareResolveInput> & { purpose: string },
|
|
155
|
+
policies: SharePolicyDoc[] = seeds(),
|
|
156
|
+
) =>
|
|
157
|
+
resolveShare({
|
|
158
|
+
scope,
|
|
159
|
+
policies,
|
|
160
|
+
platformDefault: pdFor(over.purpose),
|
|
161
|
+
sender: { accountId: A, teamId: T },
|
|
162
|
+
recipient: { kind: "partner", id: "palomar" },
|
|
163
|
+
...over,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
/** Every live row beneath `g` the codebook marks heightened (`shareableDefault: false`, CVC-236). */
|
|
167
|
+
const heightenedUnder = (g: string): string[] => {
|
|
168
|
+
const out: string[] = [];
|
|
169
|
+
const walk = (c: string): void => {
|
|
170
|
+
for (const k of scope.childrenOf(c)) {
|
|
171
|
+
if (scope.row(k)?.status === "retired") continue;
|
|
172
|
+
if (scope.row(k)?.shareableDefault === false) out.push(k);
|
|
173
|
+
walk(k);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
walk(g);
|
|
177
|
+
return out;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const leavesOf = (g: string): string[] => {
|
|
181
|
+
const out: string[] = [];
|
|
182
|
+
const walk = (c: string): void => {
|
|
183
|
+
const kids = scope
|
|
184
|
+
.childrenOf(c)
|
|
185
|
+
.filter((k) => scope.row(k)?.status !== "retired");
|
|
186
|
+
if (kids.length === 0) out.push(c);
|
|
187
|
+
else kids.forEach(walk);
|
|
188
|
+
};
|
|
189
|
+
scope.childrenOf(g).forEach(walk);
|
|
190
|
+
return out;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// ─── The ladder and the team ceiling (one-resolver-k13 A–G) ─────────────────
|
|
194
|
+
|
|
195
|
+
describe("resolveShare — the ladder names ONE policy; the sending team's own policy is a ceiling", () => {
|
|
196
|
+
it("A1 — the partner link governs (v4, relationship); the team's policy rides as the ceiling (v2, team); only what both allow, the stricter posture", () => {
|
|
197
|
+
const r = read({ purpose: "referral" });
|
|
198
|
+
expect(r.governing).toMatchObject({
|
|
199
|
+
id: "pol-zz8-palomar",
|
|
200
|
+
version: 4,
|
|
201
|
+
level: "relationship",
|
|
202
|
+
levelLabel: SHARE_LEVEL_LABEL.relationship,
|
|
203
|
+
});
|
|
204
|
+
expect(r.teamCeiling).toMatchObject({
|
|
205
|
+
id: "pol-zz8-team",
|
|
206
|
+
version: 2,
|
|
207
|
+
level: "team",
|
|
208
|
+
});
|
|
209
|
+
expect(r.posture).toBe("approval");
|
|
210
|
+
expect(r.postureSource).toBe("team_ceiling");
|
|
211
|
+
expect(r.allowed).toBe(true);
|
|
212
|
+
const four = ["identifying", "contact", "services", "risk"].filter((g) =>
|
|
213
|
+
r.allowedCategories.includes(g),
|
|
214
|
+
);
|
|
215
|
+
expect(four).toEqual(["identifying", "services"]);
|
|
216
|
+
expect(r.scope["contact"]?.allowed).toBe(false);
|
|
217
|
+
expect(r.scope["contact"]?.rulePath).toMatch(/pol-zz8-team/);
|
|
218
|
+
expect(r.scope["contact"]?.reason).toMatch(/your team/);
|
|
219
|
+
expect(r.rulePath).toMatch(/∩/);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("A2 — another team keeps the link's four (no ceiling)", () => {
|
|
223
|
+
const r = read({
|
|
224
|
+
purpose: "referral",
|
|
225
|
+
sender: { accountId: A, teamId: T2 },
|
|
226
|
+
});
|
|
227
|
+
expect(r.governing?.id).toBe("pol-zz8-palomar");
|
|
228
|
+
expect(r.teamCeiling).toBeNull();
|
|
229
|
+
expect(r.posture).toBe("open");
|
|
230
|
+
expect(r.scope["contact"]?.allowed).toBe(true);
|
|
231
|
+
expect(
|
|
232
|
+
["identifying", "contact", "services", "risk"].filter((g) =>
|
|
233
|
+
r.allowedCategories.includes(g),
|
|
234
|
+
).length,
|
|
235
|
+
).toBeGreaterThanOrEqual(3);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("B — never widens: a category only the team policy carries stays withheld, attributed to the governing link", () => {
|
|
239
|
+
const r = read({ purpose: "referral" });
|
|
240
|
+
expect(r.scope["notes"]?.allowed).toBe(false);
|
|
241
|
+
expect(r.scope["notes"]?.rulePath).not.toMatch(/pol-zz8-team/);
|
|
242
|
+
expect(r.scope["notes"]?.rulePath).toMatch(/pol-zz8-palomar/);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("C — reports: a team policy saying blocked never blocks a mandatory report; the posture reads blocked and the carve-out names the team policy", () => {
|
|
246
|
+
const r = read({ purpose: "mandatory_reporting" });
|
|
247
|
+
expect(SHARE_REPORTING_PURPOSES.has("mandatory_reporting")).toBe(true);
|
|
248
|
+
expect(r.posture).toBe("blocked");
|
|
249
|
+
expect(r.allowed).toBe(true);
|
|
250
|
+
expect(r.excluded).toBeNull();
|
|
251
|
+
expect(r.reportCarveOut?.note).toMatch(
|
|
252
|
+
/ZZ8 Mandatory — Investigative Analysts/,
|
|
253
|
+
);
|
|
254
|
+
expect(r.governing).toMatchObject({
|
|
255
|
+
id: "pol-mandatory-reporting-agency-standard",
|
|
256
|
+
level: "agency_default",
|
|
257
|
+
});
|
|
258
|
+
expect(r.teamCeiling?.id).toBe("pol-zz8-team-mand");
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("D — a team policy saying blocked does block a discretionary share, and the reason names the team's policy", () => {
|
|
262
|
+
const r = read({ purpose: "discretionary_share" });
|
|
263
|
+
expect(r.allowed).toBe(false);
|
|
264
|
+
expect(r.excluded?.reason).toMatch(
|
|
265
|
+
/ZZ8 Discretionary — Investigative Analysts/,
|
|
266
|
+
);
|
|
267
|
+
expect(r.excluded?.rulePath).toMatch(/pol-zz8-team-disc/);
|
|
268
|
+
expect(r.scope["identifying"]?.allowed).toBe(false);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it("D2 — with the relationship at approval, the block still comes from the team ceiling", () => {
|
|
272
|
+
const r = read({
|
|
273
|
+
purpose: "discretionary_share",
|
|
274
|
+
relationshipPosture: "approval",
|
|
275
|
+
});
|
|
276
|
+
expect(r.allowed).toBe(false);
|
|
277
|
+
expect(r.postureSource).toBe("team_ceiling");
|
|
278
|
+
expect(r.excluded?.reason).toMatch(/ZZ8 Discretionary/);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("E1 — inside: with no inside policy linked, a share to a sibling team runs under the platform's inside starter (full record, open); only what the account's Information Scope shuts (the codebook's heightened defaults included) stays withheld", () => {
|
|
282
|
+
const r = read({
|
|
283
|
+
purpose: "case_collaboration",
|
|
284
|
+
sender: { accountId: A, teamId: T2 },
|
|
285
|
+
recipient: { kind: "sibling_team", teamId: T },
|
|
286
|
+
});
|
|
287
|
+
expect(r.inside).toBe(true);
|
|
288
|
+
expect(r.governing).toMatchObject({
|
|
289
|
+
id: "pol-inside-starter-case_collaboration",
|
|
290
|
+
level: "inside_starter",
|
|
291
|
+
version: 1,
|
|
292
|
+
infoScope: null,
|
|
293
|
+
});
|
|
294
|
+
expect(r.posture).toBe("open");
|
|
295
|
+
expect(r.teamCeiling).toBeNull();
|
|
296
|
+
expect(r.scope["risk"]?.allowed).toBe(true);
|
|
297
|
+
expect(r.scope["notes"]?.allowed).toBe(true);
|
|
298
|
+
// Smoke E (one-resolver-k13 L173): every category shut inside is shut by the account's
|
|
299
|
+
// Information Scope (`scopeCatalog`), the floor or SAFETY — immigration & legal status is
|
|
300
|
+
// CVC-236 heightened, off until the account turns it on, with NO accountScope passed (R1).
|
|
301
|
+
const imm = r.scope["immigration_legal_status"];
|
|
302
|
+
expect(imm?.allowed).toBe(false);
|
|
303
|
+
expect(imm?.reason).toMatch(/Information Scope/);
|
|
304
|
+
for (const g of liveCategories(scope)) {
|
|
305
|
+
const e = r.scope[g];
|
|
306
|
+
if (
|
|
307
|
+
g === systemCategoryOf(scope) ||
|
|
308
|
+
e === undefined ||
|
|
309
|
+
e.allowed ||
|
|
310
|
+
e.floorItems.length
|
|
311
|
+
)
|
|
312
|
+
continue;
|
|
313
|
+
expect(e.rulePath).toMatch(/scopeCatalog|SAFETY|floor/i);
|
|
314
|
+
}
|
|
315
|
+
// …and once the account turns it on, it travels inside (the Platform default's Blocked is not read inside).
|
|
316
|
+
const on = read({
|
|
317
|
+
purpose: "case_collaboration",
|
|
318
|
+
sender: { accountId: A, teamId: T2 },
|
|
319
|
+
recipient: { kind: "sibling_team", teamId: T },
|
|
320
|
+
accountScope: {
|
|
321
|
+
categoriesOn: ["immigration_legal_status"],
|
|
322
|
+
rowsOn: heightenedUnder("immigration_legal_status"),
|
|
323
|
+
},
|
|
324
|
+
});
|
|
325
|
+
expect(on.scope["immigration_legal_status"]?.allowed).toBe(true);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("E2 — the account default to partners does not reach inside; it binds a share to a partner once authored", () => {
|
|
329
|
+
const policies = seeds().map((p) =>
|
|
330
|
+
p.id === "pol-case-collaboration-agency-standard"
|
|
331
|
+
? { ...p, edited: true, infoScope: ["identifying"] }
|
|
332
|
+
: p,
|
|
333
|
+
);
|
|
334
|
+
const inside = read(
|
|
335
|
+
{
|
|
336
|
+
purpose: "case_collaboration",
|
|
337
|
+
sender: { accountId: A, teamId: T2 },
|
|
338
|
+
recipient: { kind: "sibling_team", teamId: T },
|
|
339
|
+
},
|
|
340
|
+
policies,
|
|
341
|
+
);
|
|
342
|
+
expect(inside.scope["risk"]?.allowed).toBe(true);
|
|
343
|
+
const partner = read(
|
|
344
|
+
{
|
|
345
|
+
purpose: "case_collaboration",
|
|
346
|
+
sender: { accountId: A, teamId: T2 },
|
|
347
|
+
recipient: { kind: "partner", id: "okcpd" },
|
|
348
|
+
},
|
|
349
|
+
policies,
|
|
350
|
+
);
|
|
351
|
+
expect(partner.governing).toMatchObject({
|
|
352
|
+
id: "pol-case-collaboration-agency-standard",
|
|
353
|
+
level: "agency_default",
|
|
354
|
+
edited: true,
|
|
355
|
+
});
|
|
356
|
+
expect(partner.scope["risk"]?.allowed).toBe(false);
|
|
357
|
+
expect(partner.scope["risk"]?.rulePath).toMatch(
|
|
358
|
+
/pol-case-collaboration-agency-standard/,
|
|
359
|
+
);
|
|
360
|
+
expect(partner.scope["identifying"]?.allowed).toBe(true);
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it("E3 — the team ceiling still binds inside the account", () => {
|
|
364
|
+
const r = read({
|
|
365
|
+
purpose: "referral",
|
|
366
|
+
recipient: { kind: "sibling_team", teamId: T2 },
|
|
367
|
+
});
|
|
368
|
+
expect(r.governing?.level).toBe("inside_starter");
|
|
369
|
+
expect(r.teamCeiling?.id).toBe("pol-zz8-team");
|
|
370
|
+
expect(r.posture).toBe("approval");
|
|
371
|
+
expect(r.scope["risk"]?.allowed).toBe(false);
|
|
372
|
+
expect(r.scope["risk"]?.rulePath).toMatch(/pol-zz8-team/);
|
|
373
|
+
expect(r.scope["notes"]?.allowed).toBe(true);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
it("F — a pair row's policy governs (team_row), and the team ceiling still binds", () => {
|
|
377
|
+
const policies = seeds().map((p) =>
|
|
378
|
+
p.id === "pol-zz8-palomar"
|
|
379
|
+
? {
|
|
380
|
+
...p,
|
|
381
|
+
assignments: [
|
|
382
|
+
...(p.assignments ?? []),
|
|
383
|
+
{
|
|
384
|
+
scope: "team_pair" as const,
|
|
385
|
+
teamRowId: "tr-zz8-ia-palomar",
|
|
386
|
+
teamId: T,
|
|
387
|
+
partnerId: "palomar",
|
|
388
|
+
},
|
|
389
|
+
],
|
|
390
|
+
}
|
|
391
|
+
: p,
|
|
392
|
+
);
|
|
393
|
+
const rowId = matchTeamRow(
|
|
394
|
+
[
|
|
395
|
+
{
|
|
396
|
+
id: "tr-zz8-ia-palomar",
|
|
397
|
+
myTeamId: T,
|
|
398
|
+
their: { type: "org", id: "palomar" },
|
|
399
|
+
},
|
|
400
|
+
],
|
|
401
|
+
T,
|
|
402
|
+
{ kind: "partner", id: "palomar" },
|
|
403
|
+
);
|
|
404
|
+
expect(rowId).toBe("tr-zz8-ia-palomar");
|
|
405
|
+
const r = read({ purpose: "referral", teamRowId: rowId }, policies);
|
|
406
|
+
expect(r.governing).toMatchObject({
|
|
407
|
+
id: "pol-zz8-palomar",
|
|
408
|
+
level: "team_row",
|
|
409
|
+
});
|
|
410
|
+
expect(r.teamCeiling?.id).toBe("pol-zz8-team");
|
|
411
|
+
expect(r.scope["contact"]?.allowed).toBe(false);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it("G — a field-limits-only team ceiling (infoScope null, infoScopeItems) withholds rows, never the category, each once", () => {
|
|
415
|
+
const first = leavesOf("identifying")[0] as string;
|
|
416
|
+
const policies = seeds().map((p) =>
|
|
417
|
+
p.id === "pol-zz8-team"
|
|
418
|
+
? { ...p, infoScope: null, infoScopeItems: { identifying: [first] } }
|
|
419
|
+
: p,
|
|
420
|
+
);
|
|
421
|
+
const r = read({ purpose: "referral" }, policies);
|
|
422
|
+
expect(r.scope["identifying"]?.allowed).toBe(true);
|
|
423
|
+
const others = leavesOf("identifying").filter((c) => c !== first);
|
|
424
|
+
const ex = r.scope["identifying"]?.teamExcludedItems ?? [];
|
|
425
|
+
expect(ex).not.toContain(first);
|
|
426
|
+
for (const c of others) expect(ex).toContain(c);
|
|
427
|
+
expect(new Set(ex).size).toBe(ex.length);
|
|
428
|
+
expect(r.scope["contact"]?.allowed).toBe(true); // no category list on the ceiling → the governing link's four stand
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
// ─── Rung mechanics ─────────────────────────────────────────────────────────
|
|
433
|
+
|
|
434
|
+
describe("resolveShare — rung mechanics", () => {
|
|
435
|
+
it("N2 — a policy that answers shares received never governs a send; the next rung governs", () => {
|
|
436
|
+
const policies = seeds().map((p) =>
|
|
437
|
+
p.id === "pol-zz8-palomar"
|
|
438
|
+
? { ...p, trigger: { answers: "received" } }
|
|
439
|
+
: p,
|
|
440
|
+
);
|
|
441
|
+
const r = read(
|
|
442
|
+
{ purpose: "referral", sender: { accountId: A, teamId: T2 } },
|
|
443
|
+
policies,
|
|
444
|
+
);
|
|
445
|
+
expect(r.governing).toMatchObject({
|
|
446
|
+
id: "pol-referral-agency-standard",
|
|
447
|
+
level: "agency_default",
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it("N3 — a cross-purpose attachment is ignored, never mis-applied", () => {
|
|
452
|
+
const policies = seeds().map((p) =>
|
|
453
|
+
p.id === "pol-zz8-palomar" ? { ...p, purpose: "case_collaboration" } : p,
|
|
454
|
+
);
|
|
455
|
+
const r = read(
|
|
456
|
+
{ purpose: "referral", sender: { accountId: A, teamId: T2 } },
|
|
457
|
+
policies,
|
|
458
|
+
);
|
|
459
|
+
expect(r.governing?.id).toBe("pol-referral-agency-standard");
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
it("N4 — the team's own policy that is ALSO the governing one is no ceiling", () => {
|
|
463
|
+
const policies = seeds().map((p) =>
|
|
464
|
+
p.id === "pol-zz8-team"
|
|
465
|
+
? {
|
|
466
|
+
...p,
|
|
467
|
+
assignments: [
|
|
468
|
+
...(p.assignments ?? []),
|
|
469
|
+
{ scope: "account_partner" as const, partnerId: "palomar" },
|
|
470
|
+
],
|
|
471
|
+
}
|
|
472
|
+
: p,
|
|
473
|
+
);
|
|
474
|
+
const r = read(
|
|
475
|
+
{ purpose: "referral" },
|
|
476
|
+
policies.filter((p) => p.id !== "pol-zz8-palomar"),
|
|
477
|
+
);
|
|
478
|
+
expect(r.governing?.id).toBe("pol-zz8-team");
|
|
479
|
+
expect(r.teamCeiling).toBeNull();
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
it("a retired policy governs nowhere; a team-blind read has no pair row and no ceiling", () => {
|
|
483
|
+
const policies = seeds().map((p) =>
|
|
484
|
+
p.id === "pol-zz8-palomar" ? { ...p, active: false } : p,
|
|
485
|
+
);
|
|
486
|
+
const r = read(
|
|
487
|
+
{ purpose: "referral", sender: { accountId: A, teamId: null } },
|
|
488
|
+
policies,
|
|
489
|
+
);
|
|
490
|
+
expect(r.governing?.id).toBe("pol-referral-agency-standard");
|
|
491
|
+
expect(r.teamCeiling).toBeNull();
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
it("the Platform default is the last rung — a versioned document named on the answer", () => {
|
|
495
|
+
const r = read(
|
|
496
|
+
{ purpose: "referral", sender: { accountId: A, teamId: T2 } },
|
|
497
|
+
seeds().filter(
|
|
498
|
+
(p) => !p.purpose.startsWith("referral") || p.id === "pol-zz8-team",
|
|
499
|
+
),
|
|
500
|
+
);
|
|
501
|
+
expect(r.governing).toMatchObject({
|
|
502
|
+
id: "pol-starter-referral",
|
|
503
|
+
level: "platform_starter",
|
|
504
|
+
version: 1,
|
|
505
|
+
edited: false,
|
|
506
|
+
});
|
|
507
|
+
expect(r.rulePath).toMatch(/pol-starter-referral v1/);
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
it("N1 — an unknown purpose (no Platform default) governs nothing: fails closed, every category withheld", () => {
|
|
511
|
+
const r = resolveShare({
|
|
512
|
+
scope,
|
|
513
|
+
policies: seeds(),
|
|
514
|
+
platformDefault: null,
|
|
515
|
+
sender: { teamId: T },
|
|
516
|
+
recipient: { kind: "partner", id: "palomar" },
|
|
517
|
+
purpose: "zz-unknown",
|
|
518
|
+
});
|
|
519
|
+
expect(r.governing).toBeNull();
|
|
520
|
+
expect(r.allowed).toBe(false);
|
|
521
|
+
expect(r.excluded?.reason).toMatch(/No Platform default/);
|
|
522
|
+
expect(Object.values(r.scope).every((e) => e.allowed === false)).toBe(true);
|
|
523
|
+
expect(r.allowedCategories).toEqual([]);
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
it("an external recipient resolves through the relationship rung under __external__", () => {
|
|
527
|
+
const policies = [
|
|
528
|
+
...seeds(),
|
|
529
|
+
{
|
|
530
|
+
id: "pol-ext",
|
|
531
|
+
name: "Referral — off-platform",
|
|
532
|
+
purpose: "referral",
|
|
533
|
+
posture: "approval" as const,
|
|
534
|
+
edited: true,
|
|
535
|
+
infoScope: ["identifying"],
|
|
536
|
+
assignments: [
|
|
537
|
+
{ scope: "account_partner" as const, partnerId: "__external__" },
|
|
538
|
+
],
|
|
539
|
+
},
|
|
540
|
+
];
|
|
541
|
+
const r = read(
|
|
542
|
+
{
|
|
543
|
+
purpose: "referral",
|
|
544
|
+
sender: { accountId: A, teamId: T2 },
|
|
545
|
+
recipient: { kind: "external" },
|
|
546
|
+
},
|
|
547
|
+
policies,
|
|
548
|
+
);
|
|
549
|
+
expect(r.governing?.id).toBe("pol-ext");
|
|
550
|
+
expect(r.scope["contact"]?.allowed).toBe(false);
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
it("a malformed infoScope on a document reads as [] (binds, covers nothing); null is no list", () => {
|
|
554
|
+
const policies = seeds().map((p) =>
|
|
555
|
+
p.id === "pol-zz8-palomar"
|
|
556
|
+
? { ...p, infoScope: "identifying" as unknown as string[] }
|
|
557
|
+
: p,
|
|
558
|
+
);
|
|
559
|
+
const r = read(
|
|
560
|
+
{ purpose: "referral", sender: { accountId: A, teamId: T2 } },
|
|
561
|
+
policies,
|
|
562
|
+
);
|
|
563
|
+
expect(r.governing?.infoScope).toEqual([]);
|
|
564
|
+
expect(r.scope["identifying"]?.allowed).toBe(false);
|
|
565
|
+
expect(r.scope[systemCategoryOf(scope) as string]?.allowed).toBe(true);
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
it("an unknown purpose with a policy linked under it still governs nothing — the ladder is not read (review r1 #1)", () => {
|
|
569
|
+
const policies = seeds().map((p) =>
|
|
570
|
+
p.id === "pol-zz8-palomar"
|
|
571
|
+
? {
|
|
572
|
+
...p,
|
|
573
|
+
purpose: "zz-unknown",
|
|
574
|
+
infoScope: ["identifying", "immigration_legal_status"],
|
|
575
|
+
}
|
|
576
|
+
: p,
|
|
577
|
+
);
|
|
578
|
+
const r = resolveShare({
|
|
579
|
+
scope,
|
|
580
|
+
policies,
|
|
581
|
+
platformDefault: null,
|
|
582
|
+
sender: { teamId: T2 },
|
|
583
|
+
recipient: { kind: "partner", id: "palomar" },
|
|
584
|
+
purpose: "zz-unknown",
|
|
585
|
+
});
|
|
586
|
+
expect(r.governing).toBeNull();
|
|
587
|
+
expect(r.scope["immigration_legal_status"]?.allowed).toBe(false);
|
|
588
|
+
expect(r.allowedCategories).toEqual([]);
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
it("a blocked relationship is the relationship's block, never credited to the governing policy (review r1 #3)", () => {
|
|
592
|
+
const r = read({
|
|
593
|
+
purpose: "discretionary_share",
|
|
594
|
+
sender: { accountId: A, teamId: T2 },
|
|
595
|
+
relationshipPosture: "blocked",
|
|
596
|
+
});
|
|
597
|
+
expect(r.allowed).toBe(false);
|
|
598
|
+
expect(r.postureSource).toBe("relationship");
|
|
599
|
+
expect(r.excluded?.reason).toMatch(/by the relationship/);
|
|
600
|
+
expect(r.excluded?.reason).not.toMatch(/supervisor approval/);
|
|
601
|
+
expect(r.excluded?.rulePath).toMatch(/relationship posture = blocked/);
|
|
602
|
+
const rep = read({
|
|
603
|
+
purpose: "mandatory_reporting",
|
|
604
|
+
sender: { accountId: A, teamId: T2 },
|
|
605
|
+
relationshipPosture: "blocked",
|
|
606
|
+
});
|
|
607
|
+
expect(rep.allowed).toBe(true);
|
|
608
|
+
expect(rep.reportCarveOut?.note).toMatch(/reachable for reports/);
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
it('Y2 — a stored policy with NO infoScope field is "no list" (data.js reads every non-array as null, L54979 / L55124); an explicit [] binds an empty list', () => {
|
|
612
|
+
const strip =
|
|
613
|
+
(id: string) =>
|
|
614
|
+
(p: SharePolicyDoc): SharePolicyDoc => {
|
|
615
|
+
if (p.id !== id) return p;
|
|
616
|
+
const { infoScope: _drop, ...rest } = p;
|
|
617
|
+
return rest;
|
|
618
|
+
};
|
|
619
|
+
// the governing relationship policy, posture-only: no list of its own — the Platform
|
|
620
|
+
// default's starting scope stands as the ceiling, not "System metadata only"
|
|
621
|
+
const gov = read(
|
|
622
|
+
{ purpose: "referral", sender: { accountId: A, teamId: T2 } },
|
|
623
|
+
seeds().map(strip("pol-zz8-palomar")),
|
|
624
|
+
);
|
|
625
|
+
expect(gov.governing?.id).toBe("pol-zz8-palomar");
|
|
626
|
+
expect(gov.governing?.infoScope).toBeNull();
|
|
627
|
+
const pd = pdFor("referral");
|
|
628
|
+
for (const g of ["identifying", "contact", "services", "risk", "notes"]) {
|
|
629
|
+
const expected =
|
|
630
|
+
pd.states[g] === "default_on" || pd.states[g] === "always";
|
|
631
|
+
expect(gov.scope[g]?.allowed).toBe(expected);
|
|
632
|
+
}
|
|
633
|
+
expect(gov.scope["identifying"]?.allowed).toBe(true);
|
|
634
|
+
// the team ceiling, posture-only: it raises the posture and narrows no category
|
|
635
|
+
const tc = read(
|
|
636
|
+
{ purpose: "referral" },
|
|
637
|
+
seeds().map(strip("pol-zz8-team")),
|
|
638
|
+
);
|
|
639
|
+
expect(tc.teamCeiling?.id).toBe("pol-zz8-team");
|
|
640
|
+
expect(tc.teamCeiling?.infoScope).toBeNull();
|
|
641
|
+
expect(tc.posture).toBe("approval");
|
|
642
|
+
expect(tc.scope["contact"]?.allowed).toBe(true);
|
|
643
|
+
expect(tc.scope["risk"]?.allowed).toBe(true);
|
|
644
|
+
// an explicit [] is a list that names nothing: it binds (canon: Array.isArray([]) is true)
|
|
645
|
+
const empty = read(
|
|
646
|
+
{ purpose: "referral", sender: { accountId: A, teamId: T2 } },
|
|
647
|
+
seeds().map((p) =>
|
|
648
|
+
p.id === "pol-zz8-palomar" ? { ...p, infoScope: [] } : p,
|
|
649
|
+
),
|
|
650
|
+
);
|
|
651
|
+
expect(empty.governing?.infoScope).toEqual([]);
|
|
652
|
+
expect(empty.scope["identifying"]?.allowed).toBe(false);
|
|
653
|
+
expect(empty.scope[systemCategoryOf(scope) as string]?.allowed).toBe(true);
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
it("Y4 — the legacy cell chain's list stays a ceiling even over an AUTHORED policy (review M6)", () => {
|
|
657
|
+
// pol-zz8-palomar is authored (edited) and names identifying · contact · services · risk
|
|
658
|
+
const r = read({
|
|
659
|
+
purpose: "referral",
|
|
660
|
+
sender: { accountId: A, teamId: T2 },
|
|
661
|
+
legacyCeiling: ["identifying", "contact"],
|
|
662
|
+
});
|
|
663
|
+
expect(r.governing).toMatchObject({
|
|
664
|
+
id: "pol-zz8-palomar",
|
|
665
|
+
edited: true,
|
|
666
|
+
level: "relationship",
|
|
667
|
+
});
|
|
668
|
+
expect(r.scope["identifying"]?.allowed).toBe(true);
|
|
669
|
+
expect(r.scope["contact"]?.allowed).toBe(true);
|
|
670
|
+
expect(r.scope["services"]?.allowed).toBe(false);
|
|
671
|
+
expect(r.scope["risk"]?.allowed).toBe(false);
|
|
672
|
+
expect(r.scope["services"]?.rulePath).toMatch(/sharingScopeEdits/);
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
it("K13-12 — a SYNCED account default does not bind; the Platform default's starting scope is the ceiling", () => {
|
|
676
|
+
const policies = seeds().map((p) =>
|
|
677
|
+
p.id === "pol-referral-agency-standard"
|
|
678
|
+
? { ...p, edited: false, infoScope: ["identifying"] }
|
|
679
|
+
: p,
|
|
680
|
+
);
|
|
681
|
+
const r = read(
|
|
682
|
+
{
|
|
683
|
+
purpose: "referral",
|
|
684
|
+
sender: { accountId: A, teamId: T2 },
|
|
685
|
+
recipient: { kind: "partner", id: "okcpd" },
|
|
686
|
+
},
|
|
687
|
+
policies,
|
|
688
|
+
);
|
|
689
|
+
expect(r.governing).toMatchObject({
|
|
690
|
+
id: "pol-referral-agency-standard",
|
|
691
|
+
edited: false,
|
|
692
|
+
});
|
|
693
|
+
const pd = pdFor("referral");
|
|
694
|
+
for (const g of ["identifying", "contact", "services", "risk", "notes"]) {
|
|
695
|
+
const expected =
|
|
696
|
+
pd.states[g] === "default_on" || pd.states[g] === "always";
|
|
697
|
+
expect(r.scope[g]?.allowed).toBe(expected);
|
|
698
|
+
}
|
|
699
|
+
expect(r.scope["contact"]?.rulePath).toMatch(
|
|
700
|
+
r.scope["contact"]?.allowed ? /./ : /pol-starter-referral/,
|
|
701
|
+
);
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
it("inside the account neither the legacy cell chain nor the Platform default's Required / Blocked is read", () => {
|
|
705
|
+
const r = read({
|
|
706
|
+
purpose: "referral",
|
|
707
|
+
sender: { accountId: A, teamId: T2 },
|
|
708
|
+
recipient: { kind: "sibling_team", teamId: T },
|
|
709
|
+
legacyCeiling: ["identifying"],
|
|
710
|
+
});
|
|
711
|
+
expect(r.scope["contact"]?.allowed).toBe(true);
|
|
712
|
+
// not Blocked by the Platform default inside — but still the account's heightened default (R1)
|
|
713
|
+
expect(r.scope["immigration_legal_status"]?.allowed).toBe(false);
|
|
714
|
+
expect(r.scope["immigration_legal_status"]?.rulePath).toMatch(
|
|
715
|
+
/scopeCatalog/,
|
|
716
|
+
);
|
|
717
|
+
expect(r.scope["immigration_legal_status"]?.rulePath).not.toMatch(
|
|
718
|
+
/= Blocked/,
|
|
719
|
+
);
|
|
720
|
+
const m = read({
|
|
721
|
+
purpose: "mandatory_reporting",
|
|
722
|
+
sender: { accountId: A, teamId: T2 },
|
|
723
|
+
recipient: { kind: "sibling_team", teamId: T },
|
|
724
|
+
accountScope: { categoriesOff: ["identifying"] },
|
|
725
|
+
});
|
|
726
|
+
expect(m.scope["identifying"]?.allowed).toBe(false); // Required is a partner-layer rule; inside, the account's toggle wins
|
|
727
|
+
expect(m.scope["identifying"]?.platformRequired).toBeNull();
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
it("the answer is copies, never the caller's objects", () => {
|
|
731
|
+
const policies = seeds();
|
|
732
|
+
const r = read({ purpose: "referral" }, policies);
|
|
733
|
+
const src = policies.find(
|
|
734
|
+
(p) => p.id === "pol-zz8-palomar",
|
|
735
|
+
) as SharePolicyDoc;
|
|
736
|
+
expect(r.governing?.infoScope).toEqual(src.infoScope);
|
|
737
|
+
expect(r.governing?.infoScope).not.toBe(src.infoScope);
|
|
738
|
+
});
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
// ─── The four states (sharing-four-state-k13 A–C) ───────────────────────────
|
|
742
|
+
|
|
743
|
+
describe("derivePlatformDefault — the Platform default as the four states", () => {
|
|
744
|
+
it("S1 — system Required; heightened Blocked; the seed list covers by self, kind or row; the rest Default Off; bounds override", () => {
|
|
745
|
+
const pd = derivePlatformDefault(scope, "referral", [
|
|
746
|
+
"identifying",
|
|
747
|
+
"summary_lap",
|
|
748
|
+
"family",
|
|
749
|
+
]);
|
|
750
|
+
expect(pd.states["identifying"]).toBe("default_on");
|
|
751
|
+
expect(pd.states["instruments"]).toBe("default_on"); // via a row of it
|
|
752
|
+
expect(pd.states["family.identifying"]).toBe("default_on"); // via the kind above it
|
|
753
|
+
expect(pd.states["contact"]).toBe("default_off");
|
|
754
|
+
expect(pd.states["immigration_legal_status"]).toBe("never");
|
|
755
|
+
expect(pd.states[systemCategoryOf(scope) as string]).toBe("always");
|
|
756
|
+
expect(pd.required).toEqual([]);
|
|
757
|
+
expect(pd.blocked).toContain("immigration_legal_status");
|
|
758
|
+
expect(pd.raw).toContain(systemCategoryOf(scope));
|
|
759
|
+
expect(pd.raw).not.toContain("immigration_legal_status");
|
|
760
|
+
const bound = derivePlatformDefault(scope, "referral", ["identifying"], {
|
|
761
|
+
bounds: {
|
|
762
|
+
contact: "always",
|
|
763
|
+
identifying: "default_off",
|
|
764
|
+
immigration_legal_status: "default_on",
|
|
765
|
+
[systemCategoryOf(scope) as string]: "never",
|
|
766
|
+
},
|
|
767
|
+
version: "3",
|
|
768
|
+
});
|
|
769
|
+
expect(bound.states["contact"]).toBe("always");
|
|
770
|
+
expect(bound.required).toEqual(["contact"]);
|
|
771
|
+
expect(bound.states["identifying"]).toBe("default_off");
|
|
772
|
+
expect(bound.raw).not.toContain("identifying");
|
|
773
|
+
expect(bound.raw).toContain("contact");
|
|
774
|
+
expect(bound.states["immigration_legal_status"]).toBe("default_on");
|
|
775
|
+
expect(bound.states[systemCategoryOf(scope) as string]).toBe("always");
|
|
776
|
+
expect(bound.version).toBe(3);
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
it("S2 — a reporting purpose requires identifying; heightened beats the kind", () => {
|
|
780
|
+
const pd = derivePlatformDefault(
|
|
781
|
+
scope,
|
|
782
|
+
"mandatory_reporting",
|
|
783
|
+
["family", "risk"],
|
|
784
|
+
{
|
|
785
|
+
required: ["identifying"],
|
|
786
|
+
},
|
|
787
|
+
);
|
|
788
|
+
expect(pd.states["identifying"]).toBe("always");
|
|
789
|
+
expect(pd.required).toEqual(["identifying"]);
|
|
790
|
+
expect(pd.states["family.identifying"]).toBe("default_on");
|
|
791
|
+
expect(pd.states["family.immigration_legal_status"]).toBe("never");
|
|
792
|
+
expect(pd.states["offenders.contact"]).toBe("default_off");
|
|
793
|
+
expect(pd.states["risk"]).toBe("default_on");
|
|
794
|
+
expect(pd.raw).toContain("identifying");
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
it("every live category gets a state, in tree order; a seed that is not a list reads as none", () => {
|
|
798
|
+
const pd = derivePlatformDefault(scope, "referral", null);
|
|
799
|
+
expect(Object.keys(pd.states)).toEqual([...liveCategories(scope)]);
|
|
800
|
+
expect(
|
|
801
|
+
Object.values(pd.states).every(
|
|
802
|
+
(s) => s === "always" || s === "never" || s === "default_off",
|
|
803
|
+
),
|
|
804
|
+
).toBe(true);
|
|
805
|
+
});
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
describe("resolveShare — the four states on a share", () => {
|
|
809
|
+
it("B1 — the account's Information Scope toggle withholds a category; Required (Platform default) stands over it", () => {
|
|
810
|
+
const r = read({
|
|
811
|
+
purpose: "referral",
|
|
812
|
+
sender: { accountId: A, teamId: T2 },
|
|
813
|
+
accountScope: { categoriesOff: ["identifying"] },
|
|
814
|
+
});
|
|
815
|
+
expect(r.scope["identifying"]?.allowed).toBe(false);
|
|
816
|
+
expect(r.scope["identifying"]?.reason).toMatch(/Information Scope/);
|
|
817
|
+
const m = read({
|
|
818
|
+
purpose: "mandatory_reporting",
|
|
819
|
+
sender: { accountId: A, teamId: T2 },
|
|
820
|
+
accountScope: { categoriesOff: ["identifying"] },
|
|
821
|
+
});
|
|
822
|
+
expect(m.scope["identifying"]?.allowed).toBe(true);
|
|
823
|
+
expect(m.scope["identifying"]?.platformRequired?.rulePath).toMatch(
|
|
824
|
+
/Required \(Platform default/,
|
|
825
|
+
);
|
|
826
|
+
});
|
|
827
|
+
|
|
828
|
+
it("B2 — an authored account default binds (5b); Required bypasses it", () => {
|
|
829
|
+
const policies = seeds().map((p) =>
|
|
830
|
+
p.id === "pol-mandatory-reporting-agency-standard"
|
|
831
|
+
? { ...p, edited: true, infoScope: ["risk"] }
|
|
832
|
+
: p,
|
|
833
|
+
);
|
|
834
|
+
const r = read(
|
|
835
|
+
{
|
|
836
|
+
purpose: "mandatory_reporting",
|
|
837
|
+
sender: { accountId: A, teamId: T2 },
|
|
838
|
+
recipient: { kind: "partner", id: "tulsa_pd" },
|
|
839
|
+
},
|
|
840
|
+
policies,
|
|
841
|
+
);
|
|
842
|
+
expect(r.scope["contact"]?.allowed).toBe(false);
|
|
843
|
+
expect(r.scope["contact"]?.rulePath).toMatch(
|
|
844
|
+
/pol-mandatory-reporting-agency-standard/,
|
|
845
|
+
);
|
|
846
|
+
expect(r.scope["identifying"]?.allowed).toBe(true);
|
|
847
|
+
expect(r.scope["identifying"]?.platformRequired).not.toBeNull();
|
|
848
|
+
expect(r.scope["risk"]?.allowed).toBe(true);
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
it("H1 — heightened rows off in the account are withheld at row grain (4b); the category stands", () => {
|
|
852
|
+
const fullRows = leavesOf("instruments").filter(
|
|
853
|
+
(c) => scope.row(c)?.shareableDefault === false,
|
|
854
|
+
);
|
|
855
|
+
expect(fullRows.length).toBeGreaterThan(0);
|
|
856
|
+
const policies = seeds().map((p) =>
|
|
857
|
+
p.id === "pol-mandatory-reporting-agency-standard"
|
|
858
|
+
? { ...p, edited: true, infoScope: ["identifying", "instruments"] }
|
|
859
|
+
: p,
|
|
860
|
+
);
|
|
861
|
+
const r = read(
|
|
862
|
+
{
|
|
863
|
+
purpose: "mandatory_reporting",
|
|
864
|
+
sender: { accountId: A, teamId: T2 },
|
|
865
|
+
accountScope: { rowsOff: fullRows },
|
|
866
|
+
},
|
|
867
|
+
policies,
|
|
868
|
+
);
|
|
869
|
+
expect(r.scope["instruments"]?.allowed).toBe(true);
|
|
870
|
+
expect([...(r.scope["instruments"]?.excludedItems ?? [])].sort()).toEqual(
|
|
871
|
+
[...heightenedUnder("instruments")].sort(),
|
|
872
|
+
);
|
|
873
|
+
expect(r.scope["instruments"]?.excludedReason).toMatch(
|
|
874
|
+
/Heightened protection/,
|
|
875
|
+
);
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
it("B2-H1 — with NO account action, a policy that names Screens & assessments sends the Summary rows and never the full narratives (the codebook's CVC-236 default; four-state L109-L113, L139)", () => {
|
|
879
|
+
const policies = seeds().map((p) =>
|
|
880
|
+
p.id === "pol-mandatory-reporting-agency-standard"
|
|
881
|
+
? {
|
|
882
|
+
...p,
|
|
883
|
+
edited: true,
|
|
884
|
+
infoScope: ["identifying", "contact", "risk", "instruments"],
|
|
885
|
+
}
|
|
886
|
+
: p,
|
|
887
|
+
);
|
|
888
|
+
const r = read(
|
|
889
|
+
{
|
|
890
|
+
purpose: "mandatory_reporting",
|
|
891
|
+
sender: { accountId: A, teamId: T2 },
|
|
892
|
+
recipient: { kind: "partner", id: "tulsa_pd" },
|
|
893
|
+
},
|
|
894
|
+
policies,
|
|
895
|
+
);
|
|
896
|
+
const e = r.scope["instruments"];
|
|
897
|
+
const full = leavesOf("instruments").filter((c) => /^full_/.test(c));
|
|
898
|
+
const summary = leavesOf("instruments").filter((c) => /^summary_/.test(c));
|
|
899
|
+
expect(full.length).toBeGreaterThan(0);
|
|
900
|
+
expect(summary.length).toBeGreaterThan(0);
|
|
901
|
+
expect(e?.allowed).toBe(true);
|
|
902
|
+
for (const f of full) expect(e?.excludedItems).toContain(f);
|
|
903
|
+
for (const s2 of summary) expect(e?.excludedItems).not.toContain(s2);
|
|
904
|
+
expect(e?.excludedReason).toMatch(/Heightened protection/);
|
|
905
|
+
// The account turns the full narratives on (the grouping AND its rows — turning a grouping on
|
|
906
|
+
// does not turn on an off-by-default row beneath it): they leave.
|
|
907
|
+
const on = read(
|
|
908
|
+
{
|
|
909
|
+
purpose: "mandatory_reporting",
|
|
910
|
+
sender: { accountId: A, teamId: T2 },
|
|
911
|
+
recipient: { kind: "partner", id: "tulsa_pd" },
|
|
912
|
+
accountScope: { rowsOn: heightenedUnder("instruments") },
|
|
913
|
+
},
|
|
914
|
+
policies,
|
|
915
|
+
);
|
|
916
|
+
for (const f of full)
|
|
917
|
+
expect(on.scope["instruments"]?.excludedItems).not.toContain(f);
|
|
918
|
+
const groupingOnly = read(
|
|
919
|
+
{
|
|
920
|
+
purpose: "mandatory_reporting",
|
|
921
|
+
sender: { accountId: A, teamId: T2 },
|
|
922
|
+
recipient: { kind: "partner", id: "tulsa_pd" },
|
|
923
|
+
accountScope: { rowsOn: ["instrument_full"] },
|
|
924
|
+
},
|
|
925
|
+
policies,
|
|
926
|
+
);
|
|
927
|
+
for (const f of full)
|
|
928
|
+
expect(groupingOnly.scope["instruments"]?.excludedItems).toContain(f);
|
|
929
|
+
});
|
|
930
|
+
|
|
931
|
+
it("C relax — the Platform Admin relaxes immigration from Blocked to Default Off and an authored default names it: still withheld, by the account's Information Scope (four-state L165-L168, L190)", () => {
|
|
932
|
+
const pd = pdFor("referral", {
|
|
933
|
+
bounds: { immigration_legal_status: "default_off" },
|
|
934
|
+
version: 5,
|
|
935
|
+
});
|
|
936
|
+
expect(pd.states["immigration_legal_status"]).toBe("default_off");
|
|
937
|
+
expect(pd.blocked).not.toContain("immigration_legal_status");
|
|
938
|
+
const policies = seeds().map((p) =>
|
|
939
|
+
p.id === "pol-referral-agency-standard"
|
|
940
|
+
? {
|
|
941
|
+
...p,
|
|
942
|
+
edited: true,
|
|
943
|
+
infoScope: ["identifying", "risk", "immigration_legal_status"],
|
|
944
|
+
}
|
|
945
|
+
: p,
|
|
946
|
+
);
|
|
947
|
+
const base = {
|
|
948
|
+
scope,
|
|
949
|
+
policies,
|
|
950
|
+
platformDefault: pd,
|
|
951
|
+
sender: { accountId: A, teamId: T2 },
|
|
952
|
+
recipient: { kind: "partner", id: "tulsa_pd" } as const,
|
|
953
|
+
purpose: "referral",
|
|
954
|
+
};
|
|
955
|
+
const r = resolveShare(base);
|
|
956
|
+
expect(r.governing?.id).toBe("pol-referral-agency-standard");
|
|
957
|
+
expect(r.scope["immigration_legal_status"]?.allowed).toBe(false);
|
|
958
|
+
expect(r.scope["immigration_legal_status"]?.reason).toMatch(
|
|
959
|
+
/Information Scope/,
|
|
960
|
+
);
|
|
961
|
+
expect(r.scope["risk"]?.allowed).toBe(true);
|
|
962
|
+
// the account turns it on: the authored policy decides within the cap and it leaves
|
|
963
|
+
const on = resolveShare({
|
|
964
|
+
...base,
|
|
965
|
+
accountScope: {
|
|
966
|
+
categoriesOn: ["immigration_legal_status"],
|
|
967
|
+
rowsOn: heightenedUnder("immigration_legal_status"),
|
|
968
|
+
},
|
|
969
|
+
});
|
|
970
|
+
expect(on.scope["immigration_legal_status"]?.allowed).toBe(true);
|
|
971
|
+
// an explicit off beats an on for the same code (fail closed)
|
|
972
|
+
const both = resolveShare({
|
|
973
|
+
...base,
|
|
974
|
+
accountScope: {
|
|
975
|
+
categoriesOn: ["immigration_legal_status"],
|
|
976
|
+
categoriesOff: ["immigration_legal_status"],
|
|
977
|
+
},
|
|
978
|
+
});
|
|
979
|
+
expect(both.scope["immigration_legal_status"]?.allowed).toBe(false);
|
|
980
|
+
});
|
|
981
|
+
|
|
982
|
+
it("5c — field-group limits withhold rows of a category, never a Required category (review r1 #2)", () => {
|
|
983
|
+
const firstContact = leavesOf("contact").find(
|
|
984
|
+
(c) => scope.row(c)?.platformFloor !== true,
|
|
985
|
+
) as string;
|
|
986
|
+
const policies = seeds().map((p) =>
|
|
987
|
+
p.id === "pol-mandatory-reporting-agency-standard"
|
|
988
|
+
? {
|
|
989
|
+
...p,
|
|
990
|
+
edited: true,
|
|
991
|
+
infoScope: ["identifying", "contact"],
|
|
992
|
+
infoScopeItems: { identifying: [], contact: [firstContact] },
|
|
993
|
+
}
|
|
994
|
+
: p,
|
|
995
|
+
);
|
|
996
|
+
const r = read(
|
|
997
|
+
{ purpose: "mandatory_reporting", sender: { accountId: A, teamId: T2 } },
|
|
998
|
+
policies,
|
|
999
|
+
);
|
|
1000
|
+
expect(r.scope["identifying"]?.allowed).toBe(true);
|
|
1001
|
+
expect(r.scope["identifying"]?.excludedItems).toEqual([]);
|
|
1002
|
+
expect(r.scope["contact"]?.allowed).toBe(true);
|
|
1003
|
+
expect(r.scope["contact"]?.excludedItems).not.toContain(firstContact);
|
|
1004
|
+
expect(r.scope["contact"]?.excludedItems?.length).toBeGreaterThan(0);
|
|
1005
|
+
const all = seeds().map((p) =>
|
|
1006
|
+
p.id === "pol-referral-agency-standard"
|
|
1007
|
+
? {
|
|
1008
|
+
...p,
|
|
1009
|
+
edited: true,
|
|
1010
|
+
infoScope: ["contact"],
|
|
1011
|
+
infoScopeItems: { contact: [] },
|
|
1012
|
+
}
|
|
1013
|
+
: p,
|
|
1014
|
+
);
|
|
1015
|
+
const flip = read(
|
|
1016
|
+
{
|
|
1017
|
+
purpose: "referral",
|
|
1018
|
+
sender: { accountId: A, teamId: T2 },
|
|
1019
|
+
recipient: { kind: "partner", id: "okcpd" },
|
|
1020
|
+
},
|
|
1021
|
+
all,
|
|
1022
|
+
);
|
|
1023
|
+
expect(flip.scope["contact"]?.allowed).toBe(false); // every row withheld → the category is withheld (the group flip)
|
|
1024
|
+
expect(flip.scope["contact"]?.reason).toMatch(/Referral — agency standard/);
|
|
1025
|
+
});
|
|
1026
|
+
|
|
1027
|
+
it("4a — Blocked never reaches a Required category; the real referral seed derives sanely", () => {
|
|
1028
|
+
const pd = pdFor("mandatory_reporting", {
|
|
1029
|
+
bounds: { identifying: "never" },
|
|
1030
|
+
});
|
|
1031
|
+
expect(pd.states["identifying"]).toBe("never"); // a bound is a bound…
|
|
1032
|
+
const r = resolveShare({
|
|
1033
|
+
scope,
|
|
1034
|
+
policies: seeds(),
|
|
1035
|
+
platformDefault: { ...pd, required: ["identifying"] },
|
|
1036
|
+
sender: { teamId: T2 },
|
|
1037
|
+
recipient: { kind: "partner", id: "palomar" },
|
|
1038
|
+
purpose: "mandatory_reporting",
|
|
1039
|
+
});
|
|
1040
|
+
expect(r.scope["identifying"]?.allowed).toBe(true); // …but a category the platform REQUIRES bypasses 4a
|
|
1041
|
+
const real = pdFor("referral");
|
|
1042
|
+
expect(real.states["identifying"]).toBe("default_on");
|
|
1043
|
+
expect(real.states["immigration_legal_status"]).toBe("never");
|
|
1044
|
+
expect(real.raw).toContain("identifying");
|
|
1045
|
+
});
|
|
1046
|
+
|
|
1047
|
+
it("M1 — the purpose switch excludes the whole share, reports included; Required is not an answer on an excluded share; system alone survives", () => {
|
|
1048
|
+
const r = read({
|
|
1049
|
+
purpose: "mandatory_reporting",
|
|
1050
|
+
sender: { accountId: A, teamId: T2 },
|
|
1051
|
+
purposeOff: true,
|
|
1052
|
+
});
|
|
1053
|
+
expect(r.allowed).toBe(false);
|
|
1054
|
+
expect(r.excluded?.reason).toMatch(/disabled/);
|
|
1055
|
+
expect(r.scope["identifying"]?.allowed).toBe(false);
|
|
1056
|
+
expect(r.scope[systemCategoryOf(scope) as string]?.allowed).toBe(true);
|
|
1057
|
+
});
|
|
1058
|
+
|
|
1059
|
+
it("B3 — a Platform Admin's Blocked bound withholds a category every account had (4a), naming the default's version", () => {
|
|
1060
|
+
const legacy = ["identifying", "contact", "health_accommodation"];
|
|
1061
|
+
const before = read({
|
|
1062
|
+
purpose: "case_collaboration",
|
|
1063
|
+
sender: { accountId: A, teamId: T2 },
|
|
1064
|
+
legacyCeiling: legacy,
|
|
1065
|
+
});
|
|
1066
|
+
expect(before.scope["health_accommodation"]?.allowed).toBe(true);
|
|
1067
|
+
const after = resolveShare({
|
|
1068
|
+
scope,
|
|
1069
|
+
policies: seeds(),
|
|
1070
|
+
platformDefault: pdFor("case_collaboration", {
|
|
1071
|
+
bounds: { health_accommodation: "never" },
|
|
1072
|
+
version: 2,
|
|
1073
|
+
}),
|
|
1074
|
+
sender: { accountId: A, teamId: T2 },
|
|
1075
|
+
recipient: { kind: "partner", id: "palomar" },
|
|
1076
|
+
purpose: "case_collaboration",
|
|
1077
|
+
legacyCeiling: legacy,
|
|
1078
|
+
});
|
|
1079
|
+
expect(after.scope["health_accommodation"]?.allowed).toBe(false);
|
|
1080
|
+
expect(after.scope["health_accommodation"]?.reason).toMatch(
|
|
1081
|
+
/Blocked for this purpose by the Platform default/,
|
|
1082
|
+
);
|
|
1083
|
+
expect(after.scope["health_accommodation"]?.rulePath).toMatch(/= Blocked/);
|
|
1084
|
+
expect(after.scope["health_accommodation"]?.rulePath).toMatch(/v2/);
|
|
1085
|
+
expect(after.scope["services"]?.allowed).toBe(false); // the legacy cell chain's list stays a ceiling (review M6)
|
|
1086
|
+
});
|
|
1087
|
+
|
|
1088
|
+
it("the floor never leaves: a category made only of floor rows is withheld with the floor as the reason", () => {
|
|
1089
|
+
const r = read({
|
|
1090
|
+
purpose: "referral",
|
|
1091
|
+
sender: { accountId: A, teamId: T2 },
|
|
1092
|
+
});
|
|
1093
|
+
for (const g of liveCategories(scope)) {
|
|
1094
|
+
const e = r.scope[g];
|
|
1095
|
+
if (e === undefined) continue;
|
|
1096
|
+
for (const f of e.floorItems)
|
|
1097
|
+
expect(
|
|
1098
|
+
scope
|
|
1099
|
+
.ancestorsOf(f)
|
|
1100
|
+
.some((c) => scope.row(c)?.platformFloor === true),
|
|
1101
|
+
).toBe(true);
|
|
1102
|
+
}
|
|
1103
|
+
expect(r.scope["contact"]?.floorItems).toContain("safe_locations");
|
|
1104
|
+
expect(r.scope["contact"]?.allowed).toBe(true);
|
|
1105
|
+
});
|
|
1106
|
+
});
|
|
1107
|
+
|
|
1108
|
+
// ─── The helpers the apps adopt with ────────────────────────────────────────
|
|
1109
|
+
|
|
1110
|
+
describe("platformDefaultFor / legacyCeiling as an answer / shareRowCeiling", () => {
|
|
1111
|
+
it("platformDefaultFor derives the published starter with the platform's Required list; an unknown purpose is null", () => {
|
|
1112
|
+
const pd = platformDefaultFor(scope, "mandatory_reporting");
|
|
1113
|
+
expect(pd?.required).toEqual(["identifying"]);
|
|
1114
|
+
expect(pd?.version).toBe(1);
|
|
1115
|
+
expect(pd?.states["identifying"]).toBe("always");
|
|
1116
|
+
expect(platformDefaultFor(scope, "referral")?.required).toEqual([]);
|
|
1117
|
+
expect(platformDefaultFor(scope, "zz-unknown")).toBeNull();
|
|
1118
|
+
expect(
|
|
1119
|
+
HTI_SHARE_PLATFORM_REQUIRED_BY_PURPOSE["authority_reporting"],
|
|
1120
|
+
).toEqual(["identifying"]);
|
|
1121
|
+
});
|
|
1122
|
+
|
|
1123
|
+
it("an effectiveCeiling answer binds only from an account rule; its platform_default rung never clamps an authored policy (K13-12)", () => {
|
|
1124
|
+
const base = {
|
|
1125
|
+
purpose: "referral",
|
|
1126
|
+
sender: { accountId: A, teamId: T2 },
|
|
1127
|
+
} as const;
|
|
1128
|
+
const fromStarter = read({
|
|
1129
|
+
...base,
|
|
1130
|
+
legacyCeiling: {
|
|
1131
|
+
allowed: ["identifying"],
|
|
1132
|
+
rung: "platform_default",
|
|
1133
|
+
disabled: false,
|
|
1134
|
+
},
|
|
1135
|
+
});
|
|
1136
|
+
expect(fromStarter.scope["contact"]?.allowed).toBe(true); // the palomar link's own list binds
|
|
1137
|
+
const fromRule = read({
|
|
1138
|
+
...base,
|
|
1139
|
+
legacyCeiling: {
|
|
1140
|
+
allowed: ["identifying"],
|
|
1141
|
+
rung: "partner_rule",
|
|
1142
|
+
disabled: false,
|
|
1143
|
+
},
|
|
1144
|
+
});
|
|
1145
|
+
expect(fromRule.scope["contact"]?.allowed).toBe(false); // an account rule stays a ceiling (review M6)
|
|
1146
|
+
expect(fromRule.scope["contact"]?.reason).toMatch(/Outside the payload/);
|
|
1147
|
+
const asList = read({ ...base, legacyCeiling: ["identifying"] });
|
|
1148
|
+
expect(asList.scope["contact"]?.allowed).toBe(false);
|
|
1149
|
+
});
|
|
1150
|
+
|
|
1151
|
+
it("shareRowCeiling lists an allowed category by its code, or its rows minus the withheld ones; nothing for an excluded share", () => {
|
|
1152
|
+
const fullRows = leavesOf("instruments").filter(
|
|
1153
|
+
(c) => scope.row(c)?.shareableDefault === false,
|
|
1154
|
+
);
|
|
1155
|
+
const policies = seeds().map((p) =>
|
|
1156
|
+
p.id === "pol-mandatory-reporting-agency-standard"
|
|
1157
|
+
? { ...p, edited: true, infoScope: ["identifying", "instruments"] }
|
|
1158
|
+
: p,
|
|
1159
|
+
);
|
|
1160
|
+
const r = read(
|
|
1161
|
+
{
|
|
1162
|
+
purpose: "mandatory_reporting",
|
|
1163
|
+
sender: { accountId: A, teamId: T2 },
|
|
1164
|
+
accountScope: { rowsOff: fullRows },
|
|
1165
|
+
},
|
|
1166
|
+
policies,
|
|
1167
|
+
);
|
|
1168
|
+
const ceiling = shareRowCeiling(r, scope);
|
|
1169
|
+
expect(ceiling).toContain("identifying");
|
|
1170
|
+
expect(ceiling).not.toContain("instruments");
|
|
1171
|
+
expect(ceiling).toContain("instrument_summary"); // the surviving branch at its own grain
|
|
1172
|
+
for (const f of fullRows) expect(ceiling).not.toContain(f);
|
|
1173
|
+
expect(ceiling).not.toContain("instrument_full");
|
|
1174
|
+
expect(ceiling).not.toContain("contact");
|
|
1175
|
+
const off = read({
|
|
1176
|
+
purpose: "mandatory_reporting",
|
|
1177
|
+
sender: { accountId: A, teamId: T2 },
|
|
1178
|
+
purposeOff: true,
|
|
1179
|
+
});
|
|
1180
|
+
expect(shareRowCeiling(off, scope)).toEqual([]);
|
|
1181
|
+
});
|
|
1182
|
+
});
|
|
1183
|
+
|
|
1184
|
+
// ─── The readers ────────────────────────────────────────────────────────────
|
|
1185
|
+
|
|
1186
|
+
describe("scopeListCovers / attachmentIndexFromPolicies / matchTeamRow", () => {
|
|
1187
|
+
it("scopeListCovers reads a category by itself, an ancestor, or any row of it — never a flat indexOf (K13-14)", () => {
|
|
1188
|
+
expect(scopeListCovers(scope, ["family"], "family.identifying")).toBe(true);
|
|
1189
|
+
expect(scopeListCovers(scope, ["summary_lap"], "instruments")).toBe(true);
|
|
1190
|
+
expect(
|
|
1191
|
+
scopeListCovers(scope, ["summary_lap"], "instruments", "full_lap"),
|
|
1192
|
+
).toBe(false);
|
|
1193
|
+
expect(
|
|
1194
|
+
scopeListCovers(scope, ["instruments"], "instruments", "full_lap"),
|
|
1195
|
+
).toBe(true);
|
|
1196
|
+
// Y4 / HANDOFF K13-14 at ROW grain: a row is covered by a grouping above it, never only by
|
|
1197
|
+
// its own code (a flat `has(row)` would miss this)
|
|
1198
|
+
expect(
|
|
1199
|
+
scopeListCovers(
|
|
1200
|
+
scope,
|
|
1201
|
+
["instrument_summary"],
|
|
1202
|
+
"instruments",
|
|
1203
|
+
"summary_needs_assessment",
|
|
1204
|
+
),
|
|
1205
|
+
).toBe(true);
|
|
1206
|
+
expect(
|
|
1207
|
+
scopeListCovers(scope, ["instrument_summary"], "instruments", "full_lap"),
|
|
1208
|
+
).toBe(false);
|
|
1209
|
+
// …and through the resolver: an authored policy naming the grouping sends its rows, withholds the rest
|
|
1210
|
+
const viaGrouping = read(
|
|
1211
|
+
{ purpose: "referral", sender: { accountId: A, teamId: T2 } },
|
|
1212
|
+
seeds().map((p) =>
|
|
1213
|
+
p.id === "pol-zz8-palomar"
|
|
1214
|
+
? { ...p, infoScope: ["identifying", "instrument_summary"] }
|
|
1215
|
+
: p,
|
|
1216
|
+
),
|
|
1217
|
+
);
|
|
1218
|
+
const inst = viaGrouping.scope["instruments"];
|
|
1219
|
+
expect(inst?.allowed).toBe(true);
|
|
1220
|
+
expect(inst?.excludedItems).not.toContain("summary_needs_assessment");
|
|
1221
|
+
expect(inst?.excludedItems).toContain("full_lap");
|
|
1222
|
+
expect(scopeListCovers(scope, ["identifying"], "contact")).toBe(false);
|
|
1223
|
+
expect(scopeListCovers(scope, null, "contact")).toBe(true);
|
|
1224
|
+
expect(scopeListCovers(scope, [], "contact")).toBe(false);
|
|
1225
|
+
});
|
|
1226
|
+
|
|
1227
|
+
it("the attachment index is built from assignments only; an unknown scope governs nowhere; a retired doc is skipped", () => {
|
|
1228
|
+
const idx = attachmentIndexFromPolicies([
|
|
1229
|
+
...seeds(),
|
|
1230
|
+
{
|
|
1231
|
+
id: "pol-weird",
|
|
1232
|
+
purpose: "referral",
|
|
1233
|
+
assignments: [{ scope: "galaxy" } as unknown as { scope: "account" }],
|
|
1234
|
+
},
|
|
1235
|
+
{
|
|
1236
|
+
id: "pol-gone",
|
|
1237
|
+
purpose: "referral",
|
|
1238
|
+
active: false,
|
|
1239
|
+
assignments: [{ scope: "account" }],
|
|
1240
|
+
},
|
|
1241
|
+
]);
|
|
1242
|
+
expect(idx.agencyDefaults["referral"]).toBe("pol-referral-agency-standard");
|
|
1243
|
+
expect(idx.relationships["palomar"]?.["referral"]).toBe("pol-zz8-palomar");
|
|
1244
|
+
expect(idx.teams[T]?.["referral"]).toBe("pol-zz8-team");
|
|
1245
|
+
expect(
|
|
1246
|
+
Object.values(idx).some((m) => JSON.stringify(m).includes("pol-weird")),
|
|
1247
|
+
).toBe(false);
|
|
1248
|
+
expect(
|
|
1249
|
+
Object.values(idx).some((m) => JSON.stringify(m).includes("pol-gone")),
|
|
1250
|
+
).toBe(false);
|
|
1251
|
+
expect(attachmentIndexFromPolicies(null).agencyDefaults).toEqual({});
|
|
1252
|
+
});
|
|
1253
|
+
|
|
1254
|
+
it("matchTeamRow — one store at a time: a sibling team by its row (the sender first); a partner's team-scoped row is the team's first; all-teams takes the row whose their is absent, not a team, or this partner; share-back-only rows are dropped", () => {
|
|
1255
|
+
const pairs = [
|
|
1256
|
+
{ id: "ip-1", myTeamId: T, their: { type: "team", id: T2 } },
|
|
1257
|
+
{ id: "ip-2", myTeamId: T2, their: { type: "team", id: T } },
|
|
1258
|
+
];
|
|
1259
|
+
expect(matchTeamRow(pairs, T, { kind: "sibling_team", teamId: T2 })).toBe(
|
|
1260
|
+
"ip-1",
|
|
1261
|
+
);
|
|
1262
|
+
expect(matchTeamRow(pairs, T2, { kind: "sibling_team", teamId: T })).toBe(
|
|
1263
|
+
"ip-2",
|
|
1264
|
+
);
|
|
1265
|
+
expect(
|
|
1266
|
+
matchTeamRow(pairs, T, {
|
|
1267
|
+
kind: "sibling_team",
|
|
1268
|
+
teamId: "team-elsewhere",
|
|
1269
|
+
}),
|
|
1270
|
+
).toBeNull();
|
|
1271
|
+
// Y3 — data.js `internalPairRow` matches on `their.id` alone: a stored pair row with no
|
|
1272
|
+
// `their.type` still governs (the internal-pairs store holds only team-to-team rows)
|
|
1273
|
+
const typeless = [{ id: "ip-typeless", myTeamId: T, their: { id: T2 } }];
|
|
1274
|
+
expect(
|
|
1275
|
+
matchTeamRow(typeless, T, { kind: "sibling_team", teamId: T2 }),
|
|
1276
|
+
).toBe("ip-typeless");
|
|
1277
|
+
expect(
|
|
1278
|
+
matchTeamRow(typeless, T2, { kind: "sibling_team", teamId: T }),
|
|
1279
|
+
).toBeNull();
|
|
1280
|
+
const palomarRows = [
|
|
1281
|
+
{ id: "r-sb", myTeamId: T, their: { type: "org", id: "palomar" } },
|
|
1282
|
+
{
|
|
1283
|
+
id: "r-their-team",
|
|
1284
|
+
myTeamId: T,
|
|
1285
|
+
their: { type: "team", id: "palomar-intake" },
|
|
1286
|
+
},
|
|
1287
|
+
{ id: "r-2", myTeamId: T, their: { type: "org", id: "palomar" } },
|
|
1288
|
+
{ id: "r-3", myTeamId: T2 },
|
|
1289
|
+
];
|
|
1290
|
+
const palomar = { kind: "partner", id: "palomar" } as const;
|
|
1291
|
+
expect(
|
|
1292
|
+
matchTeamRow(palomarRows, T, palomar, { shareBackOnlyRowIds: ["r-sb"] }),
|
|
1293
|
+
).toBe("r-2");
|
|
1294
|
+
expect(
|
|
1295
|
+
matchTeamRow(palomarRows, T, palomar, {
|
|
1296
|
+
scopeMode: "team_scoped",
|
|
1297
|
+
shareBackOnlyRowIds: ["r-sb"],
|
|
1298
|
+
}),
|
|
1299
|
+
).toBe("r-their-team"); // team-scoped: the team's FIRST remaining row, whatever its `their`
|
|
1300
|
+
expect(matchTeamRow(palomarRows, T2, palomar)).toBe("r-3"); // `their` absent
|
|
1301
|
+
expect(matchTeamRow(palomarRows, T, { kind: "external" })).toBeNull();
|
|
1302
|
+
expect(matchTeamRow(palomarRows, null, palomar)).toBeNull();
|
|
1303
|
+
expect(matchTeamRow(null, T, palomar)).toBeNull();
|
|
1304
|
+
});
|
|
1305
|
+
});
|