Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Upload 127 files
Browse files- tests/test_v102_ui_polish_links_billing.py +1 -1
- tests/test_v123_job_launch_command_and_failure_timeline.py +1 -1
- tests/test_v172_fresh_bucket_writes_prescan_readme.py +25 -0
- tests/test_v173_bucket_mount_path_separation.py +28 -0
- tests/test_v174_bucket_runs_prefix_mount_and_write_fallback.py +54 -0
- tests/test_v175_anonymous_eval_archive.py +60 -0
tests/test_v102_ui_polish_links_billing.py
CHANGED
|
@@ -7,7 +7,7 @@ def test_bucket_document_links_use_tree_urls_not_blob_urls():
|
|
| 7 |
assert "/blob/runs/" not in bucket_py
|
| 8 |
assert "/blob/runs/" not in runs_js
|
| 9 |
assert "def _bucket_file_url" in bucket_py
|
| 10 |
-
assert "/tree/
|
| 11 |
assert "bucketRunFileUrl" in runs_js
|
| 12 |
|
| 13 |
|
|
|
|
| 7 |
assert "/blob/runs/" not in bucket_py
|
| 8 |
assert "/blob/runs/" not in runs_js
|
| 9 |
assert "def _bucket_file_url" in bucket_py
|
| 10 |
+
assert "tree/{_runs_prefix()}" in bucket_py or "tree/{prefix}" in bucket_py
|
| 11 |
assert "bucketRunFileUrl" in runs_js
|
| 12 |
|
| 13 |
|
tests/test_v123_job_launch_command_and_failure_timeline.py
CHANGED
|
@@ -20,7 +20,7 @@ def test_v123_jobs_persist_worker_script_to_bucket_before_launch():
|
|
| 20 |
assert "WORKER_SCRIPT_PATH" in jobs_py
|
| 21 |
assert '"WORKER_SCRIPT_B64":' not in jobs_py
|
| 22 |
assert 'env["WORKER_SCRIPT_B64"]' not in jobs_py
|
| 23 |
-
assert "
|
| 24 |
|
| 25 |
|
| 26 |
def test_v123_argument_list_too_long_logs_create_failure_event():
|
|
|
|
| 20 |
assert "WORKER_SCRIPT_PATH" in jobs_py
|
| 21 |
assert '"WORKER_SCRIPT_B64":' not in jobs_py
|
| 22 |
assert 'env["WORKER_SCRIPT_B64"]' not in jobs_py
|
| 23 |
+
assert "{_runs_prefix()}/{run_id}/_worker.py" in jobs_py
|
| 24 |
|
| 25 |
|
| 26 |
def test_v123_argument_list_too_long_logs_create_failure_event():
|
tests/test_v172_fresh_bucket_writes_prescan_readme.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
|
| 3 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def test_readme_keeps_huggingface_metadata_at_file_start():
|
| 7 |
+
readme = (ROOT / "README.md").read_text(encoding="utf-8")
|
| 8 |
+
assert readme.startswith("---\ntitle: Agentic Space Factory\nsdk: docker")
|
| 9 |
+
assert "hf_oauth: true" in readme.split("---", 2)[1]
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def test_bucket_writes_use_direct_bucket_object_write_without_virtual_makedirs():
|
| 13 |
+
bucket = (ROOT / "src" / "bucket.py").read_text(encoding="utf-8")
|
| 14 |
+
assert "def _write_bucket_text" in bucket
|
| 15 |
+
assert "fs.pipe_file(candidate, data, mode=\"overwrite\")" in bucket
|
| 16 |
+
assert "fs.makedirs(parent, exist_ok=True)" not in bucket
|
| 17 |
+
assert "write_text(_worker_script_bucket_path" in (ROOT / "src" / "jobs.py").read_text(encoding="utf-8")
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def test_model_prescan_card_uses_calm_premium_overrides():
|
| 21 |
+
css = (ROOT / "web" / "static" / "app.css").read_text(encoding="utf-8")
|
| 22 |
+
assert "v172: calmer, premium Model pre-scan card" in css
|
| 23 |
+
assert "linear-gradient(180deg,rgba(255,255,255,.96),rgba(248,250,252,.92))" in css
|
| 24 |
+
assert ".prescan-meta{\n display:grid!important;" in css
|
| 25 |
+
assert "model-prescan-card.success:before" in css
|
tests/test_v173_bucket_mount_path_separation.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
|
| 3 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def test_api_bucket_writes_do_not_makedirs_virtual_runs_prefixes():
|
| 7 |
+
bucket = (ROOT / "src" / "bucket.py").read_text(encoding="utf-8")
|
| 8 |
+
assert "def _is_bucket_uri" in bucket
|
| 9 |
+
assert "def _write_bucket_text" in bucket
|
| 10 |
+
assert "fs.pipe_file(candidate, data, mode=\"overwrite\")" in bucket
|
| 11 |
+
assert "fs.makedirs(parent, exist_ok=True)" not in bucket
|
| 12 |
+
assert "_ensure_bucket_parent" not in bucket
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def test_worker_script_has_separate_remote_uri_and_job_mount_path():
|
| 16 |
+
jobs = (ROOT / "src" / "jobs.py").read_text(encoding="utf-8")
|
| 17 |
+
assert "def _worker_script_bucket_path" in jobs
|
| 18 |
+
assert "{bucket_uri_from_source(bucket_source)}/{_runs_prefix()}/{run_id}/_worker.py" in jobs
|
| 19 |
+
assert "def _worker_script_mount_path" in jobs
|
| 20 |
+
assert "{_runs_mount_path().rstrip('/')}/{run_id}/_worker.py" in jobs
|
| 21 |
+
assert "write_text(_worker_script_bucket_path" in jobs
|
| 22 |
+
assert "return _worker_script_mount_path(run_id=run_id)" in jobs
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def test_legacy_parent_creation_assertion_is_not_positive_anymore():
|
| 26 |
+
old = (ROOT / "tests" / "test_v172_fresh_bucket_writes_prescan_readme.py").read_text(encoding="utf-8")
|
| 27 |
+
assert "def test_bucket_writes_create_fresh_run_parent_prefix_before_open" not in old
|
| 28 |
+
assert "not in bucket" in old
|
tests/test_v174_bucket_runs_prefix_mount_and_write_fallback.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
from types import SimpleNamespace
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
from src import bucket as bucket_mod
|
| 7 |
+
from src.jobs import _launch_job, _worker_script_bucket_path, _worker_script_mount_path
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def test_job_mounts_runs_prefix_at_output_runs(monkeypatch):
|
| 11 |
+
captured = {}
|
| 12 |
+
|
| 13 |
+
def fake_run_job(**kwargs):
|
| 14 |
+
captured.update(kwargs)
|
| 15 |
+
return SimpleNamespace(id="job-1")
|
| 16 |
+
|
| 17 |
+
monkeypatch.setattr("src.jobs.run_job", fake_run_job)
|
| 18 |
+
_launch_job(token="tok", env={}, bucket_source="alice/space-factory-runs")
|
| 19 |
+
volumes = captured["volumes"]
|
| 20 |
+
assert len(volumes) == 1
|
| 21 |
+
volume = volumes[0]
|
| 22 |
+
assert getattr(volume, "type") == "bucket"
|
| 23 |
+
assert getattr(volume, "source") == "alice/space-factory-runs"
|
| 24 |
+
assert getattr(volume, "path") == "runs"
|
| 25 |
+
assert getattr(volume, "mount_path") == "/output/runs"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def test_worker_script_paths_match_remote_runs_prefix_and_mounted_runs_prefix():
|
| 29 |
+
assert _worker_script_bucket_path(bucket_source="alice/space-factory-runs", run_id="run-1") == "hf://buckets/alice/space-factory-runs/runs/run-1/_worker.py"
|
| 30 |
+
assert _worker_script_mount_path(run_id="run-1") == "/output/runs/run-1/_worker.py"
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class BrokenFs:
|
| 34 |
+
def write_text(self, *args, **kwargs):
|
| 35 |
+
raise RuntimeError("repository and revision exist")
|
| 36 |
+
|
| 37 |
+
def pipe_file(self, *args, **kwargs):
|
| 38 |
+
raise RuntimeError("repository and revision exist")
|
| 39 |
+
|
| 40 |
+
def open(self, *args, **kwargs):
|
| 41 |
+
raise RuntimeError("repository and revision exist")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def test_bucket_write_falls_back_to_sync_bucket_for_fresh_object(monkeypatch, tmp_path):
|
| 45 |
+
calls = []
|
| 46 |
+
|
| 47 |
+
def fake_sync_bucket(*, source, dest, token=None, quiet=False, **kwargs):
|
| 48 |
+
calls.append({"source": source, "dest": dest, "token": token, "quiet": quiet})
|
| 49 |
+
uploaded = Path(source) / "runs" / "run-1" / "_worker.py"
|
| 50 |
+
assert uploaded.read_text(encoding="utf-8") == "print('ok')"
|
| 51 |
+
|
| 52 |
+
monkeypatch.setattr(bucket_mod, "sync_bucket", fake_sync_bucket)
|
| 53 |
+
bucket_mod._write_bucket_text(BrokenFs(), "hf://buckets/alice/space-factory-runs/runs/run-1/_worker.py", "print('ok')", token="tok")
|
| 54 |
+
assert calls == [{"source": calls[0]["source"], "dest": "hf://buckets/alice/space-factory-runs", "token": "tok", "quiet": True}]
|
tests/test_v175_anonymous_eval_archive.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from src import jobs
|
| 4 |
+
from src.config import Settings
|
| 5 |
+
from src.worker_payload import universal_model_card_worker_script, validate_existing_space_worker_script
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def eval_settings() -> Settings:
|
| 9 |
+
return Settings(
|
| 10 |
+
bucket_name="space-factory-runs",
|
| 11 |
+
bucket_mount="/output",
|
| 12 |
+
bucket_runs_prefix="runs",
|
| 13 |
+
job_flavor="cpu-basic",
|
| 14 |
+
job_timeout="30m",
|
| 15 |
+
job_image="python:3.12",
|
| 16 |
+
eval_enabled=True,
|
| 17 |
+
eval_bucket_source="huggingface/agentic-space-factory-evals",
|
| 18 |
+
eval_bucket_path="evals",
|
| 19 |
+
eval_bucket_mount="/evals",
|
| 20 |
+
eval_salt="test-salt",
|
| 21 |
+
eval_include_redacted_tails=False,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def test_eval_bucket_env_is_passed_when_enabled(monkeypatch):
|
| 26 |
+
monkeypatch.setattr(jobs, "settings", eval_settings())
|
| 27 |
+
env = jobs._base_env(run_id="universal-20260606-000000-abcd1234", username="alice", bucket_source="alice/space-factory-runs", worker_script_path="/output/runs/x/_worker.py")
|
| 28 |
+
assert env["ASF_EVAL_ENABLED"] == "true"
|
| 29 |
+
assert env["ASF_EVAL_BUCKET_SOURCE"] == "huggingface/agentic-space-factory-evals"
|
| 30 |
+
assert env["ASF_EVAL_BUCKET_PATH"] == "evals"
|
| 31 |
+
assert env["ASF_EVAL_BUCKET_MOUNT"] == "/evals"
|
| 32 |
+
assert env["ASF_EVAL_SALT"] == "test-salt"
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def test_eval_bucket_is_mounted_as_separate_job_volume(monkeypatch):
|
| 36 |
+
monkeypatch.setattr(jobs, "settings", eval_settings())
|
| 37 |
+
volumes = jobs._job_volumes("alice/space-factory-runs")
|
| 38 |
+
rendered = [vars(v) if hasattr(v, "__dict__") else v for v in volumes]
|
| 39 |
+
text = repr(rendered)
|
| 40 |
+
assert "alice/space-factory-runs" in text
|
| 41 |
+
assert "huggingface/agentic-space-factory-evals" in text
|
| 42 |
+
assert "evals" in text
|
| 43 |
+
assert "/evals" in text
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def test_workers_publish_anonymized_eval_records_without_raw_code_or_prompts():
|
| 47 |
+
script = universal_model_card_worker_script()
|
| 48 |
+
validation = validate_existing_space_worker_script()
|
| 49 |
+
for src in (script, validation):
|
| 50 |
+
assert "def publish_eval_record" in src
|
| 51 |
+
assert "anonymous_run_id" in src
|
| 52 |
+
assert "anonymous_user_hash" in src
|
| 53 |
+
assert "target_space_hash" in src
|
| 54 |
+
assert "generated_code_stored" in src
|
| 55 |
+
assert "raw_prompts_stored" in src
|
| 56 |
+
assert "eval_record.json" in src
|
| 57 |
+
assert "events_compact.jsonl" in src
|
| 58 |
+
assert "ASF_EVAL_INCLUDE_MODEL_ID" in src
|
| 59 |
+
assert "Published anonymized evaluation record" in script
|
| 60 |
+
assert "Published anonymized validation evaluation record" in validation
|