@intentius/chant 0.124.8 → 0.124.9
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/op/gate.d.ts +16 -1
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/op-waves-notify.d.ts +2 -1
- package/dist/op/op-waves-notify.d.ts.map +1 -1
- package/dist/op/op-waves-run.d.ts +57 -7
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves.d.ts +42 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/workspace/identity.d.ts +3 -2
- package/dist/workspace/identity.d.ts.map +1 -1
- package/dist/workspace/write-scope.d.ts +3 -2
- package/dist/workspace/write-scope.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/pr-run.ts +1 -1
- package/src/lifecycle/converge-ledger.ts +1 -1
- package/src/lifecycle/gate-ledger.test.ts +37 -0
- package/src/lifecycle/gate-ledger.ts +1 -1
- package/src/lifecycle/git.ts +1 -1
- package/src/lifecycle/override-ledger.ts +1 -1
- package/src/lifecycle/run-ledger.ts +1 -1
- package/src/lifecycle/work-lease.ts +1 -1
- package/src/op/gate-review.test.ts +53 -1
- package/src/op/gate.ts +31 -9
- package/src/op/op-waves-notify.ts +13 -1
- package/src/op/op-waves-point.test.ts +254 -0
- package/src/op/op-waves-run.ts +231 -40
- package/src/op/op-waves.test.ts +95 -2
- package/src/op/op-waves.ts +68 -0
- package/src/workspace/identity.test.ts +4 -1
- package/src/workspace/identity.ts +4 -3
- package/src/workspace/write-scope.ts +4 -3
package/src/op/op-waves.ts
CHANGED
|
@@ -53,9 +53,21 @@
|
|
|
53
53
|
* apply; like the policy they are read from the spec at the base commit, and
|
|
54
54
|
* one whose `onFailure` is `approve` holds the wave for an approval whatever
|
|
55
55
|
* its policy says.
|
|
56
|
+
*
|
|
57
|
+
* ## A gate that asks a decision point (#3836)
|
|
58
|
+
*
|
|
59
|
+
* With `point` (on the spec, or on a wave, whose own wins), read at base like
|
|
60
|
+
* the policy, a wave that needs an approval asks that workspace decision
|
|
61
|
+
* point instead of reading the ledger for a `chant approve`, the way an Op
|
|
62
|
+
* gate with a `point` does (#3170): `gate.planDigest` is the wave's set
|
|
63
|
+
* digest, so each plan is its own question. An open question waits (exit 3,
|
|
64
|
+
* the pending fact cites it), an answer the gate passes on records the
|
|
65
|
+
* resolution that cites it and the wave goes on, and any other answer refuses
|
|
66
|
+
* the wave (exit 8). See `./op-waves-run.ts`.
|
|
56
67
|
*/
|
|
57
68
|
|
|
58
69
|
import type { OpEnvironment, OpSetupStep } from "../lexicon";
|
|
70
|
+
import { gatePointProblems, type GatePoint } from "./gate-point";
|
|
59
71
|
import { notifyConfigProblem, type NotifyConfig } from "../notify";
|
|
60
72
|
|
|
61
73
|
/**
|
|
@@ -92,6 +104,40 @@ export const GATE_APPROVAL_SOURCES: readonly GateApprovalSource[] = ["ledger", "
|
|
|
92
104
|
/** What a failing hook does: fail the wave, or hold it for an approval of its set digest. */
|
|
93
105
|
export type OpWaveHookFailure = "fail" | "approve";
|
|
94
106
|
|
|
107
|
+
/**
|
|
108
|
+
* The decision point a wave's gate asks (#3836): a point's name, or `{ name,
|
|
109
|
+
* inputs?, pass?, store?, timeout? }` as an Op gate's `point` takes, plus the
|
|
110
|
+
* pending fact's `timeout` (default 48h). The point must declare the input
|
|
111
|
+
* `gate.planDigest`, which is the wave's set digest.
|
|
112
|
+
*/
|
|
113
|
+
export type OpWavePoint = GatePoint & {
|
|
114
|
+
/** How long the pending fact that cites an open question stands, such as `"48h"`. */
|
|
115
|
+
timeout?: string;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/** A wave's or a spec's `point` as an {@link OpWavePoint}, or undefined when it names none. */
|
|
119
|
+
export function opWavePointOf(point: string | OpWavePoint | undefined): OpWavePoint | undefined {
|
|
120
|
+
if (point === undefined) return undefined;
|
|
121
|
+
return typeof point === "string" ? { name: point } : point;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** What is wrong with a wave's `point`, empty when nothing is (#3836). */
|
|
125
|
+
export function opWavePointProblems(point: unknown): string[] {
|
|
126
|
+
if (point !== null && typeof point === "object" && !Array.isArray(point) && "timeout" in point) {
|
|
127
|
+
const { timeout, ...rest } = point as Record<string, unknown>;
|
|
128
|
+
const problems = gatePointProblems(rest);
|
|
129
|
+
if (typeof timeout !== "string" || !/^(\d+(ms|s|m|h|d))+$/.test(timeout)) problems.push("`point.timeout` is a duration such as \"48h\"");
|
|
130
|
+
return problems;
|
|
131
|
+
}
|
|
132
|
+
return gatePointProblems(point);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The point wave `name`'s gate asks (#3836): the wave's own, else the spec's, else none. */
|
|
136
|
+
export function opWavePointAt(spec: Pick<OpWavesSpec, "point" | "waves">, name: string): OpWavePoint | undefined {
|
|
137
|
+
const wave = spec.waves.find((w) => w.name === name);
|
|
138
|
+
return opWavePointOf(wave?.point ?? spec.point);
|
|
139
|
+
}
|
|
140
|
+
|
|
95
141
|
export const OP_WAVE_HOOK_FAILURES: readonly OpWaveHookFailure[] = ["fail", "approve"];
|
|
96
142
|
|
|
97
143
|
/** One stage hook (#3762): a command run before or after a wave's plan or apply. */
|
|
@@ -181,6 +227,11 @@ export interface OpWave {
|
|
|
181
227
|
* Like `gate`, the runner reads it from the spec file at the base commit.
|
|
182
228
|
*/
|
|
183
229
|
approval?: GateApprovalSource;
|
|
230
|
+
/**
|
|
231
|
+
* The decision point this wave's gate asks (#3836), in place of the spec's.
|
|
232
|
+
* Read at base like `gate`. See {@link OpWavesSpec.point}.
|
|
233
|
+
*/
|
|
234
|
+
point?: string | OpWavePoint;
|
|
184
235
|
/**
|
|
185
236
|
* Split the wave into a deciding job and this many share jobs, each
|
|
186
237
|
* applying a slice of the runs. Default 1: one job plans, decides and
|
|
@@ -266,6 +317,15 @@ export interface OpWavesSpec {
|
|
|
266
317
|
* the rules (`@intentius/chant/override-gate`).
|
|
267
318
|
*/
|
|
268
319
|
override?: OpWavesOverride;
|
|
320
|
+
/**
|
|
321
|
+
* The decision point every wave's gate asks (#3836), unless a wave names its
|
|
322
|
+
* own. Read at the base commit, like the policy: a wave that needs an
|
|
323
|
+
* approval asks the point with `gate.planDigest` set to its set digest, and
|
|
324
|
+
* only an answer the point's `pass` names (default yes) for that digest
|
|
325
|
+
* lets it apply. `chant approve` does not pass such a gate, and the wave's
|
|
326
|
+
* `approval` mode does not apply: the point's deciders and quorum decide.
|
|
327
|
+
*/
|
|
328
|
+
point?: string | OpWavePoint;
|
|
269
329
|
waves: OpWave[];
|
|
270
330
|
/**
|
|
271
331
|
* A scheduled job that starts again a wave job whose approval has arrived
|
|
@@ -442,6 +502,10 @@ export function assertOpWavesSpec(spec: OpWavesSpec): void {
|
|
|
442
502
|
if (typeof value !== "string" || value.trim() === "") throw new Error(`${where}: override.overriders must be a path, such as ".chant/overriders".`);
|
|
443
503
|
}
|
|
444
504
|
}
|
|
505
|
+
if (spec.point !== undefined) {
|
|
506
|
+
const problems = opWavePointProblems(spec.point);
|
|
507
|
+
if (problems.length > 0) throw new Error(`${where}: ${problems.join("; ")}.`);
|
|
508
|
+
}
|
|
445
509
|
if (spec.neverOverMcp !== undefined && typeof spec.neverOverMcp !== "boolean") throw new Error(`${where}: neverOverMcp must be true or false.`);
|
|
446
510
|
if (spec.notify !== undefined) {
|
|
447
511
|
const problem = notifyConfigProblem(spec.notify, "notify");
|
|
@@ -461,6 +525,10 @@ export function assertOpWavesSpec(spec: OpWavesSpec): void {
|
|
|
461
525
|
throw new Error(`${where}: wave "${wave.name}" has approval "${wave.approval}"; use ${GATE_APPROVAL_SOURCES.join(", ")}.`);
|
|
462
526
|
}
|
|
463
527
|
assertOpWaveHooks(`${where}, wave "${wave.name}"`, wave.hooks);
|
|
528
|
+
if (wave.point !== undefined) {
|
|
529
|
+
const problems = opWavePointProblems(wave.point);
|
|
530
|
+
if (problems.length > 0) throw new Error(`${where}: wave "${wave.name}": ${problems.join("; ")}.`);
|
|
531
|
+
}
|
|
464
532
|
if (wave.discover !== undefined && typeof wave.discover !== "boolean") throw new Error(`${where}: wave "${wave.name}" has discover ${JSON.stringify(wave.discover)}; use true or false.`);
|
|
465
533
|
if (wave.rest !== undefined && typeof wave.rest !== "boolean") throw new Error(`${where}: wave "${wave.name}" has rest ${JSON.stringify(wave.rest)}; use true or false.`);
|
|
466
534
|
if (wave.discover) {
|
|
@@ -202,7 +202,10 @@ describe.skipIf(!hasSshKeygen)("identity.gates", () => {
|
|
|
202
202
|
|
|
203
203
|
const roster = memoryGateLedgerPort({ pending: [pending], resolutions: [approval("alex")] });
|
|
204
204
|
expect((await evaluateGate(roster, input)).satisfied).toBe(true);
|
|
205
|
-
|
|
205
|
+
const held = await evaluateGate({ ...roster, approvalRule: async () => rule }, input);
|
|
206
|
+
expect(held.satisfied).toBe(false);
|
|
207
|
+
// #3841: the approval the rule refused is named, with why.
|
|
208
|
+
expect(!held.satisfied && held.refused?.map((x) => [x.resolution.resolvedBy, x.reason])).toEqual([["alex", expect.stringMatching(/not signed/)]]);
|
|
206
209
|
const sealed = memoryGateLedgerPort({ pending: [pending], resolutions: [approval("alex"), signed(alice, approval("github:alice"))] });
|
|
207
210
|
const check = await evaluateGate({ ...sealed, approvalRule: async () => rule }, input);
|
|
208
211
|
expect(check.satisfied && check.resolution.resolvedBy).toBe("github:alice");
|
|
@@ -179,8 +179,9 @@ export function gateAdmissionFrom(source: GateRuleSource, gate: string): GateAdm
|
|
|
179
179
|
* The rule for `gate` in the workspace holding `cwd`, read at base (the
|
|
180
180
|
* target branch tip), or null when there is no declaration or it names none.
|
|
181
181
|
* What a run, `chant approve` and `workspace status` ask before counting an
|
|
182
|
-
* approval.
|
|
182
|
+
* approval. `base` names the commit to read at instead, as an op wave reads
|
|
183
|
+
* every rule at its `--base` (#3841).
|
|
183
184
|
*/
|
|
184
|
-
export function gateAdmission(cwd: string, gate: string): GateAdmission | null {
|
|
185
|
-
return gateAdmissionFrom(scopeSource(cwd), gate);
|
|
185
|
+
export function gateAdmission(cwd: string, gate: string, base?: string): GateAdmission | null {
|
|
186
|
+
return gateAdmissionFrom(scopeSource(cwd, base), gate);
|
|
186
187
|
}
|
|
@@ -368,11 +368,12 @@ function readAt(cwd: string, at?: string): { declaration: Declaration; rootOnDis
|
|
|
368
368
|
* The scope for a write from `cwd`: the declaration and the trust policy at
|
|
369
369
|
* the base revision (`origin/HEAD`, `main` or `master`), so a write can't
|
|
370
370
|
* widen its own scope by editing its copy of the declaration. Without a base,
|
|
371
|
-
* or without a declaration at it, the working tree's declaration.
|
|
371
|
+
* or without a declaration at it, the working tree's declaration. `at` names
|
|
372
|
+
* the base instead, as an op wave's `--base` does (#3841).
|
|
372
373
|
*/
|
|
373
|
-
export function scopeSource(cwd: string): ScopeSource {
|
|
374
|
+
export function scopeSource(cwd: string, at?: string): ScopeSource {
|
|
374
375
|
const top = gitRoot(cwd);
|
|
375
|
-
const base = top ? resolveBase(top) : null;
|
|
376
|
+
const base = top ? resolveBase(top, at) : null;
|
|
376
377
|
const policy = top && base ? policyAtBase(top, base) : emptyPolicy(null);
|
|
377
378
|
const withClasses = (read: NonNullable<ReturnType<typeof readAt>>) => {
|
|
378
379
|
const { tree, ...rest } = read;
|