|
1 | 1 | import { type ShellResult, shellCommand, stripAnsiSgrAndTrim, verifyShellExitCode } from 'tests/utils/CliUtils'; |
2 | 2 | import * as cliCommands from './cliCommands'; |
3 | 3 | 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'; |
5 | 5 |
|
6 | 6 | // CLI helpers for Anaconda AI package CLI commands. |
7 | 7 | export class AnacondaAiCli { |
@@ -59,9 +59,10 @@ export class AnacondaAiCli { |
59 | 59 | const server = servers.find(s => s.model === expectedModelFile); |
60 | 60 |
|
61 | 61 | 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'); |
65 | 66 | } |
66 | 67 |
|
67 | 68 | // Executes `anaconda ai download <model>/<quant>` (positional; no --model) |
@@ -163,6 +164,22 @@ export class AnacondaAiCli { |
163 | 164 | ).toBeTruthy(); |
164 | 165 | } |
165 | 166 |
|
| 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 | + |
166 | 183 | // Validates that launching with an invalid format exits non-zero with a ValueError |
167 | 184 | public verifyLaunchModelInvalidFormatCommand(result: ShellResult): void { |
168 | 185 | expect(result.exitCode, 'Expected non-zero exit code for invalid format').not.toBe(0); |
|
0 commit comments