56 lines
2.4 KiB
Python
56 lines
2.4 KiB
Python
"""Regression coverage for installations missing the console resources."""
|
|
import json
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
import installer_payload
|
|
from packaging_checks import check_console_assets
|
|
|
|
|
|
class ConsolePackagingTests(unittest.TestCase):
|
|
def test_manifest_cannot_omit_any_console_resource(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
root = Path(directory)
|
|
names = ["ZhenAI-WeCom-Assistant-v1.5.1.exe",
|
|
"_internal/python312.dll", *installer_payload.REQUIRED_FILES]
|
|
for name in names:
|
|
path = root / name
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_bytes(b"fixture")
|
|
manifest_path = installer_payload.write_manifest(root, "1.5.1")
|
|
original = json.loads(manifest_path.read_text())
|
|
for name in names:
|
|
if "/assets/ui/" not in name:
|
|
continue
|
|
with self.subTest(resource=name):
|
|
manifest = {**original, "files": dict(original["files"])}
|
|
del manifest["files"][name]
|
|
manifest_path.write_text(json.dumps(manifest))
|
|
with self.assertRaisesRegex(RuntimeError, "Required runtime missing"):
|
|
installer_payload.validate_installation(root)
|
|
|
|
def test_missing_or_empty_console_resource_fails_probe(self):
|
|
names = ["zhenyang-ai-console.html", "console-app.js",
|
|
"console-responsive.css", "console-review.css"]
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
root = Path(directory)
|
|
with patch("runtime_paths.resource_path", side_effect=lambda *parts: root / parts[-1]):
|
|
for name in names:
|
|
(root / name).write_text("fixture")
|
|
check_console_assets()
|
|
for name in names:
|
|
with self.subTest(resource=name):
|
|
(root / name).unlink()
|
|
with self.assertRaisesRegex(RuntimeError, "missing or empty"):
|
|
check_console_assets()
|
|
(root / name).touch()
|
|
with self.assertRaisesRegex(RuntimeError, "missing or empty"):
|
|
check_console_assets()
|
|
(root / name).write_text("fixture")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|