fix(esmole): truncate all tool responses; guard normalizes leading slash

This commit is contained in:
admin committed 2026-06-16 21:21:20 +05:00
1 parent ab5416f443
commit dd6ca2deff
10 files changed
+94 -16

No files matched your search

@@ -149,4 +149,42 @@ describe('registerEsTools', () => {
expect(calls[0].path).toBe('/_cluster/health')
expect(isCallToolResult(res)).toBe(true)
})
it('es_list_indices truncates an over-budget body', async () => {
const big = Array.from({ length: 8000 }, (_, i) => ({
index: 'index_with_a_fairly_long_name_' + i,
health: 'green'
}))
const calls: RequestCall[] = []
const { handlers, server } = fakeServer()
registerEsTools(server, fakeManager(calls, big))
const handler = handlers.get('es_list_indices')
if (handler === undefined) {
throw new Error('es_list_indices not registered')
}
const res = await handler({ connection: 'c', pattern: '*' })
expect(isCallToolResult(res)).toBe(true)
const payload = JSON.parse((res.content as Array<{ text: string }>)[0].text)
expect(payload.truncated).toBe(true)
expect(payload.body._truncated).toBe(true)
})
it('es_cluster_health truncates an over-budget body', async () => {
const big: Record<string, string> = {}
for (let i = 0; i < 8000; i++) {
big['node_with_a_fairly_long_name_' + i] = 'some descriptive value ' + i
}
const calls: RequestCall[] = []
const { handlers, server } = fakeServer()
registerEsTools(server, fakeManager(calls, big))
const handler = handlers.get('es_cluster_health')
if (handler === undefined) {
throw new Error('es_cluster_health not registered')
}
const res = await handler({ connection: 'c' })
expect(isCallToolResult(res)).toBe(true)
const payload = JSON.parse((res.content as Array<{ text: string }>)[0].text)
expect(payload.truncated).toBe(true)
expect(payload.body._truncated).toBe(true)
})
})