@uipath/maestro-builder-sdk 6.87.3 → 6.87.4

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.
@@ -1,6 +1,7 @@
1
1
  /**
2
- * case-expr-check — the CASE adapter over the shared `core/expr-check`, run by
3
- * `CaseBuilder.build()` before it hands back the model to be serialized.
2
+ * case-expr-check — the CASE adapter over the shared `core/expr-check`. Its
3
+ * `lint` findings go to `check` (`caseExprLints`); the rest stop
4
+ * `CaseBuilder.build()` before it hands back the model (`caseExprRefusals`).
4
5
  *
5
6
  * A case `=js:` gate reads a declared variable as `=js:vars.<name>` — the `vars.`
6
7
  * namespace, NOT `case.` (a `case.` reference resolves to nothing; the platform's
@@ -8,7 +9,9 @@
8
9
  * `vars.` is a CLOSED namespace: a reference to a name no variable declares is a
9
10
  * definite mistake, and `validate` says so (`vars.<name> does not exist`). So this
10
11
  * flags every undeclared `vars.<root>`, exactly as the flow check flags `$vars`,
11
- * and `build()` is the fast pre-`validate` gate.
12
+ * and `check` is the fast pre-`validate` gate. It is `lint`, not a refusal:
13
+ * the serializer writes the read as authored, so a plan that has one still
14
+ * compiles (decided on builder-sdk#1712).
12
15
  *
13
16
  * The surfaces that carry a `=js:` gate: every rule's `expression`, a task's
14
17
  * `skipWhen`, and each SLA's `when`. Stage/task STRUCTURAL references
@@ -23,42 +26,46 @@ export interface CaseLocatedDiagnostic extends ExprDiagnostic {
23
26
  where: string;
24
27
  }
25
28
  /**
26
- * The undeclared `vars.<root>` names `expr` reads, as `build()` reports them
27
- * (`EXPR_UNDECLARED_REF`). A task-output reference stands in as a declared root.
28
- * For decompile, which refuses such a gate by name rather than writing source
29
- * compile refuses.
29
+ * An EXPR_UNDECLARED_REF finding with the read it is about: the expression as
30
+ * authored and the undeclared root. `check` uses it to drop plan-check's
31
+ * CASE_MGMT_REFERENCE_UNBOUND on the same read (one mistake, one finding).
30
32
  */
31
- export declare function undeclaredVarReads(expr: string, roots: ReadonlySet<string>): string[];
33
+ export interface CaseExprFinding extends CaseLocatedDiagnostic {
34
+ read?: {
35
+ expr: string;
36
+ root: string;
37
+ };
38
+ }
32
39
  /**
33
40
  * The platform variable that says whether the stage labelled `label` has run
34
41
  * (case-schema `baseLocalStageHasRunVariableInfoForStage`): `Stage 1` ->
35
42
  * `stageHasRun_Stage_1`. Exported for the Case fuzzer's stage renames.
36
43
  */
37
44
  export declare function stageHasRunVariable(label: string): string;
38
- /**
39
- * Variables the platform declares for every case, which a plan's gates may read
40
- * though no row of the plan declares them. `uip maestro case validate` adds the
41
- * same set to the variables it checks against (case-schema
42
- * `validateCaseManagementVariables`), and the BPMN converter writes each one:
43
- *
44
- * - `stageHasRun_<stage label>` per stage (`getCaseStateVariables`), set in the
45
- * initial variables setup and updated when the stage exits or completes. The
46
- * platform's own V11->V12 migration writes gates on it:
47
- * `=js:(vars.stageHasRun_Review != true)` for "first time this stage runs";
48
- * - the hidden event-subprocess rows `tasksEventSubprocessResponse`,
49
- * `mainEventSubprocessResponse`, `connectorResponse` and `eventMetadata`.
50
- *
51
- * Not here: the per-SLA `stageSla_<stage>_<sla id>` rows, whose ids compile
52
- * mints after this check runs.
53
- */
54
- export declare function platformVariables(stageLabels: readonly string[]): string[];
55
45
  /** Every first-level expression problem in a built case, each stamped with its location. */
56
46
  export declare function checkCaseExpressions(built: BuiltCase): CaseLocatedDiagnostic[];
47
+ /**
48
+ * The expression findings `CaseBuilder.build()` refuses: every error whose code
49
+ * is not `lint`. Today that is TASK_OUTPUT_REF_UNRESOLVED, a task-output
50
+ * reference naming no stage, task or output, which the serializer has no id to
51
+ * lower to.
52
+ */
53
+ export declare function caseExprRefusals(built: BuiltCase): CaseLocatedDiagnostic[];
54
+ /**
55
+ * The expression findings only `check` reports: every `lint` code, such as
56
+ * EXPR_UNDECLARED_REF (`=js:vars.missing` where no variable is named
57
+ * `missing`). The serializer writes such a read exactly as authored, so it
58
+ * never stops `build()` or `compile` (decided on builder-sdk#1712): a
59
+ * brownfield plan that already carries one still loads, compiles and merges.
60
+ */
61
+ export declare function caseExprLints(built: BuiltCase): CaseExprFinding[];
57
62
  /**
58
63
  * Thrown by `CaseBuilder.build()` when the first-level expression check finds a
59
- * likely-typo'd case-variable reference. Same shape/rationale as the flow's
60
- * `FlowBuildError`: `message` lists every problem; `diagnostics` carries them
61
- * structured.
64
+ * reference the serializer cannot lower: a task-output reference that names no
65
+ * stage, task or output (TASK_OUTPUT_REF_UNRESOLVED). An undeclared
66
+ * `vars.<name>` read (EXPR_UNDECLARED_REF) no longer throws it; `check`
67
+ * reports that one. Same shape as the flow's `FlowBuildError`: `message` lists
68
+ * every problem; `diagnostics` carries them structured.
62
69
  */
63
70
  export declare class CaseBuildError extends CompileRefusal {
64
71
  readonly diagnostics: CaseLocatedDiagnostic[];
@@ -1,6 +1,7 @@
1
1
  /**
2
- * case-expr-check — the CASE adapter over the shared `core/expr-check`, run by
3
- * `CaseBuilder.build()` before it hands back the model to be serialized.
2
+ * case-expr-check — the CASE adapter over the shared `core/expr-check`. Its
3
+ * `lint` findings go to `check` (`caseExprLints`); the rest stop
4
+ * `CaseBuilder.build()` before it hands back the model (`caseExprRefusals`).
4
5
  *
5
6
  * A case `=js:` gate reads a declared variable as `=js:vars.<name>` — the `vars.`
6
7
  * namespace, NOT `case.` (a `case.` reference resolves to nothing; the platform's
@@ -8,7 +9,9 @@
8
9
  * `vars.` is a CLOSED namespace: a reference to a name no variable declares is a
9
10
  * definite mistake, and `validate` says so (`vars.<name> does not exist`). So this
10
11
  * flags every undeclared `vars.<root>`, exactly as the flow check flags `$vars`,
11
- * and `build()` is the fast pre-`validate` gate.
12
+ * and `check` is the fast pre-`validate` gate. It is `lint`, not a refusal:
13
+ * the serializer writes the read as authored, so a plan that has one still
14
+ * compiles (decided on builder-sdk#1712).
12
15
  *
13
16
  * The surfaces that carry a `=js:` gate: every rule's `expression`, a task's
14
17
  * `skipWhen`, and each SLA's `when`. Stage/task STRUCTURAL references
@@ -17,6 +20,7 @@
17
20
  */
18
21
  import { checkExpression, extractRefs } from '../core/expr-check.js';
19
22
  import { CompileRefusal } from '../core/compile-refusal.js';
23
+ import { refusalClass } from '../core/refusals.js';
20
24
  import { readEventFilter } from '../core/event-filters.js';
21
25
  import { defaultActionOutputVar } from './action-output-var.js';
22
26
  import { lowerTaskOutputRefs, pickByName, pickOutputRow, taskOutputRefs, unresolvedTaskOutputRef } from './task-output-ref.js';
@@ -77,25 +81,18 @@ function checkTaskOutputRefs(built, value, where, out) {
77
81
  out.push({ level: 'error', code: 'TASK_OUTPUT_REF_UNRESOLVED', message: unresolvedTaskOutputRef(ref, why), where });
78
82
  }
79
83
  }
80
- /**
81
- * The undeclared `vars.<root>` names `expr` reads, as `build()` reports them
82
- * (`EXPR_UNDECLARED_REF`). A task-output reference stands in as a declared root.
83
- * For decompile, which refuses such a gate by name rather than writing source
84
- * compile refuses.
85
- */
86
- export function undeclaredVarReads(expr, roots) {
87
- const lowered = lowerTaskOutputRefs(expr, () => TASK_OUTPUT_ROOT);
88
- const scope = new Set([...roots, TASK_OUTPUT_ROOT]);
89
- return [...new Set(extractRefs(lowered, NAMESPACE).map((ref) => ref.root).filter((root) => !scope.has(root)))];
90
- }
91
84
  function checkExpr(built, expr, where, roots, out) {
92
85
  if (!expr)
93
86
  return;
94
87
  checkTaskOutputRefs(built, expr, where, out);
95
88
  const lowered = lowerTaskOutputRefs(expr, () => TASK_OUTPUT_ROOT);
96
89
  const scope = lowered === expr ? roots : new Set([...roots, TASK_OUTPUT_ROOT]);
90
+ // The undeclared roots, in the order checkExpression reports them (one each).
91
+ const undeclared = [...new Set(extractRefs(lowered, NAMESPACE).map((r) => r.root).filter((r) => !scope.has(r)))];
92
+ let next = 0;
97
93
  for (const d of checkExpression(lowered, { roots: scope, noun: NOUN, namespace: NAMESPACE })) {
98
- out.push({ ...d, where });
94
+ const root = d.code === 'EXPR_UNDECLARED_REF' ? undeclared[next++] : undefined;
95
+ out.push({ ...d, where, ...(root !== undefined ? { read: { expr, root } } : {}) });
99
96
  }
100
97
  }
101
98
  /**
@@ -158,7 +155,7 @@ export function stageHasRunVariable(label) {
158
155
  * Not here: the per-SLA `stageSla_<stage>_<sla id>` rows, whose ids compile
159
156
  * mints after this check runs.
160
157
  */
161
- export function platformVariables(stageLabels) {
158
+ function platformVariables(stageLabels) {
162
159
  return [
163
160
  ...stageLabels.map((label) => stageHasRunVariable(label)),
164
161
  'tasksEventSubprocessResponse',
@@ -226,11 +223,32 @@ export function checkCaseExpressions(built) {
226
223
  }
227
224
  return out;
228
225
  }
226
+ /**
227
+ * The expression findings `CaseBuilder.build()` refuses: every error whose code
228
+ * is not `lint`. Today that is TASK_OUTPUT_REF_UNRESOLVED, a task-output
229
+ * reference naming no stage, task or output, which the serializer has no id to
230
+ * lower to.
231
+ */
232
+ export function caseExprRefusals(built) {
233
+ return checkCaseExpressions(built).filter((d) => d.level === 'error' && refusalClass(d.code) !== 'lint');
234
+ }
235
+ /**
236
+ * The expression findings only `check` reports: every `lint` code, such as
237
+ * EXPR_UNDECLARED_REF (`=js:vars.missing` where no variable is named
238
+ * `missing`). The serializer writes such a read exactly as authored, so it
239
+ * never stops `build()` or `compile` (decided on builder-sdk#1712): a
240
+ * brownfield plan that already carries one still loads, compiles and merges.
241
+ */
242
+ export function caseExprLints(built) {
243
+ return checkCaseExpressions(built).filter((d) => refusalClass(d.code) === 'lint');
244
+ }
229
245
  /**
230
246
  * Thrown by `CaseBuilder.build()` when the first-level expression check finds a
231
- * likely-typo'd case-variable reference. Same shape/rationale as the flow's
232
- * `FlowBuildError`: `message` lists every problem; `diagnostics` carries them
233
- * structured.
247
+ * reference the serializer cannot lower: a task-output reference that names no
248
+ * stage, task or output (TASK_OUTPUT_REF_UNRESOLVED). An undeclared
249
+ * `vars.<name>` read (EXPR_UNDECLARED_REF) no longer throws it; `check`
250
+ * reports that one. Same shape as the flow's `FlowBuildError`: `message` lists
251
+ * every problem; `diagnostics` carries them structured.
234
252
  */
235
253
  export class CaseBuildError extends CompileRefusal {
236
254
  diagnostics;
@@ -238,7 +256,7 @@ export class CaseBuildError extends CompileRefusal {
238
256
  const label = built.name || built.id || 'case';
239
257
  const lines = diagnostics.map((d) => ` ✗ [${d.code}] in ${d.where}: ${d.message}${d.suggestion ? ` (did you mean "${d.suggestion}"?)` : ''}`);
240
258
  // The first problem's code; `diagnostics` carries every one.
241
- super(diagnostics[0]?.code ?? 'EXPR_UNDECLARED_REF', `Cannot build case "${label}" — ${diagnostics.length} expression problem(s):\n${lines.join('\n')}`);
259
+ super(diagnostics[0]?.code ?? 'TASK_OUTPUT_REF_UNRESOLVED', `Cannot build case "${label}" — ${diagnostics.length} expression problem(s):\n${lines.join('\n')}`);
242
260
  this.name = 'CaseBuildError';
243
261
  this.diagnostics = diagnostics;
244
262
  }
@@ -22,7 +22,7 @@ import { CASE_SCRIPT_RUNTIME } from './script.js';
22
22
  import { ACTION_PASSTHROUGH_SETTINGS } from './action-settings.js';
23
23
  import { connector as makeConnector, subscriptionFrom, } from '../core/actions.js';
24
24
  import { isTriggerDescriptor } from '../core/connectors.js';
25
- import { checkCaseExpressions, CaseBuildError } from './case-expr-check.js';
25
+ import { caseExprRefusals, CaseBuildError } from './case-expr-check.js';
26
26
  import { taskOutputMarker } from './task-output-ref.js';
27
27
  import { CASE_FORMAT_PROFILE, CASE_SCHEMA_VERSIONS, recordAuthoredCaseVersion } from './format-profile.js';
28
28
  import { schemaVersionRefusal } from '../schema-version.js';
@@ -1445,10 +1445,13 @@ class CaseBuilder {
1445
1445
  };
1446
1446
  if (this._authoredVersion !== undefined)
1447
1447
  recordAuthoredCaseVersion(built, this._authoredVersion);
1448
- // First-level validation, intrinsic to running the SDK: catch a reference to
1449
- // an undeclared `vars.<name>` HERE, before the caseplan is serialized, rather
1450
- // than three steps later at `uip maestro case validate`. See case-expr-check.
1451
- const errors = checkCaseExpressions(built).filter((d) => d.level === 'error');
1448
+ // A task-output reference that names no stage, task or output is refused
1449
+ // here (TASK_OUTPUT_REF_UNRESOLVED, `lowering`). A `lint` finding (a read of
1450
+ // a `vars.<name>` nothing declares, EXPR_UNDECLARED_REF) is not: the
1451
+ // serializer writes that read as authored, so `check` reports it and a
1452
+ // brownfield plan that already has one still builds, compiles and merges
1453
+ // (decided on builder-sdk#1712). See case-expr-check.
1454
+ const errors = caseExprRefusals(built);
1452
1455
  if (errors.length)
1453
1456
  throw new CaseBuildError(built, errors);
1454
1457
  return built;
@@ -10,6 +10,7 @@ import { httpRequestLint } from './http-request.js';
10
10
  import { checkRuleSemantics } from './check-rule-semantics.js';
11
11
  import { serialize } from './serialize.js';
12
12
  import { lintPlanFindings, planReport } from './plan-check/index.js';
13
+ import { caseExprLints } from './case-expr-check.js';
13
14
  const TYPE_NAMES = new Set(Object.values(types));
14
15
  // audit-case-coverage: rule-slot table start
15
16
  // This runtime table must equal the committed matrix's rejected cells. The audit
@@ -183,23 +184,25 @@ export function check(built, opts = {}) {
183
184
  };
184
185
  // An In-arg with no `{ from }` and no primary trigger to bind to is the
185
186
  // serializer's CASE_IN_ARG_UNBOUND (in-arg-binding.ts), reported per arg.
186
- // ── `=js:vars.<name>` resolvability — REMOVED, superseded by #257 ───────────
187
- // This file briefly carried a VAR_NOT_REFERENCEABLE error asserting that only a
188
- // trigger-bound In-arg (`.input(shape, { from })`) could be read as `=js:vars.x`,
189
- // and that a bare `.var()` always failed `uip maestro case validate` with
190
- // "Variable 'vars.x' does not exist". That was empirically true when written and
191
- // is now FALSE: #257 fixed the serializer to emit the `inputOutputs` companion
192
- // with `id: <name>` / `elementId: "root"`, which is what the platform resolves
193
- // `vars.<name>` against — so a declared `.var()` is readable.
194
- //
195
- // Both halves of the old rule are superseded:
196
- // - "declared vars are unreadable" -> no longer true (#257 serializer fix).
197
- // - "undeclared vars.x slips through" -> #257 also added a strict namespace
198
- // check to CaseBuilder.build(), which throws CaseBuildError with a
199
- // near-miss suggestion before check() ever runs.
200
- // Re-adding any variable-reachability rule here would reintroduce a false
201
- // positive that blocks emit (this gate runs before serialization), so it must be
202
- // re-derived from the serializer rather than from remembered probe results.
187
+ // ── `=js:vars.<name>` resolvability ─────────────────────────────────────────
188
+ // A read of a `vars.<name>` no variable declares (EXPR_UNDECLARED_REF) is
189
+ // `lint`: the serializer writes it as authored, so it is reported here, on
190
+ // the gate it is in, and never stops `build()` or `compile` (decided on
191
+ // builder-sdk#1712; it was a CaseBuildError from build() since #257). The
192
+ // declared set is the serializer's (`inputOutputs` companions: `.var()`s, task
193
+ // and action outputs, trigger extractions), so a declared `.var()` is not
194
+ // flagged. The refusing findings stay in build() (`caseExprRefusals`).
195
+ // The location and the near-miss hint go into the message too: `case check`
196
+ // prints `[code] message`, and its JSON carries no `where`.
197
+ const exprLints = caseExprLints(built);
198
+ for (const d of exprLints)
199
+ diags.push({
200
+ level: d.level, code: d.code,
201
+ message: `in ${d.where}: ${d.message}${d.suggestion ? ` (did you mean "${d.suggestion}"?)` : ''}`,
202
+ where: d.where,
203
+ ...(d.suggestion ? { suggestion: d.suggestion } : {}),
204
+ });
205
+ const reportedReads = exprLints.flatMap((d) => (d.read ? [d.read] : []));
203
206
  for (const stage of built.stages) {
204
207
  checkStage(stage, diags, refStage, refPlacement);
205
208
  stage.slaRules.forEach((s, i) => checkSla(s, `stage "${stage.label}" SLA #${i + 1}`, diags));
@@ -240,7 +243,7 @@ export function check(built, opts = {}) {
240
243
  diags.push({ level: 'error', code: f.code, message: f.message, ...(f.suggestion ? { suggestion: f.suggestion } : {}), where: t.name });
241
244
  checkRuleSemantics(built, diags);
242
245
  checkLibraryConnectors(built, opts, diags);
243
- diags.push(...serializerRefusals(built, opts, diags));
246
+ diags.push(...serializerRefusals(built, opts, diags, reportedReads));
244
247
  return diags;
245
248
  }
246
249
  /**
@@ -256,7 +259,7 @@ export function check(built, opts = {}) {
256
259
  * `internal SDK error:` is passed on, unless `check` or the serializer already
257
260
  * found an error, which the author has to fix first.
258
261
  */
259
- function serializerRefusals(built, opts, found) {
262
+ function serializerRefusals(built, opts, found, reportedReads = []) {
260
263
  const collected = [];
261
264
  const warned = [];
262
265
  let plan;
@@ -299,6 +302,8 @@ function serializerRefusals(built, opts, found) {
299
302
  // one place they are heard.
300
303
  if (plan)
301
304
  for (const f of lintPlanFindings(plan)) {
305
+ if (sameReadAsExprLint(plan, f, reportedReads))
306
+ continue;
302
307
  const r = planReport(f);
303
308
  out.push({
304
309
  level: f.level, code: r.code, message: r.message,
@@ -317,6 +322,64 @@ function serializerRefusals(built, opts, found) {
317
322
  }
318
323
  return out;
319
324
  }
325
+ /** The value at a plan-check path (`nodes[1].data.tasks[0][0].skipCondition`). */
326
+ function valueAtPlanPath(plan, path) {
327
+ let at = plan;
328
+ for (const m of path.matchAll(/([^.[\]]+)|\[(\d+)\]/g)) {
329
+ if (at === null || typeof at !== 'object')
330
+ return undefined;
331
+ at = at[m[2] ?? m[1]];
332
+ }
333
+ return at;
334
+ }
335
+ /** An expression without its `=js:` / `=` prefix, outer parentheses and spacing, so an authored gate and the text the plan carries compare. */
336
+ function exprBody(text) {
337
+ let body = text.trim().replace(/^=(?:js:)?/, '').trim();
338
+ while (/^\(.*\)$/s.test(body))
339
+ body = body.slice(1, -1).trim();
340
+ return body;
341
+ }
342
+ /**
343
+ * The plan fields the expression check reads, where plan-check's
344
+ * REFERENCE_UNBOUND can be about the same read: a rule's
345
+ * `conditionExpression`, a task's `skipCondition` and an SLA's `expression`
346
+ * hold the gate as authored, so the read must equal it.
347
+ */
348
+ const GATE_PATH = /(?:\.conditionExpression|\.skipCondition|slaRules\[\d+\]\.expression)$/;
349
+ /**
350
+ * A wait filter's expression sits inside a larger encoded value, so the read
351
+ * is found by containment: the filter body
352
+ * (`…inputs[0].body.filters.variables.var_0`) and the encoded configuration
353
+ * (`…context[8].body.activityPropertyConfiguration.configuration`).
354
+ */
355
+ const WAIT_FILTER_PATH = /\.body\.(?:filters\b|activityPropertyConfiguration\.configuration$)/;
356
+ /**
357
+ * True when `f` is plan-check's CASE_MGMT_REFERENCE_UNBOUND on a read the
358
+ * expression check already reported as EXPR_UNDECLARED_REF: the same root, in
359
+ * plan text written from that expression (the gate verbatim, or a wait
360
+ * filter's expression inside its encoded configuration). One mistake, one
361
+ * finding. A REFERENCE_UNBOUND anywhere else, such as a task input
362
+ * `=vars.x` or a connector body field, which the expression check does not
363
+ * read, is still reported, even when its text equals the gate's.
364
+ */
365
+ function sameReadAsExprLint(plan, f, reads) {
366
+ if (f.code !== 'CASE_MGMT_REFERENCE_UNBOUND' || !reads.length)
367
+ return false;
368
+ const gate = GATE_PATH.test(f.path);
369
+ const contained = !gate && WAIT_FILTER_PATH.test(f.path);
370
+ if (!gate && !contained)
371
+ return false;
372
+ const value = valueAtPlanPath(plan, f.path);
373
+ if (typeof value !== 'string')
374
+ return false;
375
+ const body = exprBody(value);
376
+ return reads.some((r) => {
377
+ if (!f.message.startsWith(`"vars.${r.root}"`))
378
+ return false;
379
+ const read = exprBody(r.expr);
380
+ return gate ? read === body : value.includes(read);
381
+ });
382
+ }
320
383
  /**
321
384
  * The connector-library warnings only `check` gives (#1014): a connector task's
322
385
  * schema-readiness warnings, because the `connectors-local` overlay `registry
@@ -7,9 +7,11 @@
7
7
  *
8
8
  * Only serializes, to a V32 caseplan.json (docs/CHECK_COMPILE_CONTRACT_DESIGN.md
9
9
  * D1, phase 8). It does not run `check()`'s lint rules: run `case check` first
10
- * for those. It stops only when it cannot write a correct plan, a refusal the
11
- * serializer throws, printed in `check`'s `✗ [CODE]` shape (and `case check`
12
- * reports the same refusal, from the same code). The authoritative deploy gate
10
+ * for those. One exception, as a warning that does not stop the write: a gate
11
+ * reading an undeclared case variable (EXPR_UNDECLARED_REF). It stops only
12
+ * when it cannot write a correct plan, a refusal the serializer throws,
13
+ * printed in `check`'s `✗ [CODE]` shape (and `case check` reports the same
14
+ * refusal, from the same code). The authoritative deploy gate
13
15
  * is `uip maestro case validate`.
14
16
  * Output defaults to the plan file the project in the working directory ships
15
17
  * (`caseplan.case` for a project `uip maestro case init` scaffolded), else
@@ -34,6 +36,7 @@ import { ensureTypeScriptRuntime } from '../node-runtime.js';
34
36
  import { CASE_FORMAT_PROFILE } from './format-profile.js';
35
37
  import { deriveCaseBindingsV2 } from './bindings-v2.js';
36
38
  import { orphanWarnings } from './orphaned-resources.js';
39
+ import { caseExprLints } from './case-expr-check.js';
37
40
  import { BINDINGS_V2_DOCUMENT_VERSION } from '../core/bindings-v2-resource.js';
38
41
  import { sha256Uuid } from '../core/stable-id.js';
39
42
  export async function run(argv) {
@@ -91,6 +94,15 @@ export async function run(argv) {
91
94
  }
92
95
  // Solution declarations no project binds once this derivation lands.
93
96
  warnings.push(...orphanWarnings(caseplan, out));
97
+ // A gate that reads a case variable nothing declares (`=js:vars.missing`):
98
+ // `lint`, so compile writes it as authored (#1712), but it is a definite
99
+ // mistake the gate will evaluate as `undefined`, so compile says so for an
100
+ // agent that skipped `case check`, which reports it as an error.
101
+ for (const d of caseExprLints(built))
102
+ warnings.push({
103
+ level: 'warning', code: d.code, message: `in ${d.where}: ${d.message}`, where: d.where,
104
+ ...(d.suggestion ? { suggestion: d.suggestion } : {}),
105
+ });
94
106
  for (const w of warnings)
95
107
  console.error(` ${diagnosticLine(w)}`);
96
108
  // Reported before the first write, so a write that throws still carries it.
@@ -191,7 +191,7 @@ export interface DecompileOptions {
191
191
  bestEffort?: boolean;
192
192
  }
193
193
  export interface CaseDecompileDiagnostic {
194
- code: 'UNSUPPORTED_TASK_KIND' | 'UNKNOWN_STAGE_REFERENCE' | 'UNKNOWN_TASK_REFERENCE' | 'UNKNOWN_EXIT_TARGET' | 'UNDECLARED_VARIABLE_REFERENCE';
194
+ code: 'UNSUPPORTED_TASK_KIND' | 'UNKNOWN_STAGE_REFERENCE' | 'UNKNOWN_TASK_REFERENCE' | 'UNKNOWN_EXIT_TARGET';
195
195
  message: string;
196
196
  location: string;
197
197
  }
@@ -25,8 +25,6 @@ import { bindingIdCandidates, offlineBindingLabel } from './ids.js';
25
25
  import { bindingRefId, isLiftFailure, isMintedWire, liftResourceFolder, liftResourceName, readBindingIds, resourceBindingOf, typedFolder, wireRows, } from './resource-wire.js';
26
26
  import { connectorPlaceholderKindOf } from './connector-placeholder.js';
27
27
  import { raiseTaskOutputReads, referableOutputIds } from './task-output-ref.js';
28
- import { defaultActionOutputVar } from './action-output-var.js';
29
- import { platformVariables, undeclaredVarReads } from './case-expr-check.js';
30
28
  const TASK_KIND_METHOD = {
31
29
  process: 'process',
32
30
  agent: 'agent',
@@ -2828,7 +2826,6 @@ export function decompileWithDiagnostics(plan, options = {}) {
2828
2826
  const diagnostics = [];
2829
2827
  refuseUnsupportedAuthoring(plan);
2830
2828
  plan = raiseTaskOutputRefs(plan);
2831
- refuseUndeclaredGateReads(plan, options.bestEffort ? diagnostics : undefined);
2832
2829
  const preservation = collectPreservation(plan);
2833
2830
  const refs = buildRefs(plan, options.library, options.bestEffort ? diagnostics : undefined);
2834
2831
  const selectNextStage = selectNextStageByExit(plan, refs);
@@ -2917,90 +2914,6 @@ export function decompileWithDiagnostics(plan, options = {}) {
2917
2914
  const source = `import { ${imports.join(', ')} } from ${tsLiteral(options.importSpecifier ?? './case-sdk.js')};\n\n${diagnosticHeader}${out.toString()}\n`;
2918
2915
  return { source, diagnostics };
2919
2916
  }
2920
- /**
2921
- * Every name a `vars.<name>` gate of `plan` may read without `build()` calling
2922
- * it undeclared: what the plan's rows declare (each `id` / `var` / `name`, a
2923
- * literal `value` / `target`), an action form field's default variable, and the
2924
- * variables the platform declares for every case. It is a superset of the roots
2925
- * `build()` checks the decompiled source against, so decompile never refuses a
2926
- * gate compile accepts.
2927
- */
2928
- function gateRoots(plan) {
2929
- const roots = new Set(platformVariables((plan.nodes ?? []).filter(isStage).map((s) => String(s.data?.label ?? ''))));
2930
- const walk = (value, inAction) => {
2931
- if (Array.isArray(value)) {
2932
- for (const item of value)
2933
- walk(item, inAction);
2934
- return;
2935
- }
2936
- if (!value || typeof value !== 'object')
2937
- return;
2938
- const row = value;
2939
- const action = inAction || row.type === 'action';
2940
- for (const [key, field] of Object.entries(row)) {
2941
- if (typeof field === 'string') {
2942
- if (key === 'id' || key === 'var' || key === 'name')
2943
- roots.add(field);
2944
- if ((key === 'value' || key === 'target') && !field.startsWith('='))
2945
- roots.add(field);
2946
- if ((key === 'value' || key === 'target') && /^=[\w$]+$/.test(field))
2947
- roots.add(field.slice(1));
2948
- if (key === 'name' && action)
2949
- roots.add(defaultActionOutputVar(field));
2950
- }
2951
- else
2952
- walk(field, action);
2953
- }
2954
- };
2955
- walk({ ...plan, metadata: undefined }, false);
2956
- walk(plan.metadata, false);
2957
- return roots;
2958
- }
2959
- /**
2960
- * Refuse a gate that reads a variable the plan does not declare. `build()`
2961
- * rejects such a reference (`EXPR_UNDECLARED_REF`: `vars.` is a closed
2962
- * namespace, and the runtime reads the name as `undefined`), so writing the
2963
- * gate into the source would only hand the author source compile refuses.
2964
- * Names the platform declares for every case (`stageHasRun_<stage>`, ...) are
2965
- * not refused; see `platformVariables`.
2966
- */
2967
- function refuseUndeclaredGateReads(plan, diagnostics) {
2968
- const roots = gateRoots(plan);
2969
- const check = (expr, where) => {
2970
- if (typeof expr !== 'string' || !expr)
2971
- return;
2972
- const missing = undeclaredVarReads(expr, roots);
2973
- if (!missing.length)
2974
- return;
2975
- const reads = `reads ${missing.map((name) => `\`vars.${name}\``).join(', ')}, which no variable of the plan declares `
2976
- + '(compile refuses it: EXPR_UNDECLARED_REF; at runtime it reads as undefined)';
2977
- // Best effort keeps the gate and marks the source as needing this repair.
2978
- if (diagnostics) {
2979
- diagnostics.push({ code: 'UNDECLARED_VARIABLE_REFERENCE', location: where, message: `${reads}. Declare the variable, or fix the expression.` });
2980
- return;
2981
- }
2982
- throw new Error(`${where} ${reads}. Declare the variable, or fix the expression to read one the case declares, then decompile again.`);
2983
- };
2984
- const rules = (conditions, where) => {
2985
- for (const condition of conditions ?? [])
2986
- for (const group of condition.rules ?? [])
2987
- for (const r of group ?? [])
2988
- check(r?.conditionExpression, where);
2989
- };
2990
- (plan.metadata?.slaRules ?? []).forEach((sla, i) => check(sla?.expression, `case SLA #${i + 1}`));
2991
- rules(plan.metadata?.caseExitRules, 'case completion rule');
2992
- for (const stage of (plan.nodes ?? []).filter(isStage)) {
2993
- const at = `stage "${stage.data?.label ?? stage.id ?? '?'}"`;
2994
- rules(stage.data?.entryConditions, `${at} entry rule`);
2995
- rules(stage.data?.exitConditions, `${at} exit rule`);
2996
- (stage.data?.slaRules ?? []).forEach((sla, i) => check(sla?.expression, `${at} SLA #${i + 1}`));
2997
- for (const task of (stage.data?.tasks ?? []).flat()) {
2998
- const tat = `task "${task?.displayName ?? task?.id ?? '?'}" in ${at}`;
2999
- check(task?.skipCondition, `${tat} skip condition`);
3000
- rules(task?.entryConditions, `${tat} entry rule`);
3001
- }
3002
- }
3003
- }
3004
2917
  /**
3005
2918
  * The plan with each read of a task output that recompiling could not keep,
3006
2919
  * `vars.<output id>`, written as the task-output reference that names the same
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.87.3",
3
+ "version": "6.87.4",
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",
@@ -110,5 +110,5 @@
110
110
  "@types/node": "^22.7.0",
111
111
  "esbuild": "^0.28.1"
112
112
  },
113
- "gitref": "39ebb67c20d4fbb730c1c5345fff135c19dcf34b"
113
+ "gitref": "d3a99371e59e7789379c5a846f1084d7545f17d8"
114
114
  }