test: cover routine cleanup on company deletion

Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Nicky LeachandPaperclip committed 2026-07-15 00:15:31 +00:00
1 parent 7f2ed0ad90
commit 2c0d5d828f
1 file changed
+19
@@ -125,6 +125,25 @@ describeEmbeddedPostgres("companyService", () => {
expect(afterReconcileRows.filter((row) => readBuiltInAgentMarker(row.metadata)?.key === "reflection-coach")).toHaveLength(1);
});
it("deletes built-in routines before their assigned agents during company removal", async () => {
const created = await companyService(db).create({
name: "Delete Routine Company",
});
const [routineBeforeDelete] = await db
.select({ id: routines.id, assigneeAgentId: routines.assigneeAgentId })
.from(routines)
.where(eq(routines.companyId, created.id));
expect(routineBeforeDelete?.assigneeAgentId).toBeTruthy();
const removed = await companyService(db).remove(created.id);
expect(removed?.id).toBe(created.id);
await expect(db.select().from(companies).where(eq(companies.id, created.id))).resolves.toHaveLength(0);
await expect(db.select().from(routines).where(eq(routines.companyId, created.id))).resolves.toHaveLength(0);
await expect(db.select().from(agents).where(eq(agents.companyId, created.id))).resolves.toHaveLength(0);
});
it("archives companies by pausing runnable agents and cancelling active runs", async () => {
const companyId = randomUUID();
const runningAgentId = randomUUID();