import { describe, expect, it, vi } from "vitest"; import { createToolcraftSourceAssetOperationStore } from "./source-asset-operation-store"; describe("source asset operation store", () => { it("isolates subscriber failures and continues notifying", () => { const store = createToolcraftSourceAssetOperationStore(); const throwingListener = vi.fn(() => { throw new Error("listener failed"); }); const healthyListener = vi.fn(); store.subscribe(throwingListener); store.subscribe(healthyListener); expect(() => store.setOperation({ phase: "analyzing", target: "source.files", }), ).not.toThrow(); expect(throwingListener).toHaveBeenCalledTimes(1); expect(healthyListener).toHaveBeenCalledTimes(1); }); it("stores presentation feedback beside operation status and clears it explicitly or on a new operation", () => { const store = createToolcraftSourceAssetOperationStore(); const feedback = { category: "resource-unavailable" as const, code: "model-presentation-unavailable", message: "The model presentation is unavailable.", }; store.setOperation({ phase: "analyzing", progress: 0.25, target: "source.model", }); store.setPresentationFeedback("source.model", feedback); expect(store.getOperation("source.model")).toEqual({ phase: "analyzing", presentationFeedback: feedback, progress: 0.25, target: "source.model", }); store.clearPresentationFeedback("source.model"); expect(store.getOperation("source.model").presentationFeedback).toBeUndefined(); store.setPresentationFeedback("source.model", feedback); store.setOperation({ phase: "decoding", target: "source.model" }); expect(store.getOperation("source.model").presentationFeedback).toBeUndefined(); }); });