import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { createAgentModule } from "../../src/modules/agent/index.ts"; import { createHarness, type Harness, pgAvailable } from "../auth-settings/harness.ts"; import { DEV_KEY, json } from "../helpers.ts"; // 智能体页会话分栏:对话(用户发起)/ 自动巡检(定时、事件触发);子会话随父会话归类 const hasPg = await pgAvailable(); describe.skipIf(!hasPg)("会话列表 group 筛选(真实 PG)", () => { let h: Harness; beforeAll(async () => { h = await createHarness({ extraModules: [createAgentModule()] }); }, 120_000); afterAll(async () => { await h?.close(); }); it("auto = schedule / event 及其子会话;conversation = 其余", async () => { const run = async (trigger: string, goal: string, parent?: string) => ( await h.db .insertInto("agent_run") .values({ trigger, goal, status: "succeeded", mode: "execute", parent_run_id: parent ?? null } as never) .returning("id") .executeTakeFirstOrThrow() ).id; const patrol = await run("schedule", "巡检"); await run("subagent", "巡检子会话", patrol); await run("event", "事件"); const chat = await run("user", "对话"); await run("subagent", "对话子会话", chat); const goals = async (group: string) => ( await json( await h.app.request(`/api/v1/agent/runs?group=${group}`, { headers: { authorization: `Bearer ${DEV_KEY}` } }), ) ).data.items .map((r: { goal: string }) => r.goal) .sort(); expect(await goals("auto")).toEqual(["事件", "巡检", "巡检子会话"].sort()); expect(await goals("conversation")).toEqual(["对话", "对话子会话"].sort()); }); });