test: guard discord thread title mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 02:33:10 +01:00
parent 2f4fa9cbe2
commit 578dcfbcf4

View File

@@ -11,6 +11,16 @@ const extractAssistantTextMock = vi.fn<typeof agentRuntimeModule.extractAssistan
let generateThreadTitle: typeof import("./thread-title.js").generateThreadTitle;
function firstCompletionArgs(): Parameters<
typeof agentRuntimeModule.completeWithPreparedSimpleCompletionModel
>[0] {
const firstCall = completeWithPreparedSimpleCompletionModelMock.mock.calls.at(0);
if (!firstCall) {
throw new Error("expected completion call");
}
return firstCall[0];
}
beforeAll(async () => {
({ generateThreadTitle } = await import("./thread-title.js"));
});
@@ -162,10 +172,7 @@ describe("generateThreadTitle", () => {
expect(result).toBe("Generated title");
expect(completeWithPreparedSimpleCompletionModelMock).toHaveBeenCalledTimes(1);
const completionArgs = completeWithPreparedSimpleCompletionModelMock.mock.calls[0]?.[0];
if (!completionArgs) {
throw new Error("expected completion call");
}
const completionArgs = firstCompletionArgs();
expect(completionArgs.context).toEqual({
systemPrompt:
"Generate a concise Discord thread title (3-6 words). Return only the title. Use channel context when provided and avoid redundant channel-name words unless needed for clarity.",