feat(agent): route slack-originated tasks to slack_app gateway product#2225
feat(agent): route slack-originated tasks to slack_app gateway product#2225VojtechBartos wants to merge 1 commit into
Conversation
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
packages/agent/src/server/agent-server.configure-environment.test.ts:92-127
**Prefer parameterised tests for product-routing cases**
The three new tests exercise the same `configureEnvironment` code path with different `(originProduct, isInternal, expectedProduct)` tuples — a textbook candidate for `it.each`. The codebase's own rule is to always prefer parameterised tests, and duplicating the arrange/assert boilerplate across three separate `it()` blocks makes it harder to see the full matrix at a glance and to add future cases. A single `it.each` table would also make it obvious that the `(originProduct="user_created", isInternal=true) → background_agents` cell is currently untested.
Reviews (1): Last reviewed commit: "feat(agent): route slack-originated task..." | Re-trigger Greptile |
| it("tags as slack_app when the task was initiated from Slack", () => { | ||
| buildServer("interactive").configureEnvironment({ | ||
| originProduct: "slack", | ||
| }); | ||
|
|
||
| expect(process.env.LLM_GATEWAY_URL).toBe( | ||
| "https://gateway.us.posthog.com/slack_app", | ||
| ); | ||
| expect(process.env.ANTHROPIC_BASE_URL).toBe( | ||
| "https://gateway.us.posthog.com/slack_app", | ||
| ); | ||
| expect(process.env.OPENAI_BASE_URL).toBe( | ||
| "https://gateway.us.posthog.com/slack_app/v1", | ||
| ); | ||
| }); | ||
|
|
||
| it("prefers slack_app over background_agents when both signals are present", () => { | ||
| buildServer("interactive").configureEnvironment({ | ||
| isInternal: true, | ||
| originProduct: "slack", | ||
| }); | ||
|
|
||
| expect(process.env.LLM_GATEWAY_URL).toBe( | ||
| "https://gateway.us.posthog.com/slack_app", | ||
| ); | ||
| }); | ||
|
|
||
| it("falls back to posthog_code for non-slack origin products", () => { | ||
| buildServer("background").configureEnvironment({ | ||
| originProduct: "user_created", | ||
| }); | ||
|
|
||
| expect(process.env.LLM_GATEWAY_URL).toBe( | ||
| "https://gateway.us.posthog.com/posthog_code", | ||
| ); | ||
| }); |
There was a problem hiding this comment.
Prefer parameterised tests for product-routing cases
The three new tests exercise the same configureEnvironment code path with different (originProduct, isInternal, expectedProduct) tuples — a textbook candidate for it.each. The codebase's own rule is to always prefer parameterised tests, and duplicating the arrange/assert boilerplate across three separate it() blocks makes it harder to see the full matrix at a glance and to add future cases. A single it.each table would also make it obvious that the (originProduct="user_created", isInternal=true) → background_agents cell is currently untested.
Context Used: Do not attempt to comment on incorrect alphabetica... (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/agent/src/server/agent-server.configure-environment.test.ts
Line: 92-127
Comment:
**Prefer parameterised tests for product-routing cases**
The three new tests exercise the same `configureEnvironment` code path with different `(originProduct, isInternal, expectedProduct)` tuples — a textbook candidate for `it.each`. The codebase's own rule is to always prefer parameterised tests, and duplicating the arrange/assert boilerplate across three separate `it()` blocks makes it harder to see the full matrix at a glance and to add future cases. A single `it.each` table would also make it obvious that the `(originProduct="user_created", isInternal=true) → background_agents` cell is currently untested.
**Context Used:** Do not attempt to comment on incorrect alphabetica... ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
How can I resolve this? If you propose a fix, please make it concise.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!
f7bc6de to
05a3c88
Compare
05a3c88 to
1ebba3b
Compare
Problem
The agent in the sandbox calls the LLM gateway as
posthog_coderegardless of how the task started. Slack-bot mentions are now billed differently from desktop tasks (gateway tagsslack_apptraffic with\$ai_billable=true), so the agent needs to send the correct product per task.Changes
"slack_app"to theGatewayProducttype union (packages/agent/src/utils/gateway.ts)."slack"to theTask.origin_productunion (packages/agent/src/types.ts) to mirror the PythonTask.OriginProduct.SLACKvalue already set on the backend.configureEnvironmentnow acceptsoriginProduct?: Task["origin_product"] | null. Mapping:"slack"→slack_app,internal=true→background_agents, else →posthog_code. Call site readspreTask?.origin_productfrom the Task fetched at session init.Pairs with PostHog/posthog#59040 (gateway-side product registration + per-turn quota gate). Both ship behind the existing
posthog-code-slack-availabilityflag — neither side has user-visible effect until the flag is enabled.How did you test this?
I'm an agent. No manual testing.
pnpm --filter @posthog/agent test src/server/agent-server.configure-environment.test.ts→ 8 passed (5 pre-existing + 3 new).biome format --writeclean on touched files.Publish to changelog?
no