-
Notifications
You must be signed in to change notification settings - Fork 14
chore: tag all tasks runs under posthog code limits #1942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+109
−6
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
packages/agent/src/server/agent-server.configure-environment.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { afterEach, beforeEach, describe, expect, it } from "vitest"; | ||
| import { AgentServer } from "./agent-server"; | ||
|
|
||
| interface TestableServer { | ||
| configureEnvironment(args?: { isInternal?: boolean }): void; | ||
| } | ||
|
|
||
| const ENV_KEYS_UNDER_TEST = [ | ||
| "LLM_GATEWAY_URL", | ||
| "ANTHROPIC_BASE_URL", | ||
| "OPENAI_BASE_URL", | ||
| ] as const; | ||
|
|
||
| describe("AgentServer.configureEnvironment", () => { | ||
| const originalEnv: Partial<Record<string, string | undefined>> = {}; | ||
|
|
||
| beforeEach(() => { | ||
| for (const key of ENV_KEYS_UNDER_TEST) { | ||
| originalEnv[key] = process.env[key]; | ||
| delete process.env[key]; | ||
| } | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| for (const key of ENV_KEYS_UNDER_TEST) { | ||
| const value = originalEnv[key]; | ||
| if (value === undefined) { | ||
| delete process.env[key]; | ||
| } else { | ||
| process.env[key] = value; | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| const buildServer = (mode: "background" | "interactive"): TestableServer => | ||
| new AgentServer({ | ||
| port: 0, | ||
| jwtPublicKey: "test-key", | ||
| apiUrl: "https://us.posthog.com", | ||
| apiKey: "test-api-key", | ||
| projectId: 1, | ||
| mode, | ||
| taskId: "test-task-id", | ||
| runId: "test-run-id", | ||
| }) as unknown as TestableServer; | ||
|
|
||
| it("tags as background_agents when the task is internal", () => { | ||
| buildServer("interactive").configureEnvironment({ isInternal: true }); | ||
|
|
||
| expect(process.env.LLM_GATEWAY_URL).toBe( | ||
| "https://gateway.us.posthog.com/background_agents", | ||
| ); | ||
| expect(process.env.ANTHROPIC_BASE_URL).toBe( | ||
| "https://gateway.us.posthog.com/background_agents", | ||
| ); | ||
| expect(process.env.OPENAI_BASE_URL).toBe( | ||
| "https://gateway.us.posthog.com/background_agents/v1", | ||
| ); | ||
| }); | ||
|
|
||
| it("tags as posthog_code when the task is not internal", () => { | ||
| buildServer("background").configureEnvironment({ isInternal: false }); | ||
|
|
||
| expect(process.env.LLM_GATEWAY_URL).toBe( | ||
| "https://gateway.us.posthog.com/posthog_code", | ||
| ); | ||
| }); | ||
|
|
||
| it("tags as posthog_code when isInternal is omitted (getTask failure fallback)", () => { | ||
| buildServer("background").configureEnvironment(); | ||
|
|
||
| expect(process.env.LLM_GATEWAY_URL).toBe( | ||
| "https://gateway.us.posthog.com/posthog_code", | ||
| ); | ||
| }); | ||
|
|
||
| it("ignores mode when picking the gateway product", () => { | ||
| buildServer("background").configureEnvironment({ isInternal: false }); | ||
| const fromBackground = process.env.LLM_GATEWAY_URL; | ||
|
|
||
| buildServer("interactive").configureEnvironment({ isInternal: false }); | ||
| const fromInteractive = process.env.LLM_GATEWAY_URL; | ||
|
|
||
| expect(fromBackground).toBe(fromInteractive); | ||
| expect(fromBackground).toBe("https://gateway.us.posthog.com/posthog_code"); | ||
| }); | ||
|
|
||
| it("respects the LLM_GATEWAY_URL override regardless of internal flag", () => { | ||
| process.env.LLM_GATEWAY_URL = "http://ngrok.test/proxy"; | ||
|
|
||
| buildServer("background").configureEnvironment({ isInternal: true }); | ||
|
|
||
| expect(process.env.LLM_GATEWAY_URL).toBe("http://ngrok.test/proxy"); | ||
| expect(process.env.ANTHROPIC_BASE_URL).toBe("http://ngrok.test/proxy"); | ||
| expect(process.env.OPENAI_BASE_URL).toBe("http://ngrok.test/proxy/v1"); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests at lines 61-67 and 69-75 both assert identical output (
posthog_code) and differ only in argument shape ({ isInternal: false }vs omitted). Per the team's preference for parameterised tests, these could be collapsed into a singleit.each:This also adds the missing
ANTHROPIC_BASE_URL/OPENAI_BASE_URLassertions (present in thebackground_agentscase but absent here).Context Used: Do not attempt to comment on incorrect alphabetica... (source)
Prompt To Fix With AI
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!