fix(pi): serialize managed provider catalog writes

This commit is contained in:
2026-08-24 17:00:05 +08:00
parent 2ff2e4af79
commit 0d26d17cfc
3 changed files with 56 additions and 11 deletions

View File

@@ -194,6 +194,21 @@ describe('Pi Provider catalog', () => {
expect(await readFile(filePath, 'utf8')).toBe('existing-catalog\n');
});
it('serializes concurrent writes to the shared managed catalog', async () => {
const root = await mkdtemp(path.join(tmpdir(), 'makelore-pi-provider-concurrent-'));
temporaryRoots.push(root);
const filePath = path.join(root, 'models.json');
const catalog = buildPiProviderCatalog({ accounts: [account()] });
await Promise.all(Array.from({ length: 8 }, async () => await writePiProviderCatalog(
filePath,
catalog,
{ accountId: 'account-one', modelId: 'gpt-5.4', thinkingLevel: 'off' },
)));
expect(JSON.parse(await readFile(filePath, 'utf8'))).toEqual(catalog.modelsFile);
});
it('fails closed when a non-local credential is unavailable', async () => {
const provider = account();
const descriptor = buildPiProviderCatalog({ accounts: [provider] }).descriptors[0]!;