Files
sim/packages/testing/src/index.ts
Waleed 72bb7e6945 fix(executor): skip Response block formatting for internal JWT callers (#3551)
* fix(executor): skip Response block formatting for internal JWT callers

The workflow executor tool received `{error: true}` despite successful child
workflow execution when the child had a Response block. This happened because
`createHttpResponseFromBlock()` hijacked the response with raw user-defined
data, and the executor's `transformResponse` expected the standard
`{success, executionId, output, metadata}` wrapper.

Fix: skip Response block formatting when `authType === INTERNAL_JWT` since
Response blocks are designed for external API consumers, not internal
workflow-to-workflow calls. Also extract `AuthType` constants from magic
strings across all auth type comparisons in the codebase.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* test(executor): add route-level tests for Response block auth gating

Verify that internal JWT callers receive standard format while external
callers (API key, session) get Response block formatting. Tests the
server-side condition directly using workflowHasResponseBlock and
createHttpResponseFromBlock with AuthType constants.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(testing): add AuthType to all hybrid auth test mocks

Route code now imports AuthType from @/lib/auth/hybrid, so test mocks
must export it too. Added AuthTypeMock to @sim/testing and included it
in all 15 test files that mock the hybrid auth module.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 16:56:02 -07:00

88 lines
2.0 KiB
TypeScript

/**
* @sim/testing - Shared testing utilities for Sim
*
* This package provides a comprehensive set of tools for writing tests:
* - Factories: Create mock data with sensible defaults
* - Builders: Fluent APIs for complex test scenarios
* - Mocks: Reusable mock implementations
* - Assertions: Semantic test assertions
*
* @example
* ```ts
* import {
* // Factories
* createBlock,
* createStarterBlock,
* createLinearWorkflow,
* createExecutionContext,
*
* // Builders
* WorkflowBuilder,
* ExecutionContextBuilder,
*
* // Assertions
* expectBlockExists,
* expectEdgeConnects,
* expectBlockExecuted,
* } from '@sim/testing'
*
* describe('MyFeature', () => {
* it('should work with a linear workflow', () => {
* const workflow = createLinearWorkflow(3)
* expectBlockExists(workflow.blocks, 'block-0', 'starter')
* expectEdgeConnects(workflow.edges, 'block-0', 'block-1')
* })
*
* it('should work with a complex workflow', () => {
* const workflow = WorkflowBuilder.branching().build()
* expectBlockCount(workflow, 5)
* })
* })
* ```
*/
export * from './assertions'
export * from './builders'
export * from './factories'
export {
AuthTypeMock,
auditMock,
clearRedisMocks,
createEnvMock,
createMockDb,
createMockFetch,
createMockFormDataRequest,
createMockGetEnv,
createMockLogger,
createMockRedis,
createMockRequest,
createMockResponse,
createMockSocket,
createMockStorage,
databaseMock,
defaultMockEnv,
defaultMockUser,
drizzleOrmMock,
envMock,
loggerMock,
type MockAuthResult,
type MockFetchResponse,
type MockHybridAuthResult,
type MockRedis,
type MockUser,
mockAuth,
mockCommonSchemas,
mockConsoleLogger,
mockCryptoUuid,
mockDrizzleOrm,
mockHybridAuth,
mockKnowledgeSchemas,
mockUuid,
requestUtilsMock,
setupCommonApiMocks,
setupGlobalFetchMock,
setupGlobalStorageMocks,
telemetryMock,
} from './mocks'
export * from './types'