Celestis-RL / tests /test_release.py
PureOne's picture
Release Celestis-RL v2.0.0: audited research reference
f95cbd4 verified
Raw History Blame Contribute Delete
2.47 kB
import json
from pathlib import Path
from types import SimpleNamespace
import pytest
from celestis_rl.release import build_manifest,verify_manifest,publish_release
def tree(tmp):
(tmp/"README.md").write_text("reference release")
(tmp/"src").mkdir();(tmp/"src/a.py").write_text("print('example')")
return build_manifest(tmp)
def test_manifest_and_dry_run_no_network(tmp_path):
m=tree(tmp_path);assert len(verify_manifest(tmp_path)["files"])==2
r=publish_release(tmp_path,"example/research")
assert not r["uploaded"] and r["operation"]=="dry-run"
def test_manifest_detects_changes_ignores_extras_and_rejects_unsafe_paths(tmp_path):
tree(tmp_path);(tmp_path/"README.md").write_text("changed")
with pytest.raises(ValueError,match="mismatch"):verify_manifest(tmp_path)
# Local extras are ignored because publication stages only manifest files.
tree_extra=tmp_path/"extra_case";tree_extra.mkdir();tree(tree_extra)
(tree_extra/"local-note.jpg").write_bytes(b"not part of release")
assert verify_manifest(tree_extra)["version"]=="2.0.0"
dry=publish_release(tree_extra,"example/research")
assert dry["ignored_local_files"]==["local-note.jpg"]
tree2=tmp_path/"other";tree2.mkdir();tree(tree2)
path=tree2/"release/MANIFEST.json";m=json.loads(path.read_text());m["files"]["../escape"]={}
path.write_text(json.dumps(m))
with pytest.raises(ValueError,match="unsafe"):verify_manifest(tree2)
def test_token_and_secret_scan(tmp_path):
(tmp_path/"leak.txt").write_text("hf_"+"a"*32)
with pytest.raises(ValueError,match="token"):build_manifest(tmp_path)
def test_mock_publication_stages_only_manifest_files(tmp_path):
tree(tmp_path);calls=[]
class Fake:
def create_repo(self,**kw):calls.append(kw)
def upload_folder(self,**kw):
verify_manifest(kw["folder_path"]);calls.append(kw)
return SimpleNamespace(commit_url="mock-commit")
r=publish_release(tmp_path,"example/research",publish=True,public=True,api=Fake())
assert r["uploaded"] and r["commit_url"]=="mock-commit"
assert calls[0]["private"] is False and calls[0]["exist_ok"] is False
assert calls[1]["repo_type"]=="dataset"
def test_publish_requires_auth_and_repo_id(tmp_path):
tree(tmp_path)
with pytest.raises(ValueError,match="HF_TOKEN"):publish_release(tmp_path,"x/y",publish=True)
with pytest.raises(ValueError,match="namespace"):publish_release(tmp_path,"../x")