Skip to content

Commit c2332ba

Browse files
author
settings-as-code-release
committed
refactor(snapshot): take the engine's SectionSelection and Result at the snapshot boundary
The snapshot options carry the engine's SectionSelection instead of a bare allowlist set, so the allowlist predicate is the one the apply pipeline reads. The per-section validation reads the Result validateSettingsDoc now returns and renders a refused fragment through describeProblem. Nothing else in the ten replayed commits changed.
1 parent 816ac8b commit c2332ba

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

‎src/engine/snapshot.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { stringify as stringifyYaml } from "yaml";
88
import type { RepoRef } from "../discovery/targets.js";
99
import type { GithubClient } from "../github/api.js";
1010
import type { Io } from "../io.js";
11+
import { describeProblem } from "../problem.js";
1112
import type { SectionKey } from "../schema.js";
1213
import {
1314
type EndpointDecl,
@@ -23,7 +24,7 @@ import {
2324
} from "../sections/contract/module.js";
2425
import { planContext } from "../sections/contract/plan.js";
2526
import { SECTIONS } from "../sections/registry.js";
26-
import { deniedSectionStatus, excludedBySections, type ValidatedSettings, type ValidatedSettings, validateSettingsDoc, validateSettingsDoc } from "./orchestrate.js";
27+
import { type ValidatedSettings, validateSettingsDoc } from "./orchestrate.js";
2728
import type { SectionSelection } from "./section-selection.js";
2829

2930
export interface SnapshotOptions {
@@ -181,14 +182,14 @@ export async function snapshotRepository(
181182
new Set(),
182183
io,
183184
);
184-
if ("error" in verdict) {
185-
const detail = `BUG: ${section.key} produced a snapshot its own schema rejects - ${verdict.error}`;
185+
if (verdict.isErr()) {
186+
const detail = `BUG: ${section.key} produced a snapshot its own schema rejects - ${describeProblem(verdict.error)}`;
186187
io.annotate("error", detail);
187188
outcomes.push({ key: section.key, status: "failed", detail: [...snapshot.notes, detail] });
188189
failed = true;
189190
continue;
190191
}
191-
document[section.key] = verdict.settings[section.key];
192+
document[section.key] = verdict.value[section.key];
192193
outcomes.push({ key: section.key, status: "snapshot", detail: [...snapshot.notes] });
193194
}
194195

@@ -198,15 +199,15 @@ export async function snapshotRepository(
198199
// The brand's one mint, over the already-parsed fragments: every section validated alone
199200
// above, so the whole cannot fail.
200201
const verdict = validateSettingsDoc(document, `the snapshot of ${opts.repo.slug}`, new Set(), io);
201-
if ("error" in verdict) {
202+
if (verdict.isErr()) {
202203
throw new Error(
203-
`BUG: the assembled snapshot of ${opts.repo.slug} failed validation after every section validated on its own: ${verdict.error}`,
204+
`BUG: the assembled snapshot of ${opts.repo.slug} failed validation after every section validated on its own: ${describeProblem(verdict.error)}`,
204205
);
205206
}
206207
return {
207208
repo: opts.repo.slug,
208209
result: partial ? "partial" : "snapshot",
209-
settings: verdict.settings,
210+
settings: verdict.value,
210211
outcomes,
211212
};
212213
}

‎test/engine/secrets.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import {
44
type ValidatedSettings,
55
validateSettingsDoc,
66
} from "../../src/engine/orchestrate.js";
7-
import type { SettingsSource } from "../../src/engine/secret-refs.js";
87
import { type SettingsSource, validateSecretRef } from "../../src/engine/secret-refs.js";
9-
import { collectSecretValues, collectSecretValues, snapshotSecretReference } from "../../src/engine/secrets.js";
8+
import { collectSecretValues, snapshotSecretReference } from "../../src/engine/secrets.js";
109
import { SectionSelection } from "../../src/engine/section-selection.js";
1110
import { type Io, maskRegistry } from "../../src/io.js";
1211
import { describeProblem } from "../../src/problem.js";

‎test/engine/snapshot.test.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ describe("snapshotRepository", () => {
149149
const { io, annotations } = captureIo();
150150
const result = await snapshotRepository(
151151
denied,
152-
{ ...opts(), onlySections: new Set(["pages", "custom_properties"]) },
152+
{
153+
...opts(),
154+
sections: SectionSelection.of({ only: ["pages", "custom_properties"] })._unsafeUnwrap(),
155+
},
153156
io,
154157
);
155158
const note =
@@ -173,7 +176,7 @@ describe("snapshotRepository", () => {
173176
});
174177
const present = await snapshotRepository(
175178
live,
176-
{ ...opts(), onlySections: new Set(["pages"]) },
179+
{ ...opts(), sections: SectionSelection.of({ only: ["pages"] })._unsafeUnwrap() },
177180
captureIo().io,
178181
);
179182
expect(present.outcomes).toEqual([{ key: "pages", status: "snapshot", detail: [] }]);
@@ -185,7 +188,7 @@ describe("snapshotRepository", () => {
185188
const quiet = captureIo();
186189
const nothing = await snapshotRepository(
187190
live,
188-
{ ...opts(), onlySections: new Set(["pages"]) },
191+
{ ...opts(), sections: SectionSelection.of({ only: ["pages"] })._unsafeUnwrap() },
189192
quiet.io,
190193
);
191194
expect(nothing.outcomes).toEqual([{ key: "pages", status: "snapshot", detail: [NOTHING] }]);
@@ -294,7 +297,12 @@ describe("snapshotRepository shape guard", () => {
294297
};
295298
const result = await snapshotRepository(
296299
nulling,
297-
{ ...opts(), onlySections: new Set(["code_scanning_default_setup", "labels"]) },
300+
{
301+
...opts(),
302+
sections: SectionSelection.of({
303+
only: ["code_scanning_default_setup", "labels"],
304+
})._unsafeUnwrap(),
305+
},
298306
captureIo().io,
299307
);
300308
expect(result.result).toBe("failed");
@@ -323,7 +331,7 @@ describe("pages null body", () => {
323331
};
324332
const result = await snapshotRepository(
325333
nulling,
326-
{ ...opts(), onlySections: new Set(["pages"]) },
334+
{ ...opts(), sections: SectionSelection.of({ only: ["pages"] })._unsafeUnwrap() },
327335
captureIo().io,
328336
);
329337
expect(result.result).toBe("partial");

0 commit comments

Comments
 (0)