Fix default conversation system prompt recompilation routing [LET-7976] (#1373)
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user