fix: close marketplace client review findings

This commit is contained in:
brother7 committed 2026-08-28 21:05:54 +08:00
1 parent 8dfa542860
commit 1614f7efc1
25 files changed
+1224 -143

No files matched your search

@@ -70,6 +70,53 @@ describe('plugin Marketplace store', () => {
expect(store.getState().library?.items[0].title).toBe('Acquired');
});
it('keeps the newest same-account Library read when an older response completes last', async () => {
const first = deferred<MarketplaceLibraryProjection>();
const second = deferred<MarketplaceLibraryProjection>();
const readLibrary = vi.fn()
.mockImplementationOnce(() => first.promise)
.mockImplementationOnce(() => second.promise);
const store = createPluginMarketplaceStore({ readLibrary });
store.getState().activateAccount('account-a');
const oldest = store.getState().loadLibrary();
const newest = store.getState().loadLibrary();
second.resolve(projection('newest')); await newest;
first.resolve(projection('oldest')); await oldest;
expect(store.getState().library?.items[0].title).toBe('newest');
});
it('does not let an older mutation response overwrite a newer mutation for another plugin', async () => {
const make = (pluginId: string, title: string): MarketplaceLibraryProjection => ({
library: {
total: 1, stale: false, fetchedAt: 1,
items: [{
pluginId, title, summary: title, category: 'tools', acquisition: 'free',
acquisitionMode: 'user_acquired', catalogStatus: 'active', runtimeStatus: 'enabled',
acquiredAt: '2026-08-28T00:00:00Z', removedAt: null, stableVersion: '1.0.0', betaVersion: null,
}],
},
installations: [],
});
for (const order of ['a-then-b', 'b-then-a'] as const) {
const a = deferred<MarketplaceLibraryProjection>();
const b = deferred<MarketplaceLibraryProjection>();
const store = createPluginMarketplaceStore({
acquire: vi.fn((pluginId: string) => pluginId === 'makelore.a' ? a.promise : b.promise),
});
store.getState().activateAccount('account-a');
const aRequest = store.getState().acquire('makelore.a');
const bRequest = store.getState().acquire('makelore.b');
if (order === 'a-then-b') {
a.resolve(make('makelore.a', 'A older')); await aRequest;
b.resolve(make('makelore.b', 'B newer')); await bRequest;
} else {
b.resolve(make('makelore.b', 'B newer')); await bRequest;
a.resolve(make('makelore.a', 'A older')); await aRequest;
}
expect(store.getState().library?.items[0].title).toBe('B newer');
}
});
it('calls only the selected state mutation', async () => {
const acquire = vi.fn().mockResolvedValue(projection('Acquired'));
const install = vi.fn().mockResolvedValue({ status: 'installed', pluginId: 'makelore.notes', version: '1.0.0' });
@@ -86,4 +133,21 @@ describe('plugin Marketplace store', () => {
expect(install).toHaveBeenCalledOnce();
expect(setProjectEnabled).not.toHaveBeenCalled();
});
it('projects a bounded installation failure on the affected My Plugins entry', async () => {
const error = Object.assign(new Error('Release signature is invalid'), {
code: 'plugin_signature_invalid',
});
const store = createPluginMarketplaceStore({
install: vi.fn().mockRejectedValue(error),
});
store.getState().activateAccount('account-a');
await expect(store.getState().install('makelore.notes')).rejects.toBe(error);
expect(store.getState().installations['makelore.notes']).toMatchObject({
status: 'unavailable',
pluginId: 'makelore.notes',
reason: 'plugin_signature_invalid: Release signature is invalid',
});
});
});