@intentius/chant 0.124.15 → 0.124.17
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/cli/commands/check-lexicon-plugin.d.ts.map +1 -1
- package/dist/cli/commands/check-lexicon-plugin.js +2 -1
- package/dist/cli/commands/lint.d.ts.map +1 -1
- package/dist/cli/commands/lint.js +3 -2
- package/dist/cli/flush.d.ts +16 -0
- package/dist/cli/flush.d.ts.map +1 -0
- package/dist/cli/flush.js +42 -0
- package/dist/cli/handlers/approve.d.ts +98 -0
- package/dist/cli/handlers/approve.d.ts.map +1 -0
- package/dist/cli/handlers/approve.js +495 -0
- package/dist/cli/handlers/operator.d.ts +1 -95
- package/dist/cli/handlers/operator.d.ts.map +1 -1
- package/dist/cli/handlers/operator.js +4 -488
- package/dist/cli/handlers/override-approve.js +1 -1
- package/dist/cli/main.d.ts +4 -15
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +4 -1062
- package/dist/cli/parse-args.d.ts +6 -0
- package/dist/cli/parse-args.d.ts.map +1 -0
- package/dist/cli/parse-args.js +1028 -0
- package/dist/components/discover.d.ts.map +1 -1
- package/dist/components/discover.js +2 -1
- package/dist/components/fan-out-record.d.ts +1 -1
- package/dist/components/fan-out-record.d.ts.map +1 -1
- package/dist/components/fan-out-record.js +3 -7
- package/dist/components/fan-out-run.d.ts +5 -3
- package/dist/components/fan-out-run.d.ts.map +1 -1
- package/dist/components/fan-out-run.js +7 -5
- package/dist/config-sandbox.d.ts.map +1 -1
- package/dist/config-sandbox.js +5 -1
- package/dist/discovery/import.d.ts.map +1 -1
- package/dist/discovery/import.js +2 -1
- package/dist/discovery/sandbox/driver.d.ts.map +1 -1
- package/dist/discovery/sandbox/driver.js +8 -3
- package/dist/gated-waves.d.ts +25 -6
- package/dist/gated-waves.d.ts.map +1 -1
- package/dist/gated-waves.js +21 -6
- package/dist/lexicon-module.d.ts.map +1 -1
- package/dist/lexicon-module.js +4 -3
- package/dist/lint/policy-import.d.ts.map +1 -1
- package/dist/lint/policy-import.js +2 -1
- package/dist/lint/rule-loader.d.ts.map +1 -1
- package/dist/lint/rule-loader.js +2 -1
- package/dist/module-interop.d.ts +20 -0
- package/dist/module-interop.d.ts.map +1 -0
- package/dist/module-interop.js +39 -0
- package/dist/op/activities/activity-contracts.d.ts +4 -4
- package/dist/op/discover.d.ts.map +1 -1
- package/dist/op/discover.js +3 -2
- package/dist/op/op-waves-run.d.ts +1 -1
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +5 -6
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +4 -8
- package/dist/package-version.d.ts +2 -0
- package/dist/package-version.d.ts.map +1 -0
- package/dist/package-version.js +10 -0
- package/dist/wave-engine.d.ts +62 -0
- package/dist/wave-engine.d.ts.map +1 -0
- package/dist/wave-engine.js +59 -0
- package/dist/wave-layout.d.ts +29 -0
- package/dist/wave-layout.d.ts.map +1 -0
- package/dist/wave-layout.js +41 -0
- package/dist/wave-runtime.d.ts +29 -0
- package/dist/wave-runtime.d.ts.map +1 -0
- package/dist/wave-runtime.js +103 -0
- package/dist/wave-runtime.mjs +331 -0
- package/dist/workspace/ajv2020.d.ts +5 -0
- package/dist/workspace/ajv2020.d.ts.map +1 -0
- package/dist/workspace/ajv2020.js +14 -0
- package/dist/workspace/declaration.d.ts.map +1 -1
- package/dist/workspace/declaration.js +4 -8
- package/dist/workspace/kinds.d.ts.map +1 -1
- package/dist/workspace/kinds.js +2 -5
- package/dist/workspace/lineage-migrations.d.ts.map +1 -1
- package/dist/workspace/lineage-migrations.js +2 -1
- package/dist/workspace/points.d.ts.map +1 -1
- package/dist/workspace/points.js +2 -5
- package/dist/workspace/principal-classes.d.ts.map +1 -1
- package/dist/workspace/principal-classes.js +2 -5
- package/package.json +5 -3
- package/src/cli/commands/check-lexicon-plugin.ts +2 -1
- package/src/cli/commands/lint.ts +3 -2
- package/src/cli/compiled-cli.e2e.test.ts +42 -1
- package/src/cli/flush.ts +44 -0
- package/src/cli/handlers/approve.ts +618 -0
- package/src/cli/handlers/operator.ts +10 -608
- package/src/cli/handlers/override-approve.test.ts +1 -1
- package/src/cli/handlers/override-approve.ts +1 -1
- package/src/cli/main.ts +5 -816
- package/src/cli/parse-args.ts +781 -0
- package/src/components/discover.ts +2 -1
- package/src/components/fan-out-record.ts +3 -7
- package/src/components/fan-out-run.ts +7 -5
- package/src/config-sandbox.ts +5 -1
- package/src/discovery/import.ts +2 -1
- package/src/discovery/sandbox/driver.ts +8 -3
- package/src/gate-decision-bundle.test.ts +1 -0
- package/src/gated-waves.ts +28 -6
- package/src/lexicon-module.ts +4 -3
- package/src/lint/policy-import.ts +2 -1
- package/src/lint/rule-loader.ts +2 -1
- package/src/module-interop.test.ts +65 -0
- package/src/module-interop.ts +39 -0
- package/src/op/discover.ts +3 -2
- package/src/op/op-waves-run.ts +5 -6
- package/src/op/op-waves.ts +4 -8
- package/src/package-version.ts +11 -0
- package/src/wave-engine.test.ts +107 -0
- package/src/wave-engine.ts +98 -0
- package/src/wave-layout.ts +44 -0
- package/src/wave-runtime-bundle.test.ts +70 -0
- package/src/wave-runtime.e2e.test.ts +177 -0
- package/src/wave-runtime.ts +104 -0
- package/src/workspace/ajv2020.ts +17 -0
- package/src/workspace/declaration.ts +4 -10
- package/src/workspace/kinds.ts +2 -5
- package/src/workspace/lineage-migrations.ts +2 -1
- package/src/workspace/points.ts +2 -5
- package/src/workspace/principal-classes.ts +2 -5
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wave engine (#3766): what `chant run wave` (the Op waves spec,
|
|
3
|
+
* `./op/op-waves-run.ts`) and `chant components fan-out --wave-gate`
|
|
4
|
+
* (`./components/fan-out-run.ts`) share once a wave is planned.
|
|
5
|
+
*
|
|
6
|
+
* - Gate naming: {@link waveGateName} and {@link waveGateNameFrom}.
|
|
7
|
+
* - The set digest: {@link waveSetDigest} over {@link waveDigestMembers}.
|
|
8
|
+
* - The share split of a wide wave: {@link waveShare}.
|
|
9
|
+
* - The gate decision call: {@link decideWaveGate}.
|
|
10
|
+
* - The record file a wave job hands the next one: {@link writeWaveRecordFile}.
|
|
11
|
+
*
|
|
12
|
+
* The parts that need neither the gate ledger nor the filesystem live in
|
|
13
|
+
* `./gated-waves.ts`, which terragucci bundles on its own (#3421), and
|
|
14
|
+
* `./wave-layout.ts`, which imports nothing so the Op waves spec module can
|
|
15
|
+
* use it without the change-set code; this module re-exports both so a
|
|
16
|
+
* runner imports the engine from one place.
|
|
17
|
+
*
|
|
18
|
+
* What stays with each entry point: how a wave is planned (Op runs' plan
|
|
19
|
+
* commands, or each component's capabilities), the gate policy, approval
|
|
20
|
+
* mode, decision point, hooks and spend rule (Op waves only), and the shape
|
|
21
|
+
* of the record each writes. Those shapes are read by jobs and approvals
|
|
22
|
+
* already in the wild, so the engine writes what it is handed.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { dirname } from "node:path";
|
|
26
|
+
import { mkdirSync, renameSync, writeFileSync } from "node:fs";
|
|
27
|
+
import { evaluateGate, type GateCheck, type GateLedgerPort } from "./op/gate";
|
|
28
|
+
import type { AppliedGateRecord } from "./lifecycle/gate-applied";
|
|
29
|
+
|
|
30
|
+
export { WAVE_GATE_NAME_PATTERN, waveGateNameFrom, waveShare } from "./wave-layout";
|
|
31
|
+
export {
|
|
32
|
+
layerWaves,
|
|
33
|
+
waveGateName,
|
|
34
|
+
waveDigestMembers,
|
|
35
|
+
waveSetDigest,
|
|
36
|
+
readWaveRecords,
|
|
37
|
+
withWaveRecord,
|
|
38
|
+
describeChangedWave,
|
|
39
|
+
type WaveDigestOver,
|
|
40
|
+
type WaveMember,
|
|
41
|
+
type WaveNode,
|
|
42
|
+
type WaveRecord,
|
|
43
|
+
type WaveStatus,
|
|
44
|
+
} from "./gated-waves";
|
|
45
|
+
|
|
46
|
+
/** What a wave asks its gate. */
|
|
47
|
+
export interface WaveGateRequest {
|
|
48
|
+
/** The op the gate is recorded under: the fan-out's op, or the Op waves spec's name. */
|
|
49
|
+
op: string;
|
|
50
|
+
/** The wave's full gate name. */
|
|
51
|
+
gate: string;
|
|
52
|
+
/** The wave's set digest. */
|
|
53
|
+
digest: string;
|
|
54
|
+
/** The pending fact's description. */
|
|
55
|
+
description: string;
|
|
56
|
+
/** The pending fact's expiry, as a gate's `timeout`. */
|
|
57
|
+
timeout?: string;
|
|
58
|
+
now?: string;
|
|
59
|
+
/** Approvals a wave already applied under, which count for nothing (#3784). */
|
|
60
|
+
spent?: readonly AppliedGateRecord[];
|
|
61
|
+
/** Fields the pending fact carries (#3821). */
|
|
62
|
+
fields?: Record<string, unknown>;
|
|
63
|
+
/** The pending fact carries `neverOverMcp` (#3821). */
|
|
64
|
+
neverOverMcp?: boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Decide a wave's gate: an approval of `digest` under `gate` on `op`'s
|
|
69
|
+
* ledger, or the pending fact that stands for it. A field left out of the
|
|
70
|
+
* request is left out of the call, so each entry point's pending facts are
|
|
71
|
+
* the ones it always wrote.
|
|
72
|
+
*/
|
|
73
|
+
export function decideWaveGate(port: GateLedgerPort, request: WaveGateRequest): Promise<GateCheck> {
|
|
74
|
+
return evaluateGate(port, {
|
|
75
|
+
op: request.op,
|
|
76
|
+
gate: request.gate,
|
|
77
|
+
planDigest: request.digest,
|
|
78
|
+
description: request.description,
|
|
79
|
+
...(request.timeout ? { timeout: request.timeout } : {}),
|
|
80
|
+
...(request.now !== undefined ? { now: request.now } : {}),
|
|
81
|
+
...(request.spent ? { spent: request.spent } : {}),
|
|
82
|
+
...(request.fields ? { fields: request.fields } : {}),
|
|
83
|
+
...(request.neverOverMcp ? { neverOverMcp: true } : {}),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Write a wave record file as indented JSON, through a temporary file and a
|
|
89
|
+
* rename, so a job killed during the write leaves the previous record whole.
|
|
90
|
+
* The fan-out attempt record and an Op wave's decision record both go
|
|
91
|
+
* through it.
|
|
92
|
+
*/
|
|
93
|
+
export function writeWaveRecordFile(path: string, value: unknown): void {
|
|
94
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
95
|
+
const temporary = `${path}.${process.pid}.tmp`;
|
|
96
|
+
writeFileSync(temporary, JSON.stringify(value, null, 2) + "\n");
|
|
97
|
+
renameSync(temporary, path);
|
|
98
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wave gate names and the share split of a wide wave (#3766), the parts of
|
|
3
|
+
* the wave engine (`./wave-engine.ts`) that the Op waves spec module
|
|
4
|
+
* (`./op/op-waves.ts`) needs. That module is in the gate-decision bundle
|
|
5
|
+
* (`./gate-decision.ts` re-exports a constant from it), so this imports
|
|
6
|
+
* nothing and keeps the change-set digest code out of that bundle.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** The default wave gate name pattern: `{gate}` is the base gate name, `{k}` the wave's number. */
|
|
10
|
+
export const WAVE_GATE_NAME_PATTERN = "{gate}-wave-{k}";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The gate wave `k` waits on under a name pattern (#3821). With the default
|
|
14
|
+
* pattern this is `waveGateName(gate, k)` from `./gated-waves.ts`; an Op
|
|
15
|
+
* waves spec's `gateName` names another (such as `"wave-{k}"`) so approvals
|
|
16
|
+
* already on the ledger under a product's old names keep matching.
|
|
17
|
+
*
|
|
18
|
+
* `{gate}` is filled in before `{k}`, as `opWaveGateName` always did, so a
|
|
19
|
+
* base gate name holding the text `{k}` is filled in too. That is the one
|
|
20
|
+
* input on which this and `waveGateName` differ, and each entry point keeps
|
|
21
|
+
* the one it shipped with.
|
|
22
|
+
*/
|
|
23
|
+
export function waveGateNameFrom(pattern: string | undefined, gate: string, k: number): string {
|
|
24
|
+
return (pattern ?? WAVE_GATE_NAME_PATTERN).replaceAll("{gate}", gate).replaceAll("{k}", String(k));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Share `share` (1-based) of `shares` of a wide wave (#3679): the items
|
|
29
|
+
* sorted by `keyOf`, cut into contiguous slices whose sizes differ by at most
|
|
30
|
+
* one. The deciding job and every share job cut the same way, so each item
|
|
31
|
+
* is applied by exactly one share.
|
|
32
|
+
*/
|
|
33
|
+
export function waveShare<T>(items: readonly T[], share: number, shares: number, keyOf: (item: T) => string): T[] {
|
|
34
|
+
const sorted = [...items].sort((a, b) => {
|
|
35
|
+
const x = keyOf(a);
|
|
36
|
+
const y = keyOf(b);
|
|
37
|
+
return x < y ? -1 : x > y ? 1 : 0;
|
|
38
|
+
});
|
|
39
|
+
const base = Math.floor(sorted.length / shares);
|
|
40
|
+
const extra = sorted.length % shares;
|
|
41
|
+
const start = (share - 1) * base + Math.min(share - 1, extra);
|
|
42
|
+
const size = base + (share <= extra ? 1 : 0);
|
|
43
|
+
return sorted.slice(start, start + size);
|
|
44
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wave-job runtime bundles to one self-contained file (#3896). A product
|
|
3
|
+
* copies `dist/wave-runtime.mjs` into its CI image with no npm install of
|
|
4
|
+
* chant, so the file may import nothing but `node:` builtins, and it carries
|
|
5
|
+
* no TypeScript compiler, esbuild or tsx: those three are the 33 MB a wave
|
|
6
|
+
* job's image has no use for. This builds it the way `npm run build` does and
|
|
7
|
+
* reads esbuild's own list of what went in.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { builtinModules } from "node:module";
|
|
11
|
+
import { describe, expect, test } from "vitest";
|
|
12
|
+
// @ts-expect-error: a plain .mjs script with no type declarations
|
|
13
|
+
import { buildWaveRuntime, LEFT_OUT } from "../scripts/build-wave-runtime.mjs";
|
|
14
|
+
|
|
15
|
+
interface Metafile {
|
|
16
|
+
inputs: Record<string, { bytes: number; imports: { path: string; kind: string; external?: boolean }[] }>;
|
|
17
|
+
outputs: Record<string, { imports: { path: string; kind: string; external?: boolean }[]; inputs: Record<string, { bytesInOutput: number }> }>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const built = (await buildWaveRuntime({ write: false })) as { bytes: number; metafile: Metafile; text: string };
|
|
21
|
+
const output = Object.values(built.metafile.outputs)[0]!;
|
|
22
|
+
const inputs = Object.keys(output.inputs);
|
|
23
|
+
|
|
24
|
+
describe("the wave-job runtime bundle (#3896)", () => {
|
|
25
|
+
test("leaves out the TypeScript compiler, esbuild and tsx", () => {
|
|
26
|
+
expect(LEFT_OUT).toEqual(["typescript", "esbuild", "tsx"]);
|
|
27
|
+
for (const name of LEFT_OUT as string[]) {
|
|
28
|
+
expect(inputs.filter((i) => i.includes(`node_modules/${name}/`)), name).toEqual([]);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("imports nothing but node: builtins, so it runs with no node_modules", () => {
|
|
33
|
+
const builtins = new Set(builtinModules);
|
|
34
|
+
const imported = output.imports.map((i) => i.path);
|
|
35
|
+
expect(imported.filter((p) => !builtins.has(p.replace(/^node:/, "").split("/")[0]!))).toEqual([]);
|
|
36
|
+
// zod, ajv, js-yaml and picomatch are inlined; nothing reads them from disk.
|
|
37
|
+
for (const pkg of ["zod", "ajv", "js-yaml", "picomatch"]) {
|
|
38
|
+
expect(inputs.some((i) => i.includes(`node_modules/${pkg}/`)), pkg).toBe(true);
|
|
39
|
+
}
|
|
40
|
+
expect(built.text).not.toMatch(/createRequire\(import\.meta\.url\)\("\.\.\/\.\.\/package\.json"\)/);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("a left-out package is reached only through import(), never on start", () => {
|
|
44
|
+
// The build refuses otherwise; this pins the four commands' own modules as the static graph.
|
|
45
|
+
const entry = Object.keys(built.metafile.inputs).find((k) => k.endsWith("src/wave-runtime.ts"))!;
|
|
46
|
+
const seen = new Set([entry]);
|
|
47
|
+
const queue = [entry];
|
|
48
|
+
while (queue.length) {
|
|
49
|
+
for (const im of built.metafile.inputs[queue.shift()!]?.imports ?? []) {
|
|
50
|
+
if (im.kind === "dynamic-import" || seen.has(im.path)) continue;
|
|
51
|
+
seen.add(im.path);
|
|
52
|
+
queue.push(im.path);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
for (const handler of ["cli/handlers/run-wave.ts", "cli/handlers/gate-resume.ts", "cli/handlers/approve.ts", "workspace/points-cli.ts", "cli/parse-args.ts"]) {
|
|
56
|
+
expect([...seen].some((k) => k.endsWith(`src/${handler}`)), handler).toBe(true);
|
|
57
|
+
}
|
|
58
|
+
expect([...seen].filter((k) => k.startsWith("chant-wave-runtime-left-out:"))).toEqual([]);
|
|
59
|
+
// Neither the full CLI's dispatch nor the operator loop is in it, and the build and plugin loader load on no start.
|
|
60
|
+
expect(inputs.filter((i) => /src\/cli\/main\.ts$|src\/cli\/handlers\/operator\.ts$/.test(i))).toEqual([]);
|
|
61
|
+
expect([...seen].filter((i) => /src\/cli\/plugins\.ts$|src\/build\.ts$/.test(i))).toEqual([]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("carries its version and stays small", () => {
|
|
65
|
+
expect(built.text).toContain('"workspace points"');
|
|
66
|
+
expect(built.text.startsWith("#!/usr/bin/env node\n")).toBe(true);
|
|
67
|
+
// About 1.45 MB minified today (440 KB gzipped), zod's inlined schemas about 300 KB of it.
|
|
68
|
+
expect(built.bytes).toBeLessThan(2 * 1024 * 1024);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wave-job runtime runs alone (#3896). `dist/wave-runtime.mjs` is copied
|
|
3
|
+
* into an empty directory, the way a product's CI image carries it, and run
|
|
4
|
+
* with plain node, nothing installed beside it, through a gated wave's whole
|
|
5
|
+
* life: `run wave` waits at a ledger gate, `approve` records the resolution,
|
|
6
|
+
* `run resume --dry-run` finds it, `run wave` applies; then a wave whose gate
|
|
7
|
+
* asks a decision point waits, `workspace points` lists the open question,
|
|
8
|
+
* `workspace points answer` answers it, and `run wave` applies.
|
|
9
|
+
*
|
|
10
|
+
* End to end because it builds the bundle and spawns node for each command.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
14
|
+
import { copyFileSync, cpSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { createRequire } from "node:module";
|
|
16
|
+
import { tmpdir } from "node:os";
|
|
17
|
+
import { dirname, join } from "node:path";
|
|
18
|
+
import { afterAll, beforeAll, describe, expect, test } from "vitest";
|
|
19
|
+
// @ts-expect-error: a plain .mjs script with no type declarations
|
|
20
|
+
import { buildWaveRuntime } from "../scripts/build-wave-runtime.mjs";
|
|
21
|
+
import { REPO } from "./workspace/__fixtures__/decide-workspace";
|
|
22
|
+
|
|
23
|
+
const POINTS = {
|
|
24
|
+
points: {
|
|
25
|
+
"prod-apply": {
|
|
26
|
+
title: "Apply this plan to prod",
|
|
27
|
+
question: { type: "noul", instructions: "Should this plan be applied to prod?", criteria: { true: "Apply it.", false: "Do not apply it." } },
|
|
28
|
+
inputs: { "gate.component": "the Op the gate belongs to", "gate.planDigest": "the plan the gate binds" },
|
|
29
|
+
deciders: [{ kind: "quorum", count: 1 }],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const SPEC = {
|
|
35
|
+
name: "smoke",
|
|
36
|
+
op: "smoke",
|
|
37
|
+
plan: ["node", "plan.mjs", "{target}", "{plan}"],
|
|
38
|
+
apply: ["node", "apply.mjs", "{target}", "{plan}"],
|
|
39
|
+
waves: [
|
|
40
|
+
{ name: "dev", runs: [{ target: "dev" }], gate: "always" },
|
|
41
|
+
{ name: "prod", runs: [{ target: "prod" }], gate: "always", point: "prod-apply" },
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
let scratch: string;
|
|
46
|
+
let runtimeDir: string;
|
|
47
|
+
let runtime: string;
|
|
48
|
+
let repo: string;
|
|
49
|
+
|
|
50
|
+
/** The job's environment: no CI variables, so nothing names a CI job to resume. */
|
|
51
|
+
function jobEnv(): NodeJS.ProcessEnv {
|
|
52
|
+
const env: NodeJS.ProcessEnv = {};
|
|
53
|
+
for (const [k, v] of Object.entries(process.env)) {
|
|
54
|
+
if (/^(CI|GITHUB_|GITLAB_|FORGEJO_|GITEA_|CHANT_|NODE_OPTIONS$|VITEST)/.test(k)) continue;
|
|
55
|
+
env[k] = v;
|
|
56
|
+
}
|
|
57
|
+
return env;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function chant(...args: string[]): { status: number | null; stdout: string; stderr: string } {
|
|
61
|
+
const r = spawnSync(process.execPath, [runtime, ...args], { cwd: repo, env: jobEnv(), encoding: "utf-8" });
|
|
62
|
+
return { status: r.status, stdout: r.stdout, stderr: r.stderr };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const git = (...args: string[]) =>
|
|
66
|
+
execFileSync("git", ["-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "commit.gpgsign=false", ...args], { cwd: repo, stdio: "ignore" });
|
|
67
|
+
|
|
68
|
+
beforeAll(async () => {
|
|
69
|
+
scratch = realpathSync(mkdtempSync(join(tmpdir(), "chant-wave-runtime-")));
|
|
70
|
+
const built = join(scratch, "build", "wave-runtime.mjs");
|
|
71
|
+
mkdirSync(dirname(built), { recursive: true });
|
|
72
|
+
await buildWaveRuntime({ outfile: built });
|
|
73
|
+
runtimeDir = join(scratch, "image");
|
|
74
|
+
mkdirSync(runtimeDir);
|
|
75
|
+
runtime = join(runtimeDir, "wave-runtime.mjs");
|
|
76
|
+
copyFileSync(built, runtime);
|
|
77
|
+
|
|
78
|
+
repo = join(scratch, "repo");
|
|
79
|
+
const files: Record<string, string> = {
|
|
80
|
+
"chant.workspace.json": JSON.stringify({
|
|
81
|
+
name: "wave-runtime",
|
|
82
|
+
schema: 1,
|
|
83
|
+
members: [{ name: "app", dir: "app", kind: "other", because: "a plain Node server" }],
|
|
84
|
+
records: [{ kind: "answers/answer.kind.mjs" }],
|
|
85
|
+
}),
|
|
86
|
+
"app/server.mjs": "export const port = 8080;\n",
|
|
87
|
+
"decisions/points.json": JSON.stringify(POINTS),
|
|
88
|
+
"plan.mjs": `import { writeFileSync } from "node:fs";\nwriteFileSync(process.argv[3], JSON.stringify({ planDigest: "sha256:" + (process.argv[2] === "dev" ? "a" : "b").repeat(64) }));\n`,
|
|
89
|
+
"apply.mjs": `import { appendFileSync } from "node:fs";\nappendFileSync("applied.log", process.argv[2] + "\\n");\n`,
|
|
90
|
+
"waves.json": JSON.stringify(SPEC),
|
|
91
|
+
};
|
|
92
|
+
for (const [path, text] of Object.entries(files)) {
|
|
93
|
+
mkdirSync(dirname(join(repo, path)), { recursive: true });
|
|
94
|
+
writeFileSync(join(repo, path), text);
|
|
95
|
+
}
|
|
96
|
+
cpSync(join(REPO, "reference-workspace", "answers", "answer.kind.mjs"), join(repo, "answers", "answer.kind.mjs"));
|
|
97
|
+
cpSync(join(REPO, "reference-workspace", "answers", "answer.schema.json"), join(repo, "answers", "answer.schema.json"));
|
|
98
|
+
git("init", "-q", "-b", "main");
|
|
99
|
+
git("add", "-A");
|
|
100
|
+
git("commit", "-qm", "spec");
|
|
101
|
+
// The gate policy is read at HEAD^1, so the spec needs a commit under the head.
|
|
102
|
+
writeFileSync(join(repo, ".gitignore"), ".chant/\napplied.log\n");
|
|
103
|
+
git("add", "-A");
|
|
104
|
+
git("commit", "-qm", "ignore");
|
|
105
|
+
}, 120_000);
|
|
106
|
+
|
|
107
|
+
afterAll(() => {
|
|
108
|
+
if (scratch) rmSync(scratch, { recursive: true, force: true });
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe("the wave-job runtime, alone in a directory (#3896)", () => {
|
|
112
|
+
test("is one file, with no package beside it to resolve", () => {
|
|
113
|
+
expect(readdirSync(runtimeDir)).toEqual(["wave-runtime.mjs"]);
|
|
114
|
+
const resolveBeside = createRequire(runtime).resolve;
|
|
115
|
+
for (const pkg of ["@intentius/chant", "typescript", "esbuild", "tsx", "zod", "ajv"]) {
|
|
116
|
+
expect(() => resolveBeside(pkg), pkg).toThrow();
|
|
117
|
+
}
|
|
118
|
+
const version = (JSON.parse(readFileSync(join(REPO, "packages", "core", "package.json"), "utf-8")) as { version: string }).version;
|
|
119
|
+
expect(chant("--version").stdout.trim()).toBe(version);
|
|
120
|
+
const other = chant("build");
|
|
121
|
+
expect(other.status).toBe(1);
|
|
122
|
+
expect(other.stderr).toContain("is not part of chant's wave-job runtime");
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("a ledger gate: run wave waits, approve, run resume --dry-run, run wave applies", () => {
|
|
126
|
+
const waiting = chant("run", "wave", "--spec", "waves.json", "--wave", "1", "--json");
|
|
127
|
+
expect(waiting.status, waiting.stderr).toBe(3);
|
|
128
|
+
const decision = (JSON.parse(waiting.stdout) as { decision: { status: string; gate: string; digest: string } }).decision;
|
|
129
|
+
expect(decision).toMatchObject({ status: "waiting", gate: "smoke-wave-1" });
|
|
130
|
+
|
|
131
|
+
const approved = chant("approve", "smoke", "smoke-wave-1", "--actor", "alice");
|
|
132
|
+
expect(approved.status, approved.stderr).toBe(0);
|
|
133
|
+
expect(approved.stderr).toContain(`Gate "smoke-wave-1" on "smoke" resolved by alice`);
|
|
134
|
+
expect(approved.stderr).toContain(`This approves the plan ${decision.digest}`);
|
|
135
|
+
|
|
136
|
+
const resume = chant("run", "resume", "--dry-run");
|
|
137
|
+
expect(resume.status, resume.stderr).toBe(0);
|
|
138
|
+
expect(resume.stderr).toContain("smoke / smoke-wave-1, approved by alice");
|
|
139
|
+
|
|
140
|
+
const applied = chant("run", "wave", "--spec", "waves.json", "--wave", "1");
|
|
141
|
+
expect(applied.status, applied.stderr).toBe(0);
|
|
142
|
+
expect(applied.stderr).toContain("approved by alice");
|
|
143
|
+
expect(readFileSync(join(repo, "applied.log"), "utf-8")).toBe("dev\n");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("a gate that asks a decision point: run wave waits, points lists and answers, run wave applies", () => {
|
|
147
|
+
const waiting = chant("run", "wave", "--spec", "waves.json", "--wave", "2", "--json");
|
|
148
|
+
expect(waiting.status, waiting.stderr).toBe(3);
|
|
149
|
+
const id = (JSON.parse(waiting.stdout) as { decision: { point: { question: { id: string } } } }).decision.point.question.id;
|
|
150
|
+
expect(id).toMatch(/^prod-apply-[0-9a-f]{12}$/);
|
|
151
|
+
|
|
152
|
+
const open = chant("workspace", "points", "--open");
|
|
153
|
+
expect(open.status, open.stderr).toBe(0);
|
|
154
|
+
expect(open.stdout).toContain(`${id} escalated`);
|
|
155
|
+
|
|
156
|
+
const answered = chant("workspace", "points", "answer", id, "--answer", "true", "--by", "alice");
|
|
157
|
+
expect(answered.status, answered.stderr).toBe(0);
|
|
158
|
+
expect(readFileSync(join(repo, "answers", `${id}.md`), "utf-8")).toMatch(/state: "answered"\nanswer: true/);
|
|
159
|
+
|
|
160
|
+
const applied = chant("run", "wave", "--spec", "waves.json", "--wave", "2");
|
|
161
|
+
expect(applied.status, applied.stderr).toBe(0);
|
|
162
|
+
expect(readFileSync(join(repo, "applied.log"), "utf-8")).toBe("dev\nprod\n");
|
|
163
|
+
|
|
164
|
+
// The ledger the runtime wrote is the full CLI's: pending, resolution, pending citing the question, resolution citing the answer.
|
|
165
|
+
const ledger = execFileSync("git", ["show", "chant/lifecycle:_gates/smoke.jsonl"], { cwd: repo, encoding: "utf-8" })
|
|
166
|
+
.trim()
|
|
167
|
+
.split("\n")
|
|
168
|
+
.map((l) => JSON.parse(l) as { kind?: string; gate: string; resolvedBy?: string; answer?: { id: string } });
|
|
169
|
+
expect(ledger.map((l) => [l.gate, l.kind ?? "resolution", l.resolvedBy ?? null])).toEqual([
|
|
170
|
+
["smoke-wave-1", "pending", null],
|
|
171
|
+
["smoke-wave-1", "resolution", "alice"],
|
|
172
|
+
["smoke-wave-2", "pending", null],
|
|
173
|
+
["smoke-wave-2", "resolution", "alice"],
|
|
174
|
+
]);
|
|
175
|
+
expect(ledger[3]!.answer?.id).toBe(id);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The slim wave-job runtime (#3896): the four commands a generated Op waves
|
|
3
|
+
* pipeline runs, and nothing else.
|
|
4
|
+
*
|
|
5
|
+
* chant run wave --spec <file> --wave <k> [--decide | --share <i> | --record-plans]
|
|
6
|
+
* chant run resume [--gate <op>/<gate>] [--dry-run]
|
|
7
|
+
* chant approve <op> <gate> [...]
|
|
8
|
+
* chant workspace points ask|answer|list|... [...]
|
|
9
|
+
*
|
|
10
|
+
* `scripts/build-runtime.mjs` bundles this file with esbuild into
|
|
11
|
+
* `dist/wave-runtime.mjs`: one self-contained ES module whose only imports are
|
|
12
|
+
* `node:` builtins, with no TypeScript compiler, esbuild, tsx or zod in it. A
|
|
13
|
+
* product copies that one file into its CI image and runs it with plain node,
|
|
14
|
+
* or runs it from an installed `@intentius/chant`
|
|
15
|
+
* (`node node_modules/@intentius/chant/dist/wave-runtime.mjs run wave ...`).
|
|
16
|
+
*
|
|
17
|
+
* The handlers are the full CLI's own (`./cli/main.ts` dispatches to the same
|
|
18
|
+
* functions), parsed by the same `parseArgs`, so flags, output, exit codes and
|
|
19
|
+
* the ledgers each command writes are the same. What the runtime does not do:
|
|
20
|
+
* evaluate `chant.config.ts` (which needs a TypeScript loader). None of the
|
|
21
|
+
* four commands reads the config; the full CLI loads it only to check `--env`
|
|
22
|
+
* against the declared `environments`, a check the runtime skips.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { parseArgs } from "./cli/parse-args";
|
|
26
|
+
import { resolveCommand, type CommandDef, type ParsedArgs } from "./cli/registry";
|
|
27
|
+
import { formatError } from "./cli/format";
|
|
28
|
+
import { flushAndExit } from "./cli/flush";
|
|
29
|
+
import { CHANT_VERSION } from "./cli/version";
|
|
30
|
+
import { isEntryPoint } from "./cli/is-entry-point";
|
|
31
|
+
import { ENV_VAR } from "./env";
|
|
32
|
+
import { initRuntime } from "./runtime-adapter";
|
|
33
|
+
import { runOpWaveCommand } from "./cli/handlers/run-wave";
|
|
34
|
+
import { runResumeCommand } from "./cli/handlers/gate-resume";
|
|
35
|
+
import { runApprove } from "./cli/handlers/approve";
|
|
36
|
+
import { runWorkspacePoints } from "./workspace/points-cli";
|
|
37
|
+
|
|
38
|
+
/** The commands the runtime carries, under the names the full CLI registers them by. */
|
|
39
|
+
export const RUNTIME_COMMANDS: CommandDef[] = [
|
|
40
|
+
{ name: "run wave", handler: runOpWaveCommand },
|
|
41
|
+
{ name: "run resume", handler: runResumeCommand },
|
|
42
|
+
{ name: "approve", handler: runApprove },
|
|
43
|
+
{ name: "workspace points", handler: runWorkspacePoints },
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const HELP = `
|
|
47
|
+
chant runtime ${CHANT_VERSION} - the wave-job commands of chant, in one file
|
|
48
|
+
|
|
49
|
+
Usage: node wave-runtime.mjs <command> [options]
|
|
50
|
+
|
|
51
|
+
Commands:
|
|
52
|
+
run wave --spec <file> --wave <k> Plan, gate and apply wave k of an Op waves spec
|
|
53
|
+
(--decide, --share <i>, --record-plans, --base <ref>, --json)
|
|
54
|
+
run resume Start the CI jobs that wait at gates whose approval arrived
|
|
55
|
+
(--gate <op>/<gate>, --dry-run, --json)
|
|
56
|
+
approve <op> <gate> Record a gate's resolution on the lifecycle ledger
|
|
57
|
+
(--actor, --plan, --note, --url, --sign, --expire, --resume, ...)
|
|
58
|
+
workspace points <verb> Ask, answer and list decision points
|
|
59
|
+
|
|
60
|
+
Flags, output, exit codes and ledger formats are the full chant CLI's;
|
|
61
|
+
see "chant --help" in @intentius/chant for every flag. This runtime does
|
|
62
|
+
not evaluate chant.config.ts, so --env is not checked against the
|
|
63
|
+
declared environments.
|
|
64
|
+
`;
|
|
65
|
+
|
|
66
|
+
/** Parse, dispatch and return the exit code. Exported for tests. */
|
|
67
|
+
export async function runRuntime(argv: string[]): Promise<number> {
|
|
68
|
+
let args: ParsedArgs;
|
|
69
|
+
try {
|
|
70
|
+
args = parseArgs(argv);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.error(formatError({ message: err instanceof Error ? err.message : String(err) }));
|
|
73
|
+
return 1;
|
|
74
|
+
}
|
|
75
|
+
const match = resolveCommand(args, RUNTIME_COMMANDS);
|
|
76
|
+
if (args.version && (!args.command || match)) {
|
|
77
|
+
console.log(CHANT_VERSION);
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
if (args.help || !args.command) {
|
|
81
|
+
console.log(HELP);
|
|
82
|
+
return args.help ? 0 : 1;
|
|
83
|
+
}
|
|
84
|
+
if (!match) {
|
|
85
|
+
const name = args.path && args.path !== "." ? `${args.command} ${args.path}` : args.command;
|
|
86
|
+
console.error(formatError({
|
|
87
|
+
message: `"${name}" is not part of chant's wave-job runtime`,
|
|
88
|
+
hint: "It runs run wave, run resume, approve and workspace points. Every other command needs the full @intentius/chant CLI.",
|
|
89
|
+
}));
|
|
90
|
+
return 1;
|
|
91
|
+
}
|
|
92
|
+
if (args.env) process.env[ENV_VAR] = args.env;
|
|
93
|
+
initRuntime();
|
|
94
|
+
return match.def.handler({ args, plugins: [], serializers: [] });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (isEntryPoint(process.argv[1], import.meta.url)) {
|
|
98
|
+
runRuntime(process.argv.slice(2)).then(flushAndExit, async (err) => {
|
|
99
|
+
const verbose = process.argv.includes("--verbose") || process.argv.includes("-v");
|
|
100
|
+
if (verbose && err instanceof Error && err.stack) console.error(err.stack);
|
|
101
|
+
else console.error(formatError({ message: err instanceof Error ? err.message : String(err) }));
|
|
102
|
+
await flushAndExit(1);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Ajv 2020-12 validator class, loaded on first use: ajv costs start-up
|
|
3
|
+
* time, and most commands validate nothing with it. One loader for every
|
|
4
|
+
* schema check in workspace/, so the slim wave-job runtime (#3896,
|
|
5
|
+
* `../../scripts/build-wave-runtime.mjs`) can swap in a bundled ajv here
|
|
6
|
+
* instead of a `require` resolved next to an installed chant.
|
|
7
|
+
*/
|
|
8
|
+
import { createRequire } from "node:module";
|
|
9
|
+
|
|
10
|
+
export type Ajv2020Class = new (opts: object) => { compile(schema: object): unknown };
|
|
11
|
+
|
|
12
|
+
export function loadAjv2020(): Ajv2020Class {
|
|
13
|
+
const require = createRequire(import.meta.url);
|
|
14
|
+
// ajv is CommonJS; its class is the default export, or that export's own default.
|
|
15
|
+
const mod = require("ajv/dist/2020") as { default?: unknown };
|
|
16
|
+
return (mod.default ?? mod) as Ajv2020Class;
|
|
17
|
+
}
|
|
@@ -16,15 +16,14 @@
|
|
|
16
16
|
* runs. The level-0 goldens (#2526) fail if a level-0 command loads it.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import { readFileSync } from "node:fs";
|
|
20
|
-
import { createRequire } from "node:module";
|
|
21
|
-
import { fileURLToPath } from "node:url";
|
|
22
19
|
import schema from "./declaration.schema.json" with { type: "json" };
|
|
23
20
|
import { expandGlob } from "./glob";
|
|
24
21
|
import { EXAMPLES_KIND, holdsChantProject } from "./kinds";
|
|
25
22
|
import { parseJsonText, pointerToken, type TextLocation } from "./jsonc";
|
|
26
23
|
import type { ReasonCode } from "./reason-codes";
|
|
27
24
|
import { joinPath, type WorkspaceTree } from "./tree";
|
|
25
|
+
import { loadAjv2020 } from "./ajv2020";
|
|
26
|
+
import { readChantPackageVersion } from "../package-version";
|
|
28
27
|
|
|
29
28
|
export const DECLARATION_SCHEMA_ID = schema.$id;
|
|
30
29
|
export const DECLARATION_FILES = ["chant.workspace.json", "chant.workspace.jsonc"] as const;
|
|
@@ -601,9 +600,7 @@ let readerVersionCache: string | undefined;
|
|
|
601
600
|
* well under a millisecond.
|
|
602
601
|
*/
|
|
603
602
|
export function readerVersion(): string {
|
|
604
|
-
readerVersionCache ??= (
|
|
605
|
-
JSON.parse(readFileSync(fileURLToPath(new URL("../../package.json", import.meta.url)), "utf-8")) as { version: string }
|
|
606
|
-
).version;
|
|
603
|
+
readerVersionCache ??= readChantPackageVersion();
|
|
607
604
|
return readerVersionCache;
|
|
608
605
|
}
|
|
609
606
|
|
|
@@ -638,10 +635,7 @@ type Validate = ((data: unknown) => boolean) & { errors?: AjvError[] | null };
|
|
|
638
635
|
let compiled: Validate | undefined;
|
|
639
636
|
function validator(): Validate {
|
|
640
637
|
if (compiled) return compiled;
|
|
641
|
-
const
|
|
642
|
-
// ajv is CommonJS; its class is the default export, or that export's own default.
|
|
643
|
-
const mod = require("ajv/dist/2020") as { default?: unknown };
|
|
644
|
-
const Ajv = (mod.default ?? mod) as new (opts: object) => { compile(s: object): Validate };
|
|
638
|
+
const Ajv = loadAjv2020() as new (opts: object) => { compile(s: object): Validate };
|
|
645
639
|
compiled = new Ajv({ allErrors: true, strict: true }).compile(schema);
|
|
646
640
|
return compiled;
|
|
647
641
|
}
|
package/src/workspace/kinds.ts
CHANGED
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import { readFileSync } from "node:fs";
|
|
21
|
-
import { createRequire } from "node:module";
|
|
22
21
|
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
23
22
|
import schema from "./workspace-kinds.schema.json" with { type: "json" };
|
|
24
23
|
import type { WorkspaceTree } from "./tree";
|
|
25
24
|
import { joinPath, skippedDir } from "./tree";
|
|
26
25
|
import { checkPinIntegrity } from "./pin-integrity";
|
|
27
26
|
import { dataExportTarget, findInstalledPackage } from "./class-data";
|
|
27
|
+
import { loadAjv2020 } from "./ajv2020";
|
|
28
28
|
|
|
29
29
|
export const KINDS_SCHEMA_ID = schema.$id;
|
|
30
30
|
|
|
@@ -353,10 +353,7 @@ type Validate = ((data: unknown) => boolean) & { errors?: AjvError[] | null };
|
|
|
353
353
|
let compiled: Validate | undefined;
|
|
354
354
|
function validator(): Validate {
|
|
355
355
|
if (compiled) return compiled;
|
|
356
|
-
const
|
|
357
|
-
// ajv is CommonJS; its class is the default export, or that export's own default.
|
|
358
|
-
const mod = require("ajv/dist/2020") as { default?: unknown };
|
|
359
|
-
const Ajv = (mod.default ?? mod) as new (opts: object) => { compile(s: object): Validate };
|
|
356
|
+
const Ajv = loadAjv2020() as new (opts: object) => { compile(s: object): Validate };
|
|
360
357
|
compiled = new Ajv({ allErrors: true, strict: true }).compile(schema);
|
|
361
358
|
return compiled;
|
|
362
359
|
}
|
|
@@ -26,6 +26,7 @@ import { z } from "zod";
|
|
|
26
26
|
import { LockError, type Lineage } from "./lineage-lock";
|
|
27
27
|
import { compareVersions, formatVersion, parseVersion, satisfies, validateRange, VersionRangeError, type Version } from "./lineage-version";
|
|
28
28
|
import { ensureTypeScriptLoader } from "../ts-loader";
|
|
29
|
+
import { esModuleNamespace } from "../module-interop";
|
|
29
30
|
|
|
30
31
|
/** Where a template keeps its migrations, relative to the template's directory. */
|
|
31
32
|
export const MIGRATIONS_DIR = ".chant/migrations";
|
|
@@ -283,7 +284,7 @@ export async function runMigration(m: LoadedMigration, opts: RunMigrationOptions
|
|
|
283
284
|
writeFileSync(abs, data);
|
|
284
285
|
}
|
|
285
286
|
ensureTypeScriptLoader();
|
|
286
|
-
const mod = (await import(pathToFileURL(file).href)) as { default?: unknown };
|
|
287
|
+
const mod = esModuleNamespace((await import(pathToFileURL(file).href)) as { default?: unknown });
|
|
287
288
|
if (typeof mod.default !== "function") throw new MigrationError(`${migration.id}: ${body.module} has no default export function`);
|
|
288
289
|
await (mod.default as (ctx: { dir: string }) => unknown)({ dir: opts.dir });
|
|
289
290
|
} else {
|
package/src/workspace/points.ts
CHANGED
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
import { createHash } from "node:crypto";
|
|
36
|
-
import { createRequire } from "node:module";
|
|
37
36
|
import { dirname, posix, relative, resolve, sep } from "node:path";
|
|
38
37
|
import schema from "./decision-points.schema.json" with { type: "json" };
|
|
39
38
|
import type { ReasonCode } from "./reason-codes";
|
|
40
39
|
import type { RecordSource } from "./record-source";
|
|
41
40
|
import type { LoadedRecordKind, ReadRecordsOptions, RecordEntry } from "./records";
|
|
41
|
+
import { loadAjv2020 } from "./ajv2020";
|
|
42
42
|
|
|
43
43
|
export const DECISION_POINTS_SCHEMA_ID = schema.$id;
|
|
44
44
|
|
|
@@ -200,10 +200,7 @@ type Validate = ((data: unknown) => boolean) & { errors?: AjvError[] | null };
|
|
|
200
200
|
let compiled: Validate | undefined;
|
|
201
201
|
function validator(): Validate {
|
|
202
202
|
if (compiled) return compiled;
|
|
203
|
-
const
|
|
204
|
-
// ajv is CommonJS; its class is the default export, or that export's own default.
|
|
205
|
-
const mod = require("ajv/dist/2020") as { default?: unknown };
|
|
206
|
-
const Ajv = (mod.default ?? mod) as new (opts: object) => { compile(s: object): Validate };
|
|
203
|
+
const Ajv = loadAjv2020() as new (opts: object) => { compile(s: object): Validate };
|
|
207
204
|
compiled = new Ajv({ allErrors: true, strict: false }).compile(schema);
|
|
208
205
|
return compiled;
|
|
209
206
|
}
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
* installed package, which must be at the version the base pins.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import { createRequire } from "node:module";
|
|
26
25
|
import { checkClassData, diskFiles, mergePinClasses, readClassFiles, type ClassData, type PackageFiles, type PinClassRead } from "./class-data";
|
|
27
26
|
import { pinnedPackageDir, type KindLoadProblem, type PinLike } from "./kinds";
|
|
28
27
|
import schema from "./workspace-principals.schema.json" with { type: "json" };
|
|
29
28
|
import type { TrustPolicy } from "./trust/policy";
|
|
30
29
|
import { joinPath, type WorkspaceTree } from "./tree";
|
|
31
30
|
import { CORE_CLASSES, CORE_PRINCIPAL_CLASSES, grantedClasses, type PrincipalClass } from "./identity-gate-rule";
|
|
31
|
+
import { loadAjv2020 } from "./ajv2020";
|
|
32
32
|
|
|
33
33
|
export const PRINCIPALS_SCHEMA_ID = schema.$id;
|
|
34
34
|
|
|
@@ -99,10 +99,7 @@ type Validate = ((data: unknown) => boolean) & { errors?: AjvError[] | null };
|
|
|
99
99
|
let compiled: Validate | undefined;
|
|
100
100
|
function validator(): Validate {
|
|
101
101
|
if (compiled) return compiled;
|
|
102
|
-
const
|
|
103
|
-
// ajv is CommonJS; its class is the default export, or that export's own default.
|
|
104
|
-
const mod = require("ajv/dist/2020") as { default?: unknown };
|
|
105
|
-
const Ajv = (mod.default ?? mod) as new (opts: object) => { compile(s: object): Validate };
|
|
102
|
+
const Ajv = loadAjv2020() as new (opts: object) => { compile(s: object): Validate };
|
|
106
103
|
compiled = new Ajv({ allErrors: true, strict: true }).compile(schema);
|
|
107
104
|
return compiled;
|
|
108
105
|
}
|