@intentius/chant 0.124.40 → 0.124.42
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__/oidc-emulator.d.ts +49 -0
- package/dist/__fixtures__/oidc-emulator.d.ts.map +1 -0
- package/dist/__fixtures__/oidc-emulator.js +89 -0
- package/dist/ci-handover.d.ts +117 -0
- package/dist/ci-handover.d.ts.map +1 -0
- package/dist/ci-handover.js +217 -0
- package/dist/ci-identity.d.ts +190 -0
- package/dist/ci-identity.d.ts.map +1 -0
- package/dist/ci-identity.js +219 -0
- package/dist/cli/handlers/approve.d.ts +2 -1
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +20 -6
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +18 -1
- package/dist/cli/handlers/fan-out.d.ts.map +1 -1
- package/dist/cli/handlers/fan-out.js +42 -5
- package/dist/cli/handlers/gate-resume.d.ts +3 -0
- package/dist/cli/handlers/gate-resume.d.ts.map +1 -1
- package/dist/cli/handlers/gate-resume.js +15 -2
- package/dist/cli/handlers/lock.d.ts +8 -0
- package/dist/cli/handlers/lock.d.ts.map +1 -0
- package/dist/cli/handlers/lock.js +197 -0
- package/dist/cli/handlers/pr-env.d.ts +34 -0
- package/dist/cli/handlers/pr-env.d.ts.map +1 -0
- package/dist/cli/handlers/pr-env.js +436 -0
- package/dist/cli/handlers/pr.d.ts +76 -0
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +615 -55
- package/dist/cli/handlers/promote.d.ts.map +1 -1
- package/dist/cli/handlers/promote.js +9 -0
- package/dist/cli/handlers/query.d.ts +6 -0
- package/dist/cli/handlers/query.d.ts.map +1 -0
- package/dist/cli/handlers/query.js +80 -0
- package/dist/cli/handlers/run.d.ts.map +1 -1
- package/dist/cli/handlers/run.js +11 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +49 -4
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +46 -2
- package/dist/cli/registry.d.ts +31 -2
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/capability.d.ts +47 -0
- package/dist/components/capability.d.ts.map +1 -1
- package/dist/components/capability.js +44 -0
- package/dist/components/cli-support.d.ts +6 -0
- package/dist/components/cli-support.d.ts.map +1 -1
- package/dist/components/cli-support.js +8 -1
- package/dist/components/driver.d.ts +10 -0
- package/dist/components/driver.d.ts.map +1 -1
- package/dist/components/driver.js +52 -2
- package/dist/components/fan-out-run.d.ts +37 -0
- package/dist/components/fan-out-run.d.ts.map +1 -1
- package/dist/components/fan-out-run.js +44 -4
- package/dist/components/gate-plan.d.ts +2 -0
- package/dist/components/gate-plan.d.ts.map +1 -1
- package/dist/components/gate-plan.js +1 -0
- package/dist/components/pr-environment.d.ts +298 -0
- package/dist/components/pr-environment.d.ts.map +1 -0
- package/dist/components/pr-environment.js +406 -0
- package/dist/components/pr-hooks.d.ts +66 -0
- package/dist/components/pr-hooks.d.ts.map +1 -0
- package/dist/components/pr-hooks.js +119 -0
- package/dist/components/pr-pipeline.d.ts +92 -2
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +150 -21
- package/dist/components/pr-policy.d.ts +109 -0
- package/dist/components/pr-policy.d.ts.map +1 -0
- package/dist/components/pr-policy.js +150 -0
- package/dist/components/pr-run.d.ts +6 -0
- package/dist/components/pr-run.d.ts.map +1 -1
- package/dist/components/pr-run.js +8 -3
- package/dist/components/wave-plan.d.ts +14 -1
- package/dist/components/wave-plan.d.ts.map +1 -1
- package/dist/components/wave-plan.js +34 -2
- package/dist/gate-decision.d.ts +15 -2
- package/dist/gate-decision.d.ts.map +1 -1
- package/dist/gate-decision.js +17 -2
- package/dist/gate-policy.d.ts +140 -0
- package/dist/gate-policy.d.ts.map +1 -0
- package/dist/gate-policy.js +242 -0
- package/dist/lifecycle/gate-checkpoint.d.ts +1 -1
- package/dist/lifecycle/gate-checkpoint.js +1 -1
- package/dist/{workspace/trust → lifecycle}/gate-seal.d.ts +1 -1
- package/dist/lifecycle/gate-seal.d.ts.map +1 -0
- package/dist/lifecycle/query.d.ts +68 -0
- package/dist/lifecycle/query.d.ts.map +1 -0
- package/dist/lifecycle/query.js +246 -0
- package/dist/lifecycle/run-ledger.d.ts +13 -0
- package/dist/lifecycle/run-ledger.d.ts.map +1 -1
- package/dist/lifecycle/run-ledger.js +16 -0
- package/dist/lifecycle/target-lock.d.ts +97 -0
- package/dist/lifecycle/target-lock.d.ts.map +1 -0
- package/dist/lifecycle/target-lock.js +286 -0
- package/dist/op/activities/activity-contracts.d.ts +30 -0
- package/dist/op/activities/activity-contracts.d.ts.map +1 -1
- package/dist/op/activities/activity-contracts.js +26 -0
- package/dist/op/activities/index.d.ts +2 -0
- package/dist/op/activities/index.d.ts.map +1 -1
- package/dist/op/activities/index.js +4 -0
- package/dist/op/activities/pr-refs.d.ts +10 -0
- package/dist/op/activities/pr-refs.d.ts.map +1 -0
- package/dist/op/activities/pr-refs.js +26 -0
- package/dist/op/activities/predict-behaviour.d.ts +2 -4
- package/dist/op/activities/predict-behaviour.d.ts.map +1 -1
- package/dist/op/activities/predict-behaviour.js +2 -21
- package/dist/op/activities/review-agent.d.ts +137 -0
- package/dist/op/activities/review-agent.d.ts.map +1 -0
- package/dist/op/activities/review-agent.js +266 -0
- package/dist/op/builders.d.ts +9 -0
- package/dist/op/builders.d.ts.map +1 -1
- package/dist/op/builders.js +11 -0
- package/dist/op/cron.d.ts +8 -0
- package/dist/op/cron.d.ts.map +1 -1
- package/dist/op/cron.js +51 -0
- package/dist/op/gate-approval.d.ts +20 -13
- package/dist/op/gate-approval.d.ts.map +1 -1
- package/dist/op/gate-approval.js +13 -18
- package/dist/op/gate-quorum.d.ts +131 -0
- package/dist/op/gate-quorum.d.ts.map +1 -0
- package/dist/op/gate-quorum.js +183 -0
- package/dist/op/gate-resume.d.ts +4 -2
- package/dist/op/gate-resume.d.ts.map +1 -1
- package/dist/op/gate-resume.js +5 -4
- package/dist/op/gate-review.js +1 -1
- package/dist/op/gate.d.ts +32 -4
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +40 -24
- package/dist/op/index.d.ts +6 -4
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +4 -3
- package/dist/op/local-executor.d.ts.map +1 -1
- package/dist/op/local-executor.js +9 -3
- package/dist/op/op-waves-run.d.ts +28 -43
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +170 -120
- package/dist/op/op-waves.d.ts +55 -3
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +63 -8
- package/dist/op/schedule-overdue.d.ts +57 -0
- package/dist/op/schedule-overdue.d.ts.map +1 -0
- package/dist/op/schedule-overdue.js +138 -0
- package/dist/op/stage-hooks.d.ts +132 -0
- package/dist/op/stage-hooks.d.ts.map +1 -0
- package/dist/op/stage-hooks.js +142 -0
- package/dist/override-gate.d.ts +2 -2
- package/dist/override-gate.d.ts.map +1 -1
- package/dist/override-gate.js +1 -1
- package/dist/pr-forge.d.ts +64 -0
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +331 -44
- package/dist/pr-loop.d.ts +107 -1
- package/dist/pr-loop.d.ts.map +1 -1
- package/dist/pr-loop.js +84 -3
- package/dist/pr-post.d.ts +72 -0
- package/dist/pr-post.d.ts.map +1 -0
- package/dist/pr-post.js +134 -0
- package/dist/pr-requires.d.ts +38 -0
- package/dist/pr-requires.d.ts.map +1 -0
- package/dist/pr-requires.js +48 -0
- package/dist/wave-blocked.d.ts +79 -0
- package/dist/wave-blocked.d.ts.map +1 -0
- package/dist/wave-blocked.js +245 -0
- package/dist/wave-engine.d.ts +6 -0
- package/dist/wave-engine.d.ts.map +1 -1
- package/dist/wave-engine.js +2 -0
- package/dist/wave-runtime.mjs +243 -243
- package/dist/workspace/__fixtures__/two-member-workspace.d.ts +1 -0
- package/dist/workspace/__fixtures__/two-member-workspace.d.ts.map +1 -1
- package/dist/workspace/__fixtures__/two-member-workspace.js +1 -1
- package/dist/workspace/checks/ci-workflow.d.ts.map +1 -1
- package/dist/workspace/checks/ci-workflow.js +19 -4
- package/dist/workspace/ci-branches.d.ts +51 -0
- package/dist/workspace/ci-branches.d.ts.map +1 -0
- package/dist/workspace/ci-branches.js +69 -0
- package/dist/workspace/ci-cloud-identity.d.ts +11 -0
- package/dist/workspace/ci-cloud-identity.d.ts.map +1 -0
- package/dist/workspace/ci-cloud-identity.js +24 -0
- package/dist/workspace/ci-init.d.ts.map +1 -1
- package/dist/workspace/ci-init.js +5 -4
- package/dist/workspace/ci-locks.d.ts +12 -0
- package/dist/workspace/ci-locks.d.ts.map +1 -0
- package/dist/workspace/ci-locks.js +6 -0
- package/dist/workspace/ci-run.d.ts +17 -1
- package/dist/workspace/ci-run.d.ts.map +1 -1
- package/dist/workspace/ci-run.js +66 -4
- package/dist/workspace/ci-workflow-at.d.ts +14 -0
- package/dist/workspace/ci-workflow-at.d.ts.map +1 -0
- package/dist/workspace/ci-workflow-at.js +17 -0
- package/dist/workspace/ci-workflow.d.ts +11 -3
- package/dist/workspace/ci-workflow.d.ts.map +1 -1
- package/dist/workspace/ci-workflow.js +10 -2
- package/dist/workspace/declaration.d.ts +69 -3
- package/dist/workspace/declaration.d.ts.map +1 -1
- package/dist/workspace/declaration.js +72 -1
- package/dist/workspace/declaration.schema.json +149 -2
- package/dist/workspace/identity-gate-rule.d.ts +1 -1
- package/dist/workspace/identity-gate-rule.d.ts.map +1 -1
- package/dist/workspace/identity-gate-rule.js +1 -1
- package/dist/workspace/identity.d.ts +1 -1
- package/dist/workspace/identity.d.ts.map +1 -1
- package/dist/workspace/lineage-upgrade.d.ts.map +1 -1
- package/dist/workspace/lineage-upgrade.js +8 -5
- package/dist/workspace/member-pipeline.d.ts +6 -0
- package/dist/workspace/member-pipeline.d.ts.map +1 -1
- package/dist/workspace/member-pipeline.js +23 -0
- package/dist/workspace/pr-report.schema.json +94 -3
- package/dist/workspace/reason-codes.d.ts +1 -1
- package/dist/workspace/reason-codes.d.ts.map +1 -1
- package/dist/workspace/reason-codes.js +1 -1
- package/dist/workspace/security.d.ts.map +1 -1
- package/dist/workspace/security.js +4 -0
- package/dist/workspace/status-gates.d.ts +3 -2
- package/dist/workspace/status-gates.d.ts.map +1 -1
- package/dist/workspace/status-gates.js +8 -7
- package/dist/workspace/status.d.ts.map +1 -1
- package/dist/workspace/status.js +4 -1
- package/dist/workspace/trust/seal.d.ts +2 -2
- package/dist/workspace/trust/seal.d.ts.map +1 -1
- package/dist/workspace/trust/seal.js +2 -2
- package/package.json +1 -1
- package/src/__fixtures__/oidc-emulator.ts +118 -0
- package/src/ci-handover.test.ts +209 -0
- package/src/ci-handover.ts +237 -0
- package/src/ci-identity.test.ts +201 -0
- package/src/ci-identity.ts +310 -0
- package/src/cli/handlers/approve.ts +18 -5
- package/src/cli/handlers/build.ts +18 -1
- package/src/cli/handlers/fan-out.ts +43 -6
- package/src/cli/handlers/gate-resume.ts +16 -2
- package/src/cli/handlers/lock.test.ts +98 -0
- package/src/cli/handlers/lock.ts +202 -0
- package/src/cli/handlers/operator.test.ts +3 -1
- package/src/cli/handlers/pr-before-merge.test.ts +276 -0
- package/src/cli/handlers/pr-env.ts +462 -0
- package/src/cli/handlers/pr-waves-blocked.test.ts +247 -0
- package/src/cli/handlers/pr.test.ts +184 -0
- package/src/cli/handlers/pr.ts +605 -61
- package/src/cli/handlers/promote.ts +9 -0
- package/src/cli/handlers/query.ts +78 -0
- package/src/cli/handlers/run.ts +10 -0
- package/src/cli/main.ts +49 -4
- package/src/cli/parse-args.ts +34 -2
- package/src/cli/registry.ts +31 -2
- package/src/components/capability-targets.test.ts +162 -0
- package/src/components/capability.ts +71 -0
- package/src/components/cli-support.ts +14 -1
- package/src/components/driver.ts +54 -3
- package/src/components/fan-out-run.ts +58 -3
- package/src/components/fan-out-waves.test.ts +45 -1
- package/src/components/gate-plan.ts +3 -0
- package/src/components/pr-environment.test.ts +249 -0
- package/src/components/pr-environment.ts +538 -0
- package/src/components/pr-hooks.test.ts +118 -0
- package/src/components/pr-hooks.ts +157 -0
- package/src/components/pr-pipeline.ts +194 -21
- package/src/components/pr-policy.test.ts +145 -0
- package/src/components/pr-policy.ts +211 -0
- package/src/components/pr-run.ts +14 -2
- package/src/components/wave-plan.ts +38 -3
- package/src/gate-decision-bundle.test.ts +4 -3
- package/src/gate-decision.ts +39 -2
- package/src/gate-policy-bundle.test.ts +28 -0
- package/src/gate-policy.test.ts +162 -0
- package/src/gate-policy.ts +298 -0
- package/src/lifecycle/gate-checkpoint.ts +1 -1
- package/src/{workspace/trust → lifecycle}/gate-seal.ts +1 -1
- package/src/lifecycle/query.test.ts +91 -0
- package/src/lifecycle/query.ts +315 -0
- package/src/lifecycle/run-ledger.ts +18 -0
- package/src/lifecycle/target-lock.test.ts +195 -0
- package/src/lifecycle/target-lock.ts +347 -0
- package/src/op/activities/activity-contracts.ts +31 -0
- package/src/op/activities/index.ts +6 -0
- package/src/op/activities/pr-refs.ts +28 -0
- package/src/op/activities/predict-behaviour.ts +3 -23
- package/src/op/activities/review-agent.test.ts +240 -0
- package/src/op/activities/review-agent.ts +355 -0
- package/src/op/builders.ts +13 -0
- package/src/op/cron.ts +44 -0
- package/src/op/gate-alias.test.ts +2 -2
- package/src/op/gate-approval.test.ts +30 -9
- package/src/op/gate-approval.ts +23 -26
- package/src/op/gate-quorum.test.ts +139 -0
- package/src/op/gate-quorum.ts +248 -0
- package/src/op/gate-resume.ts +6 -3
- package/src/op/gate-review.ts +1 -1
- package/src/op/gate.ts +64 -23
- package/src/op/index.ts +13 -1
- package/src/op/local-executor.ts +9 -2
- package/src/op/op-waves-hook-targets.test.ts +126 -0
- package/src/op/op-waves-policy-hold.test.ts +66 -0
- package/src/op/op-waves-quorum.test.ts +101 -0
- package/src/op/op-waves-run.ts +197 -183
- package/src/op/op-waves.ts +83 -10
- package/src/op/schedule-overdue.test.ts +220 -0
- package/src/op/schedule-overdue.ts +161 -0
- package/src/op/stage-hooks.ts +251 -0
- package/src/override-gate-bundle.test.ts +1 -1
- package/src/override-gate.ts +2 -2
- package/src/pr-forge-bundle.test.ts +2 -2
- package/src/pr-forge.test.ts +33 -0
- package/src/pr-forge.ts +347 -35
- package/src/pr-loop-bundle.test.ts +2 -2
- package/src/pr-loop.test.ts +58 -0
- package/src/pr-loop.ts +170 -4
- package/src/pr-post.test.ts +141 -0
- package/src/pr-post.ts +159 -0
- package/src/pr-requires.test.ts +184 -0
- package/src/pr-requires.ts +79 -0
- package/src/review-agent-bundle.test.ts +35 -0
- package/src/stage-hooks-bundle.test.ts +38 -0
- package/src/wave-blocked-bundle.test.ts +25 -0
- package/src/wave-blocked.test.ts +146 -0
- package/src/wave-blocked.ts +271 -0
- package/src/wave-engine.ts +8 -0
- package/src/workspace/__fixtures__/two-member-workspace.ts +2 -2
- package/src/workspace/checks/ci-workflow.test.ts +9 -0
- package/src/workspace/checks/ci-workflow.ts +18 -4
- package/src/workspace/ci-branches.test.ts +62 -0
- package/src/workspace/ci-branches.ts +79 -0
- package/src/workspace/ci-cloud-identity.test.ts +53 -0
- package/src/workspace/ci-cloud-identity.ts +23 -0
- package/src/workspace/ci-init.ts +5 -4
- package/src/workspace/ci-locks.ts +16 -0
- package/src/workspace/ci-run-index.test.ts +2 -1
- package/src/workspace/ci-run.test.ts +107 -8
- package/src/workspace/ci-run.ts +74 -5
- package/src/workspace/ci-workflow-at.ts +23 -0
- package/src/workspace/ci-workflow.ts +13 -2
- package/src/workspace/declaration.schema.json +149 -2
- package/src/workspace/declaration.test.ts +76 -0
- package/src/workspace/declaration.ts +140 -5
- package/src/workspace/identity-gate-rule.ts +1 -1
- package/src/workspace/identity.ts +1 -1
- package/src/workspace/lineage-upgrade.ts +11 -8
- package/src/workspace/member-pipeline.test.ts +29 -0
- package/src/workspace/member-pipeline.ts +30 -0
- package/src/workspace/pr-report.schema.json +94 -3
- package/src/workspace/reason-codes.ts +1 -1
- package/src/workspace/security.ts +4 -0
- package/src/workspace/status-gates.ts +9 -6
- package/src/workspace/status.ts +4 -1
- package/src/workspace/trust/gate-seal.test.ts +1 -1
- package/src/workspace/trust/seal.ts +2 -2
- package/dist/workspace/trust/gate-seal.d.ts.map +0 -1
- /package/dist/{workspace/trust → lifecycle}/gate-seal.js +0 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A pull request's environment (#4298): what it derives from the template,
|
|
3
|
+
* the records that say which environments stand, and the ownership check a
|
|
4
|
+
* teardown runs before it deletes anything.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, expect, test } from "vitest";
|
|
8
|
+
import type { ChantConfig } from "../config";
|
|
9
|
+
import type { TeardownPlan, TeardownReport } from "../lifecycle/teardown";
|
|
10
|
+
import type { ObservationLexicon, TeardownCandidate } from "../lexicon";
|
|
11
|
+
import {
|
|
12
|
+
acceptHandedRecord,
|
|
13
|
+
derivePrEnvironment,
|
|
14
|
+
handedPrEnvReport,
|
|
15
|
+
expired,
|
|
16
|
+
isPrEnvironmentName,
|
|
17
|
+
livePrEnvironments,
|
|
18
|
+
ownedEntries,
|
|
19
|
+
parsePrEnvRecords,
|
|
20
|
+
prEnvStatusState,
|
|
21
|
+
releaseTargetRefusal,
|
|
22
|
+
renderPrEnvNote,
|
|
23
|
+
teardownComplete,
|
|
24
|
+
tearDownPrEnvironment,
|
|
25
|
+
teardownRefusal,
|
|
26
|
+
ttlMs,
|
|
27
|
+
type PrEnvRecord,
|
|
28
|
+
} from "./pr-environment";
|
|
29
|
+
|
|
30
|
+
const CONFIG: ChantConfig = {
|
|
31
|
+
environments: ["local", { name: "staging", endpoint: "http://localhost:4566" }, "prod", "pr-*"],
|
|
32
|
+
ownership: { stack: "shop", env: { param: "env" } },
|
|
33
|
+
buildParams: { env: { type: "string", default: "local" } },
|
|
34
|
+
} as ChantConfig;
|
|
35
|
+
|
|
36
|
+
function up(over: Partial<PrEnvRecord> = {}): PrEnvRecord {
|
|
37
|
+
return {
|
|
38
|
+
version: 1,
|
|
39
|
+
kind: "up",
|
|
40
|
+
pr: 7,
|
|
41
|
+
env: "pr-7",
|
|
42
|
+
template: "staging",
|
|
43
|
+
marker: { stack: "shop", env: "pr-7" },
|
|
44
|
+
commit: "a".repeat(40),
|
|
45
|
+
components: ["app"],
|
|
46
|
+
planDigest: "sha256:aa",
|
|
47
|
+
result: "applied",
|
|
48
|
+
by: "octo",
|
|
49
|
+
timestamp: "2026-10-22T10:00:00.000Z",
|
|
50
|
+
expiresAt: "2026-10-25T10:00:00.000Z",
|
|
51
|
+
releaseTarget: false,
|
|
52
|
+
...over,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe("deriving a pull request's environment", () => {
|
|
57
|
+
test("pr-<n> takes the template's endpoint and the marker env follows the build parameter", () => {
|
|
58
|
+
const d = derivePrEnvironment(CONFIG, "staging", 7);
|
|
59
|
+
expect(d).toMatchObject({ env: "pr-7", template: "staging", stack: "shop", param: "env", endpoint: "http://localhost:4566" });
|
|
60
|
+
if ("refusal" in d) throw new Error(d.refusal);
|
|
61
|
+
expect(d.environments?.[0]).toEqual({ name: "pr-7", endpoint: "http://localhost:4566" });
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("a pr-* entry's own endpoint wins over the template's", () => {
|
|
65
|
+
const config = { ...CONFIG, environments: ["staging", { name: "pr-*", endpoint: "http://localhost:9000" }] } as ChantConfig;
|
|
66
|
+
expect(derivePrEnvironment(config, "staging", 7)).toMatchObject({ endpoint: "http://localhost:9000" });
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("refuses when the resources could not be told apart from the template's", () => {
|
|
70
|
+
const off = derivePrEnvironment({ ...CONFIG, ownership: undefined } as ChantConfig, "staging", 7);
|
|
71
|
+
expect(off).toMatchObject({ refusal: expect.stringContaining("no ownership.stack") });
|
|
72
|
+
const literal = derivePrEnvironment({ ...CONFIG, ownership: { stack: "shop", env: "staging" } } as ChantConfig, "staging", 7);
|
|
73
|
+
expect(literal).toMatchObject({ refusal: expect.stringContaining('the literal "staging"') });
|
|
74
|
+
const unset = derivePrEnvironment({ ...CONFIG, ownership: { stack: "shop" } } as ChantConfig, "staging", 7);
|
|
75
|
+
expect(unset).toMatchObject({ refusal: expect.stringContaining("ownership.env is unset") });
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("refuses a template the config does not declare, and a name it would not take", () => {
|
|
79
|
+
expect(derivePrEnvironment(CONFIG, "qa", 7)).toMatchObject({ refusal: expect.stringContaining("do not declare") });
|
|
80
|
+
const noPattern = { ...CONFIG, environments: ["staging", "prod"] } as ChantConfig;
|
|
81
|
+
expect(derivePrEnvironment(noPattern, "staging", 7)).toMatchObject({ refusal: expect.stringContaining('add "pr-*"') });
|
|
82
|
+
const literal = { ...CONFIG, environments: ["staging", "pr-7", "pr-*"] } as ChantConfig;
|
|
83
|
+
expect(derivePrEnvironment(literal, "staging", 7)).toMatchObject({ refusal: expect.stringContaining("declared outright") });
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe("the records", () => {
|
|
88
|
+
test("an up makes an environment live, a destroying down ends it, an incomplete down leaves it", () => {
|
|
89
|
+
const records = [up(), up({ pr: 8, env: "pr-8", marker: { stack: "shop", env: "pr-8" } }), { ...up(), kind: "down" as const, result: "destroyed" as const }];
|
|
90
|
+
const live = livePrEnvironments(records);
|
|
91
|
+
expect([...live.keys()]).toEqual(["pr-8"]);
|
|
92
|
+
const incomplete = livePrEnvironments([up(), { ...up(), kind: "down", result: "incomplete" }]);
|
|
93
|
+
expect(incomplete.get("pr-7")?.teardownIncomplete).toBe(true);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("a later up refreshes the expiry and keeps every component it ever applied", () => {
|
|
97
|
+
const live = livePrEnvironments([up(), up({ components: ["db"], expiresAt: "2026-10-26T10:00:00.000Z" })]).get("pr-7")!;
|
|
98
|
+
expect(live.components).toEqual(["app", "db"]);
|
|
99
|
+
expect(live.expiresAt).toBe("2026-10-26T10:00:00.000Z");
|
|
100
|
+
expect(expired(live, new Date("2026-10-26T10:00:00.000Z"))).toBe(true);
|
|
101
|
+
expect(expired(live, new Date("2026-10-25T10:00:00.000Z"))).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("malformed lines are skipped", () => {
|
|
105
|
+
expect(parsePrEnvRecords(`not json\n${JSON.stringify(up())}\n{"version":2}\n`)).toHaveLength(1);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe("the ownership check on teardown", () => {
|
|
110
|
+
const live = livePrEnvironments([up()]).get("pr-7")!;
|
|
111
|
+
|
|
112
|
+
test("passes for the pull request's own environment", () => {
|
|
113
|
+
expect(teardownRefusal(7, live, CONFIG.environments)).toBeUndefined();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("refuses another pull request's record, a marker of another environment, and a declared environment", () => {
|
|
117
|
+
expect(teardownRefusal(8, live, CONFIG.environments)).toContain("not 8");
|
|
118
|
+
expect(teardownRefusal(7, { ...live, marker: { stack: "shop", env: "staging" } }, CONFIG.environments)).toContain("another environment's resources");
|
|
119
|
+
expect(teardownRefusal(7, live, ["staging", "pr-7"])).toContain("declared outright");
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("drops every planned entry whose marker is not exactly the environment's", () => {
|
|
123
|
+
const plan: TeardownPlan = {
|
|
124
|
+
environment: "pr-7",
|
|
125
|
+
stack: "shop",
|
|
126
|
+
entries: [
|
|
127
|
+
{ lexicon: "k8s", name: "web", type: "K8s::Apps::Deployment", marker: { stack: "shop", env: "pr-7" } },
|
|
128
|
+
{ lexicon: "k8s", name: "web", type: "K8s::Apps::Deployment", marker: { stack: "shop", env: "staging" } },
|
|
129
|
+
{ lexicon: "k8s", name: "other", type: "K8s::Core::Service", marker: { stack: "other", env: "pr-7" } },
|
|
130
|
+
],
|
|
131
|
+
holes: [],
|
|
132
|
+
skipped: [],
|
|
133
|
+
};
|
|
134
|
+
const owned = ownedEntries(plan, { stack: "shop", env: "pr-7" });
|
|
135
|
+
expect(owned.plan.entries.map((e) => e.marker)).toEqual([{ stack: "shop", env: "pr-7" }]);
|
|
136
|
+
expect(owned.dropped).toHaveLength(2);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("a teardown with a failure, a skip or a hole is not complete", () => {
|
|
140
|
+
const plan: TeardownPlan = { environment: "pr-7", stack: "shop", entries: [], holes: [], skipped: [] };
|
|
141
|
+
const report = (outcome: TeardownReport["outcomes"][number]["outcome"]): TeardownReport => ({
|
|
142
|
+
environment: "pr-7",
|
|
143
|
+
stack: "shop",
|
|
144
|
+
plan,
|
|
145
|
+
outcomes: [{ lexicon: "k8s", name: "web", type: "K8s::Apps::Deployment", marker: { stack: "shop", env: "pr-7" }, outcome }],
|
|
146
|
+
unimplemented: [],
|
|
147
|
+
});
|
|
148
|
+
expect(teardownComplete(report("deleted"))).toBe(true);
|
|
149
|
+
expect(teardownComplete(report("retained"))).toBe(true);
|
|
150
|
+
expect(teardownComplete(report("failed"))).toBe(false);
|
|
151
|
+
expect(teardownComplete(report("skipped"))).toBe(false);
|
|
152
|
+
expect(teardownComplete({ ...report("deleted"), plan: { ...plan, holes: [{ lexicon: "k8s", name: "*", reason: "read-failed" }] } })).toBe(false);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe("tearing down through the lexicons", () => {
|
|
157
|
+
const live = livePrEnvironments([up()]).get("pr-7")!;
|
|
158
|
+
|
|
159
|
+
/** A lexicon whose enumeration also returns another environment's resource, and records what it was asked to delete. */
|
|
160
|
+
function lexicon(): { plugin: ObservationLexicon; asked: { environment?: string; deleted: TeardownCandidate[] } } {
|
|
161
|
+
const asked: { environment?: string; deleted: TeardownCandidate[] } = { deleted: [] };
|
|
162
|
+
const plugin = {
|
|
163
|
+
name: "k8s",
|
|
164
|
+
async teardownOwned({ environment }: { environment: string }) {
|
|
165
|
+
asked.environment = environment;
|
|
166
|
+
return {
|
|
167
|
+
candidates: [
|
|
168
|
+
{ name: "web", type: "K8s::Apps::Deployment", marker: { stack: "shop", env: "pr-7" } },
|
|
169
|
+
{ name: "web", type: "K8s::Apps::Deployment", marker: { stack: "shop", env: "staging" } },
|
|
170
|
+
],
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
async executeTeardown({ candidates }: { candidates: TeardownCandidate[] }) {
|
|
174
|
+
asked.deleted.push(...candidates);
|
|
175
|
+
return { outcomes: candidates.map((c) => ({ name: c.name, outcome: "deleted" as const })) };
|
|
176
|
+
},
|
|
177
|
+
} as unknown as ObservationLexicon;
|
|
178
|
+
return { plugin, asked };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
test("deletes only what carries pr-<n>'s marker", async () => {
|
|
182
|
+
const { plugin, asked } = lexicon();
|
|
183
|
+
const torn = await tearDownPrEnvironment({ pr: 7, live, config: CONFIG, plugins: [plugin] });
|
|
184
|
+
if ("refusal" in torn) throw new Error(torn.refusal);
|
|
185
|
+
expect(asked.environment).toBe("pr-7");
|
|
186
|
+
expect(asked.deleted.map((c) => c.marker)).toEqual([{ stack: "shop", env: "pr-7" }]);
|
|
187
|
+
expect(teardownComplete(torn.report)).toBe(true);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("a refused teardown reads and deletes nothing", async () => {
|
|
191
|
+
const { plugin, asked } = lexicon();
|
|
192
|
+
const torn = await tearDownPrEnvironment({ pr: 7, live: { ...live, marker: { stack: "shop", env: "staging" } }, config: CONFIG, plugins: [plugin] });
|
|
193
|
+
expect(torn).toMatchObject({ refusal: expect.stringContaining("nothing was torn down") });
|
|
194
|
+
expect(asked.environment).toBeUndefined();
|
|
195
|
+
expect(asked.deleted).toEqual([]);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe("not a release target", () => {
|
|
200
|
+
test("a pr-<n> name is refused as a release's source or target, and nothing else is", () => {
|
|
201
|
+
expect(isPrEnvironmentName("pr-42")).toBe(true);
|
|
202
|
+
expect(isPrEnvironmentName("pr-")).toBe(false);
|
|
203
|
+
expect(isPrEnvironmentName("prod")).toBe(false);
|
|
204
|
+
expect(releaseTargetRefusal("pr-42")).toContain("never a release target");
|
|
205
|
+
expect(releaseTargetRefusal("staging")).toBeUndefined();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test("the note says so", () => {
|
|
209
|
+
const note = renderPrEnvNote({ stage: "up", pr: 7, env: "pr-7", template: "staging", head: "a".repeat(40), op: "pr-7", gate: "pr-env", digest: "sha256:aa", status: "waiting", components: [] });
|
|
210
|
+
expect(note).toContain("<!-- chant-pr-env:pr-7 -->");
|
|
211
|
+
expect(note).toContain("chant approve pr-7 pr-env --plan sha256:aa");
|
|
212
|
+
expect(note).toContain("is not a release target");
|
|
213
|
+
expect(prEnvStatusState({ status: "waiting" })).toBe("pending");
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test("ttlMs reads minutes, hours and days", () => {
|
|
218
|
+
expect(ttlMs("90m")).toBe(5_400_000);
|
|
219
|
+
expect(ttlMs("72h")).toBe(259_200_000);
|
|
220
|
+
expect(ttlMs("7d")).toBe(604_800_000);
|
|
221
|
+
expect(ttlMs("1w")).toBeUndefined();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
describe("what env-up hands on is checked as data (#4295)", () => {
|
|
225
|
+
const check = { pr: 7, head: "c".repeat(40), template: "staging", ttlMs: 3_600_000, now: new Date("2026-10-22T12:00:00.000Z"), by: "github-actions" };
|
|
226
|
+
|
|
227
|
+
test("a record for this pull request is kept with the post job's own commit, actor and expiry", () => {
|
|
228
|
+
const accepted = acceptHandedRecord(up({ expiresAt: "2099-01-01T00:00:00.000Z", commit: "d".repeat(40), by: "mallory" }), check);
|
|
229
|
+
if ("refusal" in accepted) throw new Error(accepted.refusal);
|
|
230
|
+
expect(accepted.record).toMatchObject({ pr: 7, env: "pr-7", commit: check.head, by: "github-actions", expiresAt: "2026-10-22T13:00:00.000Z", marker: { stack: "shop", env: "pr-7" }, releaseTarget: false });
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test("a record for another environment, marker, template or member is refused", () => {
|
|
234
|
+
expect(acceptHandedRecord(up({ pr: 8, env: "pr-8" }), check)).toMatchObject({ refusal: expect.stringContaining("not pr-7") });
|
|
235
|
+
expect(acceptHandedRecord(up({ marker: { stack: "shop", env: "staging" } }), check)).toMatchObject({ refusal: expect.stringContaining("marker env") });
|
|
236
|
+
expect(acceptHandedRecord(up({ template: "prod" }), check)).toMatchObject({ refusal: expect.stringContaining("template") });
|
|
237
|
+
expect(acceptHandedRecord(up({ member: "api" }), check)).toMatchObject({ refusal: expect.stringContaining("member") });
|
|
238
|
+
expect(acceptHandedRecord({ ...up(), kind: "down", result: "destroyed" }, check)).toMatchObject({ refusal: expect.stringContaining("down record") });
|
|
239
|
+
expect(acceptHandedRecord("nonsense", check)).toMatchObject({ refusal: expect.stringContaining("does not read") });
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test("a report for another environment is refused, and a kept one takes the post job's head and op", () => {
|
|
243
|
+
expect(handedPrEnvReport({ stage: "up", pr: 8, env: "pr-8", status: "applied" }, { pr: 7, head: "h" })).toMatchObject({ refusal: expect.any(String) });
|
|
244
|
+
expect(handedPrEnvReport(undefined, { pr: 7, head: "h" })).toMatchObject({ refusal: "The env-up job handed on no report." });
|
|
245
|
+
const kept = handedPrEnvReport({ stage: "up", pr: 7, env: "pr-7", status: "waiting", op: "pr-99", head: "x", digest: "sha256:aa", components: [{ component: "app", status: "planned", create: 1 }] }, { pr: 7, head: "h" });
|
|
246
|
+
if ("refusal" in kept) throw new Error(kept.refusal);
|
|
247
|
+
expect(kept.report).toMatchObject({ head: "h", op: "pr-7", status: "waiting", components: [{ component: "app", create: 1, delete: 0 }] });
|
|
248
|
+
});
|
|
249
|
+
});
|