@uipath/maestro-builder-sdk 6.120.32 → 6.121.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/dist/case/check-cli.d.ts +19 -0
- package/dist/case/check-cli.js +173 -10
- package/dist/case/check.d.ts +36 -1
- package/dist/case/check.js +11 -3
- package/dist/case/decompile-cli.js +4 -1
- package/dist/case/decompile-stamp.d.ts +35 -0
- package/dist/case/decompile-stamp.js +81 -0
- package/dist/case/edit-scope.d.ts +77 -0
- package/dist/case/edit-scope.js +141 -0
- package/dist/check.js +78 -5
- package/dist/cli/commands/case.js +2 -0
- package/dist/cli-result.d.ts +7 -0
- package/dist/cli-result.js +9 -2
- package/dist/core/exclusive-join.d.ts +59 -0
- package/dist/core/exclusive-join.js +78 -0
- package/dist/core/refusals.d.ts +1 -0
- package/dist/core/refusals.js +1 -0
- package/dist/serialize.d.ts +20 -1
- package/dist/serialize.js +2 -0
- package/package.json +4 -3
package/dist/case/check-cli.d.ts
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { type CaseCheckOpts, type Diagnostic } from './check.js';
|
|
3
|
+
import type { BuiltCase } from './case-sdk.js';
|
|
2
4
|
import { type CliExitCode } from '../cli-run.js';
|
|
3
5
|
export declare function run(argv: string[]): Promise<CliExitCode>;
|
|
6
|
+
/**
|
|
7
|
+
* Check `built` and scope its findings to the edit (`scopeToEdit`): the
|
|
8
|
+
* original at `originalPath` (parsed as `original`) is decompiled as `case
|
|
9
|
+
* decompile` does, with the same library, loaded, and checked with the same
|
|
10
|
+
* options. A plan decompile refuses (the canvas form, a pre-V20 plan) comes
|
|
11
|
+
* back as the usage error to refuse `--baseline` with, worded as decompile
|
|
12
|
+
* words it. The caller has already called `ensureTypeScriptRuntime()`.
|
|
13
|
+
*
|
|
14
|
+
* `editedSource`, the text `built` was loaded from, carries the stamp `case
|
|
15
|
+
* decompile` writes (`./decompile-stamp.ts`). A baseline that is not the plan
|
|
16
|
+
* the stamp names is the usage error too (see {@link wrongBaseline}).
|
|
17
|
+
*
|
|
18
|
+
* For instance, for an edit that only renamed one task, every TASK_NO_ENTRY on
|
|
19
|
+
* the other tasks, which the original has too, comes back as a pre-existing
|
|
20
|
+
* warning.
|
|
21
|
+
*/
|
|
22
|
+
export declare function checkAgainstBaseline(built: BuiltCase, originalPath: string, original: unknown, opts?: CaseCheckOpts, editedSource?: string): Promise<Diagnostic[] | Error>;
|
package/dist/case/check-cli.js
CHANGED
|
@@ -4,25 +4,42 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Usage: node --experimental-strip-types check-cli.js <case.ts | BaseName> \
|
|
6
6
|
* [--library <library-json dir>] [--connectors-local <overlay dir>] [--bindings <bindings.json>] \
|
|
7
|
-
* [-o <the plan compile writes>] [--resources <resources.json>]
|
|
8
|
-
* Exits 0 when clean (warnings allowed), 1 on any error.
|
|
7
|
+
* [-o <the plan compile writes>] [--resources <resources.json>] [--baseline <original caseplan.json>]
|
|
8
|
+
* Exits 0 when clean (warnings allowed), 1 on any error, 2 on a usage error.
|
|
9
|
+
*
|
|
10
|
+
* `--baseline <original caseplan.json>` scopes the findings to the edit, as
|
|
11
|
+
* `flow check --baseline` does: the original is decompiled and checked in
|
|
12
|
+
* memory the same way, and each finding is marked `(edited)` or
|
|
13
|
+
* `(pre-existing)`. A pre-existing finding (on a stage, task or trigger the
|
|
14
|
+
* edit left unchanged, which the original reports too) is a warning, so only
|
|
15
|
+
* the edit's errors fail the check; a pre-existing lowering one is printed as
|
|
16
|
+
* a probable SDK defect. See `./edit-scope.ts`.
|
|
9
17
|
*
|
|
10
18
|
* The library is opened exactly as `compile-cli` opens it (`openCliLibrary`), so
|
|
11
19
|
* a connector task `compile` cannot resolve fails here first (#1014).
|
|
12
20
|
*/
|
|
13
|
-
import {
|
|
21
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
22
|
+
import { tmpdir } from 'node:os';
|
|
23
|
+
import { dirname, join, resolve } from 'node:path';
|
|
24
|
+
import { reportDiagnostics, reportResult, withOrigin } from '../cli-result.js';
|
|
14
25
|
import { resolveCaseFile, loadBuiltCase } from './load.js';
|
|
15
|
-
import { check } from './check.js';
|
|
26
|
+
import { check, checkCompiled } from './check.js';
|
|
27
|
+
import { scopeToEdit } from './edit-scope.js';
|
|
28
|
+
import { decompileWithDiagnostics } from './decompile.js';
|
|
29
|
+
import { baselineSummary } from '../core/baseline-scope.js';
|
|
30
|
+
import { CASE_IMPORT } from '../package-name.js';
|
|
31
|
+
import { caseJsonPreservation } from './preserve.js';
|
|
32
|
+
import { canonicalJson, planDigest, readCaseStamp, sourceDigest } from './decompile-stamp.js';
|
|
16
33
|
import { caseCheckOpts } from './cli-library.js';
|
|
17
34
|
import { withFetchedDefinitions } from '../registry/fetch/with-fetched-definitions.js';
|
|
18
35
|
import { caseCompileTarget } from './compile-cli.js';
|
|
19
|
-
import { runWhenInvokedDirectly } from '../cli-run.js';
|
|
36
|
+
import { flagValue, runWhenInvokedDirectly } from '../cli-run.js';
|
|
20
37
|
import { ensureTypeScriptRuntime } from '../node-runtime.js';
|
|
21
38
|
import { defaultResourcesFile } from '../workdir.js';
|
|
22
39
|
import { readCliResources } from '../registry/prepare/resources.js';
|
|
23
40
|
/** Flags that take a value: their argument is never the source positional. */
|
|
24
|
-
const VALUE_FLAGS = new Set(['--library', '--connectors-local', '--bindings', '--resources', '-o']);
|
|
25
|
-
const USAGE = 'usage: check <case.ts | BaseName> [--library <dir>] [--connectors-local <dir>] [--bindings <file>] [--resources <file>] [-o <plan>]';
|
|
41
|
+
const VALUE_FLAGS = new Set(['--library', '--connectors-local', '--bindings', '--resources', '-o', '--baseline']);
|
|
42
|
+
const USAGE = 'usage: check <case.ts | BaseName> [--library <dir>] [--connectors-local <dir>] [--bindings <file>] [--resources <file>] [-o <plan>] [--baseline <original caseplan.json>]';
|
|
26
43
|
export async function run(argv) {
|
|
27
44
|
if (argv.length === 0 || argv[0] === '-h' || argv[0] === '--help') {
|
|
28
45
|
console.error(USAGE);
|
|
@@ -33,7 +50,16 @@ export async function run(argv) {
|
|
|
33
50
|
console.error(USAGE);
|
|
34
51
|
return 2;
|
|
35
52
|
}
|
|
53
|
+
const baselinePath = flagValue(argv, '--baseline');
|
|
54
|
+
const original = baselinePath !== undefined ? readBaseline(baselinePath) : undefined;
|
|
55
|
+
if (original instanceof Error) {
|
|
56
|
+
console.error(`check: ${original.message}`);
|
|
57
|
+
reportResult({ error: original.message });
|
|
58
|
+
return 2;
|
|
59
|
+
}
|
|
36
60
|
const file = resolveCaseFile(input);
|
|
61
|
+
// Read before anything runs: the stamp names the plan the source came from.
|
|
62
|
+
const editedSource = baselinePath !== undefined ? readFileSync(file, 'utf8') : undefined;
|
|
37
63
|
ensureTypeScriptRuntime();
|
|
38
64
|
const built = await loadBuiltCase(file);
|
|
39
65
|
// The bindings `case compile` reads, plan fallback included, for the
|
|
@@ -41,12 +67,24 @@ export async function run(argv) {
|
|
|
41
67
|
const { bindings } = caseCompileTarget(argv);
|
|
42
68
|
const resources = readCliResources(argv, defaultResourcesFile());
|
|
43
69
|
// A connector operation no layer carries is fetched through `uip` and the check
|
|
44
|
-
// runs again, as `compile` does (docs/CONNECTOR_LIBRARY_OPTIONAL_DESIGN.md)
|
|
45
|
-
|
|
70
|
+
// runs again, as `compile` does (docs/CONNECTOR_LIBRARY_OPTIONAL_DESIGN.md);
|
|
71
|
+
// with a baseline, the original is checked against the same library.
|
|
72
|
+
const result = await withFetchedDefinitions(argv, (library) => {
|
|
73
|
+
const opts = { ...caseCheckOpts(library, bindings), ...(resources ? { resources } : {}) };
|
|
74
|
+
return baselinePath !== undefined ? checkAgainstBaseline(built, baselinePath, original, opts, editedSource) : check(built, opts);
|
|
75
|
+
}, { who: 'check' });
|
|
76
|
+
if (result instanceof Error) {
|
|
77
|
+
console.error(`check: ${result.message}`);
|
|
78
|
+
reportResult({ error: result.message });
|
|
79
|
+
return 2;
|
|
80
|
+
}
|
|
81
|
+
const diags = result;
|
|
46
82
|
reportDiagnostics(diags);
|
|
47
83
|
for (const d of diags)
|
|
48
|
-
console.error(` ${d.level === 'error' ? '✗' : '⚠'} [${d.code}]
|
|
84
|
+
console.error(` ${withOrigin(`${d.level === 'error' ? '✗' : '⚠'} [${d.code}]`, d)}`);
|
|
49
85
|
const errors = diags.filter((d) => d.level === 'error');
|
|
86
|
+
if (baselinePath !== undefined && diags.length)
|
|
87
|
+
console.error(`check: ${baselineSummary(diags, 'parts of the case')}.`);
|
|
50
88
|
if (errors.length) {
|
|
51
89
|
console.error(`check: ${errors.length} error(s).`);
|
|
52
90
|
return 1;
|
|
@@ -54,4 +92,129 @@ export async function run(argv) {
|
|
|
54
92
|
console.log(`check: OK${diags.length ? ` (${diags.length} warning(s))` : ''}`);
|
|
55
93
|
return 0;
|
|
56
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Check `built` and scope its findings to the edit (`scopeToEdit`): the
|
|
97
|
+
* original at `originalPath` (parsed as `original`) is decompiled as `case
|
|
98
|
+
* decompile` does, with the same library, loaded, and checked with the same
|
|
99
|
+
* options. A plan decompile refuses (the canvas form, a pre-V20 plan) comes
|
|
100
|
+
* back as the usage error to refuse `--baseline` with, worded as decompile
|
|
101
|
+
* words it. The caller has already called `ensureTypeScriptRuntime()`.
|
|
102
|
+
*
|
|
103
|
+
* `editedSource`, the text `built` was loaded from, carries the stamp `case
|
|
104
|
+
* decompile` writes (`./decompile-stamp.ts`). A baseline that is not the plan
|
|
105
|
+
* the stamp names is the usage error too (see {@link wrongBaseline}).
|
|
106
|
+
*
|
|
107
|
+
* For instance, for an edit that only renamed one task, every TASK_NO_ENTRY on
|
|
108
|
+
* the other tasks, which the original has too, comes back as a pre-existing
|
|
109
|
+
* warning.
|
|
110
|
+
*/
|
|
111
|
+
export async function checkAgainstBaseline(built, originalPath, original, opts = {}, editedSource) {
|
|
112
|
+
const stamp = editedSource !== undefined ? readCaseStamp(editedSource) : undefined;
|
|
113
|
+
if (stamp !== undefined && 'error' in stamp)
|
|
114
|
+
return new Error(`the source's @decompiled-from stamp line does not read (${stamp.error}); decompile ${originalPath} again, or delete the line`);
|
|
115
|
+
const edited = checkCompiled(built, opts);
|
|
116
|
+
let source;
|
|
117
|
+
try {
|
|
118
|
+
const result = decompileWithDiagnostics(original, { importSpecifier: CASE_IMPORT, bestEffort: true, ...(opts.library ? { library: opts.library } : {}) });
|
|
119
|
+
for (const d of result.diagnostics)
|
|
120
|
+
console.error(`check: baseline decompile: [${d.code}] ${d.location}: ${d.message}`);
|
|
121
|
+
source = result.source;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
return new Error(`--baseline ${originalPath} does not decompile: ${error instanceof Error ? error.message : String(error)}`);
|
|
125
|
+
}
|
|
126
|
+
// Beside the original, not in the system temp dir, as `flow check --baseline`
|
|
127
|
+
// writes it: the source then resolves what the author's project resolves.
|
|
128
|
+
const dir = baselineDirectory(originalPath);
|
|
129
|
+
try {
|
|
130
|
+
writeFileSync(join(dir, 'package.json'), '{"type":"module"}\n');
|
|
131
|
+
const file = join(dir, 'Baseline.case.ts');
|
|
132
|
+
writeFileSync(file, source);
|
|
133
|
+
// A best-effort decompile of a broken plan is a repair scaffold
|
|
134
|
+
// (`.__UNRESOLVED_TASK_KIND__(...)`), which does not build: that is a
|
|
135
|
+
// problem with the baseline, not with the edit, so it is the usage error.
|
|
136
|
+
let baseline;
|
|
137
|
+
let baselineBuilt;
|
|
138
|
+
try {
|
|
139
|
+
baselineBuilt = await loadBuiltCase(file);
|
|
140
|
+
baseline = checkCompiled(baselineBuilt, opts);
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
return new Error(`--baseline ${originalPath} decompiles but does not build (${error instanceof Error ? error.message : String(error)}); `
|
|
144
|
+
+ 'repair the original first, or run check without --baseline');
|
|
145
|
+
}
|
|
146
|
+
const wrong = wrongBaseline(built, baselineBuilt, original, source, stamp);
|
|
147
|
+
if (wrong !== undefined)
|
|
148
|
+
return new Error(`--baseline ${originalPath} is not the plan this source was decompiled from: ${wrong}. Pass the original plan as `
|
|
149
|
+
+ 'it was before the first compile (a plan compile wrote over holds the edit, and checking the edit against itself hides '
|
|
150
|
+
+ 'its errors), or decompile again.');
|
|
151
|
+
return scopeToEdit(edited, baseline);
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
rmSync(dir, { recursive: true, force: true });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Why the baseline is not the plan the source was decompiled from, or `undefined`
|
|
159
|
+
* when it is (or nothing says otherwise). Against a plan compile has already written
|
|
160
|
+
* the edit over, every finding of the edit reads as pre-existing, so this is checked
|
|
161
|
+
* before any finding is scoped.
|
|
162
|
+
*
|
|
163
|
+
* - A stamped source (`case decompile` writes the stamp): the baseline matches when
|
|
164
|
+
* its {@link planDigest} is the stamp's `plan=`, which no SDK version changes; or,
|
|
165
|
+
* when the plan changed only where decompile does not read (the stamp's `sha256:`
|
|
166
|
+
* is the source this SDK decompiles it to), the edit's units are still the ones
|
|
167
|
+
* the source started from.
|
|
168
|
+
* - An unstamped source decompiled before the stamp: the `preserveCaseJson(...)`
|
|
169
|
+
* payload, which decompile owns and the author never edits, must equal the one the
|
|
170
|
+
* baseline's decompile carries. This catches an edit that added or removed an id,
|
|
171
|
+
* not one made in place to a stage or a condition.
|
|
172
|
+
* - A hand-written source (no stamp, no payload): nothing to compare.
|
|
173
|
+
*
|
|
174
|
+
* For instance, an edit that adds `marksCaseComplete: false` to `.completeWhen(...)`,
|
|
175
|
+
* compiled over the plan and the plan then passed, comes back `the plan's content
|
|
176
|
+
* changed since the decompile (plan=<recorded> recorded, <now> now)`.
|
|
177
|
+
*/
|
|
178
|
+
function wrongBaseline(built, baselineBuilt, original, baselineSource, stamp) {
|
|
179
|
+
if (stamp !== undefined && !('error' in stamp)) {
|
|
180
|
+
const now = planDigest(original);
|
|
181
|
+
if (now === stamp.plan || sourceDigest(baselineSource) === stamp.sha256)
|
|
182
|
+
return undefined;
|
|
183
|
+
return `the plan's content changed since the decompile (plan=${stamp.plan} recorded, ${now} now)`;
|
|
184
|
+
}
|
|
185
|
+
const ownPayload = caseJsonPreservation(built);
|
|
186
|
+
if (ownPayload !== undefined && canonicalJson(ownPayload) !== canonicalJson(caseJsonPreservation(baselineBuilt)))
|
|
187
|
+
return 'its decompile carries different preserveCaseJson(...) data';
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
function baselineDirectory(originalPath) {
|
|
191
|
+
try {
|
|
192
|
+
return mkdtempSync(join(dirname(resolve(originalPath)), '.case-check-baseline-'));
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
return mkdtempSync(join(tmpdir(), 'case-check-baseline-'));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* The `--baseline` file, parsed, or the usage error to refuse it with: a path
|
|
200
|
+
* that does not exist, or a file that is not a caseplan (JSON with `nodes`),
|
|
201
|
+
* such as the `.case.ts` source passed by mistake. Refused before anything is
|
|
202
|
+
* loaded, with the usage exit code, so a bad flag never reads as a failed check.
|
|
203
|
+
*/
|
|
204
|
+
function readBaseline(path) {
|
|
205
|
+
const usage = `--baseline must be the original caseplan.json (JSON) the source was decompiled from: ${path}`;
|
|
206
|
+
if (!existsSync(path))
|
|
207
|
+
return new Error(`${usage} (no such file)`);
|
|
208
|
+
let parsed;
|
|
209
|
+
try {
|
|
210
|
+
parsed = JSON.parse(readFileSync(path, 'utf8'));
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
return new Error(`${usage} (not JSON: ${error instanceof Error ? error.message : String(error)})`);
|
|
214
|
+
}
|
|
215
|
+
if (!parsed || typeof parsed !== 'object' || !Array.isArray(parsed.nodes)) {
|
|
216
|
+
return new Error(`${usage} (no "nodes" array)`);
|
|
217
|
+
}
|
|
218
|
+
return parsed;
|
|
219
|
+
}
|
|
57
220
|
runWhenInvokedDirectly(import.meta.url, 'check', run);
|
package/dist/case/check.d.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import type { BuiltCase } from './case-sdk.js';
|
|
15
15
|
import { type ConnectorCheckOpts } from '../core/connector-checks.js';
|
|
16
16
|
import type { Library } from '../core/library.js';
|
|
17
|
+
import type { RefusalClass } from '../core/refusals.js';
|
|
17
18
|
export interface Diagnostic {
|
|
18
19
|
level: 'error' | 'warning';
|
|
19
20
|
code: string;
|
|
@@ -21,8 +22,40 @@ export interface Diagnostic {
|
|
|
21
22
|
/** What the finding is about: a task's name, a stage's label, a trigger's label. */
|
|
22
23
|
where?: string;
|
|
23
24
|
suggestion?: string;
|
|
24
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* The id of the stage, task or trigger `where` names: set by a refusal the
|
|
27
|
+
* serializer placed on one (`serializerRefusals`); with a baseline
|
|
28
|
+
* (`case check --baseline`, `scopeToEdit` in `./edit-scope.ts`), on every
|
|
29
|
+
* finding that names one.
|
|
30
|
+
*/
|
|
25
31
|
nodeId?: string;
|
|
32
|
+
/** Only with a baseline: the code's class (`core/refusals.ts`), `lint`, `lowering` or `draft`. */
|
|
33
|
+
class?: RefusalClass;
|
|
34
|
+
/**
|
|
35
|
+
* Only with a baseline: `pre-existing` when the finding's stage, task or
|
|
36
|
+
* trigger is unchanged from the original and the original reports the same
|
|
37
|
+
* code there, so the edit did not cause it (such a finding is a warning);
|
|
38
|
+
* `edited` for every other finding.
|
|
39
|
+
*/
|
|
40
|
+
origin?: 'edited' | 'pre-existing';
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* What {@link checkCompiled} found, with the plan its serializer pass built,
|
|
44
|
+
* which `scopeToEdit` (`./edit-scope.ts`) compares against a baseline.
|
|
45
|
+
*/
|
|
46
|
+
export interface CheckedCase {
|
|
47
|
+
diagnostics: Diagnostic[];
|
|
48
|
+
/**
|
|
49
|
+
* The collect-mode plan, stand-ins and all (`CaseSerializeOpts.collect`);
|
|
50
|
+
* nothing writes it. `undefined` when the serializer threw, so no finding
|
|
51
|
+
* past that point was reported.
|
|
52
|
+
*/
|
|
53
|
+
plan: Record<string, unknown> | undefined;
|
|
54
|
+
/** When the serializer threw past collect mode: the throw, after which nothing was judged. */
|
|
55
|
+
stoppedAt?: {
|
|
56
|
+
code?: string;
|
|
57
|
+
message: string;
|
|
58
|
+
};
|
|
26
59
|
}
|
|
27
60
|
/**
|
|
28
61
|
* The connector-library facts Case `check` reads, from the same `Library`
|
|
@@ -53,3 +86,5 @@ export type CaseCheckOpts = Pick<ConnectorCheckOpts, 'lookups' | 'resolutions' |
|
|
|
53
86
|
* @returns Every diagnostic found. An `error` fails `check`; only a `lowering` error stops `compile`.
|
|
54
87
|
*/
|
|
55
88
|
export declare function check(built: BuiltCase, opts?: CaseCheckOpts): Diagnostic[];
|
|
89
|
+
/** {@link check}, keeping the plan its serializer pass built ({@link CheckedCase}). */
|
|
90
|
+
export declare function checkCompiled(built: BuiltCase, opts?: CaseCheckOpts): CheckedCase;
|
package/dist/case/check.js
CHANGED
|
@@ -28,6 +28,10 @@ const ILLEGAL = [];
|
|
|
28
28
|
* @returns Every diagnostic found. An `error` fails `check`; only a `lowering` error stops `compile`.
|
|
29
29
|
*/
|
|
30
30
|
export function check(built, opts = {}) {
|
|
31
|
+
return checkCompiled(built, opts).diagnostics;
|
|
32
|
+
}
|
|
33
|
+
/** {@link check}, keeping the plan its serializer pass built ({@link CheckedCase}). */
|
|
34
|
+
export function checkCompiled(built, opts = {}) {
|
|
31
35
|
// Which steps share a recorded lookup row across connections (LOOKUP_CONNECTION_MISMATCH), file-wide.
|
|
32
36
|
if (opts.resolutions && !opts.lookupConnections)
|
|
33
37
|
opts = { ...opts, lookupConnections: lookupConnectionIndex(built, opts.resolutions, opts.bindings) };
|
|
@@ -254,8 +258,9 @@ export function check(built, opts = {}) {
|
|
|
254
258
|
checkTaskRetry(built, diags);
|
|
255
259
|
checkRuleSemantics(built, diags);
|
|
256
260
|
checkLibraryConnectors(built, opts, diags);
|
|
257
|
-
|
|
258
|
-
|
|
261
|
+
const serialized = serializerRefusals(built, opts, diags, reportedReads);
|
|
262
|
+
diags.push(...serialized.diagnostics);
|
|
263
|
+
return { diagnostics: diags, plan: serialized.plan, ...(serialized.stoppedAt ? { stoppedAt: serialized.stoppedAt } : {}) };
|
|
259
264
|
}
|
|
260
265
|
/**
|
|
261
266
|
* Task types whose retry policy the platform drops (`caseTaskTypeSupportsErrorHandling`
|
|
@@ -330,6 +335,7 @@ function serializerRefusals(built, opts, found, reportedReads = []) {
|
|
|
330
335
|
const collected = [];
|
|
331
336
|
const warned = [];
|
|
332
337
|
let plan;
|
|
338
|
+
let stoppedAt;
|
|
333
339
|
try {
|
|
334
340
|
plan = serialize(built, {
|
|
335
341
|
...(opts.library ? { library: opts.library } : {}),
|
|
@@ -342,6 +348,8 @@ function serializerRefusals(built, opts, found, reportedReads = []) {
|
|
|
342
348
|
catch (error) {
|
|
343
349
|
if (!found.some((d) => d.level === 'error') && !collected.some((r) => r.code !== 'LIBRARY_REQUIRED'))
|
|
344
350
|
throw error;
|
|
351
|
+
const code = error?.code;
|
|
352
|
+
stoppedAt = { ...(typeof code === 'string' ? { code } : {}), message: error instanceof Error ? error.message : String(error) };
|
|
345
353
|
}
|
|
346
354
|
const out = [];
|
|
347
355
|
const seen = new Set();
|
|
@@ -387,7 +395,7 @@ function serializerRefusals(built, opts, found, reportedReads = []) {
|
|
|
387
395
|
seen.add(key);
|
|
388
396
|
out.push({ level: 'warning', code: w.code, message: w.message });
|
|
389
397
|
}
|
|
390
|
-
return out;
|
|
398
|
+
return { diagnostics: out, plan, ...(stoppedAt ? { stoppedAt } : {}) };
|
|
391
399
|
}
|
|
392
400
|
/** The value at a plan-check path (`nodes[1].data.tasks[0][0].skipCondition`). */
|
|
393
401
|
function valueAtPlanPath(plan, path) {
|
|
@@ -35,6 +35,7 @@ import { defaultOverlayDir, defaultSourceOut, workDirBeside, workPath, writeSour
|
|
|
35
35
|
import { flagValue, runWhenInvokedDirectly } from '../cli-run.js';
|
|
36
36
|
import { decompileWithDiagnostics } from './decompile.js';
|
|
37
37
|
import { decompileWithPlanConnectors } from './plan-connectors.js';
|
|
38
|
+
import { stampCaseSource } from './decompile-stamp.js';
|
|
38
39
|
import { CASE_IMPORT } from '../package-name.js';
|
|
39
40
|
import { commentText } from '../core/comment-text.js';
|
|
40
41
|
import { pipelineFrontDoor } from '../registry/uip/pipeline-front-door.js';
|
|
@@ -101,7 +102,9 @@ export async function run(argv) {
|
|
|
101
102
|
reportResult({ connectorsFromPlan: { overlay: resolve(overlayDir), nodeTypes: carried.written.map((c) => c.entry.nodeType) } });
|
|
102
103
|
}
|
|
103
104
|
const out = flagValue(argv, '-o') ?? defaultSourceOut(`${baseName(plan)}.case.ts`);
|
|
104
|
-
|
|
105
|
+
// The stamp names the plan this came from, so `case check --baseline` can
|
|
106
|
+
// refuse a baseline that is not it (decompile-stamp.ts).
|
|
107
|
+
writeSource(out, stampCaseSource(result.source, plan, basename(pos)));
|
|
105
108
|
console.log(`decompile: wrote ${basename(out)}`);
|
|
106
109
|
reportResult({ path: resolve(out), diagnostics: result.diagnostics.map((d) => ({ code: d.code, location: d.location, message: d.message })) });
|
|
107
110
|
for (const diagnostic of result.diagnostics) {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export { sourceDigest, STAMP_MARKER } from '../core/decompile-stamp.js';
|
|
2
|
+
/** What `case decompile` records about the decompile, and `case check --baseline` reads back. */
|
|
3
|
+
export interface CaseDecompileStamp {
|
|
4
|
+
/** The original's base name. */
|
|
5
|
+
file: string;
|
|
6
|
+
/** `sourceDigest` of the source decompile made of the original, lowercase hex. */
|
|
7
|
+
sha256: string;
|
|
8
|
+
/** {@link planDigest} of the original, lowercase hex. */
|
|
9
|
+
plan: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* `value` as JSON with every object's keys sorted and `undefined` fields left out, so
|
|
13
|
+
* two values with the same content compare equal whatever their key order.
|
|
14
|
+
*
|
|
15
|
+
* @example canonicalJson({ b: 1, a: [true] }) === canonicalJson({ a: [true], b: 1 }) // '{"a":[true],"b":1}'
|
|
16
|
+
*/
|
|
17
|
+
export declare function canonicalJson(value: unknown): string;
|
|
18
|
+
/** SHA-256, lowercase hex, of a parsed plan as {@link canonicalJson}: what `plan=` records. */
|
|
19
|
+
export declare function planDigest(plan: unknown): string;
|
|
20
|
+
/** The stamp line for `source`, decompiled from `plan` read from the file named `file`, without a terminator. */
|
|
21
|
+
export declare function formatCaseStamp(stamp: CaseDecompileStamp): string;
|
|
22
|
+
/**
|
|
23
|
+
* `source`, decompiled from `plan` (read from the file whose base name is `file`), with
|
|
24
|
+
* its stamp line in front.
|
|
25
|
+
*/
|
|
26
|
+
export declare function stampCaseSource(source: string, plan: unknown, file: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Read the stamp from a `.case.ts` source.
|
|
29
|
+
*
|
|
30
|
+
* @returns The stamp; `undefined` when the source has no stamp line (decompiled before
|
|
31
|
+
* the stamp existed, or written by hand); or `{ error }` when the line does not parse.
|
|
32
|
+
*/
|
|
33
|
+
export declare function readCaseStamp(source: string): CaseDecompileStamp | {
|
|
34
|
+
error: string;
|
|
35
|
+
} | undefined;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* decompile-stamp — the line `case decompile` writes at the top of a `.case.ts` to say
|
|
3
|
+
* which plan it came from, and the reader `case check --baseline` uses to check that
|
|
4
|
+
* the baseline it is given is that plan. The line's shape and the source digest are
|
|
5
|
+
* shared with Flow and BPMN (`core/decompile-stamp.ts`); the option is Case's:
|
|
6
|
+
*
|
|
7
|
+
* // @decompiled-from <file name> sha256:<64 hex> plan=<64 hex>
|
|
8
|
+
*
|
|
9
|
+
* - `sha256:` is the shared source digest: SHA-256 of the source decompile wrote,
|
|
10
|
+
* without the stamp line and with the import specifier normalized.
|
|
11
|
+
* - `plan=` is SHA-256 of the plan decompile read, as key-order-free JSON
|
|
12
|
+
* ({@link planDigest}). It does not depend on what this SDK's decompile makes of the
|
|
13
|
+
* plan, so a source decompiled with an older SDK still matches its original. It
|
|
14
|
+
* changes with any change to the plan's content, whitespace and key order aside.
|
|
15
|
+
*
|
|
16
|
+
* Why (UiPath/builder-sdk#1962): `case check --baseline` decompiles the baseline and
|
|
17
|
+
* scopes the edit's findings against it. Passed the plan `compile` has already written
|
|
18
|
+
* the edit over, every finding of the edit reads as pre-existing and the check passes.
|
|
19
|
+
* The `preserveCaseJson(...)` payload catches that only when the edit changed an id or
|
|
20
|
+
* a task fingerprint; an edit made in place to a stage or a case condition does not.
|
|
21
|
+
*
|
|
22
|
+
* `--import`, `--no-pipeline` and `--best-effort` are not recorded: none changes which
|
|
23
|
+
* plan the source came from.
|
|
24
|
+
*
|
|
25
|
+
* Nothing here prints; the CLIs do.
|
|
26
|
+
*/
|
|
27
|
+
import { formatStampLine, readStampLine, sourceDigest } from '../core/decompile-stamp.js';
|
|
28
|
+
import { bytesToHex, sha256 } from '../core/sha.js';
|
|
29
|
+
export { sourceDigest, STAMP_MARKER } from '../core/decompile-stamp.js';
|
|
30
|
+
/**
|
|
31
|
+
* `value` as JSON with every object's keys sorted and `undefined` fields left out, so
|
|
32
|
+
* two values with the same content compare equal whatever their key order.
|
|
33
|
+
*
|
|
34
|
+
* @example canonicalJson({ b: 1, a: [true] }) === canonicalJson({ a: [true], b: 1 }) // '{"a":[true],"b":1}'
|
|
35
|
+
*/
|
|
36
|
+
export function canonicalJson(value) {
|
|
37
|
+
if (Array.isArray(value))
|
|
38
|
+
return `[${value.map(canonicalJson).join(',')}]`;
|
|
39
|
+
if (value !== null && typeof value === 'object') {
|
|
40
|
+
const o = value;
|
|
41
|
+
return `{${Object.keys(o).sort().filter((k) => o[k] !== undefined).map((k) => `${JSON.stringify(k)}:${canonicalJson(o[k])}`).join(',')}}`;
|
|
42
|
+
}
|
|
43
|
+
return JSON.stringify(value) ?? 'null';
|
|
44
|
+
}
|
|
45
|
+
/** SHA-256, lowercase hex, of a parsed plan as {@link canonicalJson}: what `plan=` records. */
|
|
46
|
+
export function planDigest(plan) {
|
|
47
|
+
return bytesToHex(sha256(canonicalJson(plan)));
|
|
48
|
+
}
|
|
49
|
+
/** The stamp line for `source`, decompiled from `plan` read from the file named `file`, without a terminator. */
|
|
50
|
+
export function formatCaseStamp(stamp) {
|
|
51
|
+
return formatStampLine({ file: stamp.file, sha256: stamp.sha256, options: [`plan=${stamp.plan}`] });
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* `source`, decompiled from `plan` (read from the file whose base name is `file`), with
|
|
55
|
+
* its stamp line in front.
|
|
56
|
+
*/
|
|
57
|
+
export function stampCaseSource(source, plan, file) {
|
|
58
|
+
return `${formatCaseStamp({ file, sha256: sourceDigest(source), plan: planDigest(plan) })}\n${source}`;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Read the stamp from a `.case.ts` source.
|
|
62
|
+
*
|
|
63
|
+
* @returns The stamp; `undefined` when the source has no stamp line (decompiled before
|
|
64
|
+
* the stamp existed, or written by hand); or `{ error }` when the line does not parse.
|
|
65
|
+
*/
|
|
66
|
+
export function readCaseStamp(source) {
|
|
67
|
+
const read = readStampLine(source);
|
|
68
|
+
if (read === undefined || 'error' in read)
|
|
69
|
+
return read;
|
|
70
|
+
let plan;
|
|
71
|
+
for (const token of read.options) {
|
|
72
|
+
const [key, value] = token.split('=', 2);
|
|
73
|
+
if (key === 'plan' && plan === undefined && value !== undefined && /^[0-9a-f]{64}$/.test(value))
|
|
74
|
+
plan = value;
|
|
75
|
+
else
|
|
76
|
+
return { error: `unknown or repeated option \`${token}\`: ${read.line}` };
|
|
77
|
+
}
|
|
78
|
+
if (plan === undefined)
|
|
79
|
+
return { error: `\`plan=\` is missing: ${read.line}` };
|
|
80
|
+
return { file: read.file, sha256: read.sha256, plan };
|
|
81
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* case/edit-scope — which stages, tasks and triggers of a case the author
|
|
3
|
+
* edited, and which `check` findings the edit did not cause
|
|
4
|
+
* (`case check --baseline <original caseplan.json>`).
|
|
5
|
+
*
|
|
6
|
+
* The brownfield loop decompiles an existing plan, edits the source, checks
|
|
7
|
+
* it and compiles it. Without a baseline, `check` judges the whole case, so a
|
|
8
|
+
* defect the original already had on a task the edit never touched (a task
|
|
9
|
+
* with no entry rule, say) fails every edit. With one, the original is
|
|
10
|
+
* decompiled and checked the same way, and a finding is `pre-existing` when:
|
|
11
|
+
*
|
|
12
|
+
* - it is on a stage, task or trigger (a "unit", by id) that is unchanged
|
|
13
|
+
* from the original, and the original reports the same code there; or
|
|
14
|
+
* - it names no unit, and the original reports the same code and message.
|
|
15
|
+
*
|
|
16
|
+
* Every other finding is `edited`: one on a unit the edit changed, on a new
|
|
17
|
+
* unit, or a new finding on an untouched unit (an edit elsewhere caused it).
|
|
18
|
+
*
|
|
19
|
+
* "Unchanged" compares the two collect-mode plans `check` builds (the edited
|
|
20
|
+
* source's, and the decompiled original's), unit by unit:
|
|
21
|
+
*
|
|
22
|
+
* - a task: its object in the plan (name, type, inputs, outputs, entry
|
|
23
|
+
* rules, ...) and the stage that holds it;
|
|
24
|
+
* - a stage or trigger: its node, with each task in it replaced by the
|
|
25
|
+
* task's id (a task's content is its own unit), and the edges into and
|
|
26
|
+
* out of it. Canvas layout fields are ignored.
|
|
27
|
+
*
|
|
28
|
+
* Ids are stable here because decompile carries the original's ids into the
|
|
29
|
+
* source (`preserveCaseJson`), so the original's round trip and an edit that
|
|
30
|
+
* leaves a task alone give that task the same id and the same content. A
|
|
31
|
+
* renamed task keeps its id but not its content, so it is edited; a deleted
|
|
32
|
+
* one has no findings left; a new one has an id the original lacks.
|
|
33
|
+
*
|
|
34
|
+
* Messages are compared with each stage, task and trigger name replaced by its
|
|
35
|
+
* id, since a task's finding names its stage (`Task "Wrap" in stage "Close"`):
|
|
36
|
+
* renaming the stage changes neither the task nor what its finding is about.
|
|
37
|
+
*
|
|
38
|
+
* For instance, TASK_NO_ENTRY on task "Approved Record Task", which the edit
|
|
39
|
+
* did not touch and the original reports too, is a pre-existing warning; the
|
|
40
|
+
* same finding after the edit gave that task a new input is an edited error.
|
|
41
|
+
*
|
|
42
|
+
* Pure: no file access. Reading and decompiling the original is check-cli's.
|
|
43
|
+
*/
|
|
44
|
+
import type { CheckedCase, Diagnostic } from './check.js';
|
|
45
|
+
type Json = Record<string, unknown>;
|
|
46
|
+
/** One unit of a plan: what kind it is, its name as `check` words it, and its content. */
|
|
47
|
+
export interface CaseUnit {
|
|
48
|
+
kind: 'stage' | 'task' | 'trigger';
|
|
49
|
+
name: string;
|
|
50
|
+
content: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The plan's stages, tasks and triggers by id ({@link CaseUnit}). A node that
|
|
54
|
+
* is no stage (a trigger, or any other node with an id) counts as a trigger.
|
|
55
|
+
*/
|
|
56
|
+
export declare function caseUnits(plan: Json | undefined): Map<string, CaseUnit>;
|
|
57
|
+
/**
|
|
58
|
+
* The id of the unit a finding is on: its `nodeId` when the serializer placed
|
|
59
|
+
* it, else the unit its `where` names. `check` words `where` as a task's name,
|
|
60
|
+
* a stage's or trigger's label, or a phrase that starts with one
|
|
61
|
+
* (`task "Review" in stage "Intake" entry`, `stage "Intake" exit`). Undefined
|
|
62
|
+
* when it names none, or a name two units share.
|
|
63
|
+
*/
|
|
64
|
+
export declare function unitOf(d: Pick<Diagnostic, 'where' | 'nodeId'>, units: ReadonlyMap<string, CaseUnit>): string | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Scope `edited`'s findings to the edit, against `baseline`: the original
|
|
67
|
+
* caseplan decompiled and checked the same way (the module doc says which
|
|
68
|
+
* finding is which). Every finding gets an `origin`, its `class`, and the
|
|
69
|
+
* `nodeId` of the unit it is on when it names one. A pre-existing finding is a
|
|
70
|
+
* warning; a pre-existing `lowering` one also says it is probably an SDK defect.
|
|
71
|
+
*
|
|
72
|
+
* When the edited case's serializer threw past collect mode, the rest of the
|
|
73
|
+
* case was never judged, so one more error, CHECK_INCOMPLETE, says so: passing
|
|
74
|
+
* never means "not checked".
|
|
75
|
+
*/
|
|
76
|
+
export declare function scopeToEdit(edited: CheckedCase, baseline: CheckedCase): Diagnostic[];
|
|
77
|
+
export {};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { refusalClass } from '../core/refusals.js';
|
|
2
|
+
import { preExistingFindings, scopeFindings } from '../core/baseline-scope.js';
|
|
3
|
+
const isObj = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
4
|
+
/** Key-order-free JSON, so two units compare by content. */
|
|
5
|
+
function stableJson(v) {
|
|
6
|
+
if (Array.isArray(v))
|
|
7
|
+
return `[${v.map(stableJson).join(',')}]`;
|
|
8
|
+
if (isObj(v))
|
|
9
|
+
return `{${Object.keys(v).sort().filter((k) => v[k] !== undefined).map((k) => `${JSON.stringify(k)}:${stableJson(v[k])}`).join(',')}}`;
|
|
10
|
+
return JSON.stringify(v) ?? 'null';
|
|
11
|
+
}
|
|
12
|
+
/** A node's canvas layout fields: where it is drawn, not what it does. */
|
|
13
|
+
const LAYOUT_FIELDS = new Set(['position', 'style', 'measured', 'width', 'height', 'zIndex', 'selected', 'dragging']);
|
|
14
|
+
/**
|
|
15
|
+
* The plan's stages, tasks and triggers by id ({@link CaseUnit}). A node that
|
|
16
|
+
* is no stage (a trigger, or any other node with an id) counts as a trigger.
|
|
17
|
+
*/
|
|
18
|
+
export function caseUnits(plan) {
|
|
19
|
+
const units = new Map();
|
|
20
|
+
if (!plan)
|
|
21
|
+
return units;
|
|
22
|
+
const edges = (Array.isArray(plan.edges) ? plan.edges : []).filter(isObj);
|
|
23
|
+
for (const node of (Array.isArray(plan.nodes) ? plan.nodes : []).filter(isObj)) {
|
|
24
|
+
if (typeof node.id !== 'string')
|
|
25
|
+
continue;
|
|
26
|
+
const data = isObj(node.data) ? node.data : {};
|
|
27
|
+
const lanes = Array.isArray(data.tasks) ? data.tasks : [];
|
|
28
|
+
const isStage = String(node.type ?? '').endsWith('Stage');
|
|
29
|
+
for (const lane of lanes)
|
|
30
|
+
for (const task of Array.isArray(lane) ? lane.filter(isObj) : [])
|
|
31
|
+
if (typeof task.id === 'string')
|
|
32
|
+
units.set(task.id, { kind: 'task', name: String(task.displayName ?? ''), content: stableJson({ stage: node.id, task }) });
|
|
33
|
+
const shell = Object.fromEntries(Object.entries(node).filter(([k]) => !LAYOUT_FIELDS.has(k)));
|
|
34
|
+
shell.data = { ...data, ...(lanes.length ? { tasks: lanes.map((lane) => (Array.isArray(lane) ? lane.map((t) => (isObj(t) ? t.id : t)) : lane)) } : {}) };
|
|
35
|
+
const touching = edges.filter((e) => e.source === node.id || e.target === node.id).map(stableJson).sort();
|
|
36
|
+
const display = isObj(data.display) ? data.display : {};
|
|
37
|
+
units.set(node.id, {
|
|
38
|
+
kind: isStage ? 'stage' : 'trigger',
|
|
39
|
+
name: String(data.label ?? display.label ?? ''),
|
|
40
|
+
content: stableJson({ node: shell, edges: touching }),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return units;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The id of the unit a finding is on: its `nodeId` when the serializer placed
|
|
47
|
+
* it, else the unit its `where` names. `check` words `where` as a task's name,
|
|
48
|
+
* a stage's or trigger's label, or a phrase that starts with one
|
|
49
|
+
* (`task "Review" in stage "Intake" entry`, `stage "Intake" exit`). Undefined
|
|
50
|
+
* when it names none, or a name two units share.
|
|
51
|
+
*/
|
|
52
|
+
export function unitOf(d, units) {
|
|
53
|
+
if (d.nodeId !== undefined && units.has(d.nodeId))
|
|
54
|
+
return d.nodeId;
|
|
55
|
+
const where = d.where;
|
|
56
|
+
if (where === undefined)
|
|
57
|
+
return undefined;
|
|
58
|
+
const named = (name, kinds) => {
|
|
59
|
+
const ids = [...units].filter(([, u]) => u.name === name && kinds.includes(u.kind)).map(([id]) => id);
|
|
60
|
+
return ids.length === 1 ? ids[0] : undefined;
|
|
61
|
+
};
|
|
62
|
+
const exact = named(where, ['stage', 'task', 'trigger']);
|
|
63
|
+
if (exact !== undefined)
|
|
64
|
+
return exact;
|
|
65
|
+
const task = /^task "(.*?)"(?= |$)/.exec(where);
|
|
66
|
+
if (task)
|
|
67
|
+
return named(task[1], ['task']);
|
|
68
|
+
const stage = /^stage "(.*?)"(?= |$)/.exec(where);
|
|
69
|
+
if (stage)
|
|
70
|
+
return named(stage[1], ['stage']);
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
/** Each unit name that names one unit, to that unit's id. A name two units share is left out. */
|
|
74
|
+
function namesToIds(units) {
|
|
75
|
+
const ids = new Map();
|
|
76
|
+
for (const [id, u] of units)
|
|
77
|
+
if (u.name)
|
|
78
|
+
ids.set(u.name, [...(ids.get(u.name) ?? []), id]);
|
|
79
|
+
return new Map([...ids].filter(([, list]) => list.length === 1).map(([name, [id]]) => [name, id]));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* `message` with every `"quoted"` unit name replaced by `"#<id>"`, for
|
|
83
|
+
* comparing findings across a rename. For instance `Task "Wrap" in stage
|
|
84
|
+
* "Closing" has no entry rule` and the original's `Task "Wrap" in stage
|
|
85
|
+
* "Close" has no entry rule` both read `Task "#t1" in stage "#Stage_a" ...`.
|
|
86
|
+
*/
|
|
87
|
+
function byId(message, names) {
|
|
88
|
+
return message.replace(/"([^"]*)"/g, (quoted, name) => {
|
|
89
|
+
const id = names.get(name);
|
|
90
|
+
return id === undefined ? quoted : `"#${id}"`;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/** What a pre-existing lowering error on a `kind` unit adds to its message ({@link scopeToEdit}). */
|
|
94
|
+
const loweringNote = (kind) => `This ${kind} is unchanged from the baseline, so this is probably an SDK defect: the SDK cannot read what the designer wrote. `
|
|
95
|
+
+ `\`compile\` still refuses this ${kind}, so the case does not compile until the SDK reads it. `
|
|
96
|
+
+ 'Report it: https://github.com/UiPath/builder-sdk/issues';
|
|
97
|
+
/**
|
|
98
|
+
* Scope `edited`'s findings to the edit, against `baseline`: the original
|
|
99
|
+
* caseplan decompiled and checked the same way (the module doc says which
|
|
100
|
+
* finding is which). Every finding gets an `origin`, its `class`, and the
|
|
101
|
+
* `nodeId` of the unit it is on when it names one. A pre-existing finding is a
|
|
102
|
+
* warning; a pre-existing `lowering` one also says it is probably an SDK defect.
|
|
103
|
+
*
|
|
104
|
+
* When the edited case's serializer threw past collect mode, the rest of the
|
|
105
|
+
* case was never judged, so one more error, CHECK_INCOMPLETE, says so: passing
|
|
106
|
+
* never means "not checked".
|
|
107
|
+
*/
|
|
108
|
+
export function scopeToEdit(edited, baseline) {
|
|
109
|
+
const editedUnits = caseUnits(edited.plan);
|
|
110
|
+
const baselineUnits = caseUnits(baseline.plan);
|
|
111
|
+
// Messages are compared with each unit's name replaced by its id, so a
|
|
112
|
+
// renamed stage does not change the findings of the untouched tasks in it.
|
|
113
|
+
const editedNames = namesToIds(editedUnits);
|
|
114
|
+
const baselineNames = namesToIds(baselineUnits);
|
|
115
|
+
const scoped = edited.diagnostics.map((d) => {
|
|
116
|
+
const message = byId(d.message, editedNames);
|
|
117
|
+
const unit = unitOf(d, editedUnits);
|
|
118
|
+
if (unit === undefined)
|
|
119
|
+
return { level: d.level, code: d.code, message, place: '', unchanged: false };
|
|
120
|
+
const before = baselineUnits.get(unit);
|
|
121
|
+
return { level: d.level, code: d.code, message, place: unit, unchanged: before !== undefined && before.content === editedUnits.get(unit).content };
|
|
122
|
+
});
|
|
123
|
+
const preExisting = preExistingFindings(scoped, baseline.diagnostics.map((d) => ({ level: d.level, code: d.code, message: byId(d.message, baselineNames), place: unitOf(d, baselineUnits) ?? '' })));
|
|
124
|
+
const placed = edited.diagnostics.map((d, i) => {
|
|
125
|
+
const unit = scoped[i].place;
|
|
126
|
+
const cls = refusalClass(d.code);
|
|
127
|
+
return { ...d, ...(unit !== '' ? { nodeId: unit } : {}), ...(cls !== undefined ? { class: cls } : {}) };
|
|
128
|
+
});
|
|
129
|
+
// The lowering note names the unit, so each finding is scoped with its own.
|
|
130
|
+
const out = placed.map((d, i) => scopeFindings([d], preExisting.has(i) ? new Set([0]) : new Set(), loweringNote(scoped[i].place !== '' ? editedUnits.get(scoped[i].place).kind : 'part of the case'))[0]);
|
|
131
|
+
if (edited.stoppedAt) {
|
|
132
|
+
const at = edited.stoppedAt.code !== undefined ? `[${edited.stoppedAt.code}] ` : '';
|
|
133
|
+
out.push({
|
|
134
|
+
level: 'error', code: 'CHECK_INCOMPLETE',
|
|
135
|
+
message: `check stopped at ${at}${edited.stoppedAt.message} Nothing after it was checked, so the edit is not judged. `
|
|
136
|
+
+ 'Fix it, even if the original has it too, and run check again.',
|
|
137
|
+
class: refusalClass('CHECK_INCOMPLETE'), origin: 'edited',
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
package/dist/check.js
CHANGED
|
@@ -19,6 +19,7 @@ import { compareSchemaVersions, schemaVersionRefusal } from './schema-version.js
|
|
|
19
19
|
import { planFlowGlobals, planSharedInputs, sharedInputRoots } from './flow-variables.js';
|
|
20
20
|
import { backedOutputs } from './flow-output-backing.js';
|
|
21
21
|
import { childStepLists } from './flow-step-tree.js';
|
|
22
|
+
import { unsatisfiableJoins } from './core/exclusive-join.js';
|
|
22
23
|
import { VARS_READ_RE } from './core/vars-read.js';
|
|
23
24
|
import { FLOW_METADATA_KEYS, unknownMetadataKeys } from './core/flow-metadata.js';
|
|
24
25
|
import { endContentKey } from './flow-end-content.js';
|
|
@@ -60,8 +61,10 @@ export function checkCompiled(built, opts = {}) {
|
|
|
60
61
|
}
|
|
61
62
|
const serialized = opts.serializer !== false
|
|
62
63
|
? serializerRefusals(built, { library: opts.library, bindings: opts.bindings, resources: opts.resources, nodeCatalog: opts.nodeCatalog, ...(opts.solution !== undefined ? { solution: opts.solution } : {}) }, diags)
|
|
63
|
-
: { diagnostics: [], flow: undefined };
|
|
64
|
+
: { diagnostics: [], flow: undefined, scopes: [] };
|
|
64
65
|
diags.push(...serialized.diagnostics);
|
|
66
|
+
if (serialized.flow !== undefined)
|
|
67
|
+
diags.push(...mergeNeverCompletes(serialized.flow, serialized.scopes ?? []));
|
|
65
68
|
const placed = serialized.flow !== undefined ? placeDiagnostics(diags, serialized.flow) : undefined;
|
|
66
69
|
const diagnostics = diags.map((d, i) => {
|
|
67
70
|
const nodeId = d.nodeId ?? (placed?.[i].nodeId || undefined);
|
|
@@ -144,6 +147,75 @@ export function scopeToEdit(edited, baseline) {
|
|
|
144
147
|
const PRE_EXISTING_LOWERING_NOTE = 'This node is unchanged from the baseline, so this is probably an SDK defect: '
|
|
145
148
|
+ 'the SDK cannot read what the designer wrote. `compile` refuses this node; `merge --baseline-from` keeps it as saved. '
|
|
146
149
|
+ 'Report it: https://github.com/UiPath/builder-sdk/issues';
|
|
150
|
+
/**
|
|
151
|
+
* MERGE_NEVER_COMPLETES, on each graph level the serializer pass emitted
|
|
152
|
+
* (`core/exclusive-join.ts`). Nodes map to steps through the ids that pass
|
|
153
|
+
* gave them (`EmittedScope.stepNodeId`), since a subflow's ids can be prefixed.
|
|
154
|
+
*/
|
|
155
|
+
function mergeNeverCompletes(flow, scopes) {
|
|
156
|
+
const out = [];
|
|
157
|
+
const definitions = Array.isArray(flow?.definitions) ? flow.definitions : [];
|
|
158
|
+
for (const scope of scopes) {
|
|
159
|
+
const graph = scope.subflow === undefined ? flow : flow?.subflows?.[scope.subflow];
|
|
160
|
+
if (graph === undefined || graph === null)
|
|
161
|
+
continue;
|
|
162
|
+
const named = new Map();
|
|
163
|
+
const visit = (list) => {
|
|
164
|
+
for (const st of list) {
|
|
165
|
+
if ('name' in st && st.kind !== 'return' && !named.has(st.name))
|
|
166
|
+
named.set(st.name, st);
|
|
167
|
+
for (const child of childStepLists(st))
|
|
168
|
+
visit(child);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
visit(scope.steps);
|
|
172
|
+
const byNode = new Map();
|
|
173
|
+
for (const [name, id] of scope.stepNodeId) {
|
|
174
|
+
const st = named.get(name);
|
|
175
|
+
if (st)
|
|
176
|
+
byNode.set(id, st);
|
|
177
|
+
}
|
|
178
|
+
const splitOf = (n, model) => {
|
|
179
|
+
const kind = byNode.get(n.id)?.kind;
|
|
180
|
+
if (kind === 'branch')
|
|
181
|
+
return 'Decision';
|
|
182
|
+
if (kind === 'switch')
|
|
183
|
+
return 'Switch';
|
|
184
|
+
return model === 'bpmn:ExclusiveGateway' ? 'Decision' : undefined;
|
|
185
|
+
};
|
|
186
|
+
const nameOf = (id, label) => { const st = byNode.get(id); return st && 'name' in st ? st.name : label; };
|
|
187
|
+
for (const j of unsatisfiableJoins({ nodes: graph.nodes, edges: graph.edges, definitions }, splitOf)) {
|
|
188
|
+
const name = nameOf(j.joinId, j.joinLabel);
|
|
189
|
+
const splitName = nameOf(j.splitId, j.splitLabel);
|
|
190
|
+
const ports = j.ports.map((p) => `"${p}"`).join(', ');
|
|
191
|
+
const isParallel = byNode.get(j.joinId)?.kind === 'parallel';
|
|
192
|
+
const method = j.splitKind === 'Switch' ? 'switch' : 'branch';
|
|
193
|
+
const prefix = scope.callers.map((c) => `In subflow "${c}": `).join('');
|
|
194
|
+
// The step the Merge hands on to: where the arms should meet instead.
|
|
195
|
+
const nextId = (graph.edges ?? []).find((e) => e?.sourceNodeId === j.joinId)?.targetNodeId;
|
|
196
|
+
const nextStep = nextId !== undefined ? byNode.get(nextId) : undefined;
|
|
197
|
+
const next = nextStep && 'name' in nextStep ? nextStep.name : undefined;
|
|
198
|
+
out.push({
|
|
199
|
+
level: 'error', code: 'MERGE_NEVER_COMPLETES',
|
|
200
|
+
message: `${prefix}${isParallel ? `.parallel("${name}")'s Merge` : `Merge "${name}"`} can never complete: every path into it `
|
|
201
|
+
+ `comes from a different branch of ${j.splitKind} "${splitName}" (ports ${ports}). A Merge is a parallel join that `
|
|
202
|
+
+ `waits for ALL its incoming paths, but a ${j.splitKind} takes exactly one branch, so the run stops at "${name}" `
|
|
203
|
+
+ `and never reaches an End (\`uip maestro flow validate\` refuses the file for the same reason). `
|
|
204
|
+
+ (isParallel
|
|
205
|
+
? `Add a step after the .${method}("${splitName}") inside the arm, so its paths meet there and the arm hands the `
|
|
206
|
+
+ `join one edge; or, if no other arm reaches the join, drop the .parallel and chain the steps.`
|
|
207
|
+
: `Remove the Merge step: the .${method}'s arms meet at ${next !== undefined ? `"${next}"` : 'the next step'} on their `
|
|
208
|
+
+ `own, since a step accepts several incoming edges. Use a Merge only to join arms that run at the same time (.parallel).`),
|
|
209
|
+
suggestion: isParallel
|
|
210
|
+
? `.parallel('${name}', [(a) => a.${method}('${splitName}', …).step('meet', …), …])`
|
|
211
|
+
: `.${method}('${splitName}', …)${next !== undefined ? `.step('${next}', …)` : ''}`,
|
|
212
|
+
step: [...scope.callers, name].join(' › '),
|
|
213
|
+
...(scope.callers.length === 0 ? { nodeId: j.joinId } : {}),
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
147
219
|
/** The error-level diagnostics a custom node's own `diagnostics()` reported (see `serializerRefusals`). */
|
|
148
220
|
const OWN_NODE_ERRORS = new WeakSet();
|
|
149
221
|
/**
|
|
@@ -163,13 +235,14 @@ const OWN_NODE_ERRORS = new WeakSet();
|
|
|
163
235
|
*/
|
|
164
236
|
function serializerRefusals(built, compile, found) {
|
|
165
237
|
const collected = [];
|
|
238
|
+
const scopes = [];
|
|
166
239
|
const warned = [];
|
|
167
240
|
let flow;
|
|
168
241
|
let stoppedAt;
|
|
169
242
|
try {
|
|
170
243
|
// A stale `.layout()` key is the one serializer warning `check` repeats: compile
|
|
171
244
|
// drops the entry, and the author can only see that here (#1994).
|
|
172
|
-
flow = serialize(built, { ...compile, collect: (r) => collected.push(r), warn: (w) => { if (w.code === 'LAYOUT_UNKNOWN_KEY')
|
|
245
|
+
flow = serialize(built, { ...compile, collect: (r) => collected.push(r), scopes: (sc) => scopes.push(sc), warn: (w) => { if (w.code === 'LAYOUT_UNKNOWN_KEY')
|
|
173
246
|
warned.push(w); } });
|
|
174
247
|
// Collection stopped: the refusal that stopped it is the last one reported.
|
|
175
248
|
const stop = collected[collected.length - 1];
|
|
@@ -217,7 +290,7 @@ function serializerRefusals(built, compile, found) {
|
|
|
217
290
|
seen.add(key);
|
|
218
291
|
out.push({ level: 'warning', code: w.code, message: w.message });
|
|
219
292
|
}
|
|
220
|
-
return { diagnostics: out, flow, ...(stoppedAt ? { stoppedAt } : {}) };
|
|
293
|
+
return { diagnostics: out, flow, scopes, ...(stoppedAt ? { stoppedAt } : {}) };
|
|
221
294
|
}
|
|
222
295
|
/**
|
|
223
296
|
* `ancestors` is the chain of child flows currently being checked, innermost
|
|
@@ -2333,8 +2406,8 @@ const OUTPUT_READ_RULES = {
|
|
|
2333
2406
|
* that was not taken, and the run stays Running with no incident. That was
|
|
2334
2407
|
* measured live on 09-01 (a Merge fed by a Decision's two ports). An older note
|
|
2335
2408
|
* here said such flows "deploy and run"; they deploy, and they do not finish.
|
|
2336
|
-
*
|
|
2337
|
-
*
|
|
2409
|
+
* MERGE_NEVER_COMPLETES (`mergeNeverCompletes`) judges that shape on the
|
|
2410
|
+
* compiled graph. This function refuses it when a
|
|
2338
2411
|
* human task's outcome edge is among the arm's alternative edges into the join
|
|
2339
2412
|
* — a fan-out task at the arm's end, one empty `.stepSwitch` arm beside a body
|
|
2340
2413
|
* arm, a task on one side of a `.branch` (HITL_FAN_OUT_INTO_JOIN) — and an
|
|
@@ -30,6 +30,7 @@ export function registerCaseCommands(program) {
|
|
|
30
30
|
.option('--connectors-local <dir>', 'connection-resolved connector overlay')
|
|
31
31
|
.option('--bindings <file>', 'bindings.json, for the connection/folder label rules')
|
|
32
32
|
.option('--resources <file>', 'resource ledger that registry prepare writes (default .flow-sdk/resources.json)')
|
|
33
|
+
.option('--baseline <file>', 'the original caseplan.json the source was decompiled from: findings on stages, tasks and triggers the edit did not touch, which the original has too, become warnings')
|
|
33
34
|
.addOption(retiredCompiledOption())
|
|
34
35
|
.action(async (input, options) => {
|
|
35
36
|
let mode;
|
|
@@ -49,6 +50,7 @@ export function registerCaseCommands(program) {
|
|
|
49
50
|
addValue(argv, '--connectors-local', options.connectorsLocal);
|
|
50
51
|
addValue(argv, '--bindings', options.bindings);
|
|
51
52
|
addValue(argv, '--resources', options.resources);
|
|
53
|
+
addValue(argv, '--baseline', options.baseline);
|
|
52
54
|
await invoke('case check', () => import('../../case/check-cli.js'), argv);
|
|
53
55
|
});
|
|
54
56
|
family.command('decompile')
|
package/dist/cli-result.d.ts
CHANGED
|
@@ -53,6 +53,13 @@ export declare function reportDiagnostics(diags: ReadonlyArray<ReportedDiagnosti
|
|
|
53
53
|
* the origin ends.
|
|
54
54
|
*/
|
|
55
55
|
export declare function diagnosticLine(d: ReportedDiagnostic): string;
|
|
56
|
+
/**
|
|
57
|
+
* `mark`, `d`'s message and `suffix`, with `check --baseline`'s origin ending
|
|
58
|
+
* the message's first line, where it is seen: ` (edited)`, ` (pre-existing)`
|
|
59
|
+
* for a lowering finding (its note follows on the next line), else
|
|
60
|
+
* ` (pre-existing, not counted)`. Without an origin, just the three.
|
|
61
|
+
*/
|
|
62
|
+
export declare function withOrigin(mark: string, d: Pick<ReportedDiagnostic, 'message' | 'class' | 'origin'>, suffix?: string): string;
|
|
56
63
|
/**
|
|
57
64
|
* The error diagnostic for a throw that ends a compile: the error's own string
|
|
58
65
|
* `code` when it carries one, else `COMPILE_FAILED`.
|
package/dist/cli-result.js
CHANGED
|
@@ -78,10 +78,17 @@ export function diagnosticLine(d) {
|
|
|
78
78
|
const named = d.step !== undefined && d.message.includes(`"${d.step.split(' › ').pop()}"`);
|
|
79
79
|
const suffix = (d.step !== undefined && !named ? ` (step "${d.step}")` : '')
|
|
80
80
|
+ (d.suggestion ? ` (did you mean "${d.suggestion}"?)` : '');
|
|
81
|
-
|
|
81
|
+
return withOrigin(`${d.level === 'error' ? '✗' : '⚠'} [${d.code}]`, d, suffix);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* `mark`, `d`'s message and `suffix`, with `check --baseline`'s origin ending
|
|
85
|
+
* the message's first line, where it is seen: ` (edited)`, ` (pre-existing)`
|
|
86
|
+
* for a lowering finding (its note follows on the next line), else
|
|
87
|
+
* ` (pre-existing, not counted)`. Without an origin, just the three.
|
|
88
|
+
*/
|
|
89
|
+
export function withOrigin(mark, d, suffix = '') {
|
|
82
90
|
if (d.origin === undefined)
|
|
83
91
|
return `${mark} ${d.message}${suffix}`;
|
|
84
|
-
// With a baseline the origin ends the finding's first line, where it is seen.
|
|
85
92
|
const origin = d.origin === 'edited' ? ' (edited)'
|
|
86
93
|
: d.class === 'lowering' ? ' (pre-existing)' : ' (pre-existing, not counted)';
|
|
87
94
|
const [first, ...rest] = d.message.split('\n');
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MERGE_NEVER_COMPLETES: a Merge (a `bpmn:ParallelGateway`) waits for a token
|
|
3
|
+
* on every incoming edge, so when every edge into it comes from a different
|
|
4
|
+
* branch of one Decision or Switch, which sends one token, it never completes.
|
|
5
|
+
*
|
|
6
|
+
* d --true--> A --> join
|
|
7
|
+
* d --false-------> join `join` waits for two tokens; `d` sends one.
|
|
8
|
+
*
|
|
9
|
+
* The same walk as `uip maestro flow validate` (maestro-tool
|
|
10
|
+
* `flow-validate-service` `findUnsatisfiableJoin`), so check and validate
|
|
11
|
+
* refuse the same files.
|
|
12
|
+
*/
|
|
13
|
+
export interface JoinNode {
|
|
14
|
+
id: string;
|
|
15
|
+
type?: string;
|
|
16
|
+
model?: {
|
|
17
|
+
type?: unknown;
|
|
18
|
+
};
|
|
19
|
+
display?: {
|
|
20
|
+
label?: unknown;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
interface JoinEdge {
|
|
24
|
+
sourceNodeId: string;
|
|
25
|
+
sourcePort?: string;
|
|
26
|
+
targetNodeId: string;
|
|
27
|
+
}
|
|
28
|
+
/** One graph level: the root flow's nodes and edges, or one subflow's, with the file's definitions. */
|
|
29
|
+
export interface JoinGraph {
|
|
30
|
+
nodes?: readonly JoinNode[];
|
|
31
|
+
edges?: readonly JoinEdge[];
|
|
32
|
+
definitions?: ReadonlyArray<{
|
|
33
|
+
nodeType?: string;
|
|
34
|
+
model?: {
|
|
35
|
+
type?: unknown;
|
|
36
|
+
};
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
39
|
+
/** A Merge that can never complete, and the split whose branches all feed it. */
|
|
40
|
+
export interface UnsatisfiableJoin {
|
|
41
|
+
/** The Merge node's id and label (its id when it has none). */
|
|
42
|
+
joinId: string;
|
|
43
|
+
joinLabel: string;
|
|
44
|
+
/** The Decision or Switch node's id and label. */
|
|
45
|
+
splitId: string;
|
|
46
|
+
splitLabel: string;
|
|
47
|
+
splitKind: 'Decision' | 'Switch';
|
|
48
|
+
/** The split's ports the Merge's incoming paths leave by, sorted. */
|
|
49
|
+
ports: string[];
|
|
50
|
+
}
|
|
51
|
+
/** Whether a node is a Decision or a Switch, and which; `undefined` for any other node. */
|
|
52
|
+
export type SplitOf = (node: JoinNode, modelType: unknown) => 'Decision' | 'Switch' | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Every Merge of one graph level that can never complete, in node order.
|
|
55
|
+
* `splitOf` names the exclusive splits; by default only a `bpmn:ExclusiveGateway`
|
|
56
|
+
* model type is one (reported as a Decision, as validate words it).
|
|
57
|
+
*/
|
|
58
|
+
export declare function unsatisfiableJoins(graph: JoinGraph, splitOf?: SplitOf): UnsatisfiableJoin[];
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MERGE_NEVER_COMPLETES: a Merge (a `bpmn:ParallelGateway`) waits for a token
|
|
3
|
+
* on every incoming edge, so when every edge into it comes from a different
|
|
4
|
+
* branch of one Decision or Switch, which sends one token, it never completes.
|
|
5
|
+
*
|
|
6
|
+
* d --true--> A --> join
|
|
7
|
+
* d --false-------> join `join` waits for two tokens; `d` sends one.
|
|
8
|
+
*
|
|
9
|
+
* The same walk as `uip maestro flow validate` (maestro-tool
|
|
10
|
+
* `flow-validate-service` `findUnsatisfiableJoin`), so check and validate
|
|
11
|
+
* refuse the same files.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Every Merge of one graph level that can never complete, in node order.
|
|
15
|
+
* `splitOf` names the exclusive splits; by default only a `bpmn:ExclusiveGateway`
|
|
16
|
+
* model type is one (reported as a Decision, as validate words it).
|
|
17
|
+
*/
|
|
18
|
+
export function unsatisfiableJoins(graph, splitOf = (_n, model) => (model === 'bpmn:ExclusiveGateway' ? 'Decision' : undefined)) {
|
|
19
|
+
const nodes = Array.isArray(graph.nodes) ? graph.nodes : [];
|
|
20
|
+
const edges = Array.isArray(graph.edges) ? graph.edges : [];
|
|
21
|
+
const modelByType = new Map();
|
|
22
|
+
for (const def of Array.isArray(graph.definitions) ? graph.definitions : []) {
|
|
23
|
+
if (typeof def?.nodeType === 'string' && typeof def.model?.type === 'string')
|
|
24
|
+
modelByType.set(def.nodeType, def.model.type);
|
|
25
|
+
}
|
|
26
|
+
const modelType = (n) => (typeof n.model?.type === 'string' ? n.model.type : modelByType.get(n.type ?? ''));
|
|
27
|
+
const byId = new Map(nodes.map((n) => [n.id, n]));
|
|
28
|
+
const incoming = new Map();
|
|
29
|
+
for (const e of edges) {
|
|
30
|
+
const list = incoming.get(e.targetNodeId) ?? [];
|
|
31
|
+
list.push(e);
|
|
32
|
+
incoming.set(e.targetNodeId, list);
|
|
33
|
+
}
|
|
34
|
+
const isJoin = (n) => modelType(n) === 'bpmn:ParallelGateway';
|
|
35
|
+
const isSplit = (n) => splitOf(n, modelType(n)) !== undefined;
|
|
36
|
+
/** The split this edge's path leaves, and by which port, when the walk reaches one. */
|
|
37
|
+
const originOf = (edge) => {
|
|
38
|
+
let current = edge;
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
while (current !== undefined && !seen.has(current.sourceNodeId)) {
|
|
41
|
+
const source = byId.get(current.sourceNodeId);
|
|
42
|
+
if (!source)
|
|
43
|
+
return undefined;
|
|
44
|
+
seen.add(source.id);
|
|
45
|
+
if (isSplit(source))
|
|
46
|
+
return { splitId: source.id, port: current.sourcePort };
|
|
47
|
+
const up = incoming.get(source.id) ?? [];
|
|
48
|
+
current = up.length === 1 ? up[0] : undefined;
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
};
|
|
52
|
+
const found = [];
|
|
53
|
+
for (const node of nodes) {
|
|
54
|
+
if (!isJoin(node))
|
|
55
|
+
continue;
|
|
56
|
+
const into = incoming.get(node.id) ?? [];
|
|
57
|
+
if (into.length < 2)
|
|
58
|
+
continue;
|
|
59
|
+
const origins = into.map(originOf);
|
|
60
|
+
if (origins.some((o) => o === undefined))
|
|
61
|
+
continue;
|
|
62
|
+
const resolved = origins;
|
|
63
|
+
if (new Set(resolved.map((o) => o.splitId)).size !== 1)
|
|
64
|
+
continue;
|
|
65
|
+
const ports = [...new Set(resolved.map((o) => String(o.port)))].sort((a, b) => a.localeCompare(b));
|
|
66
|
+
if (ports.length < 2)
|
|
67
|
+
continue;
|
|
68
|
+
const split = byId.get(resolved[0].splitId);
|
|
69
|
+
const label = (n) => (typeof n.display?.label === 'string' ? n.display.label : n.id);
|
|
70
|
+
found.push({
|
|
71
|
+
joinId: node.id, joinLabel: label(node),
|
|
72
|
+
splitId: split.id, splitLabel: label(split),
|
|
73
|
+
splitKind: splitOf(split, modelType(split)) ?? 'Decision',
|
|
74
|
+
ports,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return found;
|
|
78
|
+
}
|
package/dist/core/refusals.d.ts
CHANGED
|
@@ -618,6 +618,7 @@ export declare const REFUSALS: {
|
|
|
618
618
|
readonly LOOP_PARALLEL_LEGACY: "lint";
|
|
619
619
|
readonly LOOP_VERSION_UNSUPPORTED: "lowering";
|
|
620
620
|
readonly MANAGED_HTTP_ABSOLUTE_URL: "lint";
|
|
621
|
+
readonly MERGE_NEVER_COMPLETES: "lint";
|
|
621
622
|
readonly METHOD_MISSING_PARENTHESES: "lint";
|
|
622
623
|
readonly MISSING_CONDITION_EXPRESSION: "lint";
|
|
623
624
|
readonly MISSING_RESOURCE: "lint";
|
package/dist/core/refusals.js
CHANGED
|
@@ -694,6 +694,7 @@ export const REFUSALS = {
|
|
|
694
694
|
LOOP_PARALLEL_LEGACY: 'lint',
|
|
695
695
|
LOOP_VERSION_UNSUPPORTED: 'lowering',
|
|
696
696
|
MANAGED_HTTP_ABSOLUTE_URL: 'lint',
|
|
697
|
+
MERGE_NEVER_COMPLETES: 'lint',
|
|
697
698
|
METHOD_MISSING_PARENTHESES: 'lint',
|
|
698
699
|
MISSING_CONDITION_EXPRESSION: 'lint',
|
|
699
700
|
MISSING_RESOURCE: 'lint',
|
package/dist/serialize.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { type ResourceResolutions } from './core/resource-resolution.js';
|
|
|
10
10
|
import type { SolutionProjects } from './core/solution-projects.js';
|
|
11
11
|
import type { NodeCatalog } from './core/node-catalog.js';
|
|
12
12
|
import type { DefinitionReference } from './core/node-classes.js';
|
|
13
|
-
import type { BuiltFlow } from './flow-sdk.js';
|
|
13
|
+
import type { BuiltFlow, Step } from './flow-sdk.js';
|
|
14
14
|
import type { Library } from './library.js';
|
|
15
15
|
import { type BindingRefusalCode, type BindingsView } from './core/binding-messages.js';
|
|
16
16
|
import { CONNECTOR_INPUT_MISSING, connectorInputErrors as coreConnectorInputErrors } from './core/connector-inputs.js';
|
|
@@ -47,6 +47,16 @@ export interface DraftFinding {
|
|
|
47
47
|
/** The sentence the strict compile refuses with. */
|
|
48
48
|
message: string;
|
|
49
49
|
}
|
|
50
|
+
/** One emitted graph level (see {@link SerializeOpts.scopes}). */
|
|
51
|
+
export interface EmittedScope {
|
|
52
|
+
/** The body's key in `subflows`; absent for the root. */
|
|
53
|
+
subflow?: string;
|
|
54
|
+
/** The calling steps' names, outermost first. */
|
|
55
|
+
callers: readonly string[];
|
|
56
|
+
steps: readonly Step[];
|
|
57
|
+
/** Step name to the node id compile gave it in this graph level. */
|
|
58
|
+
stepNodeId: ReadonlyMap<string, string>;
|
|
59
|
+
}
|
|
50
60
|
/** A refusal a collect-mode serialize reported instead of throwing (see {@link SerializeOpts.collect}). */
|
|
51
61
|
export interface CollectedRefusal {
|
|
52
62
|
code: string;
|
|
@@ -167,6 +177,15 @@ export interface SerializeOpts {
|
|
|
167
177
|
* both, each on its own step, where an ordinary compile stops at the first.
|
|
168
178
|
*/
|
|
169
179
|
collect?: (refusal: CollectedRefusal) => void;
|
|
180
|
+
/**
|
|
181
|
+
* Each graph level the compile emitted, with the node id it gave each step:
|
|
182
|
+
* the root (`subflow` undefined), and every subflow body under its key in
|
|
183
|
+
* `subflows`. `callers` are the calling steps' names, outermost first.
|
|
184
|
+
* A subflow's ids can carry a prefix (`call_cd` for step `cd` of the child
|
|
185
|
+
* `call` runs), so a reader of the compiled graph maps nodes to steps here,
|
|
186
|
+
* not by name.
|
|
187
|
+
*/
|
|
188
|
+
scopes?: (scope: EmittedScope) => void;
|
|
170
189
|
/**
|
|
171
190
|
* Filled in by `serialize` with the extra files the flow needs beside the
|
|
172
191
|
* `.flow`, relative to it: one `<source>/agent.json` per inline agent, plus a
|
package/dist/serialize.js
CHANGED
|
@@ -2036,6 +2036,7 @@ function serializeFlow(built, opts) {
|
|
|
2036
2036
|
scope.variableUpdates[startId] = [...(scope.variableUpdates[startId] ?? []), ...renderUpdates(startUpdates, scope.rename)];
|
|
2037
2037
|
}
|
|
2038
2038
|
const tails = emit(child.steps, [{ node: startId, port: 'output' }], scope);
|
|
2039
|
+
opts.scopes?.({ subflow: nodeId, callers: [...subflowPath], steps: child.steps, stepNodeId: scope.stepNodeId });
|
|
2039
2040
|
// Same as the root's implicit End — mapped against the SUBFLOW's own
|
|
2040
2041
|
// outputs, which is the scope the product validates a subflow body in.
|
|
2041
2042
|
const capped = tailsToCap(scope, tails);
|
|
@@ -3659,6 +3660,7 @@ function serializeFlow(built, opts) {
|
|
|
3659
3660
|
}
|
|
3660
3661
|
}
|
|
3661
3662
|
}
|
|
3663
|
+
opts.scopes?.({ callers: [], steps: [...built.steps, ...(built.entryPoints ?? []).flatMap((ep) => ep.steps)], stepNodeId: root.stepNodeId });
|
|
3662
3664
|
// ── Shared root inputs (#924) ────────────────────────────────────────────
|
|
3663
3665
|
// An input marked `{ shared: '<var>' }` is copied into that variable on its
|
|
3664
3666
|
// root's TRIGGER node: a `variableUpdates[<triggerId>]` row, the same
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uipath/maestro-builder-sdk",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.121.0",
|
|
4
4
|
"description": "Build UiPath Flow, Case, and BPMN artifacts by writing TypeScript.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://docs.uipath.com/maestro",
|
|
@@ -86,7 +86,8 @@
|
|
|
86
86
|
"flow-decompile-scripts",
|
|
87
87
|
"flow-script-metadata",
|
|
88
88
|
"flow-pipeline-strict",
|
|
89
|
-
"flow-build"
|
|
89
|
+
"flow-build",
|
|
90
|
+
"case-check-baseline"
|
|
90
91
|
],
|
|
91
92
|
"files": [
|
|
92
93
|
"dist",
|
|
@@ -124,5 +125,5 @@
|
|
|
124
125
|
"@types/node": "^22.7.0",
|
|
125
126
|
"esbuild": "^0.28.1"
|
|
126
127
|
},
|
|
127
|
-
"gitref": "
|
|
128
|
+
"gitref": "d4c64e082269d1c48c1c9645b03ff8922b2d2a4c"
|
|
128
129
|
}
|