import { describe, expect, it } from "vitest"; import type { WorkspaceComposerAttachment } from "@/attachments/types"; import { buildDraftWorkspaceAttachmentScopeKey, resetWorkspaceAttachmentsStore, useWorkspaceAttachmentsStore, } from "@/attachments/workspace-attachments-store"; import { removeSentContextAttachments } from "./workspace-cleanup"; function chatHistoryAttachment(): WorkspaceComposerAttachment { return { kind: "chat_history", id: "chat_history:draft-1", attachment: { type: "text", mimeType: "text/plain", contextKind: "chat_history", title: "Chat history", text: "Previous chat.", }, source: { serverId: "local", agentId: "agent-1", }, }; } function pullRequestContextAttachment(): WorkspaceComposerAttachment { return { kind: "github.pull_request_comment", id: "comment-1", title: "Comment", text: "Please check this.", }; } function browserElementAttachment(): WorkspaceComposerAttachment { return { kind: "browser_element", attachment: { url: "https://example.com", selector: "button.primary", tag: "button", text: "Click me", outerHTML: '', computedStyles: {}, boundingRect: { x: 0, y: 0, width: 100, height: 40 }, reactSource: null, parentChain: [], children: [], formatted: "button.primary\nClick me", }, }; } describe("workspace composer attachment cleanup", () => { it("clears sent scoped context attachments from their stores", () => { resetWorkspaceAttachmentsStore(); const scopeKey = buildDraftWorkspaceAttachmentScopeKey("draft-1"); const chatHistory = chatHistoryAttachment(); const pullRequestContext = pullRequestContextAttachment(); const browserElement = browserElementAttachment(); useWorkspaceAttachmentsStore.getState().setWorkspaceAttachments({ scopeKey, attachments: [chatHistory, pullRequestContext, browserElement], }); removeSentContextAttachments([chatHistory, pullRequestContext, browserElement]); expect(useWorkspaceAttachmentsStore.getState().attachmentsByScope[scopeKey]).toBeUndefined(); }); });