From 1f76575925a32312148354ad8dc43807c78816ca Mon Sep 17 00:00:00 2001 From: axel7083 <42176370+axel7083@users.noreply.github.com> Date: Thu, 25 Jan 2024 10:20:38 +0100 Subject: [PATCH] feat: display error if not matching containers is found (#115) * feat: display error if not matching containers is found * tests: ensuring an error is thrown when no containers have been found * feat: display error if not matching containers is found * tests: ensuring an error is thrown when no containers have been found * fix: tests Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com> * fix: bad conflict resolution --------- Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com> --- .../src/managers/applicationManager.spec.ts | 36 +++++++++++++++++++ .../src/managers/applicationManager.ts | 15 +++++--- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/managers/applicationManager.spec.ts b/packages/backend/src/managers/applicationManager.spec.ts index cdbe1a8b3..5c7b79087 100644 --- a/packages/backend/src/managers/applicationManager.spec.ts +++ b/packages/backend/src/managers/applicationManager.spec.ts @@ -193,4 +193,40 @@ describe('pullApplication', () => { expect(cloneRepositoryMock).not.toHaveBeenCalled(); expect(downloadModelMainSpy).not.toHaveBeenCalled(); }); + + test('pullApplication should mark the loading config as error if not container are found', async () => { + mockForPullApplication({ + recipeFolderExists: true, + }); + + const recipe: Recipe = { + id: 'recipe1', + name: 'Recipe 1', + categories: [], + description: '', + readme: '', + repository: 'repo', + }; + const model: ModelInfo = { + id: 'model1', + description: '', + hw: '', + license: '', + name: 'Model 1', + popularity: 1, + registry: '', + url: '', + }; + + mocks.parseYamlMock.mockReturnValue({ + application: { + containers: [], + }, + }); + + await expect(manager.pullApplication(recipe, model)).rejects.toThrowError('No containers available.'); + + expect(cloneRepositoryMock).not.toHaveBeenCalled(); + expect(downloadModelMainSpy).not.toHaveBeenCalled(); + }); }); diff --git a/packages/backend/src/managers/applicationManager.ts b/packages/backend/src/managers/applicationManager.ts index 940b562c2..c758bb59e 100644 --- a/packages/backend/src/managers/applicationManager.ts +++ b/packages/backend/src/managers/applicationManager.ts @@ -126,15 +126,22 @@ export class ApplicationManager { throw new Error('Cannot load configuration file.'); } - // Mark as success. - loadingConfiguration.state = 'success'; - taskUtil.setTask(loadingConfiguration); - // Filter the containers based on architecture const filteredContainers = aiConfig.application.containers.filter( container => container.arch === undefined || container.arch === arch(), ); + if (filteredContainers.length > 0) { + // Mark as success. + loadingConfiguration.state = 'success'; + taskUtil.setTask(loadingConfiguration); + } else { + // Mark as failure. + loadingConfiguration.state = 'error'; + taskUtil.setTask(loadingConfiguration); + throw new Error('No containers available.'); + } + if (!this.modelsManager.isModelOnDisk(model.id)) { // Download model taskUtil.setTask({