fix(app): reuse draft command cache across tabs

This commit is contained in:
Mohamed Boudra
2026-06-11 13:17:29 +07:00
parent 08ebe5e7e1
commit a70b5c1e1d
5 changed files with 186 additions and 30 deletions
@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it } from "vitest";
import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
import type { ProviderSnapshotEntry } from "@getpaseo/protocol/agent-types";
import { draftAgentCommandsQueryKey } from "@/hooks/agent-commands-query";
import {
applyProvidersSnapshotUpdate,
fetchProvidersSnapshot,
@@ -195,6 +196,24 @@ describe("refreshAndApplyProvidersSnapshot", () => {
queryClient.getQueryState(providersSnapshotQueryKey(serverId, "/repo-b"))?.isInvalidated,
).toBe(false);
});
it("invalidates cached agent commands when refreshing providers", async () => {
const client = createClient({ snapshots: [providersSnapshot([])] });
const commandsKey = draftAgentCommandsQueryKey({
serverId,
draftConfig: { provider: "codex", cwd: "/repo-a" },
});
queryClient.setQueryData(commandsKey, [{ name: "compact", description: "", argumentHint: "" }]);
await refreshAndApplyProvidersSnapshot({
client,
queryClient,
serverId,
cwd: "/repo-a",
});
expect(queryClient.getQueryState(commandsKey)?.isInvalidated).toBe(true);
});
});
describe("applyProvidersSnapshotUpdate", () => {
@@ -271,6 +290,22 @@ describe("applyProvidersSnapshotUpdate", () => {
requestId: "providers_snapshot_update",
});
});
it("invalidates cached agent commands when a provider snapshot update arrives", () => {
const commandsKey = draftAgentCommandsQueryKey({
serverId,
draftConfig: { provider: "codex", cwd: "/repo-a" },
});
queryClient.setQueryData(commandsKey, [{ name: "compact", description: "", argumentHint: "" }]);
applyProvidersSnapshotUpdate({
serverId,
queryClient,
message: updateMessage([codexEntry("ready", [readyCodexModel])], "/repo-a"),
});
expect(queryClient.getQueryState(commandsKey)?.isInvalidated).toBe(true);
});
});
describe("selectorOpenRefetchDecision", () => {