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.
123 lines
4.6 KiB
TypeScript
123 lines
4.6 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { extractClientInfoFromBody } from '@/lib/mcp-client-info'
|
|
|
|
function initializeMessage(
|
|
clientInfo: { name?: string; version?: string } = { name: 'claude-code', version: '1.0.0' },
|
|
protocolVersion = '2025-03-26'
|
|
): object {
|
|
return {
|
|
jsonrpc: '2.0',
|
|
id: 1,
|
|
method: 'initialize',
|
|
params: {
|
|
protocolVersion,
|
|
clientInfo,
|
|
capabilities: {},
|
|
},
|
|
}
|
|
}
|
|
|
|
function postRequest(body: unknown): Request {
|
|
return new Request('https://mcp.example.com/mcp', {
|
|
method: 'POST',
|
|
body: typeof body === 'string' ? body : JSON.stringify(body),
|
|
headers: { 'Content-Type': 'application/json' },
|
|
})
|
|
}
|
|
|
|
describe('extractClientInfoFromBody', () => {
|
|
it('extracts clientInfo + protocolVersion from a single initialize message', async () => {
|
|
const info = await extractClientInfoFromBody(postRequest(initializeMessage()))
|
|
expect(info).toEqual({
|
|
clientName: 'claude-code',
|
|
clientVersion: '1.0.0',
|
|
protocolVersion: '2025-03-26',
|
|
})
|
|
})
|
|
|
|
it('extracts clientInfo from a JSON-RPC batch', async () => {
|
|
const batch = [
|
|
{ jsonrpc: '2.0', method: 'notifications/initialized' },
|
|
initializeMessage({ name: 'Cursor', version: '0.42.1' }, '2025-03-26'),
|
|
]
|
|
const info = await extractClientInfoFromBody(postRequest(batch))
|
|
expect(info.clientName).toBe('Cursor')
|
|
expect(info.clientVersion).toBe('0.42.1')
|
|
})
|
|
|
|
it('returns empty object when the body has no initialize message', async () => {
|
|
const info = await extractClientInfoFromBody(postRequest({ jsonrpc: '2.0', method: 'tools/list', id: 2 }))
|
|
expect(info).toEqual({})
|
|
})
|
|
|
|
// 2026-07-28 stateless clients never send `initialize` — identity rides in
|
|
// each request's `_meta`. Without the fallback, all stateless traffic loses
|
|
// client attribution in analytics and wide logs.
|
|
it('extracts clientInfo from per-request _meta on a stateless request', async () => {
|
|
const info = await extractClientInfoFromBody(
|
|
postRequest({
|
|
jsonrpc: '2.0',
|
|
id: 3,
|
|
method: 'tools/call',
|
|
params: {
|
|
name: 'organization-get',
|
|
arguments: {},
|
|
_meta: {
|
|
'io.modelcontextprotocol/protocolVersion': '2026-07-28',
|
|
'io.modelcontextprotocol/clientInfo': { name: 'stateless-client', version: '2.0.0' },
|
|
},
|
|
},
|
|
})
|
|
)
|
|
expect(info).toEqual({
|
|
clientName: 'stateless-client',
|
|
clientVersion: '2.0.0',
|
|
protocolVersion: '2026-07-28',
|
|
})
|
|
})
|
|
|
|
it('prefers initialize clientInfo over per-request _meta in a mixed batch', async () => {
|
|
const batch = [
|
|
{
|
|
jsonrpc: '2.0',
|
|
id: 1,
|
|
method: 'tools/list',
|
|
params: { _meta: { 'io.modelcontextprotocol/protocolVersion': '2026-07-28' } },
|
|
},
|
|
initializeMessage({ name: 'legacy-client', version: '1.2.3' }, '2025-03-26'),
|
|
]
|
|
const info = await extractClientInfoFromBody(postRequest(batch))
|
|
expect(info.clientName).toBe('legacy-client')
|
|
expect(info.protocolVersion).toBe('2025-03-26')
|
|
})
|
|
|
|
it('returns empty object for GET requests (SSE endpoint)', async () => {
|
|
const req = new Request('https://mcp.example.com/sse', { method: 'GET' })
|
|
const info = await extractClientInfoFromBody(req)
|
|
expect(info).toEqual({})
|
|
})
|
|
|
|
it('returns empty object for malformed JSON', async () => {
|
|
const info = await extractClientInfoFromBody(postRequest('not-json'))
|
|
expect(info).toEqual({})
|
|
})
|
|
|
|
it('does not consume the original request body', async () => {
|
|
const req = postRequest(initializeMessage())
|
|
await extractClientInfoFromBody(req)
|
|
// The downstream MCP transport must still be able to read the body.
|
|
const body = await req.text()
|
|
expect(body).toContain('"method":"initialize"')
|
|
})
|
|
|
|
it('sanitizes clientName/version values', async () => {
|
|
// sanitizeHeaderValue strips control characters and caps length — we
|
|
// just smoke-test that a value with embedded newlines comes out clean.
|
|
const info = await extractClientInfoFromBody(
|
|
postRequest(initializeMessage({ name: 'claude-code\nX-Injected: evil', version: '1.0' }))
|
|
)
|
|
expect(info.clientName).not.toContain('\n')
|
|
})
|
|
})
|