verulla-cli 0.0.2__tar.gz → 0.0.4__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 (28) hide show
  1. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/PKG-INFO +1 -1
  2. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/pyproject.toml +1 -1
  3. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/tests/test_apps_client.py +36 -1
  4. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/tests/test_buildkit.py +23 -16
  5. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/tests/test_buildkit_real.py +1 -0
  6. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/tests/test_dev_check.py +121 -4
  7. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/tests/test_main.py +172 -6
  8. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/verulla_cli/__init__.py +1 -1
  9. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/verulla_cli/apps_client.py +41 -0
  10. verulla_cli-0.0.4/verulla_cli/buildkit.py +208 -0
  11. verulla_cli-0.0.4/verulla_cli/config.py +3 -0
  12. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/verulla_cli/main.py +197 -39
  13. verulla_cli-0.0.2/verulla_cli/buildkit.py +0 -107
  14. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/.gitignore +0 -0
  15. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/tests/test_admin_cmd.py +0 -0
  16. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/tests/test_auth.py +0 -0
  17. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/tests/test_cli_import.py +0 -0
  18. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/tests/test_deploy_client.py +0 -0
  19. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/tests/test_emulate.py +0 -0
  20. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/tests/test_owner_commands.py +0 -0
  21. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/tests/test_packaging.py +0 -0
  22. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/tests/test_secrets_client.py +0 -0
  23. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/tests/test_sketch_status.py +0 -0
  24. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/verulla_cli/auth.py +0 -0
  25. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/verulla_cli/deploy_client.py +0 -0
  26. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/verulla_cli/emulate.py +0 -0
  27. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/verulla_cli/packaging.py +0 -0
  28. {verulla_cli-0.0.2 → verulla_cli-0.0.4}/verulla_cli/secrets_client.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: verulla-cli
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Requires-Python: >=3.12
5
5
  Requires-Dist: docker>=7
6
6
  Requires-Dist: httpx>=0.27
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "verulla-cli"
3
- version = "0.0.2"
3
+ version = "0.0.4"
4
4
  requires-python = ">=3.12"
5
5
  dependencies = [
6
6
  "verulla-manifest==0.0.2",
@@ -1,10 +1,11 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import hashlib
3
4
  import httpx
4
5
  import pytest
5
6
 
6
7
  from verulla_cli.apps_client import (
7
- AppsError, activate_app, delete_app, delete_customer, export_customers, get_app_logs, get_auth_policy,
8
+ AppsError, activate_app, create_signup, delete_app, delete_customer, export_customers, get_app_logs, get_auth_policy,
8
9
  get_spend_summary, invite_customer, list_apps, list_customers, lock_customer,
9
10
  get_sketch_events, rollback_app, set_auth_policy, unlock_customer,
10
11
  )
@@ -25,6 +26,30 @@ def response(status, body):
25
26
  return httpx.Response(status, json=body, request=req)
26
27
 
27
28
 
29
+ def test_create_signup_solves_pow_and_sends_idempotency_header():
30
+ class Client:
31
+ calls = []
32
+
33
+ def get(self, url):
34
+ self.calls.append(("GET", url, None, None))
35
+ return response(200, {"prefix": "challenge-prefix", "difficulty": 2, "challenge_id": "c-1"})
36
+
37
+ def post(self, url, *, headers, json):
38
+ self.calls.append(("POST", url, headers, json))
39
+ return response(201, {"tenant": {"slug": "demo"}})
40
+
41
+ client = Client()
42
+ result = create_signup("http://api.test", "demo", "Demo", "owner@example.test", "idempotency-key-123456", client)
43
+ assert result == {"tenant": {"slug": "demo"}}
44
+ assert client.calls[0][:2] == ("GET", "http://api.test/v1/signup/challenge")
45
+ method, url, headers, body = client.calls[1]
46
+ assert (method, url) == ("POST", "http://api.test/v1/signup")
47
+ assert headers == {"Idempotency-Key": "idempotency-key-123456"}
48
+ assert hashlib.sha256(f"challenge-prefix{body['nonce']}".encode()).hexdigest().startswith("00")
49
+ assert body == {"slug": "demo", "display_name": "Demo", "owner_email": "owner@example.test",
50
+ "challenge_id": "c-1", "nonce": body["nonce"]}
51
+
52
+
28
53
  def test_list_apps_uses_authenticated_apps_endpoint():
29
54
  client = FakeClient(response(200, {"apps": [{"app": "demo"}]}))
30
55
  assert list_apps("http://api.test", "token", client) == [{"app": "demo"}]
@@ -32,6 +57,16 @@ def test_list_apps_uses_authenticated_apps_endpoint():
32
57
 
33
58
 
34
59
 
60
+ def test_get_deployment_uses_id_scoped_endpoint():
61
+ from verulla_cli.apps_client import get_deployment
62
+
63
+ client = FakeClient(response(200, {"id": "dep-1", "status": "building"}))
64
+ assert get_deployment("http://api.test", "token", "dep-1", client)["status"] == "building"
65
+ assert client.calls[0][:3] == (
66
+ "GET", "http://api.test/v1/deployments/dep-1", {"Authorization": "Bearer token"}
67
+ )
68
+
69
+
35
70
  def test_sketch_events_passes_cursor_and_limit_without_changing_contract():
36
71
  body = {
37
72
  "events": [{
@@ -25,12 +25,15 @@ def test_auto_error_names_both_backends(monkeypatch):
25
25
  select_builder("auto", docker_available=False)
26
26
 
27
27
 
28
- def test_buildkit_timeout_is_bounded_and_does_not_leak_process_details(tmp_path, monkeypatch):
28
+ def test_buildkit_timeout_reports_safe_progress_without_leaking_output(tmp_path, monkeypatch):
29
29
  import subprocess
30
+ import traceback
30
31
 
31
32
  import verulla_cli.buildkit as buildkit
32
33
 
33
- monkeypatch.setenv("BUILDKIT_HOST", "tcp://private-builder:1234")
34
+ secret_marker = "SYNTHETIC_SECRET_MARKER_42"
35
+ builder_address = "tcp://private-builder:1234"
36
+ monkeypatch.setenv("BUILDKIT_HOST", builder_address)
34
37
  monkeypatch.setattr(buildkit.shutil, "which", lambda _: "/usr/bin/buildctl")
35
38
 
36
39
  def hang(*args, **kwargs):
@@ -38,28 +41,32 @@ def test_buildkit_timeout_is_bounded_and_does_not_leak_process_details(tmp_path,
38
41
  raise subprocess.TimeoutExpired(
39
42
  cmd=args[0],
40
43
  timeout=kwargs["timeout"],
41
- output="private build output",
42
- stderr="secret environment value",
44
+ output=(
45
+ f"#3 [stage-0 2/3] RUN echo {secret_marker}\n"
46
+ "#3 RUN echo private build output\n"
47
+ "#4 [stage-0 3/3] RUN npm ci\n"
48
+ ),
49
+ stderr=f"secret environment value {secret_marker}",
43
50
  )
44
51
 
45
52
  monkeypatch.setattr(buildkit.subprocess, "run", hang)
46
53
 
47
54
  with pytest.raises(EmulationError) as error:
48
- BuildKitRunner().build(tmp_path, "Dockerfile")
49
-
50
- assert str(error.value) == "BuildKit build timed out after 600 seconds"
51
- assert "private build output" not in str(error.value)
52
- assert "secret environment value" not in str(error.value)
53
- assert "private-builder" not in str(error.value)
54
-
55
- import traceback
56
-
55
+ BuildKitRunner().build(tmp_path, "Dockerfile", check=True)
56
+
57
+ message = str(error.value)
58
+ assert "BuildKit build timed out after 600 seconds" in message
59
+ assert "vertex #4 RUN instruction [running]" in message
60
+ assert secret_marker not in message
61
+ assert "private build output" not in message
62
+ assert "secret environment value" not in message
63
+ assert builder_address not in message
57
64
  formatted_traceback = "".join(traceback.format_exception(error.value))
58
- assert error.value.__suppress_context__
65
+ assert secret_marker not in formatted_traceback
59
66
  assert "private build output" not in formatted_traceback
60
67
  assert "secret environment value" not in formatted_traceback
61
- assert "private-builder" not in formatted_traceback
62
- assert "TimeoutExpired" not in formatted_traceback
68
+ assert builder_address not in formatted_traceback
69
+ assert error.value.__suppress_context__
63
70
 
64
71
 
65
72
  def test_buildkit_uses_shared_dockerfile_and_fake_buildctl(tmp_path, monkeypatch):
@@ -91,5 +91,6 @@ def _build_and_assert_route(build: FunctionBuild, routes: list[RouteSpec], root:
91
91
  check_name = check_dockerfile(build, routes)
92
92
  print(f"BuildKit real smoke: {build.adapter_name} build and route probes starting", flush=True)
93
93
  output = BuildKitRunner().build(root, check_name, check=True)
94
+ print(output, flush=True)
94
95
  print(f"BuildKit real smoke: {build.adapter_name} build completed", flush=True)
95
96
  assert expected in output, output
@@ -113,7 +113,121 @@ def test_buildkit_check_probe_isolated_from_host_listener(tmp_path):
113
113
  assert "127.0.0.1:8080" in content
114
114
 
115
115
 
116
- def test_buildkit_probe_installs_wget_as_root_then_drops_back_to_app_user(tmp_path):
116
+ def test_buildkit_check_stops_app_process_group_on_exit(tmp_path):
117
+ import os
118
+ import shutil
119
+ import subprocess
120
+ from types import SimpleNamespace
121
+
122
+ from verulla_cli.buildkit import check_dockerfile
123
+
124
+ (tmp_path / "Dockerfile").write_text("FROM custom:latest\n")
125
+ child_file = tmp_path / "child.pid"
126
+ function = SimpleNamespace(
127
+ build_plan=SimpleNamespace(
128
+ dockerfile_path="Dockerfile",
129
+ run_cmd=["sh", "-c", f"sleep 300 & echo $! > {child_file}; wait"],
130
+ port=8080,
131
+ base_image="custom:latest",
132
+ ),
133
+ src_root=tmp_path,
134
+ name="web",
135
+ )
136
+ generated = tmp_path / check_dockerfile(
137
+ function, [SimpleNamespace(path="/", function="web")]
138
+ )
139
+ run_line = next(
140
+ line for line in generated.read_text().splitlines() if line.startswith("RUN --network=none ")
141
+ )
142
+ script = json.loads(run_line.removeprefix("RUN --network=none "))[2]
143
+
144
+ setsid = shutil.which("setsid")
145
+ assert setsid, "setsid is required for the process-group regression test"
146
+ shells = [shutil.which("dash")]
147
+ busybox = shutil.which("busybox")
148
+ if busybox:
149
+ shells.append(f"{busybox} sh")
150
+ bin_dir = tmp_path / "bin"
151
+ bin_dir.mkdir()
152
+ wget = bin_dir / "wget"
153
+ wget.write_text("#!/bin/sh\nif [ \"$1\" = -q ]; then exit 0; fi\necho 'HTTP/1.1 500 Failed' >&2\nexit 0\n")
154
+ wget.chmod(0o755)
155
+
156
+ for shell in filter(None, shells):
157
+ shell_cmd = shell.split()
158
+ child_file.unlink(missing_ok=True)
159
+ result = subprocess.run(
160
+ [setsid, *shell_cmd, "-c", script], cwd=tmp_path,
161
+ env={**os.environ, "PATH": f"{bin_dir}:{os.environ['PATH']}"},
162
+ text=True, capture_output=True, timeout=10
163
+ )
164
+ assert child_file.exists(), result.stderr
165
+ child_pid = int(child_file.read_text())
166
+ assert result.returncode == 1, result.stderr
167
+ try:
168
+ os.kill(child_pid, 0)
169
+ except ProcessLookupError:
170
+ pass
171
+ else:
172
+ raise AssertionError(f"app child {child_pid} survived generated check script")
173
+
174
+
175
+ def test_buildkit_check_custom_base_does_not_require_setsid(tmp_path):
176
+ from types import SimpleNamespace
177
+
178
+ from verulla_cli.buildkit import check_dockerfile
179
+
180
+ (tmp_path / "Dockerfile").write_text("FROM golang:1.24\n")
181
+ function = SimpleNamespace(
182
+ build_plan=SimpleNamespace(
183
+ dockerfile_path="Dockerfile", run_cmd=["./server"], port=8080, base_image="golang:1.24"
184
+ ),
185
+ src_root=tmp_path,
186
+ name="web",
187
+ )
188
+
189
+ generated = tmp_path / check_dockerfile(function, [SimpleNamespace(path="/", function="web")])
190
+ content = generated.read_text()
191
+ run_line = next(line for line in content.splitlines() if line.startswith("RUN --network=none "))
192
+ script = json.loads(run_line.removeprefix("RUN --network=none "))[2]
193
+
194
+ assert "setsid sh -c" in script
195
+ assert "command -v setsid" in script
196
+ assert "app_group=1" in script
197
+ assert "app_group=0" in script
198
+ assert "app_pid=$!" in script
199
+ assert "kill -TERM \"$app_pid\"" in script
200
+ assert "probe_setup" not in content
201
+
202
+
203
+ def test_buildkit_node_probe_uses_builtin_http_client_without_package_install(tmp_path):
204
+ from types import SimpleNamespace
205
+
206
+ from verulla_cli.buildkit import check_dockerfile
207
+
208
+ (tmp_path / "Dockerfile").write_text("FROM node:20-slim\nUSER 10001:10001\n")
209
+ function = SimpleNamespace(
210
+ build_plan=SimpleNamespace(
211
+ dockerfile_path="Dockerfile", run_cmd=["node", "index.js"],
212
+ port=8080, base_image="node:20-slim",
213
+ ),
214
+ src_root=tmp_path,
215
+ name="web",
216
+ )
217
+ generated = tmp_path / check_dockerfile(
218
+ function, [SimpleNamespace(path="/", function="web")]
219
+ )
220
+ content = generated.read_text()
221
+
222
+ assert "apt-get update" not in content
223
+ assert "apk add" not in content
224
+ run_line = next(line for line in content.splitlines() if line.startswith("RUN --network=none "))
225
+ script = json.loads(run_line.removeprefix("RUN --network=none "))[2]
226
+ assert "node -e" in script
227
+ assert "wget" not in script
228
+
229
+
230
+ def test_buildkit_python_probe_uses_stdlib_without_package_install(tmp_path):
117
231
  from types import SimpleNamespace
118
232
 
119
233
  from verulla_cli.buildkit import check_dockerfile
@@ -134,6 +248,9 @@ def test_buildkit_probe_installs_wget_as_root_then_drops_back_to_app_user(tmp_pa
134
248
  )
135
249
  content = generated.read_text()
136
250
 
137
- assert content.index("USER root") < content.index("apt-get update")
138
- assert content.index("apt-get update") < content.rindex("USER 10001:10001")
139
- assert content.rindex("USER 10001:10001") < content.index("RUN --network=none")
251
+ assert "apt-get update" not in content
252
+ assert "apk add" not in content
253
+ run_line = next(line for line in content.splitlines() if line.startswith("RUN --network=none "))
254
+ script = json.loads(run_line.removeprefix("RUN --network=none "))[2]
255
+ assert "python -c" in script
256
+ assert "wget" not in script
@@ -14,6 +14,7 @@ def test_auth_and_customer_commands_are_registered() -> None:
14
14
  result = runner.invoke(app, ["--help"])
15
15
  assert result.exit_code == 0
16
16
  assert "auth" in result.output and "customers" in result.output
17
+ assert "signup" in result.output
17
18
  for command in ("wallet", "spend", "usage", "pricing", "topup"):
18
19
  assert command in result.output
19
20
  for command in ("show", "set"):
@@ -22,6 +23,81 @@ def test_auth_and_customer_commands_are_registered() -> None:
22
23
  assert command in runner.invoke(app, ["customers", "--help"]).output
23
24
 
24
25
 
26
+ def test_signup_stores_key_privately_and_redacts_output(tmp_path, monkeypatch) -> None:
27
+ import stat
28
+
29
+ path = tmp_path / ".verulla" / "credentials.json"
30
+ monkeypatch.setattr("verulla_cli.main.CREDENTIALS_PATH", path)
31
+ pending = tmp_path / ".verulla" / "signup-pending.json"
32
+ monkeypatch.setattr("verulla_cli.main._SIGNUP_PENDING_PATH", pending)
33
+ monkeypatch.setattr("verulla_cli.main.create_signup", lambda *args: {
34
+ "tenant": {"slug": "safe-demo", "display_name": "Demo", "schema_name": "tenant_safe_demo"},
35
+ "api_key": {"token": "vrl_secret-key", "scopes": ["tenant:read"]},
36
+ "owner_claim": {"claim_url": "https://account.verulla.com/claim#claim-secret", "expires_at": "expires"},
37
+ })
38
+ result = runner.invoke(app, ["signup", "--api-url", "https://api.example", "--owner-email", "owner@example.test",
39
+ "--display-name", "Demo", "--slug", "safe-demo"])
40
+ assert result.exit_code == 0, result.output
41
+ assert path.exists() and stat.S_IMODE(path.stat().st_mode) == 0o600
42
+ assert "vrl_secret-key" not in result.output
43
+ assert "owner@example.test" not in result.output
44
+ assert "0123456789abcdef" * 4 not in result.output
45
+ assert "claim-secret" in result.output
46
+ assert not pending.exists()
47
+
48
+
49
+ def test_signup_recovers_interrupted_request_with_same_idempotency_key(tmp_path, monkeypatch) -> None:
50
+ import stat
51
+ from verulla_cli.apps_client import AppsError
52
+
53
+ credentials = tmp_path / ".verulla" / "credentials.json"
54
+ pending = tmp_path / ".verulla" / "signup-pending.json"
55
+ monkeypatch.setattr("verulla_cli.main.CREDENTIALS_PATH", credentials)
56
+ monkeypatch.setattr("verulla_cli.main._SIGNUP_PENDING_PATH", pending)
57
+ attempts = []
58
+
59
+ def fake_signup(*args):
60
+ attempts.append(args)
61
+ if len(attempts) == 1:
62
+ raise AppsError("network interruption")
63
+ return {
64
+ "tenant": {"slug": "safe-demo", "display_name": "Demo"},
65
+ "api_key": {"token": "vrl_secret-key"},
66
+ "owner_claim": {"claim_url": "https://account.verulla.com/claim#claim-secret", "expires_at": "expires"},
67
+ }
68
+
69
+ monkeypatch.setattr("verulla_cli.main.create_signup", fake_signup)
70
+ initial = runner.invoke(app, ["signup", "--api-url", "https://api.example", "--owner-email", "owner@example.test",
71
+ "--display-name", "Demo", "--slug", "safe-demo"])
72
+ assert initial.exit_code == 1
73
+ assert pending.exists() and stat.S_IMODE(pending.stat().st_mode) == 0o600
74
+ saved_pending = json.loads(pending.read_text())
75
+ generated_key = attempts[0][-1]
76
+ assert saved_pending["idempotency_key"] == generated_key
77
+ assert len(bytes.fromhex(generated_key)) == 32
78
+ assert len(set(bytes.fromhex(generated_key))) > 16
79
+ wrong_server = runner.invoke(app, ["signup", "--recover", "--api-url", "https://other.example"])
80
+ assert wrong_server.exit_code == 1 and len(attempts) == 1 and pending.exists()
81
+ recovered = runner.invoke(app, ["signup", "--recover", "--api-url", "https://api.example", "--json"])
82
+ assert recovered.exit_code == 0, recovered.output
83
+ assert attempts[0] == attempts[1]
84
+ assert not pending.exists()
85
+ assert "vrl_secret-key" not in recovered.output
86
+ assert "owner@example.test" not in recovered.output
87
+ assert "123456789abcdef0" * 4 not in recovered.output
88
+ assert json.loads(recovered.output)["tenant"]["slug"] == "safe-demo"
89
+
90
+
91
+ def test_signup_rejects_user_supplied_repeating_recovery_key() -> None:
92
+ repeated_key = "0001020304050607" * 4
93
+ result = runner.invoke(app, [
94
+ "signup", "--api-url", "https://api.example", "--owner-email", "owner@example.test",
95
+ "--display-name", "Demo", "--idempotency-key", repeated_key,
96
+ ])
97
+ assert result.exit_code == 2
98
+ assert repeated_key not in result.output
99
+
100
+
25
101
  def test_usage_accepts_optional_app_and_prints_term_contract(monkeypatch) -> None:
26
102
  monkeypatch.setattr("verulla_cli.main.get_token", lambda: "api-token")
27
103
  monkeypatch.setattr("verulla_cli.auth.load_credentials", lambda: None)
@@ -97,6 +173,7 @@ def test_customers_export_file_is_private(tmp_path, monkeypatch) -> None:
97
173
  def test_help_lists_all_commands() -> None:
98
174
  result = runner.invoke(app, ["--help"])
99
175
  assert result.exit_code == 0
176
+ assert "https://api.verulla.app" in result.output
100
177
  for name in ("login", "dev", "deploy", "secrets", "logs", "apps", "status", "delete", "rollback", "live"):
101
178
  assert name in result.output
102
179
 
@@ -128,14 +205,45 @@ def test_secrets_scope_rejects_conflicting_flags() -> None:
128
205
  assert "either --app APP or --shared" in result.output
129
206
 
130
207
 
131
- def test_login_requires_api_url(monkeypatch) -> None:
132
- # Real device-code login landed in M4 T4.2 — login is no longer a stub.
133
- # With neither --api-url nor VERULLA_API_URL set, Typer/Click's own
134
- # required-option usage error fires (exit code 2), proving the option
135
- # is genuinely required rather than silently defaulted.
208
+ def test_login_uses_default_api_url_when_flag_and_environment_are_missing(monkeypatch) -> None:
136
209
  monkeypatch.delenv("VERULLA_API_URL", raising=False)
210
+ calls = []
211
+ monkeypatch.setattr("verulla_cli.main.run_device_login", lambda api_url: calls.append(api_url))
212
+
137
213
  result = runner.invoke(app, ["login"])
138
- assert result.exit_code == 2
214
+
215
+ assert result.exit_code == 0, result.output
216
+ assert calls == ["https://api.verulla.app"]
217
+
218
+
219
+ def test_login_environment_and_flag_override_default_in_precedence_order(monkeypatch) -> None:
220
+ calls = []
221
+ monkeypatch.setattr("verulla_cli.main.run_device_login", lambda api_url: calls.append(api_url))
222
+ monkeypatch.setenv("VERULLA_API_URL", "https://sandbox.example/")
223
+
224
+ env_result = runner.invoke(app, ["login"])
225
+ flag_result = runner.invoke(app, ["login", "--api-url", "https://dev.example/"])
226
+
227
+ assert env_result.exit_code == flag_result.exit_code == 0
228
+ assert calls == ["https://sandbox.example", "https://dev.example"]
229
+
230
+
231
+ def test_every_api_url_option_uses_the_shared_default() -> None:
232
+ from typer.main import get_command
233
+ from verulla_cli.config import DEFAULT_API_URL
234
+
235
+ def api_url_parameters(command):
236
+ for parameter in command.params:
237
+ if "--api-url" in parameter.opts:
238
+ yield parameter
239
+ for child in getattr(command, "commands", {}).values():
240
+ yield from api_url_parameters(child)
241
+
242
+ parameters = list(api_url_parameters(get_command(app)))
243
+ assert len(parameters) > 1
244
+ assert all(parameter.default == DEFAULT_API_URL for parameter in parameters)
245
+ assert all(parameter.envvar == "VERULLA_API_URL" for parameter in parameters)
246
+ assert all(getattr(parameter, "show_default", False) for parameter in parameters)
139
247
 
140
248
 
141
249
  def test_login_with_unreachable_api_url_fails_cleanly() -> None:
@@ -240,6 +348,64 @@ def test_deploy_success_prints_deployment(tmp_path, monkeypatch) -> None:
240
348
  assert recorded["tarball"].startswith(b"\x1f\x8b")
241
349
 
242
350
 
351
+ def test_deploy_wait_success_prints_sketch_handoff(tmp_path, monkeypatch) -> None:
352
+ monkeypatch.setattr("verulla_cli.main.get_token", lambda: "tok")
353
+ monkeypatch.setattr("verulla_cli.main.create_deployment", lambda *args: {
354
+ "id": "d-wait", "app": "demo-app", "url": "https://demo.verulla.app", "status": "queued",
355
+ })
356
+ states = iter([
357
+ {"status": "building", "build_log_tail": ""},
358
+ {"status": "deployed", "build_log_tail": ""},
359
+ ])
360
+ monkeypatch.setattr("verulla_cli.main.get_deployment", lambda *args: next(states))
361
+ monkeypatch.setattr("verulla_cli.main.get_sketch_status", lambda *args: {
362
+ "app": "demo-app", "status": "deployed", "url": "https://demo.verulla.app",
363
+ "expires_at": "2026-11-06T12:00:00Z", "claim_status": "pending",
364
+ "limits_url": "https://verulla.com/#pricing", "console_url": "https://account.verulla.com/",
365
+ })
366
+ monkeypatch.setattr("verulla_cli.main.time.sleep", lambda _: None)
367
+ result = runner.invoke(app, ["deploy", str(_valid_project(tmp_path)), "--api-url", "http://api.test", "--wait"])
368
+ assert result.exit_code == 0, result.output
369
+ assert "https://demo.verulla.app" in result.output
370
+ assert "2026-11-06T12:00:00Z" in result.output
371
+ assert "72 hours" in result.output
372
+ assert "custom domain" in result.output.lower()
373
+ assert "verulla sketch status demo-app" in result.output
374
+ assert "owner claim status: pending" in result.output.lower()
375
+
376
+
377
+ def test_deploy_wait_failure_exits_nonzero_and_shows_build_log_tail(tmp_path, monkeypatch) -> None:
378
+ monkeypatch.setattr("verulla_cli.main.get_token", lambda: "tok")
379
+ monkeypatch.setattr("verulla_cli.main.create_deployment", lambda *args: {
380
+ "id": "d-fail", "app": "demo-app", "status": "queued",
381
+ })
382
+ monkeypatch.setattr("verulla_cli.main.get_deployment", lambda *args: {
383
+ "id": "d-fail", "status": "apply_failed", "error": "apply failed",
384
+ })
385
+ monkeypatch.setattr("verulla_cli.main.get_app_logs", lambda *args: {
386
+ "deployment_id": "d-fail", "build_log_tail": "build output tail",
387
+ })
388
+ result = runner.invoke(app, ["deploy", str(_valid_project(tmp_path)), "--api-url", "http://api.test", "--wait"])
389
+ assert result.exit_code == 1
390
+ assert "verulla logs demo-app" in result.output
391
+ assert "build output tail" in result.output
392
+ assert "Runtime/pod logs are not available yet" in result.output
393
+
394
+
395
+ def test_deploy_wait_timeout_exits_nonzero_with_inspection_action(tmp_path, monkeypatch) -> None:
396
+ import verulla_cli.main as cli_main
397
+
398
+ monkeypatch.setattr(cli_main, "get_token", lambda: "tok")
399
+ monkeypatch.setattr(cli_main, "create_deployment", lambda *args: {"id": "d-slow", "app": "demo-app", "status": "queued"})
400
+ monkeypatch.setattr(cli_main, "get_deployment", lambda *args: {"status": "building"})
401
+ monkeypatch.setattr(cli_main.time, "monotonic", iter([0.0, 0.0, 2.0]).__next__)
402
+ monkeypatch.setattr(cli_main.time, "sleep", lambda _: None)
403
+ result = runner.invoke(app, ["deploy", str(_valid_project(tmp_path)), "--api-url", "http://api.test", "--wait", "--wait-timeout", "1"])
404
+ assert result.exit_code == 1
405
+ assert "Timed out after 1s" in result.output
406
+ assert "verulla logs demo-app" in result.output
407
+
408
+
243
409
  def test_deploy_logged_in_unreachable_api_fails_cleanly(tmp_path, monkeypatch) -> None:
244
410
  monkeypatch.setattr(
245
411
  "verulla_cli.main.get_token", lambda: "tok"
@@ -4,4 +4,4 @@ Human + agent entry point: login (OIDC device flow), dev (local Docker
4
4
  emulation via verulla_manifest), deploy, secrets, logs.
5
5
  """
6
6
 
7
- __version__ = "0.0.2"
7
+ __version__ = "0.0.3"
@@ -53,10 +53,51 @@ def _request(api_url: str, token: str, method: str, path: str, client=None, *, e
53
53
  http.close()
54
54
 
55
55
 
56
+ def create_signup(api_url: str, slug: str, display_name: str, owner_email: str,
57
+ idempotency_key: str, client=None) -> dict:
58
+ """Submit signup with a recovery key from 32 CSPRNG-generated bytes.
59
+
60
+ Encode the key as 64 lowercase hex characters. It authorizes recovery of
61
+ the bootstrap response and must never be derived from user input.
62
+ """
63
+ import hashlib
64
+
65
+ owns = client is None
66
+ http = client or httpx.Client(timeout=20)
67
+ try:
68
+ challenge_response = http.get(f"{api_url}/v1/signup/challenge")
69
+ challenge_response.raise_for_status()
70
+ challenge = challenge_response.json()
71
+ prefix, difficulty = challenge["prefix"], challenge["difficulty"]
72
+ nonce = 0
73
+ while not hashlib.sha256(f"{prefix}{nonce}".encode()).hexdigest().startswith("0" * difficulty):
74
+ nonce += 1
75
+ response = http.post(
76
+ f"{api_url}/v1/signup",
77
+ headers={"Idempotency-Key": idempotency_key},
78
+ json={"slug": slug, "display_name": display_name, "owner_email": owner_email,
79
+ "challenge_id": challenge["challenge_id"], "nonce": str(nonce)},
80
+ )
81
+ response.raise_for_status()
82
+ return response.json()
83
+ except httpx.HTTPStatusError as exc:
84
+ raise AppsError(f"signup failed ({exc.response.status_code}); check the request and retry safely") from None
85
+ except (httpx.HTTPError, KeyError, TypeError, ValueError) as exc:
86
+ raise AppsError(f"signup request could not be completed ({type(exc).__name__}); retry with the same idempotency key") from None
87
+ finally:
88
+ if owns:
89
+ http.close()
90
+
91
+
56
92
  def list_apps(api_url: str, token: str, client=None) -> list[dict]:
57
93
  return _request(api_url, token, "GET", "/v1/apps", client)["apps"]
58
94
 
59
95
 
96
+ def get_deployment(api_url: str, token: str, deployment_id: str, client=None) -> dict:
97
+ from urllib.parse import quote
98
+ return _request(api_url, token, "GET", f"/v1/deployments/{quote(deployment_id, safe='')}", client)
99
+
100
+
60
101
  def get_app(api_url: str, token: str, name: str, client=None) -> dict:
61
102
  return _request(api_url, token, "GET", f"/v1/apps/{name}", client)
62
103