Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

2.5 KB
Raw Blame
import { vi } from 'vitest'

vi.mock('cloudflare:workers', () => ({
    env: {
        INKEEP_API_KEY: undefined,
        POSTHOG_API_BASE_URL: undefined,
        POSTHOG_PUBLIC_URL: undefined,
        MCP_APPS_BASE_URL: undefined,
        POSTHOG_MCP_APPS_ANALYTICS_BASE_URL: undefined,
        POSTHOG_UI_APPS_TOKEN: undefined,
        POSTHOG_ANALYTICS_API_KEY: undefined,
        POSTHOG_ANALYTICS_HOST: undefined,
    },
}))

// Mock shared prompt files (generated by scripts/copy-instructions.ts, not checked in)
vi.mock('@shared/guidelines.md', () => ({
    default: '# Guidelines\nTest guidelines content.',
}))
vi.mock('@shared/parser_recipe_examples.yaml', () => ({
    default: 'rules: []\n',
}))

vi.mock('@/resources/ui-apps', async (importOriginal) => {
    const actual = await importOriginal<typeof import('@/resources/ui-apps')>()
    return {
        ...actual,
        registerUiAppResources: vi.fn().mockResolvedValue(undefined),
    }
})

vi.mock('@/resources/ui-apps.generated', async (importOriginal) => importOriginal())

// Product skills use a live release archive in production. Archive parsing and
// cache behavior have fixture-backed unit coverage; Hono wiring stays offline.
vi.mock('@/hono/skill-catalog-service', () => ({
    SkillCatalogService: class {
        getCatalog(): undefined {
            return undefined
        }
        async warmup(): Promise<void> {}
        start(): void {}
        stop(): void {}
        async poll(): Promise<void> {}
    },
}))

// Mock template imports that may not exist
vi.mock('@/templates/cli-proxy-command.md', async () => {
    try {
        return await vi.importActual('@/templates/cli-proxy-command.md')
    } catch {
        return { default: '' }
    }
})
vi.mock('@/templates/cli-proxy-tool.md', async () => {
    try {
        return await vi.importActual('@/templates/cli-proxy-tool.md')
    } catch {
        return { default: '' }
    }
})
vi.mock('@/templates/execute-sql-prompt.md', async () => {
    try {
        return await vi.importActual('@/templates/execute-sql-prompt.md')
    } catch {
        return { default: '' }
    }
})
vi.mock('@/templates/single-exec-instructions.md', async () => {
    try {
        return await vi.importActual('@/templates/single-exec-instructions.md')
    } catch {
        return { default: '' }
    }
})

// Mock @/tools/exec that may not exist
vi.mock('@/tools/exec', async () => {
    try {
        return await vi.importActual('@/tools/exec')
    } catch {
        return {
            createExecTool: vi.fn(() => ({ name: 'posthog', handler: vi.fn() })),
        }
    }
})