@intentius/chant 0.124.70 → 0.124.71
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/dist/ci-agent.d.ts +12 -1
- package/dist/ci-agent.d.ts.map +1 -1
- package/dist/ci-agent.js +13 -8
- package/dist/ci-commit.d.ts +297 -0
- package/dist/ci-commit.d.ts.map +1 -0
- package/dist/ci-commit.js +696 -0
- package/dist/ci-product-words.d.ts +6 -1
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +3 -1
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +7 -2
- package/dist/cli/handlers/commit.d.ts +26 -0
- package/dist/cli/handlers/commit.d.ts.map +1 -0
- package/dist/cli/handlers/commit.js +142 -0
- package/dist/cli/handlers/pr.d.ts +6 -0
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +16 -7
- package/dist/cli/handlers/release.d.ts +9 -0
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +114 -5
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +17 -0
- package/dist/components/product-pipeline.d.ts +33 -0
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +34 -1
- package/dist/components/release-compile.d.ts +2 -0
- package/dist/components/release-compile.d.ts.map +1 -1
- package/dist/components/release-compile.js +8 -4
- package/dist/config.d.ts +46 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +9 -0
- package/dist/lexicon.d.ts +37 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lexicon.js +28 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +4 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
- package/dist/lifecycle/__fixtures__/publish-fakes.js +6 -2
- package/dist/lifecycle/gated-request.d.ts +3 -1
- package/dist/lifecycle/gated-request.d.ts.map +1 -1
- package/dist/lifecycle/gated-request.js +5 -2
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +57 -0
- package/dist/lifecycle/publish-declaration.d.ts +16 -0
- package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
- package/dist/lifecycle/publish-declaration.js +35 -3
- package/dist/lifecycle/publish-forge.d.ts +12 -0
- package/dist/lifecycle/publish-forge.d.ts.map +1 -1
- package/dist/lifecycle/publish-forge.js +103 -19
- package/dist/lifecycle/publish-npm.d.ts +15 -0
- package/dist/lifecycle/publish-npm.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.js +28 -1
- package/dist/lifecycle/publish-oci.d.ts +2 -0
- package/dist/lifecycle/publish-oci.d.ts.map +1 -1
- package/dist/lifecycle/publish-oci.js +10 -0
- package/dist/lifecycle/release-cut.d.ts +7 -1
- package/dist/lifecycle/release-cut.d.ts.map +1 -1
- package/dist/lifecycle/release-cut.js +8 -1
- package/dist/lifecycle/release-images.d.ts +87 -0
- package/dist/lifecycle/release-images.d.ts.map +1 -0
- package/dist/lifecycle/release-images.js +139 -0
- package/dist/lifecycle/release-publish.d.ts +2 -0
- package/dist/lifecycle/release-publish.d.ts.map +1 -1
- package/dist/op/activities/activity-contracts.d.ts +4 -4
- package/dist/op/activities/review-agent.d.ts.map +1 -1
- package/dist/op/activities/review-agent.js +4 -2
- package/dist/op/gate.d.ts +5 -1
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +7 -2
- package/dist/op/op-waves-notify.d.ts +1 -1
- package/dist/op/op-waves-notify.d.ts.map +1 -1
- package/dist/op/op-waves-notify.js +2 -1
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +12 -8
- package/dist/op/op-waves.d.ts +9 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +11 -0
- package/dist/pr-forge-base.d.ts +18 -0
- package/dist/pr-forge-base.d.ts.map +1 -0
- package/dist/pr-forge-base.js +29 -0
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/wave-runtime.mjs +315 -315
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +1 -2
- package/dist/workspace/release-workflow.d.ts +23 -0
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +203 -12
- package/package.json +1 -1
- package/src/ci-agent.ts +13 -8
- package/src/ci-commit.test.ts +415 -0
- package/src/ci-commit.ts +857 -0
- package/src/ci-product-words.ts +6 -2
- package/src/cli/handlers/approve.ts +6 -2
- package/src/cli/handlers/commit.ts +152 -0
- package/src/cli/handlers/operator.test.ts +2 -0
- package/src/cli/handlers/pr-wave-approve-lines.test.ts +32 -0
- package/src/cli/handlers/pr.ts +17 -7
- package/src/cli/handlers/release.ts +110 -5
- package/src/cli/main.ts +17 -0
- package/src/components/product-pipeline.test.ts +28 -1
- package/src/components/product-pipeline.ts +54 -1
- package/src/components/release-compile.ts +9 -3
- package/src/config.ts +24 -0
- package/src/lexicon.ts +56 -0
- package/src/lifecycle/__fixtures__/publish-fakes.ts +11 -5
- package/src/lifecycle/gated-request-spend.test.ts +115 -0
- package/src/lifecycle/gated-request.ts +5 -2
- package/src/lifecycle/git.ts +53 -0
- package/src/lifecycle/ledger-two-clones.test.ts +132 -0
- package/src/lifecycle/publish-declaration.ts +35 -3
- package/src/lifecycle/publish-forge-notes.test.ts +193 -0
- package/src/lifecycle/publish-forge.ts +101 -22
- package/src/lifecycle/publish-npm.ts +31 -2
- package/src/lifecycle/publish-oci.ts +10 -0
- package/src/lifecycle/publish-targets.test.ts +2 -1
- package/src/lifecycle/release-cut.ts +17 -1
- package/src/lifecycle/release-images.test.ts +242 -0
- package/src/lifecycle/release-images.ts +175 -0
- package/src/lifecycle/release-publish.ts +2 -0
- package/src/op/activities/review-agent.test.ts +20 -1
- package/src/op/activities/review-agent.ts +5 -2
- package/src/op/gate.ts +7 -2
- package/src/op/op-waves-approve-target.test.ts +108 -0
- package/src/op/op-waves-notify.ts +2 -2
- package/src/op/op-waves-run.ts +12 -7
- package/src/op/op-waves.ts +12 -0
- package/src/pr-forge-base.test.ts +37 -0
- package/src/pr-forge-base.ts +36 -0
- package/src/release-floors.ts +1 -1
- package/src/workspace/__fixtures__/release-workflow/forgejo-plain-member.yml +26 -0
- package/src/workspace/__fixtures__/release-workflow/forgejo-plain.yml +23 -0
- package/src/workspace/__fixtures__/release-workflow/forgejo-secure-member.yml +27 -0
- package/src/workspace/__fixtures__/release-workflow/forgejo-secure.yml +24 -0
- package/src/workspace/__fixtures__/release-workflow/github-plain-member.yml +26 -0
- package/src/workspace/__fixtures__/release-workflow/github-plain.yml +23 -0
- package/src/workspace/__fixtures__/release-workflow/github-secure-member.yml +27 -0
- package/src/workspace/__fixtures__/release-workflow/github-secure.yml +24 -0
- package/src/workspace/__fixtures__/release-workflow/gitlab-plain-member.yml +13 -0
- package/src/workspace/__fixtures__/release-workflow/gitlab-plain.yml +12 -0
- package/src/workspace/__fixtures__/release-workflow/gitlab-secure-member.yml +14 -0
- package/src/workspace/__fixtures__/release-workflow/gitlab-secure.yml +13 -0
- package/src/workspace/ci-green.ts +1 -2
- package/src/workspace/release-workflow.test.ts +151 -0
- package/src/workspace/release-workflow.ts +270 -12
|
@@ -288,6 +288,16 @@ export function ociTags(decl: OciPublishDeclaration, ctx: Pick<PublishContext, "
|
|
|
288
288
|
return declared.filter((t) => ctx.label !== null || !t.includes("{label}")).map((t) => t.split("{label}").join(ctx.label ?? ""));
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
+
/** The digest an OCI archive (a layout directory or a tar file of one) is pushed under: its top manifest's (#4657). */
|
|
292
|
+
export function ociArchiveDigest(abs: string): string {
|
|
293
|
+
const layout = readLayout(abs);
|
|
294
|
+
try {
|
|
295
|
+
return layout.top.digest;
|
|
296
|
+
} finally {
|
|
297
|
+
layout.cleanup();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
291
301
|
export function ociTarget(decl: OciPublishDeclaration, deps: PublishDeps): PublishTarget {
|
|
292
302
|
const repo = parseRepository(decl.repository);
|
|
293
303
|
const fetchImpl: PublishFetch = deps.fetch ?? ((url, init) => fetch(url, init as RequestInit));
|
|
@@ -371,7 +371,8 @@ describe("forge release assets", () => {
|
|
|
371
371
|
|
|
372
372
|
await target!.reveal(ctx, staged);
|
|
373
373
|
expect(forge.visible()).toEqual([{ tag: "release/v1.4.0", assets: ATTACHED }]);
|
|
374
|
-
|
|
374
|
+
// #4658: GitHub is told the release is latest, since it was not cut to a channel.
|
|
375
|
+
expect(forge.calls.at(-1)).toMatchObject({ method: "PATCH", url: `${api}/repos/acme/api/releases/100`, body: JSON.stringify({ draft: false, make_latest: "true" }) });
|
|
375
376
|
expect(ctx.lines.join("\n")).not.toContain("ghs_tokentoken");
|
|
376
377
|
|
|
377
378
|
// Published with every asset: a stage finds it done and uploads nothing.
|
|
@@ -112,6 +112,8 @@ export type ReleaseCutCode =
|
|
|
112
112
|
| "release-build-inputs-differ"
|
|
113
113
|
| "release-image-invalid"
|
|
114
114
|
| "release-image-unknown-component"
|
|
115
|
+
| "release-image-name-taken"
|
|
116
|
+
| "release-image-build-failed"
|
|
115
117
|
| "release-unsigned"
|
|
116
118
|
| "release-signer-refused"
|
|
117
119
|
| "declaration-invalid";
|
|
@@ -171,6 +173,12 @@ export interface CutRequest {
|
|
|
171
173
|
* image, and the cut builds nothing for it.
|
|
172
174
|
*/
|
|
173
175
|
images?: Readonly<Record<string, string>>;
|
|
176
|
+
/**
|
|
177
|
+
* Build the images `release.images` declares (#4657), before any
|
|
178
|
+
* environment is compiled, so the build command can read their digests.
|
|
179
|
+
* Given the commit being cut; returns each as an image artifact.
|
|
180
|
+
*/
|
|
181
|
+
buildImages?: (commit: string) => Promise<ReleaseArtifact[]> | ReleaseArtifact[];
|
|
174
182
|
}
|
|
175
183
|
|
|
176
184
|
export interface CutResult {
|
|
@@ -462,6 +470,9 @@ async function prepare(req: CutRequest, record = false): Promise<Prepared> {
|
|
|
462
470
|
);
|
|
463
471
|
}
|
|
464
472
|
|
|
473
|
+
// #4657: the images first, so the build command that packs a package can pin their digests.
|
|
474
|
+
const builtImages = req.buildImages ? await req.buildImages(commit) : [];
|
|
475
|
+
|
|
465
476
|
const compiled: CompiledTarget[] = [];
|
|
466
477
|
for (const env of envs) compiled.push(await req.compiler.compile(env));
|
|
467
478
|
|
|
@@ -499,6 +510,11 @@ async function prepare(req: CutRequest, record = false): Promise<Prepared> {
|
|
|
499
510
|
handedArtifacts.push(artifact);
|
|
500
511
|
}
|
|
501
512
|
const handedTo = new Set(handedArtifacts.map((a) => a.component));
|
|
513
|
+
for (const image of builtImages) {
|
|
514
|
+
if (enabled.has(image.component) || handedTo.has(image.component)) {
|
|
515
|
+
throw new ReleaseCutError("release-image-name-taken", `release.images names "${image.component}", which is also a component of this member, and a release records one image per name`, "Rename the image in release.images.");
|
|
516
|
+
}
|
|
517
|
+
}
|
|
502
518
|
|
|
503
519
|
// Which environment each component's artifacts are built in: the first one it is enabled in.
|
|
504
520
|
const firstEnv = new Map<string, CompiledTarget>();
|
|
@@ -510,7 +526,7 @@ async function prepare(req: CutRequest, record = false): Promise<Prepared> {
|
|
|
510
526
|
const realCwd = realpathSync(cwd);
|
|
511
527
|
const previous = firstEnv.size > 0 ? await previousRelease(top, commit, cwd) : undefined;
|
|
512
528
|
const reused: CutResult["reused"] = [];
|
|
513
|
-
const artifacts: ReleaseArtifact[] = [...handedArtifacts];
|
|
529
|
+
const artifacts: ReleaseArtifact[] = [...handedArtifacts, ...builtImages];
|
|
514
530
|
const toBuild = new Map<string, string[]>();
|
|
515
531
|
for (const [component, target] of firstEnv) {
|
|
516
532
|
const prior = previous?.artifactDigests.filter((a) => a.component === component) ?? [];
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4657 (option 1): the cut builds the release's images, records their
|
|
3
|
+
* digests, and hands them to the build that packs the package; one cut and
|
|
4
|
+
* one publish take the release out, and the package pins what is pushed.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { afterAll, describe, expect, test } from "vitest";
|
|
8
|
+
import { execFileSync } from "node:child_process";
|
|
9
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { dirname, join } from "node:path";
|
|
11
|
+
import { cutRelease, ReleaseCutError } from "./release-cut";
|
|
12
|
+
import { createRedactor } from "./publish-credentials";
|
|
13
|
+
import { PublishDeclarationSchema } from "./publish-declaration";
|
|
14
|
+
import { ociArchiveDigest } from "./publish-oci";
|
|
15
|
+
import { createPublishTargets } from "./publish-targets";
|
|
16
|
+
import { runPublish, PublishTargetError, type PublishContext } from "./release-publish";
|
|
17
|
+
import {
|
|
18
|
+
buildReleaseImages,
|
|
19
|
+
checkReleaseImages,
|
|
20
|
+
packagePinProblem,
|
|
21
|
+
pinnedDigests,
|
|
22
|
+
readPins,
|
|
23
|
+
releaseImageDigests,
|
|
24
|
+
ReleaseImageError,
|
|
25
|
+
unknownPins,
|
|
26
|
+
writeReleaseDigests,
|
|
27
|
+
} from "./release-images";
|
|
28
|
+
import type { Release, ReleaseArtifact } from "./release-store";
|
|
29
|
+
import { readFakeNpmRegistry, seedFakeNpmRegistry, startFakeRegistry, writeFakeNpm, writeLockfile, writeOciLayout, writePackage } from "./__fixtures__/publish-fakes";
|
|
30
|
+
import type { CompiledTarget, TargetCompiler } from "../components/release-compile";
|
|
31
|
+
import { TestRepo } from "../workspace/trust/test-repo";
|
|
32
|
+
|
|
33
|
+
const repos: TestRepo[] = [];
|
|
34
|
+
afterAll(() => {
|
|
35
|
+
for (const r of repos) rmSync(dirname(r.dir), { recursive: true, force: true });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const D = (c: string) => `sha256:${c.repeat(64)}`;
|
|
39
|
+
const NO_OIDC = { oidc: false, ci: null, reason: "not in CI" };
|
|
40
|
+
|
|
41
|
+
describe("release.images (#4657)", () => {
|
|
42
|
+
test("names are checked, and an archive outside the member is refused", () => {
|
|
43
|
+
expect(() => checkReleaseImages([{ name: "a b", build: "x", archive: "a.tar" }])).toThrow(/not a name/);
|
|
44
|
+
expect(() => checkReleaseImages([{ name: "a", build: "x", archive: "a.tar" }, { name: "a", build: "y", archive: "b.tar" }])).toThrow(/twice/);
|
|
45
|
+
expect(() => checkReleaseImages([{ name: "a", build: "x", archive: "../a.tar" }])).toThrow(/not a path inside the member/);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("each build runs with SOURCE_DATE_EPOCH and the label, and its archive's top manifest digest is recorded", () => {
|
|
49
|
+
const r = new TestRepo("release-images-build");
|
|
50
|
+
repos.push(r);
|
|
51
|
+
const seen: Array<Record<string, string | undefined>> = [];
|
|
52
|
+
const built = buildReleaseImages({
|
|
53
|
+
images: [{ name: "tofu", build: "build tofu", archive: "out/tofu" }],
|
|
54
|
+
cwd: r.dir,
|
|
55
|
+
sourceDateEpoch: 1762473600,
|
|
56
|
+
label: "v2",
|
|
57
|
+
env: { PATH: process.env.PATH, CHANT_RELEASE_LABEL: "from the shell" },
|
|
58
|
+
archiveDigest: ociArchiveDigest,
|
|
59
|
+
run: (_command, o) => {
|
|
60
|
+
seen.push({ epoch: o.env.SOURCE_DATE_EPOCH, label: o.env.CHANT_RELEASE_LABEL });
|
|
61
|
+
writeOciLayout(join(o.cwd, "out/tofu"), "tofu layer");
|
|
62
|
+
return 0;
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
const expected = ociArchiveDigest(join(r.dir, "out/tofu"));
|
|
66
|
+
expect(built).toEqual([{ component: "tofu", kind: "image", path: "out/tofu", digest: expected }]);
|
|
67
|
+
expect(seen).toEqual([{ epoch: "1762473600", label: "v2" }]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("a failed build and a build that writes no archive stop the cut", () => {
|
|
71
|
+
const base = { cwd: "/nowhere", sourceDateEpoch: 1, label: null, archiveDigest: () => D("a"), images: [{ name: "a", build: "false", archive: "a.tar" }] };
|
|
72
|
+
expect(() => buildReleaseImages({ ...base, run: () => 2 })).toThrow(ReleaseImageError);
|
|
73
|
+
expect(() => buildReleaseImages({ ...base, run: () => 0 })).toThrow(/wrote no a.tar/);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("pins: every sha256 digest in the file is checked against the release's images", () => {
|
|
77
|
+
const release = { artifactDigests: [{ component: "tofu", kind: "image" as const, path: "out/tofu", digest: D("a") }, { component: "x", kind: "asset" as const, path: "x", digest: D("b") }] };
|
|
78
|
+
expect(pinnedDigests(`{"tofu":"${D("a")}","again":"${D("a")}"}`)).toEqual([D("a")]);
|
|
79
|
+
expect(unknownPins(`{"tofu":"${D("a")}"}`, release)).toEqual([]);
|
|
80
|
+
// An asset's digest is not an image's.
|
|
81
|
+
expect(unknownPins(`{"tofu":"${D("b")}"}`, release)).toEqual([D("b")]);
|
|
82
|
+
expect(releaseImageDigests(release)).toEqual({ tofu: D("a") });
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("pins are read from a package directory and from a packed .tgz", () => {
|
|
86
|
+
const r = new TestRepo("release-images-pins");
|
|
87
|
+
repos.push(r);
|
|
88
|
+
const pkg = join(r.dir, "pkg");
|
|
89
|
+
writePackage(pkg, "@acme/api", "1.0.0");
|
|
90
|
+
writeReleaseDigests(join(pkg, "dist", "digests.json"), { tofu: D("c") });
|
|
91
|
+
expect(readPins(pkg, "dist/digests.json", true)).toContain(D("c"));
|
|
92
|
+
expect(readPins(pkg, "dist/nope.json", true)).toBeNull();
|
|
93
|
+
const stage = join(r.dir, "stage");
|
|
94
|
+
mkdirSync(stage);
|
|
95
|
+
execFileSync("cp", ["-R", pkg, join(stage, "package")]);
|
|
96
|
+
execFileSync("tar", ["-czf", join(r.dir, "api.tgz"), "-C", stage, "package"]);
|
|
97
|
+
expect(readPins(join(r.dir, "api.tgz"), "dist/digests.json", false)).toContain(D("c"));
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
/** A member whose cut builds one image and packs one package that pins it, as terragucci's release does. */
|
|
102
|
+
async function cutWithImage(r: TestRepo, opts: { pin?: (digests: Record<string, string>) => Record<string, string> } = {}): Promise<{ release: Release; digestsFile: string; order: string[] }> {
|
|
103
|
+
r.write("chant.config.ts", `export default { environments: ["dev"] };\n`);
|
|
104
|
+
writeLockfile(r.dir);
|
|
105
|
+
r.write(".gitignore", "image/\npackages/\ndigests.json\n");
|
|
106
|
+
const head = r.commit("init");
|
|
107
|
+
r.git(["tag", `ci/green/${head}`]);
|
|
108
|
+
const digestsFile = join(r.dir, "digests.json");
|
|
109
|
+
const order: string[] = [];
|
|
110
|
+
const compiler: TargetCompiler = {
|
|
111
|
+
async compile(env): Promise<CompiledTarget> {
|
|
112
|
+
order.push(`compile ${env}`);
|
|
113
|
+
// The release's build command: pack the package with the digests the cut wrote.
|
|
114
|
+
const digests = JSON.parse(readFileSync(digestsFile, "utf-8")) as Record<string, string>;
|
|
115
|
+
const pkg = join(r.dir, "packages", "api");
|
|
116
|
+
writePackage(pkg, "@acme/api", "2.0.0");
|
|
117
|
+
writeReleaseDigests(join(pkg, "dist", "image-digests.json"), opts.pin ? opts.pin(digests) : digests);
|
|
118
|
+
return { env, params: [], components: [], buildSteps: {}, buildInputs: {}, componentFiles: {}, templates: [{ component: null, path: "dist/out.json", content: "{}\n" }] };
|
|
119
|
+
},
|
|
120
|
+
async buildArtifacts(): Promise<ReleaseArtifact[]> {
|
|
121
|
+
return [];
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
const cut = await cutRelease({
|
|
125
|
+
cwd: r.dir,
|
|
126
|
+
compiler,
|
|
127
|
+
label: "v2",
|
|
128
|
+
actor: "alice",
|
|
129
|
+
env: {},
|
|
130
|
+
now: () => new Date("2026-11-07T10:00:00.000Z"),
|
|
131
|
+
buildImages: () => {
|
|
132
|
+
order.push("images");
|
|
133
|
+
const built = buildReleaseImages({
|
|
134
|
+
images: [{ name: "tofu", build: "build", archive: "image" }],
|
|
135
|
+
cwd: r.dir,
|
|
136
|
+
sourceDateEpoch: 1762473600,
|
|
137
|
+
label: "v2",
|
|
138
|
+
archiveDigest: ociArchiveDigest,
|
|
139
|
+
run: (_c, o) => {
|
|
140
|
+
writeOciLayout(join(o.cwd, "image"), "tofu layer");
|
|
141
|
+
return 0;
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
writeReleaseDigests(digestsFile, Object.fromEntries(built.map((a) => [a.component, a.digest])));
|
|
145
|
+
return built;
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
return { release: cut.release, digestsFile, order };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
describe("one cut and one publish take an image and the package that pins it out (#4657)", () => {
|
|
152
|
+
test("the images are built before the compile, recorded, pinned by the package, pushed under that digest, and a publish run again sends nothing", async () => {
|
|
153
|
+
const r = new TestRepo("release-images-e2e");
|
|
154
|
+
repos.push(r);
|
|
155
|
+
const { release, order } = await cutWithImage(r);
|
|
156
|
+
expect(order).toEqual(["images", "compile dev"]);
|
|
157
|
+
const image = release.artifactDigests.find((a) => a.component === "tofu")!;
|
|
158
|
+
expect(image).toMatchObject({ kind: "image", path: "image" });
|
|
159
|
+
expect(readFileSync(join(r.dir, "packages/api/dist/image-digests.json"), "utf-8")).toContain(image.digest);
|
|
160
|
+
|
|
161
|
+
const reg = await startFakeRegistry({ username: "robot", password: "pw-images-1", token: "tok-images-1" });
|
|
162
|
+
try {
|
|
163
|
+
const log = join(dirname(r.dir), "npm.log");
|
|
164
|
+
seedFakeNpmRegistry(log, { packages: { "@acme/api": { versions: ["1.0.0"], distTags: { latest: "1.0.0" } } } });
|
|
165
|
+
const npm = writeFakeNpm(join(dirname(r.dir), "bin"), log);
|
|
166
|
+
const decls = [
|
|
167
|
+
{ type: "oci", image: "image", repository: `${reg.host}/acme/tofu` },
|
|
168
|
+
{ type: "npm", packages: ["packages/api"], pins: "dist/image-digests.json" },
|
|
169
|
+
].map((d) => PublishDeclarationSchema.parse(d));
|
|
170
|
+
const targets = await createPublishTargets(decls, { npm });
|
|
171
|
+
const env = { PATH: process.env.PATH ?? "", OCI_USERNAME: "robot", OCI_PASSWORD: "pw-images-1" };
|
|
172
|
+
const redactor = createRedactor(env);
|
|
173
|
+
const ctx: PublishContext = { release, label: "v2", releaseTag: "release/v2", provenance: NO_OIDC, cwd: r.dir, tag: null, env, redactor, log: () => {} };
|
|
174
|
+
const publish = () => runPublish({ cwd: r.dir, release, label: "v2", targets, ctx, say: () => {} });
|
|
175
|
+
|
|
176
|
+
await publish();
|
|
177
|
+
// The registry serves the image under the digest the package pins.
|
|
178
|
+
expect(reg.manifests.has(image.digest)).toBe(true);
|
|
179
|
+
expect(reg.manifests.has("v2")).toBe(true);
|
|
180
|
+
expect(readFakeNpmRegistry(log).packages["@acme/api"]!.distTags.latest).toBe("2.0.0");
|
|
181
|
+
|
|
182
|
+
// Run again: no image is pushed twice and the package is not published again.
|
|
183
|
+
const uploads = reg.uploads;
|
|
184
|
+
const npmLines = readFileSync(log, "utf-8").split("\n").filter(Boolean).length;
|
|
185
|
+
const again = await publish();
|
|
186
|
+
expect(reg.uploads).toBe(uploads);
|
|
187
|
+
const after = readFileSync(log, "utf-8").split("\n").filter(Boolean).slice(npmLines).map((l) => (JSON.parse(l) as { args: string[] }).args[0]);
|
|
188
|
+
expect(after).not.toContain("publish");
|
|
189
|
+
expect(again.published.length).toBe(2);
|
|
190
|
+
expect(existsSync(join(r.dir, "image", "index.json"))).toBe(true);
|
|
191
|
+
} finally {
|
|
192
|
+
await reg.close();
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test("a package that pins a digest the release does not record is refused before anything is published, and release verify's check names it", async () => {
|
|
197
|
+
const r = new TestRepo("release-images-bad-pin");
|
|
198
|
+
repos.push(r);
|
|
199
|
+
const { release } = await cutWithImage(r, { pin: () => ({ tofu: D("9") }) });
|
|
200
|
+
const decls = [PublishDeclarationSchema.parse({ type: "npm", packages: ["packages/api"], pins: "dist/image-digests.json" })];
|
|
201
|
+
const [target] = await createPublishTargets(decls, {});
|
|
202
|
+
const env = { PATH: process.env.PATH ?? "" };
|
|
203
|
+
const ctx: PublishContext = { release, label: "v2", releaseTag: "release/v2", provenance: NO_OIDC, cwd: r.dir, tag: null, env, redactor: createRedactor(env), log: () => {} };
|
|
204
|
+
const err = await target!.plan(ctx).catch((e: unknown) => e);
|
|
205
|
+
expect(err).toBeInstanceOf(PublishTargetError);
|
|
206
|
+
expect((err as PublishTargetError).code).toBe("publish-npm-pin-unknown");
|
|
207
|
+
expect(packagePinProblem(r.dir, release, decls)).toMatch(new RegExp(`packages/api pins ${D("9")} in dist/image-digests.json`));
|
|
208
|
+
|
|
209
|
+
const missing = [PublishDeclarationSchema.parse({ type: "npm", packages: ["packages/api"], pins: "dist/nope.json" })];
|
|
210
|
+
const [t2] = await createPublishTargets(missing, {});
|
|
211
|
+
expect(((await t2!.plan(ctx).catch((e: unknown) => e)) as PublishTargetError).code).toBe("publish-npm-pins-missing");
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test("an image named like a component is refused", async () => {
|
|
215
|
+
const r = new TestRepo("release-images-clash");
|
|
216
|
+
repos.push(r);
|
|
217
|
+
r.write("chant.config.ts", `export default { environments: ["dev"] };\n`);
|
|
218
|
+
const head = r.commit("init");
|
|
219
|
+
r.git(["tag", `ci/green/${head}`]);
|
|
220
|
+
const compiler: TargetCompiler = {
|
|
221
|
+
async compile(env) {
|
|
222
|
+
return { env, params: [], components: ["tofu"], buildSteps: {}, buildInputs: {}, componentFiles: { tofu: "tofu.component.ts" }, templates: [{ component: "tofu", path: "a.json", content: "{}" }] };
|
|
223
|
+
},
|
|
224
|
+
async buildArtifacts() {
|
|
225
|
+
return [];
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
const err = await cutRelease({ cwd: r.dir, compiler, label: "v1", actor: "alice", env: {}, buildImages: () => [{ component: "tofu", kind: "image", path: "image", digest: D("a") }] }).catch((e: unknown) => e);
|
|
229
|
+
expect(err).toBeInstanceOf(ReleaseCutError);
|
|
230
|
+
expect((err as ReleaseCutError).code).toBe("release-image-name-taken");
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// Kept beside the e2e so a reader sees the shape the cut hands the build.
|
|
235
|
+
test("the digests file is sorted JSON of name to digest", () => {
|
|
236
|
+
const r = new TestRepo("release-images-file");
|
|
237
|
+
repos.push(r);
|
|
238
|
+
const file = join(r.dir, "d", "digests.json");
|
|
239
|
+
writeReleaseDigests(file, { z: D("1"), a: D("2") });
|
|
240
|
+
expect(readFileSync(file, "utf-8")).toBe(`{\n "a": "${D("2")}",\n "z": "${D("1")}"\n}\n`);
|
|
241
|
+
writeFileSync(file, "");
|
|
242
|
+
});
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Images a release builds in its cut, and the digests its package pins
|
|
3
|
+
* (#4657, option 1).
|
|
4
|
+
*
|
|
5
|
+
* A package that pins container images by digest needs those digests when it
|
|
6
|
+
* is packed, and they exist only once the images are built. So the cut builds
|
|
7
|
+
* each image `release.images` declares first, as an OCI archive, and records
|
|
8
|
+
* the archive's digest in the release as an image artifact. It writes the
|
|
9
|
+
* digests to a file, `{ "<name>": "sha256:..." }`, and runs the build that
|
|
10
|
+
* packs the package with {@link RELEASE_DIGESTS_ENV} naming that file. The
|
|
11
|
+
* digest of an OCI archive is the digest of its top manifest, which is the
|
|
12
|
+
* digest a registry serves once the archive is pushed by the `oci` target.
|
|
13
|
+
*
|
|
14
|
+
* The publish job builds the images again from the release's commit
|
|
15
|
+
* (`chant release images`), with `SOURCE_DATE_EPOCH` set to the commit's
|
|
16
|
+
* time as in the cut, and refuses an archive whose digest is not the one the
|
|
17
|
+
* release records, so what is pushed is what the package pins. An image build
|
|
18
|
+
* that writes the same archive twice is the requirement (#4657's thread has
|
|
19
|
+
* the check against terragucci's Dockerfiles).
|
|
20
|
+
*
|
|
21
|
+
* An npm target's `pins` names the file in a package that carries the
|
|
22
|
+
* digests. The publish plan and `chant release verify` read it and refuse a
|
|
23
|
+
* digest the release does not record as an image.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { spawnSync } from "node:child_process";
|
|
27
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
28
|
+
import { dirname, isAbsolute, relative, resolve } from "node:path";
|
|
29
|
+
import { NEXT_RELEASE } from "../release-floors";
|
|
30
|
+
import type { PublishDeclaration } from "./publish-declaration";
|
|
31
|
+
import type { Release, ReleaseArtifact } from "./release-store";
|
|
32
|
+
|
|
33
|
+
/** The variable that names the digests file a release's package build reads. */
|
|
34
|
+
export const RELEASE_DIGESTS_ENV = "CHANT_RELEASE_DIGESTS";
|
|
35
|
+
|
|
36
|
+
/** The first chant with `release.images`, `CHANT_RELEASE_DIGESTS`, `chant release images` and an npm target's `pins` (#4657). Products feature-detect on it. */
|
|
37
|
+
export const RELEASE_IMAGES_FLOOR = NEXT_RELEASE;
|
|
38
|
+
|
|
39
|
+
/** One image a release builds in its cut. */
|
|
40
|
+
export interface ReleaseImageDeclaration {
|
|
41
|
+
/** The image's name: its key in the digests file, and its artifact's `component` in the release. */
|
|
42
|
+
name: string;
|
|
43
|
+
/** The shell command, run in the member's directory, that writes the archive. */
|
|
44
|
+
build: string;
|
|
45
|
+
/** The OCI archive the command writes, a layout directory or a tar file, relative to the member. The `oci` target's `image`. */
|
|
46
|
+
archive: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class ReleaseImageError extends Error {
|
|
50
|
+
constructor(
|
|
51
|
+
readonly code: string,
|
|
52
|
+
message: string,
|
|
53
|
+
readonly fix?: string,
|
|
54
|
+
) {
|
|
55
|
+
super(message);
|
|
56
|
+
this.name = "ReleaseImageError";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
|
|
61
|
+
|
|
62
|
+
/** Check a member's `release.images`: names valid and unique, archives inside the member. */
|
|
63
|
+
export function checkReleaseImages(images: readonly ReleaseImageDeclaration[]): void {
|
|
64
|
+
const seen = new Set<string>();
|
|
65
|
+
for (const i of images) {
|
|
66
|
+
if (!NAME.test(i.name)) throw new ReleaseImageError("release-image-name-invalid", `release.images: "${i.name}" is not a name of letters, digits, ".", "_" and "-"`);
|
|
67
|
+
if (seen.has(i.name)) throw new ReleaseImageError("release-image-name-taken", `release.images names "${i.name}" twice`);
|
|
68
|
+
seen.add(i.name);
|
|
69
|
+
if (isAbsolute(i.archive) || i.archive.split(/[\\/]/).includes("..")) {
|
|
70
|
+
throw new ReleaseImageError("release-image-archive-outside", `release.images "${i.name}": the archive ${i.archive} is not a path inside the member`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The digest of an OCI archive: its top manifest's, as `index.json` names it. */
|
|
76
|
+
export type ArchiveDigest = (abs: string) => string;
|
|
77
|
+
|
|
78
|
+
export interface BuildImagesInput {
|
|
79
|
+
images: readonly ReleaseImageDeclaration[];
|
|
80
|
+
/** The member's directory. */
|
|
81
|
+
cwd: string;
|
|
82
|
+
/** The commit's time in seconds, passed to each build as `SOURCE_DATE_EPOCH`. */
|
|
83
|
+
sourceDateEpoch: number;
|
|
84
|
+
label: string | null;
|
|
85
|
+
env?: NodeJS.ProcessEnv;
|
|
86
|
+
archiveDigest: ArchiveDigest;
|
|
87
|
+
/** Run one build command; the default runs it through the shell with its output on stderr. */
|
|
88
|
+
run?: (command: string, o: { cwd: string; env: NodeJS.ProcessEnv }) => number | null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const defaultRun = (command: string, o: { cwd: string; env: NodeJS.ProcessEnv }): number | null =>
|
|
92
|
+
spawnSync(command, { cwd: o.cwd, env: o.env, shell: true, stdio: ["ignore", 2, 2] }).status;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Build each image and return it as the release's image artifact. The
|
|
96
|
+
* command runs with `SOURCE_DATE_EPOCH` and, for a cut with a label,
|
|
97
|
+
* `CHANT_RELEASE_LABEL`; an archive it did not write, or a command that
|
|
98
|
+
* fails, stops the cut.
|
|
99
|
+
*/
|
|
100
|
+
export function buildReleaseImages(i: BuildImagesInput): ReleaseArtifact[] {
|
|
101
|
+
checkReleaseImages(i.images);
|
|
102
|
+
const run = i.run ?? defaultRun;
|
|
103
|
+
const out: ReleaseArtifact[] = [];
|
|
104
|
+
for (const image of i.images) {
|
|
105
|
+
const env: NodeJS.ProcessEnv = { ...(i.env ?? process.env), SOURCE_DATE_EPOCH: String(i.sourceDateEpoch) };
|
|
106
|
+
delete env.CHANT_RELEASE_LABEL;
|
|
107
|
+
if (i.label !== null) env.CHANT_RELEASE_LABEL = i.label;
|
|
108
|
+
const status = run(image.build, { cwd: i.cwd, env });
|
|
109
|
+
if (status !== 0) throw new ReleaseImageError("release-image-build-failed", `the build of image "${image.name}" exited ${status ?? "with a signal"}: ${image.build}`);
|
|
110
|
+
const abs = resolve(i.cwd, image.archive);
|
|
111
|
+
if (!existsSync(abs)) throw new ReleaseImageError("release-image-no-archive", `the build of image "${image.name}" wrote no ${image.archive}`, "Make the command write the OCI archive at archive, such as docker buildx build --output type=oci,dest=<archive>,rewrite-timestamp=true.");
|
|
112
|
+
out.push({ component: image.name, kind: "image", path: relative(i.cwd, abs).split("\\").join("/"), digest: i.archiveDigest(abs) });
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The release's built images by name: every image artifact with a path, which a handed image (#4694) has not. */
|
|
118
|
+
export function releaseImageDigests(release: Pick<Release, "artifactDigests">, names?: readonly string[]): Record<string, string> {
|
|
119
|
+
const out: Record<string, string> = {};
|
|
120
|
+
for (const a of release.artifactDigests) {
|
|
121
|
+
if (a.kind !== "image") continue;
|
|
122
|
+
if (names && !names.includes(a.component)) continue;
|
|
123
|
+
out[a.component] = a.digest;
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Write the digests file a package build reads. */
|
|
129
|
+
export function writeReleaseDigests(file: string, digests: Record<string, string>): void {
|
|
130
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
131
|
+
const sorted = Object.fromEntries(Object.entries(digests).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
132
|
+
writeFileSync(file, `${JSON.stringify(sorted, null, 2)}\n`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const DIGEST = /sha256:[0-9a-f]{64}/g;
|
|
136
|
+
|
|
137
|
+
/** Every `sha256:` digest in a pins file's text. */
|
|
138
|
+
export function pinnedDigests(text: string): string[] {
|
|
139
|
+
return [...new Set(text.match(DIGEST) ?? [])];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** The digests in `text` that the release does not record as an image. */
|
|
143
|
+
export function unknownPins(text: string, release: Pick<Release, "artifactDigests">): string[] {
|
|
144
|
+
const known = new Set(release.artifactDigests.filter((a) => a.kind === "image").map((a) => a.digest));
|
|
145
|
+
return pinnedDigests(text).filter((d) => !known.has(d));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** A pins file read from a package directory or a packed `.tgz`, or null when the package has none. */
|
|
149
|
+
export function readPins(abs: string, pins: string, isDirectory: boolean): string | null {
|
|
150
|
+
if (isDirectory) {
|
|
151
|
+
const file = resolve(abs, pins);
|
|
152
|
+
return existsSync(file) ? readFileSync(file, "utf-8") : null;
|
|
153
|
+
}
|
|
154
|
+
const run = spawnSync("tar", ["-xzOf", abs, `package/${pins.replace(/^\.\//, "")}`], { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
|
|
155
|
+
return run.status === 0 ? run.stdout : null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* For `chant release verify` (#4657): the first package an npm target's
|
|
160
|
+
* `pins` finds holding an image digest the release does not record, said in
|
|
161
|
+
* a sentence, or null. A package not built here is not read.
|
|
162
|
+
*/
|
|
163
|
+
export function packagePinProblem(cwd: string, release: Pick<Release, "artifactDigests">, targets: readonly PublishDeclaration[]): string | null {
|
|
164
|
+
for (const t of targets) {
|
|
165
|
+
if (t.type !== "npm" || !t.pins) continue;
|
|
166
|
+
for (const p of t.packages) {
|
|
167
|
+
const abs = resolve(cwd, p);
|
|
168
|
+
if (!existsSync(abs)) continue;
|
|
169
|
+
const text = readPins(abs, t.pins, statSync(abs).isDirectory());
|
|
170
|
+
const unknown = text === null ? [] : unknownPins(text, release);
|
|
171
|
+
if (unknown.length > 0) return `${p} pins ${unknown.join(", ")} in ${t.pins}, which the release does not record as an image`;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
@@ -90,6 +90,8 @@ export interface PublishItem {
|
|
|
90
90
|
attachment?: "sbom" | "provenance";
|
|
91
91
|
/** The SBOM file an npm package carries at its root (#4049). */
|
|
92
92
|
sbom?: string;
|
|
93
|
+
/** The notes a forge release is given (#4658), which a dry run prints. */
|
|
94
|
+
notes?: string;
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
/** The cut a publish carries the signature of (#4049): the cut whose signature verified, else the newest. */
|
|
@@ -8,7 +8,7 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
|
8
8
|
import { tmpdir } from "node:os";
|
|
9
9
|
import { join } from "node:path";
|
|
10
10
|
import { afterAll, describe, expect, test, vi } from "vitest";
|
|
11
|
-
import type
|
|
11
|
+
import { composeChangeSet, type ChangeSetDocument } from "../../change-set";
|
|
12
12
|
import { behaviourFindingMarker } from "./predict-behaviour";
|
|
13
13
|
import { commentMarker, type ReconcilePrArgs, type ReconcileResult } from "./reconcile";
|
|
14
14
|
import {
|
|
@@ -388,6 +388,25 @@ describe("the note job posts a handed-on review (#4326)", () => {
|
|
|
388
388
|
expect(posted[0]!.body).not.toContain("evil.example");
|
|
389
389
|
});
|
|
390
390
|
|
|
391
|
+
test("a composed change set's digest survives the handoff, and the note names its first 12 hex characters (#4726)", async () => {
|
|
392
|
+
const composed = composeChangeSet([]);
|
|
393
|
+
expect(composed.digest).toMatch(/^jcs1-sha256:[0-9a-f]{64}$/);
|
|
394
|
+
const { run, written } = harness({ review: "risk: low" });
|
|
395
|
+
const result = await run({ op: "pr-review", changeSet: composed, mode: "handoff", dir: "/r" });
|
|
396
|
+
const text = written[result.recordFile!]!;
|
|
397
|
+
expect(readReviewRecord(text)!.digest).toBe(composed.digest);
|
|
398
|
+
const { post, posted } = poster({ "/r/review.json": text });
|
|
399
|
+
await post({ op: "pr-review", dir: "/r" });
|
|
400
|
+
const hex = composed.digest.slice("jcs1-sha256:".length, "jcs1-sha256:".length + 12);
|
|
401
|
+
expect(posted[0]!.body).toContain(`### Review of change set \`${hex}\``);
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
test("a sha256: digest is kept and shortened after its prefix", () => {
|
|
405
|
+
expect(readReviewRecord(record())!.digest).toBe("sha256:0123456789abcdef0123");
|
|
406
|
+
const body = reviewNoteBody({ review: "risk: low", exitCode: 0, digest: "sha256:0123456789abcdef0123", instructions: "base" });
|
|
407
|
+
expect(body).toContain("### Review of change set `0123456789ab`");
|
|
408
|
+
});
|
|
409
|
+
|
|
391
410
|
test("no record, an unreadable record and an oversized record post nothing", async () => {
|
|
392
411
|
for (const files of [{} as Record<string, string>, { "/r/review.json": "not json" }, { "/r/review.json": record({ review: "x".repeat(1_100_000) }) }]) {
|
|
393
412
|
const { post, posted } = poster(files);
|
|
@@ -269,6 +269,9 @@ export function riskOf(review: string): ReviewRisk | "unknown" {
|
|
|
269
269
|
return found;
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
+
/** The first 12 hex characters of a change set's digest, after its `jcs1-sha256:` or `sha256:` prefix. */
|
|
273
|
+
const shortDigest = (d: string): string => d.replace(/^(jcs1-)?sha256:/, "").slice(0, 12);
|
|
274
|
+
|
|
272
275
|
/** The note's body. The review is the model's text: shown, never trusted, and no HTML comment of it survives. */
|
|
273
276
|
export function reviewNoteBody(o: { review: string; exitCode: number | null; digest: string; instructions: "base" | "none"; head?: string }): string {
|
|
274
277
|
const ok = o.exitCode === 0;
|
|
@@ -277,7 +280,7 @@ export function reviewNoteBody(o: { review: string; exitCode: number | null; dig
|
|
|
277
280
|
const lines = [
|
|
278
281
|
// Ours, and first: the review's own `<!--` is escaped below, so no later marker of this kind is the model's.
|
|
279
282
|
...(o.head !== undefined ? [reviewResultMarker(o.head, risk), ""] : []),
|
|
280
|
-
`### Review of change set \`${o.digest
|
|
283
|
+
`### Review of change set \`${shortDigest(o.digest)}\``,
|
|
281
284
|
"",
|
|
282
285
|
`Risk: **${risk}**. A model compared the title and description with the change set. This note approves nothing and gates nothing.`,
|
|
283
286
|
];
|
|
@@ -528,7 +531,7 @@ export function readReviewRecord(text: string): ReviewRecord | undefined {
|
|
|
528
531
|
const r = v as Record<string, unknown>;
|
|
529
532
|
if (typeof r.review !== "string") return undefined;
|
|
530
533
|
const exitCode = Number.isInteger(r.exitCode) ? (r.exitCode as number) : null;
|
|
531
|
-
const digest = typeof r.digest === "string" && /^sha256:[0-9a-f]{1,128}$/.test(r.digest) ? r.digest : "";
|
|
534
|
+
const digest = typeof r.digest === "string" && /^(jcs1-)?sha256:[0-9a-f]{1,128}$/.test(r.digest) ? r.digest : "";
|
|
532
535
|
return {
|
|
533
536
|
review: r.review,
|
|
534
537
|
exitCode,
|
package/src/op/gate.ts
CHANGED
|
@@ -1095,11 +1095,16 @@ export async function evaluateGate(port: GateLedgerPort, input: GateCheckInput):
|
|
|
1095
1095
|
* plan (#2300) gets `--plan <digest>` too (#2832), so the line approves the
|
|
1096
1096
|
* plan the reader was shown and not whatever is pending by the time they run
|
|
1097
1097
|
* it.
|
|
1098
|
+
*
|
|
1099
|
+
* `target` fills a product's `{target}` (#4574) where no environment does,
|
|
1100
|
+
* such as a wave's run target ({@link waveApproveTarget}). chant's own line
|
|
1101
|
+
* leaves it out: `chant approve` names the op and the gate.
|
|
1098
1102
|
*/
|
|
1099
|
-
export function approveCommand(op: string, gate: string, environment?: string, planDigest?: string, sealed = false): string {
|
|
1103
|
+
export function approveCommand(op: string, gate: string, environment?: string, planDigest?: string, sealed = false, target?: string): string {
|
|
1100
1104
|
// #4550: under a product's words (its bin set them), the product's approve line.
|
|
1101
1105
|
const words = activeProductWords();
|
|
1102
|
-
|
|
1106
|
+
const named = environment ?? target;
|
|
1107
|
+
if (!isChantWords(words)) return approveLine(words, { op, gate, digest: planDigest ?? "", sign: sealed, ...(named !== undefined ? { target: named } : {}) });
|
|
1103
1108
|
return `chant approve ${op} ${gate}` +
|
|
1104
1109
|
(environment === undefined ? "" : ` --env ${environment}`) +
|
|
1105
1110
|
(planDigest === undefined ? "" : ` --plan ${planDigest}`) +
|