Skip to content

Commit

Permalink
feat: display error if not matching containers is found (#115)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* fix: bad conflict resolution

---------

Signed-off-by: axel7083 <[email protected]>
  • Loading branch information
axel7083 authored Jan 25, 2024
1 parent 49ec433 commit 1f76575
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
36 changes: 36 additions & 0 deletions packages/backend/src/managers/applicationManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
15 changes: 11 additions & 4 deletions packages/backend/src/managers/applicationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 1f76575

Please sign in to comment.