test(nix): cover region routing, stable readiness and lost terminals

This commit is contained in:
lucannez64 committed 2026-10-18 13:54:18 +02:00
1 parent 33581fb216
commit 3e67d946c6
3 files changed
+86 -1

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
"""Stop at a stub fetcher: verify installer routing without network or runtime use."""
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
class InstallerRegions(unittest.TestCase):
def test_aliases_and_platform_codes_reach_the_expected_cdn_region(self):
with tempfile.TemporaryDirectory() as folder:
root = Path(folder)
(root / 'scripts').mkdir()
(root / 'build/runtime/tools').mkdir(parents=True)
shutil.copy(ROOT / 'scripts/installer.sh', root / 'scripts')
(root / 'scripts/configure.py').write_text('')
(root / 'build/runtime/tools/fetch-installer.sh').write_text(
'printf "%s" "$1" > "$TEST_REGION_LOG"\nexit 23\n')
log = root / 'region'
env = dict(os.environ, TEST_REGION_LOG=str(log))
env.pop('DARLING_WORKSPACE', None)
for region, expected in [('lan', 'la1'), ('las', 'la2'), ('oce', 'oc1'),
('la1', 'la1'), ('la2', 'la2'), ('oc1', 'oc1'),
('euw', 'euw')]:
with self.subTest(region=region):
log.unlink(missing_ok=True)
result = subprocess.run(['sh', str(root / 'scripts/installer.sh'), region],
env=env, capture_output=True, text=True, timeout=10)
self.assertEqual(result.returncode, 23, result.stderr)
self.assertEqual(log.read_text(), expected)
+20 -1
View File
@@ -6,7 +6,7 @@ import shutil
import subprocess
import tempfile
import unittest
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch
ROOT = Path(__file__).resolve().parents[1]
@@ -88,3 +88,22 @@ exit "${CLIENT_RC:-0}"
self.assertIn('23', result.stderr)
self.assertEqual(self.log.read_text().splitlines().count('shutdown:shutdown'), 2)
self.assertIn('shutdown:shutdown', self.log.read_text())
def test_shutdown_retries_when_terminal_diagnostics_fail(self):
spec = importlib.util.spec_from_file_location('lifecycle_fixture', self.root / 'scripts/nix-lifecycle.py')
lifecycle = importlib.util.module_from_spec(spec)
spec.loader.exec_module(lifecycle)
child = MagicMock()
child.wait.return_value = 17
stderr = MagicMock()
stderr.write.side_effect = OSError('terminal disconnected')
with patch.dict(os.environ, self.env), \
patch.object(lifecycle.signal, 'signal'), \
patch.object(lifecycle.subprocess, 'Popen', return_value=child), \
patch.object(lifecycle.subprocess, 'run', side_effect=[
subprocess.CompletedProcess([], 23), subprocess.CompletedProcess([], 0)]) as shutdown, \
patch.object(lifecycle.time, 'sleep'), \
patch.object(lifecycle.sys, 'stderr', stderr):
self.assertEqual(lifecycle.main(), 17)
self.assertEqual(shutdown.call_count, 2)
stderr.write.assert_called()
+33
View File
@@ -106,6 +106,39 @@ class RuntimeIdentityTests(unittest.TestCase):
env.pop('DPREFIX')
self.assertEqual(self.state('check', env).returncode, 0)
def test_inventory_ignores_changes_inside_backup_directories(self):
spec = importlib.util.spec_from_file_location('inventory_fixture', self.root / 'scripts/nix-state.py')
state = importlib.util.module_from_spec(spec)
spec.loader.exec_module(state)
runtime = self.root / 'usr-local/libexec/darling'
for suffix in ('.before-test', '.rt-test', '.llvm-test'):
backup = runtime / ('backup' + suffix) / 'nested'
backup.mkdir(parents=True)
saved = backup / 'saved.dylib'
saved.write_text('old backup')
before = state.inventory(runtime)
saved.write_text('changed backup')
self.assertEqual(state.inventory(runtime), before)
def test_inventory_is_independent_of_filesystem_directory_order(self):
from unittest.mock import patch
spec = importlib.util.spec_from_file_location('inventory_fixture', self.root / 'scripts/nix-state.py')
state = importlib.util.module_from_spec(spec)
spec.loader.exec_module(state)
runtime = self.root / 'usr-local/libexec/darling'
for name in ('a', 'b'):
folder = runtime / name
folder.mkdir()
(folder / 'file').write_text(name)
original_walk = os.walk
def reversed_walk(*args, **kwargs):
for directory, dirs, files in original_walk(*args, **kwargs):
dirs.reverse()
yield directory, dirs, files
before = state.inventory(runtime)
with patch.object(state.os, 'walk', reversed_walk):
self.assertEqual(state.inventory(runtime), before)
if __name__ == '__main__':
unittest.main()