Files
insights/services/mcp/tests/unit/skills-generated.test.ts
zeekay e552a2f764 Point the MCP tools at /v1/
The generator already resolves operations under /v1/ (40d120dbf7), and
the Python docstrings and prompts it copies say /v1/ too, but the
checked-in output still carried upstream's /api/ paths, so 771 tool
calls went to a prefix insights no longer serves.  Bring the generated
tools, types and schema in line with what the generator emits for the
/v1/ mount, and move the tests that assert those paths.

Left as they are: POST /api/orders and /api/feed are customer span
names in tool examples, and the connection tool's `api/projects/2/...`
mirrors insights_connection.py's help text.

Claude-Session: https://claude.ai/code/session_01TUxvfuta1Z44KVNYuAz71F
2026-09-24 15:00:46 -07:00

63 lines
2.3 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
import { getToolByName } from '@/shared/test-utils'
import { GENERATED_TOOLS } from '@/tools/generated/skills'
import { SKILL_DEPRECATED_ALIASES } from '@/tools/skills/deprecatedAliases'
import type { Context } from '@/tools/types'
function createContext(requestReturnValue: unknown): { context: Context; requestMock: ReturnType<typeof vi.fn> } {
const requestMock = vi.fn().mockResolvedValue(requestReturnValue)
const context = {
api: {
request: requestMock,
},
stateManager: {
getProjectId: vi.fn().mockResolvedValue('17'),
},
} as unknown as Context
return { context, requestMock }
}
describe('Generated skill-* tools', () => {
it('uses skill_name in generated skill-archive schema', () => {
const tool = getToolByName(GENERATED_TOOLS, 'skill-archive')
const parsed = tool.schema.parse({ skill_name: 'skills-store' })
expect(parsed).toEqual({ skill_name: 'skills-store' })
expect(() => tool.schema.parse({ name: 'skills-store' })).toThrow()
})
it('wires skill-archive to POST /name/{skill_name}/archive/', async () => {
const { context, requestMock } = createContext(undefined)
const tool = getToolByName(GENERATED_TOOLS, 'skill-archive')
const result = await tool.handler(context, { skill_name: 'skills-store' })
expect(requestMock).toHaveBeenCalledWith({
method: 'POST',
path: '/v1/projects/17/llm_skills/name/skills-store/archive/',
})
expect(result).toBeUndefined()
})
it('deprecated llma-skill-* alias forwards to the renamed handler and annotates the response', async () => {
const { context, requestMock } = createContext({ name: 'skills-store' })
const alias = SKILL_DEPRECATED_ALIASES['llma-skill-get']!()
expect(alias.name).toBe('llma-skill-get')
const result = (await alias.handler(context, { skill_name: 'skills-store' })) as Record<string, unknown>
expect(requestMock).toHaveBeenCalledWith(
expect.objectContaining({
method: 'GET',
path: '/v1/projects/17/llm_skills/name/skills-store/',
})
)
expect(result.name).toBe('skills-store')
expect(result._deprecation_notice).toContain('skill-get')
})
})