Skip to content

Commit 105f432

Browse files
committed
fix(sim-cli): carry --summary-file onto the apply and create commands a plan names next
1 parent faa4e56 commit 105f432

9 files changed

Lines changed: 64 additions & 6 deletions

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
errorBullets,
3232
findingsOutput,
3333
markdownCell,
34+
summaryFileFlag,
3435
summaryMarker,
3536
} from './source-ui'
3637

@@ -494,6 +495,8 @@ interface NextStepInput {
494495
* scope the status was asked for (`--only`, `--workspace`), so the command acts on what it showed.
495496
*/
496497
scope: string
498+
/** `--summary-file`, carried onto the commands that write a summary (the dry run and apply). */
499+
summaryFile?: string
497500
/**
498501
* The login command when the server was not checked because the profile has no login: nothing
499502
* else can be decided until it runs.
@@ -531,18 +534,18 @@ export function nextStep(status: SourceStatus, input: NextStepInput): NextStep |
531534
}
532535
if (input.server !== 'checked') {
533536
return {
534-
command: `${prefix} apply --dir ${dir} --dry-run${input.scope}`,
537+
command: `${prefix} apply --dir ${dir} --dry-run${input.scope}${summaryFileFlag(input.summaryFile)}`,
535538
reason: 'The dry run checks the changes against the server.',
536539
}
537540
}
538541
if (input.errors > 0) {
539542
return {
540-
command: `${prefix} apply --dir ${dir} --dry-run${input.scope}`,
543+
command: `${prefix} apply --dir ${dir} --dry-run${input.scope}${summaryFileFlag(input.summaryFile)}`,
541544
reason: `It prints the ${input.errors} error(s) to fix before applying.`,
542545
}
543546
}
544547
return {
545-
command: `${prefix} apply --dir ${dir} --yes${input.deletes ? ' --allow-delete' : ''}${input.scope}`,
548+
command: `${prefix} apply --dir ${dir} --yes${input.deletes ? ' --allow-delete' : ''}${input.scope}${summaryFileFlag(input.summaryFile)}`,
546549
reason:
547550
status.drift.length > 0
548551
? `Applies your changes; then \`${prefix} get ${input.getArgs}--dir ${dir}\` picks up the server's.`

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ export function writeMode(options: { dryRun?: boolean; yes?: boolean }): WriteMo
461461
return canPrompt() ? 'ask' : 'plan'
462462
}
463463

464+
/** ` --summary-file <path>` for a next command, so applying it writes the file the plan run was asked for; empty without one. */
465+
export function summaryFileFlag(path: string | undefined): string {
466+
return path ? ` --summary-file ${shellWord(path)}` : ''
467+
}
468+
464469
/** `value` as one shell word: as it is when it needs no quoting, else single-quoted. */
465470
export function shellWord(value: string): string {
466471
return /^[\w@%+=:,./-]+$/.test(value) ? value : `'${value.replaceAll("'", "'\\''")}'`

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,20 @@ describe('sim workflows source apply', () => {
190190
expect(stderrLines().join('\n')).not.toContain('Blocks:')
191191
})
192192

193+
it('carries --summary-file onto the apply it names next, quoted', async () => {
194+
setTerminal(false)
195+
request.mockResolvedValue(outcome({ dryRun: true }))
196+
const file = join(dir, 'my plan.md')
197+
198+
await apply(WORKFLOW_ID, '--dir', dir, '--summary-file', file)
199+
200+
expect(stdoutJson()).toMatchObject({
201+
next: {
202+
command: `sim workflows source apply --dir ${dir} --summary-file '${file}' --yes`,
203+
},
204+
})
205+
})
206+
193207
it('writes the plan to --summary-file: the counts, each block, the errors and a stale deployment', async () => {
194208
setTerminal(false)
195209
const dryRunAnswer = outcome({

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
refusedExitCode,
5252
SUMMARY_ROWS,
5353
shellWord,
54+
summaryFileFlag,
5455
summaryFileOption,
5556
summaryMarker,
5657
verboseFlag,
@@ -481,7 +482,7 @@ export function attachWorkflowSourceApply(source: Command): void {
481482
mode,
482483
creating: false,
483484
question: `Apply these changes to workflow ${workflowId}?`,
484-
command: `sim workflows source apply --dir ${shellWord(options.dir)}${options.allowDelete ? ' --allow-delete' : ''}${options.deploy ? ' --deploy' : ''}`,
485+
command: `sim workflows source apply --dir ${shellWord(options.dir)}${options.allowDelete ? ' --allow-delete' : ''}${options.deploy ? ' --deploy' : ''}${summaryFileFlag(options.summaryFile)}`,
485486
output: profile.output,
486487
client,
487488
operation: 'applyWorkflowSource',
@@ -566,7 +567,7 @@ export function attachWorkflowSourceCreate(source: Command): void {
566567
const workspaceId = client.requireWorkspace()
567568
const tree = await writeSourceScaffold(client, options.dir, workspaceId)
568569
const next: NextStep = {
569-
command: `${createCommand(shellWord(options.dir), workspaceId)} --yes`,
570+
command: `${createCommand(shellWord(options.dir), workspaceId)} --yes${summaryFileFlag(options.summaryFile)}`,
570571
reason: `${options.dir} had no ${ENTRY_FILE}, so a starter, the SDK types for workspace ${workspaceId}, tsconfig.json, .sim/AGENTS.md and the examples in .sim/examples/ were written and nothing was created. Edit ${ENTRY_FILE}, check it, then create it.`,
571572
}
572573
const machine = isMachine(profile.output)
@@ -595,7 +596,7 @@ export function attachWorkflowSourceCreate(source: Command): void {
595596
mode,
596597
creating: true,
597598
question: 'Create this workflow?',
598-
command: `${createCommand(shellWord(options.dir), workspaceId)}${options.name !== undefined ? ` --name ${shellWord(options.name)}` : ''}${options.folder !== undefined ? ` --folder ${shellWord(options.folder)}` : ''}${options.deploy ? ' --deploy' : ''}`,
599+
command: `${createCommand(shellWord(options.dir), workspaceId)}${options.name !== undefined ? ` --name ${shellWord(options.name)}` : ''}${options.folder !== undefined ? ` --folder ${shellWord(options.folder)}` : ''}${options.deploy ? ' --deploy' : ''}${summaryFileFlag(options.summaryFile)}`,
599600
output: profile.output,
600601
client,
601602
operation: 'createWorkflowFromSource',

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,23 @@ describe('workflows source status', () => {
246246
expect(process.exitCode).toBe(11)
247247
})
248248

249+
it('carries --summary-file onto the apply it recommends', async () => {
250+
const file = join(root, 'my plan.md')
251+
write(
252+
root,
253+
'workflow.ts',
254+
ENTRY.replace('})\n})', "})\n fn('Rank', { code: codeFile('./functions/rank.js') })\n})")
255+
)
256+
write(root, 'functions/rank.js', 'return 2\n')
257+
mockRequest.mockResolvedValue(dryRun([], 1))
258+
259+
await run(root, 'status', '--summary-file', file)
260+
261+
expect(printed().next).toMatchObject({
262+
command: `sim workflows source apply --dir ${root} --yes --summary-file '${file}'`,
263+
})
264+
})
265+
249266
it('names --allow-delete in the apply it recommends when the edit removes a variable', async () => {
250267
write(root, 'workflow.ts', `${ENTRY}// edited\n`)
251268
const plan = dryRun([], 1)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ export function attachWorkflowSourceStatus(source: Command): void {
246246
errors: plan?.errors ?? 0,
247247
deletes: (plan?.blocksRemoved ?? 0) + (plan?.variablesRemoved ?? 0) > 0,
248248
scope: '',
249+
summaryFile: options.summaryFile,
249250
login,
250251
}),
251252
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,20 @@ describe('workspaces source apply', () => {
17891789
])
17901790
})
17911791

1792+
it('carries --summary-file onto the apply it names next, quoted', async () => {
1793+
const file = join(dir, 'my plan.md')
1794+
request.mockResolvedValue(
1795+
answer({ dryRun: true, plan: [{ kind: 'table', key: 'leads', action: 'create' }] })
1796+
)
1797+
1798+
await apply('--summary-file', file)
1799+
1800+
const printed = JSON.parse(String(vi.mocked(console.log).mock.calls.at(-1)?.[0]))
1801+
expect(printed.next.command).toBe(
1802+
`sim workspaces source apply --dir ${dir} --summary-file '${file}' --yes`
1803+
)
1804+
})
1805+
17921806
it('writes the plan to --summary-file whatever CI runs it, opening with a marker a job can find', async () => {
17931807
const file = join(dir, 'plan.md')
17941808
writeFileSync(file, 'an earlier run\n')

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import {
6666
refusedExitCode,
6767
SUMMARY_ROWS,
6868
shellWord,
69+
summaryFileFlag,
6970
summaryFileOption,
7071
summaryMarker,
7172
verboseFlag,
@@ -1050,6 +1051,7 @@ function applyCommand(options: ApplyOptions): string {
10501051
...(options.to ? [`--to ${shellWord(options.to)}`] : []),
10511052
...(options.allowDelete ? ['--allow-delete'] : []),
10521053
...(options.deleteTargetOnly ? ['--delete-target-only'] : []),
1054+
...(options.summaryFile ? [summaryFileFlag(options.summaryFile).trimStart()] : []),
10531055
].join(' ')
10541056
}
10551057

‎packages/sim-cli/src/commands/protocol/workspace-source-status.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ export function attachWorkspaceSourceStatus(source: Command): void {
461461
errors: plan?.errors ?? 0,
462462
deletes: destructiveChanges(applyPlan) > 0,
463463
scope: `${onlyScope}${workspaceScope}`,
464+
summaryFile: options.summaryFile,
464465
login,
465466
}),
466467
}

0 commit comments

Comments
 (0)