Repository navigation
feat(ops): an environment option on a scheduled Op, so a deployment-protection reviewer can gate the generated apply (#2257) - #2264
Merged
Conversation
…generated job's deployment gate (#2257) `generateOpsPipeline` emitted no `environment:` on any job, so a GitHub environment with required reviewers bound nothing a chant-generated pipeline ran. The option lands on `ScheduledOpSpec` beside #2242's `setup` and `permissions`, not on `OpConfig` beside #2120's `schedule`: a cadence is runtime-neutral data three readers render, while which forge environment a job deploys to has exactly one reader, is a property of that job rather than of the Op (the pull-request plan touches no environment; only the push apply belongs behind the reviewer), and would have to be overridden per generate call anyway for an Op generated into more than one environment. github emits `environment: { name, url? }` on the Op's own job and never on the gate-notice job beside it, which exists to say a chant gate is pending and would be useless held behind the same reviewer. `permissionsFor` gains nothing: environment protection is repository configuration, not a token scope. `assertEnvironment` refuses only what could never bind — a blank name, and a `url` that is neither absolute nor an expression the forge resolves — because GitHub creates an unprotected environment on first use rather than failing, so whether reviewers exist is not answerable from workflow content. forgejo drops the key: Forgejo Actions has no environments, no protection rules and no required reviewers. Dropping it silently would be the worst available outcome when the whole point of the option is a human holding an apply, so the generated file gains a header comment naming the environment that was asked for, saying nothing on the forge enforces it, and pointing at chant's own gate. The drop is scoped to the Op generator rather than added to the dialect's `DROPPED_KEYS`, so every other document the dialect transforms is untouched. gitlab maps it to its own `environment:`, which exists there with the same two fields and a protected-environment approval rule behind it. As with the schedule, the approval rule is a project setting this file cannot declare, so the generated header names the environment to protect. Additive throughout: a spec without `environment` emits the same bytes it did before.
…aim to bytes (#2257) Fifteen new assertions across the three generators and the plan-on-pr example, all of them red against the parent commit: the key on github's job and its absence on the notice job beside it, the url form, forgejo's drop plus the header that says which environment did not survive, gitlab's own environment: mapping and its protected-environments header line, and the three refusals. Each generator additionally pins the exact document a spec with no environment emits, as a literal produced by the generator at the parent commit rather than by this one. That is what makes "additive" falsifiable: those three passed before the change and pass after it, so they are a byte comparison against the old output and not a tautology.
The ops guide gains a "Two gates, and how they compose" section: the reviewer stops the job before it starts, so nothing is checked out and no role is assumed; chant's gate stops the apply inside a run that already started, on a plan that already exists, and is cleared by a commit rather than a button. Either alone is coherent, both is the usual production arrangement, and the choice is per environment. The per-Op options paragraph now covers all three and says what each provider does with the new one. The terraform ops page and the plan-on-pr README carry the worked version: the apply spec names `production`, the emitted YAML shows the key, and both say that the environment costs no token scope and that the pending-gate notice job stays outside it. The lexicon-authoring page tells a generator author that this is the option where a silent drop is worst. Regenerating the terraform docs twin also picked up a stale lexicon version line (0.57.0 to 0.59.0) that predates this branch.
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2257.
generateOpsPipelineemitted noenvironment:on any job, so a GitHub environment with required reviewers bound nothing a chant-generated pipeline ran. INTENTIUS/choudoufu#807 (c) had to say in its README that itsproductionenvironment gates no job today. This is the key, per forge.Where the option lives, and why
On
ScheduledOpSpec, beside #2242'ssetupandpermissions— not onOpConfigbeside #2120'sschedule.#2120 moved the cadence onto the Op because a cadence is runtime-neutral data with three independent readers: the CI generators render it as a cron,
chant operatorreads it as a tick, a fountainStewardturns it into aSchedule. An environment has one reader, the CI generator, and it is not runtime-neutral: it names an object that exists on GitHub and GitLab and does not exist on Forgejo at all.It is also a property of the job rather than of the Op, which is exactly the reason #2242 gave for
setupbeing per Op: inplan-on-prthe pull-request plan touches no environment and only the push apply belongs behind the reviewer, over the same root and the same code. An Op generated into two environments would need two values, so a value pinned to the Op would have to be overridden per generate call anyway.Per forge
github emits
environment:on that Op's job, always as a mapping rather than theenvironment: namestring shorthand, so adding aurllater is a new key rather than a reshaped value. It is emitted on the Op's own job and never on the<op>-gate-noticejob beside it: that job exists to say a chant gate is pending, and behind the same reviewer it would only become readable after somebody had already acted on what it reports.permissionsForgains nothing. Environment protection is repository configuration — the reviewers, the wait timer and the branch restriction live on the environment object in Settings, not in the workflow and not onGITHUB_TOKEN— so the option costs no scope at all. A test asserts the permission set is identical with and without it, and that it does not reach fordeployments.assertEnvironmentrefuses only what could never bind: a blank name, an emptyurl, and aurlthat is neither absolute nor a${{ }}expression (GitHub renders it as the deployment's own link, so a relative path is a dead link rather than an error anywhere). Nothing checks that the environment exists or is protected, and that is deliberate: GitHub creates an unprotected environment on first use rather than failing, so whether reviewers exist is not answerable from workflow content.forgejo drops the key. Forgejo Actions has no environments — no protection rules, no required reviewers, no wait timers — so the key would read as a deployment gate and hold nothing back. Unlike
permissions:, which the runner reads and ignores, this names an object that does not exist on the instance, and the whole point of the option is a human holding an apply, so a silent drop is the worst outcome available. The generated file therefore gains a header comment naming the environment that was asked for, stating that nothing on the forge enforces it, and pointing at chant's own gate, which needs nothing from the forge:The drop is scoped to the Op generator rather than added to the dialect's
DROPPED_KEYS. Adding it there would also have dropped theenvironment:theDeployEnvironmentcomposite puts on component-pipeline jobs, changing output for an existing surface that is not this issue. That gap is real (aDeployEnvironmenttargeted at forgejo still emits a key the runner ignores) and worth its own issue; it is not touched here.gitlab maps it onto its own
environment:, which exists there with the same two fields and a protected-environment approval rule behind it. This is the one of the three per-Op options GitLab can honour rather than refuse. What it cannot declare from the file is the protection itself — an environment's approval rules are project settings, exactly as GitHub's required reviewers are repository settings — so the generated header names the environment to protect, the same way it already names the Pipeline Schedule to create:How the two gates compose
Documented on the ops guide as its own section, and on the terraform ops page and the
plan-on-prREADME in worked form.The environment reviewer stops the job before it starts. Nothing is checked out, the apply role is never assumed, and the run sits in the forge's queue until somebody with access to that environment releases it.
chant's own gate (#2119) stops the apply inside a run that already started. The Op plans, reaches its Gate phase, finds no resolution on the gate ledger, records a pending fact on the
chant/lifecyclebranch and ends.chant approve <op> <gate> --approver yourecords the answer as another fact on that branch, and the next run reads it and applies. Because it is a fact rather than a held connection, the decision survives the run that asked for it, and the approver is reading a plan that already exists.The reviewer answers whether the job may run at all, cheaply and before any cost is incurred. chant's gate answers whether this exact plan should be applied, which nothing can answer before the job has run far enough to produce it. Either alone is coherent — the reviewer alone pairs with
gate: "never"on the root; chant's gate alone is what a Forgejo estate gets — and both, or neither, is the user's choice per environment.plan-on-pr
The apply spec now sets
environment: { name: "production" }; the plan spec sets none, because it deploys nothing and a reviewer prompt on every pull request is the fastest way to teach people to click through one.examples.test.tsasserts the key on the apply job, its absence on the plan workflow and on the gate-notice job, and that the apply's permission set is unchanged.Additive, proven against bytes
Each of the three generators pins the exact document a spec with no
environmentemits, as a literal produced by the generator at the commit this branch started from, not by this one. Those three tests passed before the change and pass after it, so they are a byte comparison against the old output rather than a tautology. The github suite additionally asserts that adding the option changes exactly the environment block:Red first
The 15 new discriminating assertions were run against the parent commit's generators with the new test files in place. All 15 failed; the three byte-identical goldens passed, which is what makes them meaningful.
Gates
Run in this worktree, on the rebased branch:
Not run here, by instruction: anything needing a container, an emulator, a live forge or a long acceptance suite. Specifically,
just ciin full,just check-lexicons,just docs-build/docs-check-links(needs lychee), and the terraform lexicon's acceptance blocks (src/op/activities/choudoufu.acceptance.test.ts,composites/terraform-adopt-op.acceptance.test.ts), which gate on a terraform binary and the pinned floci emulator. Nothing in this change touches an activity, an executor or the emulator surface, so those blocks exercise no new code; runningjust cion the merge result is the verification someone should do before merging.Downstream
INTENTIUS/choudoufu#807's
TestPipelineGovernanceEnvironmentGapIsStillRealis designed to go red the day a regeneratedlive-apply.ymlcarries this key. Once choudoufu repins chant and regenerates, that test should fail, which is the signal to rewrite the README section saying the reviewer gates no job today. That is tracked there as item (f) of #807.Notes
npm run docs -w @intentius/chant-lexicon-terraform) also corrected a stale lexicon version line inlexicons/terraform/docs/src/content/docs/index.mdx(0.57.0 → 0.59.0) that predates this branch.environment:from theDeployEnvironmentcomposite that the Forgejo runner ignores. Out of scope here and left untouched on purpose; worth its own issue.