Files
tracer-cloud--opensre/tests/packaging/test_windows_boot_import_safety.py
T
wehub-resource-sync 4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

71 lines
2.5 KiB
Python

"""Guard: the harness boot path imports without POSIX-only stdlib modules.
Frozen Windows builds have no ``resource`` / ``fcntl`` / ``termios`` / ``pwd`` /
``grp``. A bare top-level import of one anywhere the startup import chain reaches
crashes ``opensre.exe`` before it starts. This reproduces the Windows condition
in a subprocess (the modules are made unimportable) and asserts the boot chain
run by ``__main__`` still imports and installs cleanly.
Linux/macOS CI shards cannot catch this on their own — the modules are present
there — so this test simulates their absence.
"""
from __future__ import annotations
import os
import subprocess
import sys
import textwrap
# POSIX-only stdlib modules absent on Windows.
_POSIX_ONLY_MODULES = ("resource", "fcntl", "termios", "pwd", "grp")
# The exact boot chain __main__ runs at startup (see surfaces .../boundary.py).
_BOOT_CALL = (
"from surfaces.interactive_shell.ui.output.boundary import install_harness_ports\n"
"install_harness_ports()"
)
def test_harness_boot_imports_without_posix_only_modules() -> None:
script = textwrap.dedent(
"""
import builtins
_blocked = set({blocked!r})
_real_import = builtins.__import__
def _guard(name, *args, **kwargs):
if name.split(".", 1)[0] in _blocked:
raise ModuleNotFoundError(f"No module named {{name!r}} (simulated Windows)")
return _real_import(name, *args, **kwargs)
builtins.__import__ = _guard
{boot_call}
print("BOOT_OK")
"""
).format(blocked=list(_POSIX_ONLY_MODULES), boot_call=_BOOT_CALL)
# A subprocess inherits os.environ but not this process's runtime sys.path
# (e.g. a conftest injection), so pass the current import roots through
# PYTHONPATH — otherwise 'surfaces' may be unimportable and the failure would
# look like a POSIX-only-module problem when it is really a path problem.
env = {**os.environ, "PYTHONPATH": os.pathsep.join(sys.path)}
result = subprocess.run(
[sys.executable, "-c", script],
capture_output=True,
text=True,
env=env,
timeout=60,
)
assert result.returncode == 0, (
f"harness boot subprocess exited {result.returncode} with POSIX-only "
f"modules {_POSIX_ONLY_MODULES} absent (Windows):\n"
f"--- stdout ---\n{result.stdout}\n--- stderr ---\n{result.stderr}"
)
assert "BOOT_OK" in result.stdout, (
f"boot did not reach BOOT_OK:\n"
f"--- stdout ---\n{result.stdout}\n--- stderr ---\n{result.stderr}"
)