Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

test(api): pin the seeded thread order in the agent history list test (#55)

Croffb13d96e28f39
diff --git a/apps/api/src/ai-agents/__tests__/integration/agent-threads.test.ts b/apps/api/src/ai-agents/__tests__/integration/agent-threads.test.ts
index f1289130..295781c4 100644
--- a/apps/api/src/ai-agents/__tests__/integration/agent-threads.test.ts
+++ b/apps/api/src/ai-agents/__tests__/integration/agent-threads.test.ts
@@ -68,6 +68,16 @@ async function seedThread(
});
}
+// Moves a seeded thread a minute into the past. Threads seeded one after another are
+// stamped with the same millisecond, and the history list orders by updatedAt, so
+// without this the expected order is not the only one the endpoint may return.
+async function backdateThread(threadId: string): Promise<void> {
+ const memory = buildMemory(20);
+ const thread = (await memory.getThreadById({ threadId }))!;
+ const at = new Date(thread.updatedAt.getTime() - 60_000);
+ await memory.saveThread({ thread: { ...thread, createdAt: at, updatedAt: at } });
+}
+
// Whether the thread is still in the memory store. Deletion has no read endpoint of
// its own for a thread the caller does not own, so it is checked through the store.
async function threadExists(threadId: string): Promise<boolean> {
@@ -92,6 +102,7 @@ describe('agent chat history', () => {
const { owner, asOwner } = await setup();
const agent = await createInternalAgent(asOwner, 'Design Bot', 'design');
await seedThread('t-old', owner.userId, agent, 'older question');
+ await backdateThread('t-old');
await seedThread('t-new', owner.userId, agent, 'newer question');
const res = await agents(asOwner)({ agentId: agent.id }).threads.get();