From ceac8f398eb17315c814e2c7bccbb746834952ed Mon Sep 17 00:00:00 2001 From: "posthog[bot]" <206114724+posthog[bot]@users.noreply.github.com> Date: Mon, 6 Jul 2026 14:44:53 +0000 Subject: [PATCH] fix: default generated POSTHOG_HOST to the detected region The integration agent was copying the `https://us.i.posthog.com` fallback literal from example code (skill docs / inline snippets) even when the user selected the EU region, producing configs like `POSTHOG_HOST = os.environ.get('POSTHOG_HOST', 'https://us.i.posthog.com')` for EU projects. The detected host was already in the prompt but the agent wasn't using it as the fallback default. Add an explicit instruction to the shared integration prompt to use the detected PostHog Host as any hardcoded fallback/default, and stop the inline Ruby example from hardcoding the US host (which contradicted that guidance). Generated-By: PostHog Code Task-Id: 72a06317-16be-4f06-8590-d001dd2d3dc3 --- src/frameworks/ruby/ruby-wizard-agent.ts | 2 +- .../__tests__/region-host-prompt.test.ts | 48 +++++++++++++++++++ src/lib/programs/posthog-integration/index.ts | 5 ++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/lib/programs/posthog-integration/__tests__/region-host-prompt.test.ts diff --git a/src/frameworks/ruby/ruby-wizard-agent.ts b/src/frameworks/ruby/ruby-wizard-agent.ts index aa63873b9..bffa88cc4 100644 --- a/src/frameworks/ruby/ruby-wizard-agent.ts +++ b/src/frameworks/ruby/ruby-wizard-agent.ts @@ -86,7 +86,7 @@ export const RUBY_AGENT_CONFIG: FrameworkConfig = { ``, `client = PostHog::Client.new(`, ` api_key: ENV['POSTHOG_PROJECT_TOKEN'],`, - ` host: ENV['POSTHOG_HOST'] || 'https://us.i.posthog.com'`, + ` host: ENV['POSTHOG_HOST'] || ''`, `)`, ``, `### 3. MUST Call shutdown Before Exit`, diff --git a/src/lib/programs/posthog-integration/__tests__/region-host-prompt.test.ts b/src/lib/programs/posthog-integration/__tests__/region-host-prompt.test.ts new file mode 100644 index 000000000..310c3d918 --- /dev/null +++ b/src/lib/programs/posthog-integration/__tests__/region-host-prompt.test.ts @@ -0,0 +1,48 @@ +import { posthogIntegrationConfig } from '@lib/programs/posthog-integration/index'; +import { DJANGO_AGENT_CONFIG } from '@frameworks/django/django-wizard-agent'; +import type { WizardSession } from '@lib/wizard-session'; +import type { PromptContext } from '@lib/agent/agent-prompt'; +import * as os from 'node:os'; + +function makeSession(): WizardSession { + return { + installDir: os.tmpdir(), + frameworkConfig: DJANGO_AGENT_CONFIG, + frameworkContext: {}, + additionalFeatureQueue: [], + } as unknown as WizardSession; +} + +/** + * Regression: the auto-generated config must default POSTHOG_HOST to the + * detected region's host, not the US fallback. An EU user selecting EU in the + * CLI was getting `POSTHOG_HOST = os.environ.get('POSTHOG_HOST', + * 'https://us.i.posthog.com')` because the agent copied the US literal from + * example code. The prompt now tells the agent to use the detected host as the + * fallback default. + */ +describe('integration prompt threads the region host into generated fallbacks', () => { + const euCtx: PromptContext = { + projectId: 42, + projectApiKey: 'phc_test', + host: 'https://eu.i.posthog.com', + }; + + it('instructs the agent to use the EU host as the fallback default', async () => { + const run = await posthogIntegrationConfig.run(makeSession()); + const prompt = run.customPrompt!(euCtx); + + // The detected host is present and called out as the fallback default. + expect(prompt).toContain('https://eu.i.posthog.com'); + // It explicitly warns against emitting a mismatched-region fallback. + expect(prompt).toContain('region-correct host'); + expect(prompt).toContain( + 'Never emit a fallback host for a different region than the detected one.', + ); + // The US literal only ever appears as the example of what NOT to hardcode, + // never as the value the agent should use. + expect(prompt).not.toMatch( + /use https:\/\/us\.i\.posthog\.com as that default/, + ); + }); +}); diff --git a/src/lib/programs/posthog-integration/index.ts b/src/lib/programs/posthog-integration/index.ts index 88f2395d3..aa2ffde3f 100644 --- a/src/lib/programs/posthog-integration/index.ts +++ b/src/lib/programs/posthog-integration/index.ts @@ -199,6 +199,11 @@ STEP 5: Set up environment variables for PostHog using the wizard-tools MCP serv config.metadata.name }, which you'll find in example code. The tool will also ensure .gitignore coverage. Don't assume the presence of keys means the value is up to date. Write the correct value each time. - Reference these environment variables in the code files you create instead of hardcoding the public token and host. + - IMPORTANT — region-correct host: this project's PostHog Host is ${ + ctx.host + }. Example code (from skills or docs) often hardcodes a fallback like \`https://us.i.posthog.com\`. When you write a fallback/default host in generated code (e.g. \`os.environ.get('POSTHOG_HOST', '...')\` or \`ENV['POSTHOG_HOST'] || '...'\`), use ${ + ctx.host + } as that default so it matches the user's region. Never emit a fallback host for a different region than the detected one. Important: Use the detect_package_manager tool (from the wizard-tools MCP server) to determine which package manager the project uses. Do not manually search for lockfiles or config files. Always install packages as a background task. Don't await completion; proceed with other work immediately after starting the installation. You must read a file immediately before attempting to write it, even if you have previously read it; failure to do so will cause a tool failure.