@intentius/chant 0.124.57 → 0.124.59
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/ci-product-words.d.ts +47 -2
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +59 -1
- package/dist/ci-product.d.ts +26 -2
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +25 -2
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +1 -1
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +5 -1
- package/dist/cli/handlers/init.d.ts.map +1 -1
- package/dist/cli/handlers/init.js +16 -0
- package/dist/cli/handlers/lifecycle-drift.d.ts +2 -1
- package/dist/cli/handlers/lifecycle-drift.d.ts.map +1 -1
- package/dist/cli/handlers/lifecycle-drift.js +4 -2
- package/dist/cli/handlers/lock.d.ts.map +1 -1
- package/dist/cli/handlers/lock.js +45 -2
- package/dist/cli/handlers/serve.d.ts.map +1 -1
- package/dist/cli/handlers/serve.js +9 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +11 -3
- package/dist/cli/mcp/product-tools.d.ts +40 -7
- package/dist/cli/mcp/product-tools.d.ts.map +1 -1
- package/dist/cli/mcp/product-tools.js +58 -15
- package/dist/cli/mcp/read-only.d.ts +2 -1
- package/dist/cli/mcp/read-only.d.ts.map +1 -1
- package/dist/cli/mcp/read-only.js +2 -1
- package/dist/cli/mcp/server.d.ts +11 -0
- package/dist/cli/mcp/server.d.ts.map +1 -1
- package/dist/cli/mcp/server.js +15 -3
- package/dist/cli/mcp-config.d.ts +4 -1
- package/dist/cli/mcp-config.d.ts.map +1 -1
- package/dist/cli/mcp-config.js +6 -2
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +27 -0
- package/dist/cli/registry.d.ts +14 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/pr-pipeline.d.ts +56 -0
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +55 -2
- package/dist/components/product-pipeline.d.ts +18 -1
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +8 -2
- package/dist/drift-record.d.ts +5 -0
- package/dist/drift-record.d.ts.map +1 -1
- package/dist/e2e-harness/driver.d.ts.map +1 -1
- package/dist/e2e-harness/driver.js +97 -0
- package/dist/e2e-harness/forgejo.d.ts +5 -1
- package/dist/e2e-harness/forgejo.d.ts.map +1 -1
- package/dist/e2e-harness/forgejo.js +35 -0
- package/dist/e2e-harness/index.d.ts +7 -0
- package/dist/e2e-harness/index.d.ts.map +1 -1
- package/dist/e2e-harness/index.js +10 -1
- package/dist/e2e-harness/ports.d.ts +31 -0
- package/dist/e2e-harness/ports.d.ts.map +1 -1
- package/dist/e2e-harness/scenario.d.ts.map +1 -1
- package/dist/e2e-harness/scenario.js +9 -5
- package/dist/e2e-harness/schemas/e2e-scenario.schema.json +43 -3
- package/dist/e2e-harness/schemas/index.d.ts +22 -1
- package/dist/e2e-harness/schemas/index.d.ts.map +1 -1
- package/dist/e2e-harness/schemas/index.js +1 -1
- package/dist/e2e-harness/steps.d.ts.map +1 -1
- package/dist/e2e-harness/steps.js +4 -0
- package/dist/lifecycle/lock-beat.d.ts +27 -0
- package/dist/lifecycle/lock-beat.d.ts.map +1 -0
- package/dist/lifecycle/lock-beat.js +84 -0
- package/dist/lifecycle/resource-lock.d.ts +54 -1
- package/dist/lifecycle/resource-lock.d.ts.map +1 -1
- package/dist/lifecycle/resource-lock.js +128 -7
- package/dist/mcp/types.d.ts +9 -0
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/op/activities/activity-contracts.d.ts +4 -4
- package/dist/op/index.d.ts +1 -1
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +1 -1
- package/dist/op/op-waves-notify.d.ts.map +1 -1
- package/dist/op/op-waves-notify.js +11 -0
- package/dist/op/op-waves-run.d.ts +28 -1
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +92 -7
- package/dist/op/op-waves.d.ts +12 -1
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +9 -2
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/template-request/index.d.ts +9 -0
- package/dist/template-request/index.d.ts.map +1 -0
- package/dist/template-request/index.js +8 -0
- package/dist/template-request/request-body.d.ts +21 -0
- package/dist/template-request/request-body.d.ts.map +1 -0
- package/dist/template-request/request-body.js +86 -0
- package/dist/template-request/template-request.d.ts +100 -0
- package/dist/template-request/template-request.d.ts.map +1 -0
- package/dist/template-request/template-request.js +149 -0
- package/dist/template-request/template-request.schema.json +100 -0
- package/dist/template-request/template-spec.d.ts +83 -0
- package/dist/template-request/template-spec.d.ts.map +1 -0
- package/dist/template-request/template-spec.js +146 -0
- package/dist/template-request/template.schema.json +114 -0
- package/dist/template-request/validate.d.ts +4 -0
- package/dist/template-request/validate.d.ts.map +1 -0
- package/dist/template-request/validate.js +21 -0
- package/dist/wave-runtime.mjs +298 -298
- package/dist/workspace/drift-cli.d.ts +13 -1
- package/dist/workspace/drift-cli.d.ts.map +1 -1
- package/dist/workspace/drift-cli.js +19 -3
- package/package.json +8 -1
- package/src/ci-product-words.test.ts +23 -0
- package/src/ci-product-words.ts +68 -3
- package/src/ci-product.ts +31 -1
- package/src/cli/commands/init.ts +3 -1
- package/src/cli/handlers/build.ts +5 -1
- package/src/cli/handlers/init.ts +18 -0
- package/src/cli/handlers/lifecycle-drift.test.ts +52 -0
- package/src/cli/handlers/lifecycle-drift.ts +4 -2
- package/src/cli/handlers/lock.ts +41 -2
- package/src/cli/handlers/serve.ts +9 -0
- package/src/cli/main.ts +11 -3
- package/src/cli/mcp/product-tools.test.ts +56 -1
- package/src/cli/mcp/product-tools.ts +66 -15
- package/src/cli/mcp/read-only.ts +2 -1
- package/src/cli/mcp/server.ts +20 -5
- package/src/cli/mcp-config.test.ts +52 -2
- package/src/cli/mcp-config.ts +6 -3
- package/src/cli/parse-args.ts +19 -0
- package/src/cli/registry.ts +14 -0
- package/src/components/pr-pipeline.ts +87 -2
- package/src/components/product-actions.test.ts +76 -0
- package/src/components/product-pipeline.ts +21 -2
- package/src/drift-record.ts +5 -0
- package/src/e2e-harness/driver.test.ts +163 -0
- package/src/e2e-harness/driver.ts +86 -1
- package/src/e2e-harness/forgejo.ts +42 -1
- package/src/e2e-harness/index.ts +11 -1
- package/src/e2e-harness/ports.ts +33 -0
- package/src/e2e-harness/scenario.ts +8 -6
- package/src/e2e-harness/schemas/README.md +11 -2
- package/src/e2e-harness/schemas/e2e-scenario.schema.json +43 -3
- package/src/e2e-harness/schemas/index.ts +5 -1
- package/src/e2e-harness/schemas.test.ts +44 -1
- package/src/e2e-harness/steps.ts +4 -0
- package/src/lifecycle/lock-beat.ts +99 -0
- package/src/lifecycle/resource-lock-liveness.test.ts +289 -0
- package/src/lifecycle/resource-lock.ts +143 -8
- package/src/mcp/types.ts +9 -0
- package/src/op/index.ts +1 -0
- package/src/op/op-waves-notify.ts +11 -0
- package/src/op/op-waves-preview.test.ts +167 -0
- package/src/op/op-waves-run.ts +116 -8
- package/src/op/op-waves.ts +20 -3
- package/src/release-floors.ts +1 -1
- package/src/template-request/__fixtures__/request-body.md +41 -0
- package/src/template-request/index.ts +8 -0
- package/src/template-request/request-body.ts +91 -0
- package/src/template-request/template-request.schema.json +100 -0
- package/src/template-request/template-request.test.ts +315 -0
- package/src/template-request/template-request.ts +234 -0
- package/src/template-request/template-spec.ts +176 -0
- package/src/template-request/template.schema.json +114 -0
- package/src/template-request/validate.ts +28 -0
- package/src/workspace/drift-cli.test.ts +35 -1
- package/src/workspace/drift-cli.ts +21 -3
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* template.yml, version 1 (#4651, ruling B of #4642): what a template asks
|
|
3
|
+
* for when someone requests an app or an add-on from it. The file sits in
|
|
4
|
+
* the template's signed release; a form shows one field per input, and an
|
|
5
|
+
* agent or a command line reads the same list.
|
|
6
|
+
*
|
|
7
|
+
* Each input has an engine-neutral kind (`string`, `number`, `bool`,
|
|
8
|
+
* `list`, `map`, `object`, with `of` naming a list's or map's element kind).
|
|
9
|
+
* Core checks request values against the kind and never parses an engine's
|
|
10
|
+
* own type syntax; an engine maps the kinds to its types (the terraform
|
|
11
|
+
* lexicon, #4652).
|
|
12
|
+
*
|
|
13
|
+
* In an add-on request, a value `app.<output>` names an output of the app's
|
|
14
|
+
* own module, whatever the input's kind. Core accepts it as is and leaves
|
|
15
|
+
* the engine's renderer to resolve it and refuse an output the module lacks.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import schema from "./template.schema.json" with { type: "json" };
|
|
19
|
+
import { parseYAMLDocument, YAMLParseError } from "../yaml";
|
|
20
|
+
import { schemaProblems } from "./validate";
|
|
21
|
+
|
|
22
|
+
/** The template.yml `$schema`, when the file names one. */
|
|
23
|
+
export const TEMPLATE_SPEC_SCHEMA_ID: string = schema.$id;
|
|
24
|
+
|
|
25
|
+
/** The template.yml contract version. */
|
|
26
|
+
export const TEMPLATE_SPEC_CONTRACT = 1;
|
|
27
|
+
|
|
28
|
+
/** A kind whose values are JSON scalars. */
|
|
29
|
+
export type TemplateScalarKind = "string" | "number" | "bool";
|
|
30
|
+
|
|
31
|
+
/** An input's engine-neutral kind. */
|
|
32
|
+
export type TemplateInputKind = TemplateScalarKind | "list" | "map" | "object";
|
|
33
|
+
|
|
34
|
+
/** Every input kind, in the order the schema lists them. */
|
|
35
|
+
export const TEMPLATE_INPUT_KINDS: readonly TemplateInputKind[] = ["string", "number", "bool", "list", "map", "object"];
|
|
36
|
+
|
|
37
|
+
/** One input of a template. */
|
|
38
|
+
export interface TemplateInput {
|
|
39
|
+
name: string;
|
|
40
|
+
kind: TemplateInputKind;
|
|
41
|
+
/** For a list or a map: the kind of each element or value. Absent: any JSON value. */
|
|
42
|
+
of?: TemplateScalarKind;
|
|
43
|
+
/** The form field's label. Absent: the name. */
|
|
44
|
+
label?: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
/** The value a request that gives none takes. */
|
|
47
|
+
default?: unknown;
|
|
48
|
+
/** Absent: true when there is no default. */
|
|
49
|
+
required?: boolean;
|
|
50
|
+
/** A secret, which a request never carries. */
|
|
51
|
+
sensitive?: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** A parsed template.yml. */
|
|
55
|
+
export interface TemplateSpec {
|
|
56
|
+
$schema?: string;
|
|
57
|
+
contract: 1;
|
|
58
|
+
/** Absent: `app`. */
|
|
59
|
+
kind?: "app" | "addon";
|
|
60
|
+
description: string;
|
|
61
|
+
inputs: TemplateInput[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Thrown when a template.yml is not valid, with one line per problem. */
|
|
65
|
+
export class TemplateSpecError extends Error {
|
|
66
|
+
constructor(public readonly problems: string[]) {
|
|
67
|
+
super(`template.yml is not valid: ${problems.join("; ")}`);
|
|
68
|
+
this.name = "TemplateSpecError";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Whether a request must give `input`: its own `required`, else true when it has no default. */
|
|
73
|
+
export function inputRequired(input: TemplateInput): boolean {
|
|
74
|
+
return input.required ?? !("default" in input);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The JSON type a value has, as a problem line names it. */
|
|
78
|
+
export function jsonKindOf(value: unknown): string {
|
|
79
|
+
if (value === null) return "null";
|
|
80
|
+
if (Array.isArray(value)) return "list";
|
|
81
|
+
if (typeof value === "boolean") return "bool";
|
|
82
|
+
if (typeof value === "object") return "object";
|
|
83
|
+
return typeof value;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const isPlainObject = (v: unknown): v is Record<string, unknown> => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
87
|
+
|
|
88
|
+
function scalarFits(kind: TemplateScalarKind, value: unknown): boolean {
|
|
89
|
+
if (kind === "string") return typeof value === "string";
|
|
90
|
+
if (kind === "number") return typeof value === "number" && Number.isFinite(value);
|
|
91
|
+
return typeof value === "boolean";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** An app-output reference, `app.<output>`, with the output in group 1. */
|
|
95
|
+
export const APP_OUTPUT_REF: RegExp = /^app\.([A-Za-z_][A-Za-z0-9_-]*)$/;
|
|
96
|
+
|
|
97
|
+
/** The output an `app.<output>` value names, or undefined when `value` is not one. */
|
|
98
|
+
export function appOutputRef(value: unknown): string | undefined {
|
|
99
|
+
return typeof value === "string" ? APP_OUTPUT_REF.exec(value)?.[1] : undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** True when `value` is an app-output reference, `app.<output>`. */
|
|
103
|
+
export function isAppOutputRef(value: unknown): value is string {
|
|
104
|
+
return appOutputRef(value) !== undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Why `value` is not of `input`'s kind, or undefined when it is. A null is
|
|
109
|
+
* never of a kind: a request that wants the default leaves the input out.
|
|
110
|
+
*/
|
|
111
|
+
export function inputKindProblem(input: Pick<TemplateInput, "kind" | "of">, value: unknown): string | undefined {
|
|
112
|
+
const want = input.of ? `${input.kind} of ${input.of}` : input.kind;
|
|
113
|
+
const bad = (detail?: string) => `is ${detail ?? jsonKindOf(value)}, and the input is a ${want}`;
|
|
114
|
+
switch (input.kind) {
|
|
115
|
+
case "string":
|
|
116
|
+
case "number":
|
|
117
|
+
case "bool":
|
|
118
|
+
return scalarFits(input.kind, value) ? undefined : bad();
|
|
119
|
+
case "list": {
|
|
120
|
+
if (!Array.isArray(value)) return bad();
|
|
121
|
+
if (!input.of) return undefined;
|
|
122
|
+
const at = value.findIndex((v) => !scalarFits(input.of!, v));
|
|
123
|
+
return at < 0 ? undefined : bad(`a list whose element ${at} is ${jsonKindOf(value[at])}`);
|
|
124
|
+
}
|
|
125
|
+
case "map": {
|
|
126
|
+
if (!isPlainObject(value)) return bad();
|
|
127
|
+
if (!input.of) return undefined;
|
|
128
|
+
const key = Object.keys(value).find((k) => !scalarFits(input.of!, value[k]));
|
|
129
|
+
return key === undefined ? undefined : bad(`a map whose ${JSON.stringify(key)} is ${jsonKindOf(value[key])}`);
|
|
130
|
+
}
|
|
131
|
+
case "object":
|
|
132
|
+
return isPlainObject(value) ? undefined : bad();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Every problem with a template.yml document, one line each: the schema's,
|
|
138
|
+
* then two inputs with one name, a default that is not of its input's kind,
|
|
139
|
+
* and an input both required and given a default.
|
|
140
|
+
*/
|
|
141
|
+
export function templateSpecProblems(doc: unknown): string[] {
|
|
142
|
+
const problems = schemaProblems(TEMPLATE_SPEC_SCHEMA_ID, doc);
|
|
143
|
+
if (problems.length > 0) return problems;
|
|
144
|
+
const spec = doc as TemplateSpec;
|
|
145
|
+
const seen = new Set<string>();
|
|
146
|
+
spec.inputs.forEach((input, i) => {
|
|
147
|
+
const where = `/inputs/${i} (${input.name})`;
|
|
148
|
+
if (seen.has(input.name)) problems.push(`${where} repeats the name ${JSON.stringify(input.name)}`);
|
|
149
|
+
seen.add(input.name);
|
|
150
|
+
if ("default" in input) {
|
|
151
|
+
const p = inputKindProblem(input, input.default);
|
|
152
|
+
if (p) problems.push(`${where} default ${p}`);
|
|
153
|
+
if (input.required === true) problems.push(`${where} is required and has a default; an input with a default is optional`);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
return problems;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Read a template.yml from its YAML text or its parsed value. Throws
|
|
161
|
+
* {@link TemplateSpecError} when it does not parse or is not valid.
|
|
162
|
+
*/
|
|
163
|
+
export function parseTemplateSpec(text: string | unknown): TemplateSpec {
|
|
164
|
+
let doc: unknown = text;
|
|
165
|
+
if (typeof text === "string") {
|
|
166
|
+
try {
|
|
167
|
+
doc = parseYAMLDocument(text);
|
|
168
|
+
} catch (e) {
|
|
169
|
+
if (e instanceof YAMLParseError) throw new TemplateSpecError([`not YAML: ${e.message}`]);
|
|
170
|
+
throw e;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const problems = templateSpecProblems(doc);
|
|
174
|
+
if (problems.length > 0) throw new TemplateSpecError(problems);
|
|
175
|
+
return doc as TemplateSpec;
|
|
176
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://intentius.io/chant/schemas/template-request/v1/template.schema.json",
|
|
4
|
+
"title": "chant template",
|
|
5
|
+
"description": "template.yml, version 1 of its contract: what a template asks for when someone requests an app or an add-on from it. It sits in the template's signed release beside the code it describes. A form shows one field per input; an agent and a command line read the same list. Each input has an engine-neutral kind, and each engine maps the kinds to its own types. Readers ignore fields they do not know; a field is only ever added within a version.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": [
|
|
8
|
+
"contract",
|
|
9
|
+
"description",
|
|
10
|
+
"inputs"
|
|
11
|
+
],
|
|
12
|
+
"properties": {
|
|
13
|
+
"$schema": {
|
|
14
|
+
"const": "https://intentius.io/chant/schemas/template-request/v1/template.schema.json"
|
|
15
|
+
},
|
|
16
|
+
"contract": {
|
|
17
|
+
"const": 1
|
|
18
|
+
},
|
|
19
|
+
"kind": {
|
|
20
|
+
"enum": [
|
|
21
|
+
"app",
|
|
22
|
+
"addon"
|
|
23
|
+
],
|
|
24
|
+
"default": "app",
|
|
25
|
+
"description": "What a request makes from this template: a new app, or an add-on to an app that already exists."
|
|
26
|
+
},
|
|
27
|
+
"description": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"minLength": 1,
|
|
30
|
+
"description": "One or two sentences a person reads before requesting it."
|
|
31
|
+
},
|
|
32
|
+
"inputs": {
|
|
33
|
+
"type": "array",
|
|
34
|
+
"description": "The inputs, in the order a form shows them. Names are unique. An add-on request may give any input the string `app.<output>`, naming an output of the app's module, which the engine resolves.",
|
|
35
|
+
"items": {
|
|
36
|
+
"$ref": "#/$defs/input"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"$defs": {
|
|
41
|
+
"scalarKind": {
|
|
42
|
+
"enum": [
|
|
43
|
+
"string",
|
|
44
|
+
"number",
|
|
45
|
+
"bool"
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
"kind": {
|
|
49
|
+
"description": "An input's engine-neutral kind. string: a JSON string. number: a finite JSON number. bool: true or false. list: a JSON array, each element of kind `of` when given. map: a JSON object, each value of kind `of` when given. object: a JSON object with any fields. An engine maps each kind to one of its own types (Terraform: string, number, bool, list(<of>), map(<of>), and any for object or for a list or map without `of`).",
|
|
50
|
+
"enum": [
|
|
51
|
+
"string",
|
|
52
|
+
"number",
|
|
53
|
+
"bool",
|
|
54
|
+
"list",
|
|
55
|
+
"map",
|
|
56
|
+
"object"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"input": {
|
|
60
|
+
"type": "object",
|
|
61
|
+
"required": [
|
|
62
|
+
"name",
|
|
63
|
+
"kind"
|
|
64
|
+
],
|
|
65
|
+
"properties": {
|
|
66
|
+
"name": {
|
|
67
|
+
"type": "string",
|
|
68
|
+
"pattern": "^[A-Za-z_][A-Za-z0-9_-]*$",
|
|
69
|
+
"description": "The name a request gives the value under, and the variable the engine sets."
|
|
70
|
+
},
|
|
71
|
+
"kind": {
|
|
72
|
+
"$ref": "#/$defs/kind"
|
|
73
|
+
},
|
|
74
|
+
"of": {
|
|
75
|
+
"$ref": "#/$defs/scalarKind",
|
|
76
|
+
"description": "For a list or a map only: the kind of each element or value."
|
|
77
|
+
},
|
|
78
|
+
"label": {
|
|
79
|
+
"type": "string",
|
|
80
|
+
"minLength": 1,
|
|
81
|
+
"description": "The form field's label. Absent: the name."
|
|
82
|
+
},
|
|
83
|
+
"description": {
|
|
84
|
+
"type": "string",
|
|
85
|
+
"description": "Help text shown under the field."
|
|
86
|
+
},
|
|
87
|
+
"default": {
|
|
88
|
+
"description": "The value used when a request gives none. It must be of the input's kind. An input with a default is optional."
|
|
89
|
+
},
|
|
90
|
+
"required": {
|
|
91
|
+
"type": "boolean",
|
|
92
|
+
"description": "Whether a request must give a value. Absent: true when there is no default, false when there is. An input with a default cannot be required."
|
|
93
|
+
},
|
|
94
|
+
"sensitive": {
|
|
95
|
+
"type": "boolean",
|
|
96
|
+
"default": false,
|
|
97
|
+
"description": "A secret. A request never carries it, because the request is written into a pull request; the app reads it from its own secret store."
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"dependentSchemas": {
|
|
101
|
+
"of": {
|
|
102
|
+
"properties": {
|
|
103
|
+
"kind": {
|
|
104
|
+
"enum": [
|
|
105
|
+
"list",
|
|
106
|
+
"map"
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** One Ajv for the template-request/v1 schemas (template.yml and the request), compiled on first use. */
|
|
2
|
+
|
|
3
|
+
import requestSchema from "./template-request.schema.json" with { type: "json" };
|
|
4
|
+
import templateSchema from "./template.schema.json" with { type: "json" };
|
|
5
|
+
import { loadAjv2020 } from "../workspace/ajv2020";
|
|
6
|
+
|
|
7
|
+
type ValidateFn = ((data: unknown) => boolean) & { errors?: { instancePath: string; message?: string }[] | null };
|
|
8
|
+
|
|
9
|
+
interface AjvInstance {
|
|
10
|
+
addSchema(schema: object): unknown;
|
|
11
|
+
getSchema(id: string): unknown;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let ajv: AjvInstance | undefined;
|
|
15
|
+
|
|
16
|
+
/** The problems of `doc` against the schema `id`, one line each; empty when it is valid. */
|
|
17
|
+
export function schemaProblems(id: string, doc: unknown): string[] {
|
|
18
|
+
if (!ajv) {
|
|
19
|
+
const Ajv = loadAjv2020();
|
|
20
|
+
const made = new Ajv({ allErrors: true, strict: true }) as unknown as AjvInstance;
|
|
21
|
+
for (const s of [requestSchema, templateSchema]) made.addSchema(s);
|
|
22
|
+
ajv = made;
|
|
23
|
+
}
|
|
24
|
+
const fn = ajv.getSchema(id) as ValidateFn | undefined;
|
|
25
|
+
if (!fn) throw new Error(`no schema ${id}`);
|
|
26
|
+
if (fn(doc)) return [];
|
|
27
|
+
return (fn.errors ?? []).map((e) => `${e.instancePath || "/"} ${e.message ?? "is not valid"}`);
|
|
28
|
+
}
|
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
* and each member kind answers the reads the table says.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
7
10
|
import { describe, expect, test } from "vitest";
|
|
8
11
|
import { driftRecord, driftRecordLine, driftSettle, driftStart, type DriftRecord } from "../drift-record";
|
|
9
12
|
import { readContractSchema } from "./conformance";
|
|
10
|
-
import { DRIFT_CONTRACT_VERSION, DRIFT_ERROR_CODES, DRIFT_READS_BY_KIND, DRIFT_RESOURCE_KINDS, driftReadDocument } from "./drift-cli";
|
|
13
|
+
import { DRIFT_CONTRACT_VERSION, DRIFT_ERROR_CODES, DRIFT_READS_BY_KIND, DRIFT_RESOURCE_KINDS, DRIFT_STACK_KINDS, driftReadDocument, readWorkspaceDrift } from "./drift-cli";
|
|
14
|
+
import { parseArgs } from "../cli/parse-args";
|
|
11
15
|
import driftSchema from "./drift.schema.json";
|
|
12
16
|
|
|
13
17
|
const at = "2026-10-25T09:00:00Z";
|
|
@@ -63,3 +67,33 @@ describe("chant workspace drift's document", () => {
|
|
|
63
67
|
expect(DRIFT_ERROR_CODES).toContain("no-drift-read");
|
|
64
68
|
});
|
|
65
69
|
});
|
|
70
|
+
|
|
71
|
+
describe("chant workspace drift --stack", () => {
|
|
72
|
+
test("is parsed beside --member and --resource", () => {
|
|
73
|
+
const args = parseArgs(["workspace", "drift", "--member", "shop", "--stack", "prod-eu", "--resource", "urn:x"]);
|
|
74
|
+
expect(args.carveStack).toBe("prod-eu");
|
|
75
|
+
expect(args.members).toEqual(["shop"]);
|
|
76
|
+
expect(parseArgs(["workspace", "drift", "--member", "shop"]).carveStack).toBeUndefined();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("only a pulumi member keeps one export per stack", () => {
|
|
80
|
+
expect(DRIFT_STACK_KINDS).toEqual(["pulumi"]);
|
|
81
|
+
for (const kind of DRIFT_STACK_KINDS) expect(DRIFT_READS_BY_KIND[kind]).toBeDefined();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("a member of another kind refuses it with read-unsupported before anything runs", async () => {
|
|
85
|
+
const root = mkdtempSync(join(tmpdir(), "drift-stack-"));
|
|
86
|
+
try {
|
|
87
|
+
mkdirSync(join(root, "infra"));
|
|
88
|
+
writeFileSync(join(root, "chant.workspace.json"), JSON.stringify({ name: "acme", schema: 1, members: [{ name: "infra", dir: "infra", kind: "terraform" }] }));
|
|
89
|
+
const answer = await readWorkspaceDrift({ cwd: root, member: "infra", stack: "prod-eu" });
|
|
90
|
+
expect("error" in answer && answer.error.code).toBe("read-unsupported");
|
|
91
|
+
expect("error" in answer && answer.error.message).toMatch(/--stack reads a stack's export from the index store.*infra is kind terraform/);
|
|
92
|
+
const doc = driftReadDocument("infra", answer);
|
|
93
|
+
const { validate } = readContractSchema("drift");
|
|
94
|
+
expect(validate(doc), JSON.stringify(validate.errors)).toBe(true);
|
|
95
|
+
} finally {
|
|
96
|
+
rmSync(root, { recursive: true, force: true });
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `chant workspace drift [dir] --member <name> [--read <read>] [--resource
|
|
3
|
-
* <addr>] [--env <env>] [--stream] [-o <file>]` (behold#995): one member's
|
|
3
|
+
* <addr>] [--stack <name>] [--env <env>] [--stream] [-o <file>]` (behold#995): one member's
|
|
4
4
|
* drift, read by the engine that owns it, as chant's drift record
|
|
5
5
|
* (`../drift-record.ts`, #4451).
|
|
6
6
|
*
|
|
@@ -13,6 +13,14 @@
|
|
|
13
13
|
* | `choudoufu` | `ownership` | the same, through `choudoufu live-plan -json` (and `live-ls`), or `--read plan` for live-plan with a plan beside it; `--resource <addr>` passes `choudoufu live-plan -resource=<addr>`'s stream through |
|
|
14
14
|
* | `pulumi` | `refresh` | `chant lifecycle drift` in the member's reader project: the pulumi lexicon's `readDrift`, `pulumi refresh --preview-only --json --target <urn>` per resource in the checked-in export, or `plunge drift --resource <urn> --stream` for a member on plunge; `--resource <urn>` reads that URN alone (#4455) |
|
|
15
15
|
*
|
|
16
|
+
* `--stack <name>` reads that stack's export for a `pulumi` member, from the
|
|
17
|
+
* index store (`refs/chant/snapshots`), where a member of several stacks
|
|
18
|
+
* holds one export each. Without it the member reads the export its store
|
|
19
|
+
* holds, which is the right one only for a member of one stack. A store with
|
|
20
|
+
* no export for the stack answers `no-drift-read`, naming the stack; it never
|
|
21
|
+
* falls back to another stack's export or the checked-in file. Any other kind
|
|
22
|
+
* answers `read-unsupported`.
|
|
23
|
+
*
|
|
16
24
|
* Any other kind has no drift read and answers `no-drift-read`. A member of
|
|
17
25
|
* a package's kind runs in the reader project `workspace graph` writes for it
|
|
18
26
|
* (`./kind-readers.ts`), under the member's own toolchain, so chant core
|
|
@@ -111,7 +119,10 @@ export const DRIFT_RESOURCE_KINDS: readonly string[] = ["choudoufu", "pulumi"];
|
|
|
111
119
|
const MEMBER_REFUSED_EXITS: readonly number[] = [1, 3];
|
|
112
120
|
|
|
113
121
|
const USAGE =
|
|
114
|
-
"chant workspace drift [dir] --member <name> [--read <state|plan|refresh|live-read|ownership>] [--resource <addr>] [--env <env>] [--components] [--stream] [-o <file>]";
|
|
122
|
+
"chant workspace drift [dir] --member <name> [--read <state|plan|refresh|live-read|ownership>] [--resource <addr>] [--stack <name>] [--env <env>] [--components] [--stream] [-o <file>]";
|
|
123
|
+
|
|
124
|
+
/** The kinds whose engine keeps one export per stack, for `--stack`. */
|
|
125
|
+
export const DRIFT_STACK_KINDS: readonly string[] = ["pulumi"];
|
|
115
126
|
|
|
116
127
|
/** The document `workspace drift` prints: a drift document with the read contract's head. */
|
|
117
128
|
export type WorkspaceDriftDocument = DriftDocument & {
|
|
@@ -127,6 +138,8 @@ export interface DriftQuery {
|
|
|
127
138
|
member: string;
|
|
128
139
|
read?: string;
|
|
129
140
|
resource?: string;
|
|
141
|
+
/** The stack whose stored export is read (`--stack`), for a pulumi member. */
|
|
142
|
+
stack?: string;
|
|
130
143
|
env?: string;
|
|
131
144
|
components?: boolean;
|
|
132
145
|
}
|
|
@@ -229,7 +242,7 @@ interface LexiconDiff {
|
|
|
229
242
|
/** The command line the member runs. */
|
|
230
243
|
function memberArgv(kind: string, query: DriftQuery, read: DriftRead): string[] {
|
|
231
244
|
if (kind === "chant") return ["lifecycle", "diff", query.env!, "--live", "--json"];
|
|
232
|
-
return ["lifecycle", "drift", ".", "--member", query.member, "--read", read, ...(query.resource !== undefined ? ["--resource", query.resource] : [])];
|
|
245
|
+
return ["lifecycle", "drift", ".", "--member", query.member, "--read", read, ...(query.resource !== undefined ? ["--resource", query.resource] : []), ...(query.stack !== undefined ? ["--stack", query.stack] : [])];
|
|
233
246
|
}
|
|
234
247
|
|
|
235
248
|
/**
|
|
@@ -255,6 +268,10 @@ export async function readWorkspaceDrift(query: DriftQuery): Promise<DriftReadRe
|
|
|
255
268
|
if (query.resource !== undefined && !DRIFT_RESOURCE_KINDS.includes(entry.kind)) {
|
|
256
269
|
throw new DriftReadFailure("resource-unsupported", `--resource reads one resource through choudoufu live-plan -resource, pulumi refresh --target or plunge drift --resource; ${query.member} is kind ${entry.kind}`);
|
|
257
270
|
}
|
|
271
|
+
if (query.stack !== undefined && !DRIFT_STACK_KINDS.includes(entry.kind)) {
|
|
272
|
+
throw new DriftReadFailure("read-unsupported", `--stack reads a stack's export from the index store, which a ${DRIFT_STACK_KINDS.join(" or ")} member has; ${query.member} is kind ${entry.kind}`);
|
|
273
|
+
}
|
|
274
|
+
if (query.stack !== undefined && query.stack.trim() === "") throw new DriftReadFailure("read-unsupported", "--stack needs a stack name");
|
|
258
275
|
if (entry.kind === "chant" && !query.env) throw new DriftReadFailure("env-required", `${query.member} is a chant member, read live through chant lifecycle diff <env> --live: add --env <env>`);
|
|
259
276
|
|
|
260
277
|
const { registry: kinds, problems } = loadKindRegistry(declaration.pins, located.rootOnDisk);
|
|
@@ -349,6 +366,7 @@ export async function runWorkspaceDrift(ctx: CommandContext): Promise<number> {
|
|
|
349
366
|
member: members[0],
|
|
350
367
|
...(args.driftRead !== undefined ? { read: args.driftRead } : {}),
|
|
351
368
|
...(args.resource !== undefined ? { resource: args.resource } : {}),
|
|
369
|
+
...(args.carveStack !== undefined ? { stack: args.carveStack } : {}),
|
|
352
370
|
...(args.env !== undefined ? { env: args.env } : {}),
|
|
353
371
|
...(args.components ? { components: true } : {}),
|
|
354
372
|
});
|