voltagegpu-cli 1.3.0__tar.gz → 1.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/CHANGELOG.md +35 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/PKG-INFO +7 -6
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/README.md +6 -5
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/pyproject.toml +1 -1
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/tests/test_cli.py +29 -11
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/tests/test_cli_account.py +141 -141
- voltagegpu_cli-1.3.1/tests/test_hardening.py +165 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/__init__.py +1 -1
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/cli/cmd_account.py +176 -176
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/cli/cmd_deploy.py +50 -24
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/cli/cmd_misc.py +20 -6
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/cli/cmd_pods.py +24 -15
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/cli/main.py +12 -6
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/cli/output.py +29 -6
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/sdk/client.py +2 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/sdk/config.py +47 -31
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/sdk/errors.py +2 -1
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/sdk/models.py +14 -2
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/sdk/ssh.py +48 -3
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/.gitignore +0 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/LICENSE +0 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/examples/deploy_standard_pod.py +0 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/tests/__init__.py +0 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/tests/conftest.py +0 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/tests/test_client.py +0 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/tests/test_config.py +0 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/tests/test_live.py +0 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/tests/test_models.py +0 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/tests/test_package.py +0 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/tests/test_ssh.py +0 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/__main__.py +0 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/cli/__init__.py +0 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/cli/cmd_machines.py +0 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/cli/state.py +0 -0
- {voltagegpu_cli-1.3.0 → voltagegpu_cli-1.3.1}/volt/sdk/__init__.py +0 -0
|
@@ -4,6 +4,41 @@ All notable changes to `voltagegpu-cli` are documented here. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [1.3.1] - 2026-10-10
|
|
8
|
+
|
|
9
|
+
Security hardening after an independent review of 1.3.0. Upgrade recommended.
|
|
10
|
+
|
|
11
|
+
### Security
|
|
12
|
+
- The SSH command returned by the API is only ever displayed in its validated,
|
|
13
|
+
rebuilt form (`ssh -p PORT user@host`). A command of any other form is
|
|
14
|
+
neither shown nor run, so a tampered answer cannot end up copied into a
|
|
15
|
+
shell from `pods show`, `pods wait` or `deploy --wait`.
|
|
16
|
+
- Server text (machine names, locations, error messages, ids) can no longer
|
|
17
|
+
inject terminal escape sequences or rich markup: control characters are
|
|
18
|
+
stripped and the text is printed literally. Before, an odd string could also
|
|
19
|
+
crash the CLI right after a deploy.
|
|
20
|
+
- `voltagegpu verify` calls voltage-verify in-process instead of
|
|
21
|
+
`python -m voltage_verify`, which put the current directory first on the
|
|
22
|
+
module path (a `voltage_verify.py` next to a downloaded bundle would run).
|
|
23
|
+
- `voltagegpu ssh` looks for `ssh` on PATH only, never in the current
|
|
24
|
+
directory (Windows `shutil.which` checks it first), and never runs a
|
|
25
|
+
`.bat`/`.cmd` script.
|
|
26
|
+
- The one-time sudo password of a Confidential VM is printed exactly as
|
|
27
|
+
received (no markup or emoji parsing could alter it).
|
|
28
|
+
- The API key is only sent to `voltagegpu.com` hosts (or localhost) unless
|
|
29
|
+
`VOLT_ALLOW_CUSTOM_BASE_URL=1` is set.
|
|
30
|
+
- A malformed `~/.volt/config.ini` no longer prints its content (which may be
|
|
31
|
+
the key) in an error; an existing file is set to 0600 before the key is
|
|
32
|
+
written.
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
- `deploy standard --cheapest --yes` requires `--max-price`, so a script never
|
|
36
|
+
rents an expensive machine by surprise.
|
|
37
|
+
- If the deploy request gets no answer, the CLI says the deploy may have gone
|
|
38
|
+
through and to check `voltagegpu pods list`, instead of suggesting a retry.
|
|
39
|
+
- A warning is printed if the hourly price rose between the listing and the
|
|
40
|
+
deploy.
|
|
41
|
+
|
|
7
42
|
## [1.3.0] - 2026-10-10
|
|
8
43
|
|
|
9
44
|
Realigns the CLI with the product as it is today: Confidential VMs (Intel TDX)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: voltagegpu-cli
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.1
|
|
4
4
|
Summary: VoltageGPU CLI and Python SDK: deploy Confidential VMs (Intel TDX) and standard GPU pods, SSH in, stop them, check your balance.
|
|
5
5
|
Project-URL: Homepage, https://voltagegpu.com
|
|
6
6
|
Project-URL: Documentation, https://docs.voltagegpu.com/cli
|
|
@@ -169,7 +169,7 @@ Every list command takes `--json`; deploys and stops take `--yes`.
|
|
|
169
169
|
|
|
170
170
|
```bash
|
|
171
171
|
# Deploy the cheapest standard machine, wait for SSH, run a job, release it.
|
|
172
|
-
POD=$(voltagegpu deploy standard --cheapest --yes --json | jq -r .deploy.pod_id)
|
|
172
|
+
POD=$(voltagegpu deploy standard --cheapest --max-price 1 --yes --json | jq -r .deploy.pod_id)
|
|
173
173
|
voltagegpu pods wait "$POD"
|
|
174
174
|
voltagegpu ssh "$POD" -o StrictHostKeyChecking=accept-new -- nvidia-smi
|
|
175
175
|
voltagegpu pods stop "$POD" --yes
|
|
@@ -211,7 +211,7 @@ curl https://api.voltagegpu.com/api/volt/pods -H "X-API-Key: $VOLT_API_KEY"
|
|
|
211
211
|
| Setting | Where |
|
|
212
212
|
| --- | --- |
|
|
213
213
|
| API key | `--api-key` of `login`, `VOLT_API_KEY` (or `VOLTAGEGPU_API_KEY`), then `~/.volt/config.ini` |
|
|
214
|
-
| API base URL | `VOLT_BASE_URL` (https only
|
|
214
|
+
| API base URL | `VOLT_BASE_URL` (https only, voltagegpu.com hosts unless `VOLT_ALLOW_CUSTOM_BASE_URL=1`; default `https://api.voltagegpu.com/api`) |
|
|
215
215
|
| Debug | `VOLT_DEBUG=1` shows tracebacks |
|
|
216
216
|
|
|
217
217
|
`voltagegpu config` shows where the key comes from, masked.
|
|
@@ -222,9 +222,10 @@ curl https://api.voltagegpu.com/api/volt/pods -H "X-API-Key: $VOLT_API_KEY"
|
|
|
222
222
|
never followed and certificates are always verified.
|
|
223
223
|
- The key is never printed. `~/.volt/config.ini` is created readable by you
|
|
224
224
|
only, and `voltagegpu config` warns if its permissions are too open.
|
|
225
|
-
- The SSH command returned by the API is parsed into user, host and port
|
|
226
|
-
|
|
227
|
-
|
|
225
|
+
- The SSH command returned by the API is parsed into user, host and port, only
|
|
226
|
+
that rebuilt form is ever shown, and ssh is started without a shell (and never
|
|
227
|
+
from the current directory), so a tampered answer cannot run a command on
|
|
228
|
+
your machine. Server text is printed literally, without terminal escapes.
|
|
228
229
|
- `ssh-keys add` refuses private keys.
|
|
229
230
|
|
|
230
231
|
Report a vulnerability to contact@voltagegpu.com.
|
|
@@ -105,7 +105,7 @@ Every list command takes `--json`; deploys and stops take `--yes`.
|
|
|
105
105
|
|
|
106
106
|
```bash
|
|
107
107
|
# Deploy the cheapest standard machine, wait for SSH, run a job, release it.
|
|
108
|
-
POD=$(voltagegpu deploy standard --cheapest --yes --json | jq -r .deploy.pod_id)
|
|
108
|
+
POD=$(voltagegpu deploy standard --cheapest --max-price 1 --yes --json | jq -r .deploy.pod_id)
|
|
109
109
|
voltagegpu pods wait "$POD"
|
|
110
110
|
voltagegpu ssh "$POD" -o StrictHostKeyChecking=accept-new -- nvidia-smi
|
|
111
111
|
voltagegpu pods stop "$POD" --yes
|
|
@@ -147,7 +147,7 @@ curl https://api.voltagegpu.com/api/volt/pods -H "X-API-Key: $VOLT_API_KEY"
|
|
|
147
147
|
| Setting | Where |
|
|
148
148
|
| --- | --- |
|
|
149
149
|
| API key | `--api-key` of `login`, `VOLT_API_KEY` (or `VOLTAGEGPU_API_KEY`), then `~/.volt/config.ini` |
|
|
150
|
-
| API base URL | `VOLT_BASE_URL` (https only
|
|
150
|
+
| API base URL | `VOLT_BASE_URL` (https only, voltagegpu.com hosts unless `VOLT_ALLOW_CUSTOM_BASE_URL=1`; default `https://api.voltagegpu.com/api`) |
|
|
151
151
|
| Debug | `VOLT_DEBUG=1` shows tracebacks |
|
|
152
152
|
|
|
153
153
|
`voltagegpu config` shows where the key comes from, masked.
|
|
@@ -158,9 +158,10 @@ curl https://api.voltagegpu.com/api/volt/pods -H "X-API-Key: $VOLT_API_KEY"
|
|
|
158
158
|
never followed and certificates are always verified.
|
|
159
159
|
- The key is never printed. `~/.volt/config.ini` is created readable by you
|
|
160
160
|
only, and `voltagegpu config` warns if its permissions are too open.
|
|
161
|
-
- The SSH command returned by the API is parsed into user, host and port
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
- The SSH command returned by the API is parsed into user, host and port, only
|
|
162
|
+
that rebuilt form is ever shown, and ssh is started without a shell (and never
|
|
163
|
+
from the current directory), so a tampered answer cannot run a command on
|
|
164
|
+
your machine. Server text is printed literally, without terminal escapes.
|
|
164
165
|
- `ssh-keys add` refuses private keys.
|
|
165
166
|
|
|
166
167
|
Report a vulnerability to contact@voltagegpu.com.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "voltagegpu-cli"
|
|
7
|
-
version = "1.3.
|
|
7
|
+
version = "1.3.1"
|
|
8
8
|
description = "VoltageGPU CLI and Python SDK: deploy Confidential VMs (Intel TDX) and standard GPU pods, SSH in, stop them, check your balance."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -68,7 +68,7 @@ def test_deploy_standard_refuses_to_charge_without_confirmation_in_a_script(cli_
|
|
|
68
68
|
def test_deploy_standard_cheapest_with_yes(cli_env):
|
|
69
69
|
cli_env.on("GET", "/api/volt/machines", body=list(reversed(STANDARD_MACHINES)))
|
|
70
70
|
cli_env.on("POST", "/api/volt/pods", handler=standard_deploy_answer)
|
|
71
|
-
result = run("deploy", "standard", "--cheapest", "--name", "e2e-1", "--ssh-key", "key_1", "--yes", "--json")
|
|
71
|
+
result = run("deploy", "standard", "--cheapest", "--max-price", "1", "--name", "e2e-1", "--ssh-key", "key_1", "--yes", "--json")
|
|
72
72
|
assert result.exit_code == 0, result.output
|
|
73
73
|
body = cli_env.json_of("POST", "/api/volt/pods")
|
|
74
74
|
assert body == {"provider": "standard", "name": "e2e-1", "machine_id": STANDARD_MACHINES[0]["machine_id"], "ssh_key_id": "key_1"}
|
|
@@ -90,7 +90,7 @@ def test_deploy_standard_unknown_machine_and_bad_name(cli_env):
|
|
|
90
90
|
cli_env.on("GET", "/api/volt/machines", body=STANDARD_MACHINES)
|
|
91
91
|
result = run("deploy", "standard", "--machine", "nope", "--yes")
|
|
92
92
|
assert result.exit_code == 1 and "not in the deployable list" in result.output
|
|
93
|
-
assert run("deploy", "standard", "--cheapest", "--name", "Bad Name;rm", "--yes").exit_code == 2
|
|
93
|
+
assert run("deploy", "standard", "--cheapest", "--max-price", "1", "--name", "Bad Name;rm", "--yes").exit_code == 2
|
|
94
94
|
assert run("deploy", "standard", "--yes").exit_code == 2 # neither --machine nor --cheapest
|
|
95
95
|
|
|
96
96
|
|
|
@@ -142,7 +142,7 @@ def test_ssh_print_rebuilds_the_command(cli_env):
|
|
|
142
142
|
def test_ssh_runs_ssh_without_a_shell(cli_env, monkeypatch):
|
|
143
143
|
cli_env.on("GET", "/api/volt/pods", body=[STANDARD_POD])
|
|
144
144
|
calls = []
|
|
145
|
-
monkeypatch.setattr(pods_mod.
|
|
145
|
+
monkeypatch.setattr(pods_mod.ssh_lookup, "find_ssh_binary", lambda: "/usr/bin/ssh")
|
|
146
146
|
monkeypatch.setattr(pods_mod.subprocess, "call", lambda argv, **kw: calls.append((argv, kw)) or 0)
|
|
147
147
|
result = run("ssh", STANDARD_POD["id"], "-o", "StrictHostKeyChecking=accept-new", "--", "nvidia-smi", "-L")
|
|
148
148
|
assert result.exit_code == 0
|
|
@@ -200,24 +200,42 @@ def test_config_masks_the_key(cli_env):
|
|
|
200
200
|
|
|
201
201
|
|
|
202
202
|
def test_verify_argument_mapping():
|
|
203
|
-
assert verify_argv(["bundle.json", "--offline"])
|
|
204
|
-
assert verify_argv(["quote", "q.bin"])
|
|
205
|
-
assert verify_argv(["--help"])
|
|
203
|
+
assert verify_argv(["bundle.json", "--offline"]) == ["verify", "bundle.json", "--offline"]
|
|
204
|
+
assert verify_argv(["quote", "q.bin"]) == ["quote", "q.bin"]
|
|
205
|
+
assert verify_argv(["--help"]) == ["--help"]
|
|
206
|
+
assert verify_argv([]) == []
|
|
206
207
|
|
|
207
208
|
|
|
208
|
-
def
|
|
209
|
+
def test_verify_runs_voltage_verify_in_process(monkeypatch):
|
|
210
|
+
import types
|
|
211
|
+
|
|
209
212
|
import volt.cli.cmd_misc as misc
|
|
210
213
|
|
|
214
|
+
seen = []
|
|
215
|
+
fake = types.SimpleNamespace(main=lambda argv: seen.append(argv) or 0)
|
|
211
216
|
monkeypatch.setattr(misc.importlib.util, "find_spec", lambda name: object())
|
|
212
|
-
|
|
213
|
-
monkeypatch.setattr(misc.subprocess, "call", lambda argv, **kw: calls.append(argv) or 0)
|
|
217
|
+
monkeypatch.setattr(misc.importlib, "import_module", lambda name: fake if name == "voltage_verify.cli" else None)
|
|
214
218
|
assert run("verify", "bundle.json", "--offline").exit_code == 0
|
|
215
|
-
assert
|
|
219
|
+
assert seen == [["verify", "bundle.json", "--offline"]]
|
|
216
220
|
monkeypatch.setattr(misc.importlib.util, "find_spec", lambda name: None)
|
|
217
221
|
missing = run("verify", "bundle.json")
|
|
218
222
|
assert missing.exit_code == 2 and "pip install voltage-verify" in missing.output
|
|
219
223
|
|
|
220
224
|
|
|
225
|
+
def test_verify_propagates_argparse_exits(monkeypatch):
|
|
226
|
+
import types
|
|
227
|
+
|
|
228
|
+
import volt.cli.cmd_misc as misc
|
|
229
|
+
|
|
230
|
+
def help_then_exit(argv):
|
|
231
|
+
raise SystemExit(0)
|
|
232
|
+
|
|
233
|
+
monkeypatch.setattr(misc.importlib, "import_module", lambda name: types.SimpleNamespace(main=help_then_exit))
|
|
234
|
+
assert misc.run_voltage_verify(["--help"]) == 0
|
|
235
|
+
monkeypatch.setattr(misc.importlib, "import_module", lambda name: types.SimpleNamespace(main=lambda a: (_ for _ in ()).throw(SystemExit(2))))
|
|
236
|
+
assert misc.run_voltage_verify(["bogus"]) == 2
|
|
237
|
+
|
|
238
|
+
|
|
221
239
|
def test_main_turns_api_errors_into_clean_exit_codes(cli_env, capsys):
|
|
222
240
|
cli_env.on("GET", "/api/volt/pods", 401, {"success": False, "error": "Invalid API key"})
|
|
223
241
|
with pytest.raises(SystemExit) as exit_info:
|
|
@@ -240,4 +258,4 @@ def test_main_without_a_key(monkeypatch, tmp_path, capsys):
|
|
|
240
258
|
|
|
241
259
|
def test_version_and_module_entry():
|
|
242
260
|
out = subprocess.run([__import__("sys").executable, "-m", "volt", "--version"], capture_output=True, text=True)
|
|
243
|
-
assert out.returncode == 0 and "1.3.
|
|
261
|
+
assert out.returncode == 0 and "1.3.1" in out.stdout
|
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
import json
|
|
2
|
-
from pathlib import Path
|
|
3
|
-
|
|
4
|
-
import pytest
|
|
5
|
-
from click.testing import CliRunner
|
|
6
|
-
|
|
7
|
-
import volt.cli.cmd_account as account_mod
|
|
8
|
-
from volt.cli.main import cli, main
|
|
9
|
-
|
|
10
|
-
from .conftest import STANDARD_POD, TEST_KEY
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def run(*args, input=None):
|
|
14
|
-
return CliRunner().invoke(cli, list(args), input=input, catch_exceptions=False)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def config_file(tmp_home: Path) -> Path:
|
|
18
|
-
return tmp_home / ".volt" / "config.ini"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def test_login_checks_the_key_then_saves_it(cli_env, tmp_path, monkeypatch):
|
|
22
|
-
monkeypatch.delenv("VOLT_API_KEY")
|
|
23
|
-
result = run("login", "--api-key", TEST_KEY)
|
|
24
|
-
assert result.exit_code == 0, result.output
|
|
25
|
-
assert cli_env.sent("GET", "/api/volt/ssh-keys")[0].headers["X-API-Key"] == TEST_KEY
|
|
26
|
-
assert TEST_KEY in config_file(tmp_path).read_text()
|
|
27
|
-
assert TEST_KEY not in result.output
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def test_login_prompts_hidden_when_interactive(cli_env, tmp_path, monkeypatch):
|
|
31
|
-
monkeypatch.delenv("VOLT_API_KEY")
|
|
32
|
-
monkeypatch.setattr(account_mod, "is_interactive", lambda: True)
|
|
33
|
-
result = run("login", input=TEST_KEY + "\n")
|
|
34
|
-
assert result.exit_code == 0 and config_file(tmp_path).exists()
|
|
35
|
-
assert TEST_KEY not in result.output # hidden input is not echoed
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def test_login_refusals(cli_env, tmp_path, monkeypatch):
|
|
39
|
-
monkeypatch.delenv("VOLT_API_KEY")
|
|
40
|
-
assert run("login").exit_code == 2 # no terminal, no key
|
|
41
|
-
assert run("login", "--api-key", "not-a-key").exit_code == 1
|
|
42
|
-
cli_env.on("GET", "/api/volt/ssh-keys", 401, {"success": False, "error": "Invalid API key"})
|
|
43
|
-
refused = run("login", "--api-key", TEST_KEY)
|
|
44
|
-
assert refused.exit_code == 1 and "refused" in refused.output
|
|
45
|
-
assert not config_file(tmp_path).exists()
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def test_logout(cli_env, tmp_path, monkeypatch):
|
|
49
|
-
monkeypatch.delenv("VOLT_API_KEY")
|
|
50
|
-
run("login", "--api-key", TEST_KEY)
|
|
51
|
-
assert "Removed" in run("logout").output
|
|
52
|
-
assert "No stored key" in run("logout").output
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def test_config_without_key(monkeypatch, tmp_path):
|
|
56
|
-
for name in ("VOLT_API_KEY", "VOLTAGEGPU_API_KEY", "VOLT_BASE_URL"):
|
|
57
|
-
monkeypatch.delenv(name, raising=False)
|
|
58
|
-
monkeypatch.setenv("HOME", str(tmp_path))
|
|
59
|
-
monkeypatch.setenv("USERPROFILE", str(tmp_path))
|
|
60
|
-
result = run("config")
|
|
61
|
-
assert result.exit_code == 1 and "api-keys" in result.output
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
def test_ssh_keys_delete(cli_env):
|
|
65
|
-
cli_env.on("DELETE", "/api/volt/ssh-keys/key_1", body={"success": True})
|
|
66
|
-
assert run("ssh-keys", "delete", "key_1").exit_code == 2
|
|
67
|
-
assert run("ssh-keys", "delete", "key_1", "--yes").exit_code == 0
|
|
68
|
-
assert len(cli_env.sent("DELETE", "/api/volt/ssh-keys/key_1")) == 1
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def test_ssh_keys_add_from_string_and_conflicts(cli_env, tmp_path):
|
|
72
|
-
cli_env.on("POST", "/api/volt/ssh-keys", 201, {"id": "k3", "name": "ci", "publicKey": "ssh-ed25519 AAAA ci"})
|
|
73
|
-
ok = run("ssh-keys", "add", "--name", "ci", "--key", "ssh-ed25519 AAAAC3Nza ci@runner", "--json")
|
|
74
|
-
assert ok.exit_code == 0 and json.loads(ok.output)["id"] == "k3"
|
|
75
|
-
pub = tmp_path / "k.pub"
|
|
76
|
-
pub.write_text("ssh-ed25519 AAAA x")
|
|
77
|
-
assert run("ssh-keys", "add", "--file", str(pub), "--key", "ssh-ed25519 AAAA").exit_code == 2
|
|
78
|
-
assert run("ssh-keys", "add", "--key", "hello world").exit_code == 2
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
def test_ssh_keys_add_without_any_key_file(cli_env, monkeypatch, tmp_path):
|
|
82
|
-
monkeypatch.setattr(account_mod, "default_public_key_file", lambda: None)
|
|
83
|
-
result = run("ssh-keys", "add")
|
|
84
|
-
assert result.exit_code == 2 and "ssh-keygen" in result.output
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
def test_pods_wait(cli_env):
|
|
88
|
-
cli_env.on("GET", "/api/volt/pods", body=[STANDARD_POD])
|
|
89
|
-
result = run("pods", "wait", STANDARD_POD["id"], "--timeout", "10")
|
|
90
|
-
assert result.exit_code == 0 and
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
def test_pods_list_empty(cli_env):
|
|
94
|
-
assert "No running pod" in run("pods", "list").output
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
def test_invalid_id_is_a_usage_error(cli_env, capsys):
|
|
98
|
-
with pytest.raises(SystemExit) as exit_info:
|
|
99
|
-
main(["pods", "stop", "../../admin", "--yes"])
|
|
100
|
-
assert exit_info.value.code == 2
|
|
101
|
-
assert "Invalid id" in capsys.readouterr().err
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
def test_piped_output_survives_characters_outside_the_console_codepage():
|
|
105
|
-
import io
|
|
106
|
-
|
|
107
|
-
from volt.cli.main import configure_stream
|
|
108
|
-
|
|
109
|
-
raw = io.BytesIO()
|
|
110
|
-
stream = io.TextIOWrapper(raw, encoding="cp1252")
|
|
111
|
-
configure_stream(stream) # not a TTY: switches to UTF-8
|
|
112
|
-
stream.write("Ploiești, RO\n")
|
|
113
|
-
stream.flush()
|
|
114
|
-
assert raw.getvalue().decode("utf-8").rstrip("\r\n") == "Ploiești, RO"
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
def test_piped_cli_run_in_a_cp1252_process(tmp_path):
|
|
118
|
-
"""End to end: a real subprocess whose stdout codec is cp1252."""
|
|
119
|
-
import os
|
|
120
|
-
import subprocess
|
|
121
|
-
import sys
|
|
122
|
-
|
|
123
|
-
env = {**os.environ, "PYTHONIOENCODING": "cp1252", "PYTHONUTF8": "0"}
|
|
124
|
-
code = ("import sys; from volt.cli.main import configure_stream; configure_stream(sys.stdout); "
|
|
125
|
-
"print('Ploie\\u0219ti')")
|
|
126
|
-
out = subprocess.run([sys.executable, "-c", code], capture_output=True, env=env)
|
|
127
|
-
assert out.returncode == 0
|
|
128
|
-
assert out.stdout.decode("utf-8").strip() == "Ploiești"
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
def test_network_error_message(cli_env, capsys):
|
|
132
|
-
import httpx
|
|
133
|
-
|
|
134
|
-
def boom(request):
|
|
135
|
-
raise httpx.ConnectError("dns", request=request)
|
|
136
|
-
|
|
137
|
-
cli_env.on("GET", "/api/volt/pods", handler=boom)
|
|
138
|
-
with pytest.raises(SystemExit) as exit_info:
|
|
139
|
-
main(["pods", "list"])
|
|
140
|
-
assert exit_info.value.code == 1
|
|
141
|
-
assert "Could not reach" in capsys.readouterr().err
|
|
1
|
+
import json
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
from click.testing import CliRunner
|
|
6
|
+
|
|
7
|
+
import volt.cli.cmd_account as account_mod
|
|
8
|
+
from volt.cli.main import cli, main
|
|
9
|
+
|
|
10
|
+
from .conftest import STANDARD_POD, TEST_KEY
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def run(*args, input=None):
|
|
14
|
+
return CliRunner().invoke(cli, list(args), input=input, catch_exceptions=False)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def config_file(tmp_home: Path) -> Path:
|
|
18
|
+
return tmp_home / ".volt" / "config.ini"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_login_checks_the_key_then_saves_it(cli_env, tmp_path, monkeypatch):
|
|
22
|
+
monkeypatch.delenv("VOLT_API_KEY")
|
|
23
|
+
result = run("login", "--api-key", TEST_KEY)
|
|
24
|
+
assert result.exit_code == 0, result.output
|
|
25
|
+
assert cli_env.sent("GET", "/api/volt/ssh-keys")[0].headers["X-API-Key"] == TEST_KEY
|
|
26
|
+
assert TEST_KEY in config_file(tmp_path).read_text()
|
|
27
|
+
assert TEST_KEY not in result.output
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_login_prompts_hidden_when_interactive(cli_env, tmp_path, monkeypatch):
|
|
31
|
+
monkeypatch.delenv("VOLT_API_KEY")
|
|
32
|
+
monkeypatch.setattr(account_mod, "is_interactive", lambda: True)
|
|
33
|
+
result = run("login", input=TEST_KEY + "\n")
|
|
34
|
+
assert result.exit_code == 0 and config_file(tmp_path).exists()
|
|
35
|
+
assert TEST_KEY not in result.output # hidden input is not echoed
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_login_refusals(cli_env, tmp_path, monkeypatch):
|
|
39
|
+
monkeypatch.delenv("VOLT_API_KEY")
|
|
40
|
+
assert run("login").exit_code == 2 # no terminal, no key
|
|
41
|
+
assert run("login", "--api-key", "not-a-key").exit_code == 1
|
|
42
|
+
cli_env.on("GET", "/api/volt/ssh-keys", 401, {"success": False, "error": "Invalid API key"})
|
|
43
|
+
refused = run("login", "--api-key", TEST_KEY)
|
|
44
|
+
assert refused.exit_code == 1 and "refused" in refused.output
|
|
45
|
+
assert not config_file(tmp_path).exists()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_logout(cli_env, tmp_path, monkeypatch):
|
|
49
|
+
monkeypatch.delenv("VOLT_API_KEY")
|
|
50
|
+
run("login", "--api-key", TEST_KEY)
|
|
51
|
+
assert "Removed" in run("logout").output
|
|
52
|
+
assert "No stored key" in run("logout").output
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_config_without_key(monkeypatch, tmp_path):
|
|
56
|
+
for name in ("VOLT_API_KEY", "VOLTAGEGPU_API_KEY", "VOLT_BASE_URL"):
|
|
57
|
+
monkeypatch.delenv(name, raising=False)
|
|
58
|
+
monkeypatch.setenv("HOME", str(tmp_path))
|
|
59
|
+
monkeypatch.setenv("USERPROFILE", str(tmp_path))
|
|
60
|
+
result = run("config")
|
|
61
|
+
assert result.exit_code == 1 and "api-keys" in result.output
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_ssh_keys_delete(cli_env):
|
|
65
|
+
cli_env.on("DELETE", "/api/volt/ssh-keys/key_1", body={"success": True})
|
|
66
|
+
assert run("ssh-keys", "delete", "key_1").exit_code == 2
|
|
67
|
+
assert run("ssh-keys", "delete", "key_1", "--yes").exit_code == 0
|
|
68
|
+
assert len(cli_env.sent("DELETE", "/api/volt/ssh-keys/key_1")) == 1
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_ssh_keys_add_from_string_and_conflicts(cli_env, tmp_path):
|
|
72
|
+
cli_env.on("POST", "/api/volt/ssh-keys", 201, {"id": "k3", "name": "ci", "publicKey": "ssh-ed25519 AAAA ci"})
|
|
73
|
+
ok = run("ssh-keys", "add", "--name", "ci", "--key", "ssh-ed25519 AAAAC3Nza ci@runner", "--json")
|
|
74
|
+
assert ok.exit_code == 0 and json.loads(ok.output)["id"] == "k3"
|
|
75
|
+
pub = tmp_path / "k.pub"
|
|
76
|
+
pub.write_text("ssh-ed25519 AAAA x")
|
|
77
|
+
assert run("ssh-keys", "add", "--file", str(pub), "--key", "ssh-ed25519 AAAA").exit_code == 2
|
|
78
|
+
assert run("ssh-keys", "add", "--key", "hello world").exit_code == 2
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_ssh_keys_add_without_any_key_file(cli_env, monkeypatch, tmp_path):
|
|
82
|
+
monkeypatch.setattr(account_mod, "default_public_key_file", lambda: None)
|
|
83
|
+
result = run("ssh-keys", "add")
|
|
84
|
+
assert result.exit_code == 2 and "ssh-keygen" in result.output
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_pods_wait(cli_env):
|
|
88
|
+
cli_env.on("GET", "/api/volt/pods", body=[STANDARD_POD])
|
|
89
|
+
result = run("pods", "wait", STANDARD_POD["id"], "--timeout", "10")
|
|
90
|
+
assert result.exit_code == 0 and "ssh -p 40400 root@147.135.114.178" in result.output
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def test_pods_list_empty(cli_env):
|
|
94
|
+
assert "No running pod" in run("pods", "list").output
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def test_invalid_id_is_a_usage_error(cli_env, capsys):
|
|
98
|
+
with pytest.raises(SystemExit) as exit_info:
|
|
99
|
+
main(["pods", "stop", "../../admin", "--yes"])
|
|
100
|
+
assert exit_info.value.code == 2
|
|
101
|
+
assert "Invalid id" in capsys.readouterr().err
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def test_piped_output_survives_characters_outside_the_console_codepage():
|
|
105
|
+
import io
|
|
106
|
+
|
|
107
|
+
from volt.cli.main import configure_stream
|
|
108
|
+
|
|
109
|
+
raw = io.BytesIO()
|
|
110
|
+
stream = io.TextIOWrapper(raw, encoding="cp1252")
|
|
111
|
+
configure_stream(stream) # not a TTY: switches to UTF-8
|
|
112
|
+
stream.write("Ploiești, RO\n")
|
|
113
|
+
stream.flush()
|
|
114
|
+
assert raw.getvalue().decode("utf-8").rstrip("\r\n") == "Ploiești, RO"
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def test_piped_cli_run_in_a_cp1252_process(tmp_path):
|
|
118
|
+
"""End to end: a real subprocess whose stdout codec is cp1252."""
|
|
119
|
+
import os
|
|
120
|
+
import subprocess
|
|
121
|
+
import sys
|
|
122
|
+
|
|
123
|
+
env = {**os.environ, "PYTHONIOENCODING": "cp1252", "PYTHONUTF8": "0"}
|
|
124
|
+
code = ("import sys; from volt.cli.main import configure_stream; configure_stream(sys.stdout); "
|
|
125
|
+
"print('Ploie\\u0219ti')")
|
|
126
|
+
out = subprocess.run([sys.executable, "-c", code], capture_output=True, env=env)
|
|
127
|
+
assert out.returncode == 0
|
|
128
|
+
assert out.stdout.decode("utf-8").strip() == "Ploiești"
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def test_network_error_message(cli_env, capsys):
|
|
132
|
+
import httpx
|
|
133
|
+
|
|
134
|
+
def boom(request):
|
|
135
|
+
raise httpx.ConnectError("dns", request=request)
|
|
136
|
+
|
|
137
|
+
cli_env.on("GET", "/api/volt/pods", handler=boom)
|
|
138
|
+
with pytest.raises(SystemExit) as exit_info:
|
|
139
|
+
main(["pods", "list"])
|
|
140
|
+
assert exit_info.value.code == 1
|
|
141
|
+
assert "Could not reach" in capsys.readouterr().err
|