Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)};`,
Expand Down
2 changes: 1 addition & 1 deletion src/telemetry-build-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
4 changes: 1 addition & 3 deletions src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment on lines 12 to +13

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Legacy token documentation is stale

The token selection no longer reads POSTHOG_API_KEY, but the telemetry configuration references still document it as a supported fallback. Maintainers following those references will configure a key that leaves telemetry disabled, so the affected almanac pages should be updated alongside this change.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Cursor Fix in Conductor

const POSTHOG_HOST =
process.env.POSTHOG_HOST || BUILT_IN_POSTHOG_HOST || DEFAULT_POSTHOG_HOST;

Expand Down
29 changes: 29 additions & 0 deletions test/plugin-package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
44 changes: 42 additions & 2 deletions test/prompt-hook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { execFileSync, spawn, spawnSync } from 'node:child_process';
import { once } from 'node:events';
import {
cpSync,
existsSync,
mkdirSync,
mkdtempSync,
readFileSync,
Expand Down Expand Up @@ -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');
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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');
Expand Down
Loading