Skip to content

Commit 4e82583

Browse files
committed
test(logs): pin the logged mark and attribution at the block executor
Asserts the block executor's thrown error is already logged and attributed (database failure internal, user Stop user), switches the tool-boundary test to the central jsonResponse helper, and updates exact-argument log assertions for the added failureKind and executionId fields.
1 parent 8e033f5 commit 4e82583

4 files changed

Lines changed: 20 additions & 12 deletions

File tree

‎apps/sim/background/async-preprocessing-correlation.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ describe('async preprocessing correlation threading', () => {
493493
})
494494
expect(workflowExecutionLogger.error).toHaveBeenCalledWith(
495495
'[request-fault] Workflow execution failed: workflow-1',
496-
{ executionId: 'execution-fault', error: projectedError }
496+
{ executionId: 'execution-fault', error: projectedError, failureKind: 'internal' }
497497
)
498498
const loggerPayload = JSON.stringify(workflowExecutionLogger.error.mock.calls)
499499
expect(loggerPayload).not.toContain(secret)

‎apps/sim/background/webhook-execution.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,17 @@ describe('executeWebhookJob fault vs error handling', () => {
482482
expect(loggingSessionMockFns.mockSafeCompleteWithError).toHaveBeenCalled()
483483
expect(loggingSessionMockFns.mockProjectDiagnosticError).toHaveBeenCalledWith(rawError, {
484484
workflowId: 'workflow-1',
485+
executionId: 'execution-1',
485486
provider: 'gmail',
486487
})
487488
expect(webhookExecutionLogger.error).toHaveBeenCalledWith(
488489
'[request-1] Webhook execution failed',
489-
{ workflowId: 'workflow-1', provider: 'gmail', error: projectedError }
490+
{
491+
workflowId: 'workflow-1',
492+
provider: 'gmail',
493+
error: projectedError,
494+
failureKind: 'internal',
495+
}
490496
)
491497
const loggerPayload = JSON.stringify(webhookExecutionLogger.error.mock.calls)
492498
expect(loggerPayload).not.toContain(secret)

‎apps/sim/executor/execution/block-executor.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { storageServiceMockFns } from '@sim/testing/mocks/storage-service.mock'
55
import { uploadsMock } from '@sim/testing/mocks/uploads.mock'
66
import { DrizzleQueryError } from 'drizzle-orm/errors'
77
import { beforeEach, describe, expect, it, vi } from 'vitest'
8+
import { classifyFailure, wasFailureLogged } from '@/lib/core/errors/failure-log'
89
import { clearLargeValueCacheForTests } from '@/lib/execution/payloads/cache'
910
import { createLargeArrayManifest } from '@/lib/execution/payloads/large-array-manifest'
1011
import { isLargeValueRef } from '@/lib/execution/payloads/large-value-ref'
@@ -496,6 +497,9 @@ describe('BlockExecutor', () => {
496497
expect.objectContaining({ cause: expect.objectContaining({ code: 'ECONNRESET' }) })
497498
)
498499
expect(JSON.stringify(logged)).not.toContain('owner-secret-id')
500+
/** Logged here at error, so the engine and the run surfaces must see it as already logged. */
501+
expect(classifyFailure(thrown)).toBe('internal')
502+
expect(wasFailureLogged(thrown)).toBe(true)
499503
})
500504

501505
it('fires block completion callbacks for pausing blocks so clients receive pause output', async () => {
@@ -614,11 +618,15 @@ describe('BlockExecutor', () => {
614618
const ctx = createContext(state)
615619
ctx.abortSignal = abortController.signal
616620

617-
await expect(executor.execute(ctx, createNode(block), block)).rejects.toThrow(/abort/i)
621+
const thrown = await executor.execute(ctx, createNode(block), block).catch((error) => error)
622+
expect(thrown).toBeInstanceOf(Error)
623+
expect(thrown.message).toMatch(/abort/i)
618624

619625
const output = state.getBlockOutput(block.id)
620626
expect(output?.error).toBeTruthy()
621627
expect(output).not.toEqual({ content: '' })
628+
/** A user Stop is not a Sim fault, so it must not page at error. */
629+
expect(classifyFailure(thrown)).toBe('user')
622630
})
623631

624632
it('keeps Sim Chat secret policy in runtime inputs and out of trace inputs', async () => {

‎apps/sim/tools/index.test.ts‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createSessionPrincipal } from '@sim/testing/factories/principal.factory'
2+
import { jsonResponse } from '@sim/testing/helpers/http'
23
import { apiKeyByokMock, apiKeyByokMockFns } from '@sim/testing/mocks/api-key-byok.mock'
34
import { authInternalMock, authInternalMockFns } from '@sim/testing/mocks/auth-internal.mock'
45
import { billingUsageLogMock } from '@sim/testing/mocks/billing-usage-log.mock'
@@ -5832,20 +5833,13 @@ describe('Centralized Error Handling', () => {
58325833
return buildBlockExecutionError({ block: apiBlock, error: thrown as Error })
58335834
}
58345835

5835-
function jsonResponse(status: number, body: unknown): Response {
5836-
return new Response(JSON.stringify(body), {
5837-
status,
5838-
headers: { 'content-type': 'application/json' },
5839-
})
5840-
}
5841-
58425836
it.each([
58435837
[404, 'third_party_client'],
58445838
[503, 'third_party_server'],
58455839
] as const)(
58465840
'attributes an upstream %i to the third party, logged once by the tool layer',
58475841
async (status, kind) => {
5848-
const blockError = await failApiBlock(jsonResponse(status, { error: 'rejected' }))
5842+
const blockError = await failApiBlock(jsonResponse({ error: 'rejected' }, status))
58495843
expect(classifyFailure(blockError)).toBe(kind)
58505844
expect(wasFailureLogged(blockError)).toBe(true)
58515845
}
@@ -5864,7 +5858,7 @@ describe('Centralized Error Handling', () => {
58645858
throw transformError
58655859
}
58665860
try {
5867-
const blockError = await failApiBlock(jsonResponse(200, { ok: false }))
5861+
const blockError = await failApiBlock(jsonResponse({ ok: false }))
58685862
expect(classifyFailure(blockError)).toBe(kind)
58695863
expect(wasFailureLogged(blockError)).toBe(true)
58705864
} finally {

0 commit comments

Comments
 (0)