fix(coding): remediate ML-07 plugin authority

This commit is contained in:
2026-08-27 20:40:58 +08:00
parent 9407c67df2
commit cf13aa7eba
29 changed files with 1008 additions and 214 deletions

View File

@@ -55,4 +55,60 @@ describe('coding plugins store', () => {
await store.getState().load('other-project');
expect(store.getState().dataService).toBeNull();
});
it('commits only the latest project load success or error', async () => {
const pending = new Map<string, {
resolve: (value: ReturnType<typeof projection>) => void;
reject: (reason: Error) => void;
}>();
const list = vi.fn((projectId: string) => new Promise<ReturnType<typeof projection>>((resolve, reject) => {
pending.set(projectId, { resolve, reject });
}));
const store = createCodingPluginsStore({ list });
const first = store.getState().load('project-a');
const second = store.getState().load('project-b');
pending.get('project-b')?.resolve(projection(false, 'project-b'));
await second;
pending.get('project-a')?.resolve(projection(false, 'project-a'));
await first;
expect(store.getState()).toMatchObject({
projectId: 'project-b', loadState: 'ready', error: null,
});
const third = store.getState().load('project-a');
const fourth = store.getState().load('project-b');
pending.get('project-b')?.resolve(projection(false, 'project-b'));
await fourth;
pending.get('project-a')?.reject(new Error('late project-a failure'));
await expect(third).rejects.toThrow('late project-a failure');
expect(store.getState()).toMatchObject({
projectId: 'project-b', loadState: 'ready', error: null,
});
});
it('retains ready Data Service usage when enabling an existing instance', async () => {
const readyProjection = projection(true);
readyProjection.items[0] = {
...readyProjection.items[0], state: 'ready', backend: { status: 'ready' },
};
const existing = {
instance_id: 'instance-1', project_id: 'cloud-project', collections: ['todos'],
usage: { document_count: 3, total_bytes: 128 },
limits: { max_collections: 20, max_documents: 1000, max_total_bytes: 20971520, max_document_bytes: 65536, list_default_limit: 50, list_max_limit: 100, list_max_data_bytes: 1048576, mutations_per_minute: 120 },
created_at: '2026-08-27T00:00:00Z', updated_at: '2026-08-27T00:00:00Z',
};
const inspectDataService = vi.fn().mockResolvedValue({
success: true, status: 200, code: null, error: null, retryable: false, data: existing,
});
const store = createCodingPluginsStore({
setEnabled: vi.fn().mockResolvedValue(readyProjection), inspectDataService,
});
await store.getState().setEnabled('local-project', 'makelore.data-service', true);
expect(inspectDataService).toHaveBeenCalledOnce();
expect(store.getState().dataService).toEqual(existing);
expect(store.getState().projection).toEqual(readyProjection);
});
});