diff --git a/apps/docs/content/docs/workflows/code/diagnostics.mdx b/apps/docs/content/docs/workflows/code/diagnostics.mdx index b2e718a6f83..4b0af63e5f3 100644 --- a/apps/docs/content/docs/workflows/code/diagnostics.mdx +++ b/apps/docs/content/docs/workflows/code/diagnostics.mdx @@ -72,7 +72,7 @@ Reading and writing `workflow.ts`. | `E_UNKNOWN_PARAM` | A param the block does not have; the hint has a did-you-mean, or for block meta written there (`retry`, `disabled`, `locked`, `errorPort`) the third argument that takes it. | | `E_FIXED_PARAM` | A param the builder already pins. | | `W_FIELD_NOT_APPLICABLE` | A param not visible under the block's values, or a basic-only field on a block with `advancedMode`; apply keeps the stored value and the written-back source drops it. | -| `W_REQUIRED_MISSING` | A required field left empty, including `todo()`; not repeated for a field an `E_UNKNOWN_PARAM` did-you-mean names, or one written with a value that failed to compile. | +| `W_REQUIRED_MISSING` | A required field left empty, including `''` and `todo()`; not repeated for a field an `E_UNKNOWN_PARAM` did-you-mean names, or one written with a value that failed to compile. | | `W_UNKNOWN_OPTION` | A dropdown value none of its options names; `hint` lists them. | | `E_UNKNOWN_OPERATION` | An `operation` the block does not offer; `hint` lists them. A retired one the stored block holds is `W_UNKNOWN_OPTION`. | | `W_UNKNOWN_MODEL` | A `model` the catalog does not list (kept: custom models are free text). | diff --git a/packages/workflow-code/src/compile/SYNTAX.md b/packages/workflow-code/src/compile/SYNTAX.md index dcc148c1c3b..23d0cec1cca 100644 --- a/packages/workflow-code/src/compile/SYNTAX.md +++ b/packages/workflow-code/src/compile/SYNTAX.md @@ -89,9 +89,9 @@ export default workflow('Name', { description: '…', variables: { … } }, ({ v - A param not visible under the block's values is `W_FIELD_NOT_APPLICABLE`, naming the value that hides it, as is a basic-only field (`mode: 'basic'`, no canonical pair) on a block with `advancedMode`, which the serializer never sends: it never runs, so apply keeps the stored value - (preserved state) and the written-back source drops the line. A required field left empty (or - `todo()`) is `W_REQUIRED_MISSING`. A value whose JSON type differs from the field's is - `W_VALUE_KIND`; it is never coerced. + (preserved state) and the written-back source drops the line. A required field left empty + (omitted, `''`, or `todo()`) is `W_REQUIRED_MISSING`. A value whose JSON type differs from the + field's is `W_VALUE_KIND`; it is never coerced. ### Pair mode @@ -455,7 +455,7 @@ Errors refuse the whole apply. Warnings are saved as written; info is informatio | `E_UNKNOWN_PARAM` | A param the block does not have; the hint has a did-you-mean, or for block meta written there (`retry`, `disabled`, `locked`, `errorPort`) the third argument that takes it. | | `E_FIXED_PARAM` | A param the builder already pins. | | `W_FIELD_NOT_APPLICABLE` | A param not visible under the block's values, or a basic-only field on a block with `advancedMode`; apply keeps the stored value and the written-back source drops it. | -| `W_REQUIRED_MISSING` | A required field left empty, including `todo()`; not repeated for a field an `E_UNKNOWN_PARAM` did-you-mean names, or one written with a value that failed to compile. | +| `W_REQUIRED_MISSING` | A required field left empty, including `''` and `todo()`; not repeated for a field an `E_UNKNOWN_PARAM` did-you-mean names, or one written with a value that failed to compile. | | `W_UNKNOWN_OPTION` | A dropdown value none of its options names; `hint` lists them. | | `E_UNKNOWN_OPERATION` | An `operation` the block does not offer; `hint` lists them. A retired one the stored block holds is `W_UNKNOWN_OPTION`. | | `W_UNKNOWN_MODEL` | A `model` the catalog does not list (kept: custom models are free text). | diff --git a/packages/workflow-code/src/compile/blocks.ts b/packages/workflow-code/src/compile/blocks.ts index f212ac669a4..15d824a427c 100644 --- a/packages/workflow-code/src/compile/blocks.ts +++ b/packages/workflow-code/src/compile/blocks.ts @@ -1794,8 +1794,12 @@ function checkFields(ctx: CompileContext, index: FieldIndex, state: BlockState): ) } } - const isWritten = (id: SubBlockId) => Object.hasOwn(params, id) - for (const field of missingRequiredFields(index, values, isWritten, state.meta.advancedMode)) { + // A written `''` is missing to the runtime too (`collectBlockFieldIssues`). + const holdsValue = (id: SubBlockId) => { + const param = getOwn(params, id) + return param !== undefined && !(param.kind === 'value' && param.value === '') + } + for (const field of missingRequiredFields(index, values, holdsValue, state.meta.advancedMode)) { if (state.explained.has(field.name)) continue const todo = state.todos.get(field.name) ctx.reporter.report( diff --git a/packages/workflow-code/src/compile/checks.test.ts b/packages/workflow-code/src/compile/checks.test.ts index fd2d1673090..6a8b88f8d89 100644 --- a/packages/workflow-code/src/compile/checks.test.ts +++ b/packages/workflow-code/src/compile/checks.test.ts @@ -1185,6 +1185,11 @@ describe('hints that name the fix', () => { }) expect(findings(result, 'W_REQUIRED_MISSING').map((d) => d.param)).toEqual(['url']) }) + + it("reports a required param written as '' as missing, as the runtime does", () => { + const result = run([START, "const a = api('A', { url: '' })"].join('\n')) + expect(findings(result, 'W_REQUIRED_MISSING').map((d) => d.param)).toEqual(['url']) + }) }) describe('an options object passed to .to()', () => { diff --git a/packages/workflow-code/src/compile/validate-catalog.ts b/packages/workflow-code/src/compile/validate-catalog.ts index f7d4c3c0dcf..d7e46085fa6 100644 --- a/packages/workflow-code/src/compile/validate-catalog.ts +++ b/packages/workflow-code/src/compile/validate-catalog.ts @@ -79,23 +79,24 @@ export function hiddenReason( * (`W_REQUIRED_MISSING`). `values` are the block's compiled params, which already hold each * omitted field's editor default (`catalog/defaults.ts` `editorDefaults`, the one source of what * an omitted param means), so an omitted Slack `destinationType` reads as the `'channel'` the - * canvas writes. A field counts when no member holds a value and some member is certainly visible - * and certainly required under those values: a provider's credential fields never count for a - * model of another provider, and the half of a channel/DM switch the block does not use never - * counts, nor does a basic-only field of a block in advanced mode (`basicOnlyHidden`), which never - * runs. The server's lint, which runs the registry's own conditions, still reports what this - * static check cannot decide. + * canvas writes. A field counts when no member holds a value (`holdsValue`: written, and not the + * `''` the runtime also reads as missing) and some member is certainly visible and certainly + * required under those values: a provider's credential fields never count for a model of another + * provider, and the half of a channel/DM switch the block does not use never counts, nor does a + * basic-only field of a block in advanced mode (`basicOnlyHidden`), which never runs. The server's + * lint, which runs the registry's own conditions, still reports what this static check cannot + * decide. */ export function missingRequiredFields( index: FieldIndex, values: ReadonlyMap, - isWritten: (subBlockId: SubBlockId) => boolean, + holdsValue: (subBlockId: SubBlockId) => boolean, advancedMode: boolean ): CatalogField[] { const missing: CatalogField[] = [] for (const field of index.fields.values()) { const members = field.kind === 'single' ? [field.sub] : field.members - if (members.some((sub) => isWritten(sub.id))) continue + if (members.some((sub) => holdsValue(sub.id))) continue const lookup = paramLookup(values) const declared = members.flatMap((sub) => index.declarations.get(sub.id) ?? [sub]) if (