Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test(agent): use generic test data for customToolId resolution tests
  • Loading branch information
waleedlatif1 committed Feb 12, 2026
commit 5a8752f6a6058799c4b1096d7b03133d8eae299a
82 changes: 33 additions & 49 deletions apps/sim/executor/handlers/agent/agent-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1905,51 +1905,37 @@
describe('customToolId resolution - DB as source of truth', () => {
const staleInlineSchema = {
function: {
name: 'buttonTemplate',
description: 'Creates a button template',
name: 'formatReport',
description: 'Formats a report',
parameters: {
type: 'object',
properties: {
sender_id: { type: 'string', description: 'Sender ID' },
header_value: { type: 'string', description: 'Header text' },
body_value: { type: 'string', description: 'Body text' },
button_array: {
type: 'array',
items: { type: 'string' },
description: 'Button labels',
},
title: { type: 'string', description: 'Report title' },
content: { type: 'string', description: 'Report content' },
},
required: ['sender_id', 'header_value', 'body_value', 'button_array'],
required: ['title', 'content'],
},
},
}

const dbSchema = {
function: {
name: 'buttonTemplate',
description: 'Creates a button template',
name: 'formatReport',
description: 'Formats a report',
parameters: {
type: 'object',
properties: {
sender_id: { type: 'string', description: 'Sender ID' },
header_value: { type: 'string', description: 'Header text' },
body_value: { type: 'string', description: 'Body text' },
button_array: {
type: 'array',
items: { type: 'string' },
description: 'Button labels',
},
channel: { type: 'string', description: 'Channel name' },
title: { type: 'string', description: 'Report title' },
content: { type: 'string', description: 'Report content' },
format: { type: 'string', description: 'Output format' },
},
required: ['sender_id', 'header_value', 'body_value', 'button_array', 'channel'],
required: ['title', 'content', 'format'],
},
},
}

const staleInlineCode =
'return JSON.stringify({ type: "button", phone: sender_id, header: header_value, body: body_value, buttons: button_array });'
const dbCode =
'if (channel === "whatsapp") { return JSON.stringify({ type: "button", phone: sender_id, header: header_value, body: body_value, buttons: button_array }); }'
const staleInlineCode = 'return { title, content };'
const dbCode = 'return { title, content, format };'

function mockFetchForCustomTool(toolId: string) {
mockFetch.mockImplementation((url: string) => {
Expand All @@ -1962,7 +1948,7 @@
data: [
{
id: toolId,
title: 'buttonTemplate',
title: 'formatReport',
schema: dbSchema,
code: dbCode,
},
Expand Down Expand Up @@ -2010,13 +1996,13 @@

const inputs = {
model: 'gpt-4o',
userPrompt: 'Send a button template',
userPrompt: 'Format a report',
apiKey: 'test-api-key',
tools: [
{
type: 'custom-tool',
customToolId: toolId,
title: 'buttonTemplate',
title: 'formatReport',
schema: staleInlineSchema,
code: staleInlineCode,
usageControl: 'auto' as const,
Expand All @@ -2033,9 +2019,9 @@
const tools = providerCall[1].tools

expect(tools.length).toBe(1)
// DB schema wins over stale inline — includes channel param
expect(tools[0].parameters.required).toContain('channel')
expect(tools[0].parameters.properties).toHaveProperty('channel')
// DB schema wins over stale inline — includes format param
expect(tools[0].parameters.required).toContain('format')

Check failure on line 2023 in apps/sim/executor/handlers/agent/agent-handler.test.ts

View workflow job for this annotation

GitHub Actions / Test and Build / Test and Build

executor/handlers/agent/agent-handler.test.ts > AgentBlockHandler > execute > customToolId resolution - DB as source of truth > should always fetch latest schema from DB when customToolId is present

AssertionError: expected [ 'title', 'content' ] to include 'format' ❯ executor/handlers/agent/agent-handler.test.ts:2023:46
expect(tools[0].parameters.properties).toHaveProperty('format')
})

it('should fetch from DB when customToolId has no inline schema', async () => {
Expand All @@ -2044,7 +2030,7 @@

const inputs = {
model: 'gpt-4o',
userPrompt: 'Send a button template',
userPrompt: 'Format a report',
apiKey: 'test-api-key',
tools: [
{
Expand All @@ -2063,23 +2049,23 @@
const providerCall = mockExecuteProviderRequest.mock.calls[0]
const tools = providerCall[1].tools

expect(tools.length).toBe(1)

Check failure on line 2052 in apps/sim/executor/handlers/agent/agent-handler.test.ts

View workflow job for this annotation

GitHub Actions / Test and Build / Test and Build

executor/handlers/agent/agent-handler.test.ts > AgentBlockHandler > execute > customToolId resolution - DB as source of truth > should fetch from DB when customToolId has no inline schema

AssertionError: expected +0 to be 1 // Object.is equality - Expected + Received - 1 + 0 ❯ executor/handlers/agent/agent-handler.test.ts:2052:30
expect(tools[0].name).toBe('buttonTemplate')
expect(tools[0].parameters.required).toContain('channel')
expect(tools[0].name).toBe('formatReport')
expect(tools[0].parameters.required).toContain('format')
})

it('should fall back to inline schema when DB fetch fails and inline exists', async () => {
mockFetchFailure()

const inputs = {
model: 'gpt-4o',
userPrompt: 'Send a button template',
userPrompt: 'Format a report',
apiKey: 'test-api-key',
tools: [
{
type: 'custom-tool',
customToolId: 'custom-tool-123',
title: 'buttonTemplate',
title: 'formatReport',
schema: staleInlineSchema,
code: staleInlineCode,
usageControl: 'auto' as const,
Expand All @@ -2095,18 +2081,17 @@
const providerCall = mockExecuteProviderRequest.mock.calls[0]
const tools = providerCall[1].tools

// Falls back to inline schema (4 params, no channel)
expect(tools.length).toBe(1)
expect(tools[0].name).toBe('buttonTemplate')
expect(tools[0].parameters.required).not.toContain('channel')
expect(tools[0].name).toBe('formatReport')
expect(tools[0].parameters.required).not.toContain('format')
})

it('should return null when DB fetch fails and no inline schema exists', async () => {
mockFetchFailure()

const inputs = {
model: 'gpt-4o',
userPrompt: 'Send a button template',
userPrompt: 'Format a report',
apiKey: 'test-api-key',
tools: [
{
Expand Down Expand Up @@ -2145,13 +2130,13 @@

const inputs = {
model: 'gpt-4o',
userPrompt: 'Send a button template',
userPrompt: 'Format a report',
apiKey: 'test-api-key',
tools: [
{
type: 'custom-tool',
customToolId: toolId,
title: 'buttonTemplate',
title: 'formatReport',
schema: staleInlineSchema,
code: staleInlineCode,
usageControl: 'auto' as const,
Expand All @@ -2166,10 +2151,9 @@
expect(capturedTools.length).toBe(1)
expect(typeof capturedTools[0].executeFunction).toBe('function')

await capturedTools[0].executeFunction({ sender_id: '123', channel: 'whatsapp' })
await capturedTools[0].executeFunction({ title: 'Q1', format: 'pdf' })

// Should use DB code, not stale inline code
expect(mockExecuteTool).toHaveBeenCalledWith(

Check failure on line 2156 in apps/sim/executor/handlers/agent/agent-handler.test.ts

View workflow job for this annotation

GitHub Actions / Test and Build / Test and Build

executor/handlers/agent/agent-handler.test.ts > AgentBlockHandler > execute > customToolId resolution - DB as source of truth > should use DB code for executeFunction when customToolId resolves

AssertionError: expected "spy" to be called with arguments: [ 'function_execute', …(3) ] Received: 1st spy call: [ "function_execute", - ObjectContaining { - "code": "return { title, content, format };", + { + "_context": { + "isDeployedContext": undefined, + "userId": undefined, + "workflowId": "test-workflow", + "workspaceId": undefined, + }, + "blockData": {}, + "blockNameMapping": {}, + "blockOutputSchemas": {}, + "code": "return { title, content };", + "envVars": {}, + "format": "pdf", + "isCustomTool": true, + "timeout": 5400000, + "title": "Q1", + "workflowVariables": {}, }, false, - Any<Object>, + { + "activeExecutionPath": Set {}, + "blockLogs": [], + "blockStates": Map {}, + "completedLoops": Set {}, + "decisions": { + "condition": Map {}, + "router": Map {}, + }, + "environmentVariables": {}, + "executedBlocks": Set {}, + "loopExecutions": Map {}, + "metadata": { + "duration": 0, + "startTime": "2026-02-12T20:41:39.746Z", + }, + "workflow": { + "blocks": [], + "connections": [], + "loops": {}, + "version": "1.0.0", + }, + "workflowId": "test-workflow", + }, ] Number of calls: 1 ❯ executor/handlers/agent/agent-handler.test.ts:2156:33
'function_execute',
expect.objectContaining({
code: dbCode,
Expand All @@ -2187,7 +2171,7 @@
tools: [
{
type: 'custom-tool',
title: 'inlineTool',
title: 'formatReport',
schema: staleInlineSchema,
code: staleInlineCode,
usageControl: 'auto' as const,
Expand All @@ -2209,8 +2193,8 @@
const tools = providerCall[1].tools

expect(tools.length).toBe(1)
expect(tools[0].name).toBe('buttonTemplate')
expect(tools[0].parameters.required).not.toContain('channel')
expect(tools[0].name).toBe('formatReport')
expect(tools[0].parameters.required).not.toContain('format')
})
})
})
Expand Down
Loading