Files
insights/services/mcp/vitest.workers.config.mts
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

50 lines
2.2 KiB
TypeScript

import { cloudflareTest } from '@cloudflare/vitest-pool-workers'
import tsconfigPaths from 'vite-tsconfig-paths'
import { defineConfig } from 'vitest/config'
import { dispatchHandlers } from './tests/workers/fixtures/handlers'
// vitest-pool-workers runs tests inside the real workerd runtime. Workerd's
// fetch can't be patched from the test process, so MSW's setupServer-style
// global interception doesn't apply here. Miniflare's `outboundService` is
// invoked from this Node config whenever the worker makes an outbound HTTP
// call — that's the workerd-equivalent escape hatch. We hand each request to
// MSW's `RequestHandler#run()` so handlers declared with the standard
// `http.*` DSL (see tests/workers/fixtures/handlers.ts) match and respond.
// Fixtures are real Insights API responses captured from a local dev server.
export default defineConfig({
plugins: [
cloudflareTest({
wrangler: { configPath: './wrangler.jsonc' },
miniflare: {
bindings: {
// Override secrets loaded from .env. Empty values
// make init()'s analytics / observability paths short-
// circuit cleanly.
INSIGHTS_API_BASE_URL: '',
INSIGHTS_PUBLIC_URL: '',
INSIGHTS_ANALYTICS_API_KEY: '',
INSIGHTS_ANALYTICS_HOST: '',
INSIGHTS_MCP_APPS_ANALYTICS_BASE_URL: '',
INSIGHTS_UI_APPS_TOKEN: '',
// Generic test marker. Code can short-circuit features
// that need real network (e.g. context-mill GitHub
// fetch in src/resources/index.ts).
TEST: '1',
},
outboundService: dispatchHandlers,
},
}),
tsconfigPaths({ root: '.' }),
],
test: {
name: 'workers',
include: ['tests/workers/**/*.test.ts'],
// The first test in each file pays workerd + DurableObject cold-start
// overhead that can push it past the 5s default. Bump the ceiling so
// these tests don't flake on slower CI runners.
testTimeout: 15000,
},
})