Skip to content

Commit

Permalink
fix: fix tests and reorganize based on review
Browse files Browse the repository at this point in the history
Signed-off-by: lstocchi <[email protected]>
  • Loading branch information
lstocchi committed Mar 11, 2024
1 parent a55667c commit 04aaf81
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 15 deletions.
2 changes: 2 additions & 0 deletions packages/backend/src/managers/modelsManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,9 @@ describe('downloadModel', () => {

mocks.onEventDownloadMock.mockImplementation(listener => {
listener({
id: 'id',
status: 'completed',
duration: 1000,
});
});

Expand Down
10 changes: 5 additions & 5 deletions packages/backend/src/managers/modelsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import * as podmanDesktopApi from '@podman-desktop/api';
import { Downloader } from '../utils/downloader';
import type { TaskRegistry } from '../registries/TaskRegistry';
import type { Task } from '@shared/src/models/ITask';
import type { ProgressiveEvent } from '../utils/progressiveEvent';
import { isCompletionProgressiveEvent, isProgressProgressiveEvent } from '../utils/progressiveEvent';
import { Uploader } from '../models/uploader';
import type { ProgressiveEvent } from '../models/progressiveEvent';
import { isCompletionProgressiveEvent, isExecutingProgressiveEvent } from '../models/progressiveEvent';
import { Uploader } from '../utils/uploader';

export class ModelsManager implements Disposable {
#modelsDir: string;
Expand Down Expand Up @@ -228,7 +228,7 @@ export class ModelsManager implements Disposable {
}

tasks.forEach(task => {
if (isProgressProgressiveEvent(event)) {
if (isExecutingProgressiveEvent(event)) {
task.state = 'loading';
task.progress = event.value;
} else if (isCompletionProgressiveEvent(event)) {
Expand Down Expand Up @@ -316,7 +316,7 @@ export class ModelsManager implements Disposable {

const uploader = new Uploader(localModelPath);
uploader.onEvent((event: ProgressiveEvent) => {
if (isProgressProgressiveEvent(event)) {
if (isExecutingProgressiveEvent(event)) {
task.state = 'loading';
task.progress = event.value;
} else if (isCompletionProgressiveEvent(event)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface CompletionProgressiveEvent extends ProgressiveEvent {
duration: number;
}

export interface ProgressProgressiveEvent extends ProgressiveEvent {
export interface ExecutingProgressiveEvent extends ProgressiveEvent {
status: 'progress';
value: number;
}
Expand All @@ -43,7 +43,7 @@ export const isCompletionProgressiveEvent = (value: unknown): value is Completio
);
};

export const isProgressProgressiveEvent = (value: unknown): value is ProgressProgressiveEvent => {
export const isExecutingProgressiveEvent = (value: unknown): value is ExecutingProgressiveEvent => {
return (
!!value && typeof value === 'object' && 'status' in value && value['status'] === 'progress' && 'value' in value
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { expect, test, describe, vi } from 'vitest';
import { WSLUploader } from './WSLUploader';
import * as podmanDesktopApi from '@podman-desktop/api';
import * as utils from '../utils/podman';
import * as utils from './podman';
import { beforeEach } from 'node:test';

const mocks = vi.hoisted(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import path from 'node:path';
import * as podmanDesktopApi from '@podman-desktop/api';
import { getFirstRunningMachine, getPodmanCli } from '../utils/podman';
import { getFirstRunningMachine, getPodmanCli } from './podman';
import type { UploadWorker } from './uploader';

export class WSLUploader implements UploadWorker {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/utils/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { getDurationSecondsSince } from './utils';
import { createWriteStream, promises } from 'node:fs';
import https from 'node:https';
import { EventEmitter, type Event } from '@podman-desktop/api';
import type { CompletionProgressiveEvent, ProgressProgressiveEvent, ProgressiveEvent } from './progressiveEvent';
import type { CompletionProgressiveEvent, ExecutingProgressiveEvent, ProgressiveEvent } from '../models/progressiveEvent';

export class Downloader {
private readonly _onEvent = new EventEmitter<ProgressiveEvent>();
Expand Down Expand Up @@ -129,7 +129,7 @@ export class Downloader {
id: this.requestedIdentifier,
status: 'progress',
value: progressValue,
} as ProgressProgressiveEvent);
} as ExecutingProgressiveEvent);
}
});
resp.pipe(stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ beforeEach(() => {
describe('perform', () => {
test('should return localModelPath if no workers for current system', async () => {
vi.mocked(podmanDesktopApi.env).isWindows = false;
const result = await uploader.perform();
const result = await uploader.perform('id');
expect(result).toBe('localpath');
});
test('should return remote path if there is a worker for current system', async () => {
vi.spyOn(WSLUploader.prototype, 'upload').mockResolvedValue('remote');
vi.mocked(podmanDesktopApi.env).isWindows = true;
const result = await uploader.perform();
const result = await uploader.perform('id');
expect(result).toBe('remote');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import { EventEmitter, type Event } from '@podman-desktop/api';
import { WSLUploader } from './WSLUploader';
import { getDurationSecondsSince } from '../utils/utils';
import type { CompletionProgressiveEvent, ProgressiveEvent } from '../utils/progressiveEvent';
import { getDurationSecondsSince } from './utils';
import type { CompletionProgressiveEvent, ProgressiveEvent } from '../models/progressiveEvent';

export interface UploadWorker {
canUpload: () => boolean;
Expand Down

0 comments on commit 04aaf81

Please sign in to comment.