50 lines
2.7 KiB
Python
50 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Exercise the ISO builder's actual payload-selection branches, without a build."""
|
|
import os
|
|
import pathlib
|
|
import subprocess
|
|
import tempfile
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parents[2]
|
|
source = (ROOT / 'image-recipe/_archived/build-auto-installer-iso.sh').read_text()
|
|
capture = source.split('# Native AIUI is part of the qualified dashboard graph;', 1)[1].split('# Copy app manifests', 1)[0]
|
|
program = 'set -eu\n# ' + capture
|
|
with tempfile.TemporaryDirectory(prefix='archy-iso-qualified-ui-') as tmp:
|
|
base = pathlib.Path(tmp)
|
|
qualified = base / 'qualified'
|
|
qualified.mkdir(parents=True)
|
|
(qualified / 'index.html').write_text('qualified-dashboard')
|
|
(qualified / 'packages').mkdir()
|
|
(qualified / 'packages/archipelago-companion.apk').write_bytes(b'qualified-code58-apk-fixture')
|
|
(qualified / 'packages/archipelago-companion.json').write_text('{"versionCode":58,"versionName":"0.5.38-debug"}')
|
|
(qualified / 'archipelago-runtime/scripts').mkdir(parents=True)
|
|
(qualified / 'archipelago-runtime/scripts/c01_network_owner.py').write_text('qualified-network-fixture')
|
|
for label, path, success in [('qualified', qualified, True), ('missing', base / 'absent', False)]:
|
|
out = base / 'outputs' / label / 'installer'
|
|
(out / 'web-ui').mkdir(parents=True)
|
|
if label == 'partial':
|
|
path.mkdir(exist_ok=True)
|
|
(path / 'index.html').write_text('incomplete')
|
|
stage = base / ('stage-'+label)
|
|
stage.mkdir()
|
|
if success:
|
|
import shutil
|
|
shutil.copytree(path, stage / 'web-ui')
|
|
result = subprocess.run(['bash', '-c', program], env=os.environ | {
|
|
'INPUT_STAGE': str(base / ('stage-'+label)), 'ARCH_DIR': str(out),
|
|
'BUILD_FROM_SOURCE': '0', 'DEV_SERVER': 'localhost', 'SCRIPT_DIR': str(base),
|
|
}, capture_output=True, text=True)
|
|
assert (result.returncode == 0) == success, (label, result.stdout, result.stderr)
|
|
if success:
|
|
assert (out / 'web-ui/index.html').read_text() == 'qualified-dashboard'
|
|
assert not (out / 'web-ui/aiui/index.html').exists()
|
|
for name in ('packages/archipelago-companion.apk', 'packages/archipelago-companion.json',
|
|
'archipelago-runtime/scripts/c01_network_owner.py'):
|
|
assert (out / 'web-ui' / name).read_bytes() == (qualified / name).read_bytes(), name
|
|
else:
|
|
assert not list((out / 'web-ui').iterdir()), 'invalid payload silently fell back to a live node'
|
|
print('PASS ISO payload selection:', label)
|
|
|
|
# Full input validation covers partial/changed/native archive refusal before staging.
|
|
subprocess.run(['python3','-m','unittest','scripts.tests.test_image_inputs'],cwd=ROOT,check=True)
|