trainwave-cli 0.4.1__tar.gz → 0.4.3__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.
Files changed (64) hide show
  1. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/.gitlab-ci.yml +8 -1
  2. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/PKG-INFO +15 -14
  3. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/basic/trainwave.toml +6 -4
  4. trainwave_cli-0.4.3/example/pytorch-llm/requirements.txt +8 -0
  5. trainwave_cli-0.4.3/example/pytorch-llm/run.sh +5 -0
  6. trainwave_cli-0.4.3/example/pytorch-llm/setup.sh +5 -0
  7. trainwave_cli-0.4.3/example/pytorch-llm/train.py +164 -0
  8. trainwave_cli-0.4.3/example/pytorch-llm/trainwave.toml +10 -0
  9. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/pyproject.toml +24 -21
  10. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/ruff.toml +2 -0
  11. trainwave_cli-0.4.3/tests/cli/test_file_secrets.py +102 -0
  12. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/tests/cli/test_jobs.py +156 -1
  13. trainwave_cli-0.4.3/tests/conftest.py +10 -0
  14. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/tests/test_api.py +39 -0
  15. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/trainwave_cli/api.py +82 -10
  16. trainwave_cli-0.4.3/trainwave_cli/cli/file_secrets.py +123 -0
  17. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/trainwave_cli/cli/jobs.py +83 -16
  18. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/trainwave_cli/cli/logs.py +4 -3
  19. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/trainwave_cli/cli/ssh_keys.py +3 -1
  20. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/trainwave_cli/io.py +9 -5
  21. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/trainwave_cli/main.py +13 -5
  22. trainwave_cli-0.4.3/uv.lock +2419 -0
  23. trainwave_cli-0.4.1/tests/conftest.py +0 -21
  24. trainwave_cli-0.4.1/uv.lock +0 -1772
  25. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/.dockerignore +0 -0
  26. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/.gitignore +0 -0
  27. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/Makefile +0 -0
  28. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/README.md +0 -0
  29. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/README.md +0 -0
  30. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/basic/requirements.txt +0 -0
  31. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/basic/run.sh +0 -0
  32. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/basic/setup.sh +0 -0
  33. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/basic/train.py +0 -0
  34. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/disk-exhaustion/requirements.txt +0 -0
  35. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/disk-exhaustion/run.sh +0 -0
  36. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/disk-exhaustion/setup.sh +0 -0
  37. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/disk-exhaustion/train.py +0 -0
  38. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/disk-exhaustion/trainwave.toml +0 -0
  39. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/memory-exhaustion/requirements.txt +0 -0
  40. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/memory-exhaustion/run.sh +0 -0
  41. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/memory-exhaustion/setup.sh +0 -0
  42. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/memory-exhaustion/train.py +0 -0
  43. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/memory-exhaustion/trainwave.toml +0 -0
  44. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/secret-leak/requirements.txt +0 -0
  45. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/secret-leak/run.sh +0 -0
  46. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/secret-leak/setup.sh +0 -0
  47. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/secret-leak/train.py +0 -0
  48. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/example/secret-leak/trainwave.toml +0 -0
  49. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/pyrightconfig.json +0 -0
  50. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/tests/cli/test_auth.py +0 -0
  51. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/tests/cli/test_secrets.py +0 -0
  52. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/tests/cli/test_setup.py +0 -0
  53. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/tests/test_io.py +0 -0
  54. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/tests/test_main.py +0 -0
  55. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/tests/test_utils.py +0 -0
  56. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/trainwave_cli/__init__.py +0 -0
  57. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/trainwave_cli/cli/auth.py +0 -0
  58. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/trainwave_cli/cli/offers.py +0 -0
  59. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/trainwave_cli/cli/secrets.py +0 -0
  60. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/trainwave_cli/cli/setup.py +0 -0
  61. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/trainwave_cli/config/config.py +0 -0
  62. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/trainwave_cli/format_utils.py +0 -0
  63. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/trainwave_cli/utils.py +0 -0
  64. {trainwave_cli-0.4.1 → trainwave_cli-0.4.3}/trainwave_cli/xceptions.py +0 -0
@@ -20,6 +20,13 @@ publish:
20
20
  - curl -LsSf https://astral.sh/uv/install.sh | sh
21
21
  - export PATH="/root/.local/bin:$PATH"
22
22
  - uv build
23
- - uv publish --token $PYPI_API_KEY
23
+ # Only publish when the version in pyproject.toml has been bumped
24
+ - |
25
+ VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' pyproject.toml)
26
+ if curl -fsS "https://pypi.org/pypi/trainwave-cli/$VERSION/json" > /dev/null; then
27
+ echo "trainwave-cli $VERSION is already on PyPI, skipping publish"
28
+ else
29
+ uv publish --token $PYPI_API_KEY
30
+ fi
24
31
  only:
25
32
  - main
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: trainwave-cli
3
- Version: 0.4.1
3
+ Version: 0.4.3
4
4
  Summary: Trainwave CLI - A command-line interface for managing Trainwave resources
5
5
  Project-URL: Homepage, https://trainwave.ai
6
6
  Project-URL: Documentation, https://trainwave.ai/docs
@@ -21,22 +21,23 @@ Classifier: Programming Language :: Python :: 3.12
21
21
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
22
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
23
  Requires-Python: >=3.10
24
- Requires-Dist: aiofiles<25,>=24.1.0
25
- Requires-Dist: aiohttp<4,>=3.10
26
- Requires-Dist: beaupy<4,>=3.9.2
27
- Requires-Dist: boto3>=1.30
24
+ Requires-Dist: aiofiles<26,>=25.1.0
25
+ Requires-Dist: aiohttp<4,>=3.14
26
+ Requires-Dist: beaupy<4,>=3.12.0
27
+ Requires-Dist: boto3>=1.43
28
28
  Requires-Dist: dacite<2,>=1.9.2
29
29
  Requires-Dist: httpx==0.28.1
30
- Requires-Dist: human-readable<2,>=1.3.4
31
- Requires-Dist: loguru<1,>=0.7.2
32
- Requires-Dist: pathspec<1,>=0.12.1
30
+ Requires-Dist: human-readable<3,>=2.0.3
31
+ Requires-Dist: loguru<1,>=0.7.3
32
+ Requires-Dist: pathspec<2,>=1.1.1
33
33
  Requires-Dist: pytimeparse<2,>=1.1.8
34
- Requires-Dist: tabulate<1,>=0.9.0
34
+ Requires-Dist: tabulate<1,>=0.10.0
35
35
  Requires-Dist: toml<1,>=0.10.2
36
- Requires-Dist: tqdm<5,>=4.66.4
37
- Requires-Dist: typer-config[all]<2,>=1.4.0
38
- Requires-Dist: typer<1,>=0.12.5
39
- Requires-Dist: websockets<13,>=12.0
36
+ Requires-Dist: tqdm<5,>=4.69.0
37
+ Requires-Dist: typer-config[all]<2,>=1.5.1
38
+ Requires-Dist: typer<1,>=0.27.0
39
+ Requires-Dist: websockets<17,>=16.1.1; python_version < '3.11'
40
+ Requires-Dist: websockets<18,>=17.1; python_version >= '3.11'
40
41
  Description-Content-Type: text/markdown
41
42
 
42
43
  # Trainwave CLI
@@ -2,13 +2,15 @@ name = "Example - Basic training"
2
2
  expires = "1h"
3
3
  setup_command = "bash setup.sh"
4
4
  run_command = "bash run.sh"
5
- image = "trainwave/pytorch:2.4.0"
5
+ # image = "trainwave/pytorch:2.4.0"
6
6
  framework = "PyTorch"
7
7
  project = "p-kgzxmqte"
8
- compliance_soc2 = true
9
- gpus = 1
10
- gpu_type = "NVIDIA-A40-48GB"
8
+ # compliance_soc2 = true
9
+ # gpus = 1
10
+ # gpu_type = "NVIDIA-A40-48GB"
11
11
  organization = "o-kgzxmqte"
12
+ cpus = 1
13
+ burst_count = 3
12
14
 
13
15
  [env_vars]
14
16
  TESTING1 = "1"
@@ -0,0 +1,8 @@
1
+ # Core stack typical for modern LLM fine-tuning / pretraining experiments
2
+ torch>=2.6.0
3
+ transformers>=4.36.0
4
+ datasets>=2.16.0
5
+ accelerate>=0.26.0
6
+ peft>=0.8.0
7
+ tqdm>=4.66.0
8
+ safetensors>=0.4.0
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+
4
+ echo "Starting causal LM training (tiny GPT-2 + LoRA demo)"
5
+ python train.py
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+
4
+ echo "Installing PyTorch + HF ecosystem for LLM-style training..."
5
+ pip install -r requirements.txt
@@ -0,0 +1,164 @@
1
+ """
2
+ Minimal but realistic LLM-training-shaped demo:
3
+
4
+ - Random-init Hugging Face GPT-2 (tiny config, no weight download)
5
+ - Parameter-efficient fine-tuning via PEFT / LoRA
6
+ - `datasets` for batched sequences
7
+ - `accelerate` for device placement and mixed precision prep
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import json
13
+ import math
14
+ import os
15
+ import random
16
+ from pathlib import Path
17
+
18
+ import torch
19
+ from accelerate import Accelerator
20
+ from accelerate.utils import set_seed
21
+ from datasets import Dataset
22
+ from peft import LoraConfig, TaskType, get_peft_model
23
+ from torch.optim import AdamW
24
+ from torch.utils.data import DataLoader
25
+ from tqdm.auto import tqdm
26
+ from transformers import GPT2Config, GPT2LMHeadModel, get_cosine_schedule_with_warmup
27
+
28
+
29
+ def _synthetic_causal_batch(
30
+ *,
31
+ num_rows: int,
32
+ seq_len: int,
33
+ vocab_size: int,
34
+ seed: int,
35
+ ) -> Dataset:
36
+ """Token ids in [0, vocab_size); looks like LM data without touching the network."""
37
+ rng = random.Random(seed)
38
+ rows: list[list[int]] = []
39
+ for _ in range(num_rows):
40
+ rows.append([rng.randrange(vocab_size) for _ in range(seq_len)])
41
+ return Dataset.from_dict({"input_ids": rows})
42
+
43
+
44
+ def collate_tokens(
45
+ features: list[dict[str, list[int]]],
46
+ ) -> dict[str, torch.Tensor]:
47
+ batch = torch.tensor([f["input_ids"] for f in features], dtype=torch.long)
48
+ return {"input_ids": batch}
49
+
50
+
51
+ def main() -> None:
52
+ out_dir = Path(os.environ.get("TRAINWAVE_OUTPUT_DIR", "/workspace/output"))
53
+ out_dir.mkdir(parents=True, exist_ok=True)
54
+
55
+ # Small GPT-2-shaped LM: fast on CPU, still exercises the HF stack.
56
+ vocab_size = 512
57
+ config = GPT2Config(
58
+ vocab_size=vocab_size,
59
+ n_positions=128,
60
+ n_embd=128,
61
+ n_layer=4,
62
+ n_head=4,
63
+ n_inner=512,
64
+ resid_pdrop=0.0,
65
+ embd_pdrop=0.0,
66
+ attn_pdrop=0.0,
67
+ )
68
+ model = GPT2LMHeadModel(config)
69
+
70
+ peft_config = LoraConfig(
71
+ task_type=TaskType.CAUSAL_LM,
72
+ r=8,
73
+ lora_alpha=16,
74
+ lora_dropout=0.05,
75
+ target_modules=["c_attn", "c_proj"],
76
+ fan_in_fan_out=True, # GPT-2 attention uses Conv1D
77
+ )
78
+ model = get_peft_model(model, peft_config)
79
+
80
+ mp = "fp16" if torch.cuda.is_available() else "no"
81
+ accelerator = Accelerator(mixed_precision=mp)
82
+ set_seed(42)
83
+ device = accelerator.device
84
+
85
+ dataset = _synthetic_causal_batch(
86
+ num_rows=256,
87
+ seq_len=config.n_positions,
88
+ vocab_size=vocab_size,
89
+ seed=42,
90
+ )
91
+ loader = DataLoader(
92
+ dataset,
93
+ batch_size=8,
94
+ shuffle=True,
95
+ collate_fn=collate_tokens,
96
+ num_workers=0,
97
+ )
98
+
99
+ train_steps = 50
100
+ optimizer = AdamW(model.parameters(), lr=3e-4, weight_decay=0.01)
101
+ scheduler = get_cosine_schedule_with_warmup(
102
+ optimizer,
103
+ num_warmup_steps=5,
104
+ num_training_steps=train_steps,
105
+ )
106
+
107
+ model, optimizer, loader, scheduler = accelerator.prepare(
108
+ model, optimizer, loader, scheduler
109
+ )
110
+
111
+ model.train()
112
+ losses: list[float] = []
113
+ pbar = tqdm(range(train_steps), desc="train", disable=not accelerator.is_local_main_process)
114
+ data_iter = iter(loader)
115
+
116
+ for step in pbar:
117
+ try:
118
+ batch = next(data_iter)
119
+ except StopIteration:
120
+ data_iter = iter(loader)
121
+ batch = next(data_iter)
122
+
123
+ batch = {k: v.to(device) for k, v in batch.items()}
124
+ outputs = model(**batch, labels=batch["input_ids"])
125
+ loss = outputs.loss
126
+
127
+ accelerator.backward(loss)
128
+ optimizer.step()
129
+ scheduler.step()
130
+ optimizer.zero_grad()
131
+
132
+ loss_val = float(accelerator.reduce(loss.detach(), reduction="mean"))
133
+ losses.append(loss_val)
134
+ pbar.set_postfix(loss=f"{loss_val:.4f}")
135
+
136
+ summary = {
137
+ "device": str(device),
138
+ "dtype_policy": str(accelerator.mixed_precision),
139
+ "trainable_params": sum(p.numel() for p in model.parameters() if p.requires_grad),
140
+ "total_params": sum(p.numel() for p in model.parameters()),
141
+ "final_loss": losses[-1] if losses else None,
142
+ "mean_loss_last_10": sum(losses[-10:]) / min(10, len(losses)) if losses else None,
143
+ }
144
+
145
+ if accelerator.is_main_process:
146
+ # `safetensors` is expected by many HF workflows; save adapter weights only.
147
+ adapter_dir = out_dir / "lora_adapter"
148
+ model.save_pretrained(adapter_dir)
149
+
150
+ with (out_dir / "metrics.json").open("w", encoding="utf-8") as f:
151
+ json.dump(summary, f, indent=2)
152
+
153
+ print(
154
+ "Done. "
155
+ f"Trainable / total params: {summary['trainable_params']:,} / "
156
+ f"{summary['total_params']:,}. "
157
+ f"Final loss ≈ {summary['final_loss']:.4f} "
158
+ f"(random data; expect high but finite CE ≈ ln({vocab_size}) ≈ "
159
+ f"{math.log(vocab_size):.2f})."
160
+ )
161
+
162
+
163
+ if __name__ == "__main__":
164
+ main()
@@ -0,0 +1,10 @@
1
+ name = "PyTorch LLM stack demo"
2
+ expires = "2h"
3
+ setup_command = "bash setup.sh"
4
+ run_command = "bash run.sh"
5
+ cuda_version = "12.4"
6
+ project = "p-kgzxmqte"
7
+ gpus = 1
8
+ gpu_type = "NVIDIA-A40-48GB"
9
+ compliance_soc2 = true
10
+ organization = "o-kgzxmqte"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "trainwave-cli"
3
- version = "0.4.1"
3
+ version = "0.4.3"
4
4
  description = "Trainwave CLI - A command-line interface for managing Trainwave resources"
5
5
  authors = [{ name = "Johan Backman", email = "johan@trainwave.ai" }]
6
6
  maintainers = [{ name = "Johan Backman", email = "johan@trainwave.ai" }]
@@ -23,22 +23,24 @@ classifiers = [
23
23
  "Topic :: Software Development :: Libraries :: Python Modules",
24
24
  ]
25
25
  dependencies = [
26
- "aiofiles>=24.1.0,<25",
27
- "aiohttp>=3.10,<4",
28
- "beaupy>=3.9.2,<4",
29
- "boto3>=1.30",
26
+ "aiofiles>=25.1.0,<26",
27
+ "aiohttp>=3.14,<4",
28
+ "beaupy>=3.12.0,<4",
29
+ "boto3>=1.43",
30
30
  "dacite>=1.9.2,<2",
31
31
  "httpx==0.28.1",
32
- "human-readable>=1.3.4,<2",
33
- "loguru>=0.7.2,<1",
34
- "pathspec>=0.12.1,<1",
32
+ "human-readable>=2.0.3,<3",
33
+ "loguru>=0.7.3,<1",
34
+ "pathspec>=1.1.1,<2",
35
35
  "pytimeparse>=1.1.8,<2",
36
- "tabulate>=0.9.0,<1",
36
+ "tabulate>=0.10.0,<1",
37
37
  "toml>=0.10.2,<1",
38
- "tqdm>=4.66.4,<5",
39
- "typer>=0.12.5,<1",
40
- "typer-config[all]>=1.4.0,<2",
41
- "websockets>=12.0,<13",
38
+ "tqdm>=4.69.0,<5",
39
+ "typer>=0.27.0,<1",
40
+ "typer-config[all]>=1.5.1,<2",
41
+ # websockets 17 dropped Python 3.10; keep 3.10 on the last compatible release.
42
+ "websockets>=17.1,<18; python_version >= '3.11'",
43
+ "websockets>=16.1.1,<17; python_version < '3.11'",
42
44
  ]
43
45
 
44
46
  [project.urls]
@@ -50,15 +52,16 @@ wave = "trainwave_cli.main:entrypoint"
50
52
 
51
53
  [dependency-groups]
52
54
  dev = [
53
- "freezegun>=1.5.1,<2",
55
+ "freezegun>=1.5.5,<2",
54
56
  "ipdb>=0.13.13,<1",
55
- "ipython>=8.34.0,<9",
56
- "pytest>=8.3.5,<9",
57
- "pytest-asyncio>=0.25.3,<1",
58
- "pytest-cov>=6.0.0,<7",
59
- "pytest-httpx>=0.35.0,<1",
60
- "pytest-mock>=3.14.0,<4",
61
- "ruff>=0.11.7",
57
+ # ipython 9.x requires Python >=3.11; uncapped so 3.10 resolves to 8.x.
58
+ "ipython>=8.34.0",
59
+ "pytest>=9.1.1,<10",
60
+ "pytest-asyncio>=1.4.0,<2",
61
+ "pytest-cov>=7.1.0,<8",
62
+ "pytest-httpx>=0.36.2,<1",
63
+ "pytest-mock>=3.15.1,<4",
64
+ "ruff>=0.16.10",
62
65
  ]
63
66
 
64
67
  [build-system]
@@ -66,6 +66,8 @@ lint.ignore = [
66
66
  # Let black handle line length checking
67
67
  "E501",
68
68
  "PERF203",
69
+ # Became stable in ruff 0.16; Typer commands/API helpers legitimately take many parameters
70
+ "PLR0917",
69
71
  ]
70
72
  # Allow fix for all enabled rules (when `--fix`) is provided.
71
73
  lint.fixable = ["ALL"]
@@ -0,0 +1,102 @@
1
+ import asyncio
2
+ from datetime import datetime, timezone
3
+ from pathlib import Path
4
+ from unittest.mock import AsyncMock, patch
5
+
6
+ import pytest
7
+ from typer.testing import CliRunner
8
+
9
+ from trainwave_cli.api import InstanceFileSecret
10
+ from trainwave_cli.cli.file_secrets import app
11
+ from trainwave_cli.config.config import config
12
+
13
+ runner = CliRunner()
14
+
15
+
16
+ @pytest.fixture(autouse=True)
17
+ def setup_config():
18
+ config.api_key = "test-key"
19
+ config.endpoint = "https://api.test.com"
20
+
21
+
22
+ @pytest.fixture
23
+ def file_secret() -> InstanceFileSecret:
24
+ return InstanceFileSecret(
25
+ id="secret-id",
26
+ rid="fs-secret",
27
+ instance="instance-id",
28
+ name="nats credentials",
29
+ relative_path="dynamo/nats.creds",
30
+ digest="abcdef1234567890",
31
+ mode=0o600,
32
+ created_at=datetime.now(timezone.utc),
33
+ )
34
+
35
+
36
+ @pytest.mark.asyncio
37
+ async def test_list_file_secrets(file_secret: InstanceFileSecret) -> None:
38
+ api = AsyncMock()
39
+ api.list_instance_file_secrets.return_value = [file_secret]
40
+
41
+ with patch("trainwave_cli.cli.file_secrets.Api", return_value=api):
42
+ result = await asyncio.to_thread(
43
+ runner.invoke, app, ["list", "--job", "job-id"]
44
+ )
45
+
46
+ assert result.exit_code == 0
47
+ assert "nats credentials" in result.stdout
48
+ assert "dynamo/nats.creds" in result.stdout
49
+ assert "abcdef1234567890" in result.stdout
50
+ api.list_instance_file_secrets.assert_called_once_with("job-id")
51
+
52
+
53
+ @pytest.mark.asyncio
54
+ async def test_set_file_secret_reads_file_without_printing_value(
55
+ tmp_path: Path, file_secret: InstanceFileSecret
56
+ ) -> None:
57
+ source = tmp_path / "nats.creds"
58
+ source.write_text("private credential material")
59
+ api = AsyncMock()
60
+ api.set_instance_file_secret.return_value = file_secret
61
+
62
+ with patch("trainwave_cli.cli.file_secrets.Api", return_value=api):
63
+ result = await asyncio.to_thread(
64
+ runner.invoke,
65
+ app,
66
+ [
67
+ "set",
68
+ "--job",
69
+ "job-id",
70
+ "--instance",
71
+ "instance-id",
72
+ "--name",
73
+ "nats credentials",
74
+ "--relative-path",
75
+ "dynamo/nats.creds",
76
+ "--file",
77
+ str(source),
78
+ ],
79
+ )
80
+
81
+ assert result.exit_code == 0
82
+ assert "private credential material" not in result.stdout
83
+ api.set_instance_file_secret.assert_called_once_with(
84
+ "job-id",
85
+ "instance-id",
86
+ "nats credentials",
87
+ "dynamo/nats.creds",
88
+ "private credential material",
89
+ None,
90
+ )
91
+
92
+
93
+ @pytest.mark.asyncio
94
+ async def test_revoke_file_secret() -> None:
95
+ api = AsyncMock()
96
+ with patch("trainwave_cli.cli.file_secrets.Api", return_value=api):
97
+ result = await asyncio.to_thread(
98
+ runner.invoke, app, ["revoke", "fs-secret", "--job", "job-id"]
99
+ )
100
+
101
+ assert result.exit_code == 0
102
+ api.revoke_instance_file_secret.assert_called_once_with("job-id", "fs-secret")
@@ -3,10 +3,11 @@ from datetime import datetime, timezone
3
3
  from unittest.mock import AsyncMock, patch
4
4
 
5
5
  import pytest
6
+ import typer
6
7
  from typer.testing import CliRunner
7
8
 
8
9
  from trainwave_cli.api import CloudOffer, Job, JobConfig, JobStatus, TrainwaveProject
9
- from trainwave_cli.cli.jobs import app
10
+ from trainwave_cli.cli.jobs import _parse_env_vars, app
10
11
  from trainwave_cli.config.config import config
11
12
 
12
13
  runner = CliRunner()
@@ -194,3 +195,157 @@ async def test_launch_job_with_gpu(mock_job, tmp_path):
194
195
  call_args = mock_api.create_job.call_args[0][0]
195
196
  assert call_args["gpu_type"] == "A100"
196
197
  assert call_args["gpus"] == _expected_gpu_count
198
+
199
+
200
+ @pytest.mark.asyncio
201
+ async def test_launch_job_with_burst_count(mock_job, tmp_path):
202
+ _expected_burst_count = 3
203
+ config.api_key = "test-key"
204
+
205
+ mock_api = AsyncMock()
206
+ mock_api.create_job.return_value = mock_job
207
+
208
+ workspace = tmp_path / "workspace"
209
+ workspace.mkdir()
210
+ (workspace / "test.py").write_text("print('hello')")
211
+
212
+ with (
213
+ patch("trainwave_cli.cli.jobs.Api", return_value=mock_api),
214
+ patch("trainwave_cli.cli.jobs.Path.cwd", return_value=workspace),
215
+ ):
216
+ result = await asyncio.to_thread(
217
+ runner.invoke,
218
+ app,
219
+ [
220
+ "launch",
221
+ "--name",
222
+ "test-job",
223
+ "--project",
224
+ "test-project",
225
+ "--setup-command",
226
+ "pip install -r requirements.txt",
227
+ "--run-command",
228
+ "python test.py",
229
+ "--burst-count",
230
+ str(_expected_burst_count),
231
+ ],
232
+ )
233
+
234
+ assert result.exit_code == 0
235
+ call_args = mock_api.create_job.call_args[0][0]
236
+ assert call_args["burst_count"] == _expected_burst_count
237
+
238
+
239
+ @pytest.mark.asyncio
240
+ async def test_launch_job_omits_burst_count_by_default(mock_job, tmp_path):
241
+ config.api_key = "test-key"
242
+
243
+ mock_api = AsyncMock()
244
+ mock_api.create_job.return_value = mock_job
245
+
246
+ workspace = tmp_path / "workspace"
247
+ workspace.mkdir()
248
+ (workspace / "test.py").write_text("print('hello')")
249
+
250
+ with (
251
+ patch("trainwave_cli.cli.jobs.Api", return_value=mock_api),
252
+ patch("trainwave_cli.cli.jobs.Path.cwd", return_value=workspace),
253
+ ):
254
+ result = await asyncio.to_thread(
255
+ runner.invoke,
256
+ app,
257
+ [
258
+ "launch",
259
+ "--name",
260
+ "test-job",
261
+ "--project",
262
+ "test-project",
263
+ "--setup-command",
264
+ "pip install -r requirements.txt",
265
+ "--run-command",
266
+ "python test.py",
267
+ ],
268
+ )
269
+
270
+ assert result.exit_code == 0
271
+ call_args = mock_api.create_job.call_args[0][0]
272
+ assert "burst_count" not in call_args
273
+
274
+
275
+ async def _launch_from_toml(mock_job, tmp_path, toml_body: str):
276
+ """
277
+ Run `wave jobs launch --config <file>` the way the integration tests do.
278
+
279
+ Every option comes from the TOML file.
280
+ """
281
+ config.api_key = "test-key"
282
+ mock_api = AsyncMock()
283
+ mock_api.create_job.return_value = mock_job
284
+
285
+ workspace = tmp_path / "workspace"
286
+ workspace.mkdir()
287
+ (workspace / "train.py").write_text("print('hello')")
288
+ job_toml = tmp_path / "job.toml"
289
+ job_toml.write_text(
290
+ 'name = "test-job"\n'
291
+ 'project = "test-project"\n'
292
+ 'setup_command = "true"\n'
293
+ 'run_command = "python train.py"\n'
294
+ 'expires = "10m"\n'
295
+ "cpus = 1\n" + toml_body
296
+ )
297
+
298
+ with (
299
+ patch("trainwave_cli.cli.jobs.Api", return_value=mock_api),
300
+ patch("trainwave_cli.cli.jobs.Path.cwd", return_value=workspace),
301
+ ):
302
+ result = await asyncio.to_thread(
303
+ runner.invoke, app, ["launch", "--config", str(job_toml)]
304
+ )
305
+ return result, mock_api
306
+
307
+
308
+ @pytest.mark.asyncio
309
+ async def test_launch_from_toml_without_env_vars(mock_job, tmp_path):
310
+ # Used to crash with "eval() arg 1 must be a string, bytes or code object".
311
+ result, mock_api = await _launch_from_toml(mock_job, tmp_path, "")
312
+
313
+ assert result.exit_code == 0, result.output
314
+ assert mock_api.create_job.call_args[0][0]["env_vars"] == {}
315
+
316
+
317
+ @pytest.mark.asyncio
318
+ async def test_launch_from_toml_env_vars_table(mock_job, tmp_path, monkeypatch):
319
+ monkeypatch.setenv("TW_TEST_TOKEN", "from-env")
320
+ result, mock_api = await _launch_from_toml(
321
+ mock_job,
322
+ tmp_path,
323
+ '[env_vars]\nSEED = "42"\nTOKEN = "${TW_TEST_TOKEN}"\n',
324
+ )
325
+
326
+ assert result.exit_code == 0, result.output
327
+ assert mock_api.create_job.call_args[0][0]["env_vars"] == {
328
+ "SEED": "42",
329
+ "TOKEN": "from-env",
330
+ }
331
+
332
+
333
+ @pytest.mark.parametrize(
334
+ ("raw", "expected"),
335
+ [
336
+ (None, {}),
337
+ ({}, {}),
338
+ ("", {}),
339
+ ("{}", {}),
340
+ ('{"SEED": "42"}', {"SEED": "42"}),
341
+ ({"SEED": 42}, {"SEED": "42"}),
342
+ ],
343
+ )
344
+ def test_parse_env_vars(raw, expected):
345
+ assert _parse_env_vars(raw) == expected
346
+
347
+
348
+ @pytest.mark.parametrize("raw", ["__import__('os').getcwd()", "[1, 2]", "not python"])
349
+ def test_parse_env_vars_rejects_non_mappings_and_code(raw):
350
+ with pytest.raises((ValueError, SyntaxError, typer.BadParameter)):
351
+ _parse_env_vars(raw)
@@ -0,0 +1,10 @@
1
+ import pytest
2
+ from typer.testing import CliRunner
3
+
4
+
5
+ @pytest.fixture
6
+ def runner():
7
+ """Create a CLI runner that captures output."""
8
+ return CliRunner(
9
+ env={"FORCE_COLOR": "0", "PYTHONUNBUFFERED": "1"},
10
+ )