Fix default conversation system prompt recompilation routing [LET-7976] (#1373)

This commit is contained in:
Devansh Jain
2026-03-12 19:34:35 -07:00
committed by GitHub
parent 182c65b77e
commit 94ff9f6796
4 changed files with 85 additions and 80 deletions

View File

@@ -3,71 +3,87 @@ import { recompileAgentSystemPrompt } from "../../agent/modify";
describe("recompileAgentSystemPrompt", () => {
test("calls the conversation recompile endpoint with mapped params", async () => {
const agentsRecompileMock = mock(
const conversationsRecompileMock = mock(
(_conversationId: string, _params?: Record<string, unknown>) =>
Promise.resolve("compiled-system-prompt"),
);
const client = {
conversations: {
recompile: agentsRecompileMock,
recompile: conversationsRecompileMock,
},
};
const compiledPrompt = await recompileAgentSystemPrompt(
"conv-123",
{
dryRun: true,
},
"agent-123",
true,
client,
);
expect(compiledPrompt).toBe("compiled-system-prompt");
expect(agentsRecompileMock).toHaveBeenCalledWith("conv-123", {
expect(conversationsRecompileMock).toHaveBeenCalledWith("conv-123", {
dry_run: true,
agent_id: "agent-123",
});
});
test("passes agent_id for default conversation recompiles", async () => {
const agentsRecompileMock = mock(
const conversationsRecompileMock = mock(
(_conversationId: string, _params?: Record<string, unknown>) =>
Promise.resolve("compiled-system-prompt"),
);
const client = {
conversations: {
recompile: agentsRecompileMock,
recompile: conversationsRecompileMock,
},
};
await recompileAgentSystemPrompt(
"default",
{
agentId: "agent-123",
},
client,
);
await recompileAgentSystemPrompt("default", "agent-123", undefined, client);
expect(agentsRecompileMock).toHaveBeenCalledWith("default", {
expect(conversationsRecompileMock).toHaveBeenCalledWith("default", {
dry_run: undefined,
agent_id: "agent-123",
});
});
test("throws when default conversation recompile lacks agent id", async () => {
const agentsRecompileMock = mock(
test("passes non-default conversation ids through unchanged", async () => {
const conversationsRecompileMock = mock(
(_conversationId: string, _params?: Record<string, unknown>) =>
Promise.resolve("compiled-system-prompt"),
);
const client = {
conversations: {
recompile: agentsRecompileMock,
recompile: conversationsRecompileMock,
},
};
await recompileAgentSystemPrompt(
"['default']",
"agent-123",
undefined,
client,
);
expect(conversationsRecompileMock).toHaveBeenCalledWith("['default']", {
dry_run: undefined,
agent_id: "agent-123",
});
});
test("throws when conversation recompile has empty agent id", async () => {
const conversationsRecompileMock = mock(
(_conversationId: string, _params?: Record<string, unknown>) =>
Promise.resolve("compiled-system-prompt"),
);
const client = {
conversations: {
recompile: conversationsRecompileMock,
},
};
await expect(
recompileAgentSystemPrompt("default", {}, client),
).rejects.toThrow(
'recompileAgentSystemPrompt requires options.agentId when conversationId is "default"',
);
expect(agentsRecompileMock).not.toHaveBeenCalled();
recompileAgentSystemPrompt("default", "", undefined, client),
).rejects.toThrow("recompileAgentSystemPrompt requires agentId");
expect(conversationsRecompileMock).not.toHaveBeenCalled();
});
});

View File

@@ -1,9 +1,8 @@
import { beforeEach, describe, expect, mock, test } from "bun:test";
import type { RecompileAgentSystemPromptOptions } from "../../agent/modify";
import { handleMemorySubagentCompletion } from "../../cli/helpers/memorySubagentCompletion";
const recompileAgentSystemPromptMock = mock(
(_conversationId: string, _opts?: RecompileAgentSystemPromptOptions) =>
(_conversationId: string, _agentId: string, _dryRun?: boolean) =>
Promise.resolve("compiled-system-prompt"),
);
@@ -19,7 +18,7 @@ describe("memory subagent recompile handling", () => {
beforeEach(() => {
recompileAgentSystemPromptMock.mockReset();
recompileAgentSystemPromptMock.mockImplementation(
(_agentId: string, _opts?: RecompileAgentSystemPromptOptions) =>
(_conversationId: string, _agentId: string, _dryRun?: boolean) =>
Promise.resolve("compiled-system-prompt"),
);
});
@@ -44,7 +43,7 @@ describe("memory subagent recompile handling", () => {
);
expect(recompileAgentSystemPromptMock).toHaveBeenCalledWith(
"conv-init-1",
{},
"agent-init-1",
);
});
@@ -63,9 +62,10 @@ describe("memory subagent recompile handling", () => {
},
);
expect(recompileAgentSystemPromptMock).toHaveBeenCalledWith("default", {
agentId: "agent-default",
});
expect(recompileAgentSystemPromptMock).toHaveBeenCalledWith(
"default",
"agent-default",
);
});
test("queues a trailing recompile when later completions land mid-flight", async () => {
@@ -176,7 +176,13 @@ describe("memory subagent recompile handling", () => {
"Reflected on /palace, the halls remember more now.",
);
expect(recompileAgentSystemPromptMock).toHaveBeenCalledTimes(2);
expect(recompileAgentSystemPromptMock).toHaveBeenCalledWith("conv-a", {});
expect(recompileAgentSystemPromptMock).toHaveBeenCalledWith("conv-b", {});
expect(recompileAgentSystemPromptMock).toHaveBeenCalledWith(
"conv-a",
"agent-shared",
);
expect(recompileAgentSystemPromptMock).toHaveBeenCalledWith(
"conv-b",
"agent-shared",
);
});
});