Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Give the Docker step harnesses the environment those steps now declare (#11521)

Daniel Han2656ffe63a60
diff --git a/tests/python/test_docker_credential_probe.py b/tests/python/test_docker_credential_probe.py
index b951a98de2a..68d85b324d2 100644
--- a/tests/python/test_docker_credential_probe.py
+++ b/tests/python/test_docker_credential_probe.py
@@ -10,6 +10,7 @@ the delete step is run here with curl stubbed and its requests inspected.
from __future__ import annotations
import os
+import re
import subprocess
from pathlib import Path
@@ -30,11 +31,15 @@ def delete_step() -> str:
if s.get("name") == "Delete the probe tag"
]
assert len(steps) == 1, "the delete step disappeared or was renamed"
- return steps[0]["run"]
+ return steps[0]
+
+
+# The stand-in for DOCKER_API_KEY, named so an assertion can look for it.
+SECRET = "not-a-secret"
def _run(
- step: str,
+ step: dict,
tmp_path: Path,
*,
still_there: bool,
@@ -46,6 +51,13 @@ def _run(
(bin_dir / "curl").write_text(
"#!/usr/bin/env bash\n"
f"printf '%s\\n' \"$*\" >> {log}\n"
+ # The request body does not always travel in argv. #11511 moved the token
+ # request onto stdin (`--data-binary @-`) so the org secret stops showing up
+ # in the process list, and a stub that logs only "$*" then records a call
+ # whose payload is simply absent: every assertion about what was SENT passes
+ # vacuously or fails for the wrong reason. Read it where it actually is, and
+ # only when the arguments say there is one, since `cat` with no stdin hangs.
+ f"case \"$*\" in *'--data-binary @-'*) cat >> {log} ;; esac\n"
'case "$*" in\n'
f' *auth/token*) printf \'{{"access_token": "{token}"}}\' ;;\n'
" *-X\\ DELETE*) printf '204' ;;\n"
@@ -54,13 +66,28 @@ def _run(
encoding = "utf-8",
)
(bin_dir / "curl").chmod(0o755)
- script = step.replace("${{ secrets.DOCKER_API_KEY }}", "not-a-secret")
+ script = step["run"].replace("${{ secrets.DOCKER_API_KEY }}", SECRET)
assert "${{" not in script, "unexpanded expression in the delete step"
env = dict(os.environ)
env["PATH"] = f"{bin_dir}{os.pathsep}" + env["PATH"]
env.update(
REGISTRY_USERNAME = "unsloth", IMAGE_NAME = "unsloth/unsloth", PROBE_TAG = "credential-probe"
)
+ # Whatever the step declares in its own `env:`, bound here too. #11511 moved the
+ # secret out of the run body and into `env: DOCKER_API_KEY`, read with
+ # `os.environ`, so rewriting the body alone hands the script an environment it
+ # cannot run in and the request goes out with an empty payload.
+ # Only the secret this step is supposed to read is expanded. Standing in for any
+ # `secrets.*` would make the harness agree with a workflow that names the wrong
+ # one: `${{ secrets.TYPO }}` would still produce a valid payload here, while
+ # Actions would hand the real step an empty value. Anything else is left for the
+ # assertion below to reject by name.
+ for name, value in (step.get("env") or {}).items():
+ env[name] = re.sub(r"\$\{\{\s*secrets\.DOCKER_API_KEY\s*\}\}", SECRET, str(value))
+ assert "${{" not in env[name], (
+ f"the step's env {name} reads {value!r}, which is not the secret this "
+ f"harness knows how to supply"
+ )
res = subprocess.run(
["bash", "-e", "-c", script],
capture_output = True,
@@ -73,7 +100,7 @@ def _run(
def test_the_delete_uses_the_namespace_route_the_org_token_is_allowed_on(
- delete_step: str, tmp_path: Path
+ delete_step: dict, tmp_path: Path
):
res, log = _run(delete_step, tmp_path, still_there = False)
assert res.returncode == 0, res.stdout + res.stderr
@@ -84,17 +111,22 @@ def test_the_delete_uses_the_namespace_route_the_org_token_is_allowed_on(
assert (
"/v2/repositories/" not in log
), "the legacy route answers every organization token with 403"
+ # A non-empty body first: an empty request carries no identifier either, so the
+ # check below cannot otherwise tell the wrong identity from no request at all.
+ assert (
+ f'"secret": "{SECRET}"' in log
+ ), "the token request carried no body, so this proves nothing about who it authenticates as"
assert '"identifier": "unsloth"' in log
assert "Authorization: Bearer tok" in log
-def test_a_tag_that_survives_the_delete_fails_the_step(delete_step: str, tmp_path: Path):
+def test_a_tag_that_survives_the_delete_fails_the_step(delete_step: dict, tmp_path: Path):
res, _ = _run(delete_step, tmp_path, still_there = True)
assert res.returncode != 0
assert "still resolves" in res.stdout + res.stderr
-def test_no_token_means_no_delete_and_a_failure(delete_step: str, tmp_path: Path):
+def test_no_token_means_no_delete_and_a_failure(delete_step: dict, tmp_path: Path):
res, log = _run(delete_step, tmp_path, still_there = True, token = "")
assert res.returncode != 0
assert "DELETE" not in log
diff --git a/tests/python/test_docker_hub_readme.py b/tests/python/test_docker_hub_readme.py
index 85781fcf196..5d15891c9f8 100644
--- a/tests/python/test_docker_hub_readme.py
+++ b/tests/python/test_docker_hub_readme.py
@@ -11,6 +11,7 @@ from __future__ import annotations
import json
import os
+import re
import shutil
import subprocess
from pathlib import Path
@@ -23,6 +24,9 @@ WORKFLOW = REPO_ROOT / ".github" / "workflows" / "docker-publish.yml"
HUB_README = REPO_ROOT / "docker" / "DOCKERHUB.md"
REPO_README = REPO_ROOT / "README.md"
+# The stand-in for DOCKER_API_KEY, named so an assertion can look for it.
+DEFAULT_SECRET = "not-a-secret"
+
def test_the_hub_readme_describes_the_shipped_images():
text = HUB_README.read_text(encoding = "utf-8")
@@ -139,12 +143,12 @@ def test_the_sync_runs_only_when_latest_moved(sync_job: dict):
def _run_sync(
- step: str,
+ step: dict,
tmp_path: Path,
*,
live_after_patch: str,
token: str = "tok",
- secret: str = "not-a-secret",
+ secret: str = DEFAULT_SECRET,
):
bin_dir = tmp_path / "bin"
bin_dir.mkdir()
@@ -156,6 +160,13 @@ def _run_sync(
(bin_dir / "curl").write_text(
"#!/usr/bin/env bash\n"
f"printf '%s\\n' \"$*\" >> {log}\n"
+ # The request body does not always travel in argv. #11511 moved the token
+ # request onto stdin (`--data-binary @-`) so the org secret stops showing up
+ # in the process list, and a stub that logs only "$*" then records a call
+ # whose payload is simply absent: every assertion about what was SENT passes
+ # vacuously or fails for the wrong reason. Read it where it actually is, and
+ # only when the arguments say there is one, since `cat` with no stdin hangs.
+ f"case \"$*\" in *'--data-binary @-'*) cat >> {log} ;; esac\n"
'case "$*" in\n'
f' *auth/token*) printf \'{{"access_token": "{token}"}}\' ;;\n'
" *-X\\ PATCH*) out=''; while [ $# -gt 0 ]; do [ \"$1\" = -o ] && out=$2; shift; done; : > \"$out\"; printf '200' ;;\n"
@@ -166,14 +177,33 @@ def _run_sync(
(bin_dir / "curl").chmod(0o755)
(tmp_path / "docker").mkdir()
shutil.copy(HUB_README, tmp_path / "docker" / "DOCKERHUB.md")
- script = step.replace("${{ secrets.DOCKER_API_KEY }}", secret).replace(
- "${{ env.REGISTRY_USERNAME }}", "unsloth"
+ script = (
+ step["run"]
+ .replace("${{ secrets.DOCKER_API_KEY }}", secret)
+ .replace("${{ env.REGISTRY_USERNAME }}", "unsloth")
)
assert "${{" not in script, "unexpanded expression in the sync step"
env = dict(os.environ)
env["PATH"] = f"{bin_dir}{os.pathsep}" + env["PATH"]
env["REGISTRY_USERNAME"] = "unsloth"
env["IMAGE_NAME"] = "unsloth/unsloth"
+ # Whatever the step declares in its own `env:`, bound here too. The secret used to
+ # be written inline in the run body, where substituting the expression was enough;
+ # #11511 moved it to `env: DOCKER_API_KEY` and read it with `os.environ`, so a
+ # harness that only rewrites the body hands the script an environment it cannot
+ # run in. That does not fail loudly: the body builder raises, the pipeline keeps
+ # the exit status of its last command, and the request goes out empty.
+ # Only the secret this step is supposed to read is expanded. Standing in for any
+ # `secrets.*` would make the harness agree with a workflow that names the wrong
+ # one: `${{ secrets.TYPO }}` would still produce a valid payload here, while
+ # Actions would hand the real step an empty value. Anything else is left for the
+ # assertion below to reject by name.
+ for name, value in (step.get("env") or {}).items():
+ env[name] = re.sub(r"\$\{\{\s*secrets\.DOCKER_API_KEY\s*\}\}", secret, str(value))
+ assert "${{" not in env[name], (
+ f"the step's env {name} reads {value!r}, which is not the secret this "
+ f"harness knows how to supply"
+ )
res = subprocess.run(
["bash", "-e", "-c", script],
capture_output = True,
@@ -186,11 +216,17 @@ def _run_sync(
def test_the_sync_patches_the_readme_and_confirms_it(sync_job: dict, tmp_path: Path):
- step = sync_job["steps"][-1]["run"]
+ step = sync_job["steps"][-1]
res, log = _run_sync(step, tmp_path, live_after_patch = HUB_README.read_text(encoding = "utf-8"))
assert res.returncode == 0, res.stdout + res.stderr
assert "-X PATCH https://hub.docker.com/v2/namespaces/unsloth/repositories/unsloth" in log
assert "Authorization: Bearer tok" in log
+ # The body, wherever curl was handed it. Asserted as a non-empty payload first:
+ # an empty request logs no identifier either, so the bare `in log` check below
+ # cannot tell "authenticated as someone else" from "sent nothing at all".
+ assert (
+ f'"secret": "{DEFAULT_SECRET}"' in log
+ ), "the token request carried no body, so this proves nothing about who it authenticates as"
assert '"identifier": "unsloth"' in log, "the organization token authenticates as the org"
@@ -199,7 +235,7 @@ def test_the_sync_never_touches_the_legacy_repository_route(sync_job: dict, tmp_
/v2/repositories/{owner}/{repo}/ with 403 "token issued from organization access
token is not allowed", whatever its scopes; only the namespace-scoped route
accepts it. That 403 failed the sync on every publish before this test existed."""
- step = sync_job["steps"][-1]["run"]
+ step = sync_job["steps"][-1]
_, log = _run_sync(step, tmp_path, live_after_patch = HUB_README.read_text(encoding = "utf-8"))
assert "/v2/repositories/" not in log
assert "/v2/namespaces/unsloth/repositories/unsloth" in log
@@ -208,14 +244,14 @@ def test_the_sync_never_touches_the_legacy_repository_route(sync_job: dict, tmp_
def test_the_sync_fails_when_the_page_did_not_change(sync_job: dict, tmp_path: Path):
"""A 200 from PATCH is not proof. The page is read back and compared, so a token
without description rights cannot leave the job green and the page stale."""
- step = sync_job["steps"][-1]["run"]
+ step = sync_job["steps"][-1]
res, _ = _run_sync(step, tmp_path, live_after_patch = "# the old page")
assert res.returncode != 0, "the sync reported success while the page stayed stale"
assert "does not match" in res.stdout + res.stderr
def test_the_sync_fails_without_a_token(sync_job: dict, tmp_path: Path):
- step = sync_job["steps"][-1]["run"]
+ step = sync_job["steps"][-1]
res, log = _run_sync(step, tmp_path, live_after_patch = "", token = "")
assert res.returncode != 0
assert "PATCH" not in log, "a PATCH was attempted with an empty token"