Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import type { Task } from "../types";
import { AgentServer } from "./agent-server";

interface TestableServer {
configureEnvironment(args?: {
isInternal?: boolean;
originProduct?: string | null;
originProduct?: Task["origin_product"] | null;
taskId?: string | null;
taskRunId?: string | null;
taskUserId?: number | null;
Expand Down Expand Up @@ -148,6 +149,43 @@ describe("AgentServer.configureEnvironment", () => {
);
});

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",
);
});
Comment on lines +152 to +187
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 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!


it("respects the LLM_GATEWAY_URL override regardless of internal flag", () => {
process.env.LLM_GATEWAY_URL = "http://ngrok.test/proxy";

Expand Down
3 changes: 2 additions & 1 deletion packages/agent/src/server/agent-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import type {
GitCheckpointEvent,
HandoffLocalGitState,
LogLevel,
Task,
TaskRun,
TaskRunArtifact,
} from "../types";
Expand Down Expand Up @@ -1858,7 +1859,7 @@ ${signedCommitInstructions}
taskUserId,
}: {
isInternal?: boolean;
originProduct?: string | null;
originProduct?: Task["origin_product"] | null;
taskId?: string | null;
taskRunId?: string | null;
taskUserId?: number | null;
Expand Down
3 changes: 2 additions & 1 deletion packages/agent/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export interface Task {
| "user_created"
| "support_queue"
| "session_summaries"
| "signal_report";
| "signal_report"
| "slack";
github_integration?: number | null;
repository: string; // Format: "organization/repository" (e.g., "posthog/posthog-js")
json_schema?: Record<string, unknown> | null; // JSON schema for task output validation
Expand Down
9 changes: 8 additions & 1 deletion packages/agent/src/utils/gateway.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export type GatewayProduct = "posthog_code" | "background_agents" | "signals";
export type GatewayProduct =
| "posthog_code"
| "background_agents"
| "signals"
| "slack_app";

export function resolveGatewayProduct({
isInternal,
Expand All @@ -7,6 +11,9 @@ export function resolveGatewayProduct({
isInternal?: boolean;
originProduct?: string | null;
} = {}): GatewayProduct {
if (originProduct === "slack") {
return "slack_app";
}
if (isInternal) {
return originProduct === "signal_report" ? "signals" : "background_agents";
}
Expand Down
Loading