diff --git a/packages/backend/src/managers/catalogManager.spec.ts b/packages/backend/src/managers/catalogManager.spec.ts index 4eb5aba0f..00e1f7cd6 100644 --- a/packages/backend/src/managers/catalogManager.spec.ts +++ b/packages/backend/src/managers/catalogManager.spec.ts @@ -42,6 +42,7 @@ vi.mock('node:fs', () => { readFile: vi.fn(), stat: vi.fn(), writeFile: vi.fn(), + mkdir: vi.fn(), }, }; }); @@ -183,6 +184,7 @@ test('expect to call writeFile in addLocalModelsToCatalog with catalog updated', }, ]); + expect(promises.mkdir).toHaveBeenCalled(); expect(writeFileMock).toBeCalledWith('path', JSON.stringify(updatedCatalog, undefined, 2), 'utf-8'); }); diff --git a/packages/backend/src/managers/catalogManager.ts b/packages/backend/src/managers/catalogManager.ts index 2ac211b74..c0bc030bc 100644 --- a/packages/backend/src/managers/catalogManager.ts +++ b/packages/backend/src/managers/catalogManager.ts @@ -225,6 +225,9 @@ export class CatalogManager extends Publisher implements Dis // Add all our models infos to the user's models catalog content.models.push(...models); + // ensure parent directory exists + await promises.mkdir(path.dirname(userCatalogPath), { recursive: true }); + // overwrite the existing catalog return promises.writeFile(userCatalogPath, JSON.stringify(content, undefined, 2), 'utf-8'); }