Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/docs/content/docs/cli/reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10145,7 +10145,7 @@ sim workspaces source apply [options]
| `--delete-target-only` | No | With --to and --allow-delete, also delete the target's resources this directory never declared and no promotion from it left there (prod-only tables and their rows, skills made in prod). Without it a promotion keeps them, naming each with a warning. |
| `--only <kinds>` | No | Apply only these kinds (comma-separated folders: secrets.ts, credentials.ts, tools, skills, mcp, tables, knowledge, files, workflows, deployments). |
| `--to <workspaceId>` | No | Promote the directory to another workspace (dev to prod): its resources bind by key to that workspace's own and are updated in place. Only .sim/targets/&lt;workspaceId&gt;.json changes, the record the next promotion compares with: a resource changed there since is kept, or refused as stale (exit 5) when the directory changed it too. |
| `--run <key=input>` | No | After the apply, dry-run workflows/&lt;key&gt;/'s saved draft with this input (JSON or @file, as `sim workflows run --dry --input` takes it; `--run <key>` alone: no input). Repeat it to test more workflows. deployments/ is applied only after every run completed, and only when every draft it publishes was test-run; a run that does not complete exits 1 and leaves the applied drafts in place. Sandboxed code (Python, shell, imports) really runs in it, network requests included, and is listed in runs[].sideEffects.unchecked. |
| `--run <key[.trigger]=input>` | No | After the apply, dry-run workflows/&lt;key&gt;/'s saved draft with this input (JSON or @file, as `sim workflows run --dry --input` takes it; `--run <key>` alone: no input). In a workflow with several triggers, name the one the run enters through after a period (its const, block key or id): `--run 'orders.shopWebhook={…}'`. Repeat it to test more workflows, or more triggers of one. deployments/ is applied only after every run completed, and only when every draft it publishes was test-run; a run that does not complete exits 1 and leaves the applied drafts in place. Sandboxed code (Python, shell, imports) really runs in it, network requests included, and is listed in runs[].sideEffects.unchecked. |
| `--json` | No | Print machine-readable JSON (same as --output json). |

</CommandTable>
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/cli/workspaces.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ sim workspaces source apply [options]
| `--delete-target-only` | No | With --to and --allow-delete, also delete the target's resources this directory never declared and no promotion from it left there (prod-only tables and their rows, skills made in prod). Without it a promotion keeps them, naming each with a warning. |
| `--only <kinds>` | No | Apply only these kinds (comma-separated folders: secrets.ts, credentials.ts, tools, skills, mcp, tables, knowledge, files, workflows, deployments). |
| `--to <workspaceId>` | No | Promote the directory to another workspace (dev to prod): its resources bind by key to that workspace's own and are updated in place. Only .sim/targets/&lt;workspaceId&gt;.json changes, the record the next promotion compares with: a resource changed there since is kept, or refused as stale (exit 5) when the directory changed it too. |
| `--run <key=input>` | No | After the apply, dry-run workflows/&lt;key&gt;/'s saved draft with this input (JSON or @file, as `sim workflows run --dry --input` takes it; `--run <key>` alone: no input). Repeat it to test more workflows. deployments/ is applied only after every run completed, and only when every draft it publishes was test-run; a run that does not complete exits 1 and leaves the applied drafts in place. Sandboxed code (Python, shell, imports) really runs in it, network requests included, and is listed in runs[].sideEffects.unchecked. |
| `--run <key[.trigger]=input>` | No | After the apply, dry-run workflows/&lt;key&gt;/'s saved draft with this input (JSON or @file, as `sim workflows run --dry --input` takes it; `--run <key>` alone: no input). In a workflow with several triggers, name the one the run enters through after a period (its const, block key or id): `--run 'orders.shopWebhook={…}'`. Repeat it to test more workflows, or more triggers of one. deployments/ is applied only after every run completed, and only when every draft it publishes was test-run; a run that does not complete exits 1 and leaves the applied drafts in place. Sandboxed code (Python, shell, imports) really runs in it, network requests included, and is listed in runs[].sideEffects.unchecked. |
| `--json` | No | Print machine-readable JSON (same as --output json). |

</CommandTable>
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/content/docs/workflows/code/workspace.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ The dry run prints the plan (`+` create, `~` update, `=` adopt an existing resou
sim workspaces source check --dir ./my-workspace && sim workspaces source apply --dir ./my-workspace --yes --run lead-intake='{"email":"a@b.co"}'
```

`--run <key>='<input>'` dry-runs the saved draft of `workflows/<key>/` with that input after the apply, as `sim workflows run <workflowId> --dry --input` does: writes return placeholders and are listed under each run's `sideEffects`. The input is JSON or `@file`; repeat `--run` to test several workflows. The result lists each run under `runs` with its workflow key and id, status and output. A run that does not complete exits `1` and prints the failing block's file and line in `workflows/<key>/`; the applied drafts stay in place, so fix the source and run the same command again.
`--run <key>='<input>'` dry-runs the saved draft of `workflows/<key>/` with that input after the apply, as `sim workflows run <workflowId> --dry --input` does: writes return placeholders and are listed under each run's `sideEffects`. The input is JSON or `@file`; repeat `--run` to test several workflows. A workflow with more than one trigger (an API trigger and a webhook, say) needs the trigger each run enters through, named after a period by its const, block key or id: `--run two.apiIn='{…}' --run two.hook='{…}'` tests both paths in one apply. The result lists each run under `runs` with its workflow key and id, status and output. A run that does not complete exits `1` and prints the failing block's file and line in `workflows/<key>/`; the applied drafts stay in place, so fix the source and run the same command again.

With `--run`, `deployments/` is applied only after every run completed, in a second write, so a deployment with `live: 'draft'` publishes only a draft that passed its test. Without `--run` it is applied with everything else. `--run` is refused with `--dry` (nothing is written to test), with `--to` (test in this workspace, then promote), and with an `--only` that leaves out `workflows`.
With `--run`, `deployments/` is applied only after every run completed, in a second write, so a deployment with `live: 'draft'` publishes only a draft that passed its test. It is also applied only when every draft it publishes was test-run in this apply: if it would publish a workflow no `--run` tested, `deployments/` is skipped, the apply exits non-zero, and its `next` adds the `--run` for each untested workflow. Without `--run` it is applied with everything else. `--run` is refused with `--dry` (nothing is written to test), with `--to` (test in this workspace, then promote), and with an `--only` that leaves out `workflows`.

An apply adopts a resource it never read (one made in Sim under the name a new declaration gives) only when the declaration matches it, or only adds to it: a column, rows into an empty table, a document. An adopt that would change or remove anything the resource holds is refused with `E_APPLY_NO_BASE`, even with `--allow-delete`. Run `get` into a new directory to read the resource, then make your edit there, or give the declaration another name.

Expand Down
7 changes: 4 additions & 3 deletions packages/sim-cli/src/commands/protocol/source-loop-help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ and writes the workspace; --run <key>='{…}' (one per workflow, <key> its workf
dry-runs that input on the saved draft: code runs and GET fetches are sent (point them at test
resources); writes are stubbed and listed under runs[].sideEffects, whose .unchecked lists
sandboxed code that really ran, network requests included, and .omitted counts entries left
out. Use --run when the apply changes a workflow. A workflow deploys on apply when
deployments/<key>.ts declares it; with --run, deployments/ is applied only after every run
completed.
out. A workflow with several triggers takes one --run '<key>.<trigger>={…}' per trigger (its
const, block key or id). Use --run when the apply changes a workflow. A workflow deploys on
apply when deployments/<key>.ts declares it; with --run, deployments/ is applied only after
every run completed, and only when every draft it publishes was test-run.
--allow-delete lets an edit remove a resource, column, rows, document, or a workflow's block or
variable; apply --dry only prints the plan; get --force replaces edits no apply has saved.
Promote dev to prod: \`sim workspaces source apply --dir ./ws --to <workspaceId> --dry\`, then --yes.
Expand Down
2 changes: 1 addition & 1 deletion packages/sim-cli/src/commands/protocol/source-primer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const WORKSPACE_PRIMER = `# Sim workspace source: primer

A Sim workspace as files; nothing here runs. Commands here (table ones too) act on the workspace \`${SOURCE_BASE_FILE}\` names. Every \`.ts\` file starts with \`// @sim-sdk ${SDK_MAJOR}\`.

**Edit loop**: write every file, then run one chained command; fix what it reports: \`${WORKSPACE_LOOP}\` dry-runs \`workflows/<key>/\`'s draft (one \`--run\` per workflow you changed; drop it when you changed none) and deploys only if all complete. \`check\` also type-checks (no \`tsc\`). Apply re-checks (\`apply --dry\` only plans) and rewrites files: reread before editing.
**Edit loop**: write every file, then run one chained command; fix what it reports: \`${WORKSPACE_LOOP}\` dry-runs \`workflows/<key>/\`'s draft (one \`--run\` per workflow you changed; drop it when you changed none; several triggers: \`--run '<key>.<const>={…}'\` each) and deploys only if all complete and every draft it deploys was tested. \`check\` also type-checks (no \`tsc\`). Apply re-checks (\`apply --dry\` only plans) and rewrites files: reread before editing.

- **Deletes**: removing anything (file, column, block) needs \`apply --allow-delete\` and is permanent.
- **Exit ${SOURCE_HELD_EXIT_CODE}**: partly written: what needs an unset secret or unbound credential waits; set it, reapply.
Expand Down
42 changes: 33 additions & 9 deletions packages/sim-cli/src/commands/protocol/workflow-test-runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ export interface RunRequest {
/** A `--run` test as a write's result shows it: the trigger it named, then the run. */
export type NamedTestRun = TestRun & { trigger?: string }

/**
* A run's `--run` value as a command writes it, from its `raw` and the trigger it names: a
* workspace apply puts the workflow's key in front.
*/
type RunFlag = (run: Pick<RunRequest, 'raw' | 'trigger'>) => string

/** A `--run` run in turn: its result, why it did not complete, and the `--run` to repeat next. */
export interface RunOutcome extends DraftTest {
run: NamedTestRun
/** The `--run` value the next command repeats: a trigger the refusal pointed at, else `raw`. */
/** The `--run` the next command repeats: a trigger the refusal pointed at, else `raw` (as `flag` writes it). */
next: string
}

Expand Down Expand Up @@ -107,6 +113,14 @@ function triggerId(blocks: readonly LockBlock[], name: string): string {
return match?.id ?? name
}

/**
* The id of the trigger block `name` (its const, block key or id) is in the saved `lock`, so two
* names of one block compare equal; a name the lock does not hold comes back as written.
*/
export function lockTriggerId(lock: unknown, name: string): string {
return triggerId(lockBlocks(lock), name)
}

/** The consts of the triggers a refusal lists by id, in its order, but the block `refusedId`. */
function listedTriggers(
message: string,
Expand All @@ -128,22 +142,29 @@ function triggerRefusal(
request: RunRequest,
message: string,
blocks: readonly LockBlock[],
refusedId: string | undefined
refusedId: string | undefined,
flag: RunFlag
): { failure: string; next: string } | undefined {
const triggers = listedTriggers(message, blocks, refusedId)
if (triggers.length === 0) return undefined
if (request.trigger === undefined && SEVERAL_TRIGGERS.test(message)) {
const [first, ...others] = triggers
const next = `${first}=${request.raw}`
const next = flag({
trigger: first,
raw: request.raw === '' ? first : `${first}=${request.raw}`,
})
return {
failure: `the workflow has more than one trigger (${triggers.join(', ')}), so name the one each --run enters through: --run ${shellWord(next)}${others.length > 0 ? ` (or ${others.map((other) => `${other}=<its input>`).join(', ')})` : ''}`,
failure: `the workflow has more than one trigger (${triggers.join(', ')}), so name the one each --run enters through: --run ${shellWord(next)}${others.length > 0 ? ` (or ${others.map((other) => flag({ trigger: other, raw: `${other}=<its input>` })).join(', ')})` : ''}`,
next,
}
}
if (request.trigger !== undefined && NOT_A_TRIGGER.test(message)) {
return {
failure: `${request.trigger} is not a trigger of this workflow; name one of ${triggers.join(', ')} before = in --run`,
next: `${triggers[0]}${request.raw.slice(request.trigger.length)}`,
next: flag({
trigger: triggers[0],
raw: `${triggers[0]}${request.raw.slice(request.trigger.length)}`,
}),
}
}
return undefined
Expand All @@ -163,9 +184,12 @@ export async function runTests(
workspaceId: string
lock: unknown
runs: readonly RunRequest[]
onRun: (run: NamedTestRun) => void
onRun?: (run: NamedTestRun) => void
/** How this command writes a run's `--run` value; unset: its `raw`. */
flag?: RunFlag
}
): Promise<RunOutcome[]> {
const flag = args.flag ?? ((run: Pick<RunRequest, 'raw'>) => run.raw)
const blocks = lockBlocks(args.lock)
const outcomes: RunOutcome[] = []
for (const request of args.runs) {
Expand All @@ -180,7 +204,7 @@ export async function runTests(
)
const named = request.trigger === undefined ? {} : { trigger: request.trigger }
const refusal = test.refused
? triggerRefusal(request, String(test.run.error), blocks, entryId)
? triggerRefusal(request, String(test.run.error), blocks, entryId, flag)
: undefined
const outcome: RunOutcome = refusal
? {
Expand All @@ -189,9 +213,9 @@ export async function runTests(
failure: `the server refused it before it started: ${refusal.failure}`,
next: refusal.next,
}
: { ...test, run: { ...named, ...test.run }, next: request.raw }
: { ...test, run: { ...named, ...test.run }, next: flag(request) }
outcomes.push(outcome)
args.onRun(outcome.run)
args.onRun?.(outcome.run)
}
return outcomes
}
Expand Down
Loading
Loading