Skip to content

Commit 8c8043c

Browse files
committed
test: cover internal VST3 removal cleanup
1 parent 27b7e4e commit 8c8043c

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

src/store/__tests__/vst3Store.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,18 @@ describe('vst3Store', () => {
174174
removePluginSpy.mockRestore();
175175
});
176176

177+
it('_removeInstance also removes the live plugin for bridge callback paths', () => {
178+
const removePluginSpy = vi.spyOn(pluginEngine, 'removePlugin').mockImplementation(() => undefined);
179+
useVST3Store.getState()._upsertInstance(mockInstance());
180+
181+
useVST3Store.getState()._removeInstance('inst-1');
182+
183+
expect(removePluginSpy).toHaveBeenCalledWith('track-1', 'inst-1');
184+
expect(useVST3Store.getState().instances['inst-1']).toBeUndefined();
185+
186+
removePluginSpy.mockRestore();
187+
});
188+
177189
it('removing non-existent instance is a no-op', () => {
178190
const removePluginSpy = vi.spyOn(pluginEngine, 'removePlugin').mockImplementation(() => undefined);
179191
useVST3Store.getState()._upsertInstance(mockInstance());

src/store/vst3Store.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,6 @@ export const useVST3Store = create<VST3Store>()((set, get) => ({
234234
},
235235

236236
removeInstance: (instanceId: string) => {
237-
const inst = get().instances[instanceId];
238-
if (!inst) return;
239-
240-
try {
241-
pluginEngine.removePlugin(inst.trackId, instanceId);
242-
} catch {
243-
// Store removal should still succeed if the live audio chain is already gone.
244-
}
245-
246237
get()._removeInstance(instanceId);
247238
},
248239

@@ -411,6 +402,12 @@ export const useVST3Store = create<VST3Store>()((set, get) => ({
411402
return;
412403
}
413404

405+
try {
406+
pluginEngine.removePlugin(inst.trackId, instanceId);
407+
} catch {
408+
// Store removal should still succeed if the live audio chain is already gone.
409+
}
410+
414411
const order = (pluginOrder[inst.trackId] ?? []).filter((id) => id !== instanceId);
415412
set({
416413
instances: next,

0 commit comments

Comments
 (0)