import { describe, expect, it } from "vitest"; import { AssetManager } from "@/core/AssetManager"; type FakeBundle = Record; describe("AssetSession", () => { it("tracks owner/session relationships in inspector snapshot", async () => { const loadCalls: string[] = []; const unloadCalls: string[] = []; const manager = new AssetManager({ init: async () => undefined, loadBundle: async (name: string) => { loadCalls.push(name); return { name } as FakeBundle; }, unloadBundle: async (name: string) => { unloadCalls.push(name); }, }); const sceneSessionA = manager.createSession("scene"); const sceneSessionB = manager.createSession("scene"); const uiSession = manager.createSession("ui"); await sceneSessionA.loadBundle("characters"); await sceneSessionB.loadBundle("background"); await uiSession.loadBundle("characters"); const snapshot = manager.getInspectorSnapshot(); expect(snapshot.sessions[sceneSessionA.id]?.owner).toBe("scene"); expect(snapshot.sessions[sceneSessionB.id]?.owner).toBe("scene"); expect(snapshot.sessions[uiSession.id]?.owner).toBe("ui"); expect(snapshot.owners.scene?.sessions).toContain(sceneSessionA.id); expect(snapshot.owners.scene?.sessions).toContain(sceneSessionB.id); expect(snapshot.owners.ui?.sessions).toContain(uiSession.id); expect(snapshot.activeBundles.sort()).toEqual(["background", "characters"]); expect(loadCalls).toEqual(["characters", "background"]); expect(unloadCalls).toEqual([]); }); it("clears active bundles after releaseAll", async () => { const unloadCalls: string[] = []; const manager = new AssetManager({ init: async () => undefined, loadBundle: async (name: string) => ({ name }) as FakeBundle, unloadBundle: async (name: string) => { unloadCalls.push(name); }, }); const session = manager.createSession("battle"); await session.loadBundle("fx"); await session.loadBundle("music"); expect(manager.getInspectorSnapshot().activeBundles.sort()).toEqual([ "fx", "music", ]); await session.releaseAll(); const snapshot = manager.getInspectorSnapshot(); expect(snapshot.activeBundles).toEqual([]); expect(snapshot.bundles).toEqual({}); expect(unloadCalls.sort()).toEqual(["fx", "music"]); }); });