@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,358 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ported from Thread `@thread/shared` `src/__tests__/shareReleaseTerms.test.ts` @ thread develop
|
|
3
|
+
* f021be2, adapted only for import paths (Thread's `ROI_BASIS_REASON`
|
|
4
|
+
* enum is a local two-code object; the package reads only `roi_on_file`).
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The release's terms at the share boundary (R19 / R21) — the ONE copy the
|
|
8
|
+
* api's doors and the web composer both call (Kickoff 07b; pre-review M2 /
|
|
9
|
+
* M3 / L3 were the two copies drifting).
|
|
10
|
+
*/
|
|
11
|
+
import { describe, expect, it } from "vitest";
|
|
12
|
+
import {
|
|
13
|
+
ROI_BASIS_REASON_ROI_ON_FILE,
|
|
14
|
+
ROI_WAIVER_EXEMPT_PURPOSES,
|
|
15
|
+
SHARING_METHOD,
|
|
16
|
+
endOfUtcDay,
|
|
17
|
+
isBrokeredSharingMethod,
|
|
18
|
+
isReleaseMethodExemptPurpose,
|
|
19
|
+
isReleaseTermsExemptRecipient,
|
|
20
|
+
operativeReleaseOf,
|
|
21
|
+
readReleaseMethods,
|
|
22
|
+
releaseEndDay,
|
|
23
|
+
releaseEndOfDay,
|
|
24
|
+
releaseListWords,
|
|
25
|
+
releaseListedMethods,
|
|
26
|
+
releaseMethodRefusal,
|
|
27
|
+
shareExpiryUnderRelease,
|
|
28
|
+
shareMethodOf,
|
|
29
|
+
sharingMethodLabel,
|
|
30
|
+
} from "../index.js";
|
|
31
|
+
|
|
32
|
+
/** Thread's two ROI_BASIS_REASON codes this suite names (`constants/ic.ts`). */
|
|
33
|
+
const ROI_BASIS_REASON = {
|
|
34
|
+
ROI_ON_FILE: ROI_BASIS_REASON_ROI_ON_FILE,
|
|
35
|
+
// CVC-331 convergence owed (Kickoff 12): Thread's rung-3 reason, kept.
|
|
36
|
+
SAME_AGENCY: "same_agency",
|
|
37
|
+
} as const;
|
|
38
|
+
|
|
39
|
+
const RELEASE = {
|
|
40
|
+
approvedSharingMethods: [SHARING_METHOD.CASE_SHARE, SHARING_METHOD.EMAIL],
|
|
41
|
+
expirationDate: "2027-04-17T00:00:00.000Z",
|
|
42
|
+
};
|
|
43
|
+
const REPORT_PURPOSE = ROI_WAIVER_EXEMPT_PURPOSES[0];
|
|
44
|
+
|
|
45
|
+
describe("shareMethodOf / isBrokeredSharingMethod", () => {
|
|
46
|
+
it("reads an absent method as CaseShare", () => {
|
|
47
|
+
expect(shareMethodOf(undefined)).toBe(SHARING_METHOD.CASE_SHARE);
|
|
48
|
+
expect(shareMethodOf(null)).toBe(SHARING_METHOD.CASE_SHARE);
|
|
49
|
+
expect(shareMethodOf("")).toBe(SHARING_METHOD.CASE_SHARE);
|
|
50
|
+
expect(shareMethodOf(SHARING_METHOD.FAX)).toBe(SHARING_METHOD.FAX);
|
|
51
|
+
});
|
|
52
|
+
it("only the platform-delivered methods are brokered (R76)", () => {
|
|
53
|
+
expect(isBrokeredSharingMethod(SHARING_METHOD.CASE_SHARE)).toBe(true);
|
|
54
|
+
expect(isBrokeredSharingMethod(SHARING_METHOD.MAGIC_LINK)).toBe(true);
|
|
55
|
+
expect(isBrokeredSharingMethod(undefined)).toBe(true);
|
|
56
|
+
expect(isBrokeredSharingMethod(SHARING_METHOD.EMAIL)).toBe(false);
|
|
57
|
+
expect(isBrokeredSharingMethod(SHARING_METHOD.FAX)).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("exemptions", () => {
|
|
62
|
+
it("an own-agency send is exempt from every term", () => {
|
|
63
|
+
expect(
|
|
64
|
+
isReleaseTermsExemptRecipient({
|
|
65
|
+
senderAgencyId: "a1",
|
|
66
|
+
recipientAgencyId: "a1",
|
|
67
|
+
}),
|
|
68
|
+
).toBe(true);
|
|
69
|
+
expect(
|
|
70
|
+
isReleaseTermsExemptRecipient({
|
|
71
|
+
senderAgencyId: "a1",
|
|
72
|
+
recipientAgencyId: "a2",
|
|
73
|
+
}),
|
|
74
|
+
).toBe(false);
|
|
75
|
+
});
|
|
76
|
+
it("a reporting purpose is exempt from the method rule", () => {
|
|
77
|
+
expect(REPORT_PURPOSE).toBeDefined();
|
|
78
|
+
expect(isReleaseMethodExemptPurpose(REPORT_PURPOSE)).toBe(true);
|
|
79
|
+
expect(isReleaseMethodExemptPurpose(undefined)).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe("operativeReleaseOf", () => {
|
|
84
|
+
const base = { senderAgencyId: "a1", recipientAgencyId: "a2" };
|
|
85
|
+
it("binds the cited release only on the roi_on_file rung", () => {
|
|
86
|
+
expect(
|
|
87
|
+
operativeReleaseOf({
|
|
88
|
+
...base,
|
|
89
|
+
release: RELEASE,
|
|
90
|
+
roiBasis: { reason: ROI_BASIS_REASON.ROI_ON_FILE },
|
|
91
|
+
}),
|
|
92
|
+
).toBe(RELEASE);
|
|
93
|
+
expect(
|
|
94
|
+
operativeReleaseOf({
|
|
95
|
+
...base,
|
|
96
|
+
release: RELEASE,
|
|
97
|
+
roiBasis: { reason: ROI_BASIS_REASON.SAME_AGENCY },
|
|
98
|
+
}),
|
|
99
|
+
).toBeUndefined();
|
|
100
|
+
});
|
|
101
|
+
it("no release, or an own-agency send, binds nothing", () => {
|
|
102
|
+
const onFile = { reason: ROI_BASIS_REASON.ROI_ON_FILE };
|
|
103
|
+
expect(
|
|
104
|
+
operativeReleaseOf({ ...base, release: null, roiBasis: onFile }),
|
|
105
|
+
).toBeUndefined();
|
|
106
|
+
expect(
|
|
107
|
+
operativeReleaseOf({
|
|
108
|
+
senderAgencyId: "a1",
|
|
109
|
+
recipientAgencyId: "a1",
|
|
110
|
+
release: RELEASE,
|
|
111
|
+
roiBasis: onFile,
|
|
112
|
+
}),
|
|
113
|
+
).toBeUndefined();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe("R19 — releaseListedMethods / releaseMethodRefusal", () => {
|
|
118
|
+
it("an empty or absent list restricts nothing", () => {
|
|
119
|
+
expect(releaseListedMethods({ approvedSharingMethods: [] })).toBeNull();
|
|
120
|
+
expect(releaseListedMethods({})).toBeNull();
|
|
121
|
+
expect(releaseListedMethods(undefined)).toBeNull();
|
|
122
|
+
expect(
|
|
123
|
+
releaseMethodRefusal({
|
|
124
|
+
method: SHARING_METHOD.FAX,
|
|
125
|
+
release: { approvedSharingMethods: [] },
|
|
126
|
+
sharePurpose: undefined,
|
|
127
|
+
}),
|
|
128
|
+
).toBeNull();
|
|
129
|
+
});
|
|
130
|
+
it("reads CVC-332 tokens and the old spellings into the share-method space, once each", () => {
|
|
131
|
+
expect(
|
|
132
|
+
releaseListedMethods({
|
|
133
|
+
approvedSharingMethods: [
|
|
134
|
+
"thread_caseshare",
|
|
135
|
+
SHARING_METHOD.CASE_SHARE,
|
|
136
|
+
"thread_magic_link",
|
|
137
|
+
SHARING_METHOD.EMAIL,
|
|
138
|
+
],
|
|
139
|
+
}),
|
|
140
|
+
).toEqual([
|
|
141
|
+
SHARING_METHOD.CASE_SHARE,
|
|
142
|
+
SHARING_METHOD.MAGIC_LINK,
|
|
143
|
+
SHARING_METHOD.EMAIL,
|
|
144
|
+
]);
|
|
145
|
+
// A release written with the CVC-332 token allows the share it names.
|
|
146
|
+
expect(
|
|
147
|
+
releaseMethodRefusal({
|
|
148
|
+
method: SHARING_METHOD.CASE_SHARE,
|
|
149
|
+
release: { approvedSharingMethods: ["thread_caseshare"] },
|
|
150
|
+
sharePurpose: undefined,
|
|
151
|
+
}),
|
|
152
|
+
).toBeNull();
|
|
153
|
+
expect(
|
|
154
|
+
releaseMethodRefusal({
|
|
155
|
+
method: undefined,
|
|
156
|
+
release: { approvedSharingMethods: ["thread_caseshare"] },
|
|
157
|
+
sharePurpose: undefined,
|
|
158
|
+
}),
|
|
159
|
+
).toBeNull();
|
|
160
|
+
});
|
|
161
|
+
it("a release stored with ONLY the old spellings still allows the shares it allowed before", () => {
|
|
162
|
+
// Literal old spellings, never the CVC-332 tokens: this test fails if
|
|
163
|
+
// reading the old spellings is ever dropped.
|
|
164
|
+
expect(
|
|
165
|
+
releaseListedMethods({ approvedSharingMethods: ["case_share"] }),
|
|
166
|
+
).toEqual([SHARING_METHOD.CASE_SHARE]);
|
|
167
|
+
expect(
|
|
168
|
+
releaseListedMethods({ approvedSharingMethods: ["magic_link"] }),
|
|
169
|
+
).toEqual([SHARING_METHOD.MAGIC_LINK]);
|
|
170
|
+
// `["case_share"]` allows a CaseShare, and a share that names no method.
|
|
171
|
+
for (const method of [SHARING_METHOD.CASE_SHARE, undefined]) {
|
|
172
|
+
expect(
|
|
173
|
+
releaseMethodRefusal({
|
|
174
|
+
method,
|
|
175
|
+
release: { approvedSharingMethods: ["case_share"] },
|
|
176
|
+
sharePurpose: undefined,
|
|
177
|
+
}),
|
|
178
|
+
).toBeNull();
|
|
179
|
+
}
|
|
180
|
+
// `["magic_link"]` allows a magic link.
|
|
181
|
+
expect(
|
|
182
|
+
releaseMethodRefusal({
|
|
183
|
+
method: SHARING_METHOD.MAGIC_LINK,
|
|
184
|
+
release: { approvedSharingMethods: ["magic_link"] },
|
|
185
|
+
sharePurpose: undefined,
|
|
186
|
+
}),
|
|
187
|
+
).toBeNull();
|
|
188
|
+
// The old spellings read as their CVC-332 tokens (the wire to PAVE and
|
|
189
|
+
// every token reader) — none is left unrecognized.
|
|
190
|
+
expect(readReleaseMethods(["case_share", "magic_link"])).toEqual({
|
|
191
|
+
methods: ["thread_caseshare", "thread_magic_link"],
|
|
192
|
+
unrecognized: [],
|
|
193
|
+
});
|
|
194
|
+
// `["magic_link"]` still refuses a method it does not list.
|
|
195
|
+
expect(
|
|
196
|
+
releaseMethodRefusal({
|
|
197
|
+
method: SHARING_METHOD.CASE_SHARE,
|
|
198
|
+
release: { approvedSharingMethods: ["magic_link"] },
|
|
199
|
+
sharePurpose: undefined,
|
|
200
|
+
}),
|
|
201
|
+
).not.toBeNull();
|
|
202
|
+
});
|
|
203
|
+
it("every listed string counts, an unknown one included", () => {
|
|
204
|
+
expect(
|
|
205
|
+
releaseListedMethods({ approvedSharingMethods: ["legacy_courier"] }),
|
|
206
|
+
).toEqual(["legacy_courier"]);
|
|
207
|
+
});
|
|
208
|
+
it("allows a listed method and refuses an unlisted one", () => {
|
|
209
|
+
expect(
|
|
210
|
+
releaseMethodRefusal({
|
|
211
|
+
method: SHARING_METHOD.EMAIL,
|
|
212
|
+
release: RELEASE,
|
|
213
|
+
sharePurpose: undefined,
|
|
214
|
+
}),
|
|
215
|
+
).toBeNull();
|
|
216
|
+
const refusal = releaseMethodRefusal({
|
|
217
|
+
method: SHARING_METHOD.MAGIC_LINK,
|
|
218
|
+
release: RELEASE,
|
|
219
|
+
sharePurpose: undefined,
|
|
220
|
+
});
|
|
221
|
+
expect(refusal).toContain(
|
|
222
|
+
`doesn't allow sending by ${sharingMethodLabel(SHARING_METHOD.MAGIC_LINK)}`,
|
|
223
|
+
);
|
|
224
|
+
expect(refusal).toContain(
|
|
225
|
+
releaseListWords([
|
|
226
|
+
sharingMethodLabel(SHARING_METHOD.CASE_SHARE),
|
|
227
|
+
sharingMethodLabel(SHARING_METHOD.EMAIL),
|
|
228
|
+
]),
|
|
229
|
+
);
|
|
230
|
+
});
|
|
231
|
+
it("an absent method is CaseShare", () => {
|
|
232
|
+
expect(
|
|
233
|
+
releaseMethodRefusal({
|
|
234
|
+
method: undefined,
|
|
235
|
+
release: RELEASE,
|
|
236
|
+
sharePurpose: undefined,
|
|
237
|
+
}),
|
|
238
|
+
).toBeNull();
|
|
239
|
+
});
|
|
240
|
+
it("no operative release, or a reporting purpose, never refuses", () => {
|
|
241
|
+
expect(
|
|
242
|
+
releaseMethodRefusal({
|
|
243
|
+
method: SHARING_METHOD.FAX,
|
|
244
|
+
release: undefined,
|
|
245
|
+
sharePurpose: undefined,
|
|
246
|
+
}),
|
|
247
|
+
).toBeNull();
|
|
248
|
+
expect(
|
|
249
|
+
releaseMethodRefusal({
|
|
250
|
+
method: SHARING_METHOD.FAX,
|
|
251
|
+
release: RELEASE,
|
|
252
|
+
sharePurpose: REPORT_PURPOSE,
|
|
253
|
+
}),
|
|
254
|
+
).toBeNull();
|
|
255
|
+
});
|
|
256
|
+
it("releaseListWords joins with commas and a final 'and'", () => {
|
|
257
|
+
expect(releaseListWords([])).toBe("");
|
|
258
|
+
expect(releaseListWords(["A"])).toBe("A");
|
|
259
|
+
expect(releaseListWords(["A", "B"])).toBe("A and B");
|
|
260
|
+
expect(releaseListWords(["A", "B", "C"])).toBe("A, B and C");
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
describe("R21 — the end of the release's end day", () => {
|
|
265
|
+
it("endOfUtcDay is the last instant of the UTC day", () => {
|
|
266
|
+
expect(
|
|
267
|
+
endOfUtcDay(new Date("2027-04-17T00:00:00.000Z")).toISOString(),
|
|
268
|
+
).toBe("2027-04-17T23:59:59.999Z");
|
|
269
|
+
});
|
|
270
|
+
it("reads midnight and end-of-day stores as the same day", () => {
|
|
271
|
+
expect(releaseEndDay({ expirationDate: "2027-04-17T00:00:00.000Z" })).toBe(
|
|
272
|
+
"2027-04-17",
|
|
273
|
+
);
|
|
274
|
+
expect(releaseEndDay({ expirationDate: "2027-04-17T23:59:59.999Z" })).toBe(
|
|
275
|
+
"2027-04-17",
|
|
276
|
+
);
|
|
277
|
+
expect(releaseEndDay({ expirationDate: "2027-04-17" })).toBe("2027-04-17");
|
|
278
|
+
expect(releaseEndOfDay({ expirationDate: null })).toBeNull();
|
|
279
|
+
expect(releaseEndDay({ expirationDate: "not a date" })).toBeNull();
|
|
280
|
+
expect(releaseEndDay(undefined)).toBeNull();
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
describe("R21 — shareExpiryUnderRelease", () => {
|
|
285
|
+
const cs = SHARING_METHOD.CASE_SHARE;
|
|
286
|
+
it("a blank date takes the end of the release's end day", () => {
|
|
287
|
+
const d = shareExpiryUnderRelease({
|
|
288
|
+
method: cs,
|
|
289
|
+
expirationDate: null,
|
|
290
|
+
noTimeLimit: false,
|
|
291
|
+
release: RELEASE,
|
|
292
|
+
});
|
|
293
|
+
expect(d.kind).toBe("ok");
|
|
294
|
+
if (d.kind !== "ok") return;
|
|
295
|
+
expect(d.fromRelease).toBe(true);
|
|
296
|
+
expect(d.expirationDate?.toISOString()).toBe("2027-04-17T23:59:59.999Z");
|
|
297
|
+
expect(d.noTimeLimit).toBe(false);
|
|
298
|
+
});
|
|
299
|
+
it("no time limit also takes the release's end", () => {
|
|
300
|
+
const d = shareExpiryUnderRelease({
|
|
301
|
+
method: cs,
|
|
302
|
+
expirationDate: "2030-01-01",
|
|
303
|
+
noTimeLimit: true,
|
|
304
|
+
release: RELEASE,
|
|
305
|
+
});
|
|
306
|
+
expect(d.kind === "ok" && d.fromRelease).toBe(true);
|
|
307
|
+
});
|
|
308
|
+
it("the release's own end day is allowed, a later day is refused", () => {
|
|
309
|
+
expect(
|
|
310
|
+
shareExpiryUnderRelease({
|
|
311
|
+
method: cs,
|
|
312
|
+
expirationDate: "2027-04-17T23:59:59.999Z",
|
|
313
|
+
noTimeLimit: false,
|
|
314
|
+
release: RELEASE,
|
|
315
|
+
}).kind,
|
|
316
|
+
).toBe("ok");
|
|
317
|
+
const refused = shareExpiryUnderRelease({
|
|
318
|
+
method: cs,
|
|
319
|
+
expirationDate: "2027-04-18",
|
|
320
|
+
noTimeLimit: false,
|
|
321
|
+
release: RELEASE,
|
|
322
|
+
});
|
|
323
|
+
expect(refused.kind).toBe("refused");
|
|
324
|
+
if (refused.kind !== "refused") return;
|
|
325
|
+
expect(refused.shareDay).toBe("2027-04-18");
|
|
326
|
+
expect(refused.releaseDay).toBe("2027-04-17");
|
|
327
|
+
expect(refused.message).toContain("never outlives its release");
|
|
328
|
+
});
|
|
329
|
+
it("an earlier picked day is kept, with the release's end alongside", () => {
|
|
330
|
+
const d = shareExpiryUnderRelease({
|
|
331
|
+
method: cs,
|
|
332
|
+
expirationDate: "2027-01-01",
|
|
333
|
+
noTimeLimit: false,
|
|
334
|
+
release: RELEASE,
|
|
335
|
+
});
|
|
336
|
+
expect(d.kind).toBe("ok");
|
|
337
|
+
if (d.kind !== "ok") return;
|
|
338
|
+
expect(d.fromRelease).toBe(false);
|
|
339
|
+
expect(d.releaseEnd?.toISOString()).toBe("2027-04-17T23:59:59.999Z");
|
|
340
|
+
});
|
|
341
|
+
it("a recorded method, or no end date on the release, is unbounded", () => {
|
|
342
|
+
for (const input of [
|
|
343
|
+
{ method: SHARING_METHOD.EMAIL, release: RELEASE },
|
|
344
|
+
{ method: cs, release: { approvedSharingMethods: [] } },
|
|
345
|
+
{ method: cs, release: undefined },
|
|
346
|
+
]) {
|
|
347
|
+
const d = shareExpiryUnderRelease({
|
|
348
|
+
...input,
|
|
349
|
+
expirationDate: "2030-01-01",
|
|
350
|
+
noTimeLimit: false,
|
|
351
|
+
});
|
|
352
|
+
expect(d.kind).toBe("ok");
|
|
353
|
+
if (d.kind !== "ok") return;
|
|
354
|
+
expect(d.fromRelease).toBe(false);
|
|
355
|
+
expect(d.releaseEnd).toBeNull();
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
});
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ported from Thread `@thread/shared` `src/__tests__/roiPosture.test.ts` @ thread develop
|
|
3
|
+
* f021be2, adapted only for import paths (the `readAuthoredRoiPosture` and
|
|
4
|
+
* `resolveSenderRoiPosture` blocks), plus `vspReleasePosture` from
|
|
5
|
+
* `agencyVspSignal.test.ts` L76-L81. NOT ported: the `resolveShareRoiBasis`
|
|
6
|
+
* block — the basis ladder is not lifted (sort report PR-4b) and those cases
|
|
7
|
+
* stay in Thread.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* th-u142w — the sending account's AUTHORED release posture sits ABOVE the
|
|
11
|
+
* VSP rung (canon `roiPostureFor`, prototype `d85f05b7`
|
|
12
|
+
* HTI-LEADS-PAVE-Thread-prototype.html L329257-L329319; platform-prototype
|
|
13
|
+
* `a6f1f3a5` src/data.js L51877-L51904): authored wins in both directions,
|
|
14
|
+
* the affirmed VSP flag is the fallback (VSP-TRISTATE: only an affirmed
|
|
15
|
+
* `false` waives), a team override only tightens, and a bad stored value
|
|
16
|
+
* reads exactly as canon reads it — an invalid `agencyDefault` is
|
|
17
|
+
* un-authored (the VSP rung decides), an invalid team value ignores that
|
|
18
|
+
* team (coordinator ruling 2026-10-13: same answer as canon, the platform
|
|
19
|
+
* and PAVE for the same data).
|
|
20
|
+
*/
|
|
21
|
+
import { describe, expect, it } from "vitest";
|
|
22
|
+
import {
|
|
23
|
+
readAuthoredRoiPosture,
|
|
24
|
+
resolveAgencyRoiPosture,
|
|
25
|
+
resolveSenderRoiPosture,
|
|
26
|
+
senderRoiPostureForTeam,
|
|
27
|
+
vspReleasePosture,
|
|
28
|
+
} from "../index.js";
|
|
29
|
+
|
|
30
|
+
const TEAM = "64e4ff1c2a7dcd9cb5f4a0aa";
|
|
31
|
+
const OTHER_TEAM = "64e4ff1c2a7dcd9cb5f4a0bb";
|
|
32
|
+
|
|
33
|
+
const posture = (
|
|
34
|
+
roiPolicy: unknown,
|
|
35
|
+
affirmedVsp: boolean | null,
|
|
36
|
+
sendingTeamId?: string,
|
|
37
|
+
) =>
|
|
38
|
+
resolveSenderRoiPosture({
|
|
39
|
+
authored: readAuthoredRoiPosture(roiPolicy),
|
|
40
|
+
affirmedVsp,
|
|
41
|
+
sendingTeamId,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Canon's own read of a stored slice, transcribed (monolith L329297-L329306;
|
|
46
|
+
* platform data.js L51883 / L51899) — the oracle every bad-value case is
|
|
47
|
+
* pinned against.
|
|
48
|
+
*/
|
|
49
|
+
function canonReads(
|
|
50
|
+
slice: unknown,
|
|
51
|
+
affirmedVsp: boolean | null,
|
|
52
|
+
teamId?: string,
|
|
53
|
+
): "required" | "waived" {
|
|
54
|
+
const doc = (slice || null) as Record<string, unknown> | null;
|
|
55
|
+
const derived = affirmedVsp === false ? "waived" : "required";
|
|
56
|
+
const def = doc ? doc.agencyDefault : undefined;
|
|
57
|
+
const authored = def === "required" || def === "waived" ? def : null;
|
|
58
|
+
let p: "required" | "waived" = authored || derived;
|
|
59
|
+
const overrides =
|
|
60
|
+
(doc && (doc.teamOverrides as Record<string, unknown>)) || {};
|
|
61
|
+
if (teamId && p === "waived" && doc && overrides[teamId] === "required") {
|
|
62
|
+
p = "required";
|
|
63
|
+
}
|
|
64
|
+
return p;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
describe("readAuthoredRoiPosture — the platform `agencies.roiPolicy` shape, read canon's way", () => {
|
|
68
|
+
it("absent: no field, or null", () => {
|
|
69
|
+
expect(readAuthoredRoiPosture(undefined)).toEqual({
|
|
70
|
+
present: false,
|
|
71
|
+
agencyDefault: null,
|
|
72
|
+
requiredTeamKeys: [],
|
|
73
|
+
issues: [],
|
|
74
|
+
});
|
|
75
|
+
expect(readAuthoredRoiPosture(null).present).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("the platform writer's shapes, incl. a cleared default", () => {
|
|
79
|
+
expect(
|
|
80
|
+
readAuthoredRoiPosture({
|
|
81
|
+
agencyDefault: "waived",
|
|
82
|
+
teamOverrides: { [TEAM]: "required" },
|
|
83
|
+
}),
|
|
84
|
+
).toEqual({
|
|
85
|
+
present: true,
|
|
86
|
+
agencyDefault: "waived",
|
|
87
|
+
requiredTeamKeys: [TEAM],
|
|
88
|
+
issues: [],
|
|
89
|
+
});
|
|
90
|
+
// `setRoiPolicy` $unsets a cleared default; the schema allows null.
|
|
91
|
+
expect(readAuthoredRoiPosture({ teamOverrides: {} })).toMatchObject({
|
|
92
|
+
agencyDefault: null,
|
|
93
|
+
issues: [],
|
|
94
|
+
});
|
|
95
|
+
expect(readAuthoredRoiPosture({ agencyDefault: null })).toMatchObject({
|
|
96
|
+
agencyDefault: null,
|
|
97
|
+
issues: [],
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("an invalid agencyDefault reads as un-authored, and is reported", () => {
|
|
102
|
+
for (const def of ["Waived", "off", false, 1, {}]) {
|
|
103
|
+
expect(
|
|
104
|
+
readAuthoredRoiPosture({ agencyDefault: def }),
|
|
105
|
+
JSON.stringify(def),
|
|
106
|
+
).toMatchObject({
|
|
107
|
+
present: true,
|
|
108
|
+
agencyDefault: null,
|
|
109
|
+
issues: ["agency_default_invalid"],
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("an invalid team value ignores THAT team only, and is reported", () => {
|
|
115
|
+
expect(
|
|
116
|
+
readAuthoredRoiPosture({
|
|
117
|
+
agencyDefault: "waived",
|
|
118
|
+
teamOverrides: { [TEAM]: "waived", [OTHER_TEAM]: "required" },
|
|
119
|
+
}),
|
|
120
|
+
).toEqual({
|
|
121
|
+
present: true,
|
|
122
|
+
agencyDefault: "waived",
|
|
123
|
+
requiredTeamKeys: [OTHER_TEAM],
|
|
124
|
+
issues: ["team_override_value_invalid"],
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("a non-object slice / teamOverrides reads as nothing authored, and is reported", () => {
|
|
129
|
+
expect(readAuthoredRoiPosture("waived")).toMatchObject({
|
|
130
|
+
agencyDefault: null,
|
|
131
|
+
requiredTeamKeys: [],
|
|
132
|
+
issues: ["roi_policy_not_object"],
|
|
133
|
+
});
|
|
134
|
+
expect(
|
|
135
|
+
readAuthoredRoiPosture({
|
|
136
|
+
agencyDefault: "required",
|
|
137
|
+
teamOverrides: [TEAM],
|
|
138
|
+
}),
|
|
139
|
+
).toMatchObject({
|
|
140
|
+
agencyDefault: "required",
|
|
141
|
+
requiredTeamKeys: [],
|
|
142
|
+
issues: ["team_overrides_not_object"],
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe("resolveSenderRoiPosture — authored > VSP > team tighten-only", () => {
|
|
148
|
+
it("authored waived beats a never-captured VSP answer (and an affirmed VSP)", () => {
|
|
149
|
+
expect(posture({ agencyDefault: "waived" }, null)).toMatchObject({
|
|
150
|
+
posture: "waived",
|
|
151
|
+
required: false,
|
|
152
|
+
source: "authored",
|
|
153
|
+
derivedDefault: "required",
|
|
154
|
+
});
|
|
155
|
+
expect(posture({ agencyDefault: "waived" }, true)).toMatchObject({
|
|
156
|
+
posture: "waived",
|
|
157
|
+
source: "authored",
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("authored required beats an affirmed-false VSP answer", () => {
|
|
162
|
+
expect(posture({ agencyDefault: "required" }, false)).toMatchObject({
|
|
163
|
+
posture: "required",
|
|
164
|
+
required: true,
|
|
165
|
+
source: "authored",
|
|
166
|
+
derivedDefault: "waived",
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("a team override only tightens", () => {
|
|
171
|
+
const doc = {
|
|
172
|
+
agencyDefault: "waived",
|
|
173
|
+
teamOverrides: { [TEAM]: "required" },
|
|
174
|
+
};
|
|
175
|
+
expect(posture(doc, null, TEAM)).toMatchObject({
|
|
176
|
+
posture: "required",
|
|
177
|
+
source: "team_override",
|
|
178
|
+
});
|
|
179
|
+
// Never another team, and never with no sending team (canon's gating
|
|
180
|
+
// sites pass none).
|
|
181
|
+
expect(posture(doc, null, OTHER_TEAM)).toMatchObject({
|
|
182
|
+
posture: "waived",
|
|
183
|
+
source: "authored",
|
|
184
|
+
});
|
|
185
|
+
expect(posture(doc, null)).toMatchObject({ posture: "waived" });
|
|
186
|
+
// Tightens a VSP-derived waiver too.
|
|
187
|
+
expect(
|
|
188
|
+
posture({ teamOverrides: { [TEAM]: "required" } }, false, TEAM),
|
|
189
|
+
).toMatchObject({ posture: "required", source: "team_override" });
|
|
190
|
+
// Never relaxes a required posture — a team "waived" value is ignored,
|
|
191
|
+
// and a "required" one on a required posture changes nothing.
|
|
192
|
+
expect(
|
|
193
|
+
posture(
|
|
194
|
+
{ agencyDefault: "required", teamOverrides: { [TEAM]: "waived" } },
|
|
195
|
+
false,
|
|
196
|
+
TEAM,
|
|
197
|
+
),
|
|
198
|
+
).toMatchObject({ posture: "required", source: "authored" });
|
|
199
|
+
expect(
|
|
200
|
+
posture(
|
|
201
|
+
{ agencyDefault: "required", teamOverrides: { [TEAM]: "required" } },
|
|
202
|
+
false,
|
|
203
|
+
TEAM,
|
|
204
|
+
),
|
|
205
|
+
).toMatchObject({ posture: "required", source: "authored" });
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it("an absent authored posture falls to the VSP rung (VSP-TRISTATE: affirmed false only)", () => {
|
|
209
|
+
for (const raw of [undefined, null, {}, { agencyDefault: null }]) {
|
|
210
|
+
expect(posture(raw, false), JSON.stringify(raw)).toMatchObject({
|
|
211
|
+
posture: "waived",
|
|
212
|
+
source: "derived_vsp",
|
|
213
|
+
});
|
|
214
|
+
expect(posture(raw, true).posture).toBe("required");
|
|
215
|
+
expect(posture(raw, null).posture).toBe("required");
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("a malformed authored posture falls to the VSP rung exactly as canon does", () => {
|
|
220
|
+
const slices: unknown[] = [
|
|
221
|
+
"waived",
|
|
222
|
+
["waived"],
|
|
223
|
+
42,
|
|
224
|
+
{ agencyDefault: "Waived" },
|
|
225
|
+
{ agencyDefault: "off", teamOverrides: { [TEAM]: "required" } },
|
|
226
|
+
{ agencyDefault: "waived", teamOverrides: { [TEAM]: "waived" } },
|
|
227
|
+
{ agencyDefault: "waived", teamOverrides: "required" },
|
|
228
|
+
{ agencyDefault: false, teamOverrides: { [TEAM]: true } },
|
|
229
|
+
];
|
|
230
|
+
for (const slice of slices) {
|
|
231
|
+
for (const vsp of [false, true, null]) {
|
|
232
|
+
for (const team of [undefined, TEAM]) {
|
|
233
|
+
expect(
|
|
234
|
+
posture(slice, vsp, team).posture,
|
|
235
|
+
`${JSON.stringify(slice)} vsp=${vsp} team=${team}`,
|
|
236
|
+
).toBe(canonReads(slice, vsp, team));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// The cases the ruling names: an invalid default is un-authored, so an
|
|
241
|
+
// affirmed non-VSP WAIVES (canon) and a never-captured one REQUIRES.
|
|
242
|
+
expect(posture({ agencyDefault: "Waived" }, false)).toMatchObject({
|
|
243
|
+
posture: "waived",
|
|
244
|
+
source: "derived_vsp",
|
|
245
|
+
});
|
|
246
|
+
expect(posture({ agencyDefault: "Waived" }, null).posture).toBe("required");
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("the composer's view applies the team rung with the same function", () => {
|
|
250
|
+
const authored = readAuthoredRoiPosture({
|
|
251
|
+
agencyDefault: "waived",
|
|
252
|
+
teamOverrides: { [TEAM]: "required" },
|
|
253
|
+
});
|
|
254
|
+
const view = {
|
|
255
|
+
agency: resolveAgencyRoiPosture({ authored, affirmedVsp: null }),
|
|
256
|
+
tightenedTeamIds: authored.requiredTeamKeys,
|
|
257
|
+
};
|
|
258
|
+
expect(senderRoiPostureForTeam(view, TEAM)).toEqual(
|
|
259
|
+
resolveSenderRoiPosture({
|
|
260
|
+
authored,
|
|
261
|
+
affirmedVsp: null,
|
|
262
|
+
sendingTeamId: TEAM,
|
|
263
|
+
}),
|
|
264
|
+
);
|
|
265
|
+
expect(senderRoiPostureForTeam(view, OTHER_TEAM).required).toBe(false);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it("every answer carries a coded rule path", () => {
|
|
269
|
+
expect(posture({ agencyDefault: "waived" }, null).rulePath).toMatch(
|
|
270
|
+
/agencyDefault=waived/,
|
|
271
|
+
);
|
|
272
|
+
expect(posture(undefined, null).rulePath).toMatch(/never captured/);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
// Thread agencyVspSignal.test.ts L76-L81 (the posture half; the gate's
|
|
277
|
+
// three-way status stays with Thread's agency read).
|
|
278
|
+
describe("vspReleasePosture", () => {
|
|
279
|
+
it("true → required, false → waived, null → required", () => {
|
|
280
|
+
expect(vspReleasePosture(true)).toBe("required");
|
|
281
|
+
expect(vspReleasePosture(false)).toBe("waived");
|
|
282
|
+
expect(vspReleasePosture(null)).toBe("required");
|
|
283
|
+
});
|
|
284
|
+
});
|