Skip to content

Commit c7049f7

Browse files
committed
improvement(workflow-code): simplify pass, run error read as message object, test and comment cleanup
1 parent 71a2868 commit c7049f7

9 files changed

Lines changed: 64 additions & 33 deletions

File tree

‎apps/sim/app/api/v2/logs/[runId]/route.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,45 @@ describe('GET /api/v2/logs/[runId]', () => {
205205
expect((await response.json()).data.failure).toMatchObject({ blockId: 'b' })
206206
})
207207

208+
it('reads a run error recorded as an object with a message', async () => {
209+
const failedBlock = (blockId: string, name: string) => ({
210+
id: `span-${blockId}`,
211+
blockId,
212+
name,
213+
type: 'agent',
214+
duration: 10,
215+
status: 'error',
216+
startTime: '2026-08-06T00:00:00.000Z',
217+
endTime: '2026-08-06T00:00:01.000Z',
218+
output: { error: `${name} failed` },
219+
})
220+
mocks.execute.mockResolvedValue({
221+
log: { ...log, status: 'failed', level: 'error' },
222+
workflowFolderPath: '/agents',
223+
executionData: {
224+
traceSpans: [
225+
{
226+
id: 'workflow-execution',
227+
name: 'Workflow Execution',
228+
type: 'workflow',
229+
duration: 1000,
230+
status: 'error',
231+
startTime: '2026-08-06T00:00:00.000Z',
232+
endTime: '2026-08-06T00:00:01.000Z',
233+
children: [failedBlock('a', 'Agent A'), failedBlock('b', 'Agent B')],
234+
},
235+
],
236+
error: { message: 'Agent B: timeout' },
237+
},
238+
})
239+
240+
const response = await GET(new NextRequest('http://localhost:3000/api/v2/logs/run-1'), {
241+
params: Promise.resolve({ runId: 'run-1' }),
242+
})
243+
244+
expect((await response.json()).data.failure).toMatchObject({ blockId: 'b' })
245+
})
246+
208247
it('reports no failure for a cancelled run that kept error spans', async () => {
209248
mocks.execute.mockResolvedValue({
210249
log: { ...log, status: 'cancelled', level: 'error' },

‎apps/sim/app/api/v2/logs/[runId]/route.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isRecordLike } from '@sim/utils/object'
12
import { type CostLedger, traceSpansSchema } from '@/lib/api/contracts/logs'
23
import { type V2LogDetail, v2GetLogContract, v2LogStatusSchema } from '@/lib/api/contracts/v2/logs'
34
import { defineV2JsonRoute, v2ApiKeyAuth, v2RateLimits } from '@/lib/api/server/routes'
@@ -28,12 +29,11 @@ function buildCostProjection(
2829

2930
/** The error string a run recorded for itself, when it recorded one. */
3031
function runErrorOf(executionData: Record<string, unknown>): string | undefined {
31-
const finalOutput = executionData.finalOutput
32+
const { error, finalOutput } = executionData
3233
const candidates = [
33-
executionData.error,
34-
finalOutput && typeof finalOutput === 'object'
35-
? (finalOutput as Record<string, unknown>).error
36-
: undefined,
34+
error,
35+
isRecordLike(error) ? error.message : undefined,
36+
isRecordLike(finalOutput) ? finalOutput.error : undefined,
3737
]
3838
return candidates.find((value): value is string => typeof value === 'string' && value !== '')
3939
}

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -323,18 +323,9 @@ export function codeSpan(text: string): string {
323323
return `${fence} ${line} ${fence}`
324324
}
325325

326-
/** The error findings of a summary as list items, capped at {@link SUMMARY_ROWS}. */
327-
export function errorBullets(
328-
diagnostics: ReadonlyArray<{
329-
severity: string
330-
code: string
331-
message: string
332-
file?: string
333-
line?: number
334-
}>
335-
): string[] {
336-
return diagnostics
337-
.filter((finding) => finding.severity === 'error')
326+
/** The error findings of a summary (already filtered to errors) as list items, capped at {@link SUMMARY_ROWS}. */
327+
export function errorBullets(errors: ReadonlyArray<Diagnostic>): string[] {
328+
return errors
338329
.slice(0, SUMMARY_ROWS)
339330
.map(
340331
(finding) =>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ function printFindings(data: SourceApplyData, findings: FindingsOutput, notes: S
9494
}
9595
}
9696

97-
/** One line naming what the apply changes, shown before asking to confirm it. */
9897
/** What changed in the workflow's variables, one entry per kind of change. */
9998
function variableChangeList(variables: SourceApplyData['diff']['variables']): string[] {
10099
return [
@@ -105,6 +104,7 @@ function variableChangeList(variables: SourceApplyData['diff']['variables']): st
105104
]
106105
}
107106

107+
/** One line naming what the apply changes, shown before asking to confirm it. */
108108
function diffSummary(data: SourceApplyData): string {
109109
const { blocks, edges, variables } = data.diff
110110
if (data.diff.noop) return 'No graph changes (names, order or comments may still be saved).'
@@ -299,7 +299,7 @@ function planMarkdown(data: SourceApplyData, creating: boolean, deployment: Depl
299299
: []),
300300
]
301301
: []),
302-
...(errors.length > 0 ? ['', '**Errors**', '', ...errorBullets(data.diagnostics)] : []),
302+
...(errors.length > 0 ? ['', '**Errors**', '', ...errorBullets(errors)] : []),
303303
...(needsRedeployment ? ['', 'The live deployment now differs from the draft.'] : []),
304304
].join('\n')
305305
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ function planMarkdown(data: ApplyData, workspaceId: string): string {
991991
...(changes.length > rows.length ? [`\n…and ${changes.length - rows.length} more.`] : []),
992992
]
993993
: []),
994-
...(errors.length > 0 ? ['', '**Errors**', '', ...errorBullets(data.diagnostics)] : []),
994+
...(errors.length > 0 ? ['', '**Errors**', '', ...errorBullets(errors)] : []),
995995
]
996996
return lines.join('\n')
997997
}

‎packages/sim-cli/src/output/github-actions.test.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
22
import { tmpdir } from 'node:os'
33
import { join } from 'node:path'
4-
import { afterEach, describe, expect, it } from 'vitest'
4+
import { afterEach, describe, expect, it, vi } from 'vitest'
55
import { embedStore } from '../embed-context'
66
import { annotationLine, annotationPath, publishSummary } from './github-actions'
77

@@ -56,12 +56,11 @@ describe('summaries', () => {
5656
})
5757

5858
it('builds nothing when no summary is asked for', () => {
59-
publishSummary(
60-
() => {
61-
throw new Error('built')
62-
},
63-
{ env: {} }
64-
)
59+
const build = vi.fn(() => 'summary')
60+
61+
publishSummary(build, { env: {} })
62+
63+
expect(build).not.toHaveBeenCalled()
6564
})
6665

6766
it('reports a summary it cannot build and writes nothing, leaving the command to finish', () => {

‎packages/sim-cli/src/runtime/execute.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,11 @@ const RESULT_NOTES: Readonly<
252252
* portable artifact), so the pointer to where the bindings can be read goes to stderr.
253253
*/
254254
exportWorkflow: (_payload, _body, flags) =>
255-
flags.includeWorkspaceBindings === true
256-
? 'note: a credential always prints as null here: that is the export, not an unset block. Read what blocks are set to with `sim workflows outline <workflowId>` or `sim workflows state get <workflowId>`.'
257-
: 'note: a table, child workflow, knowledge base or other workspace binding prints as null here, and a credential always does: that is the export, not an unset block. Read what blocks are set to with `sim workflows outline <workflowId>` or `sim workflows state get <workflowId>`.',
255+
`note: ${
256+
flags.includeWorkspaceBindings === true
257+
? 'a credential always prints as null here'
258+
: 'a table, child workflow, knowledge base or other workspace binding prints as null here, and a credential always does'
259+
}: that is the export, not an unset block. Read what blocks are set to with \`sim workflows outline <workflowId>\` or \`sim workflows state get <workflowId>\`.`,
258260
}
259261

260262
/** Writes the operation's result note to stderr, when it has one and the result calls for it. */

‎scripts/check-env-numbers.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('numeric env names', () => {
2424
})
2525

2626
describe('raw numeric env reads', () => {
27-
it('reports the read that reached mapWithConcurrency raw before #10326', () => {
27+
it('reports a raw numeric read that reaches a consumer unnormalized', () => {
2828
expect(
2929
lines(`const CHUNK_CONCURRENCY = env.PII_MASK_CHUNK_CONCURRENCY ?? 64
3030
await mapWithConcurrency(items, CHUNK_CONCURRENCY, run)`)

‎scripts/check-env-numbers.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
* one of the two lines above it.
1919
*
2020
* The numeric names come from the schema, so a variable declared numeric later is covered without
21-
* touching this file. Parsed with the TypeScript AST: strings and comments never count. The tree
22-
* was swept when this landed, so there is no baseline.
21+
* touching this file. Parsed with the TypeScript AST: strings and comments never count. There is
22+
* no baseline.
2323
*
2424
* Usage: bun run check:env-numbers
2525
*/

0 commit comments

Comments
 (0)