@elementumai/edk 0.10.3 → 0.11.0
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/README.md +11 -7
- package/dist-sdk/src/catalog/token.js +2 -1
- package/dist-sdk/src/core/wire/ref-serializer.js +26 -1
- package/dist-sdk/src/engine/build/context.d.ts +4 -0
- package/dist-sdk/src/engine/coverage-gaps.d.ts +2 -0
- package/dist-sdk/src/engine/coverage-gaps.js +3 -0
- package/dist-sdk/src/engine/ei/json-stream-reader.d.ts +43 -0
- package/dist-sdk/src/engine/ei/json-stream-reader.js +234 -0
- package/dist-sdk/src/engine/ei/run.d.ts +22 -0
- package/dist-sdk/src/engine/ei/run.js +99 -18
- package/dist-sdk/src/engine/ei/saved-plan.d.ts +16 -0
- package/dist-sdk/src/engine/ei/saved-plan.js +19 -0
- package/dist-sdk/src/engine/ei/state.d.ts +1 -1
- package/dist-sdk/src/engine/ei/state.js +17 -4
- package/dist-sdk/src/engine/progress.d.ts +3 -1
- package/dist-sdk/src/engine/progress.js +7 -3
- package/dist-sdk/src/engine/pull/authored-address.d.ts +15 -1
- package/dist-sdk/src/engine/pull/authored-address.js +180 -29
- package/dist-sdk/src/engine/pull/context.d.ts +52 -7
- package/dist-sdk/src/engine/pull/context.js +7 -4
- package/dist-sdk/src/engine/tf/index.d.ts +3 -2
- package/dist-sdk/src/engine/tf/index.js +3 -2
- package/dist-sdk/src/engine/tf/labels.d.ts +22 -0
- package/dist-sdk/src/engine/tf/labels.js +50 -0
- package/dist-sdk/src/engine/tf/model.d.ts +2 -0
- package/dist-sdk/src/engine/tf/model.js +26 -0
- package/dist-sdk/src/engine/tf/scan.d.ts +22 -0
- package/dist-sdk/src/engine/tf/scan.js +123 -0
- package/dist-sdk/src/engine/validation.d.ts +2 -0
- package/dist-sdk/src/engine/workspace/loader.d.ts +8 -0
- package/dist-sdk/src/engine/workspace/loader.js +20 -0
- package/dist-sdk/src/entities/access-policy/from-tf.d.ts +17 -0
- package/dist-sdk/src/entities/access-policy/from-tf.js +52 -24
- package/dist-sdk/src/entities/access-policy/member-list.d.ts +32 -0
- package/dist-sdk/src/entities/access-policy/member-list.js +57 -0
- package/dist-sdk/src/entities/access-policy/module.js +5 -0
- package/dist-sdk/src/entities/access-policy/to-tf.d.ts +4 -3
- package/dist-sdk/src/entities/access-policy/to-tf.js +21 -12
- package/dist-sdk/src/entities/agent/build.js +7 -5
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +2 -0
- package/dist-sdk/src/entities/agent/from-tf.js +13 -3
- package/dist-sdk/src/entities/agent/to-tf.d.ts +13 -11
- package/dist-sdk/src/entities/agent/to-tf.js +28 -17
- package/dist-sdk/src/entities/agent/tools.d.ts +8 -0
- package/dist-sdk/src/entities/agent/tools.js +6 -2
- package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/agent-tool/from-tf.js +2 -2
- package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +29 -0
- package/dist-sdk/src/entities/agent-tool/to-tf.js +65 -3
- package/dist-sdk/src/entities/agent-tool/types.d.ts +12 -8
- package/dist-sdk/src/entities/agent-tool/types.js +13 -9
- package/dist-sdk/src/entities/app/build.d.ts +11 -0
- package/dist-sdk/src/entities/app/build.js +1 -0
- package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +11 -7
- package/dist-sdk/src/entities/app/from-tf.js +19 -9
- package/dist-sdk/src/entities/app/to-tf.js +6 -4
- package/dist-sdk/src/entities/automation/build.d.ts +2 -7
- package/dist-sdk/src/entities/automation/build.js +55 -16
- package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +7 -4
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +7 -11
- package/dist-sdk/src/entities/automation/from-tf.d.ts +23 -1
- package/dist-sdk/src/entities/automation/from-tf.js +456 -34
- package/dist-sdk/src/entities/automation/index.d.ts +1 -1
- package/dist-sdk/src/entities/automation/module.d.ts +22 -2
- package/dist-sdk/src/entities/automation/module.js +273 -58
- package/dist-sdk/src/entities/automation/output-field-types.d.ts +8 -0
- package/dist-sdk/src/entities/automation/output-field-types.js +20 -0
- package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +24 -2
- package/dist-sdk/src/entities/automation/output-key-wire-name.js +72 -3
- package/dist-sdk/src/entities/automation/run-target.d.ts +59 -0
- package/dist-sdk/src/entities/automation/run-target.js +99 -0
- package/dist-sdk/src/entities/automation/script-code.d.ts +9 -0
- package/dist-sdk/src/entities/automation/script-code.js +24 -3
- package/dist-sdk/src/entities/automation/task-output-labels.d.ts +16 -0
- package/dist-sdk/src/entities/automation/task-output-labels.js +49 -0
- package/dist-sdk/src/entities/automation/tasks.d.ts +20 -8
- package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -3
- package/dist-sdk/src/entities/automation/to-tf.js +171 -58
- package/dist-sdk/src/entities/automation/triggers.d.ts +22 -3
- package/dist-sdk/src/entities/automation/triggers.js +40 -0
- package/dist-sdk/src/entities/automation/types.d.ts +21 -0
- package/dist-sdk/src/entities/automation/types.js +26 -0
- package/dist-sdk/src/entities/dashboard/from-tf.d.ts +11 -1
- package/dist-sdk/src/entities/dashboard/from-tf.js +57 -7
- package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
- package/dist-sdk/src/entities/dynamic-layout/build.d.ts +7 -2
- package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +3 -0
- package/dist-sdk/src/entities/dynamic-layout/from-tf.js +65 -19
- package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +4 -2
- package/dist-sdk/src/entities/dynamic-layout/to-tf.js +341 -32
- package/dist-sdk/src/entities/element/build.d.ts +10 -0
- package/dist-sdk/src/entities/element/build.js +1 -0
- package/dist-sdk/src/entities/element/from-tf.js +16 -9
- package/dist-sdk/src/entities/element/to-tf.js +6 -4
- package/dist-sdk/src/entities/field/from-tf.d.ts +24 -0
- package/dist-sdk/src/entities/field/from-tf.js +79 -1
- package/dist-sdk/src/entities/field/module.js +7 -0
- package/dist-sdk/src/entities/field/to-tf.d.ts +30 -1
- package/dist-sdk/src/entities/field/to-tf.js +51 -0
- package/dist-sdk/src/entities/file-reader/module.js +3 -3
- package/dist-sdk/src/entities/file-reader/to-tf.js +3 -3
- package/dist-sdk/src/entities/file-reader/types.d.ts +4 -16
- package/dist-sdk/src/entities/file-reader/types.js +7 -0
- package/dist-sdk/src/entities/org/group.d.ts +1 -0
- package/dist-sdk/src/entities/org/group.js +2 -1
- package/dist-sdk/src/entities/record-create-form/from-tf.d.ts +8 -0
- package/dist-sdk/src/entities/record-create-form/from-tf.js +10 -2
- package/dist-sdk/src/entities/record-create-form/to-tf.d.ts +2 -1
- package/dist-sdk/src/entities/record-create-form/to-tf.js +14 -2
- package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -0
- package/dist-sdk/src/entities/relationship/from-tf.js +88 -10
- package/dist-sdk/src/entities/relationship/to-tf.d.ts +3 -2
- package/dist-sdk/src/entities/relationship/to-tf.js +79 -8
- package/dist-sdk/src/entities/role/from-tf.js +24 -7
- package/dist-sdk/src/entities/role/to-tf.js +25 -7
- package/dist-sdk/src/entities/service-account/from-tf.js +2 -1
- package/dist-sdk/src/entities/service-account/module.js +15 -0
- package/dist-sdk/src/entities/service-account/to-tf.js +12 -4
- package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +1 -1
- package/dist-sdk/src/entities/shared/filters/tf-codec.js +12 -7
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +5 -2
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +8 -1
- package/dist-sdk/src/entities/skill/from-tf.js +10 -3
- package/dist-sdk/src/entities/skill/module.js +44 -2
- package/dist-sdk/src/entities/skill/to-tf.d.ts +8 -1
- package/dist-sdk/src/entities/skill/to-tf.js +23 -14
- package/dist-sdk/src/entities/skill/tools.d.ts +8 -0
- package/dist-sdk/src/entities/skill/tools.js +6 -2
- package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +8 -0
- package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -2
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +10 -2
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +18 -4
- package/dist-sdk/src/entities/view/custom-view-validate.js +6 -5
- package/dist-sdk/src/entities/view/from-tf.d.ts +68 -0
- package/dist-sdk/src/entities/view/from-tf.js +503 -25
- package/dist-sdk/src/entities/view/module.js +15 -0
- package/dist-sdk/src/entities/view/portable.d.ts +11 -0
- package/dist-sdk/src/entities/view/portable.js +47 -0
- package/dist-sdk/src/entities/view/to-tf.d.ts +4 -1
- package/dist-sdk/src/entities/view/to-tf.js +25 -7
- package/dist-sdk/src/entities/view/types.js +1 -1
- package/dist-sdk/src/entities/widget/build.d.ts +4 -3
- package/dist-sdk/src/entities/widget/from-tf.d.ts +3 -0
- package/dist-sdk/src/entities/widget/from-tf.js +100 -3
- package/dist-sdk/src/entities/widget/to-tf.d.ts +16 -1
- package/dist-sdk/src/entities/widget/to-tf.js +77 -14
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +27 -8
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
- package/dist-sdk/src/graph/field-resource-types.d.ts +2 -0
- package/dist-sdk/src/graph/field-resource-types.js +11 -0
- package/dist-sdk/src/graph/index.d.ts +28 -3
- package/dist-sdk/src/graph/index.js +12 -2
- package/dist-sdk/src/graph/types.d.ts +164 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -191,10 +191,11 @@ elementum migrate provider-source [orgRoot] [--check | --dry-run | --auto-approv
|
|
|
191
191
|
|
|
192
192
|
elementum pull org [--root <orgRoot>] [--no-adopt]
|
|
193
193
|
elementum pull org --data-only [--root <orgRoot>]
|
|
194
|
-
elementum pull app <namespace> [--root <orgRoot>] [--no-adopt] [--skip-unsupported-layouts]
|
|
195
|
-
elementum pull element <namespace> [--root <orgRoot>] [--no-adopt] [--skip-unsupported-layouts]
|
|
194
|
+
elementum pull app <namespace> [--root <orgRoot>] [--no-adopt] [--skip-unsupported-layouts] [--portable [--map <file>]]
|
|
195
|
+
elementum pull element <namespace> [--root <orgRoot>] [--no-adopt] [--skip-unsupported-layouts] [--portable [--map <file>]]
|
|
196
|
+
elementum pull task <namespace> [--root <orgRoot>] [--no-adopt] [--portable [--map <file>]]
|
|
196
197
|
elementum pull --restore-previous [--root <orgRoot>] # after a failed pull: .tf/in.previous -> .tf/in (failed copy kept as .tf/in.failed); never automatic
|
|
197
|
-
elementum clone app <namespace> --as <newName> [--namespace <newns>] [--root <orgRoot>]
|
|
198
|
+
elementum clone app <namespace> --as <newName> [--namespace <newns>] [--root <orgRoot>] [--target-root <destOrgRoot>] [--map <file>]
|
|
198
199
|
elementum build [orgRoot]
|
|
199
200
|
elementum plan [orgRoot-or-nested-target] [--json] [bridge args...]
|
|
200
201
|
elementum apply [orgRoot-or-nested-target] [--json] [bridge args...]
|
|
@@ -462,8 +463,9 @@ export default agent({
|
|
|
462
463
|
The Terraform path currently round-trips create-record, record-search, and
|
|
463
464
|
run-automation agent tools. Unsupported tools and runtime-only knobs are
|
|
464
465
|
reported as build diagnostics instead of being emitted as partial resources.
|
|
465
|
-
|
|
466
|
-
underscores
|
|
466
|
+
Tool names use 1–64 letters, digits, underscores, or hyphens, with no spaces
|
|
467
|
+
or doubled underscores (the platform's own rule, so platform-generated names
|
|
468
|
+
such as `resolve_<field>-<8 hex>` pull and build unchanged).
|
|
467
469
|
|
|
468
470
|
## Plan and apply
|
|
469
471
|
|
|
@@ -626,8 +628,10 @@ elementum --profile=<profile> plan <orgRoot>
|
|
|
626
628
|
```
|
|
627
629
|
|
|
628
630
|
The migration reads the configured local or remote state, creates an ignored
|
|
629
|
-
recovery snapshot, runs
|
|
630
|
-
|
|
631
|
+
recovery snapshot, runs OpenTofu `state replace-provider` (in `.tf/out` against
|
|
632
|
+
a declared backend, or directly on `terraform.tfstate` on the default local
|
|
633
|
+
backend), refreshes generated provider configuration, and never applies
|
|
634
|
+
infrastructure.
|
|
631
635
|
|
|
632
636
|
### CI/CD
|
|
633
637
|
|
|
@@ -65,7 +65,8 @@ export function slimToken(token) {
|
|
|
65
65
|
if (token.__kind === "documentModel" && typeof token.readerType === "string")
|
|
66
66
|
out.readerType = token.readerType;
|
|
67
67
|
// A platform-managed automation is looked up by display name when a widget
|
|
68
|
-
// runs it
|
|
68
|
+
// runs it. Pull prints that in `name`; sources pulled before edk#1894 carry
|
|
69
|
+
// it in `displayName`, so keep it for them.
|
|
69
70
|
if (token.__kind === "automation" && typeof token.displayName === "string")
|
|
70
71
|
out.displayName = token.displayName;
|
|
71
72
|
// Procedure lookup must carry the exact ordered Snowflake signature so the
|
|
@@ -53,6 +53,18 @@ function serializeTemplate(data) {
|
|
|
53
53
|
let templateStr = "";
|
|
54
54
|
const parameters = [];
|
|
55
55
|
let paramIndex = 1;
|
|
56
|
+
// A string part may already contain `{{{p1}}}` — the platform's mention
|
|
57
|
+
// chip text inside rich-text HTML. Naming a real reference `p1` makes the
|
|
58
|
+
// platform substitute that reference into the chip (#2086). Skip any
|
|
59
|
+
// placeholder name the literal text already uses. A template with no
|
|
60
|
+
// literal placeholders still starts at p1.
|
|
61
|
+
const reserved = literalPlaceholderNames(data.parts);
|
|
62
|
+
const nextParamName = () => {
|
|
63
|
+
let name = `p${paramIndex++}`;
|
|
64
|
+
while (reserved.has(name))
|
|
65
|
+
name = `p${paramIndex++}`;
|
|
66
|
+
return name;
|
|
67
|
+
};
|
|
56
68
|
for (const part of data.parts) {
|
|
57
69
|
if (typeof part === "string") {
|
|
58
70
|
templateStr += part;
|
|
@@ -65,13 +77,26 @@ function serializeTemplate(data) {
|
|
|
65
77
|
if (templateStr.length > 0 && templateStr.endsWith("$")) {
|
|
66
78
|
templateStr += DOLLAR_PLACEHOLDER_ESCAPE;
|
|
67
79
|
}
|
|
68
|
-
const paramName =
|
|
80
|
+
const paramName = nextParamName();
|
|
69
81
|
templateStr += `{{{${paramName}}}}`;
|
|
70
82
|
parameters.push({ value: { name: paramName, value: serializeRefData(part) } });
|
|
71
83
|
}
|
|
72
84
|
}
|
|
73
85
|
return { templateReference: { template: templateStr, parameters } };
|
|
74
86
|
}
|
|
87
|
+
/** `{{{name}}}` occurrences in literal string parts. Those names are not free for generated parameters. */
|
|
88
|
+
function literalPlaceholderNames(parts) {
|
|
89
|
+
const names = new Set();
|
|
90
|
+
for (const part of parts) {
|
|
91
|
+
if (typeof part !== "string")
|
|
92
|
+
continue;
|
|
93
|
+
for (const match of part.matchAll(/\{\{\{(\w+)\}\}\}/g)) {
|
|
94
|
+
if (match[1] !== undefined)
|
|
95
|
+
names.add(match[1]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return names;
|
|
99
|
+
}
|
|
75
100
|
/**
|
|
76
101
|
* Placeholder marker emitted for variableParam refs.
|
|
77
102
|
* Resolved to real `{ variableReference: { id, name } }` by
|
|
@@ -96,6 +96,10 @@ export interface WorkspaceAspect {
|
|
|
96
96
|
readonly automationRefNames?: ReadonlySet<string>;
|
|
97
97
|
/** Sole on-demand record parameter targeting this same owner, keyed by automation refName, for CURRENT_RECORD widget binding. */
|
|
98
98
|
readonly onDemandRecordParamByAutomationRefName?: ReadonlyMap<string, string>;
|
|
99
|
+
/** Every on-demand record input, keyed by automation refName; a static runAutomation mapping into one is refused (edk#1868). */
|
|
100
|
+
readonly onDemandRecordInputsByAutomationRefName?: ReadonlyMap<string, ReadonlySet<string>>;
|
|
101
|
+
/** Automations recorded in applied-automation-revisions.json: the platform already has them, so a live shape build refuses for new ones is reported instead. */
|
|
102
|
+
readonly pulledAutomationRefNames?: ReadonlySet<string>;
|
|
99
103
|
/** Terraform labels of datamines managed by a table in this workspace. */
|
|
100
104
|
readonly managedDatamineLabels?: ReadonlySet<string>;
|
|
101
105
|
/** Ref names of own-file children present in this workspace, grouped by kind. */
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* the config they mention is built and applied as authored:
|
|
12
12
|
* - skill input-coverage lint (`skill "x" input coverage gap [input-schema-missing]: …`)
|
|
13
13
|
* - the unbumped-automation revision reminder
|
|
14
|
+
* - a live runAutomation call into a record input the platform already runs
|
|
15
|
+
* (edk#2250; the mapping is emitted, and the called workflow fails at run time)
|
|
14
16
|
* - the custom-view non-PanesBlock root hint (check.mjs `warn`; the layout is
|
|
15
17
|
* emitted exactly as authored, edk#1771)
|
|
16
18
|
*
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* the config they mention is built and applied as authored:
|
|
12
12
|
* - skill input-coverage lint (`skill "x" input coverage gap [input-schema-missing]: …`)
|
|
13
13
|
* - the unbumped-automation revision reminder
|
|
14
|
+
* - a live runAutomation call into a record input the platform already runs
|
|
15
|
+
* (edk#2250; the mapping is emitted, and the called workflow fails at run time)
|
|
14
16
|
* - the custom-view non-PanesBlock root hint (check.mjs `warn`; the layout is
|
|
15
17
|
* emitted exactly as authored, edk#1771)
|
|
16
18
|
*
|
|
@@ -23,6 +25,7 @@ const INPUT_COVERAGE = /^(skill "[^"]*") input coverage gap \[([a-z-]+)\]: /;
|
|
|
23
25
|
const ADVISORY_DIAGNOSTICS = [
|
|
24
26
|
INPUT_COVERAGE,
|
|
25
27
|
/^automation \S+: compiled steps changed since the last apply but its revision is still /,
|
|
28
|
+
/^automation \S+: maps automation /,
|
|
26
29
|
/^applied-automation-revisions\.json .*; until then no automation is checked for an edit without a revision bump$/,
|
|
27
30
|
/\.root: "[^"]*" is (?:untyped|a [A-Za-z0-9_]+); the root is usually a PanesBlock \(needed for record lists to open the details pane\)$/,
|
|
28
31
|
];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A JSON object read as it streams in, for machine-owned OpenTofu output that
|
|
3
|
+
* grows with the org root and outgrows any fixed in-memory capture (edk#1861):
|
|
4
|
+
* a saved plan's `tofu show -json` and the `state pull` snapshot. The reader
|
|
5
|
+
* walks into the containers it is told to and parses everything else under
|
|
6
|
+
* them one value at a time (a resource, a resource change), so no single
|
|
7
|
+
* string is ever the size of the document. Top-level keys outside `keptRootKeys`
|
|
8
|
+
* are skipped without being held. A skipped value is still checked as strict
|
|
9
|
+
* JSON (matched closers, commas, string escapes, and every number or literal),
|
|
10
|
+
* so output that `JSON.parse` would reject is never read.
|
|
11
|
+
*/
|
|
12
|
+
export interface JsonStreamReaderOptions {
|
|
13
|
+
/** What the document is, for errors ("the saved plan's JSON"). */
|
|
14
|
+
readonly subject: string;
|
|
15
|
+
/** Top-level keys kept; every key when undefined. Everything else is skipped unparsed. */
|
|
16
|
+
readonly keptRootKeys?: ReadonlySet<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Containers walked into instead of parsed whole. The root is `""`; an
|
|
19
|
+
* element of an array at path `p` has path `p[]`. Anything not listed is
|
|
20
|
+
* parsed as one value.
|
|
21
|
+
*/
|
|
22
|
+
readonly walkedPaths: ReadonlySet<string>;
|
|
23
|
+
}
|
|
24
|
+
/** Feed the output chunk by chunk with {@link write}, then call {@link end}. */
|
|
25
|
+
export declare class JsonStreamReader<T extends object = Record<string, unknown>> {
|
|
26
|
+
private readonly options;
|
|
27
|
+
private readonly stack;
|
|
28
|
+
private root;
|
|
29
|
+
private done;
|
|
30
|
+
private capture;
|
|
31
|
+
private offset;
|
|
32
|
+
constructor(options: JsonStreamReaderOptions);
|
|
33
|
+
write(chunk: Buffer): void;
|
|
34
|
+
end(): T;
|
|
35
|
+
/** Handle one non-whitespace byte outside a captured value; true when it starts a capture. */
|
|
36
|
+
private structural;
|
|
37
|
+
private startValue;
|
|
38
|
+
private finishCapture;
|
|
39
|
+
/** Attach a value to the innermost walked container; skipped keys never reach here. */
|
|
40
|
+
private deliver;
|
|
41
|
+
private close;
|
|
42
|
+
private fail;
|
|
43
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
const QUOTE = 0x22;
|
|
2
|
+
const BACKSLASH = 0x5c;
|
|
3
|
+
const COMMA = 0x2c;
|
|
4
|
+
const COLON = 0x3a;
|
|
5
|
+
const OPEN_BRACE = 0x7b;
|
|
6
|
+
const CLOSE_BRACE = 0x7d;
|
|
7
|
+
const OPEN_BRACKET = 0x5b;
|
|
8
|
+
const CLOSE_BRACKET = 0x5d;
|
|
9
|
+
const LOWER_U = 0x75;
|
|
10
|
+
/** Characters allowed after a backslash in a JSON string, other than `u`. */
|
|
11
|
+
const SIMPLE_ESCAPES = new Set([QUOTE, BACKSLASH, 0x2f, 0x62, 0x66, 0x6e, 0x72, 0x74]);
|
|
12
|
+
function isHexDigit(byte) {
|
|
13
|
+
return (byte >= 0x30 && byte <= 0x39) || (byte >= 0x41 && byte <= 0x46) || (byte >= 0x61 && byte <= 0x66);
|
|
14
|
+
}
|
|
15
|
+
function isWhitespace(byte) {
|
|
16
|
+
return byte === 0x20 || byte === 0x09 || byte === 0x0a || byte === 0x0d;
|
|
17
|
+
}
|
|
18
|
+
/** Feed the output chunk by chunk with {@link write}, then call {@link end}. */
|
|
19
|
+
export class JsonStreamReader {
|
|
20
|
+
options;
|
|
21
|
+
stack = [];
|
|
22
|
+
root;
|
|
23
|
+
done = false;
|
|
24
|
+
capture;
|
|
25
|
+
offset = 0;
|
|
26
|
+
constructor(options) {
|
|
27
|
+
this.options = options;
|
|
28
|
+
}
|
|
29
|
+
write(chunk) {
|
|
30
|
+
let start = 0;
|
|
31
|
+
let i = 0;
|
|
32
|
+
while (i < chunk.length) {
|
|
33
|
+
const byte = chunk[i];
|
|
34
|
+
const capture = this.capture;
|
|
35
|
+
if (capture !== undefined) {
|
|
36
|
+
if (capture.scalar) {
|
|
37
|
+
if (byte === COMMA || byte === CLOSE_BRACE || byte === CLOSE_BRACKET || isWhitespace(byte)) {
|
|
38
|
+
this.finishCapture(capture, chunk.subarray(start, i));
|
|
39
|
+
continue; // the delimiter belongs to the enclosing container
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (capture.inString) {
|
|
43
|
+
if (capture.hex > 0) {
|
|
44
|
+
if (!isHexDigit(byte))
|
|
45
|
+
this.fail("has a bad \\u escape in a string", i);
|
|
46
|
+
capture.hex--;
|
|
47
|
+
}
|
|
48
|
+
else if (capture.escape) {
|
|
49
|
+
capture.escape = false;
|
|
50
|
+
if (byte === LOWER_U)
|
|
51
|
+
capture.hex = 4;
|
|
52
|
+
else if (!SIMPLE_ESCAPES.has(byte))
|
|
53
|
+
this.fail("has a bad escape in a string", i);
|
|
54
|
+
}
|
|
55
|
+
else if (byte === BACKSLASH)
|
|
56
|
+
capture.escape = true;
|
|
57
|
+
else if (byte === QUOTE) {
|
|
58
|
+
capture.inString = false;
|
|
59
|
+
if (capture.depth === 0) {
|
|
60
|
+
this.finishCapture(capture, chunk.subarray(start, i + 1));
|
|
61
|
+
i++;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (byte < 0x20)
|
|
66
|
+
this.fail("has a control character in a string", i);
|
|
67
|
+
}
|
|
68
|
+
else if (byte === QUOTE)
|
|
69
|
+
capture.inString = true;
|
|
70
|
+
else if (byte === OPEN_BRACE || byte === OPEN_BRACKET)
|
|
71
|
+
capture.depth++;
|
|
72
|
+
else if (byte === CLOSE_BRACE || byte === CLOSE_BRACKET) {
|
|
73
|
+
capture.depth--;
|
|
74
|
+
if (capture.depth === 0) {
|
|
75
|
+
this.finishCapture(capture, chunk.subarray(start, i + 1));
|
|
76
|
+
i++;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
i++;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (isWhitespace(byte)) {
|
|
84
|
+
i++;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const startsCapture = this.structural(byte, i);
|
|
88
|
+
if (startsCapture)
|
|
89
|
+
start = i;
|
|
90
|
+
i++;
|
|
91
|
+
}
|
|
92
|
+
if (this.capture?.hold === true)
|
|
93
|
+
this.capture.parts.push(Buffer.from(chunk.subarray(start)));
|
|
94
|
+
this.offset += chunk.length;
|
|
95
|
+
}
|
|
96
|
+
end() {
|
|
97
|
+
if (!this.done || this.root === undefined || this.capture !== undefined)
|
|
98
|
+
this.fail("ends before the top-level object closes");
|
|
99
|
+
return this.root;
|
|
100
|
+
}
|
|
101
|
+
/** Handle one non-whitespace byte outside a captured value; true when it starts a capture. */
|
|
102
|
+
structural(byte, index) {
|
|
103
|
+
const frame = this.stack.at(-1);
|
|
104
|
+
if (frame === undefined) {
|
|
105
|
+
if (this.done || byte !== OPEN_BRACE)
|
|
106
|
+
this.fail(this.done ? "has data after the top-level object" : "is not a JSON object", index);
|
|
107
|
+
this.root = {};
|
|
108
|
+
this.stack.push({ kind: "object", keep: true, path: "", value: this.root, key: "", state: "keyOrEnd" });
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
if (frame.kind === "object") {
|
|
112
|
+
switch (frame.state) {
|
|
113
|
+
case "keyOrEnd":
|
|
114
|
+
case "key":
|
|
115
|
+
if (byte === CLOSE_BRACE && frame.state === "keyOrEnd") {
|
|
116
|
+
this.close();
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (byte !== QUOTE)
|
|
120
|
+
this.fail("expected an object key", index);
|
|
121
|
+
this.capture = { keep: true, hold: true, isKey: true, scalar: false, parts: [], depth: 0, inString: true, escape: false, hex: 0 };
|
|
122
|
+
return true;
|
|
123
|
+
case "colon":
|
|
124
|
+
if (byte !== COLON)
|
|
125
|
+
this.fail("expected ':'", index);
|
|
126
|
+
frame.state = "value";
|
|
127
|
+
return false;
|
|
128
|
+
case "value": {
|
|
129
|
+
const childPath = frame.path === "" ? frame.key : `${frame.path}.${frame.key}`;
|
|
130
|
+
frame.state = "commaOrEnd";
|
|
131
|
+
const keptRootKeys = this.options.keptRootKeys;
|
|
132
|
+
return this.startValue(byte, index, childPath, frame.keep && (frame.path !== "" || keptRootKeys === undefined || keptRootKeys.has(frame.key)));
|
|
133
|
+
}
|
|
134
|
+
case "commaOrEnd":
|
|
135
|
+
if (byte === COMMA)
|
|
136
|
+
frame.state = "key";
|
|
137
|
+
else if (byte === CLOSE_BRACE)
|
|
138
|
+
this.close();
|
|
139
|
+
else
|
|
140
|
+
this.fail("expected ',' or '}'", index);
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
switch (frame.state) {
|
|
145
|
+
case "valueOrEnd":
|
|
146
|
+
case "value":
|
|
147
|
+
if (byte === CLOSE_BRACKET && frame.state === "valueOrEnd") {
|
|
148
|
+
this.close();
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
frame.state = "commaOrEnd";
|
|
152
|
+
return this.startValue(byte, index, `${frame.path}[]`, frame.keep);
|
|
153
|
+
case "commaOrEnd":
|
|
154
|
+
if (byte === COMMA)
|
|
155
|
+
frame.state = "value";
|
|
156
|
+
else if (byte === CLOSE_BRACKET)
|
|
157
|
+
this.close();
|
|
158
|
+
else
|
|
159
|
+
this.fail("expected ',' or ']'", index);
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
startValue(byte, index, path, keep) {
|
|
164
|
+
if (byte === COMMA || byte === COLON || byte === CLOSE_BRACE || byte === CLOSE_BRACKET)
|
|
165
|
+
this.fail("expected a value", index);
|
|
166
|
+
const container = byte === OPEN_BRACE || byte === OPEN_BRACKET;
|
|
167
|
+
// A walked container is kept piece by piece; a skipped one is walked the
|
|
168
|
+
// same way, so its structure is checked without holding any of it.
|
|
169
|
+
if (container && (keep ? this.options.walkedPaths.has(path) : true)) {
|
|
170
|
+
const frame = byte === OPEN_BRACE
|
|
171
|
+
? { kind: "object", keep, path, value: {}, key: "", state: "keyOrEnd" }
|
|
172
|
+
: { kind: "array", keep, path, value: [], state: "valueOrEnd" };
|
|
173
|
+
if (keep)
|
|
174
|
+
this.deliver(frame.value);
|
|
175
|
+
this.stack.push(frame);
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
const scalar = !container && byte !== QUOTE;
|
|
179
|
+
this.capture = {
|
|
180
|
+
keep,
|
|
181
|
+
hold: keep || scalar,
|
|
182
|
+
isKey: false,
|
|
183
|
+
scalar,
|
|
184
|
+
parts: [],
|
|
185
|
+
depth: container ? 1 : 0,
|
|
186
|
+
inString: byte === QUOTE,
|
|
187
|
+
escape: false,
|
|
188
|
+
hex: 0,
|
|
189
|
+
};
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
finishCapture(capture, tail) {
|
|
193
|
+
this.capture = undefined;
|
|
194
|
+
if (!capture.hold)
|
|
195
|
+
return; // a skipped string, already checked as it streamed
|
|
196
|
+
const text = (capture.parts.length === 0 ? tail : Buffer.concat([...capture.parts, tail])).toString("utf8");
|
|
197
|
+
let value;
|
|
198
|
+
try {
|
|
199
|
+
// eslint-disable-next-line no-restricted-syntax -- one value of machine-owned OpenTofu output, not an entity.
|
|
200
|
+
value = JSON.parse(text);
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
this.fail(`has an unreadable value (${error.message})`);
|
|
204
|
+
}
|
|
205
|
+
if (!capture.keep)
|
|
206
|
+
return;
|
|
207
|
+
const frame = this.stack.at(-1);
|
|
208
|
+
if (capture.isKey) {
|
|
209
|
+
if (frame.kind !== "object" || typeof value !== "string")
|
|
210
|
+
this.fail("has a non-string object key");
|
|
211
|
+
frame.key = value;
|
|
212
|
+
frame.state = "colon";
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
this.deliver(value);
|
|
216
|
+
}
|
|
217
|
+
/** Attach a value to the innermost walked container; skipped keys never reach here. */
|
|
218
|
+
deliver(value) {
|
|
219
|
+
const frame = this.stack.at(-1);
|
|
220
|
+
if (frame.kind === "array")
|
|
221
|
+
frame.value.push(value);
|
|
222
|
+
else
|
|
223
|
+
Object.defineProperty(frame.value, frame.key, { value, enumerable: true, writable: true, configurable: true });
|
|
224
|
+
}
|
|
225
|
+
close() {
|
|
226
|
+
this.stack.pop();
|
|
227
|
+
if (this.stack.length === 0)
|
|
228
|
+
this.done = true;
|
|
229
|
+
}
|
|
230
|
+
fail(problem, index) {
|
|
231
|
+
const at = index === undefined ? "" : ` at byte ${this.offset + index}`;
|
|
232
|
+
throw new Error(`${this.options.subject} ${problem}${at}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* ei owns auth (`ei auth login`) — Elementum sets no credentials and never talks
|
|
19
19
|
* to the platform itself.
|
|
20
20
|
*/
|
|
21
|
+
import { type SavedPlan } from "./saved-plan.js";
|
|
21
22
|
import { type PartialReadEvent, type ProgressEvent } from "../logging.js";
|
|
22
23
|
export declare class EiRunError extends Error {
|
|
23
24
|
readonly exitCode: number | null;
|
|
@@ -118,6 +119,22 @@ export declare function runOpenTofuCapture(args: readonly string[], opts?: {
|
|
|
118
119
|
suppressStderr?: boolean;
|
|
119
120
|
binary?: string;
|
|
120
121
|
}): Promise<string>;
|
|
122
|
+
/**
|
|
123
|
+
* `tofu show -json <planPath>` for an EDK check of a saved plan (edk#2057),
|
|
124
|
+
* read as it streams so a plan of any size fits (edk#1861): only
|
|
125
|
+
* `resource_changes` and `prior_state` are kept ({@link SavedPlanReader}).
|
|
126
|
+
* The capture keeps OpenTofu's stderr off the terminal, so a failure would
|
|
127
|
+
* otherwise reach the user as a bare exit code. Reject with the EDK step
|
|
128
|
+
* that read the plan and OpenTofu's own `Error:` diagnostics (or, when it
|
|
129
|
+
* printed none, the tail of its stderr) instead. Output that is not one
|
|
130
|
+
* complete JSON object rejects too. Callers still stop: a plan that cannot
|
|
131
|
+
* be read back is never applied unchecked.
|
|
132
|
+
*/
|
|
133
|
+
export declare function readSavedPlan(planPath: string, opts: {
|
|
134
|
+
readonly cwd: string;
|
|
135
|
+
readonly step: string;
|
|
136
|
+
readonly binary?: string;
|
|
137
|
+
}): Promise<SavedPlan>;
|
|
121
138
|
/**
|
|
122
139
|
* Run `ei` capturing stdout (the machine-consumed stream); stderr is routed by
|
|
123
140
|
* EDK to the diagnostics sink. Non-zero exit rejects — partial output must be
|
|
@@ -127,6 +144,10 @@ export declare function runOpenTofuCapture(args: readonly string[], opts?: {
|
|
|
127
144
|
* captured commands whose output is also the user's only progress signal
|
|
128
145
|
* (adoption's `ei plan`). It never moves anything onto our stdout, so the
|
|
129
146
|
* caller's single-JSON-summary contract holds.
|
|
147
|
+
*
|
|
148
|
+
* `onStdout` hands stdout to the caller chunk by chunk instead of buffering
|
|
149
|
+
* it, with no size cap (edk#2248), and the promise resolves to "". When it
|
|
150
|
+
* throws, `ei` is stopped and the promise rejects with that error.
|
|
130
151
|
*/
|
|
131
152
|
export declare function runEiCapture(args: readonly string[], opts?: {
|
|
132
153
|
cwd?: string;
|
|
@@ -136,6 +157,7 @@ export declare function runEiCapture(args: readonly string[], opts?: {
|
|
|
136
157
|
tofuJsonProgress?: {
|
|
137
158
|
readonly expectedAddresses: ReadonlySet<string>;
|
|
138
159
|
};
|
|
160
|
+
onStdout?: (chunk: Buffer) => void;
|
|
139
161
|
}): Promise<string>;
|
|
140
162
|
export type TofuJsonEvent = {
|
|
141
163
|
readonly type: "refresh_start" | "refresh_complete";
|
|
@@ -24,6 +24,7 @@ import { homedir } from "node:os";
|
|
|
24
24
|
import { constants as osConstants } from "node:os";
|
|
25
25
|
import { delimiter, isAbsolute, join, resolve } from "node:path";
|
|
26
26
|
import { applyProgressEvent, incrementProgress, progressStream, resumeProgress, suspendProgress, updateProgress, withProgressBatch, writeProgress, writeTechnicalLog, writeUserOutput, writeUserPayload } from "../progress.js";
|
|
27
|
+
import { SavedPlanReader } from "./saved-plan.js";
|
|
27
28
|
import { createLogWriter, parseBridgeLogEvent, parsePartialReadEvent, parseProgressEvent } from "../logging.js";
|
|
28
29
|
const runtimeLog = createLogWriter();
|
|
29
30
|
/** Shell convention for signal death: 128 + signal number (130 = SIGINT). */
|
|
@@ -634,7 +635,7 @@ export function runEiWithStatus(args, opts) {
|
|
|
634
635
|
};
|
|
635
636
|
const userOutput = opts?.userOutput ?? (process.stdout.isTTY === true ? process.stdout : progressStream());
|
|
636
637
|
const output = Promise.all([
|
|
637
|
-
routeEiOutput(child.stdout,
|
|
638
|
+
routeEiOutput(child.stdout, userOutput, opts?.bridge === true ? (line) => {
|
|
638
639
|
const event = parseProgressEvent(line);
|
|
639
640
|
if (event !== undefined) {
|
|
640
641
|
withProgressBatch(() => {
|
|
@@ -650,7 +651,7 @@ export function runEiWithStatus(args, opts) {
|
|
|
650
651
|
return false;
|
|
651
652
|
writeCapturedTechnicalLine(line);
|
|
652
653
|
return true;
|
|
653
|
-
} : consumeNonBridgeTofuLine, (text
|
|
654
|
+
} : consumeNonBridgeTofuLine, (text) => writeUserOutput(text, userOutput)),
|
|
654
655
|
routeEiOutput(child.stderr, process.stderr, opts?.bridge === true ? (line) => {
|
|
655
656
|
const event = parseProgressEvent(line);
|
|
656
657
|
if (event !== undefined) {
|
|
@@ -742,7 +743,24 @@ export function runOpenTofuWithStatus(args, opts) {
|
|
|
742
743
|
});
|
|
743
744
|
}
|
|
744
745
|
/** Capture bounded, machine-consumed OpenTofu stdout while preserving stderr. */
|
|
745
|
-
export function runOpenTofuCapture(args, opts) {
|
|
746
|
+
export async function runOpenTofuCapture(args, opts) {
|
|
747
|
+
const chunks = [];
|
|
748
|
+
let size = 0;
|
|
749
|
+
await runOpenTofuStreaming(args, opts, (chunk) => {
|
|
750
|
+
size += chunk.length;
|
|
751
|
+
if (size > CAPTURE_LIMIT_BYTES)
|
|
752
|
+
throw new EiRunError(`managed OpenTofu output exceeded ${CAPTURE_LIMIT_BYTES} bytes`, null);
|
|
753
|
+
chunks.push(chunk);
|
|
754
|
+
});
|
|
755
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Run OpenTofu with machine-consumed stdout handed to `onStdout` chunk by
|
|
759
|
+
* chunk, unbuffered; stderr is captured bounded as in {@link runOpenTofuCapture}.
|
|
760
|
+
* When `onStdout` throws, OpenTofu is stopped and the promise rejects with
|
|
761
|
+
* that error.
|
|
762
|
+
*/
|
|
763
|
+
function runOpenTofuStreaming(args, opts, onStdout) {
|
|
746
764
|
return new Promise((resolvePromise, reject) => {
|
|
747
765
|
let child;
|
|
748
766
|
try {
|
|
@@ -756,28 +774,38 @@ export function runOpenTofuCapture(args, opts) {
|
|
|
756
774
|
reject(error);
|
|
757
775
|
return;
|
|
758
776
|
}
|
|
759
|
-
const chunks = [];
|
|
760
777
|
const stderrChunks = [];
|
|
761
|
-
let
|
|
778
|
+
let stderrSize = 0;
|
|
762
779
|
let settled = false;
|
|
763
780
|
const stopForwarding = forwardSignalsToChild(child);
|
|
764
|
-
const
|
|
781
|
+
const abort = (error) => {
|
|
782
|
+
settled = true;
|
|
783
|
+
stopForwarding();
|
|
784
|
+
child.kill();
|
|
785
|
+
reject(error);
|
|
786
|
+
};
|
|
787
|
+
child.stdout?.on("data", (chunk) => {
|
|
765
788
|
if (settled)
|
|
766
789
|
return;
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
790
|
+
try {
|
|
791
|
+
onStdout(chunk);
|
|
792
|
+
}
|
|
793
|
+
catch (error) {
|
|
794
|
+
abort(error);
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
child.stderr?.on("data", (chunk) => {
|
|
798
|
+
if (settled)
|
|
799
|
+
return;
|
|
800
|
+
stderrSize += chunk.length;
|
|
801
|
+
if (stderrSize > CAPTURE_LIMIT_BYTES) {
|
|
802
|
+
abort(new EiRunError(`managed OpenTofu output exceeded ${CAPTURE_LIMIT_BYTES} bytes`, null));
|
|
773
803
|
return;
|
|
774
804
|
}
|
|
775
|
-
|
|
776
|
-
if (
|
|
805
|
+
stderrChunks.push(chunk);
|
|
806
|
+
if (opts?.suppressStderr !== true)
|
|
777
807
|
progressStream().write(chunk);
|
|
778
|
-
};
|
|
779
|
-
child.stdout?.on("data", collect(chunks, false));
|
|
780
|
-
child.stderr?.on("data", collect(stderrChunks, opts?.suppressStderr !== true));
|
|
808
|
+
});
|
|
781
809
|
child.on("error", (error) => {
|
|
782
810
|
stopForwarding();
|
|
783
811
|
if (settled)
|
|
@@ -796,10 +824,48 @@ export function runOpenTofuCapture(args, opts) {
|
|
|
796
824
|
reject(new EiRunError(`managed OpenTofu exited with code ${exit}`, exit, stderr));
|
|
797
825
|
return;
|
|
798
826
|
}
|
|
799
|
-
resolvePromise(
|
|
827
|
+
resolvePromise();
|
|
800
828
|
});
|
|
801
829
|
});
|
|
802
830
|
}
|
|
831
|
+
/** Most stderr lines kept when a failed `tofu show` printed no `Error:` block. */
|
|
832
|
+
const SHOW_STDERR_TAIL_LINES = 20;
|
|
833
|
+
/**
|
|
834
|
+
* `tofu show -json <planPath>` for an EDK check of a saved plan (edk#2057),
|
|
835
|
+
* read as it streams so a plan of any size fits (edk#1861): only
|
|
836
|
+
* `resource_changes` and `prior_state` are kept ({@link SavedPlanReader}).
|
|
837
|
+
* The capture keeps OpenTofu's stderr off the terminal, so a failure would
|
|
838
|
+
* otherwise reach the user as a bare exit code. Reject with the EDK step
|
|
839
|
+
* that read the plan and OpenTofu's own `Error:` diagnostics (or, when it
|
|
840
|
+
* printed none, the tail of its stderr) instead. Output that is not one
|
|
841
|
+
* complete JSON object rejects too. Callers still stop: a plan that cannot
|
|
842
|
+
* be read back is never applied unchecked.
|
|
843
|
+
*/
|
|
844
|
+
export async function readSavedPlan(planPath, opts) {
|
|
845
|
+
const where = `${opts.step} failed: \`tofu show -json ${planPath}\` in ${opts.cwd}`;
|
|
846
|
+
const reader = new SavedPlanReader();
|
|
847
|
+
try {
|
|
848
|
+
await runOpenTofuStreaming(["show", "-json", planPath], { cwd: opts.cwd, suppressStderr: true, binary: opts.binary }, (chunk) => reader.write(chunk));
|
|
849
|
+
return reader.end();
|
|
850
|
+
}
|
|
851
|
+
catch (error) {
|
|
852
|
+
if (!(error instanceof EiRunError))
|
|
853
|
+
throw new EiRunError(`${where}: ${error.message}`, null);
|
|
854
|
+
const diagnostics = tofuErrorDiagnostics(undefined, error.stderr);
|
|
855
|
+
const detail = diagnostics.length > 0
|
|
856
|
+
? capTofuDiagnostics(diagnostics).map((d) => (d.startsWith("… and ") ? d : `Error: ${d}`))
|
|
857
|
+
: stderrTail(error.stderr);
|
|
858
|
+
throw new EiRunError(`${where}: ${error.message}` +
|
|
859
|
+
(detail.length > 0 ? `\n${detail.join("\n")}` : " (OpenTofu wrote nothing to stderr)"), error.exitCode, error.stderr, error.stdout);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
function stderrTail(stderr) {
|
|
863
|
+
const lines = (stderr ?? "")
|
|
864
|
+
.split("\n")
|
|
865
|
+
.map((line) => line.replace(ANSI_SEQUENCE, "").replace(/\r$/, "").trimEnd())
|
|
866
|
+
.filter((line) => line.trim() !== "");
|
|
867
|
+
return lines.slice(-SHOW_STDERR_TAIL_LINES).map((line) => line.length > TOFU_DIAGNOSTIC_MAX_CHARS ? `${line.slice(0, TOFU_DIAGNOSTIC_MAX_CHARS)}… (truncated)` : line);
|
|
868
|
+
}
|
|
803
869
|
/**
|
|
804
870
|
* Run `ei` capturing stdout (the machine-consumed stream); stderr is routed by
|
|
805
871
|
* EDK to the diagnostics sink. Non-zero exit rejects — partial output must be
|
|
@@ -809,6 +875,10 @@ export function runOpenTofuCapture(args, opts) {
|
|
|
809
875
|
* captured commands whose output is also the user's only progress signal
|
|
810
876
|
* (adoption's `ei plan`). It never moves anything onto our stdout, so the
|
|
811
877
|
* caller's single-JSON-summary contract holds.
|
|
878
|
+
*
|
|
879
|
+
* `onStdout` hands stdout to the caller chunk by chunk instead of buffering
|
|
880
|
+
* it, with no size cap (edk#2248), and the promise resolves to "". When it
|
|
881
|
+
* throws, `ei` is stopped and the promise rejects with that error.
|
|
812
882
|
*/
|
|
813
883
|
export function runEiCapture(args, opts) {
|
|
814
884
|
return new Promise((resolvePromise, reject) => {
|
|
@@ -858,6 +928,17 @@ export function runEiCapture(args, opts) {
|
|
|
858
928
|
const onData = (destination, echoTo) => (chunk) => {
|
|
859
929
|
if (settled)
|
|
860
930
|
return;
|
|
931
|
+
if (opts?.onStdout !== undefined && destination === chunks) {
|
|
932
|
+
try {
|
|
933
|
+
opts.onStdout(chunk);
|
|
934
|
+
}
|
|
935
|
+
catch (error) {
|
|
936
|
+
settled = true;
|
|
937
|
+
child.kill();
|
|
938
|
+
reject(error);
|
|
939
|
+
}
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
861
942
|
size += chunk.length;
|
|
862
943
|
if (size > CAPTURE_LIMIT_BYTES) {
|
|
863
944
|
settled = true;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { JsonStreamReader } from "./json-stream-reader.js";
|
|
2
|
+
/**
|
|
3
|
+
* The parts of a saved plan's `tofu show -json` that EDK reads (edk#1861). The
|
|
4
|
+
* full document embeds the prior state, the planned values and the
|
|
5
|
+
* configuration of every resource. Only `resource_changes` and `prior_state`
|
|
6
|
+
* are kept, and each resource change and each prior-state resource is parsed
|
|
7
|
+
* on its own.
|
|
8
|
+
*/
|
|
9
|
+
export interface SavedPlan {
|
|
10
|
+
readonly resource_changes?: unknown;
|
|
11
|
+
readonly prior_state?: unknown;
|
|
12
|
+
}
|
|
13
|
+
/** Feed `tofu show -json` stdout chunk by chunk with {@link write}, then call {@link end}. */
|
|
14
|
+
export declare class SavedPlanReader extends JsonStreamReader<SavedPlan> {
|
|
15
|
+
constructor();
|
|
16
|
+
}
|