Files
insights/services/mcp/tests/integration/mcp-protocol.hono.integration.test.ts
zeekay 10e6fec4c0 debrand: the brand token is INSIGHTS_, and a wrong one stops the container
The rule table mapped HOG_ -> FN_ ahead of any POSTHOG rule, so POSTHOG_FOO
split into POST + HOG_ and came out POSTFN_FOO. Nothing sets that. The live
pods set INSIGHTS_SKIP_MIGRATION_CHECKS, which bin/migrate-check reads on the
container entrypoint, so the misspelling does not degrade a feature -- it runs
migrate --check against a database whose history this tree does not share and
the container never starts.

Both replacements are measured against the shipped tree rather than chosen:
every HOG_ name with a counterpart there is spelled INSIGHTS_ (HOG_QL ->
INSIGHTS_QL, HOG_FUNCTION_TEMPLATES -> INSIGHTS_FUNCTION_TEMPLATES, 12 of 12
determinate cases), and FN_ appears in it nowhere. Upstream carries 95 HOG_
tokens and zero FN_ ones, so repairing FN_ back out is exactly the inverse of
the bad rule and cannot collide with an upstream name.

The rule is fixed for the next convergence, and the tree it already produced is
repaired in the same commit -- the codemod is idempotent against its own output,
so it cannot undo this itself.
2026-08-01 17:42:28 -07:00

74 lines
3.1 KiB
TypeScript

import { afterAll, beforeAll } from 'vitest'
import { startHonoHarness } from './harness/hono'
import { loadIntegrationEnv, type IntegrationEnv, type IntegrationHarness } from './harness/types'
import {
defineAuthTests,
defineCatalogFilterTests,
defineHttpRouteTests,
defineJsonRpcEdgeCaseTests,
defineMcpProtocolTests,
defineResilienceTests,
defineResourceCatalogTests,
defineSessionLifecycleTests,
defineToolBehaviorTests,
defineUiAppProtocolTests,
type ProtocolTestHarness,
} from './mcp-protocol-suite'
// End-to-end MCP protocol test against the Hono runtime.
// - Real `@hono/node-server` listener (TCP + HTTP semantics, not `app.request`)
// - Real Insights stack at `TEST_INSIGHTS_API_BASE_URL` (defaults to localhost:8010)
// - Real personal API key from `TEST_INSIGHTS_PERSONAL_API_KEY`
//
// Boot the local Insights stack with `./bin/start` before running this suite.
// Ensure `.env.test` defines TEST_INSIGHTS_PERSONAL_API_KEY / TEST_ORG_ID /
// TEST_PROJECT_ID — matching the existing `tests/tools/*.integration.test.ts`.
//
// Suites wired here, each focused on a slice of MCP server behavior:
// - `defineMcpProtocolTests` — SDK-level initialize / list / call / read
// - `defineResilienceTests` — /sse redirects, unknown Mcp-Session-Id behavior
// - `defineUiAppProtocolTests` — ext-app metadata, HTML stub, static asset serving
// - `defineHttpRouteTests` — public routes (health, oauth, openai challenge, 405s)
// - `defineAuthTests` — bearer enforcement at the /mcp boundary
// - `defineJsonRpcEdgeCaseTests` — raw JSON-RPC (parse errors, batches, notifications, ping)
// - `defineSessionLifecycleTests` — initialize negotiation + repeated init
// - `defineResourceCatalogTests` — both UI and context-mill resources present and readable
// - `defineToolBehaviorTests` — real Insights tool calls and multi-step interactions
// - `defineCatalogFilterTests` — ?features= and ?tools= query-param filtering
let env: IntegrationEnv
let harness: IntegrationHarness
beforeAll(async () => {
env = loadIntegrationEnv()
harness = await startHonoHarness(env)
}, 30_000)
afterAll(async () => {
await harness?.stop()
})
const harnessFor = (): ProtocolTestHarness => ({
baseUrl: harness.baseUrl,
fetch: globalThis.fetch,
token: env.apiToken,
token2: env.apiToken2,
stateless: true,
gracefulUnknown: true,
orgId: env.orgId,
projectId: env.projectId,
publicRoutes: true,
})
defineMcpProtocolTests('Hono (real stack)', harnessFor)
defineResilienceTests('Hono (real stack)', harnessFor)
defineUiAppProtocolTests('Hono (real stack)', harnessFor)
defineHttpRouteTests('Hono (real stack)', harnessFor)
defineAuthTests('Hono (real stack)', harnessFor)
defineJsonRpcEdgeCaseTests('Hono (real stack)', harnessFor)
defineSessionLifecycleTests('Hono (real stack)', harnessFor)
defineResourceCatalogTests('Hono (real stack)', harnessFor)
defineToolBehaviorTests('Hono (real stack)', harnessFor)
defineCatalogFilterTests('Hono (real stack)', harnessFor)