Skip to content

Commit 8fafca8

Browse files
authored
cover sever testcases (#119)
1 parent 783b7c0 commit 8fafca8

4 files changed

Lines changed: 33 additions & 4 deletions

File tree

tests/e2e/pages/cli/anaconda-ai-cmds.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type ShellResult, shellCommand, stripAnsiSgrAndTrim, verifyShellExitCode } from 'tests/utils/CliUtils';
22
import * as cliCommands from './cliCommands';
33
import { expect } from 'tests/test-setup/page-setup';
4-
import { INVALID_MODEL_ERROR_MESSAGE, ModelApi, ServerApi } from '@testdata/model-api';
4+
import { INVALID_MODEL_ERROR_MESSAGE, INVALID_SERVER_NAME, ModelApi, ServerApi } from '@testdata/model-api';
55

66
// CLI helpers for Anaconda AI package CLI commands.
77
export class AnacondaAiCli {
@@ -59,9 +59,10 @@ export class AnacondaAiCli {
5959
const server = servers.find(s => s.model === expectedModelFile);
6060

6161
expect(server, `Expected server for model "${expectedModelFile}" to appear in servers list`).toBeDefined();
62-
expect(server!.server_id, `Expected server_id to contain model name "${modelName}"`).toContain(modelName);
63-
expect(server!.model, `Expected model to be "${expectedModelFile}"`).toBe(expectedModelFile);
64-
expect(server!.status, `Expected server status to be "running"`).toBe('running');
62+
const { server_id, model, status } = server as ServerApi;
63+
expect(server_id, `Expected server_id to contain model name "${modelName}"`).toContain(modelName);
64+
expect(model, `Expected model to be "${expectedModelFile}"`).toBe(expectedModelFile);
65+
expect(status, `Expected server status to be "running"`).toBe('running');
6566
}
6667

6768
// Executes `anaconda ai download <model>/<quant>` (positional; no --model)
@@ -163,6 +164,22 @@ export class AnacondaAiCli {
163164
).toBeTruthy();
164165
}
165166

167+
// Executes `anaconda ai stop <serverName>` with a non-existent server name
168+
public async runStopModelNotFoundCommand(): Promise<ShellResult> {
169+
return await shellCommand(cliCommands.stopModelNotFoundCmd(INVALID_SERVER_NAME));
170+
}
171+
172+
// Validates that stopping a non-existent server exits non-zero with a ServerNotFoundError
173+
public verifyStopModelNotFoundCommand(result: ShellResult): void {
174+
expect(result.exitCode, 'Expected non-zero exit code for unknown server').not.toBe(0);
175+
176+
const output = stripAnsiSgrAndTrim(result.output).toLowerCase();
177+
expect(
178+
output.includes('servernotfounderror') || output.includes('was not found'),
179+
'Expected ServerNotFoundError for unknown server',
180+
).toBeTruthy();
181+
}
182+
166183
// Validates that launching with an invalid format exits non-zero with a ValueError
167184
public verifyLaunchModelInvalidFormatCommand(result: ShellResult): void {
168185
expect(result.exitCode, 'Expected non-zero exit code for invalid format').not.toBe(0);

tests/e2e/pages/cli/cliCommands.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ export const stopModelCmd = (modelName: string, modelQuantization: string): stri
5151
// Stop and remove server — same as stop but with --rm to delete it
5252
export const stopAndRemoveModelCmd = (modelName: string, modelQuantization: string): string =>
5353
condaRun(`anaconda ai stop ${modelName}_${modelQuantization}.gguf --rm`);
54+
55+
// Negative: stop a server that does not exist — triggers ServerNotFoundError
56+
export const stopModelNotFoundCmd = (serverName: string): string =>
57+
condaRun(`anaconda ai stop ${serverName}`);

tests/e2e/specs/cli/anaconda-ai.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,9 @@ test.describe('Anaconda AI CLI Commands @anaconda-ai', () => {
101101
const result = await anacondaAiCli.runLaunchModelCommand(INVALID_MODEL_NAME, DOWNLOAD_TEST_MODEL_QUANTIZATION);
102102
anacondaAiCli.verifyLaunchModelNotFoundCommand(result);
103103
});
104+
105+
test('anaconda ai stop - unknown server returns ServerNotFoundError', async ({ anacondaAiCli }) => {
106+
const result = await anacondaAiCli.runStopModelNotFoundCommand();
107+
anacondaAiCli.verifyStopModelNotFoundCommand(result);
108+
});
104109
});

tests/e2e/testdata/model-api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ export const DOWNLOAD_TEST_MODEL_QUANTIZATION = 'q4_k_m';
2929
export const INVALID_MODEL_NAME = 'invalid-model';
3030
export const INVALID_MODEL_QUANTIZATION = 'invalid-quantization';
3131
export const INVALID_MODEL_ERROR_MESSAGE = 'you must include the quantization method in the model';
32+
33+
// Invalid server name for negative stop tests
34+
export const INVALID_SERVER_NAME = 'invalid-server';

0 commit comments

Comments
 (0)