Files
insights-js/packages/ai/tests/gemini.integration.test.ts
zeekay ec6f6b50c1 chore: kill ALL posthog — zero refs, zero filenames (1452 -> 0)
We own the ingestion server (hanzoai/insights: Django + rust/capture + nodejs
plugin) AND this SDK, so there is no external wire contract to preserve. The
server is already 100% posthog-free; this SDK was the last laggard.

- $last_posthog_reset -> $last_insights_reset. This FIXES A LIVE MISMATCH: the
  server taxonomy (insights/taxonomy/taxonomy.py, insights/insightsql/ai.py)
  already expected the insights form while the SDK emitted the posthog form.
- __PosthogExtensions__ -> __InsightsExtensions__; all PostHog/posthog/POSTHOG
  identifiers -> Insights/insights/INSIGHTS (src, tests, playground, playwright,
  scripts, rrweb subpackages, package.json keywords).
- Hosts: DEFAULT_PLUGIN_HOST + DEFAULT_NUXT_HOST + the core host default pointed
  at PostHog's cloud (us.i.posthog.com) — a real bug. All -> insights.hanzo.ai.
- Removed the us-assets/eu-assets CDN split in getRemoteConfig (PostHog-specific;
  Hanzo serves remote config from the same host) — it had degenerated to a no-op.
- Fixed generate-docs writing to a stray references/@hanzo/ subdir.
- Renamed the 3 posthog-named test files; dropped 58MB of stale reference
  snapshots named for upstream posthog versions we never shipped (they are
  generated output — references/ is now gitignored).

Verified: typecheck errors 42 (HEAD) -> 18 (all pre-existing test-mock
looseness); types package 0; every package.json valid with @hanzo/* names.
Guard: grep -rioE 'posthog' packages ... | wc -l  => 0
2026-07-16 09:09:18 -07:00

60 lines
2.1 KiB
TypeScript

// Integration tests for Gemini generateContent.
// These tests require a real GEMINI_API_KEY and proper ESM transform configuration.
// They are skipped entirely when no API key is present.
//
// To run: GEMINI_API_KEY=<key> jest --testPathPattern=gemini.integration \
// --transformIgnorePatterns='node_modules/(?!(@google/genai|p-retry|is-network-error)/)'
const GEMINI_API_KEY = process.env.GEMINI_API_KEY
if (!GEMINI_API_KEY) {
test.skip('Gemini integration tests require GEMINI_API_KEY', () => {})
} else {
// Dynamic imports to avoid ESM parse failures when @google/genai
// transitive deps are not configured in transformIgnorePatterns.
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
const { Insights } = require('@hanzo/insights-node')
jest.mock('@hanzo/insights-node', () => ({
Insights: jest.fn().mockImplementation(() => ({
capture: jest.fn(),
captureImmediate: jest.fn(),
privacyMode: false,
})),
}))
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
const InsightsGemini = require('../src/gemini').default
describe('Gemini Integration Tests', () => {
let mockInsightsClient: any
let client: any
beforeEach(() => {
mockInsightsClient = new Insights('test-key')
client = new InsightsGemini({
apiKey: GEMINI_API_KEY,
insights: mockInsightsClient,
})
})
test('generateContent captures stop_reason', async () => {
const response = await client.models.generateContent({
model: 'gemini-2.0-flash',
contents: 'Say hi',
insightsDistinctId: 'test-id',
})
expect(response.text).toBeDefined()
const captureCall = mockInsightsClient.capture.mock.calls.find((call: any[]) => call[0].event === '$ai_generation')
expect(captureCall).toBeDefined()
const props = captureCall![0].properties
expect(props.$ai_provider).toBe('gemini')
expect(props.$ai_stop_reason).toBeDefined()
expect(typeof props.$ai_stop_reason).toBe('string')
expect(props.$ai_input_tokens).toBeGreaterThan(0)
})
})
}