Resolve 21 conflicts from latest main (provider profiles, Windows fixes, 0.1.55-rc.1). Fix all type errors and syntax issues from merge artifacts.
158 lines
4.9 KiB
TypeScript
158 lines
4.9 KiB
TypeScript
import type { DaemonClient } from "@server/client/daemon-client";
|
|
import { QueryClient } from "@tanstack/react-query";
|
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
import type { Agent } from "@/stores/session-store";
|
|
import { useSessionStore } from "@/stores/session-store";
|
|
import { __private__, applyArchivedAgentCloseResults } from "./use-archive-agent";
|
|
|
|
function makeAgent(overrides: Partial<Agent> = {}): Agent {
|
|
return {
|
|
serverId: "server-a",
|
|
id: "agent-1",
|
|
provider: "codex",
|
|
status: "running",
|
|
createdAt: new Date("2026-04-01T03:00:00.000Z"),
|
|
updatedAt: new Date("2026-04-01T03:00:00.000Z"),
|
|
lastUserMessageAt: null,
|
|
lastActivityAt: new Date("2026-04-01T03:00:00.000Z"),
|
|
capabilities: {
|
|
supportsStreaming: true,
|
|
supportsSessionPersistence: true,
|
|
supportsDynamicModes: true,
|
|
supportsMcpServers: true,
|
|
supportsReasoningStream: true,
|
|
supportsToolInvocations: true,
|
|
},
|
|
currentModeId: null,
|
|
availableModes: [],
|
|
pendingPermissions: [],
|
|
persistence: null,
|
|
title: "Agent 1",
|
|
cwd: "/repo",
|
|
model: null,
|
|
labels: {},
|
|
archivedAt: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("useArchiveAgent", () => {
|
|
beforeEach(() => {
|
|
useSessionStore.setState((state) => ({ ...state, sessions: {} }));
|
|
});
|
|
|
|
it("tracks pending archive state in shared react-query cache", () => {
|
|
const queryClient = new QueryClient();
|
|
|
|
expect(
|
|
__private__.isAgentArchiving({
|
|
queryClient,
|
|
serverId: "server-a",
|
|
agentId: "agent-1",
|
|
}),
|
|
).toBe(false);
|
|
|
|
__private__.setAgentArchiving({
|
|
queryClient,
|
|
serverId: "server-a",
|
|
agentId: "agent-1",
|
|
isArchiving: true,
|
|
});
|
|
|
|
expect(
|
|
__private__.isAgentArchiving({
|
|
queryClient,
|
|
serverId: "server-a",
|
|
agentId: "agent-1",
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
__private__.isAgentArchiving({
|
|
queryClient,
|
|
serverId: "server-a",
|
|
agentId: "agent-2",
|
|
}),
|
|
).toBe(false);
|
|
|
|
__private__.setAgentArchiving({
|
|
queryClient,
|
|
serverId: "server-a",
|
|
agentId: "agent-1",
|
|
isArchiving: false,
|
|
});
|
|
|
|
expect(
|
|
__private__.isAgentArchiving({
|
|
queryClient,
|
|
serverId: "server-a",
|
|
agentId: "agent-1",
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("removes an archived agent from cached list payloads", () => {
|
|
const payload = {
|
|
entries: [{ agent: { id: "agent-1" } }, { agent: { id: "agent-2" } }],
|
|
pageInfo: { hasMore: false },
|
|
};
|
|
|
|
const next = __private__.removeAgentFromListPayload(payload, "agent-1");
|
|
|
|
expect(next.entries).toEqual([{ agent: { id: "agent-2" } }]);
|
|
expect(next.pageInfo).toEqual({ hasMore: false });
|
|
});
|
|
|
|
it("applies archived agent close results to session state and cached lists", async () => {
|
|
const queryClient = new QueryClient();
|
|
useSessionStore.getState().initializeSession("server-a", {} as DaemonClient);
|
|
useSessionStore.getState().setAgents("server-a", new Map([["agent-1", makeAgent()]]));
|
|
queryClient.setQueryData(["sidebarAgentsList", "server-a"], {
|
|
entries: [{ agent: { id: "agent-1" } }, { agent: { id: "agent-2" } }],
|
|
});
|
|
queryClient.setQueryData(["allAgents", "server-a"], {
|
|
entries: [{ agent: { id: "agent-1" } }, { agent: { id: "agent-2" } }],
|
|
});
|
|
|
|
applyArchivedAgentCloseResults({
|
|
queryClient,
|
|
serverId: "server-a",
|
|
results: [{ agentId: "agent-1", archivedAt: "2026-04-01T04:00:00.000Z" }],
|
|
});
|
|
|
|
expect(
|
|
useSessionStore
|
|
.getState()
|
|
.sessions["server-a"]?.agents.get("agent-1")
|
|
?.archivedAt?.toISOString(),
|
|
).toBe("2026-04-01T04:00:00.000Z");
|
|
expect(queryClient.getQueryData(["sidebarAgentsList", "server-a"])).toEqual({
|
|
entries: [{ agent: { id: "agent-2" } }],
|
|
});
|
|
expect(queryClient.getQueryData(["allAgents", "server-a"])).toEqual({
|
|
entries: [{ agent: { id: "agent-2" } }],
|
|
});
|
|
});
|
|
|
|
it("can apply archived agent close results without invalidating cached lists", () => {
|
|
const queryClient = new QueryClient();
|
|
useSessionStore.getState().initializeSession("server-a", {} as DaemonClient);
|
|
useSessionStore.getState().setAgents("server-a", new Map([["agent-1", makeAgent()]]));
|
|
queryClient.setQueryData(["sidebarAgentsList", "server-a"], {
|
|
entries: [{ agent: { id: "agent-1" } }, { agent: { id: "agent-2" } }],
|
|
});
|
|
queryClient.setQueryData(["allAgents", "server-a"], {
|
|
entries: [{ agent: { id: "agent-1" } }, { agent: { id: "agent-2" } }],
|
|
});
|
|
|
|
applyArchivedAgentCloseResults({
|
|
queryClient,
|
|
serverId: "server-a",
|
|
results: [{ agentId: "agent-1", archivedAt: "2026-04-01T04:00:00.000Z" }],
|
|
invalidateQueries: false,
|
|
});
|
|
|
|
expect(queryClient.getQueryState(["sidebarAgentsList", "server-a"])?.isInvalidated).toBe(false);
|
|
expect(queryClient.getQueryState(["allAgents", "server-a"])?.isInvalidated).toBe(false);
|
|
});
|
|
});
|