@intentius/chant 0.124.50 → 0.124.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/cli/handlers/pr.d.ts.map +1 -1
  2. package/dist/cli/handlers/pr.js +2 -1
  3. package/dist/components/capability.d.ts +9 -0
  4. package/dist/components/capability.d.ts.map +1 -1
  5. package/dist/components/covered-round.d.ts +173 -0
  6. package/dist/components/covered-round.d.ts.map +1 -0
  7. package/dist/components/covered-round.js +200 -0
  8. package/dist/components/driver.d.ts +8 -0
  9. package/dist/components/driver.d.ts.map +1 -1
  10. package/dist/components/driver.js +8 -0
  11. package/dist/components/index.d.ts +1 -0
  12. package/dist/components/index.d.ts.map +1 -1
  13. package/dist/components/index.js +1 -0
  14. package/dist/components/pr-run.d.ts +21 -3
  15. package/dist/components/pr-run.d.ts.map +1 -1
  16. package/dist/components/pr-run.js +147 -16
  17. package/dist/components/wave-plan.d.ts +2 -0
  18. package/dist/components/wave-plan.d.ts.map +1 -1
  19. package/dist/components/wave-plan.js +4 -1
  20. package/dist/pr-loop.d.ts +36 -2
  21. package/dist/pr-loop.d.ts.map +1 -1
  22. package/dist/pr-loop.js +11 -2
  23. package/dist/wave-runtime.mjs +3 -3
  24. package/dist/workspace/pr-report.schema.json +25 -1
  25. package/package.json +1 -1
  26. package/src/cli/handlers/pr.ts +2 -1
  27. package/src/components/capability.ts +9 -0
  28. package/src/components/covered-round.test.ts +166 -0
  29. package/src/components/covered-round.ts +293 -0
  30. package/src/components/driver.ts +12 -0
  31. package/src/components/index.ts +17 -0
  32. package/src/components/pr-run.test.ts +212 -1
  33. package/src/components/pr-run.ts +166 -16
  34. package/src/components/wave-plan.ts +5 -2
  35. package/src/pr-loop.test.ts +14 -1
  36. package/src/pr-loop.ts +43 -4
  37. package/src/workspace/pr-report.schema.json +25 -1
@@ -0,0 +1,166 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import {
3
+ coveredRound,
4
+ normalizePlanShape,
5
+ PlanShapeMovedError,
6
+ planShapeCovers,
7
+ planShapeDifferences,
8
+ planShapeDigest,
9
+ type PlanShape,
10
+ type PlanShapeEntry,
11
+ } from "./covered-round";
12
+ import type { ChangeSetDocument } from "../change-set";
13
+
14
+ const shape = (over: Partial<PlanShape> = {}): PlanShape => ({
15
+ member: "svc",
16
+ entries: [
17
+ { logicalId: "Fn", action: "create" },
18
+ { logicalId: "Role", action: "update", replacement: "conditional" },
19
+ ],
20
+ unknownInputs: ["vpc.id"],
21
+ ...over,
22
+ });
23
+
24
+ describe("planShapeCovers", () => {
25
+ test("the same ids and actions with the unknown input filled in is covered", () => {
26
+ expect(planShapeCovers(shape(), shape({ unknownInputs: [], replacement: undefined } as never))).toBeUndefined();
27
+ });
28
+
29
+ test("a resource the preview did not show is not covered", () => {
30
+ const fresh = shape({ unknownInputs: [], entries: [...shape().entries, { logicalId: "Bucket", action: "create" }] });
31
+ expect(planShapeCovers(shape(), fresh)).toBe("svc now plans to create Bucket, which the first plan did not");
32
+ });
33
+
34
+ test("a different action is not covered", () => {
35
+ const fresh = shape({ unknownInputs: [], entries: [{ logicalId: "Fn", action: "delete" }] });
36
+ expect(planShapeCovers(shape(), fresh)).toBe("svc now plans to delete Fn, where the first plan showed create");
37
+ });
38
+
39
+ test("a replacement the preview did not show is not covered; a conditional one resolving either way is", () => {
40
+ const previewed = shape({ entries: [{ logicalId: "Role", action: "update", replacement: "false" }] });
41
+ const replaced = shape({ unknownInputs: [], entries: [{ logicalId: "Role", action: "update", replacement: "true" }] });
42
+ expect(planShapeCovers(previewed, replaced)).toBe("svc now replaces Role, which the first plan did not show");
43
+ for (const r of ["true", "false"] as const) {
44
+ const fresh = shape({ unknownInputs: [], entries: [{ logicalId: "Role", action: "update", replacement: r }] });
45
+ expect(planShapeCovers(shape(), fresh)).toBeUndefined();
46
+ }
47
+ });
48
+
49
+ test("a changed known input is not covered, an unknown one filled is", () => {
50
+ const was = shape({ knownInputs: { "net.cidr": "10.0.0.0/16" } });
51
+ expect(planShapeCovers(was, shape({ unknownInputs: [], knownInputs: { "net.cidr": "10.1.0.0/16" } }))).toBe(
52
+ "svc now reads net.cidr as a different value than the first plan",
53
+ );
54
+ expect(planShapeCovers(was, shape({ unknownInputs: [], knownInputs: { "net.cidr": "10.0.0.0/16", "vpc.id": "vpc-1" } }))).toBeUndefined();
55
+ });
56
+
57
+ test("an input still unknown is not covered", () => {
58
+ expect(planShapeCovers(shape(), shape())).toBe("svc still reads vpc.id, which is not known yet");
59
+ });
60
+ });
61
+
62
+ describe("coveredRound", () => {
63
+ const doc = { members: [], entries: [] } as unknown as ChangeSetDocument;
64
+ const side = (component: string, unknownInputs?: string[], shapes?: Record<string, PlanShape>) => ({
65
+ doc,
66
+ members: [{ member: "svc", component, ...(unknownInputs ? { unknownInputs } : {}) }],
67
+ ...(shapes ? { shapes } : {}),
68
+ });
69
+
70
+ test("covered: binds the first approval's digest and names the inputs filled in", () => {
71
+ const r = coveredRound({
72
+ approved: side("svc", ["vpc.id"], { svc: shape() }),
73
+ approvedDigest: "sha256:aaa",
74
+ fresh: side("svc", undefined, { svc: shape({ unknownInputs: [] }) }),
75
+ });
76
+ expect(r).toEqual({ covered: true, digest: "sha256:aaa", filledInputs: ["vpc.id"] });
77
+ });
78
+
79
+ test("a component the first plan did not preview is not covered", () => {
80
+ const r = coveredRound({ approved: side("svc", ["vpc.id"]), approvedDigest: "sha256:aaa", fresh: side("other") });
81
+ expect(r).toEqual({ covered: false, reason: "other was not in the first plan" });
82
+ });
83
+
84
+ test("a member that was a hole with no preview shape is not covered, even with its unknown input filled in (#4422)", () => {
85
+ // The approved side has no shape for svc and no entries: the reviewer never saw what it would do.
86
+ const fresh = { svc: shape({ unknownInputs: [], entries: [{ logicalId: "Fn", action: "create" }] }) };
87
+ const r = coveredRound({ approved: side("svc", ["vpc.id"]), approvedDigest: "sha256:aaa", fresh: side("svc", undefined, fresh) });
88
+ expect(r).toEqual({ covered: false, reason: "svc now plans to create Fn, which the first plan did not" });
89
+ });
90
+
91
+ test("a known input that moved is not covered", () => {
92
+ const r = coveredRound({
93
+ approved: side("svc", ["vpc.id"]),
94
+ approvedDigest: "sha256:aaa",
95
+ fresh: side("svc"),
96
+ changedKnown: { svc: ["net.cidr", "vpc.id"] },
97
+ });
98
+ expect(r).toEqual({ covered: false, reason: "svc reads net.cidr, which the first plan read as another value" });
99
+ });
100
+ });
101
+
102
+ describe("property-level shapes (ported from plan-shape, #4419)", () => {
103
+ const entry = (over: Partial<PlanShapeEntry> = {}): PlanShapeEntry => ({
104
+ logicalId: "Eni",
105
+ action: "update",
106
+ replacement: "false",
107
+ type: "T",
108
+ properties: ["A", "B"],
109
+ unknown: ["B"],
110
+ ...over,
111
+ });
112
+ const sh = (...entries: PlanShapeEntry[]): PlanShape => ({ member: "m", unknownInputs: ["p"], entries });
113
+ const fresh = (...entries: PlanShapeEntry[]): PlanShape => ({ member: "m", unknownInputs: [], entries });
114
+
115
+ test("digests the same for the same shape in another order", () => {
116
+ const a = sh(entry({ logicalId: "a" }), entry({ logicalId: "b", properties: ["Z", "Y"] }));
117
+ const b = sh(entry({ logicalId: "b", properties: ["Y", "Z"] }), entry({ logicalId: "a" }));
118
+ expect(planShapeDigest(a)).toBe(planShapeDigest(b));
119
+ expect(normalizePlanShape(b).entries.map((e) => e.logicalId)).toEqual(["a", "b"]);
120
+ expect(planShapeDigest(a)).not.toBe(planShapeDigest(sh(entry({ logicalId: "a" }))));
121
+ });
122
+
123
+ test("accepts an identical change and one narrowed where an unknown input drives it", () => {
124
+ expect(planShapeDifferences(sh(entry()), fresh(entry()))).toEqual([]);
125
+ expect(planShapeDifferences(sh(entry()), fresh(entry({ properties: ["A"] })))).toEqual([]);
126
+ expect(planShapeDifferences(sh(entry({ replacement: "true" })), fresh(entry({ replacement: "false" })))).toEqual([]);
127
+ expect(planShapeDifferences(sh(entry({ properties: ["B"] })), fresh())).toEqual([]);
128
+ });
129
+
130
+ test("refuses an added resource, an added property, another action, more replacement", () => {
131
+ expect(planShapeDifferences(sh(entry()), fresh(entry(), entry({ logicalId: "n" })))).toHaveLength(1);
132
+ expect(planShapeCovers(sh(entry()), fresh(entry({ properties: ["A", "B", "C"] })))).toContain("also changes C");
133
+ expect(planShapeCovers(sh(entry()), fresh(entry({ action: "delete" })))).toContain("where the first plan showed update");
134
+ expect(planShapeCovers(sh(entry()), fresh(entry({ replacement: "true" })))).toContain("now replaces Eni");
135
+ expect(planShapeCovers(sh(entry()), fresh(entry({ type: "U" })))).toContain("as U, where the first plan showed T");
136
+ });
137
+
138
+ test("refuses a change that vanishes or weakens with no unknown input behind it", () => {
139
+ expect(planShapeDifferences(sh(entry({ unknown: [] })), fresh())).toHaveLength(1);
140
+ expect(planShapeDifferences(sh(entry({ unknown: [], replacement: "true" })), fresh(entry({ unknown: [], replacement: "false" })))).toHaveLength(1);
141
+ expect(planShapeCovers(sh(entry()), fresh(entry({ properties: ["B"] })))).toContain("no longer changes A");
142
+ });
143
+
144
+ test("a previewed entry without property detail may drop out, as before", () => {
145
+ expect(planShapeDifferences({ member: "m", unknownInputs: [], entries: [{ logicalId: "x", action: "create" }] }, fresh())).toEqual([]);
146
+ });
147
+
148
+ test("an entry with property detail is compared even when its action is no-op", () => {
149
+ const imp = entry({ logicalId: "I", action: "no-op" });
150
+ expect(planShapeCovers(sh(), fresh(imp))).toContain("now plans to no-op I");
151
+ expect(planShapeCovers(sh(imp), fresh(imp))).toBeUndefined();
152
+ });
153
+
154
+ test("the refusal names the differences and marks the plan as moved", () => {
155
+ const err = new PlanShapeMovedError("m", ["m now plans to create Eni, which the first plan did not"]);
156
+ expect(err.planMoved).toBe(true);
157
+ expect(err.message).toContain("Eni, which the first plan did not");
158
+ });
159
+
160
+ test("a round is not covered when a property level difference shows in the shapes a lexicon supplied", () => {
161
+ const doc = { members: [], entries: [] } as unknown as ChangeSetDocument;
162
+ const side = (shape: PlanShape, unknownInputs?: string[]) => ({ doc, members: [{ member: "m", component: "c", ...(unknownInputs ? { unknownInputs } : {}) }], shapes: { m: shape } });
163
+ const r = coveredRound({ approved: side(sh(entry()), ["up.id"]), approvedDigest: "d", fresh: side(fresh(entry({ properties: ["A", "C"] }))) });
164
+ expect(r).toEqual({ covered: false, reason: "m now also changes C on Eni" });
165
+ });
166
+ });
@@ -0,0 +1,293 @@
1
+ /**
2
+ * Covered rounds (#4419): a round planned after an upstream applied is
3
+ * covered by the pull request's first approval when it does only what that
4
+ * approval previewed.
5
+ *
6
+ * A member that reads an output an upstream in the same change has not
7
+ * created yet is previewed with a hole: the input is marked unknown
8
+ * (`PrMember.unknownInputs`). Once the upstream applied, the apply plans the
9
+ * member again with the real value. That fresh plan is covered when
10
+ *
11
+ * - it touches only components the first plan previewed,
12
+ * - within each, only the logical ids and actions previewed (and no
13
+ * replacement the preview did not show), and
14
+ * - the only inputs that differ are the ones the preview marked unknown.
15
+ *
16
+ * A lexicon that can say more than the change set's entries (CloudFormation
17
+ * previews the member with placeholder parameters and reads the real change
18
+ * set afterwards) supplies a {@link PlanShape} on its `CapabilityPlan`.
19
+ * Core decides coverage; the lexicon only reports what it planned.
20
+ *
21
+ * A shape may go below the entry, to the properties a change touches and the
22
+ * ones an unknown input drives. Where it does, a property may drop out when
23
+ * an unknown input drives it (the real value turned out equal to the current
24
+ * one), and never otherwise, and a property may never be added.
25
+ *
26
+ * Coverage binds to the digest of the first approval. {@link coveredRound}
27
+ * takes that digest and records it, so a round planned for a different
28
+ * composition never counts as covered by an approval of another one.
29
+ */
30
+
31
+ import type { ChangeSetAction, ChangeSetDocument } from "../change-set";
32
+ import { computePlanDigest } from "../lifecycle/plan-digest";
33
+
34
+ /** CloudFormation's `Replacement`, in lower case. */
35
+ export type ShapeReplacement = "true" | "false" | "conditional";
36
+
37
+ /** One resource a plan touches. */
38
+ export interface PlanShapeEntry {
39
+ /** The resource's id in the lexicon's own terms: a CloudFormation logical id, a Terraform address. */
40
+ logicalId: string;
41
+ action: ChangeSetAction;
42
+ /**
43
+ * Whether the change replaces the resource, for an `update` or `replace`.
44
+ * `conditional` is the preview not knowing, because a parameter it
45
+ * depends on was a placeholder. Absent means the lexicon does not say.
46
+ */
47
+ replacement?: ShapeReplacement;
48
+ /** The resource's type, when the lexicon says. Compared for equality when both sides carry it. */
49
+ type?: string;
50
+ /**
51
+ * The properties the change touches, when the lexicon lists them. Present
52
+ * on both sides, the fresh plan may touch fewer where an unknown input
53
+ * drives them, and never more.
54
+ */
55
+ properties?: string[];
56
+ /**
57
+ * The properties an unknown input drives. On an update a subset of
58
+ * `properties`; on a create, where a planner cannot list properties, they
59
+ * stand alone. Present (even empty) on an entry that carries detail.
60
+ */
61
+ unknown?: string[];
62
+ }
63
+
64
+ /** What one member's plan does, without the values: what a lexicon supplies and core compares. */
65
+ export interface PlanShape {
66
+ /** The member the shape is of, as in the change set. */
67
+ member: string;
68
+ /** Every resource the plan touches. A `no-op` or `read` entry may be left out. */
69
+ entries: PlanShapeEntry[];
70
+ /**
71
+ * The inputs the plan was made without, as `<component>.<output>`: the
72
+ * ones the preview marked unknown. A fresh plan lists none of them; it
73
+ * is the inputs that were filled in that are recorded.
74
+ */
75
+ unknownInputs: string[];
76
+ /**
77
+ * The inputs the plan read with a value, by reference. When both shapes
78
+ * carry a reference, the values must be equal, or an input that was
79
+ * known has changed. Optional: a shape without it is checked on its
80
+ * entries alone, plus the change set's own attributes in core.
81
+ */
82
+ knownInputs?: Record<string, unknown>;
83
+ }
84
+
85
+ const SKIPPED: ReadonlySet<ChangeSetAction> = new Set(["no-op", "read"]);
86
+
87
+ const REPLACEMENT_RANK: Record<ShapeReplacement, number> = { false: 0, conditional: 1, true: 2 };
88
+
89
+ /** An entry with property detail is compared whatever its action: a lexicon that lists properties means it. */
90
+ const skipped = (e: PlanShapeEntry): boolean => SKIPPED.has(e.action) && e.properties === undefined;
91
+
92
+ /**
93
+ * Every way `fresh` goes beyond `previewed`, as reasons; none means covered.
94
+ * Both are shapes of the same member.
95
+ *
96
+ * The fresh plan may match the preview exactly, or be narrower where an
97
+ * unknown input drives it: a property whose real value equals the current one
98
+ * drops out, a replacement that depended on a stand-in may not happen. It
99
+ * may never add a resource, add a property, change an action or a type,
100
+ * replace more than previewed, read an input that is still unknown, or read a
101
+ * known input as another value.
102
+ */
103
+ export function planShapeDifferences(previewed: PlanShape, fresh: PlanShape): string[] {
104
+ const member = fresh.member;
105
+ const out: string[] = [];
106
+ const was = new Map(previewed.entries.map((e) => [e.logicalId, e]));
107
+ const now = new Set<string>();
108
+ for (const e of fresh.entries) {
109
+ if (skipped(e)) continue;
110
+ now.add(e.logicalId);
111
+ const p = was.get(e.logicalId);
112
+ if (!p) {
113
+ out.push(`${member} now plans to ${e.action} ${e.logicalId}, which the first plan did not`);
114
+ continue;
115
+ }
116
+ if (p.action !== e.action) out.push(`${member} now plans to ${e.action} ${e.logicalId}, where the first plan showed ${p.action}`);
117
+ if (p.type !== undefined && e.type !== undefined && p.type !== e.type) out.push(`${member} now has ${e.logicalId} as ${e.type}, where the first plan showed ${p.type}`);
118
+ if (p.properties && e.properties) {
119
+ const extra = e.properties.filter((x) => !p.properties!.includes(x));
120
+ if (extra.length > 0) out.push(`${member} now also changes ${extra.join(", ")} on ${e.logicalId}`);
121
+ const driven = p.unknown ?? [];
122
+ const lost = p.properties.filter((x) => !driven.includes(x) && !e.properties!.includes(x));
123
+ if (lost.length > 0) out.push(`${member} no longer changes ${lost.join(", ")} on ${e.logicalId}, which no unknown input drives`);
124
+ }
125
+ if (e.replacement === "true" && p.replacement !== "true" && p.replacement !== "conditional") {
126
+ out.push(`${member} now replaces ${e.logicalId}, which the first plan did not show`);
127
+ } else if (e.replacement === "conditional" && p.replacement !== "conditional" && p.replacement !== "true") {
128
+ out.push(`${member} may now replace ${e.logicalId}, which the first plan did not show`);
129
+ } else if (e.replacement && p.replacement && p.unknown?.length === 0 && REPLACEMENT_RANK[e.replacement] < REPLACEMENT_RANK[p.replacement]) {
130
+ out.push(`${member} replacement of ${e.logicalId} was ${p.replacement}, now ${e.replacement}, and no unknown input drives it`);
131
+ }
132
+ }
133
+ // A previewed change that is gone: allowed only where unknown inputs drive all of it.
134
+ for (const p of previewed.entries) {
135
+ if (now.has(p.logicalId) || skipped(p) || !p.properties) continue;
136
+ const driven = p.unknown ?? [];
137
+ if (!(p.properties.length > 0 && p.properties.every((x) => driven.includes(x)))) {
138
+ out.push(`${member} no longer plans to ${p.action} ${p.logicalId}, which the first plan did and no unknown input drives`);
139
+ }
140
+ }
141
+ const unknown = new Set(previewed.unknownInputs);
142
+ const stillUnknown = fresh.unknownInputs[0];
143
+ if (stillUnknown) out.push(`${member} still reads ${stillUnknown}, which is not known yet`);
144
+ for (const [ref, value] of Object.entries(fresh.knownInputs ?? {})) {
145
+ if (unknown.has(ref)) continue;
146
+ if (!previewed.knownInputs) continue;
147
+ if (!(ref in previewed.knownInputs)) out.push(`${member} now reads ${ref}, which the first plan did not`);
148
+ else if (JSON.stringify(previewed.knownInputs[ref] ?? null) !== JSON.stringify(value ?? null)) {
149
+ out.push(`${member} now reads ${ref} as a different value than the first plan`);
150
+ }
151
+ }
152
+ return out;
153
+ }
154
+
155
+ /**
156
+ * Why `fresh` is not covered by `previewed`, or `undefined` when it is: the
157
+ * first of {@link planShapeDifferences}.
158
+ */
159
+ export function planShapeCovers(previewed: PlanShape, fresh: PlanShape): string | undefined {
160
+ return planShapeDifferences(previewed, fresh)[0];
161
+ }
162
+
163
+ /** A shape in the order that makes equal shapes digest equal. */
164
+ export function normalizePlanShape(shape: PlanShape): PlanShape {
165
+ const sorted = (xs: string[]): string[] => [...new Set(xs)].sort();
166
+ return {
167
+ member: shape.member,
168
+ entries: shape.entries
169
+ .map((e) => ({
170
+ logicalId: e.logicalId,
171
+ action: e.action,
172
+ ...(e.replacement ? { replacement: e.replacement } : {}),
173
+ ...(e.type !== undefined ? { type: e.type } : {}),
174
+ ...(e.properties ? { properties: sorted(e.properties) } : {}),
175
+ ...(e.unknown ? { unknown: sorted(e.unknown) } : {}),
176
+ }))
177
+ .sort((a, b) => a.logicalId.localeCompare(b.logicalId) || a.action.localeCompare(b.action)),
178
+ unknownInputs: sorted(shape.unknownInputs),
179
+ ...(shape.knownInputs ? { knownInputs: shape.knownInputs } : {}),
180
+ };
181
+ }
182
+
183
+ export function planShapeDigest(shape: PlanShape): string {
184
+ return computePlanDigest("plan-shape", normalizePlanShape(shape));
185
+ }
186
+
187
+ /**
188
+ * What a lexicon hands the run for a previewed member, through
189
+ * `DeployContext.plans[member]`. `kind` is the lexicon's own so its `run`
190
+ * can tell a shape from its other artifacts.
191
+ */
192
+ export interface PlanShapeArtifact {
193
+ kind: string;
194
+ member: string;
195
+ shape: PlanShape;
196
+ digest: string;
197
+ }
198
+
199
+ /**
200
+ * Thrown by a member's `run` when the change it created is not covered by the
201
+ * shape previewed. The change set is deleted unexecuted. `planMoved` is
202
+ * core's mark for a moved plan, so the command that applied it exits 3.
203
+ */
204
+ export class PlanShapeMovedError extends Error {
205
+ readonly planMoved = true;
206
+ constructor(
207
+ public readonly member: string,
208
+ public readonly differences: string[],
209
+ ) {
210
+ super(`"${member}": refusing to apply. The change differs from the preview that was approved: ${differences.join("; ")}. Plan it again.`);
211
+ this.name = "PlanShapeMovedError";
212
+ }
213
+ }
214
+
215
+ /** The shape a change-set document gives for `member`, when its lexicon supplies none. */
216
+ export function shapeFromChangeSet(doc: ChangeSetDocument, member: string, inputs: { unknownInputs?: string[]; knownInputs?: Record<string, unknown> } = {}): PlanShape {
217
+ return {
218
+ member,
219
+ entries: doc.entries
220
+ .filter((e) => e.member === member)
221
+ .map((e) => ({ logicalId: e.deposed ? `${e.address}#${e.deposed}` : e.address, action: e.action })),
222
+ unknownInputs: [...(inputs.unknownInputs ?? [])].sort(),
223
+ ...(inputs.knownInputs ? { knownInputs: inputs.knownInputs } : {}),
224
+ };
225
+ }
226
+
227
+ /** What a round was covered by, as the report records it (`PrRound.covered`). */
228
+ export interface RoundCover {
229
+ /** The digest of the first approval, which the coverage is bound to. */
230
+ digest: string;
231
+ /** The inputs the first plan marked unknown and this round planned with a value, `<component>.<output>`, sorted. */
232
+ filledInputs: string[];
233
+ }
234
+
235
+ export type RoundCoverage = ({ covered: true } & RoundCover) | { covered: false; reason: string };
236
+
237
+ /** One side of the comparison: a plan set, as far as coverage needs it. */
238
+ export interface CoverageSide {
239
+ doc: ChangeSetDocument;
240
+ /** Per member, its component and (first plan only) the inputs it was previewed without. */
241
+ members: { member: string; component: string; unknownInputs?: string[] }[];
242
+ /** Shapes a lexicon supplied, by member. Where absent, the change set gives the shape. */
243
+ shapes?: Record<string, PlanShape>;
244
+ }
245
+
246
+ export interface CoveredRoundInput {
247
+ /** The first plan, whose approval is being relied on. */
248
+ approved: CoverageSide;
249
+ /** The digest that approval binds: the report's `digest`. */
250
+ approvedDigest: string;
251
+ /** The round's fresh plan. */
252
+ fresh: CoverageSide;
253
+ /**
254
+ * Known inputs that changed between the first plan and the round, as
255
+ * `<component>.<output>`: an input the first plan read with a value that
256
+ * stands as another one now. Core reads them from the outputs.
257
+ */
258
+ changedKnown?: ReadonlyMap<string, string[]> | Record<string, string[]>;
259
+ /** The check on the change set's own attributes, per member (`planCoveredBy`). */
260
+ attributes?: (member: string) => string | undefined;
261
+ }
262
+
263
+ /**
264
+ * Whether the approval of `approvedDigest` covers `fresh`. Covered, the
265
+ * result names the digest and the inputs that were filled in; not covered,
266
+ * the reason, which the apply reports with the approval it asks for.
267
+ */
268
+ export function coveredRound(input: CoveredRoundInput): RoundCoverage {
269
+ const { approved, fresh } = input;
270
+ const previewedComponents = new Set(approved.members.map((m) => m.component));
271
+ const approvedMember = new Map(approved.members.map((m) => [m.member, m]));
272
+ const filled = new Set<string>();
273
+ for (const m of fresh.members) {
274
+ if (!previewedComponents.has(m.component)) return { covered: false, reason: `${m.component} was not in the first plan` };
275
+ const was = approvedMember.get(m.member);
276
+ if (!was) return { covered: false, reason: `${m.member} was not in the first plan` };
277
+ if (was.component !== m.component) return { covered: false, reason: `${m.member} moved from ${was.component} to ${m.component}` };
278
+ const previewed = approved.shapes?.[m.member] ?? shapeFromChangeSet(approved.doc, m.member, { unknownInputs: was.unknownInputs });
279
+ const both = [...new Set([...(previewed.unknownInputs ?? []), ...(was.unknownInputs ?? [])])];
280
+ // A lexicon that only knows the upstream stack lists the bare component; the member names the output. Keep the named one.
281
+ const unknownInputs = both.filter((ref) => !both.some((other) => other.startsWith(`${ref}.`))).sort();
282
+ const now = fresh.shapes?.[m.member] ?? shapeFromChangeSet(fresh.doc, m.member);
283
+ const reason = planShapeCovers({ ...previewed, unknownInputs }, now);
284
+ if (reason) return { covered: false, reason };
285
+ const changed = (input.changedKnown instanceof Map ? input.changedKnown.get(m.component) : (input.changedKnown as Record<string, string[]> | undefined)?.[m.component]) ?? [];
286
+ const changedKnown = changed.filter((ref: string) => !unknownInputs.includes(ref));
287
+ if (changedKnown.length > 0) return { covered: false, reason: `${m.member} reads ${changedKnown.join(", ")}, which the first plan read as another value` };
288
+ const attrs = input.attributes?.(m.member);
289
+ if (attrs) return { covered: false, reason: attrs };
290
+ for (const ref of unknownInputs) filled.add(ref);
291
+ }
292
+ return { covered: true, digest: input.approvedDigest, filledInputs: [...filled].sort() };
293
+ }
@@ -391,6 +391,18 @@ export function unresolvedWiringReferences(
391
391
  return wiringReferences(input).filter((r) => r.value(componentOutputs) === undefined).map(({ source, ref, publish }) => ({ source, ref, publish }));
392
392
  }
393
393
 
394
+ /**
395
+ * Every cross-component reference in `input`, sorted by `ref` and each once,
396
+ * with whether `componentOutputs` holds a value for it. A pull request's
397
+ * report records each as a read between components, known at plan or not.
398
+ */
399
+ export function wiringReads(
400
+ input: Record<string, unknown>,
401
+ componentOutputs: Record<string, Record<string, unknown>>,
402
+ ): Array<WiringReference & { known: boolean }> {
403
+ return wiringReferences(input).map(({ source, ref, publish, value }) => ({ source, ref, publish, known: value(componentOutputs) !== undefined }));
404
+ }
405
+
394
406
  /**
395
407
  * Every cross-component reference in `input`, each once, sorted by `ref`,
396
408
  * with the value it resolves to against a given outputs map.
@@ -55,6 +55,23 @@ export {
55
55
  CapabilityRegistry,
56
56
  CapabilityNotImplementedError,
57
57
  } from "./capability";
58
+ export {
59
+ coveredRound,
60
+ normalizePlanShape,
61
+ PlanShapeMovedError,
62
+ planShapeCovers,
63
+ planShapeDifferences,
64
+ planShapeDigest,
65
+ shapeFromChangeSet,
66
+ type CoveredRoundInput,
67
+ type CoverageSide,
68
+ type PlanShape,
69
+ type PlanShapeArtifact,
70
+ type PlanShapeEntry,
71
+ type RoundCover,
72
+ type RoundCoverage,
73
+ type ShapeReplacement,
74
+ } from "./covered-round";
58
75
  export { createCapabilityRegistry, STARTER_VERB_FAMILIES } from "./registry";
59
76
  export {
60
77
  type CapabilityPlugin,