Rewrite workspace tab management to use stable tab IDs (agent_, terminal_, draft_, file_) with dedicated /tab/[tabId] routes, replace separate file-tabs store with unified workspace-tabs store, support multiple concurrent draft agent tabs, and detect text files by content instead of extension allowlist. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
import { beforeEach, describe, expect, it } from "vitest";
|
|
import { useCreateFlowStore } from "./create-flow-store";
|
|
|
|
describe("create-flow-store", () => {
|
|
beforeEach(() => {
|
|
useCreateFlowStore.setState({ pendingByDraftId: {} });
|
|
});
|
|
|
|
it("tracks lifecycle transitions explicitly", () => {
|
|
const store = useCreateFlowStore.getState();
|
|
store.setPending({
|
|
draftId: "draft-1",
|
|
serverId: "server-1",
|
|
agentId: null,
|
|
clientMessageId: "msg-1",
|
|
text: "hello",
|
|
timestamp: Date.now(),
|
|
images: [],
|
|
});
|
|
|
|
expect(useCreateFlowStore.getState().pendingByDraftId["draft-1"]?.lifecycle).toBe("active");
|
|
|
|
useCreateFlowStore.getState().markLifecycle({ draftId: "draft-1", lifecycle: "abandoned" });
|
|
expect(useCreateFlowStore.getState().pendingByDraftId["draft-1"]?.lifecycle).toBe("abandoned");
|
|
});
|
|
|
|
it("rekeys draft id idempotently", () => {
|
|
useCreateFlowStore.getState().setPending({
|
|
draftId: "draft-a",
|
|
serverId: "server-1",
|
|
agentId: null,
|
|
clientMessageId: "msg-1",
|
|
text: "hello",
|
|
timestamp: Date.now(),
|
|
images: [],
|
|
});
|
|
|
|
useCreateFlowStore.getState().rekeyDraft({
|
|
fromDraftId: "draft-a",
|
|
toDraftId: "draft-b",
|
|
});
|
|
useCreateFlowStore.getState().rekeyDraft({
|
|
fromDraftId: "draft-a",
|
|
toDraftId: "draft-b",
|
|
});
|
|
|
|
expect(useCreateFlowStore.getState().pendingByDraftId["draft-b"]?.draftId).toBe("draft-b");
|
|
});
|
|
|
|
it("supports multiple pending attempts", () => {
|
|
useCreateFlowStore.getState().setPending({
|
|
draftId: "draft-1",
|
|
serverId: "server-1",
|
|
agentId: null,
|
|
clientMessageId: "msg-1",
|
|
text: "one",
|
|
timestamp: Date.now(),
|
|
});
|
|
useCreateFlowStore.getState().setPending({
|
|
draftId: "draft-2",
|
|
serverId: "server-1",
|
|
agentId: null,
|
|
clientMessageId: "msg-2",
|
|
text: "two",
|
|
timestamp: Date.now(),
|
|
});
|
|
|
|
const state = useCreateFlowStore.getState();
|
|
expect(Object.keys(state.pendingByDraftId).sort()).toEqual(["draft-1", "draft-2"]);
|
|
|
|
useCreateFlowStore.getState().clear({ draftId: "draft-1" });
|
|
expect(useCreateFlowStore.getState().pendingByDraftId["draft-1"]).toBeUndefined();
|
|
});
|
|
});
|