solari-runloop-compat 0.2.4__tar.gz → 0.2.6__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 (55) hide show
  1. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/COMPAT.md +2 -2
  2. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/PKG-INFO +2 -2
  3. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/README.md +1 -1
  4. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/pyproject.toml +5 -2
  5. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/__init__.py +1 -1
  6. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/_config.py +7 -3
  7. solari_runloop_compat-0.2.4/tests/run_runloop_examples.sh +0 -16
  8. solari_runloop_compat-0.2.4/tests/test_config.py +0 -114
  9. solari_runloop_compat-0.2.4/tests/test_context.py +0 -97
  10. solari_runloop_compat-0.2.4/tests/test_dockerfile.py +0 -152
  11. solari_runloop_compat-0.2.4/tests/test_gateway_wire.py +0 -690
  12. solari_runloop_compat-0.2.4/tests/test_live_staging.py +0 -253
  13. solari_runloop_compat-0.2.4/tests/test_mapping.py +0 -159
  14. solari_runloop_compat-0.2.4/tests/test_surface.py +0 -255
  15. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/.gitignore +0 -0
  16. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/LICENSE +0 -0
  17. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/NOTICE +0 -0
  18. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/_branding.py +0 -0
  19. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/_client.py +0 -0
  20. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/_context.py +0 -0
  21. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/_dockerfile.py +0 -0
  22. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/_exceptions.py +0 -0
  23. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/_gateway.py +0 -0
  24. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/_loop.py +0 -0
  25. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/_mapping.py +0 -0
  26. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/_models.py +0 -0
  27. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/_redact.py +0 -0
  28. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/_resources.py +0 -0
  29. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/_sync.py +0 -0
  30. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/_vendor_user.py +0 -0
  31. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/lib/__init__.py +0 -0
  32. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/lib/polling.py +0 -0
  33. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/pagination.py +0 -0
  34. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/sdk.py +0 -0
  35. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/__init__.py +0 -0
  36. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/blueprint_build_log.py +0 -0
  37. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/blueprint_build_logs_list_view.py +0 -0
  38. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/blueprint_build_parameters.py +0 -0
  39. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/blueprint_view.py +0 -0
  40. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/devbox_async_execution_detail_view.py +0 -0
  41. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/devbox_execution_detail_view.py +0 -0
  42. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/devbox_snapshot_list_view.py +0 -0
  43. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/devbox_snapshot_view.py +0 -0
  44. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/devbox_view.py +0 -0
  45. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/devboxes/__init__.py +0 -0
  46. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/devboxes/devbox_logs_list_view.py +0 -0
  47. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/secret_view.py +0 -0
  48. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/shared/__init__.py +0 -0
  49. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/shared/after_idle.py +0 -0
  50. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/shared/code_mount_parameters.py +0 -0
  51. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/shared/launch_parameters.py +0 -0
  52. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/shared/lifecycle_configuration.py +0 -0
  53. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/shared/lifecycle_hooks.py +0 -0
  54. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/shared/resume_triggers.py +0 -0
  55. {solari_runloop_compat-0.2.4 → solari_runloop_compat-0.2.6}/solari_runloop/types/tunnel_view.py +0 -0
@@ -131,9 +131,9 @@ Last run 2026-10-21 against the F15 integration build `desktop-gateway:staging-1
131
131
  list/retrieve/pagination, suspend/resume state, snapshot -> create from snapshot, errors, size capping. See the PR for the latest run.
132
132
 
133
133
  ## Default user and home directory (matching Runloop)
134
- **Today's sandboxes run as `root` in `/home/root`. Runloop's own run as `user` in `/home/user`; this arrives with a Solari server update, and this package already asks for it** (below).
134
+ **Sandboxes run as `user` in `/home/user` on the hosted Solari API, matching Runloop's default** (checked on staging and production on 2026-11-03). Only a gateway or a template that predates user support falls back to root, as below.
135
135
 
136
- Once the gateway supports it, Runloop sandboxes run as `user` in `/home/user`; commands, code and files all start there, and relative paths resolve against it. This package
136
+ Here, Runloop sandboxes run as `user` in `/home/user`; commands, code and files all start there, and relative paths resolve against it. This package
137
137
  asks the gateway for exactly that at create time (`user: "user"`, `cwd: "/home/user"`; the gateway creates the user at first boot with passwordless
138
138
  sudo). Restores from a snapshot keep the snapshot's own user.
139
139
  - **Gateway that predates `user` / `cwd`** (it answers 400 naming them, or ignores them): the plain create is used and the sandbox runs as **root in
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: solari-runloop-compat
3
- Version: 0.2.4
3
+ Version: 0.2.6
4
4
  Summary: Runloop-compatible Python interface over Solari Sandboxes. Not affiliated with Runloop.
5
5
  Project-URL: Homepage, https://getsolari.com
6
6
  Author: Solari
@@ -43,5 +43,5 @@ under Runloop's names. **COMPAT.md** lists exactly what is supported, what diffe
43
43
  ```
44
44
  pip install -e ../python-core -e ../python-sandbox -e '.[test]'
45
45
  pytest # offline unit tests
46
- SOLARI_API_KEY=... SOLARI_BASE_URL=https://api-sta.getsolari.com pytest -m live # staging; deletes what it creates
46
+ SOLARI_API_KEY=... SOLARI_BASE_URL=<a non-production gateway URL> pytest -m live # staging; deletes what it creates
47
47
  ```
@@ -24,5 +24,5 @@ under Runloop's names. **COMPAT.md** lists exactly what is supported, what diffe
24
24
  ```
25
25
  pip install -e ../python-core -e ../python-sandbox -e '.[test]'
26
26
  pytest # offline unit tests
27
- SOLARI_API_KEY=... SOLARI_BASE_URL=https://api-sta.getsolari.com pytest -m live # staging; deletes what it creates
27
+ SOLARI_API_KEY=... SOLARI_BASE_URL=<a non-production gateway URL> pytest -m live # staging; deletes what it creates
28
28
  ```
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "solari-runloop-compat"
7
- version = "0.2.4"
7
+ version = "0.2.6"
8
8
  description = "Runloop-compatible Python interface over Solari Sandboxes. Not affiliated with Runloop."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -21,10 +21,13 @@ Homepage = "https://getsolari.com"
21
21
 
22
22
  [tool.hatch.build.targets.wheel]
23
23
  packages = ["solari_runloop"]
24
+ # The docs and error messages point at COMPAT.md, so the wheel carries it next to the package.
25
+ [tool.hatch.build.targets.wheel.force-include]
26
+ "COMPAT.md" = "solari_runloop/COMPAT.md"
24
27
 
25
28
  # The gateway-endpoint design notes are internal working documents: they stay in the repository, not in the sdist.
26
29
  [tool.hatch.build.targets.sdist]
27
- exclude = ["GATEWAY-ENDPOINTS.md", "BLUEPRINTS.md"]
30
+ exclude = ["GATEWAY-ENDPOINTS.md", "BLUEPRINTS.md", "tests"]
28
31
 
29
32
  [tool.pytest.ini_options]
30
33
  asyncio_mode = "auto"
@@ -29,7 +29,7 @@ from ._exceptions import (
29
29
  from .lib.polling import PollingConfig, PollingTimeout
30
30
  from .sdk import AsyncRunloopSDK, RunloopSDK
31
31
 
32
- __version__ = "0.2.4"
32
+ __version__ = "0.2.6"
33
33
  Client = Runloop
34
34
  AsyncClient = AsyncRunloop
35
35
 
@@ -22,8 +22,12 @@ def _first_env(names: Tuple[str, ...]) -> Optional[str]: # base URLs only; keys
22
22
  return None
23
23
 
24
24
 
25
+ #: The only Solari hosts that may receive a key (the API gateways). Not every *.getsolari.com host: preview hosts (<label>-<port>.preview.getsolari.com) serve customer code.
26
+ SOLARI_API_HOST = re.compile(r"api(-sta(-gcp)?)?\.getsolari\.com")
27
+
28
+
25
29
  def _is_solari_host(url: str) -> bool:
26
- """https on getsolari.com or a subdomain, or loopback over http(s): where a Solari key may be sent."""
30
+ """https on a Solari API host, or loopback over http(s): where a Solari key may be sent."""
27
31
  try:
28
32
  u = urlparse(url)
29
33
  host = (u.hostname or "").lower().rstrip(".")
@@ -31,7 +35,7 @@ def _is_solari_host(url: str) -> bool:
31
35
  return False
32
36
  if not host or not u.scheme:
33
37
  return False
34
- if u.scheme == "https" and (host == "getsolari.com" or host.endswith(".getsolari.com")):
38
+ if u.scheme == "https" and SOLARI_API_HOST.fullmatch(host) is not None:
35
39
  return True
36
40
  loopback = host in ("localhost", "::1") or re.fullmatch(r"127(\.\d{1,3}){3}", host) is not None
37
41
  return loopback and u.scheme in ("http", "https")
@@ -60,7 +64,7 @@ def resolve(bearer_token: Optional[str], base_url: Optional[str]) -> Tuple[str,
60
64
  given = str(base_url) if base_url else os.environ.get("SOLARI_BASE_URL")
61
65
  if given and not _is_solari_host(given):
62
66
  host = urlparse(given).hostname or "an unparsable URL"
63
- raise RunloopError(f"Refusing to send a Solari API key to {host}: it does not point at Solari (getsolari.com or loopback).")
67
+ raise RunloopError(f"Refusing to send a Solari API key to {host}: it is not a Solari API host or loopback.")
64
68
  url = given or _env_base_url() or DEFAULT_BASE_URL
65
69
  return value, url.rstrip("/")
66
70
  log.warning("Ignoring %s: it does not start with %r, so it is not a Solari key and will not be sent to Solari.", source, KEY_PREFIX)
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Runs Runloop's own example recipes (github.com/runloopai/api-client-python/examples) against a Solari gateway
3
- # with the import swapped. Needs SOLARI_API_KEY + SOLARI_BASE_URL; every recipe deletes what it creates.
4
- # usage: tests/run_runloop_examples.sh [recipe ...] (default: the ones COMPAT.md marks as supported)
5
- set -euo pipefail
6
- work=$(mktemp -d); trap 'rm -rf "$work"' EXIT
7
- mkdir -p "$work/examples"
8
- for f in _harness example_types __init__ devbox_snapshots devbox_snapshot_resume devbox_tunnel devbox_from_blueprint_lifecycle; do
9
- curl -fsSL "https://raw.githubusercontent.com/runloopai/api-client-python/main/examples/$f.py" -o "$work/examples/$f.py"
10
- done
11
- sed -i 's/runloop_api_client/solari_runloop/g' "$work"/examples/*.py
12
- cd "$work"
13
- recipes=("${@:-devbox_snapshots devbox_snapshot_resume devbox_from_blueprint_lifecycle devbox_tunnel}")
14
- for r in ${recipes[@]}; do
15
- echo "== $r"; python -W ignore -m "examples.$r" | python -c 'import json,sys; t=sys.stdin.read(); d=json.loads(t[t.index("{\n"):]); [print(("PASS " if c["passed"] else "FAIL ")+c["name"]) for c in d["checks"]]; sys.exit(1 if any(not c["passed"] for c in d["checks"]) or d["cleanup_status"]["failed"] else 0)'
16
- done
@@ -1,114 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import logging
4
-
5
- import pytest
6
-
7
- from solari_runloop import RunloopError, _config
8
-
9
- KEYS = ("SOLARI_API_KEY", "RUNLOOP_API_KEY", "SOLARI_BASE_URL", "RUNLOOP_BASE_URL")
10
-
11
-
12
- @pytest.fixture(autouse=True)
13
- def clean_env(monkeypatch):
14
- for k in KEYS:
15
- monkeypatch.delenv(k, raising=False)
16
-
17
-
18
- def test_explicit_wins(monkeypatch):
19
- monkeypatch.setenv("SOLARI_API_KEY", "slr_env")
20
- assert _config.resolve("slr_arg", "https://x.getsolari.com/") == ("slr_arg", "https://x.getsolari.com")
21
-
22
-
23
- def test_solari_env_beats_runloop_env(monkeypatch):
24
- monkeypatch.setenv("RUNLOOP_API_KEY", "slr_runloop")
25
- monkeypatch.setenv("SOLARI_API_KEY", "slr_solari")
26
- monkeypatch.setenv("RUNLOOP_BASE_URL", "https://r.getsolari.com")
27
- monkeypatch.setenv("SOLARI_BASE_URL", "https://s.getsolari.com")
28
- assert _config.resolve(None, None) == ("slr_solari", "https://s.getsolari.com")
29
-
30
-
31
- def test_runloop_env_is_the_fallback(monkeypatch):
32
- monkeypatch.setenv("RUNLOOP_API_KEY", "slr_k")
33
- monkeypatch.setenv("RUNLOOP_BASE_URL", "https://r.getsolari.com")
34
- assert _config.resolve(None, None) == ("slr_k", "https://r.getsolari.com")
35
-
36
-
37
- def test_default_base_url(monkeypatch):
38
- monkeypatch.setenv("RUNLOOP_API_KEY", "slr_k")
39
- assert _config.resolve(None, None)[1] == "https://api.getsolari.com"
40
-
41
-
42
- def test_missing_key_raises_runloop_error():
43
- with pytest.raises(RunloopError, match="SOLARI_API_KEY"):
44
- _config.resolve(None, None)
45
-
46
-
47
- def test_explicit_non_solari_key_is_skipped_and_the_next_source_is_tried(monkeypatch, caplog):
48
- monkeypatch.setenv("SOLARI_API_KEY", "slr_good")
49
- with caplog.at_level(logging.WARNING, logger="solari_runloop"):
50
- assert _config.resolve("rl_runloop_secret", None)[0] == "slr_good"
51
- assert "bearer_token argument" in caplog.text and "rl_runloop_secret" not in caplog.text
52
-
53
-
54
- def test_only_non_solari_keys_means_an_error_and_the_key_is_never_logged(monkeypatch, caplog):
55
- monkeypatch.setenv("SOLARI_API_KEY", "rl_one")
56
- monkeypatch.setenv("RUNLOOP_API_KEY", "rl_two")
57
- with caplog.at_level(logging.WARNING, logger="solari_runloop"), pytest.raises(RunloopError, match="No Solari API key"):
58
- _config.resolve("rl_three", None)
59
- assert not any(k in caplog.text for k in ("rl_one", "rl_two", "rl_three"))
60
-
61
-
62
- def test_an_slr_key_is_accepted_from_any_source(monkeypatch):
63
- monkeypatch.setenv("RUNLOOP_API_KEY", "slr_from_runloop_var")
64
- assert _config.resolve(None, None)[0] == "slr_from_runloop_var"
65
-
66
-
67
- def test_client_construction_never_uses_a_runloop_key(monkeypatch):
68
- import solari_runloop as sr
69
-
70
- monkeypatch.setenv("RUNLOOP_API_KEY", "rl_runloop_secret")
71
- with pytest.raises(RunloopError):
72
- sr.Runloop()
73
- with pytest.raises(RunloopError):
74
- sr.AsyncRunloopSDK(bearer_token="rl_runloop_secret")
75
-
76
-
77
- @pytest.mark.parametrize("url", ["https://api.runloop.ai", "https://evil.example.com", "http://169.254.169.254", "https://getsolari.com.evil.example"])
78
- def test_a_runloop_base_url_for_a_foreign_host_is_ignored_with_a_warning(monkeypatch, caplog, url):
79
- monkeypatch.setenv("SOLARI_API_KEY", "slr_k")
80
- monkeypatch.setenv("RUNLOOP_BASE_URL", url)
81
- with caplog.at_level(logging.WARNING, logger="solari_runloop"):
82
- assert _config.resolve(None, None)[1] == "https://api.getsolari.com"
83
- assert "Ignoring RUNLOOP_BASE_URL" in caplog.text and "slr_k" not in caplog.text
84
-
85
-
86
- @pytest.mark.parametrize("url", ["https://api-sta.getsolari.com", "https://api.getsolari.com/", "http://localhost:8080", "http://127.0.0.1:18080"])
87
- def test_a_runloop_base_url_for_a_solari_or_loopback_host_is_used(monkeypatch, url):
88
- monkeypatch.setenv("SOLARI_API_KEY", "slr_k")
89
- monkeypatch.setenv("RUNLOOP_BASE_URL", url)
90
- assert _config.resolve(None, None)[1] == url.rstrip("/")
91
-
92
-
93
- @pytest.mark.parametrize("url", ["https://my.proxy.internal", "https://api.runloop.ai", "https://getsolari.com.evil.example", "http://api.getsolari.com", "http://169.254.169.254", "not a url"])
94
- def test_an_explicit_base_url_for_a_foreign_host_is_refused(monkeypatch, url):
95
- monkeypatch.setenv("SOLARI_API_KEY", "slr_k")
96
- with pytest.raises(_config.RunloopError, match="Refusing to send a Solari API key"):
97
- _config.resolve(None, url)
98
- monkeypatch.delenv("SOLARI_BASE_URL", raising=False)
99
- monkeypatch.setenv("SOLARI_BASE_URL", url)
100
- with pytest.raises(_config.RunloopError, match="Refusing to send a Solari API key"):
101
- _config.resolve(None, None)
102
-
103
-
104
- def test_an_explicit_base_url_for_a_solari_or_loopback_host_is_used(monkeypatch):
105
- monkeypatch.setenv("SOLARI_API_KEY", "slr_k")
106
- assert _config.resolve(None, "https://x.getsolari.com/")[1] == "https://x.getsolari.com"
107
- assert _config.resolve(None, "http://127.0.0.1:4010")[1] == "http://127.0.0.1:4010"
108
-
109
-
110
- def test_solari_base_url_beats_runloop_base_url(monkeypatch):
111
- monkeypatch.setenv("SOLARI_API_KEY", "slr_k")
112
- monkeypatch.setenv("SOLARI_BASE_URL", "https://api-sta.getsolari.com")
113
- monkeypatch.setenv("RUNLOOP_BASE_URL", "https://api.runloop.ai")
114
- assert _config.resolve(None, None)[1] == "https://api-sta.getsolari.com"
@@ -1,97 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import base64
4
- import io
5
- import tarfile
6
-
7
- import pytest
8
-
9
- import solari_runloop as sr
10
- from solari_runloop import _context as ctxmod
11
- from solari_runloop import _dockerfile as df
12
-
13
-
14
- def make_tree(tmp_path):
15
- (tmp_path / "app").mkdir()
16
- (tmp_path / "app/main.py").write_text("print('hi')\n")
17
- (tmp_path / "app/skip.log").write_text("noise")
18
- (tmp_path / "README.md").write_text("r")
19
- (tmp_path / ".dockerignore").write_text("*.log\n")
20
- return tmp_path
21
-
22
-
23
- def names(tar_gz):
24
- with tarfile.open(fileobj=io.BytesIO(tar_gz), mode="r:gz") as tf:
25
- return sorted(tf.getnames())
26
-
27
-
28
- def test_context_from_dir_honours_dockerignore_and_is_deterministic(tmp_path):
29
- root = make_tree(tmp_path)
30
- a, b = ctxmod.from_dir(str(root)), ctxmod.from_dir(str(root))
31
- assert "app/main.py" in names(a.tar_gz) and "app/skip.log" not in names(a.tar_gz)
32
- assert a.id == b.id and a.tar_gz == b.tar_gz
33
-
34
-
35
- def test_context_size_cap(tmp_path, monkeypatch):
36
- monkeypatch.setattr(ctxmod, "MAX_CONTEXT_BYTES", 100)
37
- (tmp_path / "big").write_bytes(__import__("os").urandom(5000))
38
- with pytest.raises(sr.SolariCompatUnsupported, match="700 KB"):
39
- ctxmod.from_dir(str(tmp_path))
40
-
41
-
42
- def compile_with(tmp_path, dockerfile):
43
- return df.compile_dockerfile(dockerfile, context=ctxmod.from_dir(str(make_tree(tmp_path))).tar_gz)
44
-
45
-
46
- def test_copy_without_a_context_is_unsupported():
47
- with pytest.raises(sr.SolariCompatUnsupported, match="build_context"):
48
- df.compile_dockerfile("FROM ubuntu\nCOPY a /a")
49
-
50
-
51
- def test_copy_steps(tmp_path):
52
- c = compile_with(tmp_path, "FROM ubuntu:22.04\nWORKDIR /opt/app\nCOPY app/main.py ./\nCOPY --chown=1000:1000 README.md /srv/README.md\nCOPY app /dst/")
53
- cmds = [s["command"] for s in c["steps"] if s["op"] == "run"]
54
- assert cmds[0].startswith("rm -rf /tmp/solari-context && mkdir -p /tmp/solari-context && echo ")
55
- assert "cd /tmp/solari-context && mkdir -p /opt/app/ && cp -a -- app/main.py /opt/app/" in cmds[1].replace("'", "")
56
- assert "chown -R 1000:1000 /srv/README.md" in cmds[2]
57
- assert "cp -a -- app /dst/" in cmds[3].replace("'", "")
58
- assert cmds[-1] == "rm -rf /tmp/solari-context"
59
- blob = cmds[0].split("echo ")[1].split(" | base64")[0]
60
- assert "app/main.py" in names(base64.b64decode(blob))
61
-
62
-
63
- def test_copy_into_a_from_image_build(tmp_path):
64
- c = compile_with(tmp_path, "FROM python:3.12-alpine\nCOPY README.md /srv/R.md")
65
- assert c["fromImage"] == "python:3.12-alpine"
66
- assert any("cp -a -- README.md /srv/R.md" in s.get("command", "").replace("'", "") for s in c["steps"])
67
- assert not any("/srv/root" in s.get("command", "") for s in c["steps"])
68
-
69
-
70
- def test_add_unpacks_a_local_archive(tmp_path):
71
- (tmp_path / "a.tgz").write_bytes(b"x")
72
- c = df.compile_dockerfile("FROM ubuntu\nADD a.tgz /opt/", context=ctxmod.from_dir(str(tmp_path)).tar_gz)
73
- assert any("tar -xf a.tgz -C /opt/" in s.get("command", "").replace("'", "") for s in c["steps"])
74
-
75
-
76
- @pytest.mark.parametrize("line", ["COPY ../x /x", "COPY /etc/passwd /x", "COPY --from=build /a /b", "ADD https://e.com/f /f", "COPY --link a /a", "COPY onlyone"])
77
- def test_bad_copy_forms_are_refused(tmp_path, line):
78
- with pytest.raises(sr.SolariCompatUnsupported):
79
- compile_with(tmp_path, "FROM ubuntu\n" + line)
80
-
81
-
82
- def test_storage_object_upload_from_dir_and_build_context(tmp_path, monkeypatch):
83
- from solari_runloop._gateway import Gateway
84
-
85
- async def no_objects(self):
86
- return False
87
-
88
- monkeypatch.setattr(Gateway, "objects_available", no_objects)
89
- monkeypatch.setenv("SOLARI_API_KEY", "slr_t")
90
- with sr.RunloopSDK() as sdk:
91
- obj = sdk.storage_object.upload_from_dir(make_tree(tmp_path))
92
- assert obj.as_build_context() == {"type": "object", "object_id": obj.id}
93
- assert sdk.storage_object.from_id(obj.id).id == obj.id
94
- with pytest.raises(sr.SolariCompatUnsupported):
95
- sdk.storage_object.get_everything()
96
- with pytest.raises(sr.SolariCompatUnsupported, match="another process"):
97
- sdk.api.blueprints.create(name="x", dockerfile="FROM ubuntu\nCOPY a /a", build_context={"type": "object", "object_id": "ctx_unknown"})
@@ -1,152 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import base64
4
-
5
- import pytest
6
-
7
- import solari_runloop as sr
8
- from solari_runloop import _dockerfile as df
9
-
10
- DOCKERFILE = """\
11
- # build image
12
- ARG PY=3.12
13
- FROM ubuntu:22.04
14
- ENV APP_MODE=prod GREETING="hello world"
15
- WORKDIR /opt/app
16
- RUN apt-get update && \\
17
- apt-get install -y ffmpeg
18
- RUN ["echo", "hi there"]
19
- LABEL a=b
20
- EXPOSE 8080
21
- ENTRYPOINT ["/opt/app/run"]
22
- CMD serve --port 8080
23
- """
24
-
25
-
26
- def test_full_dockerfile_compiles_to_steps():
27
- c = df.compile_dockerfile(DOCKERFILE)
28
- assert c["base"] == "base" and c["kind"] == "sandbox" and c["packages"] == [] and c["localFiles"] == []
29
- assert c["steps"] == [
30
- {"op": "env", "key": "APP_MODE", "value": "prod"},
31
- {"op": "env", "key": "GREETING", "value": "hello world"},
32
- {"op": "workdir", "dir": "/opt/app"},
33
- {"op": "run", "command": "export PY=3.12; apt-get update && apt-get install -y ffmpeg"},
34
- {"op": "run", "command": "echo 'hi there'"},
35
- {"op": "entrypoint", "command": ["/opt/app/run"]},
36
- {"op": "cmd", "command": ["/bin/sh", "-c", "serve --port 8080"]},
37
- ]
38
-
39
-
40
- def test_setup_commands_file_mounts_and_base_blueprint():
41
- c = df.compile_dockerfile(None, system_setup_commands=["make"], file_mounts={"/etc/x.conf": "a=1\n"}, base_blueprint_name="acme-base")
42
- assert c["fromTemplate"] == "acme-base" and "base" not in c
43
- assert c["steps"][0] == {"op": "run", "command": "make"}
44
- b64 = base64.b64encode(b"a=1\n").decode()
45
- assert b64 in c["steps"][1]["command"] and "/etc/x.conf" in c["steps"][1]["command"]
46
-
47
-
48
- def test_build_args_override_arg_defaults():
49
- c = df.compile_dockerfile("FROM debian:12\nARG V=1\nRUN echo $V", build_args={"V": "2"})
50
- assert "V=2" in c["steps"][0]["command"]
51
-
52
-
53
- @pytest.mark.parametrize(
54
- "text",
55
- ["FROM evil.example.com/team/img:1", "FROM scratch", "FROM ubuntu AS b\nRUN x", "FROM ubuntu\nFROM debian", "FROM ubuntu\nCOPY a /a", "FROM ubuntu\nUSER bob", "FROM ubuntu\nHEALTHCHECK CMD true"],
56
- )
57
- def test_unsupported_dockerfile_features(text):
58
- with pytest.raises(sr.SolariCompatUnsupported):
59
- df.compile_dockerfile(text)
60
-
61
-
62
- @pytest.mark.parametrize("image", ["ubuntu", "ubuntu:22.04", "docker.io/library/ubuntu:24.04", "debian:bookworm-slim", "base"])
63
- def test_supported_bases(image):
64
- assert df.compile_dockerfile(f"FROM {image}")["base"] == "base"
65
-
66
-
67
- def test_logical_lines_joins_continuations_and_skips_comments():
68
- assert df.logical_lines("RUN a \\\n # note\n b\n\n# c\nENV x=1") == [("RUN", "a b"), ("ENV", "x=1")]
69
-
70
-
71
- def test_other_images_use_the_native_from_image_build():
72
- c = df.compile_dockerfile("FROM python:3.12-alpine\nENV A=1\nWORKDIR /app\nRUN pip --version\nENTRYPOINT [\"/e\"]")
73
- assert c["fromImage"] == "python:3.12-alpine" and "base" not in c and "fromTemplate" not in c
74
- assert c["steps"] == [
75
- {"op": "env", "key": "A", "value": "1"},
76
- {"op": "workdir", "dir": "/app"},
77
- {"op": "run", "command": "pip --version"},
78
- {"op": "entrypoint", "command": ["/e"]},
79
- ]
80
- blob = repr(c)
81
- assert "crane" not in blob and "solari-run" not in blob and "/srv/root" not in blob # no chroot shim any more
82
-
83
-
84
- def test_from_image_env_keeps_the_images_own_variables_for_the_gateway():
85
- # golang:1.22 has PATH=/go/bin:/usr/local/go/bin:...; the gateway expands $PATH against it, so it must not be pre-expanded here.
86
- c = df.compile_dockerfile("FROM golang:1.22\nENV PATH=/opt/x/bin:$PATH\nENV GOFLAGS=-mod=mod:${PATH}")
87
- assert c["fromImage"] == "golang:1.22"
88
- assert c["steps"][0] == {"op": "env", "key": "PATH", "value": "/opt/x/bin:$PATH"}
89
- assert c["steps"][1] == {"op": "env", "key": "GOFLAGS", "value": "-mod=mod:${PATH}"}
90
-
91
-
92
- def test_from_image_env_chain_is_left_to_the_gateway_and_args_are_expanded_here():
93
- c = df.compile_dockerfile("FROM node:20\nARG V=7\nENV A=/opt/$V\nENV PATH=$A/bin:$PATH")
94
- assert [(s["key"], s["value"]) for s in c["steps"]] == [("A", "/opt/7"), ("PATH", "$A/bin:$PATH")]
95
-
96
-
97
- def test_from_image_build_arg_path_is_a_real_argument():
98
- c = df.compile_dockerfile("FROM node:20\nENV X=$PATH", build_args={"PATH": "/custom"})
99
- assert c["steps"][0]["value"] == "/custom"
100
-
101
-
102
- def test_from_image_build_arg_path_combined_with_an_env_that_references_it():
103
- c = df.compile_dockerfile("FROM node:20\nENV PATH=/opt/x/bin:$PATH", build_args={"PATH": "/custom"})
104
- assert c["steps"][0] == {"op": "env", "key": "PATH", "value": "/opt/x/bin:/custom"}
105
-
106
-
107
- def test_native_base_images_still_expand_path_against_dockers_default():
108
- c = df.compile_dockerfile("FROM ubuntu:22.04\nENV PATH=/opt/x/bin:$PATH")
109
- assert "fromImage" not in c and c["base"] == "base"
110
- assert c["steps"][0]["value"] == "/opt/x/bin:" + df.DEFAULT_PATH
111
-
112
-
113
- @pytest.mark.parametrize("image", ["ghcr.io/org/img:1", "quay.io/org/img", "public.ecr.aws/x/y:2", "python:3.12", "library/python:3.12", "docker.io/library/node:20"])
114
- def test_allowlisted_registries(image):
115
- assert df.compile_dockerfile(f"FROM {image}")["fromImage"] == image
116
-
117
-
118
- @pytest.mark.parametrize("image", ["evil.example.com/a:1", "localhost:5000/a", "10.0.0.5/a", "registry.internal/a"])
119
- def test_other_registries_refused(image):
120
- with pytest.raises(sr.SolariCompatUnsupported, match="public images"):
121
- df.compile_dockerfile(f"FROM {image}")
122
-
123
-
124
- def test_import_switch_forces_from_image_for_debian_family():
125
- assert df.compile_dockerfile("FROM ubuntu:22.04")["steps"] == []
126
- forced = df.compile_dockerfile("FROM ubuntu:22.04", build_args={"SOLARI_IMPORT": "1"})
127
- assert forced["fromImage"] == "ubuntu:22.04" and "base" not in forced
128
-
129
-
130
- def test_from_image_file_mounts_land_at_their_path():
131
- c = df.compile_dockerfile("FROM alpine", file_mounts={"/etc/x": "1"})
132
- assert c["fromImage"] == "alpine" and "/etc/x" in c["steps"][-1]["command"] and "/srv/root" not in c["steps"][-1]["command"]
133
-
134
-
135
- @pytest.mark.parametrize("bad", ["ENV A;B=1", "ENV $(id)=1", "ENV a-b=1"])
136
- def test_env_names_are_validated_before_they_reach_the_env_file(bad):
137
- with pytest.raises(sr.SolariCompatUnsupported):
138
- df.compile_dockerfile("FROM python:3.12-alpine\n" + bad)
139
-
140
-
141
-
142
- def test_env_path_prepend_expands_against_the_docker_default_path():
143
- c = df.compile_dockerfile("FROM ubuntu:22.04\nENV PATH=/opt/x/bin:$PATH\nENV PATH=${PATH}:/opt/y")
144
- assert [s for s in c["steps"] if s["op"] == "env"] == [
145
- {"op": "env", "key": "PATH", "value": "/opt/x/bin:" + df.DEFAULT_PATH},
146
- {"op": "env", "key": "PATH", "value": "/opt/x/bin:" + df.DEFAULT_PATH + ":/opt/y"},
147
- ]
148
-
149
-
150
- def test_build_arg_path_overrides_the_default():
151
- c = df.compile_dockerfile("FROM ubuntu:22.04\nENV PATH=/opt/x/bin:$PATH", build_args={"PATH": "/custom"})
152
- assert {"op": "env", "key": "PATH", "value": "/opt/x/bin:/custom"} in c["steps"]