release: freeze Nexus One AI 1.0.0-rc1
This commit is contained in:
1 parent
63acefd890
commit
4f1419ca93
152 files changed
+9445
-828
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
MODULE_PATH = Path(__file__).parents[2] / "autoinstall/offline/prepare-python-profile-operation.py"
|
||||
SPEC = importlib.util.spec_from_file_location("prepare_python_profile_operation", MODULE_PATH)
|
||||
MODULE = importlib.util.module_from_spec(SPEC)
|
||||
assert SPEC.loader
|
||||
SPEC.loader.exec_module(MODULE)
|
||||
|
||||
|
||||
class PreparePythonProfileOperationTests(unittest.TestCase):
|
||||
def test_prepares_and_resumes_without_mutating_target(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
target = root / "venv"
|
||||
target.mkdir()
|
||||
(target / "old").write_text("old")
|
||||
wheels = root / "wheels"
|
||||
wheels.mkdir()
|
||||
wheel = wheels / "torch-cpu.whl"
|
||||
wheel.write_bytes(b"cpu")
|
||||
contract = {"profiles": {"cpu-only": {
|
||||
"required": {wheel.name: hashlib.sha256(b"cpu").hexdigest()},
|
||||
"forbidden_filename_patterns": ["cu12"],
|
||||
}}}
|
||||
receipt = {
|
||||
"schema": "com.cezen.nexus-one.profile-membership-verification-receipt.v1",
|
||||
"environment": "test", "result": "verified", "manifest_sha256": "a" * 64,
|
||||
"namespace": "offline-workstation/python-runtime-profiles", "profiles": ["cpu-only"],
|
||||
}
|
||||
args = ({"architecture": "amd64"}, receipt, "auto", "op-1", root / "journal.json",
|
||||
target, root / "checkpoint", contract, wheels, True)
|
||||
first = MODULE.prepare(*args)
|
||||
second = MODULE.prepare(*args)
|
||||
self.assertEqual(first["checkpoint_id"], second["checkpoint_id"])
|
||||
self.assertEqual((target / "old").read_text(), "old")
|
||||
self.assertFalse(first["mutation_performed"])
|
||||
|
||||
def test_invalid_payload_creates_no_journal_or_checkpoint(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
wheels = root / "wheels"
|
||||
wheels.mkdir()
|
||||
receipt = {
|
||||
"schema": "com.cezen.nexus-one.profile-membership-verification-receipt.v1",
|
||||
"environment": "test", "result": "verified", "manifest_sha256": "a" * 64,
|
||||
"namespace": "offline-workstation/python-runtime-profiles", "profiles": ["cpu-only"],
|
||||
}
|
||||
journal = root / "journal.json"
|
||||
checkpoint = root / "checkpoint"
|
||||
with self.assertRaisesRegex(ValueError, "PROFILE_PAYLOAD_INVALID"):
|
||||
MODULE.prepare({"architecture": "amd64"}, receipt, "auto", "op-1", journal,
|
||||
root / "target", checkpoint,
|
||||
{"profiles": {"cpu-only": {"required": {"missing.whl": "0" * 64}}}},
|
||||
wheels, True)
|
||||
self.assertFalse(journal.exists())
|
||||
self.assertFalse(checkpoint.exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user