diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d1f8834..05b65d2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -104,8 +104,7 @@ jobs: import { writeFileSync } from 'node:fs'; const token = process.env.POSTHOG_PROJECT_TOKEN?.trim() || ''; - const host = - process.env.POSTHOG_HOST?.trim() || 'https://us.i.posthog.com'; + const host = process.env.POSTHOG_HOST?.trim() || ''; const source = [ '/** Generated in the release workspace by publish.yml. */', `export const BUILT_IN_POSTHOG_PROJECT_TOKEN = ${JSON.stringify(token)};`, diff --git a/src/telemetry-build-config.ts b/src/telemetry-build-config.ts index cd90435..76369a8 100644 --- a/src/telemetry-build-config.ts +++ b/src/telemetry-build-config.ts @@ -3,4 +3,4 @@ * the plugin bundle is built. Local and source builds keep telemetry disabled. */ export const BUILT_IN_POSTHOG_PROJECT_TOKEN = ''; -export const BUILT_IN_POSTHOG_HOST = 'https://us.i.posthog.com'; +export const BUILT_IN_POSTHOG_HOST = ''; diff --git a/src/telemetry.ts b/src/telemetry.ts index a7248b0..cb1f547 100644 --- a/src/telemetry.ts +++ b/src/telemetry.ts @@ -10,9 +10,7 @@ import { const DEFAULT_POSTHOG_HOST = 'https://us.i.posthog.com'; const POSTHOG_PROJECT_TOKEN = - process.env.POSTHOG_PROJECT_TOKEN || - process.env.POSTHOG_API_KEY || - BUILT_IN_POSTHOG_PROJECT_TOKEN; + process.env.POSTHOG_PROJECT_TOKEN || BUILT_IN_POSTHOG_PROJECT_TOKEN; const POSTHOG_HOST = process.env.POSTHOG_HOST || BUILT_IN_POSTHOG_HOST || DEFAULT_POSTHOG_HOST; diff --git a/test/plugin-package.test.ts b/test/plugin-package.test.ts index b84e475..6533d73 100644 --- a/test/plugin-package.test.ts +++ b/test/plugin-package.test.ts @@ -182,6 +182,35 @@ test('releases the root plugin package with plugin-specific artifacts', () => { ); }); +// codex/019fb375-79ec-7b02-b9d8-19fc4bfcc939/019fb37b-45f5-7d20-a5e9-82491ecced7d +test('keeps the release PostHog host explicit', () => { + const publishWorkflow = readFileSync( + join(pluginRoot, '.github', 'workflows', 'publish.yml'), + 'utf8' + ); + const telemetryBuildConfig = readFileSync( + join(pluginRoot, 'src', 'telemetry-build-config.ts'), + 'utf8' + ); + const telemetrySource = readFileSync( + join(pluginRoot, 'src', 'telemetry.ts'), + 'utf8' + ); + + assert.match( + publishWorkflow, + /const host = process\.env\.POSTHOG_HOST\?\.trim\(\) \|\| '';/ + ); + assert.match( + telemetryBuildConfig, + /export const BUILT_IN_POSTHOG_HOST = '';/, + ); + assert.match( + telemetrySource, + /const DEFAULT_POSTHOG_HOST = 'https:\/\/us\.i\.posthog\.com';/ + ); +}); + test('registers prompt submission and stop hooks from the plugin root', () => { const config = JSON.parse( readFileSync(join(pluginRoot, 'hooks', 'hooks.json'), 'utf8') diff --git a/test/prompt-hook.test.ts b/test/prompt-hook.test.ts index 5b6ba5a..bd7d176 100644 --- a/test/prompt-hook.test.ts +++ b/test/prompt-hook.test.ts @@ -3,6 +3,7 @@ import { execFileSync, spawn, spawnSync } from 'node:child_process'; import { once } from 'node:events'; import { cpSync, + existsSync, mkdirSync, mkdtempSync, readFileSync, @@ -294,6 +295,7 @@ test('the executable performs both phases without model-visible output', () => { assert.equal(storedPrompt?.previousAgentOutput, null); }); +// codex/019fb375-79ec-7b02-b9d8-19fc4bfcc939/019fb376-ca9b-7243-af54-c8affdbc0dc3 test('the executable flushes metadata-only telemetry before exiting', async () => { closeDb(); const capturePath = join(root, 'telemetry-capture.jsonl'); @@ -309,7 +311,7 @@ test('the executable flushes metadata-only telemetry before exiting', async () = env: { ...process.env, DO_NOT_TRACK: '', - POSTHOG_API_KEY: 'test-api-key', + POSTHOG_PROJECT_TOKEN: 'test-project-token', POSTHOG_HOST: receiver.host, RUDDER_HOME: process.env.RUDDER_HOME, }, @@ -330,7 +332,7 @@ test('the executable flushes metadata-only telemetry before exiting', async () = env: { ...process.env, DO_NOT_TRACK: '', - POSTHOG_API_KEY: 'test-api-key', + POSTHOG_PROJECT_TOKEN: 'test-project-token', POSTHOG_HOST: receiver.host, RUDDER_HOME: process.env.RUDDER_HOME, }, @@ -354,6 +356,44 @@ test('the executable flushes metadata-only telemetry before exiting', async () = } }); +// codex/019fb375-79ec-7b02-b9d8-19fc4bfcc939/019fb376-ca9b-7243-af54-c8affdbc0dc3 +test('the legacy PostHog API key does not enable telemetry', async () => { + closeDb(); + const capturePath = join(root, 'legacy-telemetry-capture.jsonl'); + const receiver = await startTelemetryReceiver(capturePath); + + try { + const stdout = execFileSync( + process.execPath, + [hookExecutable, '--source', 'codex'], + { + cwd: repo, + encoding: 'utf8', + env: { + ...process.env, + DO_NOT_TRACK: '', + POSTHOG_API_KEY: 'legacy-api-key', + POSTHOG_PROJECT_TOKEN: '', + POSTHOG_HOST: receiver.host, + RUDDER_HOME: process.env.RUDDER_HOME, + }, + input: JSON.stringify({ + hook_event_name: 'UserPromptSubmit', + session_id: 'legacy-telemetry-session', + turn_id: 'legacy-telemetry-turn', + prompt: 'This prompt must stay local.', + cwd: repo, + }), + } + ); + + assert.equal(stdout, ''); + assert.equal(existsSync(capturePath), false); + } finally { + await receiver.stop(); + } +}); + test('a release build sends telemetry without user environment configuration', async () => { closeDb(); const capturePath = join(root, 'built-telemetry-capture.jsonl');