Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/content/docs/cli/build.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ It reaches no network. Every schema it needs is generated into the lexicon packa
| `--allow-skip` | `boolean` | `false` | With `--promote-to`. Let the promote job skip a step of the member's [promotion order](/chant/cli/components/#the-promotion-order). The generated job runs `promote` with `--allow-skip`. |
| `--promote-to <env>` | `string` | — | Generate mode only. Add a job that promotes the deployed releases to `<env>` after every component job succeeds. Without `--components --generate <lexicon>` the command fails rather than ignoring the flag. See [Promote job](#promote-job) |
| `--merge auto --merge-token-env <VAR>` | `string` | `manual` | With `--pr-loop --apply-before-merge`. The generated apply job runs `pr-apply --before-merge --merge auto --merge-token-env <VAR>` and merges the pull request once its update applied, with the token in `<VAR>` alone. `--merge-method merge\|squash\|rebase` picks the merge. See [Pull-request pipeline](#pull-request-pipeline) |
| `--respond <list>` | `string` | chant's defaults | With `--pr-loop`. The responses the apply and note jobs post, such as `wave-refused=off,description=check`, set on both jobs as `CHANT_RESPOND`. An event or mode chant does not know is refused by name |
| `--respond <list>` | `string` | chant's defaults | With `--pr-loop`. The responses the apply and note jobs post, such as `wave-refused=off,description=check`, set on both jobs as `CHANT_RESPOND`. `wave-refused=summary` adds a model's summary above the refused diff; the apply job then carries the model's key, `ANTHROPIC_API_KEY` (from the secret of that name on GitHub and Forgejo), and the pull request loop's `waveSummary` settings as `CHANT_WAVE_SUMMARY_*` variables. An event or mode chant does not know is refused by name |
| `--decide-backend <name>`, `--decide-model <id>` | `string` | — | With `--pr-loop --respond description=check`, which needs both. The note job passes them to `pr-post`, which asks that `decide.backends` entry whether the description leaves out a destroy or a replacement |
| `--root-only` | `bool` | `false` | At the root of a declared workspace, build the root project alone instead of refusing. See [At a workspace root](#at-a-workspace-root) |
| `--fold-rank [path]` | `bool` or `string` | off | After a folded build, print the run-fallback blockers ranked by how many files each one keeps from folding. With a path, also write the ranking in collapsed-stack format to that file for a flame-graph viewer. No-op with `--no-fold` |
Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/guide/op-waves.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ A CI product passes what it adds to the generated jobs as options, so it edits n
- `artifact`: `{ step, name, path }`, the files the report writes, kept whatever the exit. `{job}` in `name` is the job's name. On GitLab the path joins the job's `artifacts:`, beside the outcome files. `path` may be a list ([#4994](https://github.com/INTENTIUS/chant/issues/4994)), so one artifact keeps every directory a product used to upload in steps of its own, such as its report and its agent's input.
- `gate`: with `beforeMerge`, `{ report?, artifact? }` for the wave's [gate job](#the-four-jobs-of-a-wave) ([#4994](https://github.com/INTENTIUS/chant/issues/4994)), which runs the `after-gate` hooks at the default branch's code. Its `report` runs after the gate's command whatever the exit (GitLab: the gate job's `after_script`), and its `artifact` keeps what the report and the hooks wrote, `{job}` being the gate job's name.

On GitHub and Forgejo the wave jobs hold no forge token unless the product asks for one with `commandToken: { permissions }` ([#5044](https://github.com/INTENTIUS/chant/issues/5044)). Then the jobs that run only the default branch's code (a push's wave, deciding, share and job group jobs, and a split wave's gate and record jobs) give their command step the job's token as `GITHUB_TOKEN`, so the spec's `respond` posts a refused wave's diff and a failed apply's triage, and a product's hooks can read the forge. The jobs ask for `permissions` beside chant's own, such as terragucci's `{ "pull-requests": "write", actions: "read" }`. `contents` and `id-token` stay chant's. A split wave's plan and applying jobs run the change's code and never get the token. GitLab refuses the option, since its jobs read `CHANT_FORGE_TOKEN`, a CI/CD variable. Floor: `OP_WAVES_COMMAND_TOKEN_FLOOR`.
On GitHub and Forgejo the wave jobs hold no forge token unless the product asks for one with `commandToken: { permissions }` ([#5044](https://github.com/INTENTIUS/chant/issues/5044)). Then the jobs that run only the default branch's code (a push's wave, deciding, share and job group jobs, and a split wave's gate and record jobs) give their command step the job's token as `GITHUB_TOKEN`, so the spec's `respond` posts a refused wave's diff (with `"wave-refused": "summary"`, a model's summary above it) and a failed apply's triage, and a product's hooks can read the forge. The jobs ask for `permissions` beside chant's own, such as terragucci's `{ "pull-requests": "write", actions: "read" }`. `contents` and `id-token` stay chant's. A split wave's plan and applying jobs run the change's code and never get the token. GitLab refuses the option, since its jobs read `CHANT_FORGE_TOKEN`, a CI/CD variable. Floor: `OP_WAVES_COMMAND_TOKEN_FLOOR`.

On GitLab a product's cache goes in `cache` ([#5045](https://github.com/INTENTIUS/chant/issues/5045)): one `cache:` entry or a list of them, as GitLab takes them, such as terragucci's `{ key: "terragucci-terragrunt", paths: [".terragrunt-cache/"] }`. It goes on each job that runs the wave's command: the wave's own, deciding, share and job group jobs, the policy job, and a split wave's plan and applying jobs. The gate and record jobs plan and apply nothing, so they take none. GitHub and Forgejo refuse it, since a wave's `setup` can carry an `actions/cache` step there. Floor: `OP_WAVES_GITLAB_CACHE_FLOOR`.

Expand Down
11 changes: 10 additions & 1 deletion docs/src/content/docs/reference/ci-product-config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ Keys that set how a stage behaves sit in this section, under `environments.<name
| `environments.<name>.secrets.<variable>.forge_secret`, `config_sets.<set>.secrets.<variable>.forge_secret` | the forge secret a set's secret is kept in | a secret or variable name | `forgeSecret` of an `EnvironmentSecretRef` |
| `environments.<name>.imports`, `config_sets.<set>.imports` | the shared sets a set takes first, in order | a list of `config_sets` names | `EnvironmentSet.imports` |
| `config_sets.<set>` | a shared set of config and secrets that environments import | a map of `config`, `secrets` and `imports` | `EnvironmentSets.configSets` |
| `agent.wave-refused.command` | the model command that summarizes a refused wave, prompt on stdin and summary on stdout | a command line | `WaveSummarySpec.command` (`CHANT_WAVE_SUMMARY_COMMAND`) |
| `agent.wave-refused.key_secret` | the secret holding the summarizing model's key | a secret or variable name | `WaveSummarySpec.keyEnv` (`CHANT_WAVE_SUMMARY_KEY_ENV`) |
| `agent.wave-refused.timeout` | the minutes the summary command may run | a whole number | `WaveSummarySpec.timeout` (`CHANT_WAVE_SUMMARY_TIMEOUT`) |
| `agent.wave-refused.max_runs` | the most refused-wave summaries per day | a whole number | `WaveSummarySpec.maxRuns` (`CHANT_WAVE_SUMMARY_MAX_RUNS`) |
| `agent.wave-refused.max_cost_usd` | the most US dollars the refused-wave summaries may cost per day | a number above 0 | `WaveSummarySpec.maxCostUsd` (`CHANT_WAVE_SUMMARY_MAX_COST_USD`) |

A product writes one component per member and puts each environment's target in its step's `environments` map, keyed by environment name. Before the step's capability sees its input, chant merges the entry for the run's environment over the step's own input, so `promote --to staging` applies the staging target and records it under staging, and `rollback` and `redeploy` pick the target of the environment they act on. An environment the map does not name is refused before anything runs, and the refusal lists the environments it names. A pull request's environment `pr-<n>` takes its template environment's entry.

Expand Down Expand Up @@ -143,6 +148,10 @@ chant reads the sets from `ci.environmentSets` in the workspace declaration, bes

The mechanism ships as `resolveEnvironmentSet` and `environmentSetJobInputs` from `@intentius/chant/components`, and a product feature-detects it on `ENVIRONMENT_SETS_FLOOR`.

### Refused wave summary

`respond.wave-refused: summary` turns the summary on, and the `agent.wave-refused` keys set the model it runs. The note holds the diff `diff` posts with a model's summary above it; a run past a limit, or one that fails, posts the diff alone and says the summary was skipped. Each summary is one run record under op `<product>-refused-wave` with its prompt digest and cost, and `max_runs` and `max_cost_usd` count those records over the last day. The command defaults to the review command with `--output-format json`, the key to `ANTHROPIC_API_KEY`, the timeout to 10 minutes. A product passes the keys as `waveSummary` of its op waves spec or pull request loop, and chant's generated apply and wave jobs carry them as `CHANT_WAVE_SUMMARY_*` variables with the model's key: on GitHub and Forgejo from the secret `key_secret` names, on GitLab as the CI/CD variable of that name. With `diff` or `off` the jobs carry none of them. The summary approves nothing and changes no exit code. A product feature-detects it on `WAVE_REFUSED_SUMMARY_FLOOR`.

## Apply

| Key | Sets | Value | chant |
Expand Down Expand Up @@ -181,7 +190,7 @@ The mechanism ships as `resolveEnvironmentSet` and `environmentSetJobInputs` fro

| Key | Sets | Value | chant |
|---|---|---|---|
| `respond.wave-refused` | what follows a wave that applied nothing because its plan moved | `diff`, `off` | `CiResponses["wave-refused"]` |
| `respond.wave-refused` | what follows a wave that applied nothing because its plan moved | `diff`, `summary`, `off` | `CiResponses["wave-refused"]` |
| `respond.apply-failed` | what follows a failed apply | `triage`, `off` | `CiResponses["apply-failed"]` |
| `respond.description` | the pull request description check | `check`, `off` | `CiResponses.description` |
| `respond.drift` | what follows a drift the scheduled check finds | `issue`, `pull-request`, `attribute`, `up`, `off` | the scheduled drift Op's response |
Expand Down
54 changes: 54 additions & 0 deletions lexicons/forgejo/src/components/generate-wave-summary.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* #5335: with `respond: { "wave-refused": "summary" }` the Forgejo wave jobs
* and the pull request loop's apply job carry the summary's settings and
* the model's key from the secret of its name. With `diff` or `off` the
* settings change nothing: the rendered files are the same bytes.
*/
import { describe, expect, test } from "vitest";
import { parseYAML } from "@intentius/chant/yaml";
import type { OpWavesSpec } from "@intentius/chant/op/op-waves";
import type { DriverComponent } from "@intentius/chant/components/driver";
import { generateForgejoOpWavesPipeline } from "./generate-op-waves-pipeline";
import { generateForgejoPipeline } from "./generate-pipeline";

const spec: OpWavesSpec = { name: "plywood-up", op: "plywood-up", plan: ["./bin/plan", "{target}", "{plan}"], waves: [{ name: "prod", runs: [{ target: "app" }] }] };
const SUMMARY = { keyEnv: "MODEL_KEY", maxRuns: 5, maxCostUsd: 2.5 };
const ESTATE: DriverComponent[] = [{ name: "net", dependsOn: [], deploy: [{ phase: "Apply", steps: [{ kind: "terraform-apply", root: "net" }] }] }];

const waves = (s: OpWavesSpec) => generateForgejoOpWavesPipeline(s, { specFile: "waves.json" }).files.map((f) => f.yaml).join("\n---\n");
/** The parsed documents as one JSON text, to look for one variable's entry whatever the YAML quoting. */
const parsed = (yaml: string) => JSON.stringify(yaml.split("\n---\n").map((d) => parseYAML(d)));
const entry = (name: string, value: string) => `${JSON.stringify(name)}:${JSON.stringify(value)}`;
const loop = (prLoop: Record<string, unknown>) => generateForgejoPipeline(ESTATE, { env: "prod", prLoop: { applyBeforeMerge: true, ...prLoop } }).yaml;

describe("the refused wave's summary on Forgejo (#5335)", () => {
test("the wave jobs carry the settings and the key's secret", () => {
const yaml = waves({ ...spec, respond: { "wave-refused": "summary" }, waveSummary: SUMMARY });
expect(parsed(yaml)).toContain(entry("MODEL_KEY", "${{ secrets.MODEL_KEY }}"));
expect(parsed(yaml)).toContain(entry("CHANT_WAVE_SUMMARY_KEY_ENV", "MODEL_KEY"));
expect(parsed(yaml)).toContain(entry("CHANT_WAVE_SUMMARY_MAX_RUNS", "5"));
expect(parsed(yaml)).toContain(entry("CHANT_WAVE_SUMMARY_MAX_COST_USD", "2.5"));
const plain = waves({ ...spec, respond: { "wave-refused": "summary" } });
expect(parsed(plain)).toContain(entry("ANTHROPIC_API_KEY", "${{ secrets.ANTHROPIC_API_KEY }}"));
});

test("with diff or off the wave files are the same bytes", () => {
for (const mode of ["diff", "off"] as const) {
expect(waves({ ...spec, respond: { "wave-refused": mode }, waveSummary: SUMMARY })).toBe(waves({ ...spec, respond: { "wave-refused": mode } }));
}
expect(waves({ ...spec, waveSummary: SUMMARY })).toBe(waves(spec));
});

test("the pull request loop's apply job carries them with summary, and nothing else changes with diff or off", () => {
const yaml = loop({ respond: { "wave-refused": "summary" }, waveSummary: SUMMARY });
expect(parsed(yaml)).toContain(entry("CHANT_RESPOND", "wave-refused=summary"));
expect(parsed(yaml)).toContain(entry("MODEL_KEY", "${{ secrets.MODEL_KEY }}"));
expect(parsed(yaml)).toContain(entry("CHANT_WAVE_SUMMARY_KEY_ENV", "MODEL_KEY"));
for (const mode of ["diff", "off"] as const) expect(loop({ respond: { "wave-refused": mode }, waveSummary: SUMMARY })).toBe(loop({ respond: { "wave-refused": mode } }));
expect(loop({ waveSummary: SUMMARY })).toBe(loop({}));
});

test("settings that are not settings are refused", () => {
expect(() => waves({ ...spec, respond: { "wave-refused": "summary" }, waveSummary: { keyEnv: "not a var" } })).toThrow(/key variable/);
});
});
4 changes: 3 additions & 1 deletion lexicons/github/src/components/generate-op-waves-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
import { opWavesWithEnvironmentSets } from "@intentius/chant/op/op-waves-environment-sets";
import {
notifyVariables,
opWavesSummaryEnv,
opWaveChecksDir,
opWaveGroupOf,
opWaveJobs,
Expand Down Expand Up @@ -388,7 +389,8 @@ export function buildGithubOpWavesDoc(

const jobsDoc: Record<string, unknown> = {};
// #3761: the notify variables come from the secrets of the same name. #4987: before merge, on the jobs that run the default branch's code alone.
const notifyEnv = githubSecretEnv(notifyVariables(spec.notify));
// #5335: with wave-refused: summary, the summary's settings and its model key from the secret of its name, beside the notify secrets.
const notifyEnv = { ...githubSecretEnv(notifyVariables(spec.notify)), ...opWavesSummaryEnv(spec, forge) };
if (split) Object.assign(jobsDoc, githubSplitJobsDoc({ spec, options, forge, product, image, byReview, timeout, inputs, renderEnv, bmEnv, notifyEnv, split, names, ...(restWave !== undefined ? { restWave } : {}), ...(firstNeeds.length > 0 ? { firstNeeds } : {}), ...(commandToken ? { commandToken } : {}) }));
for (const job of split ? [] : jobs) {
const wave = spec.waves[job.wave - 1]!;
Expand Down
54 changes: 54 additions & 0 deletions lexicons/github/src/components/generate-wave-summary.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* #5335: with `respond: { "wave-refused": "summary" }` the GitHub wave jobs
* and the pull request loop's apply job carry the summary's settings and
* the model's key from the secret of its name. With `diff` or `off` the
* settings change nothing: the rendered files are the same bytes.
*/
import { describe, expect, test } from "vitest";
import { parseYAML } from "@intentius/chant/yaml";
import type { OpWavesSpec } from "@intentius/chant/op/op-waves";
import type { DriverComponent } from "@intentius/chant/components/driver";
import { generateGithubOpWavesPipeline } from "./generate-op-waves-pipeline";
import { generateGithubPipeline } from "./generate-pipeline";

const spec: OpWavesSpec = { name: "plywood-up", op: "plywood-up", plan: ["./bin/plan", "{target}", "{plan}"], waves: [{ name: "prod", runs: [{ target: "app" }] }] };
const SUMMARY = { keyEnv: "MODEL_KEY", maxRuns: 5, maxCostUsd: 2.5 };
const ESTATE: DriverComponent[] = [{ name: "net", dependsOn: [], deploy: [{ phase: "Apply", steps: [{ kind: "terraform-apply", root: "net" }] }] }];

const waves = (s: OpWavesSpec) => generateGithubOpWavesPipeline(s, { specFile: "waves.json" }).files.map((f) => f.yaml).join("\n---\n");
/** The parsed documents as one JSON text, to look for one variable's entry whatever the YAML quoting. */
const parsed = (yaml: string) => JSON.stringify(yaml.split("\n---\n").map((d) => parseYAML(d)));
const entry = (name: string, value: string) => `${JSON.stringify(name)}:${JSON.stringify(value)}`;
const loop = (prLoop: Record<string, unknown>) => generateGithubPipeline(ESTATE, { env: "prod", prLoop: { applyBeforeMerge: true, ...prLoop } }).yaml;

describe("the refused wave's summary on GitHub (#5335)", () => {
test("the wave jobs carry the settings and the key's secret", () => {
const yaml = waves({ ...spec, respond: { "wave-refused": "summary" }, waveSummary: SUMMARY });
expect(parsed(yaml)).toContain(entry("MODEL_KEY", "${{ secrets.MODEL_KEY }}"));
expect(parsed(yaml)).toContain(entry("CHANT_WAVE_SUMMARY_KEY_ENV", "MODEL_KEY"));
expect(parsed(yaml)).toContain(entry("CHANT_WAVE_SUMMARY_MAX_RUNS", "5"));
expect(parsed(yaml)).toContain(entry("CHANT_WAVE_SUMMARY_MAX_COST_USD", "2.5"));
const plain = waves({ ...spec, respond: { "wave-refused": "summary" } });
expect(parsed(plain)).toContain(entry("ANTHROPIC_API_KEY", "${{ secrets.ANTHROPIC_API_KEY }}"));
});

test("with diff or off the wave files are the same bytes", () => {
for (const mode of ["diff", "off"] as const) {
expect(waves({ ...spec, respond: { "wave-refused": mode }, waveSummary: SUMMARY })).toBe(waves({ ...spec, respond: { "wave-refused": mode } }));
}
expect(waves({ ...spec, waveSummary: SUMMARY })).toBe(waves(spec));
});

test("the pull request loop's apply job carries them with summary, and nothing else changes with diff or off", () => {
const yaml = loop({ respond: { "wave-refused": "summary" }, waveSummary: SUMMARY });
expect(parsed(yaml)).toContain(entry("CHANT_RESPOND", "wave-refused=summary"));
expect(parsed(yaml)).toContain(entry("MODEL_KEY", "${{ secrets.MODEL_KEY }}"));
expect(parsed(yaml)).toContain(entry("CHANT_WAVE_SUMMARY_KEY_ENV", "MODEL_KEY"));
for (const mode of ["diff", "off"] as const) expect(loop({ respond: { "wave-refused": mode }, waveSummary: SUMMARY })).toBe(loop({ respond: { "wave-refused": mode } }));
expect(loop({ waveSummary: SUMMARY })).toBe(loop({}));
});

test("settings that are not settings are refused", () => {
expect(() => waves({ ...spec, respond: { "wave-refused": "summary" }, waveSummary: { keyEnv: "not a var" } })).toThrow(/key variable/);
});
});
Loading