Skip to content

Commit 21955e0

Browse files
committed
improvement(workflow-code): keep apply's next runnable: pinned deploy, tested deploy named in its reason
1 parent 5da85b6 commit 21955e0

4 files changed

Lines changed: 10 additions & 22 deletions

File tree

‎apps/docs/content/docs/workflows/code/edit.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Editing the name or description in `workflow('…')` renames or redescribes the
7676

7777
### Deploy
7878

79-
Saving writes the draft. Add `--deploy` to deploy right after the save, which also prints the URL of each webhook the workflow now serves. Add `--run '<input json>'` to dry-run the saved draft with that input first: with `--deploy`, it deploys only if the run completed. Without `--deploy`, a deployed workflow whose draft now differs prints the next command: the same apply with `--run` and `--deploy`, or `sim workflows deploy` after a completed run.
79+
Saving writes the draft. Add `--deploy` to deploy right after the save, which also prints the URL of each webhook the workflow now serves. Add `--run '<input json>'` to dry-run the saved draft with that input first: with `--deploy`, it deploys only if the run completed. Without `--deploy`, a deployed workflow whose draft now differs prints the `sim workflows deploy` command to run, pinned to the draft this apply saved; after an apply without `--run`, it also names the apply that tests and deploys in one step.
8080

8181
### Deletes
8282

‎packages/sim-cli/src/commands/protocol/workflow-dir.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ Batch it: write every file first, then run steps 2 and 4 (with a test run and th
254254
1. Edit \`${SOURCE_ENTRY_FILE}\` (and \`functions/*\`). \`${SOURCE_EXAMPLES_DIR}/\` holds correct examples to copy from: \`cookbook.ts\` (agent with structured output, condition, function, table query and upsert, knowledge search, Slack, human in the loop, loop, response), \`integrations.ts\` (webhook trigger, weekday cron schedule, HTTP request with headers, table update by row id, Gmail, an error path) and \`agents.ts\` (router, agent tools: custom tool, MCP tool, integration operation, child workflow; run a child workflow; parallel). Their resource keys are examples; this workspace's are in \`${WORKSPACE_TYPES_FILE}\`.
255255
2. \`sim workflows source check --dir .\`: compiles with the server's compiler, in milliseconds and without a request. It catches what \`tsc\` cannot (duplicate names, cycles, literal secrets), and fails (exit 1) on ${STRICT_FINDINGS_CLAUSE} in a block you added (\`--strict\`: in every block). It then adds the blocks the source now uses to \`tsconfig.json\` and type-checks with it, using the TypeScript release the declarations are built for (installed once into the CLI's cache, on the first check; \`E_TYPE\` findings). That catches what the compile and \`apply --dry\` do not, such as a reference to a start input the trigger does not declare. Offline before that install, it warns \`W_TYPES_UNCHECKED\` and passes on the compile alone; \`--no-types\` skips it. \`apply --dry\` is the authority: a type error on a printed line you did not edit that it accepts can be skipped with \`--no-types\`.
256256
3. \`sim workflows source status --dir .\`: the files you changed (\`sim workflows source diff --dir .\` shows the edits), whether the workflow changed on the server since the get, and the command to run next (\`--offline\`: skip the server). Then \`sim workflows source apply --dir . --dry\` until it exits 0.
257-
4. \`sim workflows source apply --dir . --yes\`: saves the draft, refusing errors, block deletions without \`--allow-delete\` and a stale directory, so it needs no separate dry run (without \`--yes\` and a terminal it prints the plan and exits ${SOURCE_PLANNED_EXIT_CODE}). \`--run '{…}'\` then dry-runs that input on the saved draft (\`run\` in the result: status, output, side effects; a failed run exits 1 and maps the failing block to file:line), and \`--deploy\` deploys it only if that run completed (alone, it deploys right after the apply). Without \`--deploy\`, a deployed workflow's next is that same apply with \`--run '<input json>' --deploy\`, or \`sim workflows deploy <id> --expected-draft-fingerprint <fingerprint>\` after a completed \`--run\`; both deploy only the draft this apply saved. Its first line, \`summary\`, gives the counts, findings, test run and what is live; its last lines repeat \`errors\`, \`warnings\` and \`live\`, which says what serves: \`not deployed\`, \`version N, matches the draft\`, \`version N, draft has undeployed changes\`, or after \`--deploy\` \`version N still serving; version M activating\` until the deploy is live (\`sim workflows deployment status <id>\` shows when). It then rewrites \`${SOURCE_ENTRY_FILE}\` in canonical form (order, quoting, defaults left out).
257+
4. \`sim workflows source apply --dir . --yes\`: saves the draft, refusing errors, block deletions without \`--allow-delete\` and a stale directory, so it needs no separate dry run (without \`--yes\` and a terminal it prints the plan and exits ${SOURCE_PLANNED_EXIT_CODE}). \`--run '{…}'\` then dry-runs that input on the saved draft (\`run\` in the result: status, output, side effects; a failed run exits 1 and maps the failing block to file:line), and \`--deploy\` deploys it only if that run completed (alone, it deploys right after the apply). Without \`--deploy\`, a deployed workflow's next is \`sim workflows deploy <id> --expected-draft-fingerprint <fingerprint>\`, which deploys only the draft this apply saved; after an apply without \`--run\` its reason names the same apply with \`--run '{…}' --deploy\`, which tests and deploys in one step. Its first line, \`summary\`, gives the counts, findings, test run and what is live; its last lines repeat \`errors\`, \`warnings\` and \`live\`, which says what serves: \`not deployed\`, \`version N, matches the draft\`, \`version N, draft has undeployed changes\`, or after \`--deploy\` \`version N still serving; version M activating\` until the deploy is live (\`sim workflows deployment status <id>\` shows when). It then rewrites \`${SOURCE_ENTRY_FILE}\` in canonical form (order, quoting, defaults left out).
258258
5. Exit ${SOURCE_STALE_EXIT_CODE} (\`SOURCE_STALE\`, HTTP 409, or \`E_APPLY_STALE\` on a dry run): the workflow changed and nothing was saved. Run \`sim workflows source get <workflowId> --dir <fresh dir>\`, reapply your edit there, dry-run, apply. A get into this directory refuses to overwrite your unapplied edits unless you pass \`--force\`. Exit ${SOURCE_STALE_EXIT_CODE} right after an apply that ended without an answer (a timeout, a dropped connection) means the draft changed, by that apply or by someone else: get into a fresh directory and compare. Only when it holds your edit, run \`sim workflows source get <workflowId> --dir . --force\`; otherwise reapply your edit in the fresh directory.
259259
260260
Editing the \`workflow('…')\` name or description renames or redescribes the workflow; a name another workflow in its folder holds is refused with \`E_NAME_TAKEN\`. Lines starting \`note:\` explain something the write did differently than the source says; read them.

‎packages/sim-cli/src/commands/protocol/workflow-source-apply.test.ts‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,23 +1241,21 @@ describe('sim workflows source apply', () => {
12411241
])
12421242
})
12431243

1244-
it('without --deploy, names the tested deploy when the deployed workflow now differs', async () => {
1244+
it('without --deploy, names the pinned deploy when the deployed workflow now differs, and the tested one in its reason', async () => {
12451245
setTerminal(false)
12461246
request.mockResolvedValue(outcome())
12471247

12481248
await apply(WORKFLOW_ID, '--dir', dir, '--yes')
12491249

12501250
expect(request.mock.calls.map((call) => call[0])).toEqual([APPLY_PATH])
12511251
const result = stdoutJson()
1252+
// `next.command` runs as printed: no placeholder an agent would have to fill in.
12521253
expect(result).toMatchObject({
12531254
needsRedeployment: true,
1254-
next: {
1255-
command: `sim workflows source apply --dir ${dir} --yes --run '<input json>' --deploy`,
1256-
},
1255+
next: { command: `sim workflows deploy ${WORKFLOW_ID} --expected-draft-fingerprint sf1:b` },
12571256
})
1258-
// The untested deploy stays one copy away, pinned to the draft this apply stored.
12591257
expect(toRecord(result.next).reason).toContain(
1260-
`sim workflows deploy ${WORKFLOW_ID} --expected-draft-fingerprint sf1:b`
1258+
`\`sim workflows source apply --dir ${dir} --yes --run '{…}' --deploy\` tests and deploys it in one step`
12611259
)
12621260
})
12631261

‎packages/sim-cli/src/commands/protocol/workflow-source-apply.ts‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,9 @@ async function writeWorkflowSource<Operation extends SourceWriteOperation>(args:
319319
...options,
320320
verb,
321321
machine: findings.machine,
322-
// Read only without --deploy: the next an untested draft gets is this write, tested, deployed.
322+
// Read only without --deploy: an untested draft's next names the tested deploy too.
323323
testedDeploy:
324-
run === undefined && !creating
325-
? `${args.command} --yes --run '<input json>' --deploy`
326-
: undefined,
324+
run === undefined && !creating ? `${args.command} --yes --run '{…}' --deploy` : undefined,
327325
})
328326
)
329327
report(data, deployment, run)
@@ -466,26 +464,18 @@ async function deployStep(
466464
dir: string
467465
verb: string
468466
machine: boolean
469-
/** The write again with a test run before its deploy, while the draft is untested. */
467+
/** The write again with a test run and the deploy, named in `next.reason` while the draft is untested. */
470468
testedDeploy?: string
471469
}
472470
): Promise<DeployOutcome> {
473471
// Pinned to the draft this write stored, as `--deploy` is: an edit made since is never deployed.
474472
const deployCommand = `sim workflows deploy ${data.workflowId} --expected-draft-fingerprint ${data.base.fingerprint}`
475473
if (!options.deploy) {
476474
if (!data.needsRedeployment) return {}
477-
if (options.testedDeploy) {
478-
return {
479-
next: {
480-
command: options.testedDeploy,
481-
reason: `The workflow is deployed and its draft now differs from the live version: this tests the saved draft with that input and deploys it only if the run completes (\`${deployCommand}\` deploys it untested).`,
482-
},
483-
}
484-
}
485475
return {
486476
next: {
487477
command: deployCommand,
488-
reason: `The workflow is deployed and its draft now differs from the live version: deploy to make the change live (or ${options.verb} with --deploy).`,
478+
reason: `The workflow is deployed and its draft now differs from the live version: deploy to make the change live (or ${options.verb} with --deploy).${options.testedDeploy ? ` The draft is untested: \`${options.testedDeploy}\` tests and deploys it in one step.` : ''}`,
489479
},
490480
}
491481
}

0 commit comments

Comments
 (0)