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.
118 lines
4.0 KiB
TypeScript
118 lines
4.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { formatResponse } from '@/lib/response'
|
|
|
|
describe('formatResponse', () => {
|
|
it('formats simple objects with toon', () => {
|
|
const data = {
|
|
id: 123,
|
|
name: 'Test',
|
|
active: true,
|
|
}
|
|
const result = formatResponse(data)
|
|
expect(result).toContain('id: 123')
|
|
expect(result).toContain('name: Test')
|
|
expect(result).toContain('active: true')
|
|
})
|
|
|
|
it('formats nested query keys as JSON', () => {
|
|
const data = {
|
|
id: 123,
|
|
name: 'Test',
|
|
query: {
|
|
kind: 'EventsQuery',
|
|
select: ['*'],
|
|
limit: 100,
|
|
},
|
|
}
|
|
const result = formatResponse(data)
|
|
expect(result).toContain('id: 123')
|
|
expect(result).toContain('name: Test')
|
|
expect(result).toContain('query:')
|
|
|
|
const expectedJson = JSON.stringify(data.query, null, 2)
|
|
expect(result).toContain(expectedJson)
|
|
})
|
|
|
|
it('formats deeply nested query keys as JSON', () => {
|
|
const data = {
|
|
insight: {
|
|
id: 456,
|
|
metadata: {
|
|
query: {
|
|
kind: 'TrendsQuery',
|
|
series: [{ event: 'pageview' }],
|
|
},
|
|
},
|
|
},
|
|
}
|
|
const result = formatResponse(data)
|
|
expect(result).toContain('id: 456')
|
|
expect(result).toContain('query:')
|
|
|
|
const expectedJson = JSON.stringify(data.insight.metadata.query, null, 2)
|
|
expect(result).toContain(expectedJson)
|
|
})
|
|
|
|
it('handles arrays', () => {
|
|
const data = {
|
|
flags: [
|
|
{ id: 1, key: 'flag-1' },
|
|
{ id: 2, key: 'flag-2' },
|
|
],
|
|
}
|
|
const result = formatResponse(data)
|
|
expect(result).toContain('flag-1')
|
|
expect(result).toContain('flag-2')
|
|
})
|
|
|
|
it('handles null and undefined values', () => {
|
|
const data = {
|
|
value: null,
|
|
other: undefined,
|
|
query: null,
|
|
}
|
|
const result = formatResponse(data)
|
|
expect(result).toBeTruthy()
|
|
})
|
|
|
|
it('returns string input verbatim (no TOON, no character expansion)', () => {
|
|
// Regression: previously a string handler result was object-rest-destructured
|
|
// in the MCP wrapper, turning 'foo' into {'0':'f','1':'o','2':'o'} before
|
|
// hitting formatResponse. formatResponse itself must pass strings through
|
|
// unchanged so the wrapper's pass-through is correct.
|
|
const jsonPayload = '{"name":"query-trends","title":"Run a trends query"}'
|
|
const result = formatResponse(jsonPayload)
|
|
|
|
expect(result).toBe(jsonPayload)
|
|
// The character-indexed regression signature must never appear.
|
|
expect(result).not.toMatch(/"0":\s*"\{"/)
|
|
expect(result).not.toMatch(/"1":\s*"\\"/)
|
|
})
|
|
|
|
it('does NOT truncate even for very large responses (MCP must return full data)', () => {
|
|
// IMPORTANT: truncation was removed because the MCP must never silently
|
|
// drop data — downstream clients are responsible for any size handling.
|
|
// This test exists to catch anyone re-introducing truncation.
|
|
const hugeValue = 'X'.repeat(500_000)
|
|
const data = { payload: hugeValue }
|
|
|
|
const result = formatResponse(data)
|
|
|
|
expect(result.length).toBeGreaterThan(500_000)
|
|
expect(result).toContain(hugeValue)
|
|
expect(result).not.toContain('[Response truncated')
|
|
expect(result).not.toContain('Response truncated')
|
|
expect(result).not.toContain('exceeded maximum length')
|
|
})
|
|
|
|
it('does NOT truncate large string inputs either', () => {
|
|
const hugeString = 'Y'.repeat(500_000)
|
|
const result = formatResponse(hugeString)
|
|
|
|
expect(result).toBe(hugeString)
|
|
expect(result.length).toBe(500_000)
|
|
expect(result).not.toContain('[Response truncated')
|
|
})
|
|
})
|