test(release): make native macOS acceptance reproducible
This commit is contained in:
1 parent
428b5fb619
commit
30c66c1719
4 files changed
+61
-17
No files matched your search
@@ -4,7 +4,9 @@ import asyncio
|
||||
import json
|
||||
import logging
|
||||
import sys
|
||||
import tempfile
|
||||
from contextlib import asynccontextmanager
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from websockets.asyncio.client import connect, unix_connect
|
||||
@@ -16,6 +18,17 @@ from nanobot.webui.gateway_services import build_gateway_services
|
||||
from nanobot.webui.websocket_logging import WebSocketHandshakeNoiseFilter
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def listener_path(tmp_path):
|
||||
if sys.platform != "darwin":
|
||||
yield tmp_path
|
||||
return
|
||||
# macOS limits sockaddr_un to 104 bytes; pytest's descriptive temporary
|
||||
# paths can exceed it. Keep the real socket in its own private short root.
|
||||
with tempfile.TemporaryDirectory(prefix="nb-ws-", dir="/tmp") as root:
|
||||
yield Path(root)
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def _listener(tmp_path, monkeypatch, caplog, unix, process_request):
|
||||
if unix and sys.platform == "win32":
|
||||
@@ -84,7 +97,7 @@ async def _request(writer, path):
|
||||
@pytest.mark.parametrize("unix", [False, True], ids=["tcp", "unix"])
|
||||
@pytest.mark.parametrize("half_close", [False, True], ids=["close", "half-close"])
|
||||
async def test_disconnect_during_http_response_keeps_listener_usable(
|
||||
tmp_path, monkeypatch, caplog, unix, half_close,
|
||||
listener_path, monkeypatch, caplog, unix, half_close,
|
||||
):
|
||||
arrived = asyncio.get_running_loop().create_future()
|
||||
release = asyncio.Event()
|
||||
@@ -97,7 +110,7 @@ async def test_disconnect_during_http_response_keeps_listener_usable(
|
||||
completed.set()
|
||||
return connection.respond(200, "healthy\n")
|
||||
|
||||
async with _listener(tmp_path, monkeypatch, caplog, unix, process_request) as (channel, address):
|
||||
async with _listener(listener_path, monkeypatch, caplog, unix, process_request) as (channel, address):
|
||||
try:
|
||||
async with _stream(address) as (_reader, writer):
|
||||
await _request(writer, "/delayed")
|
||||
@@ -136,7 +149,7 @@ async def test_disconnect_during_http_response_keeps_listener_usable(
|
||||
@pytest.mark.parametrize("unix", [False, True], ids=["tcp", "unix"])
|
||||
@pytest.mark.parametrize("peer_left", [False, True], ids=["connected", "disconnected"])
|
||||
async def test_http_callback_failure_remains_visible(
|
||||
tmp_path, monkeypatch, caplog, unix, peer_left,
|
||||
listener_path, monkeypatch, caplog, unix, peer_left,
|
||||
):
|
||||
arrived = asyncio.get_running_loop().create_future()
|
||||
release = asyncio.Event()
|
||||
@@ -147,7 +160,7 @@ async def test_http_callback_failure_remains_visible(
|
||||
await release.wait()
|
||||
raise failure
|
||||
|
||||
async with _listener(tmp_path, monkeypatch, caplog, unix, process_request) as (_channel, address):
|
||||
async with _listener(listener_path, monkeypatch, caplog, unix, process_request) as (_channel, address):
|
||||
try:
|
||||
async with _stream(address) as (reader, writer):
|
||||
await _request(writer, "/delayed")
|
||||
|
||||
@@ -11,6 +11,7 @@ import json
|
||||
import math
|
||||
import os
|
||||
import platform
|
||||
import plistlib
|
||||
import shutil
|
||||
import sqlite3
|
||||
import statistics
|
||||
@@ -111,6 +112,20 @@ def filesystem_identity(path):
|
||||
)
|
||||
filesystem_type = fs_name.value if ok else None
|
||||
collector = "GetVolumeInformationW"
|
||||
elif sys.platform == "darwin":
|
||||
# diskutil accepts a device or mount point, not an arbitrary directory.
|
||||
# df resolves APFS firmlinks (for example /Users on the Data volume).
|
||||
try:
|
||||
rows = subprocess.check_output(["/bin/df", "-P", str(resolved)], text=True, timeout=10).splitlines()
|
||||
device = rows[1].split()[0]
|
||||
info = plistlib.loads(subprocess.check_output(
|
||||
["/usr/sbin/diskutil", "info", "-plist", device], timeout=10,
|
||||
))
|
||||
filesystem_type = info.get("FilesystemType")
|
||||
mount_point = info.get("MountPoint", mount_point)
|
||||
collector = "diskutil"
|
||||
except (OSError, subprocess.SubprocessError, ValueError, IndexError):
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
best = ("", None)
|
||||
|
||||
@@ -71,6 +71,13 @@ def uv_installation(tmp_path, monkeypatch):
|
||||
tmp_path = tmp_path.resolve()
|
||||
account = tmp_path / "private account"
|
||||
account.mkdir()
|
||||
# Test the receipt-bound installation, not the invoking uv run process or
|
||||
# a developer's resolver policy. Explicit policy cases add their own input.
|
||||
for key in list(os.environ):
|
||||
if key.startswith("UV_"):
|
||||
monkeypatch.delenv(key)
|
||||
monkeypatch.setenv("XDG_CONFIG_HOME", str(account / ".config"))
|
||||
monkeypatch.setenv("XDG_CONFIG_DIRS", str(account / "config-dirs"))
|
||||
monkeypatch.setattr(Path, "home", classmethod(lambda cls: account))
|
||||
# The read-only bootstrap has the same isolated account as frozen workers.
|
||||
monkeypatch.setattr(update_process, "_INSPECTION_BOOTSTRAP", (
|
||||
|
||||
@@ -4,6 +4,7 @@ Linux/Windows CI retain the portable generation tests in test_sandbox.py.
|
||||
These native tests use only isolated fixtures and a loopback HTTP service.
|
||||
"""
|
||||
|
||||
import re
|
||||
import shlex
|
||||
import shutil
|
||||
import sys
|
||||
@@ -59,10 +60,18 @@ async def run_script(paths, script):
|
||||
return str(await tool.execute(command="sh probe.sh", timeout=5))
|
||||
|
||||
|
||||
def completed(result):
|
||||
# Keep output and exit-status assertions exact while checking the current
|
||||
# exec metadata envelope, including its variable wall-clock duration.
|
||||
match = re.fullmatch(r"(?:(.*)\n)?Exit code: (-?\d+)\nElapsed: \d+\.\ds", result, re.DOTALL)
|
||||
assert match, result
|
||||
return match.group(1) or "", int(match.group(2))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("target", ["workspace", "media", "ro", "rw"])
|
||||
async def test_native_allowed_reads(layout, target):
|
||||
result = await run_script(layout, f"cat {shlex.quote(str(layout[target] / 'sentinel'))}")
|
||||
assert result == "synthetic-data\n\nExit code: 0"
|
||||
assert completed(result) == ("synthetic-data", 0)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("target", ["config", "peer", "link"])
|
||||
@@ -77,7 +86,7 @@ async def test_native_outside_reads_denied(layout, target):
|
||||
async def test_native_explicit_writes_allowed(layout, target):
|
||||
path = layout[target] / "sentinel"
|
||||
result = await run_script(layout, f"printf changed > {shlex.quote(str(path))}")
|
||||
assert result == "\nExit code: 0"
|
||||
assert completed(result) == ("", 0)
|
||||
assert path.read_text() == "changed"
|
||||
|
||||
|
||||
@@ -97,14 +106,14 @@ async def test_native_scratch_and_home_stay_in_workspace(layout):
|
||||
layout, 'printf "%s\\n" "$HOME"; mktemp "$TMPDIR/probe.XXXXXX" && printf ok > /dev/null',
|
||||
)
|
||||
assert "STDERR" not in result
|
||||
assert result.endswith("Exit code: 0")
|
||||
assert completed(result)[1] == 0
|
||||
assert all(line.startswith(str(layout["workspace"])) for line in result.splitlines()[:2])
|
||||
|
||||
|
||||
async def test_native_system_git_starts(layout):
|
||||
result = await run_script(layout, "git --version")
|
||||
assert "git version " in result
|
||||
assert result.endswith("Exit code: 0")
|
||||
assert completed(result)[1] == 0
|
||||
|
||||
|
||||
async def test_native_launcher_cannot_be_shadowed_by_project_path(layout):
|
||||
@@ -116,7 +125,7 @@ async def test_native_launcher_cannot_be_shadowed_by_project_path(layout):
|
||||
working_dir=str(workspace), sandbox="seatbelt", path_prepend=str(workspace),
|
||||
)
|
||||
result = str(await tool.execute(command="printf real-sandbox", timeout=5))
|
||||
assert result == "real-sandbox\n\nExit code: 0"
|
||||
assert completed(result) == ("real-sandbox", 0)
|
||||
|
||||
|
||||
async def test_native_network_remains_available(layout):
|
||||
@@ -136,7 +145,7 @@ async def test_native_network_remains_available(layout):
|
||||
result = await run_script(
|
||||
layout, f"curl --noproxy '*' --max-time 2 -sS http://127.0.0.1:{server.server_port}",
|
||||
)
|
||||
assert result == "network-ok\n\nExit code: 0"
|
||||
assert completed(result) == ("network-ok", 0)
|
||||
finally:
|
||||
server.shutdown()
|
||||
thread.join(timeout=3)
|
||||
@@ -175,7 +184,7 @@ async def test_native_readonly_ancestor_keeps_other_children_writable(layout):
|
||||
"mv tree/sibling tree/renamed && rm tree/renamed/file && rmdir tree/renamed",
|
||||
)
|
||||
|
||||
assert result == "\nExit code: 0"
|
||||
assert completed(result) == ("", 0)
|
||||
assert protected.is_dir()
|
||||
assert not (workspace / "tree" / "renamed").exists()
|
||||
|
||||
@@ -190,7 +199,7 @@ async def test_native_rw_override_preserves_readonly_ancestor_policy(layout, ove
|
||||
layout["rw"] = {"root": protected, "parent": protected.parent, "child": writable}[override]
|
||||
|
||||
result = await run_script(layout, "printf writable > tree/readonly/cache/file")
|
||||
assert result == "\nExit code: 0"
|
||||
assert completed(result) == ("", 0)
|
||||
assert (writable / "file").read_text() == "writable"
|
||||
|
||||
result = await run_script(layout, "mv tree shifted")
|
||||
@@ -198,7 +207,7 @@ async def test_native_rw_override_preserves_readonly_ancestor_policy(layout, ove
|
||||
assert "Operation not permitted" in result
|
||||
assert protected.is_dir()
|
||||
else:
|
||||
assert result == "\nExit code: 0"
|
||||
assert completed(result) == ("", 0)
|
||||
assert (workspace / "shifted" / "readonly" / "cache" / "file").read_text() == "writable"
|
||||
|
||||
|
||||
@@ -217,7 +226,7 @@ async def test_native_failed_cwd_does_not_execute_shell_list(layout, cwd_kind, s
|
||||
))
|
||||
|
||||
assert "cd:" in result
|
||||
assert not result.endswith("Exit code: 0")
|
||||
assert completed(result)[1] != 0
|
||||
assert not (workspace / "first").exists()
|
||||
assert not (workspace / "second").exists()
|
||||
|
||||
@@ -233,7 +242,7 @@ async def test_native_nested_cwd_runs_complete_shell_list(layout):
|
||||
working_dir=str(cwd), timeout=5,
|
||||
))
|
||||
|
||||
assert result == "\nExit code: 0"
|
||||
assert completed(result) == ("", 0)
|
||||
assert (cwd / "first").read_text() == "first"
|
||||
assert (cwd / "second").read_text() == "second"
|
||||
assert not (workspace / "second").exists()
|
||||
@@ -253,11 +262,11 @@ async def test_native_rw_override_respects_volume_case_sensitivity(layout, overr
|
||||
layout["rw"] = alias if override == "root" else alias.parent
|
||||
|
||||
result = await run_script(layout, "printf writable > tree/readonly/other")
|
||||
assert result == "\nExit code: 0"
|
||||
assert completed(result) == ("", 0)
|
||||
result = await run_script(layout, "mv Tree shifted")
|
||||
|
||||
if same_directory:
|
||||
assert result == "\nExit code: 0"
|
||||
assert completed(result) == ("", 0)
|
||||
assert (workspace / "shifted" / "ReadOnly" / "other").read_text() == "writable"
|
||||
else:
|
||||
# On a case-sensitive volume the distinct RW directory must not remove
|
||||
|
||||
Reference in new issue
Block a user