mirror of
https://github.com/hanzoai/insights.git
synced 2026-11-02 09:24:48 +00:00
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.
65 lines
2.6 KiB
TypeScript
65 lines
2.6 KiB
TypeScript
import { serve } from '@hono/node-server'
|
||
import Redis from 'ioredis'
|
||
import type { AddressInfo } from 'node:net'
|
||
|
||
import { createApp } from '@/hono/app'
|
||
|
||
import type { IntegrationEnv, IntegrationHarness } from './types'
|
||
|
||
// Pinned test DB so we don't collide with the dev Redis (DB 0). Must be in
|
||
// 0–15 (Redis default DB count). FLUSHDB at boot is safe because the test
|
||
// owns this DB exclusively. Override via TEST_REDIS_DB if your local Redis is
|
||
// configured with a different db count.
|
||
const TEST_REDIS_DB = parseInt(process.env.TEST_REDIS_DB ?? '15', 10)
|
||
// Integration test harness targets a local dev Redis; production paths set REDIS_URL.
|
||
// nosemgrep: trailofbits.generic.redis-unencrypted-transport.redis-unencrypted-transport
|
||
const TEST_REDIS_URL = process.env.TEST_REDIS_URL ?? process.env.REDIS_URL ?? 'redis://localhost:6379'
|
||
|
||
async function startTestRedis(): Promise<InstanceType<typeof Redis>> {
|
||
const redis = new Redis(TEST_REDIS_URL, {
|
||
db: TEST_REDIS_DB,
|
||
lazyConnect: true,
|
||
maxRetriesPerRequest: 1,
|
||
connectTimeout: 2000,
|
||
})
|
||
try {
|
||
await redis.connect()
|
||
} catch (err) {
|
||
await redis.quit().catch(() => undefined)
|
||
throw new Error(
|
||
`Hono integration harness needs Redis at ${TEST_REDIS_URL} (db ${TEST_REDIS_DB}). ` +
|
||
`Boot the dev stack with \`./bin/start\`, or override TEST_REDIS_URL/TEST_REDIS_DB. Cause: ${String(err)}`
|
||
)
|
||
}
|
||
await redis.flushdb()
|
||
return redis
|
||
}
|
||
|
||
export async function startHonoHarness(env: IntegrationEnv): Promise<IntegrationHarness> {
|
||
process.env.INSIGHTS_API_BASE_URL = env.apiBaseUrl
|
||
|
||
// Start a temporary listener on port 0 to discover a free port, then
|
||
// set MCP_APPS_BASE_URL before creating the app so the ResourceCatalog
|
||
// (which snapshots env at construction time) sees the correct URL.
|
||
const probe = serve({ fetch: () => new Response(), port: 0 })
|
||
const probePort = (probe.address() as AddressInfo).port
|
||
await new Promise<void>((resolve) => probe.close(() => resolve()))
|
||
|
||
const baseUrl = new URL(`http://127.0.0.1:${probePort}`)
|
||
process.env.MCP_APPS_BASE_URL = baseUrl.toString().replace(/\/$/, '')
|
||
|
||
const redis = await startTestRedis()
|
||
const { app, warmup } = createApp(redis as unknown as Parameters<typeof createApp>[0])
|
||
await warmup()
|
||
|
||
const server = serve({ fetch: app.fetch, port: probePort })
|
||
|
||
return {
|
||
baseUrl,
|
||
stop: async () => {
|
||
await new Promise<void>((resolve) => server.close(() => resolve()))
|
||
await redis.quit().catch(() => undefined)
|
||
},
|
||
}
|
||
}
|