@htilabs/platform-common-models 0.34.0 → 0.36.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 +135 -0
- package/dist/constants/index.cjs +2 -0
- package/dist/constants/index.cjs.map +1 -1
- package/dist/constants/index.js +2 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/{cvcEntry-DAuhe0cd.d.cts → cvcEntry-BqAGctqK.d.cts} +36 -36
- package/dist/{cvcEntry-DAuhe0cd.d.ts → cvcEntry-BqAGctqK.d.ts} +36 -36
- package/dist/{index-1pWiqEBC.d.cts → index-BTqHP4DM.d.cts} +1 -1
- package/dist/{index-uz57Fic9.d.ts → index-Dr6GBCoY.d.ts} +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/models/index.d.cts +2 -2
- package/dist/models/index.d.ts +2 -2
- package/dist/org-directory/index.cjs +4 -3
- package/dist/org-directory/index.cjs.map +1 -1
- package/dist/org-directory/index.d.cts +22 -6
- package/dist/org-directory/index.d.ts +22 -6
- package/dist/org-directory/index.js +4 -3
- package/dist/org-directory/index.js.map +1 -1
- package/dist/points-of-contact/index.cjs +6 -3
- package/dist/points-of-contact/index.cjs.map +1 -1
- package/dist/points-of-contact/index.js +6 -3
- package/dist/points-of-contact/index.js.map +1 -1
- package/dist/schemas/index.d.cts +11 -11
- package/dist/schemas/index.d.ts +11 -11
- package/dist/share-review/index.cjs +301 -0
- package/dist/share-review/index.cjs.map +1 -0
- package/dist/share-review/index.d.cts +431 -0
- package/dist/share-review/index.d.ts +431 -0
- package/dist/share-review/index.js +263 -0
- package/dist/share-review/index.js.map +1 -0
- package/package.json +11 -1
- package/src/__sot__/README.md +2 -0
- package/src/__sot__/captureConflictSemantics.pin.json +156 -0
- package/src/generated/captureConflictSemantics.ts +200 -0
- package/src/orgDirectory/__tests__/orgDirectory.test.ts +60 -0
- package/src/orgDirectory/rules.ts +26 -9
- package/src/pointsOfContact/__tests__/writer.test.ts +15 -0
- package/src/shareReview/__tests__/captureConflictSemantics.test.ts +148 -0
- package/src/shareReview/__tests__/captureConflictSemanticsPin.test.ts +78 -0
- package/src/shareReview/__tests__/recommendedDecision.test.ts +35 -0
- package/src/shareReview/__tests__/reviewDecision.test.ts +102 -0
- package/src/shareReview/__tests__/shareFieldReviewPlan.test.ts +523 -0
- package/src/shareReview/captureConflictSemantics.ts +170 -0
- package/src/shareReview/index.ts +23 -0
- package/src/shareReview/recommendedDecision.ts +21 -0
- package/src/shareReview/reviewDecision.ts +71 -0
- package/src/shareReview/shareFieldReviewPlan.ts +288 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Ported from pave-2.0 packages/domain/src/reviewDecision.test.ts @ 312943078.
|
|
2
|
+
// PAVE's barrel tombstone suite (retired v1 recommendation exports) is adapted to
|
|
3
|
+
// this package's subpath barrel: the v1 names never existed here, and the
|
|
4
|
+
// PAVE-only `resolveReviewControls` / `checkReviewDecision` were not lifted.
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
|
|
7
|
+
import { isReviewDecision, REVIEW_DECISIONS, type ReviewDecision } from "../reviewDecision.js";
|
|
8
|
+
|
|
9
|
+
describe("REVIEW_DECISIONS", () => {
|
|
10
|
+
it("is exactly the seven", () => {
|
|
11
|
+
expect([...REVIEW_DECISIONS]).toEqual([
|
|
12
|
+
"add",
|
|
13
|
+
"theirs_current",
|
|
14
|
+
"mine_current",
|
|
15
|
+
"replace",
|
|
16
|
+
"keep_mine",
|
|
17
|
+
"keep_both_flagged",
|
|
18
|
+
"exclude",
|
|
19
|
+
]);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("has no duplicates", () => {
|
|
23
|
+
expect(new Set(REVIEW_DECISIONS).size).toBe(REVIEW_DECISIONS.length);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("does NOT admit the retired v1 tokens", () => {
|
|
27
|
+
for (const old of ["keep_existing", "add_to_existing"]) {
|
|
28
|
+
expect(isReviewDecision(old)).toBe(false);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("isReviewDecision", () => {
|
|
34
|
+
it("accepts every member", () => {
|
|
35
|
+
for (const d of REVIEW_DECISIONS) {
|
|
36
|
+
expect(isReviewDecision(d)).toBe(true);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// THE GUARD. A persisted decision column carries no enum, so all of these
|
|
41
|
+
// genuinely arrive — and every one passes a `v != null && v !== "add"`
|
|
42
|
+
// negation while failing the allowlist.
|
|
43
|
+
it('rejects "", false, 0, {} and arbitrary strings', () => {
|
|
44
|
+
for (const bad of [
|
|
45
|
+
"",
|
|
46
|
+
" ",
|
|
47
|
+
false,
|
|
48
|
+
0,
|
|
49
|
+
{},
|
|
50
|
+
[],
|
|
51
|
+
null,
|
|
52
|
+
undefined,
|
|
53
|
+
"obliterate",
|
|
54
|
+
"ADD",
|
|
55
|
+
"Add",
|
|
56
|
+
]) {
|
|
57
|
+
expect(isReviewDecision(bad)).toBe(false);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("narrows the type for a caller", () => {
|
|
62
|
+
const raw: unknown = "keep_both_flagged";
|
|
63
|
+
if (isReviewDecision(raw)) {
|
|
64
|
+
const narrowed: ReviewDecision = raw;
|
|
65
|
+
expect(narrowed).toBe("keep_both_flagged");
|
|
66
|
+
} else {
|
|
67
|
+
throw new Error("expected the guard to accept a real member");
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe("the share-review barrel", () => {
|
|
73
|
+
it("exports the kernel and none of the PAVE pieces that were not lifted", async () => {
|
|
74
|
+
const barrel = (await import("../index.js")) as Record<string, unknown>;
|
|
75
|
+
for (const name of [
|
|
76
|
+
"REVIEW_DECISIONS",
|
|
77
|
+
"isReviewDecision",
|
|
78
|
+
"resolvedSemantics",
|
|
79
|
+
"isOfferedForRow",
|
|
80
|
+
"planFieldReview",
|
|
81
|
+
"canApproveReview",
|
|
82
|
+
"recommendedDecision",
|
|
83
|
+
"CAPTURE_CONFLICT_SEMANTICS_BY_FIELD",
|
|
84
|
+
]) {
|
|
85
|
+
expect(name in barrel, name).toBe(true);
|
|
86
|
+
}
|
|
87
|
+
// D-b: fieldConflictOutcome / reviewControls depend on PAVE's assertion
|
|
88
|
+
// spine; justificationRequired is ruled out (Q8 follows the prototype); the
|
|
89
|
+
// assertion_domain-keyed table is replaced by the field-id one; the
|
|
90
|
+
// field-level isOfferedDecision is replaced by the row gate isOfferedForRow.
|
|
91
|
+
for (const name of [
|
|
92
|
+
"isOfferedDecision",
|
|
93
|
+
"planConflictOutcome",
|
|
94
|
+
"resolveReviewControls",
|
|
95
|
+
"checkReviewDecision",
|
|
96
|
+
"justificationRequired",
|
|
97
|
+
"CAPTURE_CONFLICT_SEMANTICS_BY_DOMAIN",
|
|
98
|
+
]) {
|
|
99
|
+
expect(name in barrel, name).toBe(false);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
// Ported from pave-2.0 packages/domain/src/shareFieldReviewPlan.test.ts (+ the
|
|
2
|
+
// field-keyable parts of shareFieldReviewPlan.parity.test.ts) @ 312943078,
|
|
3
|
+
// re-keyed to registry field ids. PAVE's `targetHeld: "unknown"` (unverified
|
|
4
|
+
// bucket) and `survivorDeclined` suites are replaced by tests that the dropped
|
|
5
|
+
// inputs have NO effect here (see "dropped PAVE extras").
|
|
6
|
+
import { describe, expect, it } from "vitest";
|
|
7
|
+
|
|
8
|
+
import { REVIEW_DECISIONS } from "../reviewDecision.js";
|
|
9
|
+
import {
|
|
10
|
+
canApproveReview,
|
|
11
|
+
DISPLAY_CHOICES,
|
|
12
|
+
DISPLAY_REPRESENTATIVE_FIELDS,
|
|
13
|
+
type DisplayChoice,
|
|
14
|
+
type FieldOfferInput,
|
|
15
|
+
isOfferedForRow,
|
|
16
|
+
type PlannedFieldOffer,
|
|
17
|
+
planFieldReview,
|
|
18
|
+
} from "../shareFieldReviewPlan.js";
|
|
19
|
+
|
|
20
|
+
const LOG = "capture.living_situation"; // log_end_date_current
|
|
21
|
+
const KEEP_REPLACE = "capture.immigration_status"; // single_value_keep_replace (authored)
|
|
22
|
+
const UNAUTHORED = "capture.vital_status"; // no registry value → fallback
|
|
23
|
+
const UNAUTHORED_2 = "capture.marital_status_legal";
|
|
24
|
+
const DERIVED = "capture.session_personnel"; // no_conflict_derived
|
|
25
|
+
|
|
26
|
+
const offer = (o: Partial<FieldOfferInput> & { offerId: string }): FieldOfferInput => ({
|
|
27
|
+
fieldId: UNAUTHORED,
|
|
28
|
+
targetPopulated: false,
|
|
29
|
+
...o,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("bucketing", () => {
|
|
33
|
+
it("pre-accepts an offer the recipient holds nothing against", () => {
|
|
34
|
+
// Even a hard single-value field has no question to ask on a blank target.
|
|
35
|
+
const plan = planFieldReview([offer({ offerId: "a", fieldId: KEEP_REPLACE })]);
|
|
36
|
+
expect(plan.adds).toHaveLength(1);
|
|
37
|
+
expect(plan.conflicts).toHaveLength(0);
|
|
38
|
+
expect(plan.adds[0]?.rulePath).toBe("no_held_value");
|
|
39
|
+
expect(plan.adds[0]?.blocking).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("pre-accepts a competing offer when entries accumulate", () => {
|
|
43
|
+
const plan = planFieldReview([
|
|
44
|
+
offer({ offerId: "a", fieldId: "capture.contact_info", targetPopulated: true }),
|
|
45
|
+
]);
|
|
46
|
+
expect(plan.adds).toHaveLength(1);
|
|
47
|
+
expect(plan.adds[0]?.rulePath).toBe("additive_never_conflicts");
|
|
48
|
+
expect(plan.adds[0]?.blocking).toBe(false);
|
|
49
|
+
expect(plan.adds[0]?.choices).toEqual([]);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("pre-accepts a competing offer on a derived field, under its OWN rule path", () => {
|
|
53
|
+
const plan = planFieldReview([offer({ offerId: "a", fieldId: DERIVED, targetPopulated: true })]);
|
|
54
|
+
expect(plan.adds.map((a) => a.rulePath)).toEqual(["derived_never_conflicts"]);
|
|
55
|
+
expect(plan.adds[0]?.semantics).toBe("no_conflict_derived");
|
|
56
|
+
expect(plan.adds[0]?.choices).toEqual([]);
|
|
57
|
+
expect(plan.blockingRemaining).toBe(0);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("an additive field is NOT labelled derived", () => {
|
|
61
|
+
const plan = planFieldReview([
|
|
62
|
+
offer({ offerId: "a", fieldId: "capture.address", targetPopulated: true }),
|
|
63
|
+
]);
|
|
64
|
+
expect(plan.adds[0]?.rulePath).toBe("additive_never_conflicts");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("raises a blocking conflict when a value competes and only one can be current", () => {
|
|
68
|
+
const plan = planFieldReview([offer({ offerId: "a", fieldId: LOG, targetPopulated: true })]);
|
|
69
|
+
expect(plan.conflicts).toHaveLength(1);
|
|
70
|
+
expect(plan.conflicts[0]?.rulePath).toBe("conflict_requires_decision");
|
|
71
|
+
expect(plan.conflicts[0]?.blocking).toBe(true);
|
|
72
|
+
expect(plan.conflicts[0]?.choices).toEqual([
|
|
73
|
+
"theirs_current",
|
|
74
|
+
"mine_current",
|
|
75
|
+
"keep_both_flagged",
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("offers the end-date pair ONLY on the log-shaped row", () => {
|
|
80
|
+
const plan = planFieldReview([
|
|
81
|
+
offer({ offerId: "c1", fieldId: LOG, targetPopulated: true }),
|
|
82
|
+
offer({ offerId: "c2", fieldId: KEEP_REPLACE, targetPopulated: true }),
|
|
83
|
+
]);
|
|
84
|
+
expect(plan.conflicts[1]?.choices).toEqual(["replace", "keep_mine", "keep_both_flagged"]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("partitions totally — every offer lands in exactly one bucket", () => {
|
|
88
|
+
const offers = [
|
|
89
|
+
offer({ offerId: "a", fieldId: "capture.name", targetPopulated: true }),
|
|
90
|
+
offer({ offerId: "b", fieldId: LOG, targetPopulated: true }),
|
|
91
|
+
offer({ offerId: "c", fieldId: UNAUTHORED, targetPopulated: false }),
|
|
92
|
+
offer({ offerId: "d", fieldId: UNAUTHORED_2, targetPopulated: true }),
|
|
93
|
+
];
|
|
94
|
+
const plan = planFieldReview(offers);
|
|
95
|
+
const ids = [...plan.adds, ...plan.conflicts].map((p) => p.offerId).sort();
|
|
96
|
+
expect(ids).toEqual(["a", "b", "c", "d"]);
|
|
97
|
+
expect(plan.adds.length + plan.conflicts.length).toBe(offers.length);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("preserves input order within each bucket", () => {
|
|
101
|
+
const plan = planFieldReview([
|
|
102
|
+
offer({ offerId: "c1", fieldId: UNAUTHORED, targetPopulated: true }),
|
|
103
|
+
offer({ offerId: "a1", fieldId: "capture.name", targetPopulated: false }),
|
|
104
|
+
offer({ offerId: "c2", fieldId: UNAUTHORED_2, targetPopulated: true }),
|
|
105
|
+
offer({ offerId: "a2", fieldId: "capture.address", targetPopulated: true }),
|
|
106
|
+
]);
|
|
107
|
+
expect(plan.adds.map((a) => a.offerId)).toEqual(["a1", "a2"]);
|
|
108
|
+
expect(plan.conflicts.map((c) => c.offerId)).toEqual(["c1", "c2"]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("carries the registry field id through to the planned row", () => {
|
|
112
|
+
const plan = planFieldReview([offer({ offerId: "c", fieldId: LOG, targetPopulated: true })]);
|
|
113
|
+
expect(plan.conflicts[0]?.fieldId).toBe(LOG);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("a wrong-but-plausible field id changes the bucket (the mapping is falsifiable)", () => {
|
|
117
|
+
// Mapping the living-situation conflict to contact_info — a real, adjacent
|
|
118
|
+
// registry id — moves it out of `conflicts`. So a consumer's mapping table
|
|
119
|
+
// is load-bearing, not true-by-fallback.
|
|
120
|
+
const wrong = planFieldReview([
|
|
121
|
+
offer({ offerId: "c1", fieldId: "capture.contact_info", targetPopulated: true }),
|
|
122
|
+
]);
|
|
123
|
+
expect(wrong.conflicts).toHaveLength(0);
|
|
124
|
+
expect(wrong.adds).toHaveLength(1);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe("blockingRemaining", () => {
|
|
129
|
+
it("counts undecided conflicts and NOTHING else", () => {
|
|
130
|
+
const plan = planFieldReview([
|
|
131
|
+
offer({ offerId: "a1", fieldId: "capture.name", targetPopulated: false }),
|
|
132
|
+
offer({ offerId: "a2", fieldId: "capture.contact_info", targetPopulated: true }),
|
|
133
|
+
offer({ offerId: "a3", fieldId: "capture.address", targetPopulated: true }),
|
|
134
|
+
offer({ offerId: "a4", fieldId: KEEP_REPLACE, targetPopulated: false }),
|
|
135
|
+
offer({ offerId: "c1", fieldId: LOG, targetPopulated: true }),
|
|
136
|
+
]);
|
|
137
|
+
expect(plan.adds).toHaveLength(4);
|
|
138
|
+
expect(plan.blockingRemaining).toBe(1);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("does not count an untouched add, nor an excluded add", () => {
|
|
142
|
+
const plan = planFieldReview([
|
|
143
|
+
offer({ offerId: "a1", fieldId: "capture.contact_info", targetPopulated: true }),
|
|
144
|
+
offer({
|
|
145
|
+
offerId: "a2",
|
|
146
|
+
fieldId: "capture.contact_info",
|
|
147
|
+
targetPopulated: true,
|
|
148
|
+
decision: "exclude",
|
|
149
|
+
}),
|
|
150
|
+
]);
|
|
151
|
+
expect(plan.blockingRemaining).toBe(0);
|
|
152
|
+
expect(plan.adds.every((a) => !a.blocking)).toBe(true);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("counts a DECIDED conflict as not blocking but still a conflict", () => {
|
|
156
|
+
const plan = planFieldReview([
|
|
157
|
+
offer({ offerId: "c1", fieldId: LOG, targetPopulated: true, decision: "mine_current" }),
|
|
158
|
+
]);
|
|
159
|
+
expect(plan.conflicts).toHaveLength(1);
|
|
160
|
+
expect(plan.conflicts[0]?.blocking).toBe(false);
|
|
161
|
+
expect(plan.blockingRemaining).toBe(0);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("drops to zero as conflicts are decided", () => {
|
|
165
|
+
const base: FieldOfferInput[] = [
|
|
166
|
+
offer({ offerId: "c1", fieldId: LOG, targetPopulated: true }),
|
|
167
|
+
offer({ offerId: "c2", fieldId: UNAUTHORED, targetPopulated: true }),
|
|
168
|
+
];
|
|
169
|
+
expect(planFieldReview(base).blockingRemaining).toBe(2);
|
|
170
|
+
expect(
|
|
171
|
+
planFieldReview([{ ...base[0]!, decision: "theirs_current" }, base[1]!]).blockingRemaining,
|
|
172
|
+
).toBe(1);
|
|
173
|
+
expect(
|
|
174
|
+
planFieldReview([
|
|
175
|
+
{ ...base[0]!, decision: "theirs_current" },
|
|
176
|
+
{ ...base[1]!, decision: "replace" },
|
|
177
|
+
]).blockingRemaining,
|
|
178
|
+
).toBe(0);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("treats keep_both_flagged as a decision that UNBLOCKS", () => {
|
|
182
|
+
const plan = planFieldReview([
|
|
183
|
+
offer({ offerId: "c1", fieldId: LOG, targetPopulated: true, decision: "keep_both_flagged" }),
|
|
184
|
+
]);
|
|
185
|
+
expect(plan.blockingRemaining).toBe(0);
|
|
186
|
+
expect(plan.conflicts[0]?.blocking).toBe(false);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("treats exclude as a decision that unblocks", () => {
|
|
190
|
+
const plan = planFieldReview([
|
|
191
|
+
offer({ offerId: "c1", fieldId: UNAUTHORED, targetPopulated: true, decision: "exclude" }),
|
|
192
|
+
]);
|
|
193
|
+
expect(plan.blockingRemaining).toBe(0);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// ── Resolution is ROW-AWARE: only a decision the row offers clears it ──
|
|
197
|
+
it("an end-date conflict is resolved only by its own pair, keep_both_flagged or exclude", () => {
|
|
198
|
+
const resolves = (d: string) =>
|
|
199
|
+
planFieldReview([
|
|
200
|
+
offer({ offerId: "c1", fieldId: LOG, targetPopulated: true, decision: d as never }),
|
|
201
|
+
]).blockingRemaining === 0;
|
|
202
|
+
for (const d of ["theirs_current", "mine_current", "keep_both_flagged", "exclude"]) {
|
|
203
|
+
expect(resolves(d), d).toBe(true);
|
|
204
|
+
}
|
|
205
|
+
// The keep/replace pair is NOT offered on a log_end_date_current row.
|
|
206
|
+
for (const d of ["replace", "keep_mine", "add"]) expect(resolves(d), d).toBe(false);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("a keep/replace conflict (authored or fallback) is NOT resolved by the end-date pair", () => {
|
|
210
|
+
for (const fieldId of [KEEP_REPLACE, UNAUTHORED]) {
|
|
211
|
+
const resolves = (d: string) =>
|
|
212
|
+
planFieldReview([
|
|
213
|
+
offer({ offerId: "c1", fieldId, targetPopulated: true, decision: d as never }),
|
|
214
|
+
]).blockingRemaining === 0;
|
|
215
|
+
for (const d of ["replace", "keep_mine", "keep_both_flagged", "exclude"]) {
|
|
216
|
+
expect(resolves(d), `${fieldId} ${d}`).toBe(true);
|
|
217
|
+
}
|
|
218
|
+
for (const d of ["theirs_current", "mine_current", "add"]) {
|
|
219
|
+
expect(resolves(d), `${fieldId} ${d}`).toBe(false);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("does NOT let a garbage runtime value unblock a conflict", () => {
|
|
225
|
+
for (const garbage of ["", "nonsense", "ADD", "Replace", 0, false, {}]) {
|
|
226
|
+
const plan = planFieldReview([
|
|
227
|
+
offer({
|
|
228
|
+
offerId: "c1",
|
|
229
|
+
fieldId: LOG,
|
|
230
|
+
targetPopulated: true,
|
|
231
|
+
decision: garbage as never,
|
|
232
|
+
}),
|
|
233
|
+
]);
|
|
234
|
+
expect(plan.blockingRemaining, String(garbage)).toBe(1);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("is zero for a share of nothing but adds, which is not the same as empty", () => {
|
|
239
|
+
const plan = planFieldReview([
|
|
240
|
+
offer({ offerId: "a1", fieldId: "capture.name", targetPopulated: true }),
|
|
241
|
+
offer({ offerId: "a2", fieldId: "capture.address", targetPopulated: true }),
|
|
242
|
+
]);
|
|
243
|
+
expect(plan.blockingRemaining).toBe(0);
|
|
244
|
+
expect(plan.adds).toHaveLength(2);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("is zero for an empty share — and the plan has exactly two buckets", () => {
|
|
248
|
+
// Exact shape on purpose — a new bucket must be a deliberate edit here.
|
|
249
|
+
expect(planFieldReview([])).toEqual({ adds: [], conflicts: [], blockingRemaining: 0 });
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
describe("unauthored fields take the keep/replace fallback", () => {
|
|
254
|
+
it("conflicts on a competing value, blocks, and says the semantics were not authored", () => {
|
|
255
|
+
const plan = planFieldReview([
|
|
256
|
+
offer({ offerId: "c", fieldId: UNAUTHORED, targetPopulated: true }),
|
|
257
|
+
]);
|
|
258
|
+
expect(plan.conflicts).toHaveLength(1);
|
|
259
|
+
expect(plan.conflicts[0]?.semantics).toBe("single_value_keep_replace");
|
|
260
|
+
expect(plan.conflicts[0]?.semanticsAuthored).toBe(false);
|
|
261
|
+
expect(plan.conflicts[0]?.blocking).toBe(true);
|
|
262
|
+
expect(plan.conflicts[0]?.choices).toEqual(["replace", "keep_mine", "keep_both_flagged"]);
|
|
263
|
+
expect(plan.blockingRemaining).toBe(1);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("is an add on an empty slot — never a silent add over a held value", () => {
|
|
267
|
+
const empty = planFieldReview([offer({ offerId: "a", fieldId: UNAUTHORED })]);
|
|
268
|
+
expect(empty.adds[0]?.rulePath).toBe("no_held_value");
|
|
269
|
+
const held = planFieldReview([
|
|
270
|
+
offer({ offerId: "c", fieldId: "capture.__never_authored__", targetPopulated: true }),
|
|
271
|
+
]);
|
|
272
|
+
expect(held.adds).toHaveLength(0);
|
|
273
|
+
expect(held.conflicts[0]?.blocking).toBe(true);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
describe("displayQuestion", () => {
|
|
278
|
+
it("is keyed by the registry field id capture.name", () => {
|
|
279
|
+
expect([...DISPLAY_REPRESENTATIVE_FIELDS]).toEqual(["capture.name"]);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("asks which name displays when the recipient already holds one", () => {
|
|
283
|
+
const plan = planFieldReview([
|
|
284
|
+
offer({ offerId: "a", fieldId: "capture.name", targetPopulated: true }),
|
|
285
|
+
]);
|
|
286
|
+
expect(plan.adds[0]?.displayQuestion).toBe(true);
|
|
287
|
+
expect(plan.adds[0]?.bucket).toBe("add");
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("asks nothing when the recipient holds no name", () => {
|
|
291
|
+
const plan = planFieldReview([offer({ offerId: "a", fieldId: "capture.name" })]);
|
|
292
|
+
expect(plan.adds[0]?.displayQuestion).toBe(false);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it("does NOT key on the bare PAVE domain `name`", () => {
|
|
296
|
+
const plan = planFieldReview([offer({ offerId: "a", fieldId: "name", targetPopulated: true })]);
|
|
297
|
+
expect(plan.adds).toHaveLength(0);
|
|
298
|
+
expect(plan.conflicts[0]?.displayQuestion).toBe(false);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it("does NOT generalise to other additive fields", () => {
|
|
302
|
+
for (const f of ["capture.contact_info", "capture.address"]) {
|
|
303
|
+
const plan = planFieldReview([offer({ offerId: "a", fieldId: f, targetPopulated: true })]);
|
|
304
|
+
expect(plan.adds[0]?.displayQuestion, f).toBe(false);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
describe("canApproveReview", () => {
|
|
310
|
+
it("blocks while a conflict is undecided and clears once it is", () => {
|
|
311
|
+
const undecided = planFieldReview([
|
|
312
|
+
offer({ offerId: "c", fieldId: UNAUTHORED, targetPopulated: true }),
|
|
313
|
+
]);
|
|
314
|
+
expect(canApproveReview(undecided)).toBe(false);
|
|
315
|
+
const decided = planFieldReview([
|
|
316
|
+
offer({ offerId: "c", fieldId: UNAUTHORED, targetPopulated: true, decision: "keep_mine" }),
|
|
317
|
+
]);
|
|
318
|
+
expect(canApproveReview(decided)).toBe(true);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("does not block a share made entirely of adds", () => {
|
|
322
|
+
expect(
|
|
323
|
+
canApproveReview(
|
|
324
|
+
planFieldReview([
|
|
325
|
+
offer({ offerId: "a", fieldId: "capture.contact_info", targetPopulated: true }),
|
|
326
|
+
]),
|
|
327
|
+
),
|
|
328
|
+
).toBe(true);
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
describe("canExclude", () => {
|
|
333
|
+
it("offers exclude on ordinary adds and on conflicts", () => {
|
|
334
|
+
const plan = planFieldReview([
|
|
335
|
+
offer({ offerId: "a", fieldId: "capture.contact_info", targetPopulated: true }),
|
|
336
|
+
offer({ offerId: "b", fieldId: "capture.name" }), // name over an EMPTY slot: plain add
|
|
337
|
+
offer({ offerId: "c", fieldId: UNAUTHORED, targetPopulated: true }),
|
|
338
|
+
]);
|
|
339
|
+
expect(plan.adds.map((a) => a.canExclude)).toEqual([true, true]);
|
|
340
|
+
expect(plan.conflicts[0]?.canExclude).toBe(true);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("the name display-question row CANNOT be excluded (canon: only the two display buttons)", () => {
|
|
344
|
+
const plan = planFieldReview([
|
|
345
|
+
offer({ offerId: "n", fieldId: "capture.name", targetPopulated: true }),
|
|
346
|
+
]);
|
|
347
|
+
expect(plan.adds[0]?.displayQuestion).toBe(true);
|
|
348
|
+
expect(plan.adds[0]?.canExclude).toBe(false);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it("is exactly !displayQuestion on every row", () => {
|
|
352
|
+
const plan = planFieldReview([
|
|
353
|
+
offer({ offerId: "1", fieldId: "capture.name", targetPopulated: true }),
|
|
354
|
+
offer({ offerId: "2", fieldId: "capture.name" }),
|
|
355
|
+
offer({ offerId: "3", fieldId: "capture.address", targetPopulated: true }),
|
|
356
|
+
offer({ offerId: "4", fieldId: DERIVED, targetPopulated: true }),
|
|
357
|
+
offer({ offerId: "5", fieldId: LOG, targetPopulated: true }),
|
|
358
|
+
]);
|
|
359
|
+
for (const r of [...plan.adds, ...plan.conflicts]) {
|
|
360
|
+
expect(r.canExclude, r.offerId).toBe(!r.displayQuestion);
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it("keeps exclude OUT of the semantics choices", () => {
|
|
365
|
+
const plan = planFieldReview([offer({ offerId: "c", fieldId: LOG, targetPopulated: true })]);
|
|
366
|
+
expect(plan.conflicts[0]?.choices).not.toContain("exclude");
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
// ── The dropped PAVE extras (ADR D-b) ────────────────────────────────────────
|
|
371
|
+
describe("dropped PAVE extras: no `unverified` bucket, no `survivorDeclined`", () => {
|
|
372
|
+
it("the plan has no `unverified` bucket", () => {
|
|
373
|
+
const plan = planFieldReview([offer({ offerId: "c", fieldId: LOG, targetPopulated: true })]);
|
|
374
|
+
expect(Object.keys(plan).sort()).toEqual(["adds", "blockingRemaining", "conflicts"]);
|
|
375
|
+
expect("unverified" in plan).toBe(false);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it("a stray PAVE `targetHeld: \"unknown\"` is ignored — the boolean decides", () => {
|
|
379
|
+
const stray = { targetHeld: "unknown" } as Record<string, unknown>;
|
|
380
|
+
const conflict = planFieldReview([
|
|
381
|
+
{ ...offer({ offerId: "c", fieldId: LOG, targetPopulated: true }), ...stray },
|
|
382
|
+
]);
|
|
383
|
+
expect(conflict.conflicts.map((c) => c.offerId)).toEqual(["c"]);
|
|
384
|
+
expect(conflict.conflicts[0]?.rulePath).toBe("conflict_requires_decision");
|
|
385
|
+
// and an `exclude`-only resolution rule does not apply: any real decision unblocks
|
|
386
|
+
const decided = planFieldReview([
|
|
387
|
+
{
|
|
388
|
+
...offer({ offerId: "c", fieldId: LOG, targetPopulated: true, decision: "theirs_current" }),
|
|
389
|
+
...stray,
|
|
390
|
+
},
|
|
391
|
+
]);
|
|
392
|
+
expect(decided.blockingRemaining).toBe(0);
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it("a stray PAVE `survivorDeclined: true` is ignored — a held conflict still blocks", () => {
|
|
396
|
+
const plan = planFieldReview([
|
|
397
|
+
{
|
|
398
|
+
...offer({ offerId: "c", fieldId: KEEP_REPLACE, targetPopulated: true }),
|
|
399
|
+
...({ survivorDeclined: true } as Record<string, unknown>),
|
|
400
|
+
},
|
|
401
|
+
]);
|
|
402
|
+
expect(plan.conflicts).toHaveLength(1);
|
|
403
|
+
expect(plan.conflicts[0]?.blocking).toBe(true);
|
|
404
|
+
expect(plan.conflicts[0]?.canExclude).toBe(true);
|
|
405
|
+
expect(plan.blockingRemaining).toBe(1);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
it("no planned row ever carries a PAVE-only rule path", () => {
|
|
409
|
+
const plan = planFieldReview([
|
|
410
|
+
offer({ offerId: "a", fieldId: "capture.name" }),
|
|
411
|
+
offer({ offerId: "b", fieldId: "capture.name", targetPopulated: true }),
|
|
412
|
+
offer({ offerId: "c", fieldId: LOG, targetPopulated: true }),
|
|
413
|
+
]);
|
|
414
|
+
const paths = [...plan.adds, ...plan.conflicts].map((p) => p.rulePath);
|
|
415
|
+
for (const p of paths) {
|
|
416
|
+
expect([
|
|
417
|
+
"no_held_value",
|
|
418
|
+
"additive_never_conflicts",
|
|
419
|
+
"derived_never_conflicts",
|
|
420
|
+
"conflict_requires_decision",
|
|
421
|
+
]).toContain(p);
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
// ── THE row gate ────────────────────────────────────────────────────────────
|
|
427
|
+
describe("isOfferedForRow — the write gate, bucket-aware", () => {
|
|
428
|
+
const rowOf = (o: FieldOfferInput): PlannedFieldOffer => {
|
|
429
|
+
const p = planFieldReview([o]);
|
|
430
|
+
return (p.adds[0] ?? p.conflicts[0])!;
|
|
431
|
+
};
|
|
432
|
+
const offered = (row: PlannedFieldOffer) =>
|
|
433
|
+
REVIEW_DECISIONS.filter((d) => isOfferedForRow(row, d));
|
|
434
|
+
|
|
435
|
+
it("an ordinary add row admits `add` and `exclude` only", () => {
|
|
436
|
+
for (const o of [
|
|
437
|
+
offer({ offerId: "a", fieldId: "capture.contact_info", targetPopulated: true }),
|
|
438
|
+
offer({ offerId: "b", fieldId: KEEP_REPLACE }), // empty slot
|
|
439
|
+
offer({ offerId: "c", fieldId: DERIVED, targetPopulated: true }),
|
|
440
|
+
]) {
|
|
441
|
+
expect(offered(rowOf(o)), o.offerId).toEqual(["add", "exclude"]);
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
it("the name display-question row admits `add` only (the display choice records add)", () => {
|
|
446
|
+
const row = rowOf(offer({ offerId: "n", fieldId: "capture.name", targetPopulated: true }));
|
|
447
|
+
expect(offered(row)).toEqual(["add"]);
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
it("an add row refuses every conflict resolution", () => {
|
|
451
|
+
const row = rowOf(
|
|
452
|
+
offer({ offerId: "a", fieldId: "capture.contact_info", targetPopulated: true }),
|
|
453
|
+
);
|
|
454
|
+
for (const d of ["keep_mine", "replace", "keep_both_flagged", "theirs_current"]) {
|
|
455
|
+
expect(isOfferedForRow(row, d), d).toBe(false);
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
it("an end-date conflict row admits its pair + keep_both_flagged + exclude", () => {
|
|
460
|
+
const row = rowOf(offer({ offerId: "c", fieldId: LOG, targetPopulated: true }));
|
|
461
|
+
expect(offered(row)).toEqual(["theirs_current", "mine_current", "keep_both_flagged", "exclude"]);
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
it("a keep/replace conflict row (authored or fallback) admits replace/keep_mine + the two", () => {
|
|
465
|
+
for (const fieldId of [KEEP_REPLACE, UNAUTHORED, "capture.__never_authored__"]) {
|
|
466
|
+
const row = rowOf(offer({ offerId: "c", fieldId, targetPopulated: true }));
|
|
467
|
+
expect(offered(row), fieldId).toEqual(["replace", "keep_mine", "keep_both_flagged", "exclude"]);
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
it("refuses non-strings and off-vocabulary strings", () => {
|
|
472
|
+
const row = rowOf(offer({ offerId: "c", fieldId: LOG, targetPopulated: true }));
|
|
473
|
+
for (const bad of ["", "ADD", "delete", null, undefined, 0, false, {}]) {
|
|
474
|
+
expect(isOfferedForRow(row, bad), String(bad)).toBe(false);
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it("is the SAME rule the planner resolves conflicts by", () => {
|
|
479
|
+
for (const fieldId of [LOG, KEEP_REPLACE, UNAUTHORED]) {
|
|
480
|
+
for (const d of REVIEW_DECISIONS) {
|
|
481
|
+
const o = offer({ offerId: "c", fieldId, targetPopulated: true, decision: d });
|
|
482
|
+
const row = rowOf(o);
|
|
483
|
+
expect(row.blocking, `${fieldId} ${d}`).toBe(!isOfferedForRow(row, d));
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
describe("DISPLAY_CHOICES", () => {
|
|
490
|
+
it("is canon's two display answers", () => {
|
|
491
|
+
const choices: readonly DisplayChoice[] = DISPLAY_CHOICES;
|
|
492
|
+
expect([...choices]).toEqual(["keep", "incoming"]);
|
|
493
|
+
});
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
// ── Input contracts ─────────────────────────────────────────────────────────
|
|
497
|
+
describe("input contracts", () => {
|
|
498
|
+
it("an IDENTICAL held value is passed as not competing — a non-blocking add, never a conflict", () => {
|
|
499
|
+
// The caller compared and found the recipient already holds exactly the
|
|
500
|
+
// offered value, so it passes targetPopulated: false (see FieldOfferInput).
|
|
501
|
+
for (const fieldId of [LOG, KEEP_REPLACE, UNAUTHORED, "capture.name"]) {
|
|
502
|
+
const plan = planFieldReview([offer({ offerId: "same", fieldId, targetPopulated: false })]);
|
|
503
|
+
expect(plan.conflicts, fieldId).toEqual([]);
|
|
504
|
+
expect(plan.adds[0]?.rulePath, fieldId).toBe("no_held_value");
|
|
505
|
+
expect(plan.adds[0]?.displayQuestion, fieldId).toBe(false);
|
|
506
|
+
expect(plan.blockingRemaining, fieldId).toBe(0);
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
it("a field with no incoming value is never planned — the plan has one row per offer, no more", () => {
|
|
511
|
+
// The sender offered two fields; the recipient holds many more. Only the
|
|
512
|
+
// offered fields appear — the planner never synthesizes a row for a held
|
|
513
|
+
// field nobody sent.
|
|
514
|
+
const offers = [
|
|
515
|
+
offer({ offerId: "a", fieldId: "capture.address", targetPopulated: true }),
|
|
516
|
+
offer({ offerId: "c", fieldId: LOG, targetPopulated: true }),
|
|
517
|
+
];
|
|
518
|
+
const plan = planFieldReview(offers);
|
|
519
|
+
const rows = [...plan.adds, ...plan.conflicts];
|
|
520
|
+
expect(rows.map((r) => r.offerId).sort()).toEqual(["a", "c"]);
|
|
521
|
+
expect(rows.map((r) => r.fieldId).sort()).toEqual(["capture.address", LOG].sort());
|
|
522
|
+
});
|
|
523
|
+
});
|