@intentius/chant 0.124.84 → 0.124.86
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/bundle-check.d.ts +102 -0
- package/dist/bundle-check.d.ts.map +1 -0
- package/dist/bundle-check.js +310 -0
- package/dist/chant-install.d.ts +100 -0
- package/dist/chant-install.d.ts.map +1 -0
- package/dist/chant-install.js +158 -0
- package/dist/ci-commit.d.ts +19 -6
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +23 -4
- package/dist/ci-evidence-jobs.d.ts +54 -0
- package/dist/ci-evidence-jobs.d.ts.map +1 -0
- package/dist/ci-evidence-jobs.js +55 -0
- package/dist/ci-image.d.ts +274 -0
- package/dist/ci-image.d.ts.map +1 -0
- package/dist/ci-image.js +635 -0
- package/dist/ci-login.d.ts +150 -0
- package/dist/ci-login.d.ts.map +1 -0
- package/dist/ci-login.js +240 -0
- package/dist/ci-product.d.ts +16 -0
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +17 -0
- package/dist/cli/commands/import-index.js +2 -2
- package/dist/cli/handlers/build.d.ts +8 -0
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +22 -4
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +57 -2
- package/dist/cli/handlers/ci-evidence.d.ts +3 -0
- package/dist/cli/handlers/ci-evidence.d.ts.map +1 -0
- package/dist/cli/handlers/ci-evidence.js +171 -0
- package/dist/cli/handlers/components.js +3 -3
- package/dist/cli/handlers/dead-guards.d.ts +3 -0
- package/dist/cli/handlers/dead-guards.d.ts.map +1 -0
- package/dist/cli/handlers/dead-guards.js +35 -0
- package/dist/cli/handlers/graph.js +4 -4
- package/dist/cli/handlers/lifecycle.d.ts +2 -1
- package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
- package/dist/cli/handlers/lifecycle.js +5 -4
- package/dist/cli/handlers/local-chant.d.ts +16 -0
- package/dist/cli/handlers/local-chant.d.ts.map +1 -0
- package/dist/cli/handlers/local-chant.js +109 -0
- package/dist/cli/handlers/operator.js +2 -2
- package/dist/cli/handlers/search.js +5 -5
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +38 -0
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +28 -0
- package/dist/cli/registry.d.ts +16 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/check-hooks.d.ts +49 -0
- package/dist/components/check-hooks.d.ts.map +1 -1
- package/dist/components/check-hooks.js +64 -4
- package/dist/components/check-steps.d.ts +17 -0
- package/dist/components/check-steps.d.ts.map +1 -1
- package/dist/components/check-steps.js +37 -5
- package/dist/components/product-pipeline.d.ts +23 -0
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +6 -2
- package/dist/components/product-plan.d.ts +137 -0
- package/dist/components/product-plan.d.ts.map +1 -0
- package/dist/components/product-plan.js +143 -0
- package/dist/components/release-compile.d.ts.map +1 -1
- package/dist/components/release-compile.js +2 -2
- package/dist/config.d.ts +39 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +35 -3
- package/dist/dead-guards.d.ts +82 -0
- package/dist/dead-guards.d.ts.map +1 -0
- package/dist/dead-guards.js +436 -0
- package/dist/discovery/files.d.ts +3 -1
- package/dist/discovery/files.d.ts.map +1 -1
- package/dist/discovery/files.js +5 -3
- package/dist/drift-issue.d.ts +152 -0
- package/dist/drift-issue.d.ts.map +1 -0
- package/dist/drift-issue.js +167 -0
- package/dist/floor-table.d.ts +30 -0
- package/dist/floor-table.d.ts.map +1 -0
- package/dist/floor-table.data.d.ts +3 -0
- package/dist/floor-table.data.d.ts.map +1 -0
- package/dist/floor-table.data.js +178 -0
- package/dist/floor-table.js +56 -0
- package/dist/forge-flags.d.ts +90 -0
- package/dist/forge-flags.d.ts.map +1 -0
- package/dist/forge-flags.js +184 -0
- package/dist/lexicon.d.ts +69 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/gated-op.d.ts +7 -1
- package/dist/lifecycle/gated-op.d.ts.map +1 -1
- package/dist/lifecycle/gated-op.js +7 -4
- package/dist/local-chant.d.ts +98 -0
- package/dist/local-chant.d.ts.map +1 -0
- package/dist/local-chant.js +307 -0
- package/dist/op/activities/predict-behaviour.js +2 -2
- package/dist/op/op-waves-evidence-spec.d.ts +13 -0
- package/dist/op/op-waves-evidence-spec.d.ts.map +1 -0
- package/dist/op/op-waves-evidence-spec.js +21 -0
- package/dist/op/op-waves-evidence.d.ts +38 -0
- package/dist/op/op-waves-evidence.d.ts.map +1 -0
- package/dist/op/op-waves-evidence.js +57 -0
- package/dist/op/op-waves-run.d.ts +4 -0
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +24 -1
- package/dist/op/op-waves.d.ts +17 -1
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +23 -0
- package/dist/op/schedule-overdue.d.ts +41 -9
- package/dist/op/schedule-overdue.d.ts.map +1 -1
- package/dist/op/schedule-overdue.js +154 -25
- package/dist/plan-summary.d.ts +25 -0
- package/dist/plan-summary.d.ts.map +1 -1
- package/dist/plan-summary.js +31 -0
- package/dist/pr-plan-note.d.ts +35 -0
- package/dist/pr-plan-note.d.ts.map +1 -1
- package/dist/pr-plan-note.js +10 -0
- package/dist/pr-post.d.ts +23 -0
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +125 -3
- package/dist/release-floors.d.ts +31 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +31 -1
- package/dist/state-migration.d.ts +24 -0
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +100 -5
- package/dist/wave-runtime.mjs +305 -298
- package/dist/workspace/lexicon-outputs.d.ts.map +1 -1
- package/dist/workspace/lexicon-outputs.js +21 -7
- package/dist/workspace/reason-codes.d.ts +3 -0
- package/dist/workspace/reason-codes.d.ts.map +1 -1
- package/dist/workspace/reason-codes.js +4 -0
- package/dist/workspace/ref-gate.schema.json +85 -0
- package/dist/workspace/search-contract.d.ts +1 -1
- package/dist/workspace/search-contract.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence-report.d.ts +51 -0
- package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -0
- package/dist/workspace/trust/check-evidence-report.js +102 -0
- package/dist/workspace/trust/check-evidence.d.ts +126 -0
- package/dist/workspace/trust/check-evidence.d.ts.map +1 -0
- package/dist/workspace/trust/check-evidence.js +237 -0
- package/dist/workspace/trust/local-evidence.d.ts +120 -0
- package/dist/workspace/trust/local-evidence.d.ts.map +1 -0
- package/dist/workspace/trust/local-evidence.js +259 -0
- package/dist/workspace/trust/policy.d.ts +84 -0
- package/dist/workspace/trust/policy.d.ts.map +1 -1
- package/dist/workspace/trust/policy.js +94 -1
- package/dist/workspace/trust/ref-gate-cli.d.ts +33 -0
- package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -0
- package/dist/workspace/trust/ref-gate-cli.js +234 -0
- package/dist/workspace/trust/ref-gate-fixture.d.ts +38 -0
- package/dist/workspace/trust/ref-gate-fixture.d.ts.map +1 -0
- package/dist/workspace/trust/ref-gate-fixture.js +97 -0
- package/dist/workspace/trust/ref-gate.d.ts +187 -0
- package/dist/workspace/trust/ref-gate.d.ts.map +1 -0
- package/dist/workspace/trust/ref-gate.js +430 -0
- package/dist/workspace/trust/trust-files.d.ts.map +1 -1
- package/dist/workspace/trust/trust-files.js +18 -1
- package/package.json +1 -1
- package/src/bundle-check.test.ts +140 -0
- package/src/bundle-check.ts +352 -0
- package/src/chant-install.test.ts +112 -0
- package/src/chant-install.ts +179 -0
- package/src/ci-commit.test.ts +45 -0
- package/src/ci-commit.ts +38 -4
- package/src/ci-evidence-jobs.ts +67 -0
- package/src/ci-image.test.ts +506 -0
- package/src/ci-image.ts +822 -0
- package/src/ci-login.test.ts +235 -0
- package/src/ci-login.ts +307 -0
- package/src/ci-product.ts +18 -0
- package/src/cli/commands/__fixtures__/source-dir-include/chant.config.json +1 -0
- package/src/cli/commands/__fixtures__/source-dir-include/infra.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-include/scripts/run-on-load.ts +3 -0
- package/src/cli/commands/__fixtures__/source-dir-root/chant.config.json +1 -0
- package/src/cli/commands/__fixtures__/source-dir-root/infra.test.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-root/infra.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-root/scripts/run-on-load.ts +3 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/app.ts +3 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/chant.config.json +1 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/infra/net.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/scripts/run-on-load.ts +3 -0
- package/src/cli/commands/import-index.ts +2 -2
- package/src/cli/handlers/build-source-dir.test.ts +64 -0
- package/src/cli/handlers/build.ts +21 -4
- package/src/cli/handlers/ci-check.ts +56 -3
- package/src/cli/handlers/ci-evidence.ts +162 -0
- package/src/cli/handlers/components.ts +3 -3
- package/src/cli/handlers/dead-guards.ts +37 -0
- package/src/cli/handlers/graph.ts +4 -4
- package/src/cli/handlers/lifecycle.ts +5 -4
- package/src/cli/handlers/local-chant.ts +106 -0
- package/src/cli/handlers/operator.ts +2 -2
- package/src/cli/handlers/search.ts +5 -5
- package/src/cli/main.test.ts +7 -0
- package/src/cli/main.ts +38 -0
- package/src/cli/parse-args.ts +21 -0
- package/src/cli/registry.ts +16 -0
- package/src/components/check-evidence-stage.test.ts +80 -0
- package/src/components/check-hooks.ts +84 -4
- package/src/components/check-local-evidence-stage.test.ts +141 -0
- package/src/components/check-steps.ts +56 -6
- package/src/components/product-pipeline.ts +28 -3
- package/src/components/product-plan.test.ts +87 -0
- package/src/components/product-plan.ts +226 -0
- package/src/components/release-compile.ts +2 -2
- package/src/config.ts +44 -3
- package/src/dead-guards.test.ts +206 -0
- package/src/dead-guards.ts +446 -0
- package/src/discovery/files.ts +5 -3
- package/src/drift-issue-bundle.test.ts +31 -0
- package/src/drift-issue.test.ts +206 -0
- package/src/drift-issue.ts +274 -0
- package/src/fit-note.test.ts +44 -0
- package/src/floor-table.data.ts +180 -0
- package/src/floor-table.ts +77 -0
- package/src/forge-flags.test.ts +110 -0
- package/src/forge-flags.ts +208 -0
- package/src/gate-decision-bundle.test.ts +1 -0
- package/src/lexicon.ts +68 -0
- package/src/lifecycle/gated-op.ts +10 -5
- package/src/local-chant.e2e.test.ts +94 -0
- package/src/local-chant.test.ts +162 -0
- package/src/local-chant.ts +341 -0
- package/src/op/activities/predict-behaviour.ts +2 -2
- package/src/op/op-waves-evidence-spec.ts +24 -0
- package/src/op/op-waves-evidence.test.ts +130 -0
- package/src/op/op-waves-evidence.ts +57 -0
- package/src/op/op-waves-run.ts +25 -1
- package/src/op/op-waves.ts +31 -1
- package/src/op/schedule-overdue.test.ts +85 -0
- package/src/op/schedule-overdue.ts +162 -26
- package/src/plan-summary.ts +40 -0
- package/src/pr-plan-note.ts +34 -0
- package/src/pr-post-plan-note.test.ts +146 -0
- package/src/pr-post.ts +127 -3
- package/src/release-floors.ts +44 -1
- package/src/stage-hooks-bundle.test.ts +1 -0
- package/src/state-migration.test.ts +52 -1
- package/src/state-migration.ts +107 -5
- package/src/workspace/lexicon-outputs.ts +23 -6
- package/src/workspace/reason-codes.test.ts +3 -0
- package/src/workspace/reason-codes.ts +4 -0
- package/src/workspace/ref-gate.schema.json +85 -0
- package/src/workspace/trust/check-evidence-report.ts +106 -0
- package/src/workspace/trust/check-evidence.test.ts +133 -0
- package/src/workspace/trust/check-evidence.ts +257 -0
- package/src/workspace/trust/local-evidence.test.ts +127 -0
- package/src/workspace/trust/local-evidence.ts +266 -0
- package/src/workspace/trust/policy.ts +134 -1
- package/src/workspace/trust/ref-gate-cli.ts +244 -0
- package/src/workspace/trust/ref-gate-fixture.ts +125 -0
- package/src/workspace/trust/ref-gate.e2e.test.ts +76 -0
- package/src/workspace/trust/ref-gate.test.ts +247 -0
- package/src/workspace/trust/ref-gate.ts +538 -0
- package/src/workspace/trust/trust-files.test.ts +16 -0
- package/src/workspace/trust/trust-files.ts +41 -1
|
@@ -25,6 +25,21 @@ import type { RecordSource } from "../record-source.js";
|
|
|
25
25
|
import { type ExcludedSigner, type Signer } from "./trust-files.js";
|
|
26
26
|
import type { PasskeySigner } from "../../lifecycle/gate-webauthn.js";
|
|
27
27
|
export { DEFAULT_SIGNERS_PATH, TRUST_CONFIG_PATH, parseAllowedSigners, renderAllowedSigners, type ExcludedSigner, type Signer, type SignerSet, } from "./trust-files.js";
|
|
28
|
+
/** A check name a ref rule requires (#4867): it is also part of an override's subject. */
|
|
29
|
+
export declare const REF_CHECK_NAME: RegExp;
|
|
30
|
+
/** A ref pattern (#4867): a full ref name, where `*` matches within one `/` segment and `**` matches across them. */
|
|
31
|
+
export declare const REF_PATTERN: RegExp;
|
|
32
|
+
/**
|
|
33
|
+
* Checks local evidence never stands in for (#4868): the ones that gate an
|
|
34
|
+
* apply, a release or a gate. A name is refused when it is one of these, or
|
|
35
|
+
* one of these followed by `:` (a wave's `plan:<wave>`).
|
|
36
|
+
*/
|
|
37
|
+
export declare const LOCAL_EVIDENCE_NEVER: readonly ["plan", "policy", "apply", "drift", "release", "gate", "approval", "confirm"];
|
|
38
|
+
/** Whether local evidence may ever be accepted for `check` (#4868). */
|
|
39
|
+
export declare function localEvidenceAllowedFor(check: string): boolean;
|
|
40
|
+
/** Who signs local evidence (#4868): a person on their machine, or an agent session as itself. */
|
|
41
|
+
export declare const LOCAL_SIGNER_CLASSES: readonly ["person", "agent"];
|
|
42
|
+
export type LocalSignerClass = (typeof LOCAL_SIGNER_CLASSES)[number];
|
|
28
43
|
export declare const trustConfigSchema: z.ZodObject<{
|
|
29
44
|
schema: z.ZodLiteral<1>;
|
|
30
45
|
signers: z.ZodOptional<z.ZodString>;
|
|
@@ -57,10 +72,75 @@ export declare const trustConfigSchema: z.ZodObject<{
|
|
|
57
72
|
}, z.core.$strict>>;
|
|
58
73
|
note: z.ZodOptional<z.ZodString>;
|
|
59
74
|
}, z.core.$strict>>>;
|
|
75
|
+
refs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
76
|
+
ref: z.ZodString;
|
|
77
|
+
checks: z.ZodArray<z.ZodObject<{
|
|
78
|
+
check: z.ZodString;
|
|
79
|
+
action: z.ZodOptional<z.ZodEnum<{
|
|
80
|
+
block: "block";
|
|
81
|
+
warn: "warn";
|
|
82
|
+
}>>;
|
|
83
|
+
command: z.ZodString;
|
|
84
|
+
}, z.core.$strict>>;
|
|
85
|
+
status: z.ZodOptional<z.ZodString>;
|
|
86
|
+
overrides: z.ZodOptional<z.ZodEnum<{
|
|
87
|
+
ledger: "ledger";
|
|
88
|
+
sealed: "sealed";
|
|
89
|
+
}>>;
|
|
90
|
+
}, z.core.$strict>>>;
|
|
91
|
+
local: z.ZodOptional<z.ZodObject<{
|
|
92
|
+
keys: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
93
|
+
principal: z.ZodString;
|
|
94
|
+
class: z.ZodEnum<{
|
|
95
|
+
agent: "agent";
|
|
96
|
+
person: "person";
|
|
97
|
+
}>;
|
|
98
|
+
key: z.ZodString;
|
|
99
|
+
}, z.core.$strict>>>;
|
|
100
|
+
checks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
101
|
+
check: z.ZodString;
|
|
102
|
+
from: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
103
|
+
agent: "agent";
|
|
104
|
+
person: "person";
|
|
105
|
+
}>>>;
|
|
106
|
+
}, z.core.$strict>>>;
|
|
107
|
+
}, z.core.$strict>>;
|
|
60
108
|
}, z.core.$strict>;
|
|
61
109
|
export type TrustConfig = z.infer<typeof trustConfigSchema>;
|
|
62
110
|
/** The role whose holders may change the policy. Without any grant of it, every signer may. */
|
|
63
111
|
export declare const ADMIN_ROLE = "admin";
|
|
112
|
+
/** A ref rule of `.chant/trust.json` (#4867), with `action` filled in. */
|
|
113
|
+
export interface RefRule {
|
|
114
|
+
ref: string;
|
|
115
|
+
checks: Array<{
|
|
116
|
+
check: string;
|
|
117
|
+
action: "block" | "warn";
|
|
118
|
+
command: string;
|
|
119
|
+
}>;
|
|
120
|
+
status?: string;
|
|
121
|
+
overrides?: "ledger" | "sealed";
|
|
122
|
+
}
|
|
123
|
+
/** A key that signs local evidence (#4868): a person's or an agent session's. */
|
|
124
|
+
export interface LocalKey {
|
|
125
|
+
principal: string;
|
|
126
|
+
class: LocalSignerClass;
|
|
127
|
+
/** `ssh-ed25519 <base64>`. */
|
|
128
|
+
key: string;
|
|
129
|
+
}
|
|
130
|
+
/** What `local` in `.chant/trust.json` at base says (#4868), with `from` filled in (default: people only). */
|
|
131
|
+
export interface LocalEvidencePolicy {
|
|
132
|
+
keys: LocalKey[];
|
|
133
|
+
/** Keys left out, and why. */
|
|
134
|
+
excluded: Array<{
|
|
135
|
+
principal: string;
|
|
136
|
+
reason: string;
|
|
137
|
+
}>;
|
|
138
|
+
/** The checks local evidence stands in for, and from whom. */
|
|
139
|
+
checks: Array<{
|
|
140
|
+
check: string;
|
|
141
|
+
from: LocalSignerClass[];
|
|
142
|
+
}>;
|
|
143
|
+
}
|
|
64
144
|
/** A key that signs runner evidence: a service or CI identity. */
|
|
65
145
|
export interface RunnerKey {
|
|
66
146
|
principal: string;
|
|
@@ -94,6 +174,10 @@ export interface TrustPolicy {
|
|
|
94
174
|
passkeys?: PasskeySigner[];
|
|
95
175
|
/** Signers admitted per return (#2552), keyed by return id. They verify that return's commits and seals only. */
|
|
96
176
|
admitted: Record<string, Signer[]>;
|
|
177
|
+
/** The checks a ref update needs evidence for (#4867). Absent on a policy built by hand: none. */
|
|
178
|
+
refs?: RefRule[];
|
|
179
|
+
/** Local evidence (#4868). Absent on a policy built by hand: no key, no check accepts it. */
|
|
180
|
+
local?: LocalEvidencePolicy;
|
|
97
181
|
/**
|
|
98
182
|
* Set on a copy of the policy used for one returned record (#2552): the
|
|
99
183
|
* return it came back in. A seal by a principal the policy does not list
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAgE,KAAK,cAAc,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAC/H,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,SAAS,GACf,MAAM,eAAe,CAAC;AAcvB,eAAO,MAAM,iBAAiB
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/policy.ts"],"names":[],"mappings":"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"}
|
|
@@ -33,6 +33,22 @@ const repoPath = z
|
|
|
33
33
|
.refine((p) => !p.startsWith("/") && !p.includes("\\") && posix.normalize(p) === p && !p.split("/").includes(".."), {
|
|
34
34
|
message: "a path inside the repository, with / separators and no ..",
|
|
35
35
|
});
|
|
36
|
+
/** A check name a ref rule requires (#4867): it is also part of an override's subject. */
|
|
37
|
+
export const REF_CHECK_NAME = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/;
|
|
38
|
+
/** A ref pattern (#4867): a full ref name, where `*` matches within one `/` segment and `**` matches across them. */
|
|
39
|
+
export const REF_PATTERN = /^refs\/[^\s\\]+$/;
|
|
40
|
+
/**
|
|
41
|
+
* Checks local evidence never stands in for (#4868): the ones that gate an
|
|
42
|
+
* apply, a release or a gate. A name is refused when it is one of these, or
|
|
43
|
+
* one of these followed by `:` (a wave's `plan:<wave>`).
|
|
44
|
+
*/
|
|
45
|
+
export const LOCAL_EVIDENCE_NEVER = ["plan", "policy", "apply", "drift", "release", "gate", "approval", "confirm"];
|
|
46
|
+
/** Whether local evidence may ever be accepted for `check` (#4868). */
|
|
47
|
+
export function localEvidenceAllowedFor(check) {
|
|
48
|
+
return !LOCAL_EVIDENCE_NEVER.some((n) => check === n || check.startsWith(`${n}:`));
|
|
49
|
+
}
|
|
50
|
+
/** Who signs local evidence (#4868): a person on their machine, or an agent session as itself. */
|
|
51
|
+
export const LOCAL_SIGNER_CLASSES = ["person", "agent"];
|
|
36
52
|
export const trustConfigSchema = z
|
|
37
53
|
.object({
|
|
38
54
|
schema: z.literal(1),
|
|
@@ -103,6 +119,65 @@ export const trustConfigSchema = z
|
|
|
103
119
|
})
|
|
104
120
|
.strict())
|
|
105
121
|
.optional(),
|
|
122
|
+
/**
|
|
123
|
+
* The checks a ref update must carry evidence for (#4867). Each entry
|
|
124
|
+
* names a ref pattern and the checks a commit pushed there needs current
|
|
125
|
+
* runner evidence of, each with what to do without it (`block` refuses
|
|
126
|
+
* the update, `warn` admits it and says what was missing) and the command
|
|
127
|
+
* that produces it. `status` is the commit status a forge requires, by
|
|
128
|
+
* default `chant/ref-gate`. `overrides` says how an override is judged:
|
|
129
|
+
* `sealed` when the signers file at base exists, else `ledger`.
|
|
130
|
+
*/
|
|
131
|
+
refs: z
|
|
132
|
+
.array(z
|
|
133
|
+
.object({
|
|
134
|
+
ref: z.string().regex(REF_PATTERN, "a full ref name such as refs/heads/main, where * and ** match"),
|
|
135
|
+
checks: z
|
|
136
|
+
.array(z
|
|
137
|
+
.object({
|
|
138
|
+
check: z.string().regex(REF_CHECK_NAME, "a check name: letters, digits, . _ : -"),
|
|
139
|
+
action: z.enum(["block", "warn"]).optional(),
|
|
140
|
+
command: z.string().min(1),
|
|
141
|
+
})
|
|
142
|
+
.strict())
|
|
143
|
+
.min(1),
|
|
144
|
+
status: z.string().min(1).optional(),
|
|
145
|
+
overrides: z.enum(["ledger", "sealed"]).optional(),
|
|
146
|
+
})
|
|
147
|
+
.strict())
|
|
148
|
+
.optional(),
|
|
149
|
+
/**
|
|
150
|
+
* Local evidence (#4868): keys that sign on a developer's machine, for a
|
|
151
|
+
* person or an agent session, and the checks whose CI run such evidence
|
|
152
|
+
* stands in for. Off for every check not named in `checks`, and never
|
|
153
|
+
* for the checks {@link LOCAL_EVIDENCE_NEVER} names. A local key is
|
|
154
|
+
* never a runner key: local evidence never counts as runner evidence.
|
|
155
|
+
*/
|
|
156
|
+
local: z
|
|
157
|
+
.object({
|
|
158
|
+
keys: z
|
|
159
|
+
.array(z
|
|
160
|
+
.object({
|
|
161
|
+
principal: z.string().min(1),
|
|
162
|
+
class: z.enum(LOCAL_SIGNER_CLASSES),
|
|
163
|
+
key: z.string().regex(/^ssh-ed25519 [A-Za-z0-9+/]+={0,2}$/, "an ssh-ed25519 public key, with no comment"),
|
|
164
|
+
})
|
|
165
|
+
.strict())
|
|
166
|
+
.optional(),
|
|
167
|
+
checks: z
|
|
168
|
+
.array(z
|
|
169
|
+
.object({
|
|
170
|
+
check: z
|
|
171
|
+
.string()
|
|
172
|
+
.regex(REF_CHECK_NAME, "a check name: letters, digits, . _ : -")
|
|
173
|
+
.refine(localEvidenceAllowedFor, { message: `local evidence never stands in for ${LOCAL_EVIDENCE_NEVER.join(", ")} (or <name>:<wave>)` }),
|
|
174
|
+
from: z.array(z.enum(LOCAL_SIGNER_CLASSES)).min(1).optional(),
|
|
175
|
+
})
|
|
176
|
+
.strict())
|
|
177
|
+
.optional(),
|
|
178
|
+
})
|
|
179
|
+
.strict()
|
|
180
|
+
.optional(),
|
|
106
181
|
})
|
|
107
182
|
.strict();
|
|
108
183
|
/** The role whose holders may change the policy. Without any grant of it, every signer may. */
|
|
@@ -121,7 +196,7 @@ export function policyWriters(policy) {
|
|
|
121
196
|
}
|
|
122
197
|
/** A policy with nothing in it: attestation off. */
|
|
123
198
|
export function emptyPolicy(base, problems = []) {
|
|
124
|
-
return { base, signersPath: DEFAULT_SIGNERS_PATH, active: false, signers: [], excluded: [], roles: {}, adopted: [], runners: [], excludedRunners: [], passkeys: [], admitted: {}, problems };
|
|
199
|
+
return { base, signersPath: DEFAULT_SIGNERS_PATH, active: false, signers: [], excluded: [], roles: {}, adopted: [], runners: [], excludedRunners: [], passkeys: [], admitted: {}, refs: [], local: { keys: [], excluded: [], checks: [] }, problems };
|
|
125
200
|
}
|
|
126
201
|
/**
|
|
127
202
|
* Read the policy through `source`, which must read the base revision.
|
|
@@ -179,9 +254,27 @@ export function readTrustPolicy(source, base) {
|
|
|
179
254
|
excludedRunners,
|
|
180
255
|
passkeys: config.passkeys ?? [],
|
|
181
256
|
admitted: admittedOf(config),
|
|
257
|
+
refs: (config.refs ?? []).map((r) => ({ ...r, checks: r.checks.map((c) => ({ ...c, action: c.action ?? "block" })) })),
|
|
258
|
+
local: localOf(config, runners),
|
|
182
259
|
problems: [],
|
|
183
260
|
};
|
|
184
261
|
}
|
|
262
|
+
/** The local evidence policy (#4868): a key a runner entry also holds is left out, so one key never speaks as both. */
|
|
263
|
+
function localOf(config, runners) {
|
|
264
|
+
const runnerKeys = new Set([...runners.map((r) => r.key), ...(config.runners ?? []).map((r) => r.key)]);
|
|
265
|
+
const all = config.local?.keys ?? [];
|
|
266
|
+
const keys = [];
|
|
267
|
+
const excluded = [];
|
|
268
|
+
for (const k of all) {
|
|
269
|
+
if (runnerKeys.has(k.key))
|
|
270
|
+
excluded.push({ principal: k.principal, reason: "a runner entry has this key; local evidence is signed by a person's or an agent's key, never a runner's" });
|
|
271
|
+
else if (all.filter((o) => o.key === k.key || o.principal === k.principal).length > 1)
|
|
272
|
+
excluded.push({ principal: k.principal, reason: "another local key has the same key or principal" });
|
|
273
|
+
else
|
|
274
|
+
keys.push(k);
|
|
275
|
+
}
|
|
276
|
+
return { keys, excluded, checks: (config.local?.checks ?? []).map((c) => ({ check: c.check, from: c.from ?? ["person"] })) };
|
|
277
|
+
}
|
|
185
278
|
/** The admitted signers, by return id. Two entries for one return add up. */
|
|
186
279
|
function admittedOf(config) {
|
|
187
280
|
const out = {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant workspace ref-gate` (#4867): refuse a ref update that lacks the
|
|
3
|
+
* evidence the policy at base requires. See ./ref-gate.ts.
|
|
4
|
+
*
|
|
5
|
+
* - `pre-receive` and `pre-push` are what the hooks `install` writes run;
|
|
6
|
+
* they read git's hook input on standard input.
|
|
7
|
+
* - `check --ref <ref>` decides one update from a checkout, and records the
|
|
8
|
+
* request for an override of each blocked check, as `pre-push` does.
|
|
9
|
+
* - `status --ref <ref>` decides the update a merge would make and sets the
|
|
10
|
+
* commit status the forge requires, so the forge refuses the merge.
|
|
11
|
+
* - `attach --envelope <file>` attaches runner evidence to a commit.
|
|
12
|
+
* - `install --hook pre-receive|pre-push` writes the hook.
|
|
13
|
+
*
|
|
14
|
+
* With `--json` each prints the `ref-gate.schema.json` document.
|
|
15
|
+
*/
|
|
16
|
+
import type { CommandContext } from "../../cli/registry.js";
|
|
17
|
+
import { type RefDecision } from "./ref-gate.js";
|
|
18
|
+
export declare const REF_GATE_CONTRACT_VERSION = 1;
|
|
19
|
+
export declare const REF_GATE_OUTPUT_SCHEMA_ID = "https://intentius.io/chant/schemas/workspace/ref-gate/v1/ref-gate.schema.json";
|
|
20
|
+
/** The line a hook chant writes carries, so `install` knows it may replace it. */
|
|
21
|
+
export declare const REF_GATE_HOOK_MARK = "# chant ref gate (#4867)";
|
|
22
|
+
export declare function runWorkspaceRefGate(ctx: CommandContext): Promise<number>;
|
|
23
|
+
/** The commit status a forge requires for `d`'s ref: `success` when it is admitted, `failure` naming the missing checks when not. */
|
|
24
|
+
export declare function postRefGateStatus(forge: {
|
|
25
|
+
setStatus(sha: string, status: {
|
|
26
|
+
context: string;
|
|
27
|
+
state: "success" | "failure";
|
|
28
|
+
description: string;
|
|
29
|
+
}): Promise<void>;
|
|
30
|
+
}, d: RefDecision): Promise<void>;
|
|
31
|
+
/** The hook script: it runs `chant` (or `command`) with the hook's arguments and input. */
|
|
32
|
+
export declare function refGateHook(hook: "pre-receive" | "pre-push", command?: string): string;
|
|
33
|
+
//# sourceMappingURL=ref-gate-cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref-gate-cli.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/ref-gate-cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAYL,KAAK,WAAW,EAGjB,MAAM,YAAY,CAAC;AAIpB,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAC3C,eAAO,MAAM,yBAAyB,kFAAkF,CAAC;AACzH,kFAAkF;AAClF,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAyF7D,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAuE9E;AAED,qIAAqI;AACrI,wBAAsB,iBAAiB,CAAC,KAAK,EAAE;IAAE,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAUvM;AAED,2FAA2F;AAC3F,wBAAgB,WAAW,CAAC,IAAI,EAAE,aAAa,GAAG,UAAU,EAAE,OAAO,SAAU,GAAG,MAAM,CAEvF"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant workspace ref-gate` (#4867): refuse a ref update that lacks the
|
|
3
|
+
* evidence the policy at base requires. See ./ref-gate.ts.
|
|
4
|
+
*
|
|
5
|
+
* - `pre-receive` and `pre-push` are what the hooks `install` writes run;
|
|
6
|
+
* they read git's hook input on standard input.
|
|
7
|
+
* - `check --ref <ref>` decides one update from a checkout, and records the
|
|
8
|
+
* request for an override of each blocked check, as `pre-push` does.
|
|
9
|
+
* - `status --ref <ref>` decides the update a merge would make and sets the
|
|
10
|
+
* commit status the forge requires, so the forge refuses the merge.
|
|
11
|
+
* - `attach --envelope <file>` attaches runner evidence to a commit.
|
|
12
|
+
* - `install --hook pre-receive|pre-push` writes the hook.
|
|
13
|
+
*
|
|
14
|
+
* With `--json` each prints the `ref-gate.schema.json` document.
|
|
15
|
+
*/
|
|
16
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
import { formatError, formatSuccess } from "../../cli/format.js";
|
|
19
|
+
import { readerVersion } from "../declaration.js";
|
|
20
|
+
import { appendRefGateLedger, attachEvidence, commitOf, decideRefUpdate, describeDecision, readRefGateLedger, refGateLedgerPath, RefUpdateInputError, runPrePush, runPreReceive, spentOverrides, } from "./ref-gate.js";
|
|
21
|
+
import { resolveBase } from "./provenance.js";
|
|
22
|
+
import { spawnSync } from "node:child_process";
|
|
23
|
+
export const REF_GATE_CONTRACT_VERSION = 1;
|
|
24
|
+
export const REF_GATE_OUTPUT_SCHEMA_ID = "https://intentius.io/chant/schemas/workspace/ref-gate/v1/ref-gate.schema.json";
|
|
25
|
+
/** The line a hook chant writes carries, so `install` knows it may replace it. */
|
|
26
|
+
export const REF_GATE_HOOK_MARK = "# chant ref gate (#4867)";
|
|
27
|
+
/** How long a recorded request for an override stands. */
|
|
28
|
+
const OVERRIDE_REQUEST_HOURS = 72;
|
|
29
|
+
const USAGE = "chant workspace ref-gate check --ref <ref> [--at <rev>] [--base <rev>] [--dry-run] [--ledger <file>] [--json]\n" +
|
|
30
|
+
" chant workspace ref-gate status --ref <ref> [--at <rev>] [--base <rev>] [--dry-run] [--ledger <file>] [--json]\n" +
|
|
31
|
+
" chant workspace ref-gate pre-receive|pre-push [--ledger <file>] [--dry-run] [--json] (git hook input on stdin)\n" +
|
|
32
|
+
" chant workspace ref-gate attach --envelope <file> [--at <rev>]\n" +
|
|
33
|
+
" chant workspace ref-gate install --hook pre-receive|pre-push [--git-dir <dir>] [--chant <command>]";
|
|
34
|
+
function head() {
|
|
35
|
+
return { $schema: REF_GATE_OUTPUT_SCHEMA_ID, contract: REF_GATE_CONTRACT_VERSION, chant: readerVersion() };
|
|
36
|
+
}
|
|
37
|
+
function fail(json, code, message) {
|
|
38
|
+
if (json)
|
|
39
|
+
console.log(JSON.stringify({ ...head(), error: { code, message } }, null, 2));
|
|
40
|
+
else
|
|
41
|
+
console.error(formatError({ message: `${message} (${code})` }));
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
function usage(message) {
|
|
45
|
+
console.error(formatError({ message, hint: USAGE }));
|
|
46
|
+
return 1;
|
|
47
|
+
}
|
|
48
|
+
/** The git directory of the current directory, bare or not, and the work tree root when there is one. */
|
|
49
|
+
function repoHere() {
|
|
50
|
+
const r = spawnSync("git", ["rev-parse", "--is-bare-repository", "--show-toplevel"], { encoding: "utf-8" });
|
|
51
|
+
if (r.status !== 0) {
|
|
52
|
+
const g = spawnSync("git", ["rev-parse", "--absolute-git-dir"], { encoding: "utf-8" });
|
|
53
|
+
return g.status === 0 ? { repo: g.stdout.trim(), bare: true } : null;
|
|
54
|
+
}
|
|
55
|
+
const [bare, top] = r.stdout.trim().split("\n");
|
|
56
|
+
if (bare === "true" || !top) {
|
|
57
|
+
const g = spawnSync("git", ["rev-parse", "--absolute-git-dir"], { encoding: "utf-8" });
|
|
58
|
+
return { repo: g.stdout.trim(), bare: true };
|
|
59
|
+
}
|
|
60
|
+
return { repo: top, bare: false };
|
|
61
|
+
}
|
|
62
|
+
function print(json, decisions, ledger, stream) {
|
|
63
|
+
const ok = decisions.every((d) => d.decision === "admit");
|
|
64
|
+
if (json) {
|
|
65
|
+
console.log(JSON.stringify({ ...head(), ok, ...(ledger ? { ledger } : {}), decisions }, null, 2));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
for (const d of decisions) {
|
|
69
|
+
if (d.status === null && d.checks.length === 0 && !d.error)
|
|
70
|
+
continue;
|
|
71
|
+
const text = describeDecision(d).join("\n");
|
|
72
|
+
if (stream === "err" || d.decision === "refuse")
|
|
73
|
+
console.error(text);
|
|
74
|
+
else
|
|
75
|
+
console.log(text);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Record the request for an override of each blocked check, unless one
|
|
80
|
+
* stands, so a person can answer it with `chant approve policy-override`.
|
|
81
|
+
* Needs a checkout with `chant/lifecycle`; a failure to record is said and
|
|
82
|
+
* does not change the decision.
|
|
83
|
+
*/
|
|
84
|
+
async function recordRequests(repo, decisions, now) {
|
|
85
|
+
const blocked = decisions.flatMap((d) => d.checks.filter((c) => c.action === "block" && (c.status === "missing" || c.status === "stale")).map((c) => ({ d, c })));
|
|
86
|
+
if (blocked.length === 0)
|
|
87
|
+
return;
|
|
88
|
+
const { readOverrideLedger, recordOverrideDenial } = await import("../../lifecycle/override-ledger.js");
|
|
89
|
+
const { recordedDenials } = await import("../../override-gate.js");
|
|
90
|
+
try {
|
|
91
|
+
const standing = recordedDenials((await readOverrideLedger({ cwd: repo })).pending);
|
|
92
|
+
for (const { d, c } of blocked) {
|
|
93
|
+
const s = standing.find((x) => x.gate === c.subject);
|
|
94
|
+
if (s && Date.parse(s.expiresAt) > Date.parse(now) && s.plan === d.new)
|
|
95
|
+
continue;
|
|
96
|
+
await recordOverrideDenial({
|
|
97
|
+
subject: c.subject,
|
|
98
|
+
planDigest: d.new,
|
|
99
|
+
rules: [c.check],
|
|
100
|
+
timestamp: now,
|
|
101
|
+
expiresAt: new Date(Date.parse(now) + OVERRIDE_REQUEST_HOURS * 3600000).toISOString(),
|
|
102
|
+
description: `update of ${d.ref} to ${d.new.slice(0, 12)}, which has no current evidence for ${c.check}`,
|
|
103
|
+
}, { cwd: repo });
|
|
104
|
+
}
|
|
105
|
+
console.error(`chant ref gate: the request for an override of ${blocked.map((b) => b.c.subject).join(", ")} is recorded on chant/lifecycle; push chant/lifecycle with the override.`);
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
console.error(`chant ref gate: could not record the request for an override: ${err instanceof Error ? err.message : String(err)}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export async function runWorkspaceRefGate(ctx) {
|
|
112
|
+
const { args } = ctx;
|
|
113
|
+
const sub = args.extraPositional;
|
|
114
|
+
const subs = ["check", "status", "pre-receive", "pre-push", "attach", "install"];
|
|
115
|
+
if (!sub || !subs.includes(sub))
|
|
116
|
+
return usage(sub ? `Unknown ref-gate subcommand: ${sub}` : `chant workspace ref-gate needs one of ${subs.join(", ")}`);
|
|
117
|
+
const here = repoHere();
|
|
118
|
+
if (!here)
|
|
119
|
+
return fail(args.json, "not-a-git-repository", "the ref gate judges git ref updates, and this directory is not in a git repository");
|
|
120
|
+
const now = new Date().toISOString();
|
|
121
|
+
if (sub === "install")
|
|
122
|
+
return install(here.repo, args.hook, args.gitDir, args.ciChant);
|
|
123
|
+
if (sub === "attach") {
|
|
124
|
+
if (!args.envelope)
|
|
125
|
+
return usage("--envelope <file> is required");
|
|
126
|
+
const commit = commitOf(here.repo, args.at ?? "HEAD");
|
|
127
|
+
if (!commit)
|
|
128
|
+
return fail(args.json, "revision-unknown", `--at ${args.at ?? "HEAD"} names no commit`);
|
|
129
|
+
let envelope;
|
|
130
|
+
try {
|
|
131
|
+
envelope = JSON.parse(readFileSync(args.envelope, "utf-8"));
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
return usage(`--envelope ${args.envelope} could not be read as JSON: ${err instanceof Error ? err.message : String(err)}`);
|
|
135
|
+
}
|
|
136
|
+
attachEvidence(here.repo, commit, envelope);
|
|
137
|
+
console.error(formatSuccess(`attached the evidence to ${commit.slice(0, 8)}; push refs/notes/chant/evidence with the ref`));
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
if (sub === "pre-receive" || sub === "pre-push") {
|
|
141
|
+
const stdin = readFileSync(0, "utf-8");
|
|
142
|
+
try {
|
|
143
|
+
if (sub === "pre-receive") {
|
|
144
|
+
const r = runPreReceive(here.repo, stdin, { ...(args.ledger ? { ledger: args.ledger } : {}), now });
|
|
145
|
+
print(args.json, r.decisions, r.ledger, "err");
|
|
146
|
+
return r.ok ? 0 : 1;
|
|
147
|
+
}
|
|
148
|
+
const r = runPrePush(here.repo, stdin, { ...(args.ledger ? { ledger: args.ledger } : {}), now, base: (repo) => resolveBase(repo).commit });
|
|
149
|
+
print(args.json, r.decisions, r.ledger, "err");
|
|
150
|
+
if (!r.ok && !args.dryRun && !here.bare)
|
|
151
|
+
await recordRequests(here.repo, r.decisions, now);
|
|
152
|
+
return r.ok ? 0 : 1;
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
if (err instanceof RefUpdateInputError)
|
|
156
|
+
return fail(args.json, "ref-update-invalid", err.message);
|
|
157
|
+
throw err;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// check and status: one update, from a checkout or a CI job.
|
|
161
|
+
if (!args.ref || !args.ref.startsWith("refs/"))
|
|
162
|
+
return usage("--ref <ref> is required, as a full ref name such as refs/heads/main");
|
|
163
|
+
const at = commitOf(here.repo, args.at ?? "HEAD");
|
|
164
|
+
if (!at)
|
|
165
|
+
return fail(args.json, "revision-unknown", `--at ${args.at ?? "HEAD"} names no commit`);
|
|
166
|
+
const resolved = resolveBase(here.repo, args.base);
|
|
167
|
+
if (args.base !== undefined && !resolved.commit)
|
|
168
|
+
return fail(args.json, "revision-unknown", resolved.problem ?? `--base ${args.base} names no commit`);
|
|
169
|
+
const site = sub === "status" ? "status" : "check";
|
|
170
|
+
const ledger = args.ledger ?? refGateLedgerPath(here.repo);
|
|
171
|
+
const spent = spentOverrides(readRefGateLedger(ledger));
|
|
172
|
+
const d = decideRefUpdate({ repo: here.repo, update: { ref: args.ref, old: resolved.commit, new: at }, base: resolved.commit, spent, now });
|
|
173
|
+
if (!args.dryRun)
|
|
174
|
+
appendRefGateLedger(ledger, [{ ...d, version: 1, kind: "ref-update", site, timestamp: now }]);
|
|
175
|
+
print(args.json, [d], args.dryRun ? undefined : ledger, "out");
|
|
176
|
+
if (site === "check" && d.decision === "refuse" && !args.dryRun && !here.bare)
|
|
177
|
+
await recordRequests(here.repo, [d], now);
|
|
178
|
+
if (site === "status" && d.status !== null) {
|
|
179
|
+
if (args.dryRun) {
|
|
180
|
+
console.error(`chant ref gate: would set ${d.status} to ${d.decision === "admit" ? "success" : "failure"} on ${at.slice(0, 8)}`);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
const { detectForge, forgeFromEnv } = await import("../../pr-forge.js");
|
|
184
|
+
const kind = detectForge();
|
|
185
|
+
if (!kind) {
|
|
186
|
+
console.error(formatError({ message: `no forge detected, so ${d.status} was not set`, hint: "run it in a GitHub, GitLab or Forgejo job, or pass --dry-run" }));
|
|
187
|
+
return 1;
|
|
188
|
+
}
|
|
189
|
+
await postRefGateStatus(forgeFromEnv(kind), d);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return d.decision === "admit" ? 0 : 1;
|
|
193
|
+
}
|
|
194
|
+
/** The commit status a forge requires for `d`'s ref: `success` when it is admitted, `failure` naming the missing checks when not. */
|
|
195
|
+
export async function postRefGateStatus(forge, d) {
|
|
196
|
+
if (d.status === null || d.new === null)
|
|
197
|
+
return;
|
|
198
|
+
const missing = d.checks.filter((c) => c.action === "block" && (c.status === "missing" || c.status === "stale"));
|
|
199
|
+
const overridden = d.checks.filter((c) => c.status === "overridden").map((c) => c.check);
|
|
200
|
+
const description = d.error
|
|
201
|
+
? `refused: ${d.error.code}`
|
|
202
|
+
: missing.length > 0
|
|
203
|
+
? `missing evidence: ${missing.map((c) => `${c.check} (run ${c.command})`).join(", ")}`
|
|
204
|
+
: `evidence current${overridden.length ? `; overridden: ${overridden.join(", ")}` : ""}`;
|
|
205
|
+
await forge.setStatus(d.new, { context: d.status, state: d.decision === "admit" ? "success" : "failure", description });
|
|
206
|
+
}
|
|
207
|
+
/** The hook script: it runs `chant` (or `command`) with the hook's arguments and input. */
|
|
208
|
+
export function refGateHook(hook, command = "chant") {
|
|
209
|
+
return `#!/bin/sh\n${REF_GATE_HOOK_MARK}\nexec ${command} workspace ref-gate ${hook} "$@"\n`;
|
|
210
|
+
}
|
|
211
|
+
function install(repo, hook, gitDir, command) {
|
|
212
|
+
if (hook !== "pre-receive" && hook !== "pre-push")
|
|
213
|
+
return usage("--hook pre-receive (on the remote) or --hook pre-push (in a checkout) is required");
|
|
214
|
+
let dir = gitDir;
|
|
215
|
+
if (!dir) {
|
|
216
|
+
const r = spawnSync("git", ["rev-parse", "--git-path", "hooks"], { cwd: repo, encoding: "utf-8" });
|
|
217
|
+
dir = r.status === 0 ? join(repo, r.stdout.trim()) : join(repo, "hooks");
|
|
218
|
+
if (r.status === 0 && r.stdout.trim().startsWith("/"))
|
|
219
|
+
dir = r.stdout.trim();
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
dir = join(dir, "hooks");
|
|
223
|
+
}
|
|
224
|
+
const path = join(dir, hook);
|
|
225
|
+
if (existsSync(path) && !readFileSync(path, "utf-8").includes(REF_GATE_HOOK_MARK)) {
|
|
226
|
+
console.error(formatError({ message: `${path} exists and is not chant's ref gate hook; it was left as it is`, hint: `call ${command ?? "chant"} workspace ref-gate ${hook} from it` }));
|
|
227
|
+
return 1;
|
|
228
|
+
}
|
|
229
|
+
mkdirSync(dir, { recursive: true });
|
|
230
|
+
writeFileSync(path, refGateHook(hook, command));
|
|
231
|
+
chmodSync(path, 0o755);
|
|
232
|
+
console.error(formatSuccess(`wrote ${path}`));
|
|
233
|
+
return 0;
|
|
234
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test support for the ref gate (#4867): a checkout and a bare remote, a
|
|
3
|
+
* runner key, fake runner evidence signed with it, and override lines on
|
|
4
|
+
* `chant/lifecycle`. Isolated from the user's git config. The temporary
|
|
5
|
+
* directories are left in the system's temp directory.
|
|
6
|
+
*/
|
|
7
|
+
export interface RunnerKeyPair {
|
|
8
|
+
pem: string;
|
|
9
|
+
pub: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function runnerKey(): RunnerKeyPair;
|
|
12
|
+
export declare const RUNNER = "ci@example.test";
|
|
13
|
+
export declare class GateRepos {
|
|
14
|
+
readonly root: string;
|
|
15
|
+
readonly work: string;
|
|
16
|
+
readonly origin: string;
|
|
17
|
+
readonly home: string;
|
|
18
|
+
constructor(label: string);
|
|
19
|
+
env(): NodeJS.ProcessEnv;
|
|
20
|
+
run(cwd: string, args: string[], input?: string): string;
|
|
21
|
+
git(args: string[], input?: string): string;
|
|
22
|
+
write(path: string, text: string): void;
|
|
23
|
+
commit(message: string): string;
|
|
24
|
+
/** Push `refspecs` to the bare remote with no hook in the way, and return git's output. */
|
|
25
|
+
push(...refspecs: string[]): string;
|
|
26
|
+
/** Sign evidence for `check` at `at` over `paths`, with `key`, and attach it to `to` (default `at`). */
|
|
27
|
+
sign(key: RunnerKeyPair, check: string, at: string, paths: string[], to?: string): unknown;
|
|
28
|
+
notesTip(): string;
|
|
29
|
+
/** Write `chant/lifecycle` holding a request for an override of `check` on `commit` and `by`'s override of it. */
|
|
30
|
+
override(commit: string, check: string, by: string, reason: string, at?: string): string;
|
|
31
|
+
}
|
|
32
|
+
/** `.chant/trust.json` with one runner and a ref rule for `refs/heads/main` and `refs/heads/release/*`. */
|
|
33
|
+
export declare function trustJson(runner: RunnerKeyPair, checks: Array<{
|
|
34
|
+
check: string;
|
|
35
|
+
action?: "block" | "warn";
|
|
36
|
+
command: string;
|
|
37
|
+
}>, extra?: Record<string, unknown>): string;
|
|
38
|
+
//# sourceMappingURL=ref-gate-fixture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref-gate-fixture.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/ref-gate-fixture.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAED,wBAAgB,SAAS,IAAI,aAAa,CAIzC;AAED,eAAO,MAAM,MAAM,oBAAoB,CAAC;AAExC,qBAAa,SAAS;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YAAY,KAAK,EAAE,MAAM,EASxB;IAED,GAAG,IAAI,MAAM,CAAC,UAAU,CAWvB;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAEvD;IAED,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAE1C;IAED,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAGtC;IAED,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAI9B;IAED,2FAA2F;IAC3F,IAAI,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAElC;IAED,wGAAwG;IACxG,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,SAAK,GAAG,OAAO,CAMrF;IAED,QAAQ,IAAI,MAAM,CAEjB;IAED,kHAAkH;IAClH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,SAA6B,GAAG,MAAM,CAW3G;CACF;AAED,2GAA2G;AAC3G,wBAAgB,SAAS,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,MAAM,CAW1K"}
|