@uipath/maestro-builder-sdk 6.97.3 → 6.99.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.
@@ -0,0 +1,76 @@
1
+ import type { BuiltBpmn } from './bpmn-sdk.js';
2
+ import { type BpmnCheckOpts, type CheckedBpmn, type Diagnostic } from './check.js';
3
+ /** A built process together with what `check` found in it. */
4
+ export interface CheckedProcess {
5
+ built: BuiltBpmn;
6
+ checked: CheckedBpmn;
7
+ }
8
+ /**
9
+ * Every element of `built` by id, as the text two builds are compared by. Nodes and
10
+ * flows at every depth, and the declarations: variables (the root's and each
11
+ * sub-process's own), bindings, messages and errors.
12
+ * Two declarations that share an id are kept together, so either changing counts.
13
+ */
14
+ export declare function elementIndex(built: BuiltBpmn): Map<string, string>;
15
+ /**
16
+ * Scope `edited`'s findings to the edit, against `baseline`: the original decompiled,
17
+ * built and checked the same way. See the file header for the rule. Each finding comes
18
+ * back with its `class` (when the code has one) and its `origin`.
19
+ *
20
+ * For instance, an `INTSVC_CONNECTION_MISSING` on a connector task the edit did not
21
+ * touch, which the original reports too, comes back as a `pre-existing` warning; the
22
+ * same finding after the edit renamed that task is an `edited` error.
23
+ */
24
+ export declare function scopeToEdit(edited: CheckedProcess, baseline: CheckedProcess): Diagnostic[];
25
+ /** What {@link checkAgainstBaseline} needs besides the edited process and the original. */
26
+ export interface BaselineCheckOpts extends BpmnCheckOpts {
27
+ /**
28
+ * The edited `.bpmn.ts` text, for the decompile stamp on its first line: the original
29
+ * is decompiled with the options it records, so an untouched element builds the same
30
+ * on both sides. With no readable stamp, `bpmn decompile`'s defaults are used
31
+ * (`style=explicit`, connectors lifted when a library is open).
32
+ */
33
+ source?: string;
34
+ /** Called with each note worth printing (the original changed since the decompile). */
35
+ onWarning?: (message: string) => void;
36
+ }
37
+ /**
38
+ * Why `xml` is not a `.bpmn` document, or `undefined` when it is one: XML with a
39
+ * `bpmn:process`. `check --baseline` refuses anything else before loading it, such as
40
+ * the `.bpmn.ts` source passed by mistake (`no bpmn:process element`) or a truncated
41
+ * file (`not XML: <the parser's message>`).
42
+ */
43
+ export declare function bpmnDocumentProblem(xml: string): string | undefined;
44
+ /**
45
+ * Check `built` and scope its findings to the edit ({@link scopeToEdit}), against
46
+ * `original`, the `.bpmn` text the source was decompiled from.
47
+ *
48
+ * @param built - The edited process, built from the source.
49
+ * @param original - The original `.bpmn` text.
50
+ * @param opts - The check options (the same for both checks) and the edited source.
51
+ * @returns Every finding of the edited check, each with its `origin`.
52
+ */
53
+ export declare function checkAgainstBaseline(built: BuiltBpmn, original: string, opts?: BaselineCheckOpts): Promise<Diagnostic[]>;
54
+ /**
55
+ * The baseline half of {@link checkAgainstBaseline}: `original` decompiled (with the
56
+ * options the source's stamp records), built and checked.
57
+ *
58
+ * @throws What the decompile or the build throws: the original does not decompile.
59
+ */
60
+ export declare function checkOriginal(original: string, opts?: BaselineCheckOpts): Promise<CheckedProcess>;
61
+ /**
62
+ * `original` decompiled, with the options the source's stamp records, and built: the
63
+ * process the source was before the edit. A CLI runs it before it loads the source, so
64
+ * a failure here is reported as the original's, never the source's; it then checks the
65
+ * result with the library it checks the edit with (`bpmn/check-cli.ts`).
66
+ *
67
+ * @param opts - `library` lifts connector tasks as `bpmn decompile` did; `source`
68
+ * carries the stamp; `onWarning` hears that the original changed since the decompile.
69
+ * @throws What the decompile or the build throws: the original does not decompile.
70
+ */
71
+ export declare function buildOriginal(original: string, opts?: Pick<BaselineCheckOpts, 'library' | 'source' | 'onWarning'>): Promise<BuiltBpmn>;
72
+ /**
73
+ * The `--baseline` summary line, for instance
74
+ * `1 error(s) in edited elements, 0 pre-existing SDK defect(s), 9 pre-existing warning(s)`.
75
+ */
76
+ export declare function bpmnBaselineSummary(diags: readonly Diagnostic[]): string;
@@ -0,0 +1,201 @@
1
+ /**
2
+ * check-baseline — `bpmn check --baseline <original.bpmn>`: scope the findings to the edit.
3
+ *
4
+ * In a brownfield edit the agent decompiles an existing `.bpmn`, edits the source, and
5
+ * checks it. `check` judges the whole process, so a defect the original already had, on
6
+ * an element the agent never touched, fails every edit anywhere in the file. For
7
+ * instance, a production process whose nine connector tasks name no connection gets nine
8
+ * `INTSVC_CONNECTION_MISSING` errors, and an agent fixing a typo in one script task can
9
+ * never get a green check without rewiring connections it did not touch.
10
+ *
11
+ * With a baseline, the original is decompiled (with the options the source's decompile
12
+ * stamp records), built and checked the same way, in memory, and each finding gets an
13
+ * `origin` (core/baseline-scope.ts, shared with `flow check --baseline`):
14
+ *
15
+ * - `pre-existing` when its element is UNCHANGED (below) and the original reports the
16
+ * same code, at the same level, on that element; it becomes a warning. A finding that names no element
17
+ * is pre-existing when the original reports the same code and message.
18
+ * - `edited` otherwise: an element the edit changed or added, or an untouched element
19
+ * the original does not have the finding on (an edit elsewhere broke it).
20
+ *
21
+ * An element is unchanged when the edited build and the original's build hold the same
22
+ * element under its id: the same node (kind, name, type, inputs, outputs, extension
23
+ * payload, every field the builder carries), the same sequence flow (source, target,
24
+ * condition), the same variable, binding, message or error declaration. Wiring is not
25
+ * part of a node, so a node whose neighbour was rewired is still unchanged; a
26
+ * sub-process is compared without its children, which are elements of their own.
27
+ * Both builds come from a decompile of the same original with the same options, so an
28
+ * element the author did not edit is the same object on both sides.
29
+ *
30
+ * A pre-existing `lowering` error (`compile` cannot write the element) also says it is
31
+ * probably an SDK defect: the element is the original's, so the SDK failed to read it.
32
+ * When the serializer pass of the edited check stopped early, the rest of the process
33
+ * was never judged, so CHECK_INCOMPLETE says so: passing never means "not checked".
34
+ */
35
+ import { baselineSummary, preExistingFindings, scopeFindings } from '../core/baseline-scope.js';
36
+ import { refusalClass } from '../core/refusals.js';
37
+ import { checkModel } from './check.js';
38
+ import { readStamp, sourceDigest } from './decompile-stamp.js';
39
+ import { stableJson } from './lift-verify.js';
40
+ import { buildDecompiled, stampedDecompile } from './merge-source.js';
41
+ import { findByLocal, parseXmlRanges } from './xml-ranges.js';
42
+ /** What a pre-existing lowering finding adds to its message. */
43
+ const PRE_EXISTING_LOWERING_NOTE = 'This element is unchanged from the baseline, so this is probably an SDK defect: '
44
+ + 'the SDK cannot read what the original holds here. `compile` refuses this element, so `bpmn merge` of this edit refuses too. '
45
+ + 'Report it: https://github.com/UiPath/builder-sdk/issues';
46
+ /**
47
+ * Every element of `built` by id, as the text two builds are compared by. Nodes and
48
+ * flows at every depth, and the declarations: variables (the root's and each
49
+ * sub-process's own), bindings, messages and errors.
50
+ * Two declarations that share an id are kept together, so either changing counts.
51
+ */
52
+ export function elementIndex(built) {
53
+ const index = new Map();
54
+ const add = (id, what, value) => {
55
+ const text = `${what}:${stableJson(value)}`;
56
+ const had = index.get(id);
57
+ index.set(id, had === undefined ? text : `${had}\n${text}`);
58
+ };
59
+ const walk = (nodes, flows) => {
60
+ for (const n of nodes) {
61
+ if (n.kind === 'subProcess') {
62
+ // Its children and its own declarations are elements of their own.
63
+ const { nodes: children, flows: childFlows, variables, ...own } = n;
64
+ add(n.id, 'node', own);
65
+ for (const v of variables)
66
+ add(v.id, 'variable', v);
67
+ walk(children, childFlows);
68
+ }
69
+ else {
70
+ add(n.id, 'node', n);
71
+ }
72
+ }
73
+ // `implied` says how the source wrote the flow (an arm's chain, an explicit
74
+ // `.sequenceFlow()`), not what the flow is.
75
+ for (const { implied: _implied, ...f } of flows)
76
+ add(f.id, 'flow', f);
77
+ };
78
+ walk(built.nodes, built.flows);
79
+ for (const v of built.variables)
80
+ add(v.id, 'variable', v);
81
+ for (const b of built.bindings)
82
+ add(b.id, 'binding', b);
83
+ for (const m of built.messages)
84
+ add(m.id, 'message', m);
85
+ for (const e of built.errors)
86
+ add(e.id, 'error', e);
87
+ return index;
88
+ }
89
+ /** The element a finding is on: its `nodeId`, else its `where`, when that is an element id; `''` otherwise. */
90
+ function placeOf(d, index) {
91
+ for (const id of [d.nodeId, d.where])
92
+ if (id !== undefined && index.has(id))
93
+ return id;
94
+ return '';
95
+ }
96
+ /**
97
+ * Scope `edited`'s findings to the edit, against `baseline`: the original decompiled,
98
+ * built and checked the same way. See the file header for the rule. Each finding comes
99
+ * back with its `class` (when the code has one) and its `origin`.
100
+ *
101
+ * For instance, an `INTSVC_CONNECTION_MISSING` on a connector task the edit did not
102
+ * touch, which the original reports too, comes back as a `pre-existing` warning; the
103
+ * same finding after the edit renamed that task is an `edited` error.
104
+ */
105
+ export function scopeToEdit(edited, baseline) {
106
+ const editedIndex = elementIndex(edited.built);
107
+ const baselineIndex = elementIndex(baseline.built);
108
+ const preExisting = preExistingFindings(edited.checked.diagnostics.map((d) => {
109
+ const place = placeOf(d, editedIndex);
110
+ return { level: d.level, code: d.code, message: d.message, place, unchanged: place !== '' && editedIndex.get(place) === baselineIndex.get(place) };
111
+ }), baseline.checked.diagnostics.map((d) => ({ level: d.level, code: d.code, message: d.message, place: placeOf(d, baselineIndex) })));
112
+ // Each finding names its element (`nodeId`, which uip prints as `NodeId`), however
113
+ // check placed it, so the reader can tell which element an `(edited)` error is on.
114
+ const classed = edited.checked.diagnostics.map((d) => {
115
+ const cls = refusalClass(d.code);
116
+ const place = placeOf(d, editedIndex);
117
+ return { ...d, ...(place !== '' ? { nodeId: place } : {}), ...(cls !== undefined ? { class: cls } : {}) };
118
+ });
119
+ const out = scopeFindings(classed, preExisting, PRE_EXISTING_LOWERING_NOTE);
120
+ const stop = edited.checked.stoppedAt;
121
+ if (stop) {
122
+ const at = stop.code !== undefined ? `[${stop.code}] ` : '';
123
+ out.push({
124
+ level: 'error', code: 'CHECK_INCOMPLETE',
125
+ message: `check stopped at ${at}${stop.message} Nothing the serializer refuses after that point was checked, so the edit is not judged. `
126
+ + 'Fix it, even if the original has it too, and run check again.',
127
+ class: refusalClass('CHECK_INCOMPLETE'), origin: 'edited',
128
+ });
129
+ }
130
+ return out;
131
+ }
132
+ /**
133
+ * Why `xml` is not a `.bpmn` document, or `undefined` when it is one: XML with a
134
+ * `bpmn:process`. `check --baseline` refuses anything else before loading it, such as
135
+ * the `.bpmn.ts` source passed by mistake (`no bpmn:process element`) or a truncated
136
+ * file (`not XML: <the parser's message>`).
137
+ */
138
+ export function bpmnDocumentProblem(xml) {
139
+ let ranges;
140
+ try {
141
+ ranges = parseXmlRanges(xml);
142
+ }
143
+ catch (error) {
144
+ return `not XML: ${error instanceof Error ? error.message : String(error)}`;
145
+ }
146
+ return findByLocal(ranges, 'process') !== undefined ? undefined : 'no bpmn:process element';
147
+ }
148
+ /**
149
+ * Check `built` and scope its findings to the edit ({@link scopeToEdit}), against
150
+ * `original`, the `.bpmn` text the source was decompiled from.
151
+ *
152
+ * @param built - The edited process, built from the source.
153
+ * @param original - The original `.bpmn` text.
154
+ * @param opts - The check options (the same for both checks) and the edited source.
155
+ * @returns Every finding of the edited check, each with its `origin`.
156
+ */
157
+ export async function checkAgainstBaseline(built, original, opts = {}) {
158
+ const { source: _source, onWarning: _onWarning, ...checkOpts } = opts;
159
+ return scopeToEdit({ built, checked: checkModel(built, checkOpts) }, await checkOriginal(original, opts));
160
+ }
161
+ /**
162
+ * The baseline half of {@link checkAgainstBaseline}: `original` decompiled (with the
163
+ * options the source's stamp records), built and checked.
164
+ *
165
+ * @throws What the decompile or the build throws: the original does not decompile.
166
+ */
167
+ export async function checkOriginal(original, opts = {}) {
168
+ const { source: _source, onWarning: _onWarning, ...checkOpts } = opts;
169
+ const built = await buildOriginal(original, opts);
170
+ return { built, checked: checkModel(built, checkOpts) };
171
+ }
172
+ /**
173
+ * `original` decompiled, with the options the source's stamp records, and built: the
174
+ * process the source was before the edit. A CLI runs it before it loads the source, so
175
+ * a failure here is reported as the original's, never the source's; it then checks the
176
+ * result with the library it checks the edit with (`bpmn/check-cli.ts`).
177
+ *
178
+ * @param opts - `library` lifts connector tasks as `bpmn decompile` did; `source`
179
+ * carries the stamp; `onWarning` hears that the original changed since the decompile.
180
+ * @throws What the decompile or the build throws: the original does not decompile.
181
+ */
182
+ export async function buildOriginal(original, opts = {}) {
183
+ const { source, onWarning, library } = opts;
184
+ const stamp = source !== undefined ? readStamp(source) : undefined;
185
+ const decompileOpts = stampedDecompile(stamp !== undefined && !('error' in stamp)
186
+ ? stamp
187
+ : { file: '', sha256: '', style: 'explicit', connectors: 'lift', keepFlowIds: false, keepUnusedBindings: false, verbatim: [], fetch: true }, library);
188
+ const { built, decompile } = await buildDecompiled(original, decompileOpts);
189
+ if (stamp !== undefined && !('error' in stamp) && sourceDigest(decompile.source) !== stamp.sha256) {
190
+ onWarning?.(`the original changed since the source was decompiled from it (sha256 ${stamp.sha256} recorded, `
191
+ + `${sourceDigest(decompile.source)} now); a finding on an element it changed counts as the edit's.`);
192
+ }
193
+ return built;
194
+ }
195
+ /**
196
+ * The `--baseline` summary line, for instance
197
+ * `1 error(s) in edited elements, 0 pre-existing SDK defect(s), 9 pre-existing warning(s)`.
198
+ */
199
+ export function bpmnBaselineSummary(diags) {
200
+ return baselineSummary(diags, 'elements');
201
+ }
@@ -5,7 +5,7 @@
5
5
  * Usage:
6
6
  * node --experimental-strip-types check-cli.js <bpmn.ts | BaseName> [--graph] [--no-types] \
7
7
  * [--library <library-json dir>] [--connectors-local <overlay dir>] [--bindings <bindings.json>] \
8
- * [--resources <resources.json>]
8
+ * [--resources <resources.json>] [--baseline <original.bpmn>]
9
9
  *
10
10
  * --resources defaults to .flow-sdk/resources.json, the ledger `registry prepare`
11
11
  * writes, when present.
@@ -18,22 +18,30 @@
18
18
  * value of the wrong type is a `TS<code>` error with its `file:line:col`, and it
19
19
  * is reported even when the source then crashes on load or in the check.
20
20
  * `--no-types` skips it.
21
+ *
22
+ * `--baseline <original.bpmn>` scopes the findings to the edit (check-baseline.ts): the
23
+ * original is decompiled, built and checked in memory the same way, and each finding is
24
+ * marked `(edited)` or `(pre-existing)`. A pre-existing finding (its element unchanged,
25
+ * and the original reports it too) is a warning, so only the edit's errors fail the
26
+ * check; a pre-existing lowering one is printed as a probable SDK defect.
21
27
  */
22
- import { existsSync } from 'node:fs';
23
- import { printResult, reportCompileRefusal, reportDiagnostics, reportResult } from '../cli-result.js';
28
+ import { existsSync, readFileSync } from 'node:fs';
29
+ import { diagnosticLine, printResult, reportCompileRefusal, reportDiagnostics, reportResult } from '../cli-result.js';
24
30
  import { resolveBpmnFile, loadBuiltBpmn } from './load.js';
25
- import { check } from './check.js';
31
+ import { check, checkModel } from './check.js';
32
+ import { bpmnBaselineSummary, bpmnDocumentProblem, buildOriginal, scopeToEdit } from './check-baseline.js';
26
33
  import { sourceTypeDiagnostics } from './source-types.js';
27
34
  import { graphModel, renderGraph } from './graph.js';
28
35
  import { Bindings } from '../core/bindings.js';
29
- import { connectorCheckOpts } from '../core/cli-library.js';
36
+ import { connectorCheckOpts, openCliLibrary } from '../core/cli-library.js';
37
+ import { fetchDefinitionsEnabled } from '../registry/fetch/fetch-definitions.js';
30
38
  import { withFetchedDefinitions } from '../registry/fetch/with-fetched-definitions.js';
31
39
  import { flagValue, runWhenInvokedDirectly } from '../cli-run.js';
32
40
  import { ensureTypeScriptRuntime } from '../node-runtime.js';
33
41
  import { readCliResources } from '../registry/prepare/resources.js';
34
42
  import { defaultResourcesFile } from '../workdir.js';
35
43
  /** Flags that take a value — their argument is never the source positional. */
36
- const VALUE_FLAGS = new Set(['--library', '--connectors-local', '--bindings', '--resources']);
44
+ const VALUE_FLAGS = new Set(['--library', '--connectors-local', '--bindings', '--resources', '--baseline']);
37
45
  /**
38
46
  * The connector facts, resolved exactly as `compile-cli` resolves them, so the
39
47
  * inner loop and the emit rung cannot disagree about a field, a lookup or a
@@ -57,17 +65,45 @@ function report(diags) {
57
65
  }
58
66
  export async function run(argv) {
59
67
  if (argv.length === 0 || argv[0] === '-h' || argv[0] === '--help') {
60
- console.error('usage: check <bpmn.ts | BaseName> [--graph] [--no-types] [--library <dir>] [--connectors-local <dir>] [--bindings <file>] [--resources <file>]');
68
+ console.error('usage: check <bpmn.ts | BaseName> [--graph] [--no-types] [--library <dir>] [--connectors-local <dir>] [--bindings <file>] [--resources <file>] [--baseline <original.bpmn>]');
61
69
  return 2;
62
70
  }
63
71
  ensureTypeScriptRuntime();
64
72
  const graph = argv.includes('--graph');
65
73
  const input = argv.find((a, i) => !a.startsWith('--') && !VALUE_FLAGS.has(argv[i - 1]));
66
74
  if (input === undefined) {
67
- console.error('usage: check <bpmn.ts | BaseName> [--graph] [--no-types] [--library <dir>] [--connectors-local <dir>] [--bindings <file>] [--resources <file>]');
75
+ console.error('usage: check <bpmn.ts | BaseName> [--graph] [--no-types] [--library <dir>] [--connectors-local <dir>] [--bindings <file>] [--resources <file>] [--baseline <original.bpmn>]');
76
+ return 2;
77
+ }
78
+ const baselinePath = flagValue(argv, '--baseline');
79
+ const original = baselinePath !== undefined ? readBaseline(baselinePath) : undefined;
80
+ if (original instanceof Error) {
81
+ console.error(`check: ${original.message}`);
82
+ reportResult({ error: original.message });
68
83
  return 2;
69
84
  }
70
85
  const file = resolveBpmnFile(input);
86
+ // The original is decompiled first, on its own: when it does not decompile, that is
87
+ // a usage error about --baseline (exit 2), never a fault in the source being checked.
88
+ // It lifts connector tasks against the library `bpmn decompile` opens, and is checked
89
+ // below with the library the edit is checked with, so the two checks agree.
90
+ let baselineBuilt;
91
+ if (original !== undefined) {
92
+ try {
93
+ const library = openCliLibrary(argv, { always: fetchDefinitionsEnabled() });
94
+ baselineBuilt = await buildOriginal(original, {
95
+ ...(library ? { library } : {}),
96
+ source: readFileSync(file, 'utf8'),
97
+ onWarning: (m) => console.error(`check: warning: ${m}`),
98
+ });
99
+ }
100
+ catch (error) {
101
+ const message = `--baseline ${baselinePath} does not decompile: ${error instanceof Error ? error.message : String(error)}`;
102
+ console.error(`check: ${message}`);
103
+ reportResult({ error: message });
104
+ return 2;
105
+ }
106
+ }
71
107
  const typeDiags = argv.includes('--no-types') ? [] : sourceTypeDiagnostics(file);
72
108
  let built;
73
109
  let diags;
@@ -76,7 +112,16 @@ export async function run(argv) {
76
112
  // A connector operation no layer carries is fetched through `uip` and the check
77
113
  // runs again, as `compile` does (docs/CONNECTOR_LIBRARY_OPTIONAL_DESIGN.md).
78
114
  const loaded = built;
79
- diags = [...typeDiags, ...(await withFetchedDefinitions(argv, (library) => check(loaded, bpmnCheckOpts(argv, library)), { who: 'check' }))];
115
+ diags = [
116
+ // A type error is the edit's: the source is.
117
+ ...(original !== undefined ? typeDiags.map((d) => ({ ...d, origin: 'edited' })) : typeDiags),
118
+ ...(await withFetchedDefinitions(argv, (library) => {
119
+ const opts = bpmnCheckOpts(argv, library);
120
+ return baselineBuilt !== undefined
121
+ ? scopeToEdit({ built: loaded, checked: checkModel(loaded, opts) }, { built: baselineBuilt, checked: checkModel(baselineBuilt, opts) })
122
+ : check(loaded, opts);
123
+ }, { who: 'check' })),
124
+ ];
80
125
  }
81
126
  catch (error) {
82
127
  // A value of the wrong type usually crashes the build or the check before
@@ -104,6 +149,16 @@ export async function run(argv) {
104
149
  printResult(renderGraph(built).trimEnd());
105
150
  reportResult({ graph: graphModel(built) });
106
151
  }
152
+ if (original !== undefined) {
153
+ // Each finding says whether the edit caused it (`(edited)`, `(pre-existing)`), as
154
+ // `flow check --baseline` prints it. A BPMN message already carries its
155
+ // suggestion, so it is not appended twice.
156
+ for (const d of diags)
157
+ console.error(` ${diagnosticLine({ ...d, suggestion: undefined })}`);
158
+ const errors = diags.filter((d) => d.level === 'error').length;
159
+ console.error(`check: ${bpmnBaselineSummary(diags)}.`);
160
+ return errors ? 1 : 0;
161
+ }
107
162
  printDiagnostics(diags);
108
163
  const errors = diags.filter((d) => d.level === 'error').length;
109
164
  if (errors) {
@@ -113,4 +168,18 @@ export async function run(argv) {
113
168
  console.error(`check: ok${diags.length ? ` (${diags.length} warning(s))` : ''}.`);
114
169
  return 0;
115
170
  }
171
+ /**
172
+ * The `--baseline` file's text, or the usage error to refuse it with: a path that does
173
+ * not exist, or a file that is not a `.bpmn` (no `bpmn:process`), such as the `.bpmn.ts`
174
+ * source passed by mistake. Refused before anything is loaded, with the usage exit
175
+ * code, so a bad flag never reads as a failed check.
176
+ */
177
+ function readBaseline(path) {
178
+ const usage = `--baseline must be the original .bpmn the source was decompiled from: ${path}`;
179
+ if (!existsSync(path))
180
+ return new Error(`${usage} (no such file)`);
181
+ const xml = readFileSync(path, 'utf8');
182
+ const problem = bpmnDocumentProblem(xml);
183
+ return problem === undefined ? xml : new Error(`${usage} (${problem})`);
184
+ }
116
185
  runWhenInvokedDirectly(import.meta.url, 'check', run);
@@ -1,6 +1,7 @@
1
1
  import type { BuiltBpmn } from './bpmn-sdk.js';
2
2
  import type { Library } from '../core/library.js';
3
3
  import type { ResourceResolutions } from '../core/resource-resolution.js';
4
+ import type { RefusalClass } from '../core/refusals.js';
4
5
  import { type ConnectorCheckOpts } from '../core/connector-checks.js';
5
6
  import { type EventCheckOpts } from '../core/event-checks.js';
6
7
  export interface Diagnostic {
@@ -11,6 +12,18 @@ export interface Diagnostic {
11
12
  suggestion?: string;
12
13
  /** The id of the element `where` names, for a refusal the serializer placed on one (`serializerRefusals`). */
13
14
  nodeId?: string;
15
+ /**
16
+ * Only when the check ran against a baseline (`bpmn check --baseline`, check-baseline.ts):
17
+ * the code's class (`core/refusals.ts`: `lint`, `lowering`, `draft`).
18
+ */
19
+ class?: RefusalClass;
20
+ /**
21
+ * Only when the check ran against a baseline (`bpmn check --baseline`, check-baseline.ts):
22
+ * `pre-existing` when the finding's element is unchanged from the original and the
23
+ * original reports the same code on it, so the edit did not cause it (such a finding
24
+ * is a warning); `edited` for every other finding.
25
+ */
26
+ origin?: 'edited' | 'pre-existing';
14
27
  }
15
28
  /**
16
29
  * The facts this check cannot derive from the built model.
@@ -38,3 +51,19 @@ export interface BpmnCheckOpts extends ConnectorCheckOpts, EventCheckOpts {
38
51
  * builds the model and stops before the XML is written.
39
52
  */
40
53
  export declare function check(built: BuiltBpmn, opts?: BpmnCheckOpts): Diagnostic[];
54
+ /** What {@link checkModel} found, and whether the serializer pass judged the whole process. */
55
+ export interface CheckedBpmn {
56
+ diagnostics: Diagnostic[];
57
+ /**
58
+ * Set when the serializer pass stopped before it built the whole model: the
59
+ * scope-level refusal that stopped it (a repeated id), or the throw `check`
60
+ * swallowed because it had errors of its own to report. Nothing the serializer
61
+ * refuses past that point is reported. Absent when the pass ran to the end.
62
+ */
63
+ stoppedAt?: {
64
+ code?: string;
65
+ message: string;
66
+ };
67
+ }
68
+ /** {@link check}, saying whether the serializer pass stopped early, for `check --baseline` (check-baseline.ts). */
69
+ export declare function checkModel(built: BuiltBpmn, opts?: BpmnCheckOpts): CheckedBpmn;
@@ -116,6 +116,10 @@ function isActivityNode(n) {
116
116
  * builds the model and stops before the XML is written.
117
117
  */
118
118
  export function check(built, opts = {}) {
119
+ return checkModel(built, opts).diagnostics;
120
+ }
121
+ /** {@link check}, saying whether the serializer pass stopped early, for `check --baseline` (check-baseline.ts). */
122
+ export function checkModel(built, opts = {}) {
119
123
  const diags = [];
120
124
  // Duplicate and missing ids (`documentIdProblems`) are the serializer's.
121
125
  checkScope(built.nodes, built.flows, 'process', diags, true);
@@ -131,11 +135,11 @@ export function check(built, opts = {}) {
131
135
  checkConnectorEvents(built, opts, diags);
132
136
  checkCarriedPayloadTags(built, diags);
133
137
  // A `.dataService()` entity's recorded row is the serializer's (`lowerDataServiceEntity`).
134
- const { refusals, definitions, stoodIn } = serializerRefusals(built, opts, diags);
138
+ const { refusals, definitions, stoodIn, stoppedAt } = serializerRefusals(built, opts, diags);
135
139
  diags.push(...refusals);
136
140
  if (definitions)
137
141
  diags.push(...refreshConnections(built, definitions, stoodIn, diags));
138
- return diags;
142
+ return { diagnostics: diags, ...(stoppedAt ? { stoppedAt } : {}) };
139
143
  }
140
144
  /**
141
145
  * What `uip maestro bpmn refresh` refuses about the emitted connections
@@ -234,7 +238,7 @@ function serializerRefusals(built, opts, found) {
234
238
  catch (error) {
235
239
  if (!found.some((d) => d.level === 'error'))
236
240
  throw error;
237
- return { refusals: [], stoodIn: new Set() };
241
+ return { refusals: [], stoodIn: new Set(), stoppedAt: { message: error instanceof Error ? error.message : String(error) } };
238
242
  }
239
243
  const stoodIn = new Set(collected.flatMap((r) => (r.nodeId !== undefined ? [r.nodeId] : [])));
240
244
  const out = [];
@@ -258,7 +262,10 @@ function serializerRefusals(built, opts, found) {
258
262
  ...(r.nodeId !== undefined ? { nodeId: r.nodeId } : {}),
259
263
  });
260
264
  }
261
- return { refusals: out, stoodIn, ...(definitions ? { definitions } : {}) };
265
+ // No model means collection stopped: the refusal that stopped it is the last one reported.
266
+ const stop = collected[collected.length - 1];
267
+ const stoppedAt = !definitions ? { ...(stop ? { code: stop.code } : {}), message: stop?.message ?? 'the serializer stopped' } : undefined;
268
+ return { refusals: out, stoodIn, ...(definitions ? { definitions } : {}), ...(stoppedAt ? { stoppedAt } : {}) };
262
269
  }
263
270
  /**
264
271
  * The library-backed connector rules, shared with Flow (`core/connector-checks.ts`).
@@ -6,6 +6,12 @@ export interface GraphComparison {
6
6
  /** When they do not: which source failed to build, or what differed. */
7
7
  reason?: string;
8
8
  }
9
+ /**
10
+ * JSON with every object's keys sorted, so two builds that set the same fields in a
11
+ * different order — a start event's `payload` before or after its `event` — read as
12
+ * the same. `Map` values are not expected here; `canonicalGraph` flattens the one it has.
13
+ */
14
+ export declare function stableJson(value: unknown): string;
9
15
  /**
10
16
  * The part of a built process that is the process: ordered by id, `implied`
11
17
  * provenance dropped, and `undefined` fields gone the way JSON drops them.
@@ -21,7 +21,7 @@ function sortById(xs) {
21
21
  * different order — a start event's `payload` before or after its `event` — read as
22
22
  * the same. `Map` values are not expected here; `canonicalGraph` flattens the one it has.
23
23
  */
24
- function stableJson(value) {
24
+ export function stableJson(value) {
25
25
  return JSON.stringify(value, (_key, v) => v && typeof v === 'object' && !Array.isArray(v)
26
26
  ? Object.fromEntries(Object.keys(v).sort().map((k) => [k, v[k]]))
27
27
  : v);
@@ -41,9 +41,8 @@
41
41
  import { reportCompileRefusal, reportDiagnostics, reportResult } from '../cli-result.js';
42
42
  import { readFileSync, writeFileSync } from 'node:fs';
43
43
  import { basename, resolve } from 'node:path';
44
- import { fileURLToPath } from 'node:url';
45
44
  import { mergeBpmn } from './merge.js';
46
- import { decompiledDigest, deriveBaseline } from './merge-source.js';
45
+ import { decompiledDigest, deriveBaseline, stampedDecompile } from './merge-source.js';
47
46
  import { readStamp, sourceDigest, restampSource, STAMP_MARKER } from './decompile-stamp.js';
48
47
  import { loadBuiltBpmn } from './load.js';
49
48
  import { serialize } from './serialize.js';
@@ -69,19 +68,6 @@ const VALUE_FLAGS = new Set([
69
68
  '-o', '--baseline', '--style', '--connectors', '--library', '--connectors-local', '--bindings', '--resources',
70
69
  ]);
71
70
  const BARE_FLAGS = new Set(['--keep-flow-ids', '--keep-unused-bindings']);
72
- /** The decompile options a stamp records, as `deriveBaseline` and `decompiledDigest` take them. */
73
- function stampedDecompile(stamp, library) {
74
- return {
75
- sdkEntry: fileURLToPath(new URL('./bpmn-sdk.js', import.meta.url)),
76
- style: stamp.style,
77
- keepFlowIds: stamp.keepFlowIds,
78
- keepUnusedBindings: stamp.keepUnusedBindings,
79
- ...(stamp.connectors === 'lift' && library ? { liftLibrary: library } : {}),
80
- // The tasks that decompile could not name stay verbatim, whatever has been
81
- // fetched for them since, so the stamped source comes back.
82
- ...(stamp.verbatim.length > 0 ? { keepVerbatim: new Set(stamp.verbatim) } : {}),
83
- };
84
- }
85
71
  /** Refuse the merge with a coded diagnostic; nothing has been written. */
86
72
  function refuseMerge(code, message) {
87
73
  console.error(`bpmn-merge: ${message}`);
@@ -38,8 +38,10 @@
38
38
  * Nothing here prints or reads argv; merge-cli.ts does.
39
39
  */
40
40
  import type { Library } from '../core/library.js';
41
+ import type { BuiltBpmn } from './bpmn-sdk.js';
41
42
  import { type BpmnSerializeOpts } from './serialize.js';
42
43
  import { type DecompilePipelineResult } from './decompile-pipeline.js';
44
+ import { type DecompileStamp } from './decompile-stamp.js';
43
45
  /** What both in-memory compiles need, and how to decompile the original. */
44
46
  export interface SourceMergeOptions {
45
47
  /** The library, bindings and resources `compile` would use; the edited and baseline compiles share them. */
@@ -61,6 +63,8 @@ export interface SourceMergeOptions {
61
63
  /** The tasks the decompile kept verbatim because its library could not name them (its stamp's `verbatim=`). */
62
64
  keepVerbatim?: ReadonlySet<string>;
63
65
  }
66
+ /** The decompile options a stamp records, as `deriveBaseline` and `decompiledDigest` take them. */
67
+ export declare function stampedDecompile(stamp: DecompileStamp, library: Library | undefined): Omit<SourceMergeOptions, 'serialize'>;
64
68
  /** The baseline merge derived from the original. */
65
69
  export interface DerivedBaseline {
66
70
  /** `compile(decompile(original))`, the document a `--baseline` file would hold. */
@@ -77,6 +81,19 @@ export interface DerivedBaseline {
77
81
  * @returns The baseline document and what the decompile did.
78
82
  */
79
83
  export declare function deriveBaseline(original: string, opts: SourceMergeOptions): Promise<DerivedBaseline>;
84
+ /**
85
+ * `decompile(original)`, built in memory: the process the author's source was before
86
+ * the edit. `bpmn check --baseline` checks it to learn what the original already
87
+ * reports (check-baseline.ts); `deriveBaseline` compiles it.
88
+ *
89
+ * @param original - The original `.bpmn` text.
90
+ * @param opts - The decompile options.
91
+ * @returns The built process and what the decompile did.
92
+ */
93
+ export declare function buildDecompiled(original: string, opts: Omit<SourceMergeOptions, 'serialize'>): Promise<{
94
+ built: BuiltBpmn;
95
+ decompile: DecompilePipelineResult;
96
+ }>;
80
97
  /**
81
98
  * The stamp digest of `xml` decompiled with `opts`'s options: what `bpmn decompile`
82
99
  * would record for it. Merge restamps the source with this after writing over the
@@ -2,6 +2,20 @@ import { serialize } from './serialize.js';
2
2
  import { buildSource } from './lift-verify.js';
3
3
  import { decompilePipeline } from './decompile-pipeline.js';
4
4
  import { sourceDigest } from './decompile-stamp.js';
5
+ import { fileURLToPath } from 'node:url';
6
+ /** The decompile options a stamp records, as `deriveBaseline` and `decompiledDigest` take them. */
7
+ export function stampedDecompile(stamp, library) {
8
+ return {
9
+ sdkEntry: fileURLToPath(new URL('./bpmn-sdk.js', import.meta.url)),
10
+ style: stamp.style,
11
+ keepFlowIds: stamp.keepFlowIds,
12
+ keepUnusedBindings: stamp.keepUnusedBindings,
13
+ ...(stamp.connectors === 'lift' && library ? { liftLibrary: library } : {}),
14
+ // The tasks that decompile could not name stay verbatim, whatever has been
15
+ // fetched for them since, so the stamped source comes back.
16
+ ...(stamp.verbatim.length > 0 ? { keepVerbatim: new Set(stamp.verbatim) } : {}),
17
+ };
18
+ }
5
19
  /**
6
20
  * `compile(decompile(original))`, made in memory: the baseline the file-based pipeline
7
21
  * writes to `X.baseline.bpmn` before the edit.
@@ -11,9 +25,21 @@ import { sourceDigest } from './decompile-stamp.js';
11
25
  * @returns The baseline document and what the decompile did.
12
26
  */
13
27
  export async function deriveBaseline(original, opts) {
14
- const decompiled = await decompileAs(original, opts);
15
- const built = await buildSource(decompiled.source, opts.sdkEntry);
16
- return { xml: await serialize(built, opts.serialize), decompile: decompiled };
28
+ const { built, decompile } = await buildDecompiled(original, opts);
29
+ return { xml: await serialize(built, opts.serialize), decompile };
30
+ }
31
+ /**
32
+ * `decompile(original)`, built in memory: the process the author's source was before
33
+ * the edit. `bpmn check --baseline` checks it to learn what the original already
34
+ * reports (check-baseline.ts); `deriveBaseline` compiles it.
35
+ *
36
+ * @param original - The original `.bpmn` text.
37
+ * @param opts - The decompile options.
38
+ * @returns The built process and what the decompile did.
39
+ */
40
+ export async function buildDecompiled(original, opts) {
41
+ const decompile = await decompileAs(original, opts);
42
+ return { built: await buildSource(decompile.source, opts.sdkEntry), decompile };
17
43
  }
18
44
  /**
19
45
  * The stamp digest of `xml` decompiled with `opts`'s options: what `bpmn decompile`
package/dist/check-cli.js CHANGED
@@ -26,6 +26,7 @@ import { Bindings } from './bindings.js';
26
26
  import { flagValue, flagValues, runWhenInvokedDirectly } from './cli-run.js';
27
27
  import { ensureTypeScriptRuntime } from './node-runtime.js';
28
28
  import { withDecompiledOriginal } from './merge-compile.js';
29
+ import { baselineSummary } from './core/baseline-scope.js';
29
30
  import { loadNodePackages } from './node-packages.js';
30
31
  /** Flags that take a value, so the value is never read as the source argument. */
31
32
  const VALUE_FLAGS = new Set(['--library', '--bindings', '--connectors-local', '--resources', '--baseline', '--package']);
@@ -85,7 +86,7 @@ export async function run(argv) {
85
86
  for (const d of diags)
86
87
  console.log(diagnosticLine(d));
87
88
  const errors = diags.filter((d) => d.level === 'error').length;
88
- console.log(`\n${baselinePath !== undefined ? baselineSummary(diags) : `${errors} error(s), ${diags.length - errors} warning(s)`}`);
89
+ console.log(`\n${baselinePath !== undefined ? baselineSummary(diags, 'nodes') : `${errors} error(s), ${diags.length - errors} warning(s)`}`);
89
90
  return errors ? 1 : 0;
90
91
  }
91
92
  /**
@@ -124,19 +125,4 @@ function readBaseline(path) {
124
125
  }
125
126
  return parsed;
126
127
  }
127
- /**
128
- * The `--baseline` summary: the errors that fail the check (the edit's), the
129
- * pre-existing lowering findings (probable SDK defects) and the other
130
- * pre-existing findings, and the edit's own warnings when there are any. For
131
- * instance `1 error(s) in edited nodes, 1 pre-existing SDK defect(s), 1 pre-existing warning(s)`.
132
- */
133
- function baselineSummary(diags) {
134
- const edited = diags.filter((d) => d.origin !== 'pre-existing');
135
- const pre = diags.filter((d) => d.origin === 'pre-existing');
136
- const errors = edited.filter((d) => d.level === 'error').length;
137
- const defects = pre.filter((d) => d.class === 'lowering').length;
138
- const warnings = edited.length - errors;
139
- return `${errors} error(s) in edited nodes, ${defects} pre-existing SDK defect(s), ${pre.length - defects} pre-existing warning(s)`
140
- + (warnings ? `, ${warnings} warning(s) in edited nodes` : '');
141
- }
142
128
  runWhenInvokedDirectly(import.meta.url, 'check', run);
package/dist/check.js CHANGED
@@ -22,7 +22,8 @@ import { resolveVersion, resolveVersionCarried } from './core/nodes/versioned.js
22
22
  import { registeredRawType } from './raw-node-advice.js';
23
23
  import { loopParallelWarning, resolveLoopDefinition, loopVersion } from './loop-version.js';
24
24
  import { refusalClass } from './core/refusals.js';
25
- import { classifyDrafts, findingCounts, placeDiagnostics, splitUnplaced } from './edit-scope.js';
25
+ import { classifyDrafts, placeDiagnostics } from './edit-scope.js';
26
+ import { preExistingFindings, scopeFindings } from './core/baseline-scope.js';
26
27
  export function check(built, opts = {}) {
27
28
  return checkCompiled(built, opts).diagnostics;
28
29
  }
@@ -89,47 +90,12 @@ export function checkCompiled(built, opts = {}) {
89
90
  export function scopeToEdit(edited, baseline) {
90
91
  const locate = (c) => placeDiagnostics(c.diagnostics, c.flow)
91
92
  .map((d, i) => ({ ...d, nodeId: c.diagnostics[i].nodeId ?? d.nodeId, index: i }));
92
- const sorted = classifyDrafts(baseline.flow ?? {}, edited.flow ?? {}, baseline.flow, locate(edited));
93
- // The baseline's findings on each node, by code; each one vouches for one edited finding.
94
- const onNode = (f) => `${f.nodeId}\n${f.code}`;
95
- const pool = new Map();
96
- for (const b of locate(baseline)) {
97
- if (b.nodeId === '')
98
- continue;
99
- pool.set(onNode(b), [...(pool.get(onNode(b)) ?? []), b.message]);
100
- }
101
- const preExisting = new Set();
102
- // Exact messages are matched first: of two findings of one code on a node,
103
- // the one the baseline has word for word is the pre-existing one. The second
104
- // pass forgives wording the edit can shift without touching the finding (a
105
- // "Known steps: ..." list), but only between messages that name the same
106
- // quoted subjects: `UNKNOWN_REF "lookup" in "audit"` is a different finding
107
- // from the baseline's `UNKNOWN_REF "ghost" in "audit"`, so it stays edited.
108
- for (const exact of [true, false]) {
109
- for (const f of sorted.kept) {
110
- if (preExisting.has(f.index))
111
- continue;
112
- const messages = pool.get(onNode(f)) ?? [];
113
- const j = exact ? messages.indexOf(f.message) : messages.findIndex((m) => quotedSubjects(m) === quotedSubjects(f.message));
114
- if (j < 0)
115
- continue;
116
- messages.splice(j, 1);
117
- preExisting.add(f.index);
118
- }
119
- }
120
- for (const f of splitUnplaced(sorted.unplaced, findingCounts(baseline.diagnostics)).known)
121
- preExisting.add(f.index);
122
- const out = edited.diagnostics.map((d, i) => {
123
- if (!preExisting.has(i))
124
- return { ...d, origin: 'edited' };
125
- const defect = d.level === 'error' && d.class === 'lowering';
126
- return {
127
- ...d,
128
- level: 'warning',
129
- message: defect ? `${d.message}\n ${PRE_EXISTING_LOWERING_NOTE}` : d.message,
130
- origin: 'pre-existing',
131
- };
132
- });
93
+ const placed = locate(edited);
94
+ const sorted = classifyDrafts(baseline.flow ?? {}, edited.flow ?? {}, baseline.flow, placed);
95
+ const kept = new Set(sorted.kept.map((f) => f.index));
96
+ const unplaced = new Set(sorted.unplaced.map((f) => f.index));
97
+ const preExisting = preExistingFindings(placed.map((f) => ({ level: f.level, code: f.code, message: f.message, place: unplaced.has(f.index) ? '' : f.nodeId, unchanged: kept.has(f.index) })), locate(baseline).map((b) => ({ level: b.level, code: b.code, message: b.message, place: b.nodeId })));
98
+ const out = scopeFindings(edited.diagnostics, preExisting, PRE_EXISTING_LOWERING_NOTE);
133
99
  if (edited.stoppedAt) {
134
100
  const at = edited.stoppedAt.code !== undefined ? `[${edited.stoppedAt.code}] ` : '';
135
101
  out.push({
@@ -141,10 +107,6 @@ export function scopeToEdit(edited, baseline) {
141
107
  }
142
108
  return out;
143
109
  }
144
- /** The `"quoted"` names in a finding's message, in order: what it is about, apart from its wording. */
145
- function quotedSubjects(message) {
146
- return JSON.stringify(message.match(/"[^"]*"/g) ?? []);
147
- }
148
110
  /** What a pre-existing lowering finding adds to its message ({@link scopeToEdit}). */
149
111
  const PRE_EXISTING_LOWERING_NOTE = 'This node is unchanged from the baseline, so this is probably an SDK defect: '
150
112
  + 'the SDK cannot read what the designer wrote. `compile` refuses this node; `merge --baseline-from` keeps it as saved. '
@@ -1009,6 +971,23 @@ function checkFlow(built, ancestors, opts = {}) {
1009
971
  });
1010
972
  continue;
1011
973
  }
974
+ // `$vars.start.output.<x>` inside a subflow, for an `x` the subflow does
975
+ // not declare as an input (#1969). A subflow body is its own scope: its
976
+ // `start` is the child's OWN Start node (serialize renames it to
977
+ // `<caller>Start`), and that node publishes exactly the child's declared
978
+ // inputs. So the read names nothing at run time, typically a parent input
979
+ // the author expected to be visible: `input('n')` or `$vars.start.output.n`
980
+ // written in the child as if it were the caller. A step of the caller is
981
+ // UNKNOWN_REF above; this is the one parent-scope read that `start` being
982
+ // declared in every scope let through.
983
+ if (ancestors.length > 0 && (name === 'start' || name === built.triggerId) && field === 'output'
984
+ && code.startsWith('$vars', m.index ?? 0)) {
985
+ const key = rest.split('.')[1];
986
+ if (key !== undefined && key !== '' && !inputNames.has(key)) {
987
+ diags.push(subflowParentScopeRead(built, ancestors, name, key, step));
988
+ continue;
989
+ }
990
+ }
1012
991
  // `$vars.<input>` — a flow INPUT read by its bare name.
1013
992
  //
1014
993
  // Inputs, outputs and vars share one namespace in `variables.globals[]`,
@@ -1584,6 +1563,40 @@ function checkSubflow(step, child, inputs, parent, ancestors, diags) {
1584
1563
  }
1585
1564
  }
1586
1565
  }
1566
+ /**
1567
+ * SUBFLOW_PARENT_SCOPE_READ: a subflow body reads `$vars.<start>.output.<key>`
1568
+ * for a `key` that is not one of its own inputs (#1969). The child's Start
1569
+ * publishes only the child's inputs, so the read is empty on every run. When
1570
+ * `key` is an input of a calling flow, the message says so; the fix is the
1571
+ * same either way: declare it on the child and pass it in.
1572
+ *
1573
+ * ```ts
1574
+ * const child = flow('C').output({ r: types.number })
1575
+ * .step('s', script({ code: 'return $vars.start.output.n + 1;' })) // n is the PARENT's input
1576
+ * .return({ r: out('s') });
1577
+ * // fix: flow('C').input({ n: types.number })… and subflow(child, { n: input('n') })
1578
+ * ```
1579
+ */
1580
+ function subflowParentScopeRead(child, ancestors, root, key, step) {
1581
+ // The nearest calling flow that declares `key`, on its trigger or an entry point.
1582
+ const owner = [...ancestors].reverse().map((f) => ({
1583
+ f, input: [...f.inputs, ...(f.entryPoints ?? []).flatMap((ep) => ep.inputs)].find((i) => i.name === key),
1584
+ })).find((x) => x.input !== undefined);
1585
+ const type = owner?.input ? String(owner.input.type) : undefined;
1586
+ const whose = owner
1587
+ ? `"${key}" is an input of the calling flow "${owner.f.id}", not of this subflow`
1588
+ : `the subflow "${child.id}" declares no input "${key}"`;
1589
+ return {
1590
+ level: 'error',
1591
+ code: 'SUBFLOW_PARENT_SCOPE_READ',
1592
+ message: `"$vars.${root}.output.${key}" in "${step}" reads the subflow's own start, and ${whose}. A subflow `
1593
+ + `sees only the inputs it declares, so this read is empty at run time. Declare `
1594
+ + `.input({ ${key}: types.${type ?? '…'} }) on "${child.id}" and pass it from the subflow step: `
1595
+ + `subflow(…, { ${key}: input('${key}') }).`,
1596
+ step,
1597
+ suggestion: `{ ${key}: input('${key}') }`,
1598
+ };
1599
+ }
1587
1600
  /**
1588
1601
  * Diagnose a read of a subflow's output: `$vars.<step>.output.<childOutput>`.
1589
1602
  *
@@ -36,6 +36,7 @@ export function registerBpmnCommands(program) {
36
36
  .addOption(retiredCompiledOption())
37
37
  .option('--resources <file>', 'resource ledger that registry prepare writes (default .flow-sdk/resources.json)')
38
38
  .option('--no-types', 'skip the TypeScript type check of the source')
39
+ .option('--baseline <file>', 'the original .bpmn the source was decompiled from: findings on elements the edit did not touch, which the original has too, become warnings')
39
40
  .action(async (input, options) => {
40
41
  let mode;
41
42
  try {
@@ -58,6 +59,7 @@ export function registerBpmnCommands(program) {
58
59
  addValue(argv, '--connectors-local', options.connectorsLocal);
59
60
  addValue(argv, '--bindings', options.bindings);
60
61
  addValue(argv, '--resources', options.resources);
62
+ addValue(argv, '--baseline', options.baseline);
61
63
  await invoke('bpmn check', () => import('../../bpmn/check-cli.js'), argv);
62
64
  });
63
65
  family
@@ -0,0 +1,98 @@
1
+ /**
2
+ * baseline-scope — the part of `check --baseline <original>` every family shares:
3
+ * given each finding's place and whether that place is unchanged from the
4
+ * original, decide which findings the edit did not cause.
5
+ *
6
+ * The family decides the two things that are its own: where a finding sits (a
7
+ * Flow node, a BPMN element) and what "unchanged" means there (Flow: merge's
8
+ * `classifyDrafts`; BPMN: the same built element, payload and all). This file
9
+ * matches the findings against the original's own check, the same way for all.
10
+ *
11
+ * For instance, an edited check that reports `INTSVC_CONNECTION_MISSING` on an
12
+ * element `task1` the edit did not touch, while the original's check reports
13
+ * the same code on `task1`, gets that finding back as pre-existing. The same
14
+ * finding on an element the edit changed is not, and neither is a finding the
15
+ * original does not have.
16
+ *
17
+ * Pure: no file access, no family imports.
18
+ */
19
+ import { type RefusalClass } from './refusals.js';
20
+ /** A finding of the ORIGINAL's check: its level, code, message and place (`''` when it names none). */
21
+ export interface BaselineFinding {
22
+ /**
23
+ * Some codes are a warning or an error depending on the rest of the process, with the
24
+ * same subjects either way (BPMN's SCOPED_VAR_UNKNOWN_ELEMENT turns into an error once
25
+ * something reads the variable), so only a finding of the same level vouches.
26
+ */
27
+ level: 'error' | 'warning';
28
+ code: string;
29
+ message: string;
30
+ /** The node or element id the finding is on; `''` when it names none the family knows. */
31
+ place: string;
32
+ }
33
+ /** A finding of the EDITED check, with whether its place is unchanged from the original. */
34
+ export interface EditedFinding extends BaselineFinding {
35
+ /** The place is in the original and the edit did not change it. Ignored when `place` is `''`. */
36
+ unchanged: boolean;
37
+ }
38
+ /** How many times each code-and-message pair occurs, for {@link splitUnplaced}'s baseline. */
39
+ export declare function findingCounts(findings: ReadonlyArray<{
40
+ code: string;
41
+ message: string;
42
+ }>): Map<string, number>;
43
+ /**
44
+ * Sort findings that name no node or element by whether the edit introduced
45
+ * them: `known` when the ORIGINAL's own check (`baseline`, as
46
+ * {@link findingCounts}) reports the same code and message — once per
47
+ * occurrence, so a second copy of a finding the original has once is
48
+ * `introduced` — and `introduced` otherwise. With no baseline counts (a
49
+ * precompiled `--baseline` file in `flow merge`), every one is `introduced`.
50
+ */
51
+ export declare function splitUnplaced<T extends {
52
+ code: string;
53
+ message: string;
54
+ }>(unplaced: readonly T[], baseline: ReadonlyMap<string, number> | undefined): {
55
+ known: T[];
56
+ introduced: T[];
57
+ };
58
+ /**
59
+ * The indexes into `edited` of the findings the edit did not cause:
60
+ *
61
+ * - a finding on an unchanged place is pre-existing when the original
62
+ * reports the same code on the same place, once per occurrence. Exact
63
+ * messages are matched first; a second pass forgives wording the edit can
64
+ * shift without touching the finding (a "Known steps: ..." list), but only
65
+ * between messages that name the same `"quoted"` subjects;
66
+ * - a finding that names no place is pre-existing when the original reports
67
+ * the same code and message ({@link splitUnplaced});
68
+ * - a finding on a changed or new place never is.
69
+ *
70
+ * Every match also needs the same level: an edited error is never vouched for by a
71
+ * warning the original has, since the edit is what made it an error.
72
+ */
73
+ export declare function preExistingFindings(edited: readonly EditedFinding[], baseline: readonly BaselineFinding[]): Set<number>;
74
+ /** A diagnostic as {@link scopeFindings} reads and writes it. */
75
+ interface ScopableDiagnostic {
76
+ level: 'error' | 'warning';
77
+ code: string;
78
+ message: string;
79
+ class?: RefusalClass;
80
+ origin?: 'edited' | 'pre-existing';
81
+ }
82
+ /**
83
+ * `diags` with an `origin` on each: `pre-existing` for the indexes in
84
+ * `preExisting` (a {@link preExistingFindings} result), `edited` for the rest.
85
+ * A pre-existing finding becomes a warning, so it does not fail the check; a
86
+ * pre-existing `lowering` error also gets `loweringNote` on a line of its own,
87
+ * since the SDK cannot write back what the original holds there.
88
+ */
89
+ export declare function scopeFindings<D extends ScopableDiagnostic>(diags: readonly D[], preExisting: ReadonlySet<number>, loweringNote: string): D[];
90
+ /**
91
+ * The `check --baseline` summary line: the errors that fail the check (the
92
+ * edit's), the pre-existing lowering findings (probable SDK defects) and the
93
+ * other pre-existing findings, and the edit's own warnings when there are any.
94
+ * `places` names what was edited (`nodes`, `elements`). For instance
95
+ * `1 error(s) in edited nodes, 1 pre-existing SDK defect(s), 1 pre-existing warning(s)`.
96
+ */
97
+ export declare function baselineSummary(diags: readonly ScopableDiagnostic[], places: string): string;
98
+ export {};
@@ -0,0 +1,132 @@
1
+ /**
2
+ * baseline-scope — the part of `check --baseline <original>` every family shares:
3
+ * given each finding's place and whether that place is unchanged from the
4
+ * original, decide which findings the edit did not cause.
5
+ *
6
+ * The family decides the two things that are its own: where a finding sits (a
7
+ * Flow node, a BPMN element) and what "unchanged" means there (Flow: merge's
8
+ * `classifyDrafts`; BPMN: the same built element, payload and all). This file
9
+ * matches the findings against the original's own check, the same way for all.
10
+ *
11
+ * For instance, an edited check that reports `INTSVC_CONNECTION_MISSING` on an
12
+ * element `task1` the edit did not touch, while the original's check reports
13
+ * the same code on `task1`, gets that finding back as pre-existing. The same
14
+ * finding on an element the edit changed is not, and neither is a finding the
15
+ * original does not have.
16
+ *
17
+ * Pure: no file access, no family imports.
18
+ */
19
+ import { refusalClass } from './refusals.js';
20
+ /** The identity of a finding for the introduced-or-not comparison: its code and message. */
21
+ function findingKey(f) {
22
+ return `${f.code}\n${f.message}`;
23
+ }
24
+ /** How many times each code-and-message pair occurs, for {@link splitUnplaced}'s baseline. */
25
+ export function findingCounts(findings) {
26
+ const counts = new Map();
27
+ for (const f of findings)
28
+ counts.set(findingKey(f), (counts.get(findingKey(f)) ?? 0) + 1);
29
+ return counts;
30
+ }
31
+ /**
32
+ * Sort findings that name no node or element by whether the edit introduced
33
+ * them: `known` when the ORIGINAL's own check (`baseline`, as
34
+ * {@link findingCounts}) reports the same code and message — once per
35
+ * occurrence, so a second copy of a finding the original has once is
36
+ * `introduced` — and `introduced` otherwise. With no baseline counts (a
37
+ * precompiled `--baseline` file in `flow merge`), every one is `introduced`.
38
+ */
39
+ export function splitUnplaced(unplaced, baseline) {
40
+ const known = [];
41
+ const introduced = [];
42
+ const left = new Map(baseline ?? []);
43
+ for (const f of unplaced) {
44
+ const n = left.get(findingKey(f)) ?? 0;
45
+ if (n > 0) {
46
+ left.set(findingKey(f), n - 1);
47
+ known.push(f);
48
+ }
49
+ else
50
+ introduced.push(f);
51
+ }
52
+ return { known, introduced };
53
+ }
54
+ /** The `"quoted"` names in a finding's message, in order: what it is about, apart from its wording. */
55
+ function quotedSubjects(message) {
56
+ return JSON.stringify(message.match(/"[^"]*"/g) ?? []);
57
+ }
58
+ /**
59
+ * The indexes into `edited` of the findings the edit did not cause:
60
+ *
61
+ * - a finding on an unchanged place is pre-existing when the original
62
+ * reports the same code on the same place, once per occurrence. Exact
63
+ * messages are matched first; a second pass forgives wording the edit can
64
+ * shift without touching the finding (a "Known steps: ..." list), but only
65
+ * between messages that name the same `"quoted"` subjects;
66
+ * - a finding that names no place is pre-existing when the original reports
67
+ * the same code and message ({@link splitUnplaced});
68
+ * - a finding on a changed or new place never is.
69
+ *
70
+ * Every match also needs the same level: an edited error is never vouched for by a
71
+ * warning the original has, since the edit is what made it an error.
72
+ */
73
+ export function preExistingFindings(edited, baseline) {
74
+ const onPlace = (f) => `${f.place}\n${f.level}\n${f.code}`;
75
+ // The original's findings on each place, by code; each one vouches for one edited finding.
76
+ const pool = new Map();
77
+ for (const b of baseline) {
78
+ if (b.place === '')
79
+ continue;
80
+ pool.set(onPlace(b), [...(pool.get(onPlace(b)) ?? []), b.message]);
81
+ }
82
+ const preExisting = new Set();
83
+ for (const exact of [true, false]) {
84
+ for (const [i, f] of edited.entries()) {
85
+ if (f.place === '' || !f.unchanged || preExisting.has(i))
86
+ continue;
87
+ const messages = pool.get(onPlace(f)) ?? [];
88
+ const j = exact ? messages.indexOf(f.message) : messages.findIndex((m) => quotedSubjects(m) === quotedSubjects(f.message));
89
+ if (j < 0)
90
+ continue;
91
+ messages.splice(j, 1);
92
+ preExisting.add(i);
93
+ }
94
+ }
95
+ // The level rides in the code, so a warning the original has does not vouch for an error.
96
+ const leveled = (f) => ({ ...f, code: `${f.level}\n${f.code}` });
97
+ const unplaced = [...edited.entries()].filter(([, f]) => f.place === '').map(([i, f]) => ({ ...leveled(f), i }));
98
+ for (const f of splitUnplaced(unplaced, findingCounts(baseline.map(leveled))).known)
99
+ preExisting.add(f.i);
100
+ return preExisting;
101
+ }
102
+ /**
103
+ * `diags` with an `origin` on each: `pre-existing` for the indexes in
104
+ * `preExisting` (a {@link preExistingFindings} result), `edited` for the rest.
105
+ * A pre-existing finding becomes a warning, so it does not fail the check; a
106
+ * pre-existing `lowering` error also gets `loweringNote` on a line of its own,
107
+ * since the SDK cannot write back what the original holds there.
108
+ */
109
+ export function scopeFindings(diags, preExisting, loweringNote) {
110
+ return diags.map((d, i) => {
111
+ if (!preExisting.has(i))
112
+ return { ...d, origin: 'edited' };
113
+ const defect = d.level === 'error' && (d.class ?? refusalClass(d.code)) === 'lowering';
114
+ return { ...d, level: 'warning', message: defect ? `${d.message}\n ${loweringNote}` : d.message, origin: 'pre-existing' };
115
+ });
116
+ }
117
+ /**
118
+ * The `check --baseline` summary line: the errors that fail the check (the
119
+ * edit's), the pre-existing lowering findings (probable SDK defects) and the
120
+ * other pre-existing findings, and the edit's own warnings when there are any.
121
+ * `places` names what was edited (`nodes`, `elements`). For instance
122
+ * `1 error(s) in edited nodes, 1 pre-existing SDK defect(s), 1 pre-existing warning(s)`.
123
+ */
124
+ export function baselineSummary(diags, places) {
125
+ const edited = diags.filter((d) => d.origin !== 'pre-existing');
126
+ const pre = diags.filter((d) => d.origin === 'pre-existing');
127
+ const errors = edited.filter((d) => d.level === 'error').length;
128
+ const defects = pre.filter((d) => (d.class ?? refusalClass(d.code)) === 'lowering').length;
129
+ const warnings = edited.length - errors;
130
+ return `${errors} error(s) in edited ${places}, ${defects} pre-existing SDK defect(s), ${pre.length - defects} pre-existing warning(s)`
131
+ + (warnings ? `, ${warnings} warning(s) in edited ${places}` : '');
132
+ }
@@ -728,6 +728,7 @@ export declare const REFUSALS: {
728
728
  readonly SUBFLOW_NO_CHILD: "lint";
729
729
  readonly SUBFLOW_OUTPUT_NEVER_RETURNED: "lint";
730
730
  readonly SUBFLOW_OUTPUT_NO_FIELD: "lint";
731
+ readonly SUBFLOW_PARENT_SCOPE_READ: "lint";
731
732
  readonly SUBFLOW_UNKNOWN_INPUT: "lint";
732
733
  readonly SUBFLOW_UNKNOWN_OUTPUT: "lint";
733
734
  readonly SUPERFLUOUS_GATEWAY: "lint";
@@ -802,6 +802,7 @@ export const REFUSALS = {
802
802
  SUBFLOW_NO_CHILD: 'lint',
803
803
  SUBFLOW_OUTPUT_NEVER_RETURNED: 'lint',
804
804
  SUBFLOW_OUTPUT_NO_FIELD: 'lint',
805
+ SUBFLOW_PARENT_SCOPE_READ: 'lint',
805
806
  SUBFLOW_UNKNOWN_INPUT: 'lint',
806
807
  SUBFLOW_UNKNOWN_OUTPUT: 'lint',
807
808
  SUPERFLUOUS_GATEWAY: 'lint',
@@ -211,27 +211,9 @@ export type PlacedDiagnostic = Diagnostic & {
211
211
  * to, gets nodeId `''`.
212
212
  */
213
213
  export declare function placeDiagnostics(diagnostics: readonly Diagnostic[], editedFlow: any): PlacedDiagnostic[];
214
- /** How many times each {@link findingKey} occurs, for {@link splitUnplaced}'s baseline. */
215
- export declare function findingCounts(findings: ReadonlyArray<{
216
- code: string;
217
- message: string;
218
- }>): Map<string, number>;
219
214
  /**
220
- * Sort findings merge could not place on a node by whether the edit introduced
221
- * them: `known` when the ORIGINAL's own round trip (`baseline`, the decompiled
222
- * original compiled and checked, as {@link findingCounts}) reports the same
223
- * code and message — once per occurrence, so a second copy of a finding the
224
- * original has once is `introduced` — so the finding predates the edit and
225
- * only prints; `introduced` otherwise, which is refused like any error on an
226
- * edited node (#1322). With no baseline findings to compare against (a
227
- * precompiled `--baseline` file), every one is `introduced`, as merge treated
228
- * them before.
215
+ * Sorting the findings that name no node by whether the original has them too
216
+ * (`findingCounts`, `splitUnplaced`) is shared with every family's
217
+ * `check --baseline` (core/baseline-scope.ts).
229
218
  */
230
- export declare function splitUnplaced<T extends {
231
- code: string;
232
- message: string;
233
- }>(unplaced: readonly T[], baseline: ReadonlyMap<string, number> | undefined): {
234
- known: T[];
235
- introduced: T[];
236
- };
237
- export {};
219
+ export { findingCounts, splitUnplaced } from './core/baseline-scope.js';
@@ -292,42 +292,11 @@ export function placeDiagnostics(diagnostics, editedFlow) {
292
292
  };
293
293
  return diagnostics.map((d) => ({ ...d, ...place(d.step) }));
294
294
  }
295
- /** The identity of a finding for the introduced-or-not comparison: its code and message. */
296
- function findingKey(f) {
297
- return `${f.code}\n${f.message}`;
298
- }
299
- /** How many times each {@link findingKey} occurs, for {@link splitUnplaced}'s baseline. */
300
- export function findingCounts(findings) {
301
- const counts = new Map();
302
- for (const f of findings)
303
- counts.set(findingKey(f), (counts.get(findingKey(f)) ?? 0) + 1);
304
- return counts;
305
- }
306
295
  /**
307
- * Sort findings merge could not place on a node by whether the edit introduced
308
- * them: `known` when the ORIGINAL's own round trip (`baseline`, the decompiled
309
- * original compiled and checked, as {@link findingCounts}) reports the same
310
- * code and message — once per occurrence, so a second copy of a finding the
311
- * original has once is `introduced` — so the finding predates the edit and
312
- * only prints; `introduced` otherwise, which is refused like any error on an
313
- * edited node (#1322). With no baseline findings to compare against (a
314
- * precompiled `--baseline` file), every one is `introduced`, as merge treated
315
- * them before.
296
+ * Sorting the findings that name no node by whether the original has them too
297
+ * (`findingCounts`, `splitUnplaced`) is shared with every family's
298
+ * `check --baseline` (core/baseline-scope.ts).
316
299
  */
317
- export function splitUnplaced(unplaced, baseline) {
318
- const known = [];
319
- const introduced = [];
320
- const left = new Map(baseline ?? []);
321
- for (const f of unplaced) {
322
- const n = left.get(findingKey(f)) ?? 0;
323
- if (n > 0) {
324
- left.set(findingKey(f), n - 1);
325
- known.push(f);
326
- }
327
- else
328
- introduced.push(f);
329
- }
330
- return { known, introduced };
331
- }
300
+ export { findingCounts, splitUnplaced } from './core/baseline-scope.js';
332
301
  /** How `check` joins a subflow's calling step and the step inside it in a diagnostic's `step`. */
333
302
  const SUBFLOW_STEP_SEPARATOR = ' › ';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.97.3",
3
+ "version": "6.99.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",
@@ -77,7 +77,8 @@
77
77
  "prepare-resource",
78
78
  "bpmn-merge-source",
79
79
  "flow-merge-source",
80
- "fetch-definitions"
80
+ "fetch-definitions",
81
+ "bpmn-check-baseline"
81
82
  ],
82
83
  "files": [
83
84
  "dist",
@@ -114,5 +115,5 @@
114
115
  "@types/node": "^22.7.0",
115
116
  "esbuild": "^0.28.1"
116
117
  },
117
- "gitref": "2ae3d2904f0970fae81e8f36dbb3d30ae97be938"
118
+ "gitref": "a882a35fe0c0650eaf61789446cbcb6e5e245335"
118
119
  }