-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into fix/openai_coverage_misc
- Loading branch information
Showing
25 changed files
with
624 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
cortex-js/src/infrastructure/commanders/benchmark.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { CommandRunner, SubCommand } from 'nest-commander'; | ||
import { BenchmarkCliUsecases } from './usecases/benchmark.cli.usecases'; | ||
|
||
@SubCommand({ | ||
name: 'benchmark', | ||
subCommands: [], | ||
description: | ||
'Benchmark and analyze the performance of a specific AI model using a variety of system resources', | ||
}) | ||
export class BenchmarkCommand extends CommandRunner { | ||
constructor(private readonly benchmarkUsecases: BenchmarkCliUsecases) { | ||
super(); | ||
} | ||
|
||
async run(): Promise<void> { | ||
return this.benchmarkUsecases.benchmark(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
cortex-js/src/infrastructure/commanders/test/helpers.command.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { TestingModule } from '@nestjs/testing'; | ||
import { spy, Stub, stubMethod } from 'hanbi'; | ||
import { CommandTestFactory } from 'nest-commander-testing'; | ||
import { CommandModule } from '@/command.module'; | ||
import { LogService } from '@/infrastructure/commanders/test/log.service'; | ||
import axios from 'axios'; | ||
|
||
let commandInstance: TestingModule, | ||
exitSpy: Stub<typeof process.exit>, | ||
stdoutSpy: Stub<typeof process.stdout.write>, | ||
stderrSpy: Stub<typeof process.stderr.write>; | ||
export const timeout = 500000; | ||
|
||
beforeEach( | ||
() => | ||
new Promise<void>(async (res) => { | ||
stubMethod(process.stderr, 'write'); | ||
exitSpy = stubMethod(process, 'exit'); | ||
stdoutSpy = stubMethod(process.stdout, 'write'); | ||
stderrSpy = stubMethod(process.stderr, 'write'); | ||
commandInstance = await CommandTestFactory.createTestingCommand({ | ||
imports: [CommandModule], | ||
}) | ||
.overrideProvider(LogService) | ||
.useValue({ log: spy().handler }) | ||
.compile(); | ||
res(); | ||
stdoutSpy.reset(); | ||
stderrSpy.reset(); | ||
}), | ||
); | ||
|
||
describe('Helper commands', () => { | ||
test( | ||
'Init with hardware auto detection', | ||
async () => { | ||
await CommandTestFactory.run(commandInstance, ['init', '-s']); | ||
|
||
// Wait for a brief period to allow the command to execute | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
|
||
expect(stdoutSpy.firstCall?.args.length).toBeGreaterThan(0); | ||
}, | ||
timeout, | ||
); | ||
|
||
test('Chat with option -m', async () => { | ||
const logMock = stubMethod(console, 'log'); | ||
|
||
await CommandTestFactory.run(commandInstance, [ | ||
'chat', | ||
// '-m', | ||
// 'hello', | ||
// '>output.txt', | ||
]); | ||
expect(logMock.firstCall?.args[0]).toBe("Inorder to exit, type 'exit()'."); | ||
// expect(exitSpy.callCount).toBe(1); | ||
// expect(exitSpy.firstCall?.args[0]).toBe(1); | ||
}); | ||
|
||
test('Show / kill running models', async () => { | ||
const tableMock = stubMethod(console, 'table'); | ||
|
||
const logMock = stubMethod(console, 'log'); | ||
await CommandTestFactory.run(commandInstance, ['kill']); | ||
await CommandTestFactory.run(commandInstance, ['ps']); | ||
|
||
expect(logMock.firstCall?.args[0]).toEqual({ | ||
message: 'Cortex stopped successfully', | ||
status: 'success', | ||
}); | ||
expect(tableMock.firstCall?.args[0]).toBeInstanceOf(Array); | ||
expect(tableMock.firstCall?.args[0].length).toEqual(0); | ||
}); | ||
|
||
test('Help command return guideline to users', async () => { | ||
await CommandTestFactory.run(commandInstance, ['-h']); | ||
expect(stdoutSpy.firstCall?.args).toBeInstanceOf(Array); | ||
expect(stdoutSpy.firstCall?.args.length).toBe(1); | ||
expect(stdoutSpy.firstCall?.args[0]).toContain('display help for command'); | ||
|
||
expect(exitSpy.callCount).toBeGreaterThan(1); | ||
expect(exitSpy.firstCall?.args[0]).toBe(0); | ||
}); | ||
|
||
test('Should handle missing command', async () => { | ||
await CommandTestFactory.run(commandInstance, ['--unknown']); | ||
expect(stderrSpy.firstCall?.args[0]).toContain('error: unknown option'); | ||
expect(stderrSpy.firstCall?.args[0]).toContain('--unknown'); | ||
expect(exitSpy.callCount).toBe(1); | ||
expect(exitSpy.firstCall?.args[0]).toBe(1); | ||
}); | ||
|
||
test('Local API server via localhost:1337/api', async () => { | ||
await CommandTestFactory.run(commandInstance, ['serve']); | ||
|
||
// Add a delay of 1000 milliseconds (1 second) | ||
return new Promise<void>(async (resolve) => { | ||
setTimeout(async () => { | ||
// Send a request to the API server to check if it's running | ||
const response = await axios.get('http://localhost:1337/api'); | ||
expect(response.status).toBe(200); | ||
resolve(); | ||
}, 1000); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class LogService { | ||
log(...args: any[]): void { | ||
console.log(...args); | ||
} | ||
} |
67 changes: 0 additions & 67 deletions
67
cortex-js/src/infrastructure/commanders/test/model-list.command.spec.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.