Skip to content

Commit

Permalink
feat: creating task in task manager (#152)
Browse files Browse the repository at this point in the history
* feat: creating task in task manager

* test: ensuring pull application create a task in the api

* fix: dangling promises

* fix: using podman error propagation for error management

* fix: prettier

* test: fixing missing resolved value
  • Loading branch information
axel7083 authored Jan 29, 2024
1 parent c9c97bb commit b6e2ed7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
34 changes: 33 additions & 1 deletion packages/backend/src/studio-api-impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@ vi.mock('@podman-desktop/api', () => {
};
});

const mocks = vi.hoisted(() => ({
withProgressMock: vi.fn(),
}));

vi.mock('@podman-desktop/api', async () => {
return {
window: {
withProgress: mocks.withProgressMock,
},
ProgressLocation: {
TASK_WIDGET: 'TASK_WIDGET',
},
fs: {
createFileSystemWatcher: () => ({
onDidCreate: vi.fn(),
onDidDelete: vi.fn(),
onDidChange: vi.fn(),
}),
},
};
});

let studioApiImpl: StudioApiImpl;
let catalogManager;

Expand All @@ -71,7 +93,6 @@ beforeEach(async () => {

// Creating StudioApiImpl
studioApiImpl = new StudioApiImpl(
appUserDirectory,
{} as unknown as ApplicationManager,
{} as unknown as RecipeStatusRegistry,
{} as unknown as PlayGroundManager,
Expand Down Expand Up @@ -126,3 +147,14 @@ test('expect correct model is returned with valid id when the user catalog is va
expect(model.registry).toEqual('Hugging Face');
expect(model.url).toEqual('https://model1.example.com');
});

test('expect pull application to call the withProgress api method', async () => {
vi.spyOn(fs, 'existsSync').mockReturnValue(true);
vi.spyOn(fs.promises, 'readFile').mockResolvedValue(JSON.stringify(userContent));

mocks.withProgressMock.mockResolvedValue(undefined);

await catalogManager.loadCatalog();
await studioApiImpl.pullApplication('recipe 1');
expect(mocks.withProgressMock).toHaveBeenCalledOnce();
});
12 changes: 8 additions & 4 deletions packages/backend/src/studio-api-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import type { ModelsManager } from './managers/modelsManager';

export class StudioApiImpl implements StudioAPI {
constructor(
private appUserDirectory: string,
private applicationManager: ApplicationManager,
private recipeStatusRegistry: RecipeStatusRegistry,
private playgroundManager: PlayGroundManager,
Expand Down Expand Up @@ -73,9 +72,14 @@ export class StudioApiImpl implements StudioAPI {
const model = await this.getModelById(modelId);

// Do not wait for the pull application, run it separately
this.applicationManager.pullApplication(recipe, model).catch((error: unknown) => console.warn(error));

return Promise.resolve(undefined);
void podmanDesktopApi.window
.withProgress<void>(
{ location: podmanDesktopApi.ProgressLocation.TASK_WIDGET, title: `Pulling ${recipe.name}.` },
() => this.applicationManager.pullApplication(recipe, model),
)
.catch(() => {
this.recipeStatusRegistry.setStatus(recipeId, { recipeId: recipeId, state: 'error', tasks: [] });
});
}

async getLocalModels(): Promise<ModelInfo[]> {
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export class Studio {

// Creating StudioApiImpl
this.studioApi = new StudioApiImpl(
appUserDirectory,
applicationManager,
recipeStatusRegistry,
this.playgroundManager,
Expand Down

0 comments on commit b6e2ed7

Please sign in to comment.