Files
archy/scripts/tests/test_production_dashboard_boundary.py
Dorian 8366a4dbc8 Bind production dashboard build to non-demo profile
(cherry picked from commit 1320db90b65afd3e79543ca6c515a21c800a3fde)
2026-11-12 14:27:04 -05:00

60 lines
2.6 KiB
Python

import os
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
from scripts.check_production_dashboard_boundary import check
class ProductionDashboardBoundaryTest(unittest.TestCase):
source_commit = "a" * 40
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()
self.addCleanup(self.tmp.cleanup)
self.root = Path(self.tmp.name)
(self.root / "neode-ui/src").mkdir(parents=True)
self.dist = self.root / "web/dist/neode-ui"
self.dist.mkdir(parents=True)
(self.dist / "index.html").write_text("<html></html>")
(self.dist / "ARCHY-BUILD-PROFILE.json").write_text(
'{"schema":1,"builder":"vite-dashboard","demo":false,"source_revision":"' + self.source_commit + '"}'
)
self.env = patch.dict(os.environ, {"VITE_DEMO": "0"}, clear=True)
self.env.start()
self.addCleanup(self.env.stop)
def test_clean_native_build_is_hashed(self):
result = check(self.root, self.dist, "native-vite-production", self.source_commit)
self.assertEqual(result["vite_demo"], "0")
self.assertEqual(result["files"], 2)
self.assertEqual(len(result["tree_sha256"]), 64)
def test_demo_builder_or_flag_cannot_pass(self):
with self.assertRaisesRegex(ValueError, "release builder"):
check(self.root, self.dist, "neode-ui/Dockerfile.web", self.source_commit)
os.environ["VITE_DEMO"] = "1"
with self.assertRaisesRegex(ValueError, "VITE_DEMO=0"):
check(self.root, self.dist, "native-vite-production", self.source_commit)
def test_demo_profile_cannot_be_renamed_as_production(self):
(self.dist / "ARCHY-BUILD-PROFILE.json").write_text(
'{"schema":1,"builder":"vite-dashboard","demo":true,"source_revision":"' + self.source_commit + '"}'
)
with self.assertRaisesRegex(ValueError, "build-time profile"):
check(self.root, self.dist, "native-vite-production", self.source_commit)
def test_mock_import_or_server_asset_cannot_pass(self):
(self.root / "neode-ui/src/App.ts").write_text("import './mock/content-payments.js'\n")
with self.assertRaisesRegex(ValueError, "imports a demo mock"):
check(self.root, self.dist, "native-vite-production", self.source_commit)
(self.root / "neode-ui/src/App.ts").unlink()
(self.dist / "mock-backend.js").write_text("server")
with self.assertRaisesRegex(ValueError, "demo mock/server asset"):
check(self.root, self.dist, "native-vite-production", self.source_commit)
if __name__ == "__main__":
unittest.main()