mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
130 lines
5.4 KiB
TypeScript
130 lines
5.4 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { z } from 'zod'
|
|
|
|
import { toMcpInputSchema } from '@/hono/tool-catalog'
|
|
import { isToolCallPayload, type ToolResultPayload } from '@/lib/build-tool-result'
|
|
import { RENDER_UI_RESOURCE_URI, URI_MAP } from '@/resources/ui-apps.generated'
|
|
import { createRenderUiTool, getRenderableToolNames, RENDER_UI_TOOL_NAME } from '@/tools/render-ui'
|
|
import { type Context, type Tool, type ZodObjectAny } from '@/tools/types'
|
|
|
|
const mockContext = {
|
|
getDistinctId: async () => 'test-distinct-id',
|
|
} as unknown as Context
|
|
|
|
function makeTool(name: string, resourceUri?: string): Tool<ZodObjectAny> {
|
|
return {
|
|
name,
|
|
title: name,
|
|
description: `Tool ${name}`,
|
|
schema: z.object({}),
|
|
scopes: [],
|
|
annotations: { destructiveHint: false, idempotentHint: true, openWorldHint: false, readOnlyHint: true },
|
|
handler: async () => ({ ok: true }),
|
|
...(resourceUri ? { _meta: { ui: { resourceUri } } } : {}),
|
|
}
|
|
}
|
|
|
|
// Generated and opted-in custom apps are dispatchable; other custom apps are not.
|
|
const surveyTool = makeTool('survey-get', URI_MAP['survey'])
|
|
const queryTrendsTool = makeTool('query-trends', URI_MAP['query-results'])
|
|
const debugTool = makeTool('debug-tool', URI_MAP['debug'])
|
|
const plainTool = makeTool('plain-tool')
|
|
|
|
describe('render-ui tool', () => {
|
|
it('only counts tools whose UI app has a reusable view as renderable', () => {
|
|
expect(getRenderableToolNames([surveyTool, queryTrendsTool, debugTool, plainTool])).toEqual([
|
|
'survey-get',
|
|
'query-trends',
|
|
])
|
|
})
|
|
|
|
it('excludes non-read-only tools so render-ui cannot dispatch mutating tools', () => {
|
|
const mutatingTool = makeTool('survey-launch', URI_MAP['survey'])
|
|
mutatingTool.annotations.readOnlyHint = false
|
|
expect(getRenderableToolNames([mutatingTool])).toEqual([])
|
|
})
|
|
|
|
it('returns null when no tool has a renderable UI app', () => {
|
|
expect(createRenderUiTool([debugTool, plainTool], mockContext)).toBeNull()
|
|
})
|
|
|
|
it('restricts tool_name to the renderable tools', () => {
|
|
const tool = createRenderUiTool([surveyTool, queryTrendsTool, debugTool, plainTool], mockContext)
|
|
expect(tool).not.toBeNull()
|
|
const schema = tool!.schema
|
|
|
|
expect(schema.safeParse({ tool_name: 'survey-get', tool_input: { surveyId: 'abc' } }).success).toBe(true)
|
|
expect(schema.safeParse({ tool_name: 'query-trends', tool_input: { kind: 'TrendsQuery' } }).success).toBe(true)
|
|
// Non-UI and non-dispatchable custom-app tools are not valid enum members.
|
|
expect(schema.safeParse({ tool_name: 'plain-tool' }).success).toBe(false)
|
|
expect(schema.safeParse({ tool_name: 'debug-tool' }).success).toBe(false)
|
|
})
|
|
|
|
it('advertises the render-ui input schema', () => {
|
|
const tool = createRenderUiTool([surveyTool, queryTrendsTool, debugTool, plainTool], mockContext)
|
|
expect(tool).not.toBeNull()
|
|
|
|
expect(toMcpInputSchema(tool!.schema)).toMatchInlineSnapshot(`
|
|
{
|
|
"properties": {
|
|
"tool_input": {
|
|
"additionalProperties": {},
|
|
"description": "The generated input for that tool. The UI app uses it to fetch and render the visualization.",
|
|
"propertyNames": {
|
|
"type": "string",
|
|
},
|
|
"type": "object",
|
|
},
|
|
"tool_name": {
|
|
"description": "A tool that has a UI app — its visualization will be rendered for the user.",
|
|
"enum": [
|
|
"survey-get",
|
|
"query-trends",
|
|
],
|
|
"type": "string",
|
|
},
|
|
},
|
|
"required": [
|
|
"tool_name",
|
|
],
|
|
"type": "object",
|
|
}
|
|
`)
|
|
})
|
|
|
|
it('emits a render directive payload with the envelope and render-ui resourceUri', async () => {
|
|
const tool = createRenderUiTool([surveyTool, debugTool, plainTool], mockContext)!
|
|
const result = (await tool.handler(mockContext, {
|
|
tool_name: 'survey-get',
|
|
tool_input: { surveyId: 'abc' },
|
|
})) as ToolResultPayload
|
|
|
|
expect(isToolCallPayload(result)).toBe(true)
|
|
expect(result.structuredContent).toEqual({
|
|
tool_name: 'survey-get',
|
|
tool_input: { surveyId: 'abc' },
|
|
app_key: 'survey',
|
|
_analytics: { distinctId: 'test-distinct-id', toolName: RENDER_UI_TOOL_NAME },
|
|
})
|
|
expect(result._meta?.ui).toEqual({ resourceUri: RENDER_UI_RESOURCE_URI })
|
|
})
|
|
|
|
it('defaults tool_input to an empty object when omitted', async () => {
|
|
const tool = createRenderUiTool([surveyTool], mockContext)!
|
|
const result = (await tool.handler(mockContext, { tool_name: 'survey-get' })) as ToolResultPayload
|
|
expect((result.structuredContent as Record<string, unknown>).tool_input).toEqual({})
|
|
})
|
|
|
|
it('does not execute the inner tool — it only emits a render directive', async () => {
|
|
let innerCalled = false
|
|
const spyTool = makeTool('survey-get', URI_MAP['survey'])
|
|
spyTool.handler = async () => {
|
|
innerCalled = true
|
|
return { ok: true }
|
|
}
|
|
const tool = createRenderUiTool([spyTool], mockContext)!
|
|
await tool.handler(mockContext, { tool_name: 'survey-get' })
|
|
expect(innerCalled).toBe(false)
|
|
})
|
|
})
|