@intentius/chant 0.124.71 → 0.124.73

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.
Files changed (58) hide show
  1. package/dist/ci-commit.d.ts +41 -1
  2. package/dist/ci-commit.d.ts.map +1 -1
  3. package/dist/ci-commit.js +54 -8
  4. package/dist/ci-estate/delivery.d.ts +75 -2
  5. package/dist/ci-estate/delivery.d.ts.map +1 -1
  6. package/dist/ci-estate/delivery.js +129 -0
  7. package/dist/ci-estate.d.ts +3 -1
  8. package/dist/ci-estate.d.ts.map +1 -1
  9. package/dist/ci-estate.js +3 -1
  10. package/dist/ci-product.d.ts +1 -1
  11. package/dist/ci-product.d.ts.map +1 -1
  12. package/dist/ci-product.js +1 -1
  13. package/dist/cli/handlers/commit.d.ts.map +1 -1
  14. package/dist/cli/handlers/commit.js +5 -2
  15. package/dist/cli/handlers/notify-relay.d.ts.map +1 -1
  16. package/dist/cli/handlers/notify-relay.js +22 -2
  17. package/dist/config.d.ts +14 -0
  18. package/dist/config.d.ts.map +1 -1
  19. package/dist/config.js +7 -0
  20. package/dist/lexicon.d.ts +17 -0
  21. package/dist/lexicon.d.ts.map +1 -1
  22. package/dist/lifecycle/publish-forge.d.ts.map +1 -1
  23. package/dist/lifecycle/publish-forge.js +1 -2
  24. package/dist/lifecycle/release-images.d.ts.map +1 -1
  25. package/dist/lifecycle/release-images.js +1 -2
  26. package/dist/notify-relay.d.ts +41 -1
  27. package/dist/notify-relay.d.ts.map +1 -1
  28. package/dist/notify-relay.js +39 -0
  29. package/dist/notify.d.ts +16 -3
  30. package/dist/notify.d.ts.map +1 -1
  31. package/dist/notify.js +16 -10
  32. package/dist/op/activities/activity-contracts.d.ts +4 -4
  33. package/dist/release-floors.d.ts +1 -1
  34. package/dist/release-floors.js +1 -1
  35. package/dist/wave-runtime.mjs +237 -237
  36. package/dist/workspace/release-workflow.d.ts +24 -0
  37. package/dist/workspace/release-workflow.d.ts.map +1 -1
  38. package/dist/workspace/release-workflow.js +61 -8
  39. package/package.json +1 -1
  40. package/src/ci-commit.test.ts +22 -1
  41. package/src/ci-commit.ts +79 -8
  42. package/src/ci-estate/__fixtures__/terragucci-dora.json +1305 -0
  43. package/src/ci-estate/delivery.ts +186 -2
  44. package/src/ci-estate/records-delivery.test.ts +55 -0
  45. package/src/ci-estate.ts +9 -0
  46. package/src/ci-product.ts +1 -0
  47. package/src/cli/handlers/commit.ts +4 -1
  48. package/src/cli/handlers/notify-relay.ts +21 -2
  49. package/src/config.ts +7 -0
  50. package/src/lexicon.ts +16 -0
  51. package/src/lifecycle/publish-forge.ts +1 -2
  52. package/src/lifecycle/release-images.ts +1 -2
  53. package/src/notify-relay.test.ts +55 -1
  54. package/src/notify-relay.ts +48 -1
  55. package/src/notify.ts +25 -12
  56. package/src/release-floors.ts +1 -1
  57. package/src/workspace/release-workflow.test.ts +49 -1
  58. package/src/workspace/release-workflow.ts +91 -7
@@ -107,8 +107,8 @@ export interface Dora {
107
107
  drift_window_seconds: number;
108
108
  /** Whether any apply record was on the ledger. Without one only drift counts. */
109
109
  audit: boolean;
110
- /** Where the numbers came from: always `ledger` here. terragucci's own file has no such field. */
111
- source: "ledger";
110
+ /** `ledger` from {@link buildDelivery}. Absent from {@link buildRecordDelivery}, whose file is terragucci's shape, which has no such field. */
111
+ source?: "ledger";
112
112
  estate: DoraMetrics;
113
113
  projects: DoraProject[];
114
114
  }
@@ -431,3 +431,187 @@ export function deliveryGauges(dora: Dora, words: Pick<CiProductWords, "product"
431
431
  for (const p of dora.projects) of(p.project, p);
432
432
  return out;
433
433
  }
434
+
435
+ // ── from a product's own records (#4612) ────────────────────────────────
436
+
437
+ /**
438
+ * One line of a product's audit trail, as terragucci's reports bucket keeps
439
+ * it (`audit.jsonl`). Three kinds are read: `apply` (an applied or failed
440
+ * wave: `detail.commit`, `detail.roots`, `detail.failed`, and the
441
+ * `detail.approval` entry it applied under), `approval-requested` (a wave
442
+ * reaching its gate) and `approval`. `what` is the gate. Other kinds and
443
+ * results are left alone: a waiting wave is not an apply yet, and a refused
444
+ * one is the gate working.
445
+ */
446
+ export interface DeliveryAuditEntry {
447
+ id: string;
448
+ kind: string;
449
+ project: string;
450
+ at: string;
451
+ what: string;
452
+ digest: string | null;
453
+ result: string;
454
+ detail?: Record<string, unknown>;
455
+ }
456
+
457
+ /**
458
+ * One row of a product's report index. A plan row (`stages.plan`) says when
459
+ * a change was planned, on which pull request, and the set digests its waves
460
+ * bind. A drift row (`stages.drift`) says whether the check found drift and
461
+ * on which roots, when the open drift was first found (`drift_since`), and
462
+ * which drift a clean check cleared (`drift_cleared`).
463
+ */
464
+ export interface DeliveryIndexRow {
465
+ project: string;
466
+ stage: string;
467
+ finished: string;
468
+ commit?: string;
469
+ pull_request?: string;
470
+ wave_digests?: string[];
471
+ changed?: number;
472
+ drifted_roots?: string[];
473
+ drift_since?: string;
474
+ drift_cleared?: { since: string; roots: string[] };
475
+ }
476
+
477
+ /** One project's index rows. A control repo passes one per project it reads. */
478
+ export interface DeliveryRecordSource {
479
+ project: string;
480
+ rows: readonly DeliveryIndexRow[];
481
+ }
482
+
483
+ export interface RecordDeliveryOptions {
484
+ words?: Pick<CiProductWords, "product">;
485
+ now?: Date;
486
+ /** The index's stage names: `tf-plan` and `tf-drift` for terragucci. */
487
+ stages: { plan: string; drift: string };
488
+ }
489
+
490
+ const strings = (v: unknown): string[] => (Array.isArray(v) ? v.filter((x): x is string => typeof x === "string") : []);
491
+
492
+ /** A records apply: the shared {@link Apply} with the gate it passed and the approval it applied under. */
493
+ type RecordApply = Apply & { gate: string; approval?: string };
494
+
495
+ function recordApplies(entries: readonly DeliveryAuditEntry[]): RecordApply[] {
496
+ const seen = new Set<string>();
497
+ const out: RecordApply[] = [];
498
+ for (const e of entries) {
499
+ if (e.kind !== "apply" || (e.result !== "applied" && e.result !== "failed") || seen.has(e.id)) continue;
500
+ seen.add(e.id);
501
+ const d = e.detail ?? {};
502
+ out.push({
503
+ project: e.project,
504
+ at: at(e.at),
505
+ applied: e.result === "applied",
506
+ spec: e.what,
507
+ gate: e.what,
508
+ ...(e.digest !== null ? { digest: e.digest } : {}),
509
+ ...(typeof d.commit === "string" ? { commit: d.commit } : {}),
510
+ roots: strings(d.roots),
511
+ failed: strings(d.failed),
512
+ ...(typeof d.approval === "string" ? { approval: d.approval } : {}),
513
+ });
514
+ }
515
+ return out.sort((a, b) => a.at - b.at);
516
+ }
517
+
518
+ /**
519
+ * The lead time of an applied wave. Its plan is the plan row of the same
520
+ * commit, or the one whose wave digests hold the wave's digest (a pull
521
+ * request's head, planned before the merge commit applied); the change
522
+ * starts at the first plan of that row's pull request.
523
+ */
524
+ function recordLead(a: RecordApply, plans: readonly DeliveryIndexRow[], requests: readonly DeliveryAuditEntry[], approvals: Map<string, DeliveryAuditEntry>): Lead | undefined {
525
+ const before = plans.filter((r) => at(r.finished) <= a.at);
526
+ const matched = before
527
+ .filter((r) => (a.commit !== undefined && r.commit === a.commit) || (a.digest !== undefined && (r.wave_digests ?? []).some((d) => samePlanDigest(d, a.digest!))))
528
+ .sort((x, y) => at(y.finished) - at(x.finished))[0];
529
+ if (!matched) return undefined;
530
+ const pr = matched.pull_request;
531
+ const first = pr ? Math.min(...before.filter((r) => r.pull_request === pr).map((r) => at(r.finished))) : at(matched.finished);
532
+ const asked = requests
533
+ .filter((q) => q.project === a.project && q.what === a.gate && a.digest !== undefined && q.digest !== null && samePlanDigest(q.digest, a.digest) && at(q.at) <= a.at)
534
+ .map((q) => at(q.at))
535
+ .sort((x, y) => x - y)[0];
536
+ const approved = a.approval ? approvals.get(a.approval) : undefined;
537
+ const ok = approved ? Math.min(Math.max(at(approved.at), asked ?? first), a.at) : undefined;
538
+ if (asked === undefined) return { project: a.project, at: a.at, total: secs(first, a.at), before: secs(first, a.at), gate: 0, after: 0 };
539
+ const gateEnd = ok ?? asked;
540
+ return { project: a.project, at: a.at, total: secs(first, a.at), before: secs(first, Math.max(first, asked)), gate: secs(asked, gateEnd), after: secs(gateEnd, a.at) };
541
+ }
542
+
543
+ /**
544
+ * A project's drift incidents from its drift rows, oldest first. A row that
545
+ * found drift opens one at its `drift_since` (or, for a row written before
546
+ * that field, at the open incident or its own time); a clean row names the
547
+ * drift it cleared, since a later check of the same commit replaces the row
548
+ * that found it; a clean row of the old kind closes the open incident.
549
+ */
550
+ export function recordDriftIncidents(drifts: readonly DeliveryIndexRow[]): DriftIncident[] {
551
+ const incidents = new Map<number, DriftIncident>();
552
+ const get = (since: number): DriftIncident => {
553
+ let i = incidents.get(since);
554
+ if (!i) incidents.set(since, (i = { since, roots: new Set() }));
555
+ return i;
556
+ };
557
+ let open: number | undefined;
558
+ for (const r of [...drifts].sort((x, y) => at(x.finished) - at(y.finished))) {
559
+ if ((r.changed ?? 0) > 0) {
560
+ const since = r.drift_since ? at(r.drift_since) : (open ?? at(r.finished));
561
+ for (const x of r.drifted_roots ?? []) get(since).roots.add(x);
562
+ open = since;
563
+ } else if (r.drift_cleared) {
564
+ const i = get(at(r.drift_cleared.since));
565
+ for (const x of r.drift_cleared.roots) i.roots.add(x);
566
+ i.closed = Math.min(i.closed ?? Infinity, at(r.finished));
567
+ if (open === i.since) open = undefined;
568
+ } else if (open !== undefined) {
569
+ const i = get(open);
570
+ i.closed ??= at(r.finished);
571
+ open = undefined;
572
+ }
573
+ }
574
+ return [...incidents.values()].sort((a, b) => a.since - b.since);
575
+ }
576
+
577
+ function recordEventsOf(source: DeliveryRecordSource, entries: readonly DeliveryAuditEntry[], stages: RecordDeliveryOptions["stages"]): Events {
578
+ const mine = entries.filter((e) => e.project === source.project);
579
+ const applies = recordApplies(mine);
580
+ const rows = source.rows.filter((r) => r.project === source.project);
581
+ const plans = rows.filter((r) => r.stage === stages.plan);
582
+ const incidents = recordDriftIncidents(rows.filter((r) => r.stage === stages.drift));
583
+ const requests = mine.filter((e) => e.kind === "approval-requested");
584
+ const approvals = new Map(mine.filter((e) => e.kind === "approval").map((e) => [e.id, e]));
585
+ const leads = applies.filter((a) => a.applied).flatMap((a) => recordLead(a, plans, requests, approvals) ?? []);
586
+ const drifted = driftedApplies(applies, incidents);
587
+ const failures = applies.filter((a) => !a.applied || drifted.has(a)).map((a) => ({ project: a.project, at: a.at }));
588
+ const ar = applyRestores(applies);
589
+ const dr = incidents.filter((i) => i.closed !== undefined).map((i) => ({ project: source.project, at: i.closed!, seconds: secs(i.since, i.closed!), kind: "drift" as const }));
590
+ return { applies, leads, failures, drifted, restores: [...ar.restored, ...dr], open: ar.open + incidents.filter((i) => i.closed === undefined).length };
591
+ }
592
+
593
+ /**
594
+ * The metrics of every project and of the estate from a product's own
595
+ * records (#4612): its report index and its audit trail, for a member whose
596
+ * ledger holds no wave records and for a control repo that reads each
597
+ * project's bucket. The same numbers {@link buildDelivery} computes from the
598
+ * ledger, and the same file, `dora.json` in terragucci's shape. `entries`
599
+ * is undefined when there is no audit trail; then no apply counts and only
600
+ * drift does.
601
+ */
602
+ export function buildRecordDelivery(sources: readonly DeliveryRecordSource[], entries: readonly DeliveryAuditEntry[] | undefined, options: RecordDeliveryOptions): Dora {
603
+ const now = options.now ?? new Date();
604
+ const end = now.getTime();
605
+ const from = weekStart(end) - (DORA_WEEKS - 1) * WEEK_MS;
606
+ const events = sources.map((s) => recordEventsOf(s, entries ?? [], options.stages));
607
+ return {
608
+ schema: doraSchema(options.words),
609
+ generated: now.toISOString(),
610
+ weeks: DORA_WEEKS,
611
+ window: { from: new Date(from).toISOString(), to: now.toISOString() },
612
+ drift_window_seconds: DRIFT_WINDOW_SECONDS,
613
+ audit: entries !== undefined,
614
+ estate: metricsOf(merge(events), from, end),
615
+ projects: sources.map((s, i) => ({ project: s.project, ...metricsOf(events[i]!, from, end) })),
616
+ };
617
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * #4612: delivery metrics from a product's own records, the report index and
3
+ * the audit trail. `__fixtures__/terragucci-dora.json` holds a fixture and
4
+ * the `dora.json` terragucci's own `buildDora` (report/dora.ts at terragucci
5
+ * main d8878e4) wrote for it, with and without the audit trail and with no
6
+ * sources. chant's numbers must be the same, byte for byte.
7
+ */
8
+ import { describe, expect, test } from "vitest";
9
+ import { readFileSync } from "node:fs";
10
+ import { join } from "node:path";
11
+ import { buildDelivery, buildRecordDelivery, type DeliveryAuditEntry, type DeliveryRecordSource, type Dora } from "./delivery";
12
+ import { assertProductWords } from "../ci-product-words";
13
+
14
+ const golden = JSON.parse(readFileSync(join(__dirname, "__fixtures__", "terragucci-dora.json"), "utf-8")) as {
15
+ now: string;
16
+ sources: DeliveryRecordSource[];
17
+ entries: DeliveryAuditEntry[];
18
+ dora: Dora;
19
+ noAudit: Dora;
20
+ empty: Dora;
21
+ };
22
+ const options = { words: assertProductWords({ product: "terragucci" }), now: new Date(golden.now), stages: { plan: "tf-plan", drift: "tf-drift" } };
23
+
24
+ describe("buildRecordDelivery (#4612)", () => {
25
+ test("gives terragucci's dora.json for its index and audit trail", () => {
26
+ expect(buildRecordDelivery(golden.sources, golden.entries, options)).toEqual(golden.dora);
27
+ expect(JSON.stringify(buildRecordDelivery(golden.sources, golden.entries, options))).toBe(JSON.stringify(golden.dora));
28
+ });
29
+
30
+ test("with no audit trail only drift counts, and with no sources the estate is empty, as terragucci's", () => {
31
+ expect(buildRecordDelivery(golden.sources, undefined, options)).toEqual(golden.noAudit);
32
+ expect(buildRecordDelivery([], [], options)).toEqual(golden.empty);
33
+ });
34
+
35
+ test("the fixture moves the numbers it is meant to: a gate split, a digest join, an open incident and a cleared one", () => {
36
+ const d = buildRecordDelivery(golden.sources, golden.entries, options);
37
+ const [p, q] = d.projects;
38
+ expect(p!.lead_time).toEqual({ changes: 2, median_seconds: 4500, before_gate_seconds: 3300, at_gate_seconds: 900, after_gate_seconds: 300 });
39
+ expect(q!.lead_time.changes).toBe(2);
40
+ expect(q!.restore).toMatchObject({ open: 2, drift_restored: 1 });
41
+ expect(d.schema).toBe("terragucci.dora/v1");
42
+ expect(d).not.toHaveProperty("source");
43
+ });
44
+
45
+ test("the stage names are the product's: other names read no plan and no drift", () => {
46
+ const other = buildRecordDelivery(golden.sources, golden.entries, { ...options, stages: { plan: "pulumi-preview", drift: "pulumi-drift" } });
47
+ expect(other.estate.lead_time.changes).toBe(0);
48
+ expect(other.estate.restore.drift_restored).toBe(0);
49
+ });
50
+
51
+ test("the ledger's file still says where it came from", () => {
52
+ const d = buildDelivery({ members: [], waves: [], gates: [], approved: [], drift: [], prEnvs: [] } as never, { now: new Date(golden.now) });
53
+ expect(d.source).toBe("ledger");
54
+ });
55
+ });
package/src/ci-estate.ts CHANGED
@@ -35,10 +35,15 @@ import { estateRows, type EstateRowOptions, type EstateRows, type EstateTables }
35
35
  /** The first chant with `@intentius/chant/ci-estate` (#4612). */
36
36
  export const CI_ESTATE_FLOOR = "0.124.55";
37
37
 
38
+ /** The first chant with `buildRecordDelivery`: delivery metrics from a product's report index and audit trail (#4612). Products feature-detect on it. */
39
+ export const CI_ESTATE_RECORDS_FLOOR = "0.124.72";
40
+
38
41
  export { estateRows, type ApprovedApply, type DriftRun, type EstateRowOptions, type EstateRows, type EstateTables, type GateLine, type PrEnvLine, type WaveJob } from "./ci-estate/rows";
39
42
  export {
40
43
  appliesOf,
41
44
  buildDelivery,
45
+ buildRecordDelivery,
46
+ recordDriftIncidents,
42
47
  deliveryGauges,
43
48
  doraMetricNames,
44
49
  doraSchema,
@@ -51,8 +56,12 @@ export {
51
56
  DORA_MIN_SPAN_SECONDS,
52
57
  DORA_WEEKS,
53
58
  DRIFT_WINDOW_SECONDS,
59
+ type DeliveryAuditEntry,
54
60
  type DeliveryGauge,
61
+ type DeliveryIndexRow,
55
62
  type DeliveryOptions,
63
+ type DeliveryRecordSource,
64
+ type RecordDeliveryOptions,
56
65
  type Dora,
57
66
  type DoraLeadTime,
58
67
  type DoraMetrics,
package/src/ci-product.ts CHANGED
@@ -79,6 +79,7 @@ export const PR_PREVIEW_FLOOR = "0.124.55";
79
79
  export {
80
80
  decideRelayClick,
81
81
  handleRelayRequest,
82
+ NOTIFY_RELAY_POINTS_FLOOR,
82
83
  relayPrincipalFor,
83
84
  RELAY_ENV,
84
85
  slackRelayClick,
@@ -14,7 +14,7 @@
14
14
  */
15
15
 
16
16
  import { execFileSync } from "node:child_process";
17
- import { readFileSync } from "node:fs";
17
+ import { readFileSync, writeFileSync } from "node:fs";
18
18
  import { tmpdir } from "node:os";
19
19
  import { join, resolve } from "node:path";
20
20
  import { AgentError, type AgentGit } from "../../ci-agent";
@@ -26,6 +26,7 @@ import {
26
26
  runCommit,
27
27
  runCommitArgv,
28
28
  type HeadApproval,
29
+ COMMIT_PUSHED_FILE,
29
30
  } from "../../ci-commit";
30
31
  import { activeProductWords, type CiProductWords } from "../../ci-product-words";
31
32
  import { CHANT_EXIT } from "../../exit-codes";
@@ -143,6 +144,8 @@ export async function runCommitCommandLine(ctx: CommandContext): Promise<number>
143
144
  now: () => new Date(),
144
145
  ...(ci ? { runOrigin: ci.runOrigin } : {}),
145
146
  });
147
+ // #4749: what was pushed, for the push job's `after` lines.
148
+ if (out.result === "pushed" && out.commit) writeFileSync(join(dir, COMMIT_PUSHED_FILE), `${out.commit}\n`);
146
149
  console.error(formatInfo(`${settings.name}: ${out.result}: ${out.reason}`));
147
150
  return out.code;
148
151
  } catch (e) {
@@ -15,7 +15,8 @@
15
15
  *
16
16
  * Each click fetches `chant/lifecycle`, reads the signers file at base, and
17
17
  * records through `recordGateApproval`, one click at a time, so two clicks
18
- * never race on the ledger.
18
+ * never race on the ledger. A gate that asks a decision point gets its
19
+ * question answered through `answerPoint` instead (#4611).
19
20
  */
20
21
  import { activeProductWords } from "../../ci-product-words";
21
22
  import { CHANT_EXIT } from "../../exit-codes";
@@ -79,10 +80,28 @@ export function checkoutRelayDeps(cwd: string, principal: string): RelayDeps {
79
80
  const digestAsked = p.planDigest ?? p.changeSet;
80
81
  if (!digestAsked) continue;
81
82
  const fact = latestPendingGate((await readGateLedger(p.op, { cwd })).pending.filter((f) => f.environment === p.environment), p.gate);
82
- out.push({ op: p.op, gate: p.gate, digest: digestAsked, ...(p.environment !== undefined ? { environment: p.environment } : {}), ...(fact?.request ? { request: fact.request } : {}) });
83
+ const q = fact?.answer;
84
+ out.push({
85
+ op: p.op,
86
+ gate: p.gate,
87
+ digest: digestAsked,
88
+ ...(p.environment !== undefined ? { environment: p.environment } : {}),
89
+ ...(fact?.request ? { request: fact.request } : {}),
90
+ ...(q ? { question: { point: q.point, id: q.id, ...(q.pass ? { pass: q.pass } : {}) } } : {}),
91
+ });
83
92
  }
84
93
  return out;
85
94
  }),
95
+ answer: (input) =>
96
+ one(async () => {
97
+ const { answerPoint } = await import("../../workspace/decide");
98
+ const doc = await answerPoint({ cwd, id: input.id, answer: input.answer, by: [input.by], relayedBy: input.relayedBy });
99
+ if ("error" in doc) return { ok: false as const, error: `${doc.error.code}: ${doc.error.message}` };
100
+ if (doc.question.state !== "answered") return { ok: false as const, error: `the question is ${doc.question.state}: ${input.by}'s answer does not settle it on its own` };
101
+ const { pushLifecycleRebasing } = await import("../../lifecycle/git");
102
+ await pushLifecycleRebasing({ cwd }).catch(() => undefined);
103
+ return { ok: true as const };
104
+ }),
86
105
  approve: (input) =>
87
106
  one(async () => {
88
107
  const { recordGateApproval } = await import("./approve");
package/src/config.ts CHANGED
@@ -118,6 +118,13 @@ export const ChantConfigSchema = z.object({
118
118
  build: z.union([z.string().min(1), z.literal(false)]).optional(),
119
119
  chant: z.string().min(1).optional(),
120
120
  after: z.array(z.string().min(1)).optional(),
121
+ permissions: z.record(z.string(), z.enum(["read", "write"])).optional(),
122
+ env: z.record(z.string(), z.string()).optional(),
123
+ setup: z.array(z.union([
124
+ z.object({ uses: z.string().min(1), with: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(), env: z.record(z.string(), z.string()).optional() }).strict(),
125
+ z.object({ run: z.string().min(1), env: z.record(z.string(), z.string()).optional() }).strict(),
126
+ ])).optional(),
127
+ file: z.string().regex(/^[^/][^\0]*$/, "a path from the repository root").refine((f) => !f.split("/").includes(".."), "a path inside the repository").optional(),
121
128
  }).strict().optional(),
122
129
  }).optional(),
123
130
  // Strict: a misspelt key here would leave Ops on the local runtime with
package/src/lexicon.ts CHANGED
@@ -973,6 +973,22 @@ export interface ScheduledOpSpec {
973
973
  * Not on a `reviewAgent` split or a comment agent's workflow.
974
974
  */
975
975
  artifacts?: ScheduledOpArtifact[];
976
+ /** GitLab only (#4753): what a GitLab Op job declares beyond chant's own. Ignored by the other generators. */
977
+ gitlab?: ScheduledOpGitlab;
978
+ }
979
+
980
+ /** A scheduled Op job's GitLab-only settings (#4753). */
981
+ export interface ScheduledOpGitlab {
982
+ /** Named `id_tokens:` with their audiences, beside chant's own (`CHANT_ID_TOKEN`, a cloud trade's); a name chant uses is refused. */
983
+ idTokens?: Record<string, { aud: string | string[] }>;
984
+ /** The job's `cache:` entry, or entries, as GitLab takes them. */
985
+ cache?: Record<string, unknown> | Array<Record<string, unknown>>;
986
+ /**
987
+ * For a cron trigger: the `rules: if:` that picks the pipeline schedule,
988
+ * in place of `$CI_PIPELINE_SOURCE == "schedule" && $CHANT_SCHEDULED_OP == "<name>"`,
989
+ * such as a product's rule that runs on every schedule but its own named ones.
990
+ */
991
+ scheduleRule?: string;
976
992
  }
977
993
 
978
994
  /** A named set of files a scheduled Op's job keeps after its run (#4622). */
@@ -48,7 +48,6 @@ import { readFileSync } from "node:fs";
48
48
  import { basename } from "node:path";
49
49
  import { memberSbom, releaseProvenance } from "./publish-attachments";
50
50
  import { releaseVersion } from "./publish-homebrew";
51
- import { NEXT_RELEASE } from "../release-floors";
52
51
  import { readCredential, type Credential } from "./publish-credentials";
53
52
  import type { ForgePublishDeclaration } from "./publish-declaration";
54
53
  import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets";
@@ -58,7 +57,7 @@ import { PublishTargetError, type PublishContext, type PublishDeps, type Publish
58
57
  export const PUBLISH_FORGE_LATEST_FLOOR = "0.124.63";
59
58
 
60
59
  /** The first chant whose forge target reads `notes` and may have no assets (#4658). Products feature-detect on it. */
61
- export const PUBLISH_FORGE_NOTES_FLOOR = NEXT_RELEASE;
60
+ export const PUBLISH_FORGE_NOTES_FLOOR = "0.124.71";
62
61
 
63
62
  /** `text` with `{label}`, `{version}` and `{tag}` filled in. */
64
63
  function fillNotesText(text: string, values: { label: string; version: string; tag: string }): string {
@@ -26,7 +26,6 @@
26
26
  import { spawnSync } from "node:child_process";
27
27
  import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
28
28
  import { dirname, isAbsolute, relative, resolve } from "node:path";
29
- import { NEXT_RELEASE } from "../release-floors";
30
29
  import type { PublishDeclaration } from "./publish-declaration";
31
30
  import type { Release, ReleaseArtifact } from "./release-store";
32
31
 
@@ -34,7 +33,7 @@ import type { Release, ReleaseArtifact } from "./release-store";
34
33
  export const RELEASE_DIGESTS_ENV = "CHANT_RELEASE_DIGESTS";
35
34
 
36
35
  /** The first chant with `release.images`, `CHANT_RELEASE_DIGESTS`, `chant release images` and an npm target's `pins` (#4657). Products feature-detect on it. */
37
- export const RELEASE_IMAGES_FLOOR = NEXT_RELEASE;
36
+ export const RELEASE_IMAGES_FLOOR = "0.124.71";
38
37
 
39
38
  /** One image a release builds in its cut. */
40
39
  export interface ReleaseImageDeclaration {
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { afterEach, describe, expect, test } from "vitest";
7
7
  import { assertProductWords, CHANT_WORDS } from "./ci-product-words";
8
- import { makeNotifyEvent, notifyConfigProblem, relayRefOf, relayToken, sendNotify, slackMessage, teamsMessage, RELAY_APPROVE_ACTION, RELAY_DECLINE_ACTION, type NotifyFetch } from "./notify";
8
+ import { makeNotifyEvent, notifyConfigProblem, relayRefOf, relayToken, sendNotify, slackMessage, slackRelayActions, teamsMessage, teamsRelayReply, RELAY_APPROVE_ACTION, RELAY_DECLINE_ACTION, type NotifyFetch, type RelayButtons } from "./notify";
9
9
  import { relayPrincipalFor, slackSignature, startRelayServer, teamsSignature, type RelayDeps, type RelayPending, type RelaySettings } from "./notify-relay";
10
10
  import { relaySettingsFromEnv } from "./cli/handlers/notify-relay";
11
11
 
@@ -172,7 +172,61 @@ describe("chant notify relay (#4611)", () => {
172
172
  });
173
173
  });
174
174
 
175
+ describe("a gate that asks a decision point (#4611)", () => {
176
+ const point = (pass?: Array<string | boolean>): RelayPending => ({ op: "tf-apply", gate: "tf-apply-wave-2", digest, question: { point: "prod-apply", id: "q-17", ...(pass ? { pass } : {}) } });
177
+ function withAnswers(pending: RelayPending, refuse?: string) {
178
+ const m = memoryDeps({ pending: [pending] });
179
+ const answers: Array<{ id: string; answer: string | boolean; by: string; relayedBy: string }> = [];
180
+ const deps: RelayDeps = { ...m.deps, answer: async (input) => (refuse ? { ok: false, error: refuse } : (answers.push(input), { ok: true })) };
181
+ return { deps, answers, approvals: m.approvals };
182
+ }
183
+
184
+ test("the click answers the question the gate waits on, as the clicker, relayed by the relay, and records no approval", async () => {
185
+ const { deps, answers, approvals } = withAnswers(point());
186
+ const r = await relay(deps);
187
+ const out = await r.teams(`approve ${tokenFor()}`);
188
+ expect(out.json.text).toMatch(/^tf-apply-wave-2 on tf-apply: decision point prod-apply, question q-17, answered true by github:ana, relayed by chant-relay, for sha256:a{64}/);
189
+ expect(answers).toEqual([{ id: "q-17", answer: true, by: "github:ana", relayedBy: "chant-relay" }]);
190
+ expect(approvals).toEqual([]);
191
+ });
192
+
193
+ test("a gate that passes on one named answer gets that answer; one that passes on several is refused", async () => {
194
+ const one = withAnswers(point(["go"]));
195
+ await (await relay(one.deps)).teams(`approve ${tokenFor()}`);
196
+ expect(one.answers.map((a) => a.answer)).toEqual(["go"]);
197
+ const several = withAnswers(point(["go", "canary"]));
198
+ expect((await (await relay(several.deps)).teams(`approve ${tokenFor()}`)).json.text).toMatch(/passes on go or canary, so a button names no one answer/);
199
+ expect(several.answers).toEqual([]);
200
+ });
201
+
202
+ test("the point's refusal reaches the thread, and a relay with no way to answer refuses as before", async () => {
203
+ const refused = withAnswers(point(), "points-quorum: github:ana holds the agent role");
204
+ expect((await (await relay(refused.deps)).teams(`approve ${tokenFor()}`)).json.text).toMatch(/question q-17 was not answered for github:ana: points-quorum: github:ana holds the agent role/);
205
+ const { deps, approvals } = memoryDeps({ pending: [point()] });
206
+ expect((await (await relay(deps)).teams(`approve ${tokenFor()}`)).json.text).toMatch(/asks decision point prod-apply, so its answer passes the gate, not an approval/);
207
+ expect(approvals).toEqual([]);
208
+ });
209
+ });
210
+
175
211
  describe("the buttons notify posts (#4611)", () => {
212
+ test("a product's own render gets the signed buttons, and its clicks reach the relay", async () => {
213
+ const bodies: string[] = [];
214
+ const fetch: NotifyFetch = async (_u, init) => (bodies.push(init.body), { ok: true, status: 200 });
215
+ const seen: Array<RelayButtons | undefined> = [];
216
+ const render = {
217
+ slack: (_e: unknown, relay?: RelayButtons) => (seen.push(relay), { text: "terragucci wave 2", ...(relay ? { blocks: [slackRelayActions(relay)] } : {}) }),
218
+ teams: (_e: unknown, relay?: RelayButtons) => ({ text: relay ? teamsRelayReply(relay) : "" }),
219
+ };
220
+ await sendNotify({ slack: "SLACK", teams: "TEAMS", relay: "CHANT_RELAY_KEY" }, waitingEvent(), { env: { SLACK: "http://127.0.0.1:9/s", TEAMS: "http://127.0.0.1:9/t", CHANT_RELAY_KEY: KEY }, fetch, log: () => {}, render });
221
+ expect(seen).toEqual([{ token: tokenFor() }]);
222
+ const slack = JSON.parse(bodies[0]!) as { blocks: Array<{ elements: Array<{ action_id: string; value: string }> }> };
223
+ expect(slack.blocks[0]!.elements.map((b) => b.action_id)).toEqual([RELAY_APPROVE_ACTION, RELAY_DECLINE_ACTION]);
224
+ expect(JSON.parse(bodies[1]!).text).toBe(`approve ${tokenFor()}`);
225
+ const { deps, approvals } = memoryDeps();
226
+ await (await relay(deps)).slack(slackBody("UANA", RELAY_APPROVE_ACTION, slack.blocks[0]!.elements[0]!.value));
227
+ expect(approvals).toHaveLength(1);
228
+ });
229
+
176
230
  test("a waiting event's Slack message carries Approve and Decline with the signed reference, and Teams the reply", async () => {
177
231
  const event = waitingEvent();
178
232
  const token = tokenFor(event);
@@ -25,6 +25,17 @@
25
25
  * command applies: the decision point, `identity.gates` (the relay holds
26
26
  * no key, so a sealed gate is refused), the gate policy and the push.
27
27
  *
28
+ * A gate that asks a decision point (#3170) passes on the point's answer,
29
+ * not an approval. There the relay answers the question the gate waits on
30
+ * instead, as `chant workspace points answer <id> --answer <yes> --by
31
+ * <principal> --relayed-by <relay>` does, when the gate passes on one answer
32
+ * (a yes, or the one value its `pass` names). The point's quorum decides
33
+ * whether that principal counts. A gate that passes on several answers names
34
+ * no one answer for a button, and is refused.
35
+ *
36
+ * A product that renders its own chat messages gets the signed buttons from
37
+ * `sendNotify`'s `render` (`./notify.ts`), so its clicks reach this relay too.
38
+ *
28
39
  * Decline records nothing and says who declined. The type-the-name prompt
29
40
  * of `chant approve` (#4575) is for a terminal; a signed click is the
30
41
  * person's confirmation here. The relay starts no job: the resume job
@@ -37,6 +48,14 @@ import type { CiProductWords } from "./ci-product-words";
37
48
  import type { GatedRequest } from "./lifecycle/gated-request-digest";
38
49
  import { readRelayToken, RELAY_APPROVE_ACTION, RELAY_DECLINE_ACTION, type RelayRef } from "./notify";
39
50
 
51
+ /**
52
+ * The first chant whose relay answers a gate's decision point and whose
53
+ * `sendNotify` hands a product's own render the signed buttons
54
+ * (`slackRelayActions`, `teamsRelayReply`), so a product can drop a relay of
55
+ * its own (#4611). Products feature-detect on it.
56
+ */
57
+ export const NOTIFY_RELAY_POINTS_FLOOR = "0.124.72";
58
+
40
59
  /** The relay's settings, by environment variable. */
41
60
  export const RELAY_ENV = {
42
61
  /** The key the notify buttons are signed with: the variable `notify.relay` names on the sending side. */
@@ -198,6 +217,8 @@ export interface RelayPending {
198
217
  environment?: string;
199
218
  /** On a gated request (#4551): the request, whose requester may not approve it. */
200
219
  request?: GatedRequest;
220
+ /** When the gate asks a decision point: the open question it waits on, and the answers that pass it (absent: a yes). */
221
+ question?: { point: string; id: string; pass?: Array<string | boolean> };
201
222
  }
202
223
 
203
224
  /** What the relay reads and writes, so a test stands in for the repo. */
@@ -208,6 +229,12 @@ export interface RelayDeps {
208
229
  pending(digest: string): Promise<RelayPending[]>;
209
230
  /** Record the approval as `chant approve` does. `error` is why it refused. */
210
231
  approve(input: { op: string; gate: string; digest: string; environment?: string; actor: string; relayedBy: string }): Promise<{ ok: true } | { ok: false; error: string }>;
232
+ /**
233
+ * Answer a decision point's question as `chant workspace points answer`
234
+ * does, relayed by the relay (#4611). Absent: a gate that asks a decision
235
+ * point is refused.
236
+ */
237
+ answer?(input: { id: string; answer: string | boolean; by: string; relayedBy: string }): Promise<{ ok: true } | { ok: false; error: string }>;
211
238
  /** Who the relay records as `relayedBy`. */
212
239
  principal: string;
213
240
  words: CiProductWords;
@@ -227,7 +254,7 @@ export interface RelaySettings {
227
254
  export interface RelayAnswer {
228
255
  ok: boolean;
229
256
  /** What the relay did: `approved`, `declined`, or the refusal's kind. */
230
- outcome: "approved" | "declined" | "bad-reference" | "stale" | "ineligible" | "moved" | "refused";
257
+ outcome: "approved" | "answered" | "declined" | "bad-reference" | "stale" | "ineligible" | "moved" | "refused";
231
258
  text: string;
232
259
  /** The gate's op, when the click reached one. */
233
260
  op?: string;
@@ -264,6 +291,26 @@ export async function decideRelayClick(click: RelayClick, settings: RelaySetting
264
291
  if (pending.request && norm(pending.request.by) === norm(principal)) {
265
292
  return { ok: false, outcome: "ineligible", op: pending.op, gate: pending.gate, principal, text: `Refused: ${principal} made the request, and a requester's own approval does not count. Someone else approves it.` };
266
293
  }
294
+ if (pending.question) {
295
+ const q = pending.question;
296
+ if (!deps.answer) {
297
+ return { ok: false, outcome: "refused", op: pending.op, gate: pending.gate, principal, text: `Not approved: ${pending.gate} asks decision point ${q.point}, so its answer passes the gate, not an approval. Answer question ${q.id} at a shell.` };
298
+ }
299
+ if (q.pass && q.pass.length !== 1) {
300
+ return { ok: false, outcome: "refused", op: pending.op, gate: pending.gate, principal, text: `Not approved: ${pending.gate} asks decision point ${q.point}, which ${q.pass.length === 0 ? "names no answer that passes it" : `passes on ${q.pass.map(String).join(" or ")}`}, so a button names no one answer. Answer question ${q.id} at a shell.` };
301
+ }
302
+ const value = q.pass ? q.pass[0]! : true;
303
+ const answered = await deps.answer({ id: q.id, answer: value, by: principal, relayedBy: deps.principal });
304
+ if (!answered.ok) return { ok: false, outcome: "refused", op: pending.op, gate: pending.gate, principal, text: `Not approved: ${pending.gate} asks decision point ${q.point}, and question ${q.id} was not answered for ${principal}: ${answered.error}` };
305
+ return {
306
+ ok: true,
307
+ outcome: "answered",
308
+ op: pending.op,
309
+ gate: pending.gate,
310
+ principal,
311
+ text: `${pending.gate} on ${pending.op}: decision point ${q.point}, question ${q.id}, answered ${String(value)} by ${principal}, relayed by ${deps.principal}, for ${pending.digest} and no other plan. The resume job starts the ${words.stages.apply} once the answer passes the gate.`,
312
+ };
313
+ }
267
314
  const recorded = await deps.approve({ op: pending.op, gate: pending.gate, digest: pending.digest, ...(pending.environment !== undefined ? { environment: pending.environment } : {}), actor: principal, relayedBy: deps.principal });
268
315
  if (!recorded.ok) return { ok: false, outcome: "refused", op: pending.op, gate: pending.gate, principal, text: `Not approved: ${recorded.error}` };
269
316
  return {