@intentius/chant 0.124.76 → 0.124.77
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/__fixtures__/agent-guard/plywood.d.ts +8 -0
- package/dist/__fixtures__/agent-guard/plywood.d.ts.map +1 -0
- package/dist/__fixtures__/agent-guard/plywood.js +19 -0
- package/dist/__fixtures__/agent-guard/terragucci.d.ts +8 -0
- package/dist/__fixtures__/agent-guard/terragucci.d.ts.map +1 -0
- package/dist/__fixtures__/agent-guard/terragucci.js +30 -0
- package/dist/__fixtures__/gated-ledger.d.ts +10 -0
- package/dist/__fixtures__/gated-ledger.d.ts.map +1 -0
- package/dist/__fixtures__/gated-ledger.js +51 -0
- package/dist/agent-guard.d.ts +143 -0
- package/dist/agent-guard.d.ts.map +1 -0
- package/dist/agent-guard.js +456 -0
- package/dist/ci-commit.d.ts +54 -3
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +69 -7
- package/dist/ci-own-jobs.d.ts +81 -0
- package/dist/ci-own-jobs.d.ts.map +1 -0
- package/dist/ci-own-jobs.js +234 -0
- package/dist/ci-product.d.ts +39 -0
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +40 -0
- package/dist/cli/handlers/approve.d.ts +5 -1
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +17 -11
- package/dist/cli/handlers/build.d.ts +1 -1
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +88 -2
- package/dist/cli/handlers/commit.d.ts.map +1 -1
- package/dist/cli/handlers/commit.js +3 -1
- package/dist/cli/handlers/notify-relay.d.ts +18 -1
- package/dist/cli/handlers/notify-relay.d.ts.map +1 -1
- package/dist/cli/handlers/notify-relay.js +90 -14
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +3 -1
- package/dist/cli/handlers/release.d.ts +5 -1
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +17 -5
- package/dist/cli/handlers/run-generate.d.ts.map +1 -1
- package/dist/cli/handlers/run-generate.js +2 -1
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +21 -1
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +60 -4
- package/dist/cli/registry.d.ts +16 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/pr-env-components.d.ts +65 -0
- package/dist/components/pr-env-components.d.ts.map +1 -0
- package/dist/components/pr-env-components.js +163 -0
- package/dist/components/pr-policy.d.ts +15 -0
- package/dist/components/pr-policy.d.ts.map +1 -1
- package/dist/components/pr-policy.js +24 -1
- package/dist/components/release-compile.d.ts +15 -3
- package/dist/components/release-compile.d.ts.map +1 -1
- package/dist/components/release-compile.js +66 -15
- package/dist/gate-policy.d.ts +14 -1
- package/dist/gate-policy.d.ts.map +1 -1
- package/dist/gate-policy.js +16 -6
- package/dist/lexicon.d.ts +17 -1
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lexicon.js +1 -0
- package/dist/lifecycle/gated-op.d.ts +95 -0
- package/dist/lifecycle/gated-op.d.ts.map +1 -0
- package/dist/lifecycle/gated-op.js +96 -0
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +83 -2
- package/dist/notify-relay-repo.d.ts +131 -0
- package/dist/notify-relay-repo.d.ts.map +1 -0
- package/dist/notify-relay-repo.js +202 -0
- package/dist/notify-relay.d.ts +25 -1
- package/dist/notify-relay.d.ts.map +1 -1
- package/dist/notify-relay.js +28 -2
- package/dist/op/op-waves-capability.js +2 -2
- package/dist/policy-engine.d.ts +95 -0
- package/dist/policy-engine.d.ts.map +1 -0
- package/dist/policy-engine.js +158 -0
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/state-export.d.ts +126 -0
- package/dist/state-export.d.ts.map +1 -0
- package/dist/state-export.js +157 -0
- package/dist/state-migration.d.ts +148 -0
- package/dist/state-migration.d.ts.map +1 -0
- package/dist/state-migration.js +147 -0
- package/dist/state-unlock.d.ts +167 -0
- package/dist/state-unlock.d.ts.map +1 -0
- package/dist/state-unlock.js +197 -0
- package/dist/wave-runtime.mjs +329 -329
- package/dist/workspace/declaration.schema.json +1 -1
- package/dist/workspace/release-workflow.d.ts +10 -0
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +8 -3
- package/package.json +1 -1
- package/src/__fixtures__/agent-guard/plywood.ts +27 -0
- package/src/__fixtures__/agent-guard/terragucci.ts +39 -0
- package/src/__fixtures__/gated-ledger.ts +58 -0
- package/src/agent-guard.test.ts +320 -0
- package/src/agent-guard.ts +548 -0
- package/src/ci-commit.test.ts +50 -2
- package/src/ci-commit.ts +93 -9
- package/src/ci-own-jobs.test.ts +109 -0
- package/src/ci-own-jobs.ts +253 -0
- package/src/ci-product.ts +81 -0
- package/src/cli/handlers/approve-cwd.test.ts +112 -0
- package/src/cli/handlers/approve.ts +22 -11
- package/src/cli/handlers/build-own-jobs.test.ts +80 -0
- package/src/cli/handlers/build-pr-loop-control.test.ts +88 -0
- package/src/cli/handlers/build-run-group.test.ts +60 -0
- package/src/cli/handlers/build.ts +83 -3
- package/src/cli/handlers/commit.ts +3 -0
- package/src/cli/handlers/notify-relay.ts +99 -17
- package/src/cli/handlers/pr.ts +3 -1
- package/src/cli/handlers/release.ts +15 -5
- package/src/cli/handlers/run-generate.ts +2 -1
- package/src/cli/main.ts +21 -1
- package/src/cli/parse-args.ts +45 -3
- package/src/cli/registry.ts +16 -0
- package/src/components/pr-env-components.test.ts +138 -0
- package/src/components/pr-env-components.ts +214 -0
- package/src/components/pr-policy.test.ts +41 -1
- package/src/components/pr-policy.ts +25 -1
- package/src/components/release-compile.test.ts +47 -0
- package/src/components/release-compile.ts +70 -13
- package/src/gate-policy-bundle.test.ts +14 -0
- package/src/gate-policy.test.ts +7 -0
- package/src/gate-policy.ts +22 -7
- package/src/lexicon.ts +18 -1
- package/src/lifecycle/gated-op.ts +158 -0
- package/src/lifecycle/git.test.ts +92 -0
- package/src/lifecycle/git.ts +71 -2
- package/src/notify-relay-repo.test.ts +284 -0
- package/src/notify-relay-repo.ts +234 -0
- package/src/notify-relay.test.ts +12 -0
- package/src/notify-relay.ts +30 -3
- package/src/op/op-waves-capability.ts +2 -2
- package/src/policy-engine.test.ts +163 -0
- package/src/policy-engine.ts +201 -0
- package/src/release-floors.ts +1 -1
- package/src/state-export.test.ts +125 -0
- package/src/state-export.ts +228 -0
- package/src/state-migration.test.ts +134 -0
- package/src/state-migration.ts +237 -0
- package/src/state-unlock.test.ts +166 -0
- package/src/state-unlock.ts +294 -0
- package/src/workspace/declaration.schema.json +1 -1
- package/src/workspace/release-workflow.test.ts +34 -0
- package/src/workspace/release-workflow.ts +17 -3
package/src/ci-product.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type { CiProductWords, CiProductWordsInput } from "./ci-product-words";
|
|
|
13
13
|
import type { ProductMcpHook } from "./cli/mcp/product-tools";
|
|
14
14
|
import type { ProductWaveHook } from "./op/op-waves-after-plan";
|
|
15
15
|
import { OTLP_EXPORTER_FLOOR } from "./otlp";
|
|
16
|
+
import { NEXT_RELEASE } from "./release-floors";
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* The first chant with the product pipeline (#4550): the words, the
|
|
@@ -167,6 +168,59 @@ export const CI_RESPOND_FLOOR = "0.124.56";
|
|
|
167
168
|
* its pull request jobs with the build feature-detects on this floor.
|
|
168
169
|
*/
|
|
169
170
|
export const PR_LOOP_BUILD_FLAGS_FLOOR = "0.124.56";
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* A repository's own jobs in the generated pipeline file (#4769):
|
|
174
|
+
* `mergeOwnJobs` adds a map of jobs (or `readOwnJobsFile`'s) after chant's
|
|
175
|
+
* and refuses a name chant's file has or a GitLab keyword; `keepOwnJobs`
|
|
176
|
+
* carries over the old file's jobs that run neither `chant` nor the
|
|
177
|
+
* product's bin. `chant build --components --generate <forge> --own-jobs
|
|
178
|
+
* <file>` and `--keep-own-jobs` do the same on the build line. A product
|
|
179
|
+
* feature-detects on `OWN_JOBS_FLOOR`.
|
|
180
|
+
*/
|
|
181
|
+
export {
|
|
182
|
+
GITLAB_RESERVED_JOB_NAMES,
|
|
183
|
+
GITLAB_TOP_KEYWORDS,
|
|
184
|
+
isGeneratedJob,
|
|
185
|
+
jobBlocks,
|
|
186
|
+
jobNames,
|
|
187
|
+
keepOwnJobs,
|
|
188
|
+
mergeOwnJobs,
|
|
189
|
+
OWN_JOB_NAME,
|
|
190
|
+
OWN_JOBS_FLOOR,
|
|
191
|
+
OWN_JOBS_FORGES,
|
|
192
|
+
OWN_JOBS_LINE,
|
|
193
|
+
OwnJobsError,
|
|
194
|
+
ownJobsOf,
|
|
195
|
+
ownJobsProblems,
|
|
196
|
+
ownJobsYAML,
|
|
197
|
+
readOwnJobsFile,
|
|
198
|
+
type KeepOwnJobsOptions,
|
|
199
|
+
type MergeOwnJobsOptions,
|
|
200
|
+
type OwnJobsForge,
|
|
201
|
+
} from "./ci-own-jobs";
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* The Forgejo generators write a workflow-level run group a product asks for
|
|
205
|
+
* (#4771): `runGroup: "pull-request"` on the components pipeline (`chant
|
|
206
|
+
* build --components --generate forgejo --run-group pull-request`) and
|
|
207
|
+
* `runGroup: "commit"` on an op waves spec (its `options`, or `chant run
|
|
208
|
+
* --generate forgejo --spec <file> --run-group commit`). A workflow with a
|
|
209
|
+
* group of its own keeps it, and GitHub and GitLab files are unchanged. A
|
|
210
|
+
* product feature-detects on this floor.
|
|
211
|
+
*/
|
|
212
|
+
export const FORGEJO_RUN_GROUP_FLOOR = NEXT_RELEASE;
|
|
213
|
+
export { RUN_GROUP_KEYS, type RunGroupKey } from "./lexicon";
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* `chant build --pr-loop` takes the control repo (#4772): `--control <repo>`
|
|
217
|
+
* and `--control-setting <key>=<value>` (op, member, readTokenSecret, and
|
|
218
|
+
* the rest of the control settings) are the pull request loop's `control`,
|
|
219
|
+
* so the note job the build writes reads the control repo's records itself,
|
|
220
|
+
* the step `productPipelineJobs(...).post.control` returns. A product that
|
|
221
|
+
* writes its pipeline with the build feature-detects on this floor.
|
|
222
|
+
*/
|
|
223
|
+
export const PR_LOOP_CONTROL_FLOOR = NEXT_RELEASE;
|
|
170
224
|
export {
|
|
171
225
|
CI_RESPOND_DEFAULTS,
|
|
172
226
|
CI_RESPOND_ENV,
|
|
@@ -203,6 +257,33 @@ export async function runChantInProcess(argv: string[], words: CiProductWordsInp
|
|
|
203
257
|
*/
|
|
204
258
|
export { CI_AGENT_FLOOR, agentForbiddenPaths, type AgentSettings, type OpAgentSpec } from "./ci-agent";
|
|
205
259
|
|
|
260
|
+
/**
|
|
261
|
+
* The agent guard (#4770): a Claude Code PreToolUse hook on Bash and a
|
|
262
|
+
* wrapper per engine binary that refuse an agent's apply, approve or
|
|
263
|
+
* override. A product passes its words (its name, the refusal) and rules
|
|
264
|
+
* (engines, their refused subcommands and flags, its own refused commands)
|
|
265
|
+
* to `installAgentGuard`, and `agentGuard` checks a command line in process
|
|
266
|
+
* with the same rule. Feature-detect on `AGENT_GUARD_FLOOR`.
|
|
267
|
+
*/
|
|
268
|
+
export {
|
|
269
|
+
AGENT_GUARD_FLOOR,
|
|
270
|
+
agentGuard,
|
|
271
|
+
agentGuardScript,
|
|
272
|
+
agentGuardWrapper,
|
|
273
|
+
CLAUDE_SETTINGS_LOCAL,
|
|
274
|
+
CLAUDE_SETTINGS_SHARED,
|
|
275
|
+
installAgentGuard,
|
|
276
|
+
withAgentGuardHook,
|
|
277
|
+
type AgentGuard,
|
|
278
|
+
type AgentGuardEngine,
|
|
279
|
+
type AgentGuardInstall,
|
|
280
|
+
type AgentGuardInstallOptions,
|
|
281
|
+
type AgentGuardRules,
|
|
282
|
+
type AgentGuardSpec,
|
|
283
|
+
type AgentGuardVerdict,
|
|
284
|
+
type AgentGuardWords,
|
|
285
|
+
} from "./agent-guard";
|
|
286
|
+
|
|
206
287
|
/**
|
|
207
288
|
* After-plan hooks in a wave job's process (#4614): `runChantInProcess(["run",
|
|
208
289
|
* "wave", ...], words, { wave: { afterPlan, capabilities } })`, or
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4760: `recordGateApproval(op, gate, { cwd })` reads, appends and pushes the
|
|
3
|
+
* ledger of the repository at `cwd`, never the one the process runs in.
|
|
4
|
+
*
|
|
5
|
+
* Both repositories are temp repos with temp bare remotes, and the process is
|
|
6
|
+
* moved into the bystander for the call, so a regression writes into and
|
|
7
|
+
* pushes a throwaway repository rather than the checkout running the tests.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { afterEach, describe, expect, test, vi } from "vitest";
|
|
11
|
+
import { withTestDir } from "@intentius/chant-test-utils";
|
|
12
|
+
import { spawnSync } from "node:child_process";
|
|
13
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { appendPendingGate, readGateLedger } from "../../lifecycle/gate-ledger";
|
|
16
|
+
import { resetGateOrigin } from "../../lifecycle/gate-origin";
|
|
17
|
+
|
|
18
|
+
vi.mock("../../op/discover", () => ({ discoverOps: async () => ({ errors: [], ops: new Map() }) }));
|
|
19
|
+
|
|
20
|
+
const { recordGateApproval } = await import("./approve");
|
|
21
|
+
|
|
22
|
+
function git(cwd: string, ...args: string[]): { status: number | null; out: string } {
|
|
23
|
+
const r = spawnSync("git", args, { cwd, encoding: "utf-8" });
|
|
24
|
+
return { status: r.status, out: (r.stdout ?? "").trim() };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function ok(cwd: string, ...args: string[]): string {
|
|
28
|
+
const r = spawnSync("git", args, { cwd, encoding: "utf-8" });
|
|
29
|
+
if (r.status !== 0) throw new Error(`git ${args.join(" ")}: ${r.stderr}`);
|
|
30
|
+
return r.stdout.trim();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const PLAN = `jcs1-sha256:${"a".repeat(64)}`;
|
|
34
|
+
|
|
35
|
+
/** A repo at `<root>/<name>` with one commit on main, pushed to a bare remote at `<root>/<name>.git`. */
|
|
36
|
+
function repoWithRemote(root: string, name: string): { dir: string; remote: string } {
|
|
37
|
+
const dir = join(root, name);
|
|
38
|
+
const remote = join(root, `${name}.git`);
|
|
39
|
+
mkdirSync(dir);
|
|
40
|
+
ok(root, "init", "-q", "--bare", "-b", "main", remote);
|
|
41
|
+
ok(dir, "init", "-q", "-b", "main");
|
|
42
|
+
ok(dir, "config", "user.email", "t@chant.dev");
|
|
43
|
+
ok(dir, "config", "user.name", "T");
|
|
44
|
+
writeFileSync(join(dir, "README"), `${name}\n`);
|
|
45
|
+
ok(dir, "add", ".");
|
|
46
|
+
ok(dir, "commit", "-q", "-m", "init");
|
|
47
|
+
ok(dir, "remote", "add", "origin", remote);
|
|
48
|
+
ok(dir, "push", "-q", "origin", "main");
|
|
49
|
+
return { dir, remote };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function hasLifecycleBranch(gitDir: string): boolean {
|
|
53
|
+
return git(gitDir, "rev-parse", "--verify", "--quiet", "refs/heads/chant/lifecycle").status === 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe("recordGateApproval with a cwd other than the process's (#4760)", () => {
|
|
57
|
+
const home = process.cwd();
|
|
58
|
+
afterEach(() => {
|
|
59
|
+
process.chdir(home);
|
|
60
|
+
resetGateOrigin();
|
|
61
|
+
vi.restoreAllMocks();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
async function inTwoRepos(fn: (target: { dir: string; remote: string }, bystander: { dir: string; remote: string }) => Promise<void>) {
|
|
65
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
66
|
+
await withTestDir(async (root) => {
|
|
67
|
+
const target = repoWithRemote(root, "target");
|
|
68
|
+
const bystander = repoWithRemote(root, "bystander");
|
|
69
|
+
process.chdir(bystander.dir);
|
|
70
|
+
try {
|
|
71
|
+
await fn(target, bystander);
|
|
72
|
+
} finally {
|
|
73
|
+
process.chdir(home);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function expectUntouched(bystander: { dir: string; remote: string }) {
|
|
79
|
+
expect(hasLifecycleBranch(bystander.dir)).toBe(false);
|
|
80
|
+
expect(hasLifecycleBranch(bystander.remote)).toBe(false);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
test("answers the pending fact in the cwd's ledger and pushes there, leaving the process's repo alone", async () => {
|
|
84
|
+
await inTwoRepos(async (target, bystander) => {
|
|
85
|
+
await appendPendingGate(
|
|
86
|
+
{ op: "deploy", gate: "prod", timestamp: "2026-11-07T10:00:00.000Z", expiresAt: "2999-01-01T00:00:00.000Z", planDigest: PLAN },
|
|
87
|
+
{ cwd: target.dir },
|
|
88
|
+
);
|
|
89
|
+
ok(target.dir, "push", "-q", "origin", "chant/lifecycle");
|
|
90
|
+
|
|
91
|
+
const outcome = await recordGateApproval("deploy", "prod", { origin: "cli", actor: "alice", cwd: target.dir });
|
|
92
|
+
|
|
93
|
+
expect(outcome).toMatchObject({ ok: true, pushed: true });
|
|
94
|
+
expect((await readGateLedger("deploy", { cwd: target.dir })).resolutions).toEqual([
|
|
95
|
+
expect.objectContaining({ gate: "prod", resolvedBy: "alice", planDigest: PLAN }),
|
|
96
|
+
]);
|
|
97
|
+
expect(ok(target.remote, "rev-parse", "refs/heads/chant/lifecycle")).toBe(ok(target.dir, "rev-parse", "refs/heads/chant/lifecycle"));
|
|
98
|
+
expectUntouched(bystander);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("with --plan and nothing pending anywhere, the record and the push still go to the cwd", async () => {
|
|
103
|
+
await inTwoRepos(async (target, bystander) => {
|
|
104
|
+
const outcome = await recordGateApproval("deploy", "prod", { origin: "cli", actor: "alice", plan: PLAN, cwd: target.dir });
|
|
105
|
+
|
|
106
|
+
expect(outcome).toMatchObject({ ok: true, pushed: true });
|
|
107
|
+
expect((await readGateLedger("deploy", { cwd: target.dir })).resolutions).toHaveLength(1);
|
|
108
|
+
expect(hasLifecycleBranch(target.remote)).toBe(true);
|
|
109
|
+
expectUntouched(bystander);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -73,9 +73,10 @@ const LIFECYCLE_BRANCH = "chant/lifecycle";
|
|
|
73
73
|
* failure; the exit code is unchanged. With no remote at all there is nobody
|
|
74
74
|
* elsewhere to tell, so that case is a quiet suffix and no warning (#3677).
|
|
75
75
|
*/
|
|
76
|
-
async function reportedPush(consequence: string): Promise<{ pushed: boolean; suffix: string }> {
|
|
76
|
+
async function reportedPush(consequence: string, cwd?: string): Promise<{ pushed: boolean; suffix: string }> {
|
|
77
77
|
// #4637: a push another writer beat is replayed onto the remote's tip and tried again; an approval line appends.
|
|
78
|
-
|
|
78
|
+
// #4760: and the push is of the repository at `cwd`, not whatever one the process runs in.
|
|
79
|
+
const { pushed, pushWarning } = await pushLifecycleRebasing(...(cwd !== undefined ? [{ cwd }] : [])).catch((err: unknown) => {
|
|
79
80
|
if (err instanceof LifecyclePushLostError) return { pushed: false, pushWarning: err.message };
|
|
80
81
|
throw err;
|
|
81
82
|
});
|
|
@@ -328,7 +329,11 @@ export interface GateApprovalOptions {
|
|
|
328
329
|
* `--statement` and `--signature`.
|
|
329
330
|
*/
|
|
330
331
|
binding?: string;
|
|
331
|
-
/**
|
|
332
|
+
/**
|
|
333
|
+
* The repository the approval is for: its ops, its workspace and key file,
|
|
334
|
+
* and its `chant/lifecycle`, which is read, appended to and pushed (#4760).
|
|
335
|
+
* Defaults to the process's directory.
|
|
336
|
+
*/
|
|
332
337
|
cwd?: string;
|
|
333
338
|
/** Replaces the lexicon evaluator a gate policy is loaded from. For tests. */
|
|
334
339
|
evaluator?: GatePolicyEvaluator;
|
|
@@ -428,7 +433,13 @@ async function approveGate(
|
|
|
428
433
|
}));
|
|
429
434
|
return { ok: false };
|
|
430
435
|
}
|
|
431
|
-
|
|
436
|
+
// #4760: every ledger read, append and push below acts on the repository at
|
|
437
|
+
// `opts.cwd`, the one the scope and signing key come from, and never on
|
|
438
|
+
// process.cwd() when a caller names another. With no `opts.cwd` the calls
|
|
439
|
+
// are made exactly as before, with no location, so they default as they did.
|
|
440
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
441
|
+
const at: [] | [{ cwd: string }] = opts.cwd !== undefined ? [{ cwd: opts.cwd }] : [];
|
|
442
|
+
const { ops } = await discoverOps(...at);
|
|
432
443
|
// `fan-out` is the op name every `chant components fan-out` gate is recorded
|
|
433
444
|
// under (../handlers/fan-out.ts). It is a command rather than a declaration,
|
|
434
445
|
// so there is no `*.op.ts` to find and nothing is wrong when none is there.
|
|
@@ -446,7 +457,7 @@ async function approveGate(
|
|
|
446
457
|
// single commit holding only this resolution — the pending fact it is
|
|
447
458
|
// answering is discarded rather than appended to.
|
|
448
459
|
try {
|
|
449
|
-
await requireLifecycleLedger();
|
|
460
|
+
await requireLifecycleLedger(...at);
|
|
450
461
|
} catch (err) {
|
|
451
462
|
console.error(formatError({
|
|
452
463
|
message: `Cannot record the approval: ${err instanceof Error ? err.message : String(err)}`,
|
|
@@ -459,7 +470,7 @@ async function approveGate(
|
|
|
459
470
|
// the new gate has no standing fact of its own. Once it has one, approve
|
|
460
471
|
// the gate the runs now stop at.
|
|
461
472
|
if (successor) {
|
|
462
|
-
const theirs = latestPendingGate((await readGateLedger(successor.op)).pending, successor.gate);
|
|
473
|
+
const theirs = latestPendingGate((await readGateLedger(successor.op, ...at)).pending, successor.gate);
|
|
463
474
|
if (theirs && !isPendingGateExpired(theirs, new Date().toISOString())) {
|
|
464
475
|
console.error(formatError({
|
|
465
476
|
message:
|
|
@@ -498,7 +509,7 @@ async function approveGate(
|
|
|
498
509
|
// recorded in, and an approval answers one environment. `--env` picks it;
|
|
499
510
|
// without it, the newest standing fact decides, and the success line below
|
|
500
511
|
// names the environment it chose.
|
|
501
|
-
const ledgerBefore = await readGateLedger(opName);
|
|
512
|
+
const ledgerBefore = await readGateLedger(opName, ...at);
|
|
502
513
|
const pendingFor = (all: PendingGateRecord[]): PendingGateRecord[] => {
|
|
503
514
|
const bound = all.some((p) => p.gate === gate && p.environment !== undefined);
|
|
504
515
|
return bound && opts.environment !== undefined ? all.filter((p) => p.environment === opts.environment) : all;
|
|
@@ -552,7 +563,7 @@ async function approveGate(
|
|
|
552
563
|
// commit is superseded. Its promote refuses the release, so an approval of
|
|
553
564
|
// it would count for nothing; refuse it here, whatever plan is named.
|
|
554
565
|
if (standing?.releaseDigest !== undefined) {
|
|
555
|
-
const refused = await refuseRevokedRelease(opName, gate, standing.releaseDigest,
|
|
566
|
+
const refused = await refuseRevokedRelease(opName, gate, standing.releaseDigest, cwd);
|
|
556
567
|
if (refused) return { ok: false };
|
|
557
568
|
}
|
|
558
569
|
|
|
@@ -563,7 +574,7 @@ async function approveGate(
|
|
|
563
574
|
// resolved over the same one has no second party in it. Refused by default,
|
|
564
575
|
// the way #2300 refuses a plan nobody approved.
|
|
565
576
|
const origin = opts.origin ?? currentGateOrigin();
|
|
566
|
-
const ledger = await readGateLedger(opName);
|
|
577
|
+
const ledger = await readGateLedger(opName, ...at);
|
|
567
578
|
const standingForOrigin = latestPendingGate(pendingFor(ledger.pending), gate);
|
|
568
579
|
|
|
569
580
|
// chant#3485: a gate that is never resolved over MCP or ACP says so on its
|
|
@@ -625,7 +636,6 @@ async function approveGate(
|
|
|
625
636
|
// #3163, ws-080: the declaration at base may require a checkable approver
|
|
626
637
|
// (identity.attribution "identified") and a signed approval for this gate
|
|
627
638
|
// (identity.gates). Both are judged before anything is written.
|
|
628
|
-
const cwd = opts.cwd ?? process.cwd();
|
|
629
639
|
const identity = await import("../../workspace/identity");
|
|
630
640
|
const { scopeSource } = await import("../../workspace/write-scope");
|
|
631
641
|
const scope = scopeSource(cwd);
|
|
@@ -832,10 +842,11 @@ async function approveGate(
|
|
|
832
842
|
...(standing?.runId ? { runId: standing.runId } : {}),
|
|
833
843
|
origin,
|
|
834
844
|
...(refusal && opts.allowSameOrigin ? { sameOriginOverride: true } : {}),
|
|
835
|
-
});
|
|
845
|
+
}, ...at);
|
|
836
846
|
const push = await reportedPush(
|
|
837
847
|
`The resolution is recorded locally on ${LIFECYCLE_BRANCH}. Until it reaches the remote, ` +
|
|
838
848
|
`a run in another checkout will not see it.`,
|
|
849
|
+
opts.cwd,
|
|
839
850
|
);
|
|
840
851
|
|
|
841
852
|
console.error(formatSuccess(
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant build --components --generate <forge> --own-jobs <file>` and
|
|
3
|
+
* `--keep-own-jobs` (#4769): the generated file carries the repository's
|
|
4
|
+
* own jobs, and a build without either writes what it wrote before.
|
|
5
|
+
*/
|
|
6
|
+
import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { beforeEach, describe, expect, test, vi } from "vitest";
|
|
10
|
+
import { parseArgs } from "../parse-args";
|
|
11
|
+
import { setActiveProductWords } from "../../ci-product-words";
|
|
12
|
+
|
|
13
|
+
const generateComponentsPipelineMock = vi.fn();
|
|
14
|
+
vi.mock("../../components/cli-support", () => ({
|
|
15
|
+
generateComponentsPipeline: (...args: unknown[]) => generateComponentsPipelineMock(...args),
|
|
16
|
+
}));
|
|
17
|
+
vi.mock("../../config", async () => {
|
|
18
|
+
const actual = await vi.importActual<typeof import("../../config")>("../../config");
|
|
19
|
+
return { ...actual, loadChantConfigUpward: async () => ({ config: {} }) };
|
|
20
|
+
});
|
|
21
|
+
vi.mock("../plugins", async () => {
|
|
22
|
+
const actual = await vi.importActual<typeof import("../plugins")>("../plugins");
|
|
23
|
+
return { ...actual, resolveProjectLexicons: async () => [] };
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const { runBuild } = await import("./build");
|
|
27
|
+
|
|
28
|
+
const GENERATED = ["name: chant", "jobs:", " plan:", " steps:", " - run: npx --no-install plywood components pr-plan prod", ""].join("\n");
|
|
29
|
+
|
|
30
|
+
async function build(argv: string[]): Promise<{ code: number; err: string }> {
|
|
31
|
+
const err: string[] = [];
|
|
32
|
+
vi.spyOn(console, "error").mockImplementation((s: string) => void err.push(String(s)));
|
|
33
|
+
vi.spyOn(console, "log").mockImplementation(() => undefined);
|
|
34
|
+
const code = await runBuild({ args: parseArgs(argv) } as never);
|
|
35
|
+
return { code, err: err.join("\n") };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe("build --own-jobs and --keep-own-jobs", () => {
|
|
39
|
+
let dir: string;
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
dir = mkdtempSync(join(tmpdir(), "chant-build-own-"));
|
|
42
|
+
generateComponentsPipelineMock.mockReset().mockResolvedValue({ success: true, yaml: GENERATED, stages: [], jobs: [] });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("without either flag the file is what the generator wrote", async () => {
|
|
46
|
+
const out = join(dir, "ci.yml");
|
|
47
|
+
expect((await build(["build", ".", "--components", "--generate", "github", "--output", out])).code).toBe(0);
|
|
48
|
+
expect(readFileSync(out, "utf-8")).toBe(GENERATED);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("--own-jobs merges the file's jobs after chant's, and refuses a collision", async () => {
|
|
52
|
+
const out = join(dir, "ci.yml");
|
|
53
|
+
writeFileSync(join(dir, "own.yml"), "lint:\n runs-on: x\n");
|
|
54
|
+
expect((await build(["build", ".", "--components", "--generate", "forgejo", "--own-jobs", join(dir, "own.yml"), "--output", out])).code).toBe(0);
|
|
55
|
+
expect(readFileSync(out, "utf-8")).toMatch(/\n {2}# Your own jobs[^\n]*\n {2}lint:\n {4}runs-on: x\n$/);
|
|
56
|
+
writeFileSync(join(dir, "bad.yml"), "plan:\n runs-on: x\n");
|
|
57
|
+
const refused = await build(["build", ".", "--components", "--generate", "forgejo", "--own-jobs", join(dir, "bad.yml"), "--output", join(dir, "other.yml")]);
|
|
58
|
+
expect(refused.code).toBe(1);
|
|
59
|
+
expect(refused.err).toMatch(/plan: chant's file has a job of that name/);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("--keep-own-jobs keeps the old file's hand-added job, and drops one that runs the product's bin", async () => {
|
|
63
|
+
const out = join(dir, "ci.yml");
|
|
64
|
+
writeFileSync(out, GENERATED + " audit:\n steps:\n - run: npm audit\n stale:\n steps:\n - run: npx --no-install plywood ci run drift\n");
|
|
65
|
+
const before = setActiveProductWords({ product: "plywood", bin: "npx --no-install plywood" });
|
|
66
|
+
try {
|
|
67
|
+
expect((await build(["build", ".", "--components", "--generate", "github", "--keep-own-jobs", "--output", out])).code).toBe(0);
|
|
68
|
+
} finally {
|
|
69
|
+
setActiveProductWords(before);
|
|
70
|
+
}
|
|
71
|
+
const text = readFileSync(out, "utf-8");
|
|
72
|
+
expect(text).toContain(" audit:\n steps:\n - run: npm audit\n");
|
|
73
|
+
expect(text).not.toContain("stale:");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("--keep-own-jobs needs a file to read, and the flags need generate mode", async () => {
|
|
77
|
+
expect((await build(["build", ".", "--components", "--generate", "github", "--keep-own-jobs"])).err).toMatch(/needs --output/);
|
|
78
|
+
expect(() => parseArgs(["build", ".", "--own-jobs", "own.yml"])).toThrow(/--own-jobs needs build --components --generate/);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant build --pr-loop --control <repo> --control-setting <key>=<value>`
|
|
3
|
+
* (#4772): the build takes the control repo and its read secret, so the
|
|
4
|
+
* note job it writes reads the control repo's records itself, and no
|
|
5
|
+
* product splices `productPipelineJobs(...).post.control` into the file.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, expect, test, vi } from "vitest";
|
|
8
|
+
import { parseYAML } from "../../yaml";
|
|
9
|
+
import { parseArgs } from "../parse-args";
|
|
10
|
+
import { prLoopFlagsProblem } from "./build";
|
|
11
|
+
import { controlNoteCheckout } from "../../control/dispatch";
|
|
12
|
+
import { productPipelineJobs } from "../../components/product-pipeline";
|
|
13
|
+
import type { DriverComponent } from "../../components/driver";
|
|
14
|
+
|
|
15
|
+
const generateComponentsPipelineMock = vi.fn(async () => ({ success: true, yaml: "x", stages: [], jobs: [] }));
|
|
16
|
+
vi.mock("../../components/cli-support", () => ({ generateComponentsPipeline: (...a: unknown[]) => generateComponentsPipelineMock(...(a as [])) }));
|
|
17
|
+
vi.mock("../../config", async () => {
|
|
18
|
+
const actual = await vi.importActual<typeof import("../../config")>("../../config");
|
|
19
|
+
return { ...actual, loadChantConfigUpward: async () => ({ config: {} }) };
|
|
20
|
+
});
|
|
21
|
+
vi.mock("../plugins", async () => {
|
|
22
|
+
const actual = await vi.importActual<typeof import("../plugins")>("../plugins");
|
|
23
|
+
return { ...actual, resolveProjectLexicons: async () => [] };
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const { runBuild } = await import("./build");
|
|
27
|
+
|
|
28
|
+
const CONTROL = ["--control", "github.com/acme/control", "--control-setting", "op=deploy", "--control-setting", "member=network", "--control-setting", "readTokenSecret=PLYWOOD_CONTROL_READ"];
|
|
29
|
+
const ESTATE: DriverComponent[] = [{ name: "net", dependsOn: [], deploy: [{ phase: "Apply", steps: [{ kind: "terraform-apply", root: "net" }] }] }];
|
|
30
|
+
|
|
31
|
+
async function options(forge: string, extra: string[] = []): Promise<{ code: number; options: Record<string, unknown> | undefined; err: string }> {
|
|
32
|
+
generateComponentsPipelineMock.mockClear();
|
|
33
|
+
const err: string[] = [];
|
|
34
|
+
vi.spyOn(console, "error").mockImplementation((s: string) => void err.push(String(s)));
|
|
35
|
+
vi.spyOn(console, "log").mockImplementation(() => undefined);
|
|
36
|
+
const code = await runBuild({ args: parseArgs(["build", ".", "--components", "--generate", forge, "--pr-loop", ...extra]) } as never);
|
|
37
|
+
const call = generateComponentsPipelineMock.mock.calls[0] as unknown[] | undefined;
|
|
38
|
+
return { code, options: call?.[2] as Record<string, unknown> | undefined, err: err.join("\n") };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe("build --pr-loop --control", () => {
|
|
42
|
+
test("hands the generator the control target, with the read secret", async () => {
|
|
43
|
+
const { code, options: o } = await options("github", CONTROL);
|
|
44
|
+
expect(code).toBe(0);
|
|
45
|
+
const control = (o!.prLoop as { control: { target: Record<string, unknown> } }).control;
|
|
46
|
+
expect(control.target).toMatchObject({ repo: "github.com/acme/control", forge: "github", op: "deploy", member: "network", readTokenSecret: "PLYWOOD_CONTROL_READ" });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
for (const forge of ["github", "forgejo", "gitlab"] as const) {
|
|
50
|
+
test(`the ${forge} note job carries the read, the step productPipelineJobs hands back as post.control`, async () => {
|
|
51
|
+
const { options: o } = await options(forge, CONTROL);
|
|
52
|
+
const prLoop = o!.prLoop as { control: { target: import("../../control/dispatch").ControlTarget } };
|
|
53
|
+
const step = controlNoteCheckout(forge, prLoop.control.target);
|
|
54
|
+
expect(productPipelineJobs(forge, "prod", { words: { commands: {} }, control: { target: prLoop.control.target } }).post.control).toEqual(step);
|
|
55
|
+
const lexicon = forge === "gitlab" ? "gitlab" : "github";
|
|
56
|
+
const gen = (await import(`@intentius/chant-lexicon-${lexicon}/components/generate-pipeline`)) as Record<string, (c: DriverComponent[], o: unknown) => { yaml: string }>;
|
|
57
|
+
const { yaml } = forge === "gitlab" ? gen.generateGitlabPipeline!(ESTATE, o) : gen.generateGithubPipeline!(ESTATE, { ...o, prLoop: { ...prLoop, forge } });
|
|
58
|
+
const note = (parseYAML(yaml) as Record<string, unknown> & { jobs?: Record<string, unknown> });
|
|
59
|
+
const job = JSON.stringify(forge === "gitlab" ? note["plan-note"] : note.jobs!["plan-note"]);
|
|
60
|
+
expect(job).toContain(JSON.stringify(step.script).slice(1, -1));
|
|
61
|
+
if (forge !== "gitlab") expect(job).toContain("secrets.PLYWOOD_CONTROL_READ");
|
|
62
|
+
else expect(job).toContain("PLYWOOD_CONTROL_READ");
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
test("without --control no control reaches the generator", async () => {
|
|
67
|
+
const { options: o } = await options("github");
|
|
68
|
+
expect((o!.prLoop as Record<string, unknown>).control).toBeUndefined();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("refuses settings that do not hold, and the flags without --pr-loop", async () => {
|
|
72
|
+
const missing = await options("github", ["--control", "github.com/acme/control"]);
|
|
73
|
+
expect(missing.code).toBe(1);
|
|
74
|
+
expect(missing.err).toMatch(/control\.op must name the Op/);
|
|
75
|
+
expect(missing.err).toMatch(/control\.member must name this repo/);
|
|
76
|
+
const same = await options("github", [...CONTROL, "--control-setting", "tokenSecret=PLYWOOD_CONTROL_READ"]);
|
|
77
|
+
expect(same.err).toMatch(/must not be the dispatch token's secret/);
|
|
78
|
+
expect(() => parseArgs(["build", "--control-setting", "color=blue"])).toThrow(/--control-setting needs <key>=<value>/);
|
|
79
|
+
expect(prLoopFlagsProblem({ controlRepo: "github.com/acme/control" })).toMatch(/--control .*needs --pr-loop/);
|
|
80
|
+
expect(prLoopFlagsProblem({ prLoop: true, controlSettings: { op: "deploy" } })).toMatch(/needs --control <repo>/);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("PR_LOOP_CONTROL_FLOOR marks it in the ci-product entry", async () => {
|
|
85
|
+
const ciProduct = await import("../../ci-product");
|
|
86
|
+
const { NEXT_RELEASE } = await import("../../release-floors");
|
|
87
|
+
expect((ciProduct as Record<string, unknown>).PR_LOOP_CONTROL_FLOOR).toBe(NEXT_RELEASE);
|
|
88
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `--run-group <key>` (#4771) reaches the generator's `runGroup`, on `chant
|
|
3
|
+
* build --components --generate` and on `chant run --generate` with an op
|
|
4
|
+
* waves spec, and a build without it passes no `runGroup`.
|
|
5
|
+
*/
|
|
6
|
+
import { mkdtempSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { describe, expect, test, vi } from "vitest";
|
|
10
|
+
import { parseArgs } from "../parse-args";
|
|
11
|
+
|
|
12
|
+
const generateComponentsPipelineMock = vi.fn(async () => ({ success: true, yaml: "x", stages: [], jobs: [] }));
|
|
13
|
+
const generateOpWavesPipelineMock = vi.fn(async () => ({ success: true, files: [], jobs: [] }));
|
|
14
|
+
vi.mock("../../components/cli-support", () => ({ generateComponentsPipeline: (...a: unknown[]) => generateComponentsPipelineMock(...(a as [])) }));
|
|
15
|
+
vi.mock("../../op/generate-pipeline", async () => {
|
|
16
|
+
const actual = await vi.importActual<typeof import("../../op/generate-pipeline")>("../../op/generate-pipeline");
|
|
17
|
+
return { ...actual, generateOpWavesPipeline: (...a: unknown[]) => generateOpWavesPipelineMock(...(a as [])) };
|
|
18
|
+
});
|
|
19
|
+
vi.mock("../../config", async () => {
|
|
20
|
+
const actual = await vi.importActual<typeof import("../../config")>("../../config");
|
|
21
|
+
return { ...actual, loadChantConfigUpward: async () => ({ config: {} }) };
|
|
22
|
+
});
|
|
23
|
+
vi.mock("../plugins", async () => {
|
|
24
|
+
const actual = await vi.importActual<typeof import("../plugins")>("../plugins");
|
|
25
|
+
return { ...actual, resolveProjectLexicons: async () => [] };
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const { runBuild } = await import("./build");
|
|
29
|
+
const { runOpGenerate } = await import("./run-generate");
|
|
30
|
+
|
|
31
|
+
describe("--run-group", () => {
|
|
32
|
+
test("takes commit or pull-request", () => {
|
|
33
|
+
expect(parseArgs(["build", ".", "--components", "--generate", "forgejo", "--run-group", "pull-request"]).runGroup).toBe("pull-request");
|
|
34
|
+
expect(() => parseArgs(["build", "--run-group", "branch"])).toThrow(/--run-group takes commit or pull-request/);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("build passes it to the generator, and passes none without it", async () => {
|
|
38
|
+
vi.spyOn(console, "log").mockImplementation(() => undefined);
|
|
39
|
+
await runBuild({ args: parseArgs(["build", ".", "--components", "--generate", "forgejo", "--run-group", "pull-request"]) } as never);
|
|
40
|
+
expect((generateComponentsPipelineMock.mock.calls[0] as unknown[])[2]).toMatchObject({ runGroup: "pull-request" });
|
|
41
|
+
await runBuild({ args: parseArgs(["build", ".", "--components", "--generate", "forgejo"]) } as never);
|
|
42
|
+
expect((generateComponentsPipelineMock.mock.calls[1] as unknown[])[2]).not.toHaveProperty("runGroup");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("run --generate passes it with an op waves spec", async () => {
|
|
46
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-run-group-"));
|
|
47
|
+
const spec = join(dir, "waves.json");
|
|
48
|
+
writeFileSync(spec, JSON.stringify({ name: "w", op: "o", plan: ["p"], waves: [{ name: "a", runs: [{ target: "a" }] }] }));
|
|
49
|
+
vi.spyOn(console, "error").mockImplementation(() => undefined);
|
|
50
|
+
await runOpGenerate({ args: parseArgs(["run", "--generate", "forgejo", "--spec", spec, "--run-group", "commit", "--output", dir]) } as never);
|
|
51
|
+
expect((generateOpWavesPipelineMock.mock.calls[0] as unknown[])[2]).toMatchObject({ runGroup: "commit" });
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("FORGEJO_RUN_GROUP_FLOOR marks it in the ci-product entry", async () => {
|
|
56
|
+
const ciProduct = await import("../../ci-product");
|
|
57
|
+
const { NEXT_RELEASE } = await import("../../release-floors");
|
|
58
|
+
expect(ciProduct.FORGEJO_RUN_GROUP_FLOOR).toBe(NEXT_RELEASE);
|
|
59
|
+
expect(ciProduct.RUN_GROUP_KEYS).toEqual(["commit", "pull-request"]);
|
|
60
|
+
});
|