feat: unify source and skills for Dever 0.1.2 installation

This commit is contained in:
Antigravity committed 2026-10-05 02:49:17 +00:00
1 parent a2e0436ed4
commit 19f122b4b4
47 files changed
+1951 -63

No files matched your search

+84
View File
@@ -212,6 +212,8 @@ class InstallerTests(unittest.TestCase):
calls = []
def download(address):
self.assertTrue(address.startswith(
f"https://git.dever.cc/shemic/dever/dist/1.2.3/dever-{self.platform}."))
return (assets_path / address.rsplit("/", 1)[-1]).open("rb")
def extract(command, **kwargs):
@@ -298,6 +300,88 @@ class InstallerTests(unittest.TestCase):
self.assertEqual(len(calls), 1)
self.assertEqual(list(image.iterdir()), [])
def test_metadata_uses_latest_or_exact_directory_and_never_a_github_fallback(self):
for version in ("latest", "1.2.3"):
destination = self.directory(version)
addresses = []
def download(address):
addresses.append(address)
return io.BytesIO(b"metadata")
with mock.patch.object(installer, "download", side_effect=download):
installer.metadata(destination, None, version, self.platform)
self.assertEqual(addresses, [
f"https://git.dever.cc/shemic/dever/dist/{version}/dever-{self.platform}.{suffix}"
for suffix in ("manifest.json", "manifest.sig")
])
def test_redirects_remain_on_the_official_https_site(self):
handler = installer.OfficialRedirect()
current = "https://git.dever.cc/shemic/dever/dist/latest/a"
request = installer.urllib.request.Request(current)
allowed = "https://git.dever.cc/shemic/dever/dist/1.2.3/a"
redirected = handler.redirect_request(request, None, 302, "Found", {}, allowed)
self.assertEqual(redirected.full_url, allowed)
for address in (
"http://git.dever.cc/a", "https://evil.example/a",
"https://git.dever.cc.evil.example/a", "https://user@git.dever.cc/a",
"https://git.dever.cc:444/a", "https://git.dever.cc/a#fragment",
"https://github.com/a", "https://release-assets.githubusercontent.com/a"):
with self.subTest(address=address), self.assertRaises(ValueError):
handler.redirect_request(request, None, 302, "Found", {}, address)
def test_prerequisites_reject_unsupported_hosts_before_download(self):
with mock.patch.object(installer.os, "confstr", return_value="glibc 2.39"):
installer.prerequisites("linux-x86_64")
for libc in ("glibc 2.38", "musl 1.2", ""):
with mock.patch.object(installer.os, "confstr", return_value=libc), \
self.assertRaisesRegex(ValueError, "glibc"):
installer.prerequisites("linux-x86_64")
with mock.patch.object(installer.os, "access", return_value=False), \
self.assertRaisesRegex(ValueError, "openssl"):
installer.prerequisites("linux-x86_64")
@unittest.skipUnless(installer.os.geteuid() == 0, "owned image installation requires root")
def test_standalone_bash_uses_embedded_key_and_cleans_after_signature_failure(self):
# Execute an independently signed fixture to observe the entire entry
# and bootstrap call chain, without installing a machine or service.
generator = load_module("dever_install_entry", ROOT / "sdk/install-entry.py")
launcher = self.release / "bootstrap/dever"
launcher.write_text('''#!/usr/bin/python3
import json
from pathlib import Path
import sys
assert sys.argv[1] == "--dever-install"
setting = json.loads((Path(sys.argv[2]) / "config/setting.json").read_text())
assert setting["activate_service"] is False
(Path(setting["system_root"]) / "called.json").write_text(json.dumps(setting))
''')
content = launcher.read_bytes()
manifest = json.loads((self.release / "manifest.json").read_text())
for artifact in manifest["artifacts"]:
if artifact["path"] == "bootstrap/dever":
artifact.update(bytes=len(content), sha256=hashlib.sha256(content).hexdigest())
(self.release / "manifest.json").write_text(json.dumps(manifest))
self.sign_manifest()
entry = generator.render((ROOT / "skills/scripts/install.py").read_text(), self.public.read_text())
image = self.directory("image")
arguments = ["/bin/bash", "-s", "--", "--release", str(self.release),
"--system-root", str(image), "--version", "1.2.3", "--no-start"]
completed = subprocess.run(arguments, input=entry, env={}, text=True,
capture_output=True, timeout=20)
self.assertEqual(completed.returncode, 0, completed.stderr)
self.assertTrue((image / "called.json").is_file())
self.assertEqual(list(image.glob(".dever-install-*")), [])
(image / "called.json").unlink()
with (self.release / "manifest.json").open("a") as stream:
stream.write(" ")
rejected = subprocess.run(arguments, input=entry, env={}, text=True,
capture_output=True, timeout=20)
self.assertNotEqual(rejected.returncode, 0)
self.assertIn("签名校验失败", rejected.stderr)
self.assertEqual(list(image.iterdir()), [])
if __name__ == "__main__":
unittest.main()