diff --git a/apps/docs/content/docs/cli/reference.mdx b/apps/docs/content/docs/cli/reference.mdx index 6c054ff1717..3997762fb2b 100644 --- a/apps/docs/content/docs/cli/reference.mdx +++ b/apps/docs/content/docs/cli/reference.mdx @@ -8521,7 +8521,7 @@ sim workflows run [options] | `--allow ` | No | Send this block's writes for real during a dry run (its id, display name or key, or <workflow>.<block> for a workflow it calls); for an Agent, only its own tool calls, not a workflow or custom block it calls; repeatable. | | `--mock =` | No | Answer this block with the given JSON object instead of running it during a dry run (its id, display name or key, or <workflow>.<block> for a workflow it calls), to steer a branch or give a stubbed write a realistic result; a bare --mock <block> takes its output from --mock-from. Not a locked block, or one of a locked workflow or folder; data only (the API reference lists the fields a mock cannot set). The run records only which blocks were mocked, not the outputs, so a rerun reads them again with --mock-from; repeatable. | | `--mock-from ` | No | Answer each block a bare --mock <block> names with the output it recorded in this earlier run of the workflow, redacted as the run shows it: this workflow's blocks (not a child's; not inside a loop or parallel unless that run mocked it); fields a mock cannot set, such as cost or model, are left out. | -| `--trigger ` | No | Enter the run through this runnable trigger, by its block id; runs the saved draft (implies --draft). | +| `--trigger ` | No | Enter the run through this runnable trigger (its id, display name or key); runs the saved draft (implies --draft). | | `--sample` | No | Run with the selected trigger's sample payload instead of --input; runs the saved draft (implies --draft), whose writes are sent unless --dry. | | `--from-block ` | No | Rerun the saved draft from this block (its id, display name or key), reusing the outputs --source-run produced before it; a failed run prints this command as next. | | `--source-run ` | No | Earlier run of this workflow, deployed or draft, whose outputs the blocks before --from-block keep (requires --from-block). | @@ -8681,7 +8681,7 @@ sim workflows source apply [workflowId] [options] -Exit codes: 0 applied (or a clean dry run); 1 the source has errors (each printed as file:line:column with its frame and hint), the workflowId given is not the one .sim/base.json names (SOURCE_WORKFLOW_MISMATCH: the directory holds another workflow's source), the --run test run did not complete (the draft is saved; nothing was deployed), or the command failed; 5 the workflow changed since the directory was read (SOURCE_STALE, on a dry run too: get it again, reapply the edit, retry); 6 the workflow or its folder is locked (E_APPLY_LOCKED; a locked block exits 1, E_APPLY_LOCKED_BLOCK); 7 the source is too large; 9 rate limited (HTTP 429) after the CLI's retries, so nothing was written: wait a minute and run it again; 10 (busy, retry) another sim command is using --dir, or the workspace directory it is a workflow folder of (SOURCE_DIR_BUSY): nothing was read or written, run it again once the other finished; 13 not logged in, the login expired, or the server refused the credential (AUTH_REQUIRED): nothing was sent, run `sim login` (or fix or unset SIM_API_KEY when the key comes from it) and the command again; 14 without --yes and with no terminal to ask: the plan was printed with no errors and nothing was written (run the same command with --yes to apply it); 130 interrupted (Ctrl-C): a write already sent is finished and saved into the directory first, waiting up to 60s for its answer, and a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written and how to check. +Exit codes: 0 applied (or a clean dry run); 1 the source has errors (each printed as file:line:column with its frame and hint), the workflowId given is not the one .sim/base.json names (SOURCE_WORKFLOW_MISMATCH: the directory holds another workflow's source), the --run test run did not complete (the draft is saved; nothing was deployed), or the command failed; 5 the workflow changed since the directory was read (SOURCE_STALE, on a dry run too: get it again, reapply the edit, retry); 6 the workflow or its folder is locked (E_APPLY_LOCKED; a locked block exits 1, E_APPLY_LOCKED_BLOCK); 7 the source is too large; 9 rate limited (HTTP 429) after the CLI's retries: wait a minute and run it again. Nothing was written, unless the message says the apply was saved and only its --deploy was limited (a limited --run exits 1); 10 (busy, retry) another sim command is using --dir, or the workspace directory it is a workflow folder of (SOURCE_DIR_BUSY): nothing was read or written, run it again once the other finished; 13 not logged in, the login expired, or the server refused the credential (AUTH_REQUIRED): nothing was sent, run `sim login` (or fix or unset SIM_API_KEY when the key comes from it) and the command again; 14 without --yes and with no terminal to ask: the plan was printed with no errors and nothing was written (run the same command with --yes to apply it); 130 interrupted (Ctrl-C): a write already sent is finished and saved into the directory first, waiting up to 60s for its answer, and a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written and how to check. API request and response schemas: [applyWorkflowSource](/api-reference/workflows/applyWorkflowSource), [deployWorkflow](/api-reference/workflows/deployWorkflow), [getWorkflowDeployment](/api-reference/workflows/getWorkflowDeployment), [getSourceResources](/api-reference/workflows/getSourceResources), [executeWorkflow](/api-reference/workflows/executeWorkflowV2). @@ -8711,7 +8711,7 @@ sim workflows source create [options] -Exit codes: 0 created (or a clean dry run, or a starter written); 1 the source has errors (each printed as file:line:column with its frame and hint), the workflow name is taken (SOURCE_NAME_TAKEN: pass --name), the --run test run did not complete (the workflow is created; nothing was deployed), or the command failed (a starter is created in the workspace its types were written for unless --workspace or SIM_WORKSPACE names another); 6 the folder is locked; 7 the source is too large; 9 rate limited (HTTP 429) after the CLI's retries, so nothing was created: wait a minute and run it again; 10 (busy, retry) another sim command is using --dir, or the workspace directory it is a workflow folder of (SOURCE_DIR_BUSY): nothing was read or written, run it again once the other finished; 13 not logged in, the login expired, or the server refused the credential (AUTH_REQUIRED): nothing was sent, run `sim login` (or fix or unset SIM_API_KEY when the key comes from it) and the command again; 14 without --yes and with no terminal to ask: the plan was printed with no errors and nothing was created (run the same command with --yes); 130 interrupted (Ctrl-C): a write already sent is finished and saved into the directory first, waiting up to 60s for its answer, and a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written and how to check. +Exit codes: 0 created (or a clean dry run, or a starter written); 1 the source has errors (each printed as file:line:column with its frame and hint), the workflow name is taken (SOURCE_NAME_TAKEN: pass --name), the --run test run did not complete (the workflow is created; nothing was deployed), or the command failed (a starter is created in the workspace its types were written for unless --workspace or SIM_WORKSPACE names another); 6 the folder is locked; 7 the source is too large; 9 rate limited (HTTP 429) after the CLI's retries: wait a minute and run it again. Nothing was created, unless the message says the create was saved and only its --deploy was limited (a limited --run exits 1); 10 (busy, retry) another sim command is using --dir, or the workspace directory it is a workflow folder of (SOURCE_DIR_BUSY): nothing was read or written, run it again once the other finished; 13 not logged in, the login expired, or the server refused the credential (AUTH_REQUIRED): nothing was sent, run `sim login` (or fix or unset SIM_API_KEY when the key comes from it) and the command again; 14 without --yes and with no terminal to ask: the plan was printed with no errors and nothing was created (run the same command with --yes); 130 interrupted (Ctrl-C): a write already sent is finished and saved into the directory first, waiting up to 60s for its answer, and a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written and how to check. API request and response schemas: [createWorkflowFromSource](/api-reference/workflows/createWorkflowFromSource), [getSourceCatalog](/api-reference/catalog/getSourceCatalog), [getSourceResources](/api-reference/workflows/getSourceResources), [deployWorkflow](/api-reference/workflows/deployWorkflow), [getWorkflowDeployment](/api-reference/workflows/getWorkflowDeployment), [executeWorkflow](/api-reference/workflows/executeWorkflowV2). diff --git a/apps/docs/content/docs/cli/workflows.mdx b/apps/docs/content/docs/cli/workflows.mdx index 8bb1e13dded..1ba505bb7d7 100644 --- a/apps/docs/content/docs/cli/workflows.mdx +++ b/apps/docs/content/docs/cli/workflows.mdx @@ -838,7 +838,7 @@ sim workflows run [options] | `--allow ` | No | Send this block's writes for real during a dry run (its id, display name or key, or <workflow>.<block> for a workflow it calls); for an Agent, only its own tool calls, not a workflow or custom block it calls; repeatable. | | `--mock =` | No | Answer this block with the given JSON object instead of running it during a dry run (its id, display name or key, or <workflow>.<block> for a workflow it calls), to steer a branch or give a stubbed write a realistic result; a bare --mock <block> takes its output from --mock-from. Not a locked block, or one of a locked workflow or folder; data only (the API reference lists the fields a mock cannot set). The run records only which blocks were mocked, not the outputs, so a rerun reads them again with --mock-from; repeatable. | | `--mock-from ` | No | Answer each block a bare --mock <block> names with the output it recorded in this earlier run of the workflow, redacted as the run shows it: this workflow's blocks (not a child's; not inside a loop or parallel unless that run mocked it); fields a mock cannot set, such as cost or model, are left out. | -| `--trigger ` | No | Enter the run through this runnable trigger, by its block id; runs the saved draft (implies --draft). | +| `--trigger ` | No | Enter the run through this runnable trigger (its id, display name or key); runs the saved draft (implies --draft). | | `--sample` | No | Run with the selected trigger's sample payload instead of --input; runs the saved draft (implies --draft), whose writes are sent unless --dry. | | `--from-block ` | No | Rerun the saved draft from this block (its id, display name or key), reusing the outputs --source-run produced before it; a failed run prints this command as next. | | `--source-run ` | No | Earlier run of this workflow, deployed or draft, whose outputs the blocks before --from-block keep (requires --from-block). | @@ -1452,7 +1452,7 @@ sim workflows source create [options] -Exit codes: 0 created (or a clean dry run, or a starter written); 1 the source has errors (each printed as file:line:column with its frame and hint), the workflow name is taken (SOURCE_NAME_TAKEN: pass --name), the --run test run did not complete (the workflow is created; nothing was deployed), or the command failed (a starter is created in the workspace its types were written for unless --workspace or SIM_WORKSPACE names another); 6 the folder is locked; 7 the source is too large; 9 rate limited (HTTP 429) after the CLI's retries, so nothing was created: wait a minute and run it again; 10 (busy, retry) another sim command is using --dir, or the workspace directory it is a workflow folder of (SOURCE_DIR_BUSY): nothing was read or written, run it again once the other finished; 13 not logged in, the login expired, or the server refused the credential (AUTH_REQUIRED): nothing was sent, run `sim login` (or fix or unset SIM_API_KEY when the key comes from it) and the command again; 14 without --yes and with no terminal to ask: the plan was printed with no errors and nothing was created (run the same command with --yes); 130 interrupted (Ctrl-C): a write already sent is finished and saved into the directory first, waiting up to 60s for its answer, and a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written and how to check. +Exit codes: 0 created (or a clean dry run, or a starter written); 1 the source has errors (each printed as file:line:column with its frame and hint), the workflow name is taken (SOURCE_NAME_TAKEN: pass --name), the --run test run did not complete (the workflow is created; nothing was deployed), or the command failed (a starter is created in the workspace its types were written for unless --workspace or SIM_WORKSPACE names another); 6 the folder is locked; 7 the source is too large; 9 rate limited (HTTP 429) after the CLI's retries: wait a minute and run it again. Nothing was created, unless the message says the create was saved and only its --deploy was limited (a limited --run exits 1); 10 (busy, retry) another sim command is using --dir, or the workspace directory it is a workflow folder of (SOURCE_DIR_BUSY): nothing was read or written, run it again once the other finished; 13 not logged in, the login expired, or the server refused the credential (AUTH_REQUIRED): nothing was sent, run `sim login` (or fix or unset SIM_API_KEY when the key comes from it) and the command again; 14 without --yes and with no terminal to ask: the plan was printed with no errors and nothing was created (run the same command with --yes); 130 interrupted (Ctrl-C): a write already sent is finished and saved into the directory first, waiting up to 60s for its answer, and a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written and how to check. API request and response schemas: [createWorkflowFromSource](/api-reference/workflows/createWorkflowFromSource), [getSourceCatalog](/api-reference/catalog/getSourceCatalog), [getSourceResources](/api-reference/workflows/getSourceResources), [deployWorkflow](/api-reference/workflows/deployWorkflow), [getWorkflowDeployment](/api-reference/workflows/getWorkflowDeployment), [executeWorkflow](/api-reference/workflows/executeWorkflowV2). @@ -1489,7 +1489,7 @@ sim workflows source apply [workflowId] [options] -Exit codes: 0 applied (or a clean dry run); 1 the source has errors (each printed as file:line:column with its frame and hint), the workflowId given is not the one .sim/base.json names (SOURCE_WORKFLOW_MISMATCH: the directory holds another workflow's source), the --run test run did not complete (the draft is saved; nothing was deployed), or the command failed; 5 the workflow changed since the directory was read (SOURCE_STALE, on a dry run too: get it again, reapply the edit, retry); 6 the workflow or its folder is locked (E_APPLY_LOCKED; a locked block exits 1, E_APPLY_LOCKED_BLOCK); 7 the source is too large; 9 rate limited (HTTP 429) after the CLI's retries, so nothing was written: wait a minute and run it again; 10 (busy, retry) another sim command is using --dir, or the workspace directory it is a workflow folder of (SOURCE_DIR_BUSY): nothing was read or written, run it again once the other finished; 13 not logged in, the login expired, or the server refused the credential (AUTH_REQUIRED): nothing was sent, run `sim login` (or fix or unset SIM_API_KEY when the key comes from it) and the command again; 14 without --yes and with no terminal to ask: the plan was printed with no errors and nothing was written (run the same command with --yes to apply it); 130 interrupted (Ctrl-C): a write already sent is finished and saved into the directory first, waiting up to 60s for its answer, and a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written and how to check. +Exit codes: 0 applied (or a clean dry run); 1 the source has errors (each printed as file:line:column with its frame and hint), the workflowId given is not the one .sim/base.json names (SOURCE_WORKFLOW_MISMATCH: the directory holds another workflow's source), the --run test run did not complete (the draft is saved; nothing was deployed), or the command failed; 5 the workflow changed since the directory was read (SOURCE_STALE, on a dry run too: get it again, reapply the edit, retry); 6 the workflow or its folder is locked (E_APPLY_LOCKED; a locked block exits 1, E_APPLY_LOCKED_BLOCK); 7 the source is too large; 9 rate limited (HTTP 429) after the CLI's retries: wait a minute and run it again. Nothing was written, unless the message says the apply was saved and only its --deploy was limited (a limited --run exits 1); 10 (busy, retry) another sim command is using --dir, or the workspace directory it is a workflow folder of (SOURCE_DIR_BUSY): nothing was read or written, run it again once the other finished; 13 not logged in, the login expired, or the server refused the credential (AUTH_REQUIRED): nothing was sent, run `sim login` (or fix or unset SIM_API_KEY when the key comes from it) and the command again; 14 without --yes and with no terminal to ask: the plan was printed with no errors and nothing was written (run the same command with --yes to apply it); 130 interrupted (Ctrl-C): a write already sent is finished and saved into the directory first, waiting up to 60s for its answer, and a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written and how to check. API request and response schemas: [applyWorkflowSource](/api-reference/workflows/applyWorkflowSource), [deployWorkflow](/api-reference/workflows/deployWorkflow), [getWorkflowDeployment](/api-reference/workflows/getWorkflowDeployment), [getSourceResources](/api-reference/workflows/getSourceResources), [executeWorkflow](/api-reference/workflows/executeWorkflowV2). diff --git a/apps/docs/openapi-v2-workflows.json b/apps/docs/openapi-v2-workflows.json index baa318608ea..361a1ae1552 100644 --- a/apps/docs/openapi-v2-workflows.json +++ b/apps/docs/openapi-v2-workflows.json @@ -6065,7 +6065,7 @@ "post": { "operationId": "applyWorkflowSource", "summary": "Apply workflow source", - "description": "Write TypeScript workflow source to the saved draft in one all-or-nothing write. Send the files, lock and `base` from Get Workflow Source with your edits. Requires workspace write access. The live deployment is unchanged.\n\nThe server compiles the files and checks them against the same rules as canvas and operation edits. Any error returns `400` with `details.code` `SOURCE_REJECTED` and `details.diagnostics` (each with a file, line and column), and nothing is saved; a source over a size limit (`E_LIMIT_EXCEEDED`) gets the same body with `413`. A `409` means the draft changed since the source was read (`details.currentFingerprint`): get the source again, reapply the edit and retry. A rename onto a name another workflow in the folder took meanwhile returns `409` with `details.code` `SOURCE_NAME_TAKEN`. A `base.workflowId` that names another workflow is refused with `400` (`E_APPLY_WORKFLOW_MISMATCH`). Locked blocks cannot be changed from source. Unchanged blocks keep their ids and stored values, renamed blocks keep their ids, and existing blocks keep their canvas positions. Source that matches the draft returns `applied: false` without saving. The response re-prints the saved source with its new lock and `base`. `dry=true` runs every check without saving and answers `200` with the findings in `diagnostics`, a stale `base` included (`E_APPLY_STALE`). A request refused before the source is evaluated is refused on a dry run too: `400` for an invalid body, `413` for a body over the size limit, and `423` for a locked workflow or folder. Returns `403` while workflows as code is not enabled. Workspace API keys return `403`; use a personal API key or scoped OAuth token.\n\nOAuth scope: `api:write`.", + "description": "Write TypeScript workflow source to the saved draft in one all-or-nothing write. Send the files, lock and `base` from Get Workflow Source with your edits. Requires workspace write access. The live deployment is unchanged.\n\nThe server compiles the files and checks them against the same rules as canvas and operation edits. Any error returns `400` with `details.code` `SOURCE_REJECTED` and `details.diagnostics` (each with a file, line and column), and nothing is saved; a source over a size limit (`E_LIMIT_EXCEEDED`) gets the same body with `413`. A `409` means the draft changed since the source was read (`details.currentFingerprint`): get the source again, reapply the edit and retry. A rename onto a name another workflow in the folder took meanwhile returns `409` with `details.code` `SOURCE_NAME_TAKEN`. A `base.workflowId` that names another workflow is refused with `400` (`E_APPLY_WORKFLOW_MISMATCH`). Locked blocks cannot be changed from source. Unchanged blocks keep their ids and stored values, renamed blocks keep their ids, and existing blocks keep their canvas positions. Source that matches the draft returns `applied: false` and `wroteSourceMeta: false` without saving; source that changes only block names, order or comments returns `applied: false` with `wroteSourceMeta: true`, as those are saved. The response re-prints the saved source with its new lock and `base`. `dry=true` runs every check without saving and answers `200` with the findings in `diagnostics`, a stale `base` included (`E_APPLY_STALE`). A request refused before the source is evaluated is refused on a dry run too: `400` for an invalid body, `413` for a body over the size limit, and `423` for a locked workflow or folder. Returns `403` while workflows as code is not enabled. Workspace API keys return `403`; use a personal API key or scoped OAuth token.\n\nOAuth scope: `api:write`.", "x-sim-operation": "workflows.source.apply", "x-oauth-scope": "api:write", "tags": ["Workflows"], @@ -6094,9 +6094,9 @@ "name": "dry", "in": "query", "required": false, - "description": "Run every check without writing, auditing, or notifying collaborators. Findings, errors included, come back in `diagnostics` with `applied: false` and a `200`, and the files, lock and fingerprint show what a committed apply would store. A request refused before the source is evaluated (an invalid or oversized body, a locked workflow or folder) gets the same status as without `dry`, and a create under a taken name answers `409`.", + "description": "Run every check without writing, auditing, or notifying collaborators. Findings, errors included, come back in `diagnostics` with `applied: false` and a `200`, and the files, lock and fingerprint show what a committed write would store. A request refused before the source is evaluated (an invalid or oversized body, a locked workflow or folder) gets the same status as without `dry`, and a create under a taken name answers `409`.", "schema": { - "description": "Run every check without writing, auditing, or notifying collaborators. Findings, errors included, come back in `diagnostics` with `applied: false` and a `200`, and the files, lock and fingerprint show what a committed apply would store. A request refused before the source is evaluated (an invalid or oversized body, a locked workflow or folder) gets the same status as without `dry`, and a create under a taken name answers `409`.", + "description": "Run every check without writing, auditing, or notifying collaborators. Findings, errors included, come back in `diagnostics` with `applied: false` and a `200`, and the files, lock and fingerprint show what a committed write would store. A request refused before the source is evaluated (an invalid or oversized body, a locked workflow or folder) gets the same status as without `dry`, and a create under a taken name answers `409`.", "type": "boolean" } }, @@ -6104,9 +6104,9 @@ "name": "allowDelete", "in": "query", "required": false, - "description": "Allow the apply to delete blocks and variables the source no longer declares. Without it, an apply that would delete any block is refused with `E_APPLY_BLOCK_DELETE`, and one that would delete any variable with `E_APPLY_VARIABLE_DELETE`, naming them. Ignored when creating a workflow.", + "description": "Allow the apply to delete blocks and variables the source no longer declares. Without it, an apply that would delete any block is refused with `E_APPLY_BLOCK_DELETE`, and one that would delete any variable with `E_APPLY_VARIABLE_DELETE`, naming them.", "schema": { - "description": "Allow the apply to delete blocks and variables the source no longer declares. Without it, an apply that would delete any block is refused with `E_APPLY_BLOCK_DELETE`, and one that would delete any variable with `E_APPLY_VARIABLE_DELETE`, naming them. Ignored when creating a workflow.", + "description": "Allow the apply to delete blocks and variables the source no longer declares. Without it, an apply that would delete any block is refused with `E_APPLY_BLOCK_DELETE`, and one that would delete any variable with `E_APPLY_VARIABLE_DELETE`, naming them.", "type": "boolean" } }, @@ -6192,6 +6192,7 @@ "dry": false, "dryRun": false, "applied": false, + "wroteSourceMeta": false, "diff": { "noop": true, "blocks": { @@ -6390,6 +6391,7 @@ "dry": true, "dryRun": true, "applied": false, + "wroteSourceMeta": false, "diff": { "noop": true, "blocks": { @@ -6477,7 +6479,7 @@ "post": { "operationId": "createWorkflowFromSource", "summary": "Create workflow from source", - "description": "Create a workflow from TypeScript workflow source in one all-or-nothing write. Requires workspace write access. The source is compiled and checked against the same rules as Apply Workflow Source; every block is new. Any error returns `400` with `details.code` `SOURCE_REJECTED` and `details.diagnostics` (each with a file, line and column), and nothing is created; a source over a size limit (`E_LIMIT_EXCEEDED`) gets the same body with `413`. The name defaults to the one in the source's `workflow('…')` call; a name already used in the folder returns `409` with `details.code` `SOURCE_NAME_TAKEN`. The response carries the new `workflowId` and the source re-printed from what was saved, with its lock and `base`, ready for the next apply. The workflow is not deployed. `dry=true` runs every check without creating anything and answers `200` with the findings in `diagnostics`. A request refused before the source is evaluated is refused on a dry run too: `400` for an invalid body, `404` for a missing folder, `413` for a body over the size limit, and `423` for a locked folder. A taken name is checked after the source compiles and answers `409` (`SOURCE_NAME_TAKEN`) on a dry run as on a create. Returns `403` while workflows as code is not enabled. Workspace API keys return `403`; use a personal API key or scoped OAuth token.\n\nOAuth scope: `api:write`.", + "description": "Create a workflow from TypeScript workflow source in one all-or-nothing write. Requires workspace write access. The source is compiled and checked against the same rules as Apply Workflow Source; every block is new. Any error returns `400` with `details.code` `SOURCE_REJECTED` and `details.diagnostics` (each with a file, line and column), and nothing is created; a source over a size limit (`E_LIMIT_EXCEEDED`) gets the same body with `413`. The name defaults to the one in the source's `workflow('…')` call; a name already used in the folder returns `409` with `details.code` `SOURCE_NAME_TAKEN`. A create answers `201` with the new `workflowId` and the source re-printed from what was saved, with its lock and `base`, ready for the next apply. The workflow is not deployed. `dry=true` runs every check without creating anything and answers `200` with the findings in `diagnostics`. A request refused before the source is evaluated is refused on a dry run too: `400` for an invalid body, `404` for a missing folder, `413` for a body over the size limit, and `423` for a locked folder. A taken name is checked after the source compiles and answers `409` (`SOURCE_NAME_TAKEN`) on a dry run as on a create. Returns `403` while workflows as code is not enabled. Workspace API keys return `403`; use a personal API key or scoped OAuth token.\n\nOAuth scope: `api:write`.", "x-sim-operation": "workflows.source.create", "x-oauth-scope": "api:write", "tags": ["Workflows"], @@ -6506,19 +6508,9 @@ "name": "dry", "in": "query", "required": false, - "description": "Run every check without writing, auditing, or notifying collaborators. Findings, errors included, come back in `diagnostics` with `applied: false` and a `200`, and the files, lock and fingerprint show what a committed apply would store. A request refused before the source is evaluated (an invalid or oversized body, a locked workflow or folder) gets the same status as without `dry`, and a create under a taken name answers `409`.", + "description": "Run every check without writing, auditing, or notifying collaborators. Findings, errors included, come back in `diagnostics` with `applied: false` and a `200`, and the files, lock and fingerprint show what a committed write would store. A request refused before the source is evaluated (an invalid or oversized body, a locked workflow or folder) gets the same status as without `dry`, and a create under a taken name answers `409`.", "schema": { - "description": "Run every check without writing, auditing, or notifying collaborators. Findings, errors included, come back in `diagnostics` with `applied: false` and a `200`, and the files, lock and fingerprint show what a committed apply would store. A request refused before the source is evaluated (an invalid or oversized body, a locked workflow or folder) gets the same status as without `dry`, and a create under a taken name answers `409`.", - "type": "boolean" - } - }, - { - "name": "allowDelete", - "in": "query", - "required": false, - "description": "Allow the apply to delete blocks and variables the source no longer declares. Without it, an apply that would delete any block is refused with `E_APPLY_BLOCK_DELETE`, and one that would delete any variable with `E_APPLY_VARIABLE_DELETE`, naming them. Ignored when creating a workflow.", - "schema": { - "description": "Allow the apply to delete blocks and variables the source no longer declares. Without it, an apply that would delete any block is refused with `E_APPLY_BLOCK_DELETE`, and one that would delete any variable with `E_APPLY_VARIABLE_DELETE`, naming them. Ignored when creating a workflow.", + "description": "Run every check without writing, auditing, or notifying collaborators. Findings, errors included, come back in `diagnostics` with `applied: false` and a `200`, and the files, lock and fingerprint show what a committed write would store. A request refused before the source is evaluated (an invalid or oversized body, a locked workflow or folder) gets the same status as without `dry`, and a create under a taken name answers `409`.", "type": "boolean" } }, @@ -6559,7 +6551,95 @@ }, "responses": { "200": { - "description": "The created (or evaluated) workflow.", + "description": "The evaluated workflow of a dry run; nothing was created.", + "headers": { + "X-RateLimit-Limit": { + "$ref": "#/components/headers/X-RateLimit-Limit" + }, + "X-RateLimit-Remaining": { + "$ref": "#/components/headers/X-RateLimit-Remaining" + }, + "X-RateLimit-Reset": { + "$ref": "#/components/headers/X-RateLimit-Reset" + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreateWorkflowFromSourceDryRunResponse" + }, + "examples": { + "example1": { + "summary": "Response example 1", + "value": { + "data": { + "workflowId": "3b1f7c92-8d4e-4a6b-9c0d-5e2f8a714b36", + "workspaceId": "a91c4b2e-6d3f-4e8a-b5c7-0d9e2f1a8c64", + "dry": true, + "dryRun": true, + "applied": false, + "wroteSourceMeta": false, + "diff": { + "noop": false, + "blocks": { + "added": [ + { + "id": "a3f1c0b2-7a44-4c1d-9d3a-2b8e5f0a1c77", + "key": "start", + "type": "start_trigger" + } + ], + "removed": [], + "renamed": [], + "modified": [] + }, + "edges": { + "added": 0, + "removed": 0 + }, + "variables": { + "added": [], + "removed": [], + "renamed": [], + "modified": [] + } + }, + "diagnostics": [], + "files": { + "workflow.ts": "// @sim-sdk 1\nimport { trigger, workflow } from '@sim/workflow-sdk'\n\nexport default workflow('Support triage', () => {\n const start = trigger.start('Start')\n})\n" + }, + "lock": { + "version": 1, + "blocks": { + "start": { + "id": "a3f1c0b2-7a44-4c1d-9d3a-2b8e5f0a1c77", + "parent": null, + "ident": "start", + "order": 0 + } + }, + "variables": {} + }, + "base": { + "version": 1, + "workflowId": "3b1f7c92-8d4e-4a6b-9c0d-5e2f8a714b36", + "workspaceId": "a91c4b2e-6d3f-4e8a-b5c7-0d9e2f1a8c64", + "fingerprint": "sf1:9c1d4e7f0a3b6c9d2e5f8a1b4c7d0e3f6a9b2c5d8e1f4a7b0c3d6e9f2a5b8c1d", + "catalogHash": "3f0c1a9e5b7d2c4f6a8e0b1d3c5f7a9e2b4d6f8a0c2e4b6d8f0a2c4e6b8d0f2a" + }, + "mintedIds": {}, + "notes": [], + "deployedVersion": null, + "needsRedeployment": false + } + } + } + } + } + } + }, + "201": { + "description": "The created workflow.", "headers": { "X-RateLimit-Limit": { "$ref": "#/components/headers/X-RateLimit-Limit" @@ -6586,6 +6666,7 @@ "dry": false, "dryRun": false, "applied": true, + "wroteSourceMeta": true, "diff": { "noop": false, "blocks": { @@ -17923,7 +18004,7 @@ "description": "Enter the draft run through a runnable trigger." }, "blockId": { - "description": "Runnable trigger block to enter through. Omit only when the saved workflow has exactly one runnable trigger.", + "description": "Runnable trigger block to enter through: its id, display name or reference key (the name lowercased, whitespace and dots removed). Omit only when the saved workflow has exactly one runnable trigger.", "type": "string", "minLength": 1 }, @@ -20020,6 +20101,10 @@ "type": "boolean", "description": "True when the draft was written or the workflow renamed or redescribed; false on a dry run and on a no-op." }, + "wroteSourceMeta": { + "type": "boolean", + "description": "True when the source’s block names, order and comments were saved. With `applied: false`, the source changed only those, so it was saved although the graph did not change; false on a dry run and on a true no-op." + }, "diff": { "type": "object", "properties": { @@ -20687,6 +20772,7 @@ "dry", "dryRun", "applied", + "wroteSourceMeta", "diff", "diagnostics", "files", @@ -20713,6 +20799,7 @@ "dry": false, "dryRun": false, "applied": false, + "wroteSourceMeta": false, "diff": { "noop": true, "blocks": { @@ -21010,6 +21097,10 @@ "type": "boolean", "description": "True when the draft was written or the workflow renamed or redescribed; false on a dry run and on a no-op." }, + "wroteSourceMeta": { + "type": "boolean", + "description": "True when the source’s block names, order and comments were saved. With `applied: false`, the source changed only those, so it was saved although the graph did not change; false on a dry run and on a true no-op." + }, "diff": { "type": "object", "properties": { @@ -21677,6 +21768,7 @@ "dry", "dryRun", "applied", + "wroteSourceMeta", "diff", "diagnostics", "files", @@ -21703,6 +21795,7 @@ "dry": true, "dryRun": true, "applied": false, + "wroteSourceMeta": false, "diff": { "noop": true, "blocks": { @@ -21949,7 +22042,7 @@ "title": "Plan workflow source body", "description": "Edited source files with the lock and base they were read with." }, - "CreateWorkflowFromSourceResponse": { + "CreateWorkflowFromSourceDryRunResponse": { "type": "object", "properties": { "data": { @@ -21976,6 +22069,792 @@ "type": "boolean", "description": "True when the draft was written or the workflow renamed or redescribed; false on a dry run and on a no-op." }, + "wroteSourceMeta": { + "type": "boolean", + "description": "True when the source’s block names, order and comments were saved. With `applied: false`, the source changed only those, so it was saved although the graph did not change; false on a dry run and on a true no-op." + }, + "diff": { + "type": "object", + "properties": { + "noop": { + "type": "boolean", + "description": "True when the source matches the saved draft." + }, + "meta": { + "description": "The workflow name and description fields the source changes.", + "type": "array", + "items": { + "type": "string", + "enum": ["name", "description"] + } + }, + "blocks": { + "type": "object", + "properties": { + "added": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "Stored block id." + }, + "key": { + "type": "string", + "description": "Block key in the source." + }, + "type": { + "type": "string", + "description": "Block type." + } + }, + "required": ["id", "key", "type"], + "additionalProperties": false, + "description": "An added or removed block by id, source key and type." + }, + "description": "New blocks." + }, + "removed": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "Stored block id." + }, + "key": { + "type": "string", + "description": "Block key in the source." + }, + "type": { + "type": "string", + "description": "Block type." + } + }, + "required": ["id", "key", "type"], + "additionalProperties": false, + "description": "An added or removed block by id, source key and type." + }, + "description": "Deleted blocks." + }, + "renamed": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "Stored block id; unchanged by the rename." + }, + "from": { + "type": "string", + "description": "Previous key." + }, + "to": { + "type": "string", + "description": "New key." + } + }, + "required": ["id", "from", "to"], + "additionalProperties": false, + "description": "A renamed block." + }, + "description": "Renamed blocks; each keeps its id." + }, + "modified": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "Stored block id." + }, + "key": { + "type": "string", + "description": "Block key in the source." + }, + "fields": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Changed fields, modes (`modes.`) and attributes." + }, + "reparented": { + "description": "Moved into or out of a container.", + "type": "boolean" + } + }, + "required": ["id", "key", "fields"], + "additionalProperties": false, + "description": "A changed block." + }, + "description": "Changed blocks." + } + }, + "required": ["added", "removed", "renamed", "modified"], + "additionalProperties": false, + "description": "Block changes." + }, + "edges": { + "type": "object", + "properties": { + "added": { + "type": "integer", + "minimum": -9007199254740991, + "maximum": 9007199254740991, + "description": "Connections added." + }, + "removed": { + "type": "integer", + "minimum": -9007199254740991, + "maximum": 9007199254740991, + "description": "Connections removed." + } + }, + "required": ["added", "removed"], + "additionalProperties": false, + "description": "Connection changes." + }, + "variables": { + "type": "object", + "properties": { + "added": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Variable keys added." + }, + "removed": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Variable keys removed." + }, + "renamed": { + "type": "array", + "items": { + "type": "object", + "properties": { + "from": { + "type": "string", + "description": "Former key." + }, + "to": { + "type": "string", + "description": "New key." + } + }, + "required": ["from", "to"], + "additionalProperties": false, + "description": "A renamed variable." + }, + "description": "Variables renamed; each keeps its id, so none is deleted." + }, + "modified": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Variable keys changed." + } + }, + "required": ["added", "removed", "renamed", "modified"], + "additionalProperties": false, + "description": "Variable changes." + } + }, + "required": ["noop", "blocks", "edges", "variables"], + "additionalProperties": false, + "description": "What the apply changed, or would change on a dry run." + }, + "diagnostics": { + "type": "array", + "items": { + "type": "object", + "properties": { + "code": { + "type": "string", + "enum": [ + "E_SYNTAX", + "E_SDK_HEADER", + "E_SDK_MAJOR", + "E_UNSUPPORTED_SYNTAX", + "E_WORKFLOW_EXPORT", + "E_LIMIT_EXCEEDED", + "E_INVALID_CHARACTER", + "E_NUMBER_NOT_FINITE", + "W_NUMBER_PRECISION", + "E_TOO_MANY_ERRORS", + "I_FINDINGS_TRUNCATED", + "E_DUPLICATE_NAME", + "E_RESERVED_NAME", + "E_KEY_OVERRIDE", + "E_EMPTY_NAME", + "E_LOOKALIKE_NAME", + "W_LOOKALIKE_NAME", + "W_SUSPICIOUS_CHARACTER", + "E_NAME_NOT_LITERAL", + "E_UNKNOWN_IDENTIFIER", + "E_OUT_OF_SCOPE", + "E_UNKNOWN_VARIABLE", + "E_DUPLICATE_VARIABLE", + "E_VARIABLE_NAME_MISMATCH", + "E_INVALID_ENV_NAME", + "W_ENV_UNKNOWN", + "W_CHILD_INPUT_UNKNOWN", + "W_CHILD_NO_START", + "W_CHILD_RESULT_PATH", + "E_UNKNOWN_SUBFLOW_PROPERTY", + "W_FORWARD_REF", + "W_REF_NOT_NORMALIZED", + "E_REF_UNREPRESENTABLE", + "W_REF_OUT_OF_SCOPE", + "E_EDGE_SCOPE", + "E_EDGE_NOTE", + "E_TARGET_TRIGGER", + "E_NO_DEFAULT_OUTPUT", + "E_DUPLICATE_EDGE", + "E_ERROR_PORT_UNSUPPORTED", + "W_ERROR_PORT_STORED", + "E_UNKNOWN_BRANCH", + "E_DUPLICATE_BRANCH_KEY", + "E_BRANCH_KEY_COLLIDES", + "E_BRANCH_ELSE_LAST", + "W_RAW_HANDLE", + "W_SUBFLOW_HANDLE_SCOPE", + "E_EDGE_CYCLE", + "W_EDGE_CYCLE", + "W_BRANCH_UNWIRED", + "E_UNKNOWN_BUILDER", + "E_UNKNOWN_PARAM", + "E_FIXED_PARAM", + "W_FIELD_NOT_APPLICABLE", + "W_REQUIRED_MISSING", + "W_UNKNOWN_OPTION", + "E_UNKNOWN_OPERATION", + "W_UNKNOWN_MODEL", + "W_LEGACY_BLOCK_TYPE", + "W_UNKNOWN_BLOCK_TYPE", + "W_TYPE_NOT_ADDABLE", + "I_SCHEDULE_UTC", + "E_STORED_VALUE_MISSING", + "W_VALUE_KIND", + "W_OUT_OF_RANGE", + "W_TABLE_FILTER_SHAPE", + "W_LITERAL_SECRET", + "W_SUBFLOW_COUNT", + "W_UNKNOWN_OUTPUT_PATH", + "W_OUTPUT_PATH_UNDECLARED", + "W_JSON_REF_UNTYPED", + "W_LOOP_CONDITION_SYNTAX", + "E_CODE_FILE_MISSING", + "E_CODE_FILE_PATH", + "W_CODE_FILE_INLINED", + "W_CODE_FILE_REF_SYNTAX", + "W_CODE_FILE_REF_QUOTED", + "W_UNRESOLVED_REF", + "W_FORWARD_REF_LITERALIZED", + "W_COMMENT_MOVED", + "W_COMMENT_DROPPED", + "E_LOCK_JSON", + "E_LOCK_VERSION", + "E_LOCK_SHAPE", + "E_LOCK_UNKNOWN_FIELD", + "E_LOCK_KEY", + "E_LOCK_IDENT", + "E_LOCK_DUPLICATE_IDENT", + "E_LOCK_DUPLICATE_ID", + "E_LOCK_PARENT", + "E_LOCK_BRANCH", + "E_LOCK_CODE_FILE_PATH", + "E_SOURCE_META_JSON", + "E_SOURCE_META_VERSION", + "E_SOURCE_META_SHAPE", + "E_SOURCE_META_UNKNOWN_FIELD", + "E_SOURCE_META_IDENT", + "E_SOURCE_META_DUPLICATE_IDENT", + "E_SOURCE_META_ANCHOR", + "E_CANON_LEGACY_NAME_COLLISION", + "E_CANON_EDGE_SCOPE", + "W_CANON_RESERVED_NAME", + "W_CANON_DANGLING_EDGE", + "W_CANON_DANGLING_PARENT", + "W_CANON_RAW_HANDLE", + "W_CANON_UNKNOWN_BLOCK_TYPE", + "W_CANON_UNRESOLVED_ID", + "W_CANON_TITLE_OVERRIDE", + "W_CANON_SUBFLOW_REPAIRED", + "W_CANON_SUBBLOCK_TYPE_DRIFT", + "W_CANON_UNDECODABLE_JSON", + "E_MAT_DUPLICATE_LOCK_ID", + "E_MAT_UNKNOWN_RESOURCE", + "E_MAT_UNKNOWN_VARIABLE", + "W_MAT_DELETED_SINCE_PULL", + "W_MAT_INFERRED_RENAME", + "W_MAT_RETYPE_RECREATED", + "W_MAT_LOCK_ID_CLAIMED", + "I_MAT_NEEDS_LAYOUT", + "E_APPLY_STALE", + "E_APPLY_WORKFLOW_MISMATCH", + "E_APPLY_LOCKED_BLOCK", + "E_APPLY_TYPE_NOT_ADDABLE", + "E_APPLY_INVALID_STATE", + "E_APPLY_BLOCK_NOT_FOUND", + "E_APPLY_INVALID_BLOCK_TYPE", + "E_APPLY_BLOCK_NOT_ALLOWED", + "E_APPLY_MODEL_NOT_ALLOWED", + "E_APPLY_TOOL_NOT_ALLOWED", + "E_APPLY_INVALID_EDGE_SOURCE", + "E_APPLY_INVALID_EDGE_SCOPE", + "E_APPLY_INVALID_SOURCE_HANDLE", + "E_APPLY_INVALID_TARGET_HANDLE", + "E_APPLY_INVALID_SUBBLOCK_FIELD", + "E_APPLY_MISSING_REQUIRED_PARAMS", + "E_APPLY_RETRY_NOT_SUPPORTED", + "E_APPLY_DUPLICATE_TRIGGER", + "E_APPLY_DUPLICATE_SINGLE_INSTANCE_BLOCK", + "E_APPLY_DISABLED_ANCESTOR", + "E_APPLY_CREDENTIAL_UNREACHABLE", + "W_APPLY_CREDENTIAL_KEPT", + "E_APPLY_SANDBOX_PLAN_REQUIRED", + "W_APPLY_HOSTED_KEY_DROPPED", + "W_APPLY_VALUE_NORMALIZED", + "W_APPLY_TYPE_CHANGED", + "W_APPLY_TRIGGER_REMOVED", + "W_APPLY_CATALOG_MOVED", + "W_APPLY_PROBABLE_RENAME", + "E_APPLY_LINT", + "E_APPLY_UNRESOLVED_REF", + "E_APPLY_REF_OUT_OF_SCOPE", + "E_APPLY_CODE_FILE_REF_SYNTAX", + "E_APPLY_LOOP_CONDITION_SYNTAX", + "W_APPLY_LINT", + "W_TABLE_UNKNOWN_COLUMN", + "E_APPLY_INVALID_SCHEDULE", + "E_APPLY_BLOCK_DELETE", + "E_APPLY_VARIABLE_DELETE", + "E_NAME_TAKEN", + "E_WORKFLOW_META_INVALID", + "E_TYPE", + "W_TYPES_UNCHECKED" + ], + "description": "Diagnostic code, e.g. `E_UNKNOWN_PARAM` or `E_APPLY_LOCKED_BLOCK`." + }, + "severity": { + "type": "string", + "enum": ["error", "warning", "info"], + "description": "Diagnostic severity." + }, + "message": { + "type": "string", + "description": "What was found." + }, + "hint": { + "description": "How to address it.", + "type": "string" + }, + "blockKey": { + "description": "Block the finding is about.", + "type": "string" + }, + "param": { + "description": "Field the finding is about.", + "type": "string" + }, + "file": { + "description": "Submitted file the finding is in.", + "type": "string" + }, + "line": { + "description": "1-based line in `file`.", + "type": "integer", + "minimum": -9007199254740991, + "maximum": 9007199254740991 + }, + "column": { + "description": "1-based column in `file`.", + "type": "integer", + "minimum": -9007199254740991, + "maximum": 9007199254740991 + }, + "endLine": { + "description": "1-based line the finding ends on.", + "type": "integer", + "minimum": -9007199254740991, + "maximum": 9007199254740991 + }, + "endColumn": { + "description": "1-based column the finding ends at.", + "type": "integer", + "minimum": -9007199254740991, + "maximum": 9007199254740991 + }, + "frame": { + "description": "The source lines around the finding, with a caret row.", + "type": "string" + }, + "blockId": { + "description": "Stored id of the block the finding is about.", + "type": "string" + }, + "path": { + "description": "JSON Pointer into the lock, for a lock finding.", + "type": "string" + } + }, + "required": ["code", "severity", "message"], + "additionalProperties": false, + "description": "A finding from applying workflow source, pinned to the submitted files." + }, + "description": "Warnings, and on a dry run every error a commit would refuse." + }, + "files": { + "type": "object", + "propertyNames": { + "type": "string" + }, + "additionalProperties": { + "type": "string" + }, + "description": "The source re-printed from what was saved, including any normalized values." + }, + "lock": { + "type": "object", + "properties": { + "version": { + "type": "number", + "const": 1, + "description": "Lock format version." + }, + "blocks": { + "description": "Block key → identity.", + "type": "object", + "propertyNames": { + "type": "string" + }, + "additionalProperties": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "Block id." + }, + "parent": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "description": "Key of the enclosing loop or parallel, or null." + }, + "branches": { + "description": "Condition or router branch key → stored branch id.", + "type": "object", + "propertyNames": { + "type": "string" + }, + "additionalProperties": { + "type": "string" + } + }, + "items": { + "description": "Per field, its id-bearing items (input format fields) in stored order.", + "type": "object", + "propertyNames": { + "type": "string" + }, + "additionalProperties": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "Item name." + }, + "id": { + "type": "string", + "description": "Item id." + } + }, + "required": ["name", "id"], + "additionalProperties": false, + "description": "One id-bearing list item." + } + } + }, + "ident": { + "type": "string", + "description": "The `const` name the block is printed as." + }, + "order": { + "type": "integer", + "minimum": -9007199254740991, + "maximum": 9007199254740991, + "description": "Declaration-order tie-break." + }, + "layout": { + "type": "object", + "properties": { + "x": { + "type": "number", + "description": "Canvas x position." + }, + "y": { + "type": "number", + "description": "Canvas y position." + }, + "w": { + "description": "Container width.", + "type": "number" + }, + "h": { + "description": "Container height.", + "type": "number" + }, + "height": { + "description": "Stored block height.", + "type": "number" + }, + "horizontalHandles": { + "description": "Handles on the left and right.", + "type": "boolean" + } + }, + "required": ["x", "y"], + "additionalProperties": { + "description": "An `x-` extension field, kept verbatim." + }, + "description": "Stored canvas geometry; applied only to new blocks." + }, + "codeFile": { + "description": "Path of the block’s function-code file.", + "type": "string" + } + }, + "required": ["id", "parent", "ident", "order"], + "additionalProperties": { + "description": "An `x-` extension field, kept verbatim." + }, + "description": "One block’s identity." + } + }, + "variables": { + "description": "Variable key → variable id.", + "type": "object", + "propertyNames": { + "type": "string" + }, + "additionalProperties": { + "type": "string" + } + } + }, + "required": ["version", "blocks", "variables"], + "additionalProperties": { + "description": "An `x-` extension field, kept verbatim." + }, + "description": "Identity sidecar (`.sim/lock.json`): binds the keys in the source to stored ids." + }, + "base": { + "type": "object", + "properties": { + "version": { + "type": "number", + "const": 1, + "description": "Base format version." + }, + "workflowId": { + "type": "string", + "minLength": 1, + "description": "Workflow the source was read from; an apply to another workflow is refused." + }, + "workspaceId": { + "type": "string", + "description": "Workspace the workflow belongs to." + }, + "fingerprint": { + "type": "string", + "minLength": 1, + "maxLength": 256, + "description": "Freshness token of the draft the source was read at: a hash of the canonical workflow and its ids. It ignores canvas positions, so moving blocks does not change it." + }, + "catalogHash": { + "type": "string", + "description": "Hash of the block catalog the source was printed against." + } + }, + "required": ["version", "workflowId", "workspaceId", "fingerprint", "catalogHash"], + "additionalProperties": { + "description": "An `x-` extension field, kept verbatim." + }, + "description": "Where the saved (or, on a dry run, would-be) draft was read: the next apply’s `base`." + }, + "mintedIds": { + "type": "object", + "propertyNames": { + "type": "string" + }, + "additionalProperties": { + "type": "string" + }, + "description": "Block key → id for new blocks whose id was minted rather than taken from the lock." + }, + "notes": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Non-fatal notes about the write." + }, + "deployedVersion": { + "anyOf": [ + { + "type": "integer", + "exclusiveMinimum": 0, + "maximum": 9007199254740991 + }, + { + "type": "null" + } + ], + "description": "The live deployment version `needsRedeployment` compares the draft against, or null when the workflow is not deployed." + }, + "needsRedeployment": { + "type": "boolean", + "description": "Whether the draft now differs from the live deployment; apply never deploys. False when nothing is deployed, so read it beside `deployedVersion`." + } + }, + "required": [ + "workflowId", + "workspaceId", + "dry", + "dryRun", + "applied", + "wroteSourceMeta", + "diff", + "diagnostics", + "files", + "lock", + "base", + "mintedIds", + "notes", + "deployedVersion", + "needsRedeployment" + ], + "additionalProperties": false, + "description": "Response data." + } + }, + "required": ["data"], + "additionalProperties": false, + "title": "Create workflow from source dry run response", + "description": "What a create would store, and every finding; nothing was created.", + "examples": [ + { + "data": { + "workflowId": "3b1f7c92-8d4e-4a6b-9c0d-5e2f8a714b36", + "workspaceId": "a91c4b2e-6d3f-4e8a-b5c7-0d9e2f1a8c64", + "dry": true, + "dryRun": true, + "applied": false, + "wroteSourceMeta": false, + "diff": { + "noop": false, + "blocks": { + "added": [ + { + "id": "a3f1c0b2-7a44-4c1d-9d3a-2b8e5f0a1c77", + "key": "start", + "type": "start_trigger" + } + ], + "removed": [], + "renamed": [], + "modified": [] + }, + "edges": { + "added": 0, + "removed": 0 + }, + "variables": { + "added": [], + "removed": [], + "renamed": [], + "modified": [] + } + }, + "diagnostics": [], + "files": { + "workflow.ts": "// @sim-sdk 1\nimport { trigger, workflow } from '@sim/workflow-sdk'\n\nexport default workflow('Support triage', () => {\n const start = trigger.start('Start')\n})\n" + }, + "lock": { + "version": 1, + "blocks": { + "start": { + "id": "a3f1c0b2-7a44-4c1d-9d3a-2b8e5f0a1c77", + "parent": null, + "ident": "start", + "order": 0 + } + }, + "variables": {} + }, + "base": { + "version": 1, + "workflowId": "3b1f7c92-8d4e-4a6b-9c0d-5e2f8a714b36", + "workspaceId": "a91c4b2e-6d3f-4e8a-b5c7-0d9e2f1a8c64", + "fingerprint": "sf1:9c1d4e7f0a3b6c9d2e5f8a1b4c7d0e3f6a9b2c5d8e1f4a7b0c3d6e9f2a5b8c1d", + "catalogHash": "3f0c1a9e5b7d2c4f6a8e0b1d3c5f7a9e2b4d6f8a0c2e4b6d8f0a2c4e6b8d0f2a" + }, + "mintedIds": {}, + "notes": [], + "deployedVersion": null, + "needsRedeployment": false + } + } + ] + }, + "CreateWorkflowFromSourceResponse": { + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "workflowId": { + "type": "string", + "description": "Workflow id." + }, + "workspaceId": { + "type": "string", + "description": "Workspace id." + }, + "dry": { + "type": "boolean", + "description": "True when nothing was written because `dry` was set." + }, + "dryRun": { + "type": "boolean", + "deprecated": true, + "description": "Deprecated name of `dry`, always sent with the same value. Read `dry`." + }, + "applied": { + "type": "boolean", + "description": "True when the draft was written or the workflow renamed or redescribed; false on a dry run and on a no-op." + }, + "wroteSourceMeta": { + "type": "boolean", + "description": "True when the source’s block names, order and comments were saved. With `applied: false`, the source changed only those, so it was saved although the graph did not change; false on a dry run and on a true no-op." + }, "diff": { "type": "object", "properties": { @@ -22643,6 +23522,7 @@ "dry", "dryRun", "applied", + "wroteSourceMeta", "diff", "diagnostics", "files", @@ -22660,7 +23540,7 @@ "required": ["data"], "additionalProperties": false, "title": "Create workflow from source response", - "description": "The outcome, with the source re-printed from the saved workflow.", + "description": "The created workflow, with the source re-printed from what was saved.", "examples": [ { "data": { @@ -22669,6 +23549,7 @@ "dry": false, "dryRun": false, "applied": true, + "wroteSourceMeta": true, "diff": { "noop": false, "blocks": { diff --git a/apps/sim/app/api/v2/workflows/[workflowId]/source/route.test.ts b/apps/sim/app/api/v2/workflows/[workflowId]/source/route.test.ts index 6099966ae95..02bf35a2312 100644 --- a/apps/sim/app/api/v2/workflows/[workflowId]/source/route.test.ts +++ b/apps/sim/app/api/v2/workflows/[workflowId]/source/route.test.ts @@ -188,6 +188,7 @@ const applied = { workspaceId: WORKSPACE_ID, dryRun: false, applied: true, + wroteSourceMeta: true, diff: { noop: false, blocks: { @@ -395,6 +396,20 @@ describe('POST /api/v2/workflows/{workflowId}/source', () => { expect(mocks.apply).not.toHaveBeenCalled() }) + it('answers a source that changed only names, order or comments as saved, with no graph change', async () => { + mocks.apply.mockResolvedValue({ + ...applied, + applied: false, + wroteSourceMeta: true, + diff: { ...applied.diff, noop: true, blocks: { ...applied.diff.blocks, modified: [] } }, + }) + + const response = await POST(applyRequest(applyBody), context) + + expect(response.status).toBe(200) + expect((await response.json()).data).toMatchObject({ applied: false, wroteSourceMeta: true }) + }) + it('passes dry through as a boolean', async () => { mocks.apply.mockResolvedValue({ ...applied, dryRun: true, applied: false }) diff --git a/apps/sim/app/api/v2/workspaces/[workspaceId]/workflows/source/route.test.ts b/apps/sim/app/api/v2/workspaces/[workspaceId]/workflows/source/route.test.ts index 027fdfff54e..f5c2eb1d36c 100644 --- a/apps/sim/app/api/v2/workspaces/[workspaceId]/workflows/source/route.test.ts +++ b/apps/sim/app/api/v2/workspaces/[workspaceId]/workflows/source/route.test.ts @@ -47,6 +47,7 @@ const created = { workspaceId: WORKSPACE_ID, dryRun: false, applied: true, + wroteSourceMeta: true, diff: { noop: false, blocks: { @@ -100,13 +101,13 @@ describe('POST /api/v2/workspaces/{workspaceId}/workflows/source', () => { mocks.create.mockResolvedValue(created) }) - it('creates in the workspace named by the path and returns the new id, files and lock', async () => { + it('creates in the workspace named by the path and answers 201 with the new id, files and lock', async () => { const response = await POST( createRequest({ files, name: 'Triage', folderPath: 'Ops' }), context ) - expect(response.status).toBe(200) + expect(response.status).toBe(201) expect(mocks.create.mock.calls[0][0].input).toEqual({ workspaceId: WORKSPACE_ID, files, @@ -178,7 +179,7 @@ describe('POST /api/v2/workspaces/{workspaceId}/workflows/source', () => { expect(refused.status).toBe(429) expect(refused.headers.get('Retry-After')).toBe('5') expect((await refused.json()).error.code).toBe('RATE_LIMITED') - expect((await POST(createRequest({ files }), context)).status).toBe(200) + expect((await POST(createRequest({ files }), context)).status).toBe(201) for (const done of finish) done() expect((await Promise.all(running)).map((response) => response.status)).toEqual([ @@ -186,6 +187,13 @@ describe('POST /api/v2/workspaces/{workspaceId}/workflows/source', () => { ]) }) + it('refuses allowDelete, which a create has no blocks to apply to, and creates nothing', async () => { + const response = await POST(createRequest({ files }, '?allowDelete=true'), context) + + expect(response.status).toBe(400) + expect(mocks.create).not.toHaveBeenCalled() + }) + it('passes dry through', async () => { mocks.create.mockResolvedValue({ ...created, dryRun: true, applied: false }) diff --git a/apps/sim/app/api/v2/workspaces/[workspaceId]/workflows/source/route.ts b/apps/sim/app/api/v2/workspaces/[workspaceId]/workflows/source/route.ts index c9eb75fbf26..a80bad9129e 100644 --- a/apps/sim/app/api/v2/workspaces/[workspaceId]/workflows/source/route.ts +++ b/apps/sim/app/api/v2/workspaces/[workspaceId]/workflows/source/route.ts @@ -15,11 +15,11 @@ export const revalidate = 0 /** * POST /api/v2/workspaces/[workspaceId]/workflows/source — creates a workflow from TypeScript - * source through the same pipeline and checks as an apply, in one all-or-nothing write. Error - * diagnostics answer 400 and nothing is created; a dry run answers 200 with its diagnostics and - * creates nothing. Answers 403 while the `workflow-code` flag is off. Charged and admitted as an - * apply is (`v2RateLimits.sourceApply`): a real create shares the source-write budget and the - * apply slots, and a dry run the source-plan budget and the plan slots. + * source through the same pipeline and checks as an apply, in one all-or-nothing write: a create + * answers 201. Error diagnostics answer 400 and nothing is created; a dry run answers 200 with its + * diagnostics and creates nothing. Answers 403 while the `workflow-code` flag is off. Charged and + * admitted as an apply is (`v2RateLimits.sourceApply`): a real create shares the source-write + * budget and the apply slots, and a dry run the source-plan budget and the plan slots. */ export const POST = defineV2JsonRoute({ contract: v2CreateWorkflowFromSourceContract, @@ -39,4 +39,5 @@ export const POST = defineV2JsonRoute({ }), useCase: withSourceSlot(createWorkflowFromSource, applyOrDryRunLane), present: (result) => ({ data: presentSourceOutcome(result) }), + statusForResult: ({ dryRun, applied }) => (!dryRun && applied ? 201 : 200), }) diff --git a/apps/sim/lib/api/contracts/v2/openapi/workflow-source.ts b/apps/sim/lib/api/contracts/v2/openapi/workflow-source.ts index d1a09326ce9..20b7dee9b20 100644 --- a/apps/sim/lib/api/contracts/v2/openapi/workflow-source.ts +++ b/apps/sim/lib/api/contracts/v2/openapi/workflow-source.ts @@ -44,6 +44,82 @@ const WORKFLOW_SOURCE_EXAMPLE = { diagnostics: [], } +const createdFromSourceResponse = documentedSchema( + v2CreateWorkflowFromSourceContract.response.schema, + 'CreateWorkflowFromSourceResponse', + 'Create workflow from source response', + 'The created workflow, with the source re-printed from what was saved.', + [ + { + data: { + workflowId: WORKFLOW_SOURCE_EXAMPLE.workflowId, + workspaceId: WORKFLOW_SOURCE_EXAMPLE.workspaceId, + dry: false, + dryRun: false, + applied: true, + wroteSourceMeta: true, + diff: { + noop: false, + blocks: { + added: [{ id: BLOCK_ID, key: 'start', type: 'start_trigger' }], + removed: [], + renamed: [], + modified: [], + }, + edges: { added: 0, removed: 0 }, + variables: { added: [], removed: [], renamed: [], modified: [] }, + }, + diagnostics: [], + files: WORKFLOW_SOURCE_EXAMPLE.files, + lock: WORKFLOW_SOURCE_EXAMPLE.lock, + base: WORKFLOW_SOURCE_EXAMPLE.base, + mintedIds: { start: BLOCK_ID }, + notes: [], + deployedVersion: null, + needsRedeployment: false, + }, + }, + ] +) + +const createFromSourceDryRunResponse = documentedSchema( + v2CreateWorkflowFromSourceContract.response.schema, + 'CreateWorkflowFromSourceDryRunResponse', + 'Create workflow from source dry run response', + 'What a create would store, and every finding; nothing was created.', + [ + { + data: { + workflowId: WORKFLOW_SOURCE_EXAMPLE.workflowId, + workspaceId: WORKFLOW_SOURCE_EXAMPLE.workspaceId, + dry: true, + dryRun: true, + applied: false, + wroteSourceMeta: false, + diff: { + noop: false, + blocks: { + added: [{ id: BLOCK_ID, key: 'start', type: 'start_trigger' }], + removed: [], + renamed: [], + modified: [], + }, + edges: { added: 0, removed: 0 }, + variables: { added: [], removed: [], renamed: [], modified: [] }, + }, + diagnostics: [], + files: WORKFLOW_SOURCE_EXAMPLE.files, + lock: WORKFLOW_SOURCE_EXAMPLE.lock, + base: WORKFLOW_SOURCE_EXAMPLE.base, + mintedIds: {}, + notes: [], + deployedVersion: null, + needsRedeployment: false, + }, + }, + ] +) + export const workflowSourceOpenApiRoutes = [ defineOpenApiRoute( v2GetWorkflowSourceContract, @@ -79,7 +155,7 @@ export const workflowSourceOpenApiRoutes = [ applicationOperation: workflowOperations.applySource, operationId: 'applyWorkflowSource', summary: 'Apply workflow source', - description: `Write TypeScript workflow source to the saved draft in one all-or-nothing write. Send the files, lock and \`base\` from Get Workflow Source with your edits. Requires workspace write access. The live deployment is unchanged.\n\nThe server compiles the files and checks them against the same rules as canvas and operation edits. Any error returns \`400\` with \`details.code\` \`SOURCE_REJECTED\` and \`details.diagnostics\` (each with a file, line and column), and nothing is saved; a source over a size limit (\`E_LIMIT_EXCEEDED\`) gets the same body with \`413\`. A \`409\` means the draft changed since the source was read (\`details.currentFingerprint\`): get the source again, reapply the edit and retry. A rename onto a name another workflow in the folder took meanwhile returns \`409\` with \`details.code\` \`SOURCE_NAME_TAKEN\`. A \`base.workflowId\` that names another workflow is refused with \`400\` (\`E_APPLY_WORKFLOW_MISMATCH\`). Locked blocks cannot be changed from source. Unchanged blocks keep their ids and stored values, renamed blocks keep their ids, and existing blocks keep their canvas positions. Source that matches the draft returns \`applied: false\` without saving. The response re-prints the saved source with its new lock and \`base\`. \`dry=true\` runs every check without saving and answers \`200\` with the findings in \`diagnostics\`, a stale \`base\` included (\`E_APPLY_STALE\`). A request refused before the source is evaluated is refused on a dry run too: \`400\` for an invalid body, \`413\` for a body over the size limit, and \`423\` for a locked workflow or folder. Returns \`403\` while workflows as code is not enabled. ${WORKSPACE_API_KEY_DENIED}`, + description: `Write TypeScript workflow source to the saved draft in one all-or-nothing write. Send the files, lock and \`base\` from Get Workflow Source with your edits. Requires workspace write access. The live deployment is unchanged.\n\nThe server compiles the files and checks them against the same rules as canvas and operation edits. Any error returns \`400\` with \`details.code\` \`SOURCE_REJECTED\` and \`details.diagnostics\` (each with a file, line and column), and nothing is saved; a source over a size limit (\`E_LIMIT_EXCEEDED\`) gets the same body with \`413\`. A \`409\` means the draft changed since the source was read (\`details.currentFingerprint\`): get the source again, reapply the edit and retry. A rename onto a name another workflow in the folder took meanwhile returns \`409\` with \`details.code\` \`SOURCE_NAME_TAKEN\`. A \`base.workflowId\` that names another workflow is refused with \`400\` (\`E_APPLY_WORKFLOW_MISMATCH\`). Locked blocks cannot be changed from source. Unchanged blocks keep their ids and stored values, renamed blocks keep their ids, and existing blocks keep their canvas positions. Source that matches the draft returns \`applied: false\` and \`wroteSourceMeta: false\` without saving; source that changes only block names, order or comments returns \`applied: false\` with \`wroteSourceMeta: true\`, as those are saved. The response re-prints the saved source with its new lock and \`base\`. \`dry=true\` runs every check without saving and answers \`200\` with the findings in \`diagnostics\`, a stale \`base\` included (\`E_APPLY_STALE\`). A request refused before the source is evaluated is refused on a dry run too: \`400\` for an invalid body, \`413\` for a body over the size limit, and \`423\` for a locked workflow or folder. Returns \`403\` while workflows as code is not enabled. ${WORKSPACE_API_KEY_DENIED}`, tags: ['Workflows'], errors: [...RESOURCE_MUTATION_ERRORS, 'PayloadTooLarge'], success: { description: 'The applied (or evaluated) source.', headers: RATE_LIMIT_HEADERS }, @@ -118,6 +194,7 @@ export const workflowSourceOpenApiRoutes = [ dry: false, dryRun: false, applied: false, + wroteSourceMeta: false, diff: { noop: true, blocks: { added: [], removed: [], renamed: [], modified: [] }, @@ -183,6 +260,7 @@ export const workflowSourceOpenApiRoutes = [ dry: true, dryRun: true, applied: false, + wroteSourceMeta: false, diff: { noop: true, blocks: { added: [], removed: [], renamed: [], modified: [] }, @@ -209,10 +287,18 @@ export const workflowSourceOpenApiRoutes = [ applicationOperation: workflowOperations.createFromSource, operationId: 'createWorkflowFromSource', summary: 'Create workflow from source', - description: `Create a workflow from TypeScript workflow source in one all-or-nothing write. Requires workspace write access. The source is compiled and checked against the same rules as Apply Workflow Source; every block is new. Any error returns \`400\` with \`details.code\` \`SOURCE_REJECTED\` and \`details.diagnostics\` (each with a file, line and column), and nothing is created; a source over a size limit (\`E_LIMIT_EXCEEDED\`) gets the same body with \`413\`. The name defaults to the one in the source's \`workflow('…')\` call; a name already used in the folder returns \`409\` with \`details.code\` \`SOURCE_NAME_TAKEN\`. The response carries the new \`workflowId\` and the source re-printed from what was saved, with its lock and \`base\`, ready for the next apply. The workflow is not deployed. \`dry=true\` runs every check without creating anything and answers \`200\` with the findings in \`diagnostics\`. A request refused before the source is evaluated is refused on a dry run too: \`400\` for an invalid body, \`404\` for a missing folder, \`413\` for a body over the size limit, and \`423\` for a locked folder. A taken name is checked after the source compiles and answers \`409\` (\`SOURCE_NAME_TAKEN\`) on a dry run as on a create. Returns \`403\` while workflows as code is not enabled. ${WORKSPACE_API_KEY_DENIED}`, + description: `Create a workflow from TypeScript workflow source in one all-or-nothing write. Requires workspace write access. The source is compiled and checked against the same rules as Apply Workflow Source; every block is new. Any error returns \`400\` with \`details.code\` \`SOURCE_REJECTED\` and \`details.diagnostics\` (each with a file, line and column), and nothing is created; a source over a size limit (\`E_LIMIT_EXCEEDED\`) gets the same body with \`413\`. The name defaults to the one in the source's \`workflow('…')\` call; a name already used in the folder returns \`409\` with \`details.code\` \`SOURCE_NAME_TAKEN\`. A create answers \`201\` with the new \`workflowId\` and the source re-printed from what was saved, with its lock and \`base\`, ready for the next apply. The workflow is not deployed. \`dry=true\` runs every check without creating anything and answers \`200\` with the findings in \`diagnostics\`. A request refused before the source is evaluated is refused on a dry run too: \`400\` for an invalid body, \`404\` for a missing folder, \`413\` for a body over the size limit, and \`423\` for a locked folder. A taken name is checked after the source compiles and answers \`409\` (\`SOURCE_NAME_TAKEN\`) on a dry run as on a create. Returns \`403\` while workflows as code is not enabled. ${WORKSPACE_API_KEY_DENIED}`, tags: ['Workflows'], errors: [...RESOURCE_MUTATION_ERRORS, 'PayloadTooLarge'], - success: { description: 'The created (or evaluated) workflow.', headers: RATE_LIMIT_HEADERS }, + success: { + byStatus: { + 200: { + description: 'The evaluated workflow of a dry run; nothing was created.', + headers: RATE_LIMIT_HEADERS, + }, + 201: { description: 'The created workflow.', headers: RATE_LIMIT_HEADERS }, + }, + }, }, { params: documentedSchema( @@ -234,42 +320,8 @@ export const workflowSourceOpenApiRoutes = [ 'Source files and where to create the workflow.', [{ files: WORKFLOW_SOURCE_EXAMPLE.files, folderPath: '/Operations' }] ), - response: documentedSchema( - v2CreateWorkflowFromSourceContract.response.schema, - 'CreateWorkflowFromSourceResponse', - 'Create workflow from source response', - 'The outcome, with the source re-printed from the saved workflow.', - [ - { - data: { - workflowId: WORKFLOW_SOURCE_EXAMPLE.workflowId, - workspaceId: WORKFLOW_SOURCE_EXAMPLE.workspaceId, - dry: false, - dryRun: false, - applied: true, - diff: { - noop: false, - blocks: { - added: [{ id: BLOCK_ID, key: 'start', type: 'start_trigger' }], - removed: [], - renamed: [], - modified: [], - }, - edges: { added: 0, removed: 0 }, - variables: { added: [], removed: [], renamed: [], modified: [] }, - }, - diagnostics: [], - files: WORKFLOW_SOURCE_EXAMPLE.files, - lock: WORKFLOW_SOURCE_EXAMPLE.lock, - base: WORKFLOW_SOURCE_EXAMPLE.base, - mintedIds: { start: BLOCK_ID }, - notes: [], - deployedVersion: null, - needsRedeployment: false, - }, - }, - ] - ), + response: createdFromSourceResponse, + responses: { 200: createFromSourceDryRunResponse, 201: createdFromSourceResponse }, } ), ] diff --git a/apps/sim/lib/api/contracts/v2/workflow-source.ts b/apps/sim/lib/api/contracts/v2/workflow-source.ts index e5b77bada1a..10dc649bd2d 100644 --- a/apps/sim/lib/api/contracts/v2/workflow-source.ts +++ b/apps/sim/lib/api/contracts/v2/workflow-source.ts @@ -27,18 +27,20 @@ export const v2GetWorkflowSourceContract = defineRouteContract({ response: { mode: 'json', schema: v2DataResponse(workflowSourceSchema) }, }) +const sourceWriteDrySchema = booleanQueryFlagSchema + .optional() + .describe( + 'Run every check without writing, auditing, or notifying collaborators. Findings, errors included, come back in `diagnostics` with `applied: false` and a `200`, and the files, lock and fingerprint show what a committed write would store. A request refused before the source is evaluated (an invalid or oversized body, a locked workflow or folder) gets the same status as without `dry`, and a create under a taken name answers `409`.' + ) + const applyWorkflowSourceQuerySchema = foldDeprecatedName( z .object({ - dry: booleanQueryFlagSchema - .optional() - .describe( - 'Run every check without writing, auditing, or notifying collaborators. Findings, errors included, come back in `diagnostics` with `applied: false` and a `200`, and the files, lock and fingerprint show what a committed apply would store. A request refused before the source is evaluated (an invalid or oversized body, a locked workflow or folder) gets the same status as without `dry`, and a create under a taken name answers `409`.' - ), + dry: sourceWriteDrySchema, allowDelete: booleanQueryFlagSchema .optional() .describe( - 'Allow the apply to delete blocks and variables the source no longer declares. Without it, an apply that would delete any block is refused with `E_APPLY_BLOCK_DELETE`, and one that would delete any variable with `E_APPLY_VARIABLE_DELETE`, naming them. Ignored when creating a workflow.' + 'Allow the apply to delete blocks and variables the source no longer declares. Without it, an apply that would delete any block is refused with `E_APPLY_BLOCK_DELETE`, and one that would delete any variable with `E_APPLY_VARIABLE_DELETE`, naming them.' ), dryRun: deprecatedRequestName('dry', booleanQueryFlagSchema.optional()), }) @@ -47,6 +49,18 @@ const applyWorkflowSourceQuerySchema = foldDeprecatedName( 'dry' ) +/** A create has no blocks to delete, so it takes only `dry` (and its deprecated `dryRun`). */ +const createWorkflowFromSourceQuerySchema = foldDeprecatedName( + z + .object({ + dry: sourceWriteDrySchema, + dryRun: deprecatedRequestName('dry', booleanQueryFlagSchema.optional()), + }) + .strict(), + 'dryRun', + 'dry' +) + /** Longest path a source file may have, in a workflow's source and in a workspace's alike. */ export const SOURCE_PATH_MAX_LENGTH = 1024 @@ -247,6 +261,11 @@ const applyWorkflowSourceDataSchema = z .describe( 'True when the draft was written or the workflow renamed or redescribed; false on a dry run and on a no-op.' ), + wroteSourceMeta: z + .boolean() + .describe( + 'True when the source’s block names, order and comments were saved. With `applied: false`, the source changed only those, so it was saved although the graph did not change; false on a dry run and on a true no-op.' + ), diff: sourceDiffSchema, diagnostics: z .array(sourceDiagnosticSchema) @@ -350,6 +369,8 @@ const createWorkflowFromSourceBodySchema = z }) .strict() +const createWorkflowFromSourceResponseSchema = v2DataResponse(applyWorkflowSourceDataSchema) + /** * `POST /api/v2/workspaces/{workspaceId}/workflows/source`: create a workflow from TypeScript * source, through the same checks as an apply. @@ -358,7 +379,16 @@ export const v2CreateWorkflowFromSourceContract = defineRouteContract({ method: 'POST', path: '/api/v2/workspaces/[workspaceId]/workflows/source', params: createWorkflowFromSourceParamsSchema, - query: applyWorkflowSourceQuerySchema, + query: createWorkflowFromSourceQuerySchema, body: createWorkflowFromSourceBodySchema, - response: { mode: 'json', schema: v2DataResponse(applyWorkflowSourceDataSchema) }, + response: { + mode: 'json', + status: [200, 201], + schema: createWorkflowFromSourceResponseSchema, + // One shape for both: a dry run (200) and a create (201) are documented with their own examples. + statusSchemas: { + 200: createWorkflowFromSourceResponseSchema, + 201: createWorkflowFromSourceResponseSchema, + }, + }, }) diff --git a/apps/sim/lib/api/contracts/v2/workflows.ts b/apps/sim/lib/api/contracts/v2/workflows.ts index 0f041130394..6a4ac5b3a33 100644 --- a/apps/sim/lib/api/contracts/v2/workflows.ts +++ b/apps/sim/lib/api/contracts/v2/workflows.ts @@ -1679,7 +1679,7 @@ export const v2WorkflowRunSelectionSchema = z.discriminatedUnion('source', [ .min(1, 'run.entry.blockId cannot be empty') .optional() .describe( - 'Runnable trigger block to enter through. Omit only when the saved workflow has exactly one runnable trigger.' + 'Runnable trigger block to enter through: its id, display name or reference key (the name lowercased, whitespace and dots removed). Omit only when the saved workflow has exactly one runnable trigger.' ), sample: z .boolean() diff --git a/apps/sim/lib/api/mcp/generated/v2-operations.ts b/apps/sim/lib/api/mcp/generated/v2-operations.ts index 25c348145e4..eabb3cf51dc 100644 --- a/apps/sim/lib/api/mcp/generated/v2-operations.ts +++ b/apps/sim/lib/api/mcp/generated/v2-operations.ts @@ -487,7 +487,7 @@ export const V2_MCP_OPERATIONS = { contract: v2ApplyWorkflowSourceContract, summary: 'Apply workflow source', description: - 'Write TypeScript workflow source to the saved draft in one all-or-nothing write. Send the files, lock and `base` from Get Workflow Source with your edits. Requires workspace write access. The live deployment is unchanged.\n\nThe server compiles the files and checks them against the same rules as canvas and operation edits. Any error returns `400` with `details.code` `SOURCE_REJECTED` and `details.diagnostics` (each with a file, line and column), and nothing is saved; a source over a size limit (`E_LIMIT_EXCEEDED`) gets the same body with `413`. A `409` means the draft changed since the source was read (`details.currentFingerprint`): get the source again, reapply the edit and retry. A rename onto a name another workflow in the folder took meanwhile returns `409` with `details.code` `SOURCE_NAME_TAKEN`. A `base.workflowId` that names another workflow is refused with `400` (`E_APPLY_WORKFLOW_MISMATCH`). Locked blocks cannot be changed from source. Unchanged blocks keep their ids and stored values, renamed blocks keep their ids, and existing blocks keep their canvas positions. Source that matches the draft returns `applied: false` without saving. The response re-prints the saved source with its new lock and `base`. `dry=true` runs every check without saving and answers `200` with the findings in `diagnostics`, a stale `base` included (`E_APPLY_STALE`). A request refused before the source is evaluated is refused on a dry run too: `400` for an invalid body, `413` for a body over the size limit, and `423` for a locked workflow or folder. Returns `403` while workflows as code is not enabled. Workspace API keys return `403`; use a personal API key or scoped OAuth token.\n\nOAuth scope: `api:write`.', + 'Write TypeScript workflow source to the saved draft in one all-or-nothing write. Send the files, lock and `base` from Get Workflow Source with your edits. Requires workspace write access. The live deployment is unchanged.\n\nThe server compiles the files and checks them against the same rules as canvas and operation edits. Any error returns `400` with `details.code` `SOURCE_REJECTED` and `details.diagnostics` (each with a file, line and column), and nothing is saved; a source over a size limit (`E_LIMIT_EXCEEDED`) gets the same body with `413`. A `409` means the draft changed since the source was read (`details.currentFingerprint`): get the source again, reapply the edit and retry. A rename onto a name another workflow in the folder took meanwhile returns `409` with `details.code` `SOURCE_NAME_TAKEN`. A `base.workflowId` that names another workflow is refused with `400` (`E_APPLY_WORKFLOW_MISMATCH`). Locked blocks cannot be changed from source. Unchanged blocks keep their ids and stored values, renamed blocks keep their ids, and existing blocks keep their canvas positions. Source that matches the draft returns `applied: false` and `wroteSourceMeta: false` without saving; source that changes only block names, order or comments returns `applied: false` with `wroteSourceMeta: true`, as those are saved. The response re-prints the saved source with its new lock and `base`. `dry=true` runs every check without saving and answers `200` with the findings in `diagnostics`, a stale `base` included (`E_APPLY_STALE`). A request refused before the source is evaluated is refused on a dry run too: `400` for an invalid body, `413` for a body over the size limit, and `423` for a locked workflow or folder. Returns `403` while workflows as code is not enabled. Workspace API keys return `403`; use a personal API key or scoped OAuth token.\n\nOAuth scope: `api:write`.', workspaceKeyUnsupported: true, handler: () => import('@/app/api/v2/workflows/[workflowId]/source/route').then((route) => route.POST), @@ -1002,7 +1002,7 @@ export const V2_MCP_OPERATIONS = { contract: v2CreateWorkflowFromSourceContract, summary: 'Create workflow from source', description: - "Create a workflow from TypeScript workflow source in one all-or-nothing write. Requires workspace write access. The source is compiled and checked against the same rules as Apply Workflow Source; every block is new. Any error returns `400` with `details.code` `SOURCE_REJECTED` and `details.diagnostics` (each with a file, line and column), and nothing is created; a source over a size limit (`E_LIMIT_EXCEEDED`) gets the same body with `413`. The name defaults to the one in the source's `workflow('…')` call; a name already used in the folder returns `409` with `details.code` `SOURCE_NAME_TAKEN`. The response carries the new `workflowId` and the source re-printed from what was saved, with its lock and `base`, ready for the next apply. The workflow is not deployed. `dry=true` runs every check without creating anything and answers `200` with the findings in `diagnostics`. A request refused before the source is evaluated is refused on a dry run too: `400` for an invalid body, `404` for a missing folder, `413` for a body over the size limit, and `423` for a locked folder. A taken name is checked after the source compiles and answers `409` (`SOURCE_NAME_TAKEN`) on a dry run as on a create. Returns `403` while workflows as code is not enabled. Workspace API keys return `403`; use a personal API key or scoped OAuth token.\n\nOAuth scope: `api:write`.", + "Create a workflow from TypeScript workflow source in one all-or-nothing write. Requires workspace write access. The source is compiled and checked against the same rules as Apply Workflow Source; every block is new. Any error returns `400` with `details.code` `SOURCE_REJECTED` and `details.diagnostics` (each with a file, line and column), and nothing is created; a source over a size limit (`E_LIMIT_EXCEEDED`) gets the same body with `413`. The name defaults to the one in the source's `workflow('…')` call; a name already used in the folder returns `409` with `details.code` `SOURCE_NAME_TAKEN`. A create answers `201` with the new `workflowId` and the source re-printed from what was saved, with its lock and `base`, ready for the next apply. The workflow is not deployed. `dry=true` runs every check without creating anything and answers `200` with the findings in `diagnostics`. A request refused before the source is evaluated is refused on a dry run too: `400` for an invalid body, `404` for a missing folder, `413` for a body over the size limit, and `423` for a locked folder. A taken name is checked after the source compiles and answers `409` (`SOURCE_NAME_TAKEN`) on a dry run as on a create. Returns `403` while workflows as code is not enabled. Workspace API keys return `403`; use a personal API key or scoped OAuth token.\n\nOAuth scope: `api:write`.", workspaceKeyUnsupported: true, handler: () => import('@/app/api/v2/workspaces/[workspaceId]/workflows/source/route').then( diff --git a/apps/sim/lib/workflows/api/source-presenters.ts b/apps/sim/lib/workflows/api/source-presenters.ts index fa8e9e14b0a..301bb3c88c3 100644 --- a/apps/sim/lib/workflows/api/source-presenters.ts +++ b/apps/sim/lib/workflows/api/source-presenters.ts @@ -9,8 +9,8 @@ type SourceOutcomeData = ContractJsonResponse { expect(mocks.executeService).not.toHaveBeenCalled() }) + it('enters through a trigger named by its display name or reference key, not only its id', async () => { + mocks.resolveOptions.mockReturnValue([ + triggerOption, + { ...triggerOption, triggerBlockId: 'trigger-2', blockName: 'Nightly Digest' }, + ]) + + for (const selector of ['Nightly Digest', 'nightlydigest']) { + await executeManualWorkflowOperation.execute({ + principal, + input: { ...baseInput, triggerBlockId: selector, sample: false }, + }) + expect(mocks.executeService).toHaveBeenLastCalledWith( + expect.objectContaining({ triggerBlockId: 'trigger-2' }) + ) + } + }) + + it('refuses a trigger selector naming no runnable trigger, listing the triggers', async () => { + await expect( + executeManualWorkflowOperation.execute({ + principal, + input: { ...baseInput, triggerBlockId: 'Nightly', sample: false }, + }) + ).rejects.toMatchObject({ + code: 'validation', + message: expect.stringContaining('Valid triggers: trigger-1 (Slack Trigger)'), + }) + expect(mocks.executeService).not.toHaveBeenCalled() + }) + it('rejects input combined with the sample payload before loading saved state', async () => { await expect( executeManualWorkflowOperation.execute({ diff --git a/apps/sim/lib/workflows/application/execute-manual-workflow.ts b/apps/sim/lib/workflows/application/execute-manual-workflow.ts index 6f89b140596..809a599972b 100644 --- a/apps/sim/lib/workflows/application/execute-manual-workflow.ts +++ b/apps/sim/lib/workflows/application/execute-manual-workflow.ts @@ -1,5 +1,6 @@ import { requirePrincipalSubjectUserId, type WorkflowExecutionPrincipal } from '@sim/auth/principal' import { mergeSubblockStateWithValues } from '@sim/workflow-persistence/subblocks' +import { normalizeWorkflowBlockName } from '@sim/workflow-types/workflow' import { OrchestrationError } from '@/lib/core/orchestration/types' import { inlinesRunFiles, @@ -120,10 +121,31 @@ function resolveStopAfterBlock( return blockId } -function listTriggers(options: ReturnType): string { +type TriggerRunOptions = ReturnType + +function listTriggers(options: TriggerRunOptions): string { return options.map((option) => `${option.triggerBlockId} (${option.blockName})`).join(', ') } +/** + * The runnable trigger `selector` names: its block id, else its display name or reference key + * ("Nightly" and `nightly`), as a block selector names any block. One naming no runnable trigger, + * or several, is refused with the triggers to choose from. + */ +function selectTrigger(options: TriggerRunOptions, selector: string): TriggerRunOptions[number] { + const byId = options.find((option) => option.triggerBlockId === selector) + if (byId) return byId + const key = normalizeWorkflowBlockName(selector) + const named = options.filter((option) => normalizeWorkflowBlockName(option.blockName) === key) + if (named.length === 1) return named[0] + throw new OrchestrationError( + 'validation', + named.length > 1 + ? `run.entry.blockId "${selector}" names ${named.length} runnable triggers: ${listTriggers(named)}. Pass one of their ids.` + : `run.entry.blockId "${selector}" is not a runnable trigger in the saved workflow. Valid triggers: ${listTriggers(options)}.` + ) +} + async function executionServiceInput(params: { principal: WorkflowExecutionPrincipal context: Awaited> @@ -189,18 +211,11 @@ export const executeManualWorkflowOperation = defineAuthorizedWorkflowUseCase({ let selected = options[0] if (input.triggerBlockId) { - const explicit = options.find((option) => option.triggerBlockId === input.triggerBlockId) - if (!explicit) { - throw new OrchestrationError( - 'validation', - `run.entry.blockId "${input.triggerBlockId}" is not a runnable trigger in the saved workflow. Valid triggers: ${listTriggers(options)}.` - ) - } - selected = explicit + selected = selectTrigger(options, input.triggerBlockId) } else if (options.length > 1) { throw new OrchestrationError( 'validation', - `This workflow has multiple runnable triggers. Pass run.entry.blockId to choose one: ${listTriggers(options)}.` + `This workflow has multiple runnable triggers. Choose one with run.entry.blockId, by its id or name: ${listTriggers(options)}.` ) } diff --git a/apps/sim/scripts/test-workflow-source-apply-e2e.ts b/apps/sim/scripts/test-workflow-source-apply-e2e.ts index 9091f23732d..319c5cb35ff 100644 --- a/apps/sim/scripts/test-workflow-source-apply-e2e.ts +++ b/apps/sim/scripts/test-workflow-source-apply-e2e.ts @@ -366,11 +366,12 @@ async function main() { await check('creating from source writes a new workflow with fresh ids', async () => { const source = await readSource(workflowId) - const { data } = await request('POST', createPath, { - files: source.files, - name: copyName, - provenance: { client: 'api' }, - }) + const { data } = await request( + 'POST', + createPath, + { files: source.files, name: copyName, provenance: { client: 'api' } }, + 201 + ) const result = record(data) assert.equal(result.applied, true) const newId = String(result.workflowId) diff --git a/packages/sim-cli/src/commands/protocol/source-exit-codes.ts b/packages/sim-cli/src/commands/protocol/source-exit-codes.ts index 57fc092e4e1..122b7669b6e 100644 --- a/packages/sim-cli/src/commands/protocol/source-exit-codes.ts +++ b/packages/sim-cli/src/commands/protocol/source-exit-codes.ts @@ -179,9 +179,9 @@ export function sourceExitCodeRows(prefix: SourceCommandGroup): SourceExitCodeRo next: 'Wait a minute and run the same command again', help: { 'workflows source apply': - "rate limited (HTTP 429) after the CLI's retries, so nothing was written: wait a minute and run it again", + "rate limited (HTTP 429) after the CLI's retries: wait a minute and run it again. Nothing was written, unless the message says the apply was saved and only its --deploy was limited (a limited --run exits 1)", 'workflows source create': - "rate limited (HTTP 429) after the CLI's retries, so nothing was created: wait a minute and run it again", + "rate limited (HTTP 429) after the CLI's retries: wait a minute and run it again. Nothing was created, unless the message says the create was saved and only its --deploy was limited (a limited --run exits 1)", 'workflows source get': "rate limited (HTTP 429) after the CLI's retries: wait a minute and run it again", 'workflows source status': diff --git a/packages/sim-cli/src/commands/protocol/source-ui.ts b/packages/sim-cli/src/commands/protocol/source-ui.ts index bd8864c4c84..3b1836be5c0 100644 --- a/packages/sim-cli/src/commands/protocol/source-ui.ts +++ b/packages/sim-cli/src/commands/protocol/source-ui.ts @@ -15,6 +15,7 @@ import { type FlatDiagnostic, refusalClass } from '@sim/workspace-code' import type { Command } from 'commander' import { annotationLine, annotationPath, printAnnotations } from '#sim-cli/output/github-actions' import { printError } from '#sim-cli/output/io' +import type { NextStep } from '#sim-cli/output/next-step' import { askLine } from '#sim-cli/terminal/line-input' import { isMachineFormat, type OutputFormat } from '../../config/index' import { embedStore, setSoftExitCode } from '../../embed-context' @@ -427,7 +428,8 @@ const DETAILS_REFERENCE = / See details\.diagnostics\.$/ * refusal's details with each finding as a success result carries it ({@link resultDiagnostics}); * a display format prints the findings once, above the error, and `verbose` keeps info findings in * the machine document as it does in a result. `ifAnswerLost` is the next step for a write whose - * answer never came back, appended to its message. + * answer never came back, appended to its message; `ifStale` the one for a stale refusal + * (`SOURCE_STALE`), appended to its message and kept as `details.next`. */ export function printRefusal( error: unknown, @@ -437,9 +439,10 @@ export function printRefusal( verbose?: boolean /** The `--folder` a create named, which the server answers "Folder not found" for. */ folder?: string + ifStale?: NextStep } = {} ): never { - const { ifAnswerLost, verbose = false, folder } = options + const { ifAnswerLost, verbose = false, folder, ifStale } = options if (!(error instanceof SimApiError)) throw error const details = toRecord(error.details) const diagnostics = details.diagnostics @@ -451,20 +454,25 @@ export function printRefusal( : error.message.replace(DETAILS_REFERENCE, printed ? ' Each finding is printed above.' : '') const nameTaken = error.status === 409 && details.code === SOURCE_REFUSAL_CODES.nameTaken const folderMissing = folder !== undefined && /\bfolder not found\b/i.test(error.message) + const staleNext = + error.status === 409 && details.code === SOURCE_REFUSAL_CODES.stale ? ifStale : undefined const hint = nameTaken ? 'Pass --name to create it under another name, or apply to that workflow.' : folderMissing ? `Create it with \`sim workflows folders create ${shellWord(folder)}\`, then create the workflow again.` - : ifAnswerLost && answerLost(error) - ? ifAnswerLost - : null + : staleNext + ? `${staleNext.reason} Next: \`${staleNext.command}\`` + : ifAnswerLost && answerLost(error) + ? ifAnswerLost + : null + const kept = printed ? refusalDetails(format, details, diagnostics, verbose) : error.details throw new SimApiError( hint ? `${folderMissing && !/[.!?]$/.test(message) ? `${message}.` : message} ${hint}` : message, error.status, error.code, - printed ? refusalDetails(format, details, diagnostics, verbose) : error.details, + staleNext ? { ...toRecord(kept), next: staleNext } : kept, refusalExitCode(error, details.code), error.requestId ) diff --git a/packages/sim-cli/src/commands/protocol/workflow-run-follow.test.ts b/packages/sim-cli/src/commands/protocol/workflow-run-follow.test.ts index 4d9c3df00f2..abc7e8ab8e7 100644 --- a/packages/sim-cli/src/commands/protocol/workflow-run-follow.test.ts +++ b/packages/sim-cli/src/commands/protocol/workflow-run-follow.test.ts @@ -305,6 +305,29 @@ describe('sim workflows run --follow', () => { ) }) + it('names --trigger, the flag that chooses a trigger, where the server refuses the choice', async () => { + requestRaw.mockRejectedValue( + new SimApiError( + 'This workflow has multiple runnable triggers. Choose one with run.entry.blockId, by its id or name: b-start (Start), b-nightly (Nightly).', + 400 + ) + ) + + await expect(run(WORKFLOW_ID, '--draft')).rejects.toThrow( + 'This workflow has multiple runnable triggers. Choose one with --trigger, by its id or name: b-start (Start), b-nightly (Nightly).' + ) + }) + + it('keeps run.entry.blockId in a refusal of the --from-block entry, which --trigger does not set', async () => { + const refusal = + 'run.entry.blockId "Score" is not a block in the current saved workflow. Pass a block\'s id, name or key: "Start" (b-start).' + requestRaw.mockRejectedValue(new SimApiError(refusal, 400)) + + await expect( + run(WORKFLOW_ID, '--from-block', 'Score', '--source-run', 'run-1') + ).rejects.toThrow(refusal) + }) + it('lets --trigger and --sample imply --draft', async () => { vi.spyOn(console, 'log').mockImplementation(() => {}) diff --git a/packages/sim-cli/src/commands/protocol/workflow-run-follow.ts b/packages/sim-cli/src/commands/protocol/workflow-run-follow.ts index 97d0ad3de9c..99f97f9fe0c 100644 --- a/packages/sim-cli/src/commands/protocol/workflow-run-follow.ts +++ b/packages/sim-cli/src/commands/protocol/workflow-run-follow.ts @@ -467,14 +467,20 @@ async function sendWaitedRun( flags: Record, workspaceId: string | null, selection: WorkflowRunSelection | undefined, - waitTimeoutSeconds?: number + options: { + waitTimeoutSeconds?: number + /** Resend a `429`: the run is refused at admission, before it starts, so nothing ran. */ + retryRateLimited?: boolean + } = {} ): Promise { + const { waitTimeoutSeconds, retryRateLimited } = options const request = await runRequest(workflowId, flags, workspaceId, selection, true) const response = await client.requestRaw('executeWorkflow', { params: request.params, query: request.query, body: waitTimeoutSeconds === undefined ? request.body : { ...request.body, waitTimeoutSeconds }, headers: { ...request.headers, accept: WORKFLOW_RESULT_STREAM_CONTENT_TYPE }, + retryRateLimited, }) return readWorkflowResult(response) } @@ -530,7 +536,8 @@ async function dryRunDraft( source: 'draft', dry: true, ...(triggerBlockId ? { entry: { type: 'trigger', blockId: triggerBlockId } } : {}), - } + }, + { retryRateLimited: true } ) // A dry run is never detached (it cannot take --wait-timeout); a server that did is reported. if ('detachedRunId' in result) { @@ -572,14 +579,16 @@ export interface DraftTest { failure?: string /** Whether the server refused the run before it started (an input the trigger does not take). */ refused?: boolean + /** Whether the run was still rate limited after the client's resends, so it never started. */ + rateLimited?: boolean } /** * Dry-runs the saved draft of `workflowId` with `input`, through the trigger block * `triggerBlockId` when given, and, when the run does not complete, maps its failure to a line of * `sourceDir` and says why. A run the server refuses (a 400: an input the trigger's fields do not - * match, or no trigger named where the workflow has several) is a test that failed before it - * started, not an error of the write. + * match, or no trigger named where the workflow has several) or still rate limits (a 429 after the + * client's resends) is a test that failed before it started, not an error of the write. */ export async function testRunDraft( client: OperationClient<'executeWorkflow'>, @@ -593,7 +602,16 @@ export async function testRunDraft( try { record = await dryRunDraft(client, workflowId, input, workspaceId, triggerBlockId) } catch (error) { - if (!(error instanceof SimApiError) || error.status !== 400) throw error + if (!(error instanceof SimApiError)) throw error + if (error.status === 429) { + const failure = 'the server rate limited it before it started (HTTP 429)' + return { + run: { runId: null, status: 'failed', error: failure, output: null }, + failure, + rateLimited: true, + } + } + if (error.status !== 400) throw error return { run: { runId: null, status: 'failed', error: error.message, output: null }, failure: `the server refused it before it started: ${error.message}`, @@ -629,14 +647,9 @@ async function runWithResultStream( const commandSpec = CLI_CONTRACT.executeWorkflow ?? {} try { - const result = await sendWaitedRun( - client, - workflowId, - flags, - profile.workspaceId, - selection, - waitTimeoutSeconds - ) + const result = await sendWaitedRun(client, workflowId, flags, profile.workspaceId, selection, { + waitTimeoutSeconds, + }) if ('detachedRunId' in result) { // The server already spent the wait, so the run is read once and reported. const now = Date.now() @@ -964,6 +977,43 @@ async function runWorkflow(workflowId: string, _options: unknown, command: Comma ) } const selection = await resolveWorkflowRunSelection(workflowId, command, initialFlags) + try { + await sendRun(workflowId, command, selection, waitTimeoutSeconds) + } catch (error) { + const entersByTrigger = selection?.source === 'draft' && selection.entry?.type !== 'block' + throw entersByTrigger ? inTriggerFlagTerms(error) : error + } +} + +/** The wire field `--trigger` sets, which a refused trigger choice names. */ +const TRIGGER_FIELD = 'run.entry.blockId' + +/** + * A refused trigger choice (none named where the workflow has several, or one naming no runnable + * trigger) as the flag that makes it: the server names `run.entry.blockId`, which a caller of + * `workflows run` sets with `--trigger`. + */ +function inTriggerFlagTerms(error: unknown): unknown { + if (!(error instanceof SimApiError) || error.status !== 400) return error + if (!error.message.includes(TRIGGER_FIELD)) return error + return new SimApiError( + error.message.replaceAll(TRIGGER_FIELD, '--trigger'), + error.status, + error.code, + error.details, + error.exitCode, + error.requestId + ) +} + +/** Runs, follows or queues the run `selection` makes, as the flags ask. */ +async function sendRun( + workflowId: string, + command: Command, + selection: WorkflowRunSelection | undefined, + waitTimeoutSeconds: number | undefined +): Promise { + const initialFlags = command.optsWithGlobals() as Record const stopBlock = stopBlockSelection(selection, initialFlags) if (stopBlock) command.setOptionValue('selectOutput', stopBlock) const flags = command.optsWithGlobals() as Record @@ -1087,8 +1137,8 @@ export function attachWorkflowRunFollow(workflows: Command): void { "Answer each block a bare --mock names with the output it recorded in this earlier run of the workflow, redacted as the run shows it: this workflow's blocks (not a child's; not inside a loop or parallel unless that run mocked it); fields a mock cannot set, such as cost or model, are left out" ) .option( - '--trigger ', - 'Enter the run through this runnable trigger, by its block id; runs the saved draft (implies --draft)' + '--trigger ', + 'Enter the run through this runnable trigger (its id, display name or key); runs the saved draft (implies --draft)' ) .option( '--sample', diff --git a/packages/sim-cli/src/commands/protocol/workflow-source-apply.test.ts b/packages/sim-cli/src/commands/protocol/workflow-source-apply.test.ts index 4abdc9aca33..57e97950dde 100644 --- a/packages/sim-cli/src/commands/protocol/workflow-source-apply.test.ts +++ b/packages/sim-cli/src/commands/protocol/workflow-source-apply.test.ts @@ -71,6 +71,7 @@ function outcome(overrides: { dry?: boolean; diagnostics?: unknown[]; notes?: st workspaceId: WORKSPACE_ID, dry, applied: !dry, + wroteSourceMeta: false, diff: { noop: false, blocks: { @@ -1226,6 +1227,29 @@ describe('sim workflows source apply', () => { ) }) + it('says a source that changed only names, order or comments was saved, not that nothing changed', async () => { + setTerminal(false) + const renamed = outcome() + renamed.data.applied = false + renamed.data.wroteSourceMeta = true + renamed.data.diff.noop = true + request.mockResolvedValue(renamed) + contextMockFns.mockRequestRaw.mockResolvedValue( + runAnswer({ status: 'failed', error: { message: 'score is not a number' } }) + ) + + await expect(apply(WORKFLOW_ID, '--dir', dir, '--yes', '--run', '{}')).rejects.toThrow( + /^The apply was saved into .*, but the test run failed: score is not a number\. Fix the source/ + ) + expect(stdoutJson()).toMatchObject({ + summary: expect.stringMatching( + /^saved \(names, order or comments only\): no graph changes;/ + ), + applied: false, + wroteSourceMeta: true, + }) + }) + it("prints the run's side effects before the result, so the output still ends with it", async () => { setTerminal(false) contextMockState.output = 'table' @@ -1277,7 +1301,7 @@ describe('sim workflows source apply', () => { path === DEPLOY_PATH ? deployed : path === STATUS_PATH ? liveStatus : twoTriggers() ) const several = - 'This workflow has multiple runnable triggers. Pass run.entry.blockId to choose one: b-api (API), b-hook (Shop Webhook).' + 'This workflow has multiple runnable triggers. Choose one with run.entry.blockId, by its id or name: b-api (API), b-hook (Shop Webhook).' it('names each trigger and the corrected command when a --run names none', async () => { setTerminal(false) @@ -1416,6 +1440,53 @@ describe('sim workflows source apply', () => { }) }) + it('resends a rate-limited --run, and reports one still limited as a failed run of the saved apply', async () => { + setTerminal(false) + serveTwoTriggers() + contextMockFns.mockRequestRaw + .mockResolvedValueOnce(runAnswer({ status: 'completed', output: { source: 'api' } })) + .mockRejectedValueOnce( + new SimApiError( + 'API rate limit exceeded (still limited after 6 retries). Nothing more was sent; wait a minute, then run the command again.', + 429, + 'RATE_LIMITED', + undefined, + 9 + ) + ) + + const error = await apply( + WORKFLOW_ID, + '--dir', + dir, + '--yes', + '--run', + 'api={}', + '--run', + 'shopWebhook={}', + '--deploy' + ).catch((caught: unknown) => caught) + + expect(error).toBeInstanceOf(SimApiError) + expect((error as SimApiError).exitCode).toBe(1) + expect((error as Error).message).toMatch( + /^The apply was saved into .*, but the test run shopWebhook failed: the server rate limited it before it started \(HTTP 429\)\. Nothing was deployed\. Wait a minute, then run `sim workflows source apply --dir .* --run 'api=\{\}' --run 'shopWebhook=\{\}' --deploy --yes`\.$/ + ) + expect( + contextMockFns.mockRequestRaw.mock.calls.map(([, sent]) => sent.retryRateLimited) + ).toEqual([true, true]) + expect(request.mock.calls.map((call) => call[0])).toEqual([APPLY_PATH]) + const result = stdoutJson() + expect(result).toMatchObject({ + runs: [ + { trigger: 'api', status: 'completed' }, + { trigger: 'shopWebhook', status: 'failed' }, + ], + next: { reason: 'runs the tests again once the rate limit allows' }, + }) + expect(String(result.summary)).toContain('shopWebhook failed') + }) + it('keeps the runs that finished when a later --run cannot be sent', async () => { setTerminal(false) serveTwoTriggers() @@ -1725,6 +1796,49 @@ describe('sim workflows source apply', () => { expect(request).not.toHaveBeenCalled() }) + it('after a deploy refused because the draft changed since, names the read of the change, not the same deploy', async () => { + setTerminal(false) + request.mockImplementation(async (path: string) => { + if (path === DEPLOY_PATH) { + throw new SimApiError( + 'The workflow draft changed since it was applied, so it was not deployed. Read it again to review the change, then deploy.', + 409, + 'CONFLICT' + ) + } + return outcome() + }) + + const error = await apply(WORKFLOW_ID, '--dir', dir, '--yes', '--deploy').catch( + (caught: unknown) => caught + ) + + expect(error).toMatchObject({ status: 409, code: 'CONFLICT' }) + const message = (error as Error).message + expect(message).toContain(`The apply was saved into ${dir}`) + expect(message).toContain(`sim workflows source status --dir ${dir}`) + expect(message).toContain(`sim workflows source get ${WORKFLOW_ID} --dir `) + expect(message).not.toContain('--expected-draft-fingerprint') + }) + + it('keeps the pinned deploy for a conflict other than a changed draft', async () => { + setTerminal(false) + request.mockImplementation(async (path: string) => { + if (path === DEPLOY_PATH) { + throw new SimApiError('Webhook path /hooks/orders is already in use.', 409, 'CONFLICT') + } + return outcome() + }) + + const error = await apply(WORKFLOW_ID, '--dir', dir, '--yes', '--deploy').catch( + (caught: unknown) => caught + ) + + expect((error as Error).message).toContain( + `Fix that, then run \`sim workflows deploy ${WORKFLOW_ID} --expected-draft-fingerprint sf1:b\`` + ) + }) + it('says the apply was saved when the deploy after it fails', async () => { setTerminal(false) request.mockImplementation(async (path: string) => { @@ -1747,6 +1861,40 @@ describe('sim workflows source apply', () => { }) }) + it('names the fresh get to redo the edit in when the apply is refused as stale', async () => { + setTerminal(false) + request.mockRejectedValue( + new SimApiError( + 'Workflow "W" changed since this source was read. Get the source again, reapply your edit and retry.', + 409, + 'CONFLICT', + { code: 'SOURCE_STALE', currentFingerprint: 'sf1:z' } + ) + ) + + const error = await apply(WORKFLOW_ID, '--dir', dir, '--yes').catch((caught: unknown) => caught) + + const command = `sim workflows source get ${WORKFLOW_ID} --dir ` + expect(error).toMatchObject({ + exitCode: 5, + details: { code: 'SOURCE_STALE', next: { command } }, + }) + expect((error as Error).message).toContain(`Next: \`${command}\``) + }) + + it('refuses a source over the total size limit before sending it, naming its size', async () => { + setTerminal(false) + writeFileSync(join(dir, 'workflow.ts'), `${ENTRY}//${'x'.repeat(4_000_000)}\n`) + + const error = await apply(WORKFLOW_ID, '--dir', dir, '--yes').catch((caught: unknown) => caught) + + expect(error).toMatchObject({ code: 'E_LIMIT_EXCEEDED', exitCode: 7 }) + expect((error as Error).message).toMatch( + /its files total 4000\d{3} bytes, over the 4000000-byte limit, so nothing was sent/ + ) + expect(request).not.toHaveBeenCalled() + }) + it('exits 5 when a dry run finds the directory stale', async () => { setTerminal(false) request.mockResolvedValue(outcome({ dry: true, diagnostics: [STALE] })) diff --git a/packages/sim-cli/src/commands/protocol/workflow-source-apply.ts b/packages/sim-cli/src/commands/protocol/workflow-source-apply.ts index 7b05c86418f..1da465e933e 100644 --- a/packages/sim-cli/src/commands/protocol/workflow-source-apply.ts +++ b/packages/sim-cli/src/commands/protocol/workflow-source-apply.ts @@ -1,11 +1,12 @@ import { toRecord } from '@sim/utils/object' -import { SOURCE_ENTRY_FILE as ENTRY_FILE } from '@sim/workflow-code/limits' +import { SOURCE_ENTRY_FILE as ENTRY_FILE, sourceFileExcesses } from '@sim/workflow-code/limits' import type { Command } from 'commander' import { publishSummary } from '#sim-cli/output/github-actions' import { printError } from '#sim-cli/output/io' import type { NextStep } from '#sim-cli/output/next-step' import { isMachineFormat } from '../../config/index' import { setSoftExitCode } from '../../embed-context' +import { SOURCE_TOO_LARGE_EXIT_CODE } from '../../exit-codes' import type { ApplyWorkflowSourceBody, ApplyWorkflowSourceResponse, @@ -187,6 +188,8 @@ async function writeWorkflowSource(args: save: (data: SourceApplyData) => Promise /** The next step when the write's answer never came back, so it may have been stored. */ ifAnswerLost: string + /** The next step when the workflow changed since the directory was read (`SOURCE_STALE`). */ + ifStale?: NextStep /** The folder a create puts the workflow in (`--folder`). */ folder?: string /** This write as a command, without `--yes`: what a `plan` run names next with it. */ @@ -200,6 +203,7 @@ async function writeWorkflowSource(args: }): Promise { const { options, creating } = args assertSendableCodeFiles(args.body.files) + assertWithinFileLimits(args.body.files) /** Sends the write (or its dry run); a refusal prints its diagnostics and rethrows. */ const send = async (dry: boolean): Promise => { try { @@ -219,6 +223,7 @@ async function writeWorkflowSource(args: ...(dry ? {} : { ifAnswerLost: args.ifAnswerLost }), verbose: options.verbose === true, ...(args.folder !== undefined ? { folder: args.folder } : {}), + ifStale: args.ifStale, }) } } @@ -328,18 +333,22 @@ async function writeWorkflowSource(args: const failed = outcomes.filter((outcome) => outcome.failure !== undefined) if (failed.length > 0) { const refused = failed.some((outcome) => outcome.refused) + const rateLimited = failed.every((outcome) => outcome.rateLimited) const next = { command: `${args.savedCommand(outcomes.map((outcome) => outcome.next))} --yes`, - reason: refused - ? 'applies again and tests it with your fixed --run input' - : 'applies your fix and tests it again', + reason: rateLimited + ? 'runs the tests again once the rate limit allows' + : refused + ? 'applies again and tests it with your fixed --run input' + : 'applies your fix and tests it again', } report(data, { next }, runs) - const written = data.applied - ? `The ${verb} was saved into ${options.dir}, but` - : `Nothing changed: the draft already matched ${options.dir}, and` + const written = + data.applied || data.wroteSourceMeta + ? `The ${verb} was saved into ${options.dir}, but` + : `Nothing changed: the draft already matched ${options.dir}, and` throw new SimApiError( - `${written} ${failedRunsText(outcomes)}${options.deploy ? ' Nothing was deployed.' : ''} Fix the ${refused ? '--run input' : 'source'}, then run \`${next.command}\`.`, + `${written} ${failedRunsText(outcomes)}${options.deploy ? ' Nothing was deployed.' : ''} ${rateLimited ? 'Wait a minute' : `Fix the ${refused ? '--run input' : 'source'}`}, then run \`${next.command}\`.`, 0 ) } @@ -359,6 +368,23 @@ async function writeWorkflowSource(args: report(data, deployment, runs) } +/** + * Refuses a source over the file-count or total-size limit before it is sent: the server would + * refuse it as `E_LIMIT_EXCEEDED` only after the whole upload. + */ +function assertWithinFileLimits(files: Record): void { + const excesses = sourceFileExcesses(files).map(({ limit, actual, max }) => + limit === 'maxFiles' + ? `it has ${actual} files, over the ${max}-file limit` + : `its files total ${actual} bytes, over the ${max}-byte limit` + ) + if (excesses.length === 0) return + throw new SourceDirError( + `This source is too large to send: ${excesses.join('; ')}, so nothing was sent. Share one code file between blocks, or shorten the code.`, + { code: 'E_LIMIT_EXCEEDED', exitCode: SOURCE_TOO_LARGE_EXIT_CODE } + ) +} + /** * Each run that did not complete, as one sentence: `the test run failed: …` for a lone run, else * each named by its trigger (`the test run api failed: …; the test run #2 …`). @@ -421,8 +447,8 @@ function testRunsClause(runs: readonly NamedTestRun[]): string { function writeOutcome(data: SourceApplyData, creating: boolean, errors: number): string { if (data.dry) return 'plan' if (errors > 0) return 'refused' - if (!data.applied) return 'not applied' - return creating ? 'created' : 'applied' + if (data.applied) return creating ? 'created' : 'applied' + return data.wroteSourceMeta ? 'saved (names, order or comments only)' : 'not applied' } /** @@ -533,7 +559,7 @@ async function deployStep( .then( (response) => response.data, (error: unknown) => { - throw deployFailure(error, options, deployCommand) + throw deployFailure(error, { ...options, workflowId: data.workflowId }, deployCommand) } ) if (draftIsLive(status)) { @@ -560,7 +586,7 @@ async function deployStep( .then( (response) => response.data, (error: unknown) => { - throw deployFailure(error, options, deployCommand) + throw deployFailure(error, { ...options, workflowId: data.workflowId }, deployCommand) } ) if (!options.machine) { @@ -595,15 +621,27 @@ async function deployStep( } } -/** A failed deploy after a saved write, saying the write itself stands and how to deploy it. */ +/** The server's refusal of a deploy whose draft changed since the write it is pinned to. */ +const DRAFT_CHANGED = /draft changed since it was applied/ + +/** + * A failed deploy after a saved write, saying the write itself stands and how to deploy it. A + * deploy refused because the draft changed after the write ({@link DRAFT_CHANGED}) can never + * succeed pinned to it, so the next step reads the change instead; any other failure, another + * 409 included, names the pinned deploy. + */ function deployFailure( error: unknown, - options: { dir: string; verb: string }, + options: { dir: string; verb: string; workflowId: string }, deployCommand: string ): unknown { if (!(error instanceof SimApiError)) return error + const next = + error.status === 409 && DRAFT_CHANGED.test(error.message) + ? `Run \`sim workflows source status --dir ${shellWord(options.dir)}\` to see what changed, or \`sim workflows source get ${options.workflowId} --dir \` to read the draft as it is now, then apply and deploy again.` + : `Fix that, then run \`${deployCommand}\`.` return new SimApiError( - `The ${options.verb} was saved into ${options.dir}, but the deploy failed: ${error.message} Fix that, then run \`${deployCommand}\`.`, + `The ${options.verb} was saved into ${options.dir}, but the deploy failed: ${error.message} ${next}`, error.status, error.code, error.details, @@ -746,6 +784,10 @@ export function attachWorkflowSourceApply(source: Command): void { await writeBack(options.dir, data, lock, { write: edges ? [edges] : [] }) await refreshWorkflowTsconfigs(options.dir, data) }, + ifStale: { + command: `${sim} workflows source get ${workflowId} --dir `, + reason: `The workflow changed since ${options.dir} was read: get it into a fresh directory, carry your edit over, and apply from there.`, + }, ifAnswerLost: `It may have been saved. Run \`${sim} workflows source apply ${workflowId} --dir ${shellWord(options.dir)} --dry\`: exit 5 (stale) means the draft changed since this directory was read, by this apply or by someone else. Run \`${sim} workflows source get ${workflowId} --dir \` and compare it with ${options.dir}: if it holds your edit, \`${sim} workflows source get ${workflowId} --dir ${shellWord(options.dir)} --force\` brings this directory up to date; if not, reapply your edit in the fresh directory. Any other outcome means it was not saved: apply again.`, }) }, @@ -915,6 +957,7 @@ function summarize(data: SourceApplyData, creating: boolean, machine: boolean) { return { ...(creating && !data.applied ? {} : { workflowId: data.workflowId }), applied: data.applied, + ...(data.wroteSourceMeta ? { wroteSourceMeta: true } : {}), dry: data.dry, noop: data.diff.noop, ...(created.length > 0 ? { created } : {}), diff --git a/packages/sim-cli/src/commands/protocol/workspace-source-apply.test.ts b/packages/sim-cli/src/commands/protocol/workspace-source-apply.test.ts index 53b0a150798..89cd61302fd 100644 --- a/packages/sim-cli/src/commands/protocol/workspace-source-apply.test.ts +++ b/packages/sim-cli/src/commands/protocol/workspace-source-apply.test.ts @@ -2479,6 +2479,22 @@ describe('workspaces source apply', () => { }) }) + it('reports a run still rate limited as one to retry after a wait, not a --run input to fix', async () => { + serveApplies() + contextMockFns.mockRequestRaw.mockRejectedValue( + new SimApiError('API rate limit exceeded.', 429, 'RATE_LIMITED', undefined, 9) + ) + + await expect(apply('--yes', '--run', 'ingest={}')).rejects.toThrow( + /but the test run of ingest failed: the server rate limited it before it started \(HTTP 429\)\. deployments\/ was not applied\. Wait a minute, then run `sim workspaces source apply --dir .* --run 'ingest=\{\}' --yes`\.$/ + ) + const printed = JSON.parse(String(vi.mocked(console.log).mock.calls.at(-1)?.[0])) + expect(printed).toMatchObject({ + runs: [{ workflow: 'ingest', status: 'failed', rateLimited: true }], + next: { reason: 'runs the tests again once the rate limit allows' }, + }) + }) + it("prints no workflow finding of the deployments write, which the apply's result drops too", async () => { contextMockState.output = 'table' const finding = (message: string) => ({ diff --git a/packages/sim-cli/src/commands/protocol/workspace-source-apply.ts b/packages/sim-cli/src/commands/protocol/workspace-source-apply.ts index 1992e5b9e97..ba9c439a8b2 100644 --- a/packages/sim-cli/src/commands/protocol/workspace-source-apply.ts +++ b/packages/sim-cli/src/commands/protocol/workspace-source-apply.ts @@ -1068,20 +1068,24 @@ export function attachWorkspaceSourceApply(source: Command): void { await afterWrite(() => testRuns(client, options.dir, workspaceId, data, runs, tested)) const failedRuns = tested.filter((run) => run.status !== 'completed') if (failedRuns.length > 0) { - // A run the server refused before it started has no id: its fix is the --run input. - const refused = failedRuns.some((run) => run.runId === null) + // A run the server refused before it started has no id: its fix is the --run input, + // unless it was only rate limited, which waiting fixes. + const rateLimited = failedRuns.every((run) => run.rateLimited) + const refused = failedRuns.some((run) => run.runId === null && !run.rateLimited) const next = { command: `${applyCommand(options, sim)} --yes`, - reason: refused - ? 'applies again and tests it with your fixed --run input' - : 'applies your fix and tests it again', + reason: rateLimited + ? 'runs the tests again once the rate limit allows' + : refused + ? 'applies again and tests it with your fixed --run input' + : 'applies your fix and tests it again', } await finish(data, next) const why = failedRuns .map((run) => `the test run of ${run.workflow} ${String(run.status)}: ${run.error}`) .join('; ') throw new SimApiError( - `The apply was written into ${options.dir}, but ${why}.${gated ? ' deployments/ was not applied.' : ''} Fix the ${refused ? 'source or the refused --run input' : 'source'}, then run \`${next.command}\`.`, + `The apply was written into ${options.dir}, but ${why}.${gated ? ' deployments/ was not applied.' : ''} ${rateLimited ? 'Wait a minute' : `Fix the ${refused ? 'source or the refused --run input' : 'source'}`}, then run \`${next.command}\`.`, 0 ) } @@ -1300,6 +1304,8 @@ function mergedApply(first: ApplyData, deployed: ApplyData): ApplyData { interface WorkflowTestRun extends TestRun { workflow: string workflowId: string + /** Still rate limited after the client's resends, so it never started. */ + rateLimited?: true } /** The test runs as one display line: `ingest completed; score failed: …`. */ @@ -1353,6 +1359,7 @@ async function testRuns( workflowId, ...test.run, ...(test.failure !== undefined ? { error: test.failure } : {}), + ...(test.rateLimited ? { rateLimited: true as const } : {}), }) } } diff --git a/packages/sim-cli/src/generated/v2-api.ts b/packages/sim-cli/src/generated/v2-api.ts index 3cbf028dd5a..5e6465a8637 100644 --- a/packages/sim-cli/src/generated/v2-api.ts +++ b/packages/sim-cli/src/generated/v2-api.ts @@ -784,6 +784,7 @@ export type ApplyWorkflowSourceResponse = { dry: boolean dryRun: boolean applied: boolean + wroteSourceMeta: boolean diff: { noop: boolean meta?: Array<'name' | 'description'> @@ -5246,7 +5247,6 @@ export type CreateWorkflowFromSourceParams = { export type CreateWorkflowFromSourceQuery = { dry?: boolean - allowDelete?: boolean dryRun?: boolean } @@ -5271,6 +5271,7 @@ export type CreateWorkflowFromSourceResponse = { dry: boolean dryRun: boolean applied: boolean + wroteSourceMeta: boolean diff: { noop: boolean meta?: Array<'name' | 'description'> @@ -14539,6 +14540,7 @@ export type PlanWorkflowSourceResponse = { dry: boolean dryRun: boolean applied: boolean + wroteSourceMeta: boolean diff: { noop: boolean meta?: Array<'name' | 'description'> @@ -20864,12 +20866,12 @@ export const V2_OPERATIONS = { dry: { kind: 'boolean', describe: - 'Run every check without writing, auditing, or notifying collaborators. Findings, errors included, come back in `diagnostics` with `applied: false` and a `200`, and the files, lock and fingerprint show what a committed apply would store. A request refused before the source is evaluated (an invalid or oversized body, a locked workflow or folder) gets the same status as without `dry`, and a create under a taken name answers `409`.', + 'Run every check without writing, auditing, or notifying collaborators. Findings, errors included, come back in `diagnostics` with `applied: false` and a `200`, and the files, lock and fingerprint show what a committed write would store. A request refused before the source is evaluated (an invalid or oversized body, a locked workflow or folder) gets the same status as without `dry`, and a create under a taken name answers `409`.', }, allowDelete: { kind: 'boolean', describe: - 'Allow the apply to delete blocks and variables the source no longer declares. Without it, an apply that would delete any block is refused with `E_APPLY_BLOCK_DELETE`, and one that would delete any variable with `E_APPLY_VARIABLE_DELETE`, naming them. Ignored when creating a workflow.', + 'Allow the apply to delete blocks and variables the source no longer declares. Without it, an apply that would delete any block is refused with `E_APPLY_BLOCK_DELETE`, and one that would delete any variable with `E_APPLY_VARIABLE_DELETE`, naming them.', }, }, body: { @@ -22546,12 +22548,7 @@ export const V2_OPERATIONS = { dry: { kind: 'boolean', describe: - 'Run every check without writing, auditing, or notifying collaborators. Findings, errors included, come back in `diagnostics` with `applied: false` and a `200`, and the files, lock and fingerprint show what a committed apply would store. A request refused before the source is evaluated (an invalid or oversized body, a locked workflow or folder) gets the same status as without `dry`, and a create under a taken name answers `409`.', - }, - allowDelete: { - kind: 'boolean', - describe: - 'Allow the apply to delete blocks and variables the source no longer declares. Without it, an apply that would delete any block is refused with `E_APPLY_BLOCK_DELETE`, and one that would delete any variable with `E_APPLY_VARIABLE_DELETE`, naming them. Ignored when creating a workflow.', + 'Run every check without writing, auditing, or notifying collaborators. Findings, errors included, come back in `diagnostics` with `applied: false` and a `200`, and the files, lock and fingerprint show what a committed write would store. A request refused before the source is evaluated (an invalid or oversized body, a locked workflow or folder) gets the same status as without `dry`, and a create under a taken name answers `409`.', }, }, body: { diff --git a/packages/workflow-code/src/limits.ts b/packages/workflow-code/src/limits.ts index 9dea152c978..8c5d05d8d9d 100644 --- a/packages/workflow-code/src/limits.ts +++ b/packages/workflow-code/src/limits.ts @@ -110,6 +110,16 @@ export function sourceLimitExcesses( max: SOURCE_LIMITS.maxVariables, }) } + excesses.push(...sourceFileExcesses(files)) + return excesses +} + +/** + * The file-count and total-size limits `files` exceeds, which need no compile to measure: what a + * client can refuse before it sends a source. + */ +export function sourceFileExcesses(files: Readonly>): SourceLimitExcess[] { + const excesses: SourceLimitExcess[] = [] const paths = Object.keys(files) if (paths.length > SOURCE_LIMITS.maxFiles) { excesses.push({ limit: 'maxFiles', actual: paths.length, max: SOURCE_LIMITS.maxFiles })