Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
35 changes: 35 additions & 0 deletions apps/sim/lib/sim-search/live/hex-mcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ describe('Hex source retrieval', () => {
await expect(readHexMcp(client({ workspace: OTHER }), reference)).rejects.toThrow(/workspace/i)
})

it('withholds notebook source when the provider workspace changes during paging', async () => {
const api = client()
let connectedWorkspace = WORKSPACE
const changingWorkspace: ManagedSearchMcpClient = {
async call(name, args) {
if (name === 'get_me') return { org: { id: connectedWorkspace } }
const result = await api.call(name, args)
if (name === 'list_cells') connectedWorkspace = OTHER
return result
},
}

await expect(readHexMcp(changingWorkspace, reference)).rejects.toThrow(/workspace/i)
})

it.each([
{ ...metadata, id: OTHER },
{ ...metadata, trashedAt: '2026-01-01T13:00:00Z' },
Expand Down Expand Up @@ -253,4 +268,24 @@ describe('Hex source retrieval', () => {
)
).rejects.toThrow(/page limit/i)
})

it('reads a complete eight-page notebook within the managed request budget', async () => {
const api = client({
pages: Array.from({ length: 8 }, (_, index) => ({
values: [cell(`cell-${index}`, 'MARKDOWN', `Source page ${index}`)],
pagination: { after: index === 7 ? null : `page-${index}` },
})),
})
let requests = 0
const budgetedClient: ManagedSearchMcpClient = {
call(name, args) {
if (++requests > 12) throw new Error('Managed request budget exceeded')
return api.call(name, args)
},
}

const result = await readHexMcp(budgetedClient, reference)
expect(result.content).toContain('Source page 0')
expect(result.content).toContain('Source page 7')
})
})
2 changes: 2 additions & 0 deletions apps/sim/lib/sim-search/live/hex-mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ export async function readHexMcp(
const current = await project(client, reference.id, workspaceId)
if (!current || current.revision !== before.revision)
invalid('The Hex project changed while it was being read. Search again.')
if ((await workspace(client)) !== workspaceId)
invalid('The Hex workspace changed while it was being read. Search again.')
return { ...current, content: parts.join('\n\n') }
}
if (
Expand Down
Loading