Files
insights/services/mcp/tests/cli/tool-call-properties.test.ts
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
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.
2026-08-01 15:44:40 -07:00

79 lines
3.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { buildToolCallProperties } from '@/cli/tool-call-properties'
import type { ExecInnerCallProperties } from '@/tools/exec'
import { getToolCategory, getToolDescription } from '@/tools/toolDefinitions'
// The CLI flushes these events on the error path, so anything value-carrying
// here (raw error messages, inputs) would ship caller content and API response
// bodies to usage analytics. `toEqual` pins the exact shape: reintroducing
// `error_message` or `input` fails every case below. Catalog metadata
// (category, clipped description) is safe by construction: it comes from the
// tool registry, never from the caller.
describe('buildToolCallProperties', () => {
const base: ExecInnerCallProperties = {
duration_ms: 42,
success: false,
output_format: 'text',
error_message: 'API error: {"detail": "secret notebook content …"}',
input: { markdown: 'private caller-supplied text' },
}
function catalogMetadata(toolName: string): Record<string, unknown> {
return {
$mcp_tool_category: getToolCategory(toolName),
$mcp_tool_description: getToolDescription(toolName),
}
}
it('never forwards error_message or input, only a value-free classification', () => {
expect(buildToolCallProperties('notebook-edit', base)).toEqual({
tool_name: 'notebook-edit',
$mcp_tool_name: 'notebook-edit',
$mcp_duration_ms: 42,
$mcp_is_error: true,
output_format: 'text',
error_class: 'error',
...catalogMetadata('notebook-edit'),
})
})
it.each([
['schema rejection', { validation_error: true }, { error_class: 'validation_error' }],
['typed API failure', { error_status: 429 }, { error_class: 'api_error', error_status: 429 }],
])('classifies a %s without carrying the message', (_name, extra, expected) => {
expect(buildToolCallProperties('feature-flag-get-all', { ...base, ...extra })).toEqual({
tool_name: 'feature-flag-get-all',
$mcp_tool_name: 'feature-flag-get-all',
$mcp_duration_ms: 42,
$mcp_is_error: true,
output_format: 'text',
...catalogMetadata('feature-flag-get-all'),
...expected,
})
})
it('omits error fields entirely on success', () => {
expect(buildToolCallProperties('feature-flag-get-all', { ...base, success: true })).toEqual({
tool_name: 'feature-flag-get-all',
$mcp_tool_name: 'feature-flag-get-all',
$mcp_duration_ms: 42,
$mcp_is_error: false,
output_format: 'text',
...catalogMetadata('feature-flag-get-all'),
})
})
it('stamps catalog metadata on catalogued tools and omits it for unknown names', () => {
// The CLI path silently shipped without category or description while the
// hosted server stamped both; this pins the two paths to the same catalog.
const catalogued = buildToolCallProperties('feature-flag-get-all', { ...base, success: true })
expect(catalogued.$mcp_tool_category).toBeTruthy()
expect(catalogued.$mcp_tool_description).toBeTruthy()
const unknown = buildToolCallProperties('not-a-real-tool', { ...base, success: true })
expect(unknown).not.toHaveProperty('$mcp_tool_category')
expect(unknown).not.toHaveProperty('$mcp_tool_description')
})
})