diff --git a/loopx/chat/coordination.py b/loopx/chat/coordination.py index 6f3399b920..f6f57f06eb 100644 --- a/loopx/chat/coordination.py +++ b/loopx/chat/coordination.py @@ -82,20 +82,29 @@ def _workspace_file(workspace: Path, ref: str, *, required: bool) -> str | None: opens keep a replaced parent from redirecting a source read outside the original workspace; source digests are host observations, not verdicts. """ - if os.open not in os.supports_dir_fd or not all(hasattr(os, flag) for flag in ("O_DIRECTORY", "O_NOFOLLOW", "O_NONBLOCK")): + directory_only = getattr(os, "O_DIRECTORY", None) + no_follow = getattr(os, "O_NOFOLLOW", None) + nonblock = getattr(os, "O_NONBLOCK", None) + if ( + os.open not in os.supports_dir_fd + or directory_only is None + or no_follow is None + or nonblock is None + ): raise ValueError("this host cannot safely inspect workspace checker sources") if (not isinstance(ref, str) or not ref or "\\" in ref or "\0" in ref or ref.startswith("/") or any(part in {"", ".", ".."} for part in ref.split("/"))): raise ValueError("checker files must remain relative to the original workspace") descriptors = [] try: - parent = os.open(workspace, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW) + directory_flags = os.O_RDONLY | directory_only | no_follow + parent = os.open(workspace, directory_flags) descriptors.append(parent) parts = ref.split("/") for part in parts[:-1]: - parent = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=parent) + parent = os.open(part, directory_flags, dir_fd=parent) descriptors.append(parent) - source = os.open(parts[-1], os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=parent) + source = os.open(parts[-1], os.O_RDONLY | no_follow | nonblock, dir_fd=parent) descriptors.append(source) if not stat.S_ISREG(os.fstat(source).st_mode): raise ValueError("checker sources and present artifacts must be regular files") diff --git a/tests/architecture/test_posix_flag_portability.py b/tests/architecture/test_posix_flag_portability.py index 86a8da7427..7b42b11b61 100644 --- a/tests/architecture/test_posix_flag_portability.py +++ b/tests/architecture/test_posix_flag_portability.py @@ -96,16 +96,13 @@ def test_no_module_exceeds_its_bare_posix_flag_ceiling() -> None: observed = observed_ceiling() exceeded = { - path: {"ceiling": ceiling.get(path, 0), "observed": uses} + path: [f"{line}: {what}" for line, what in uses] for path, uses in observed.items() if len(uses) > ceiling.get(path, 0) } assert not exceeded, ( "bare POSIX-only os flags grew: " - + json.dumps( - {path: [f"{line}: {what}" for line, what in uses] for path, uses in exceeded.items()}, - indent=2, - ) + + json.dumps(exceeded, indent=2) + ". Read the flag with `getattr(os, \"\", 0)` the way the peer, completion " "and decision-capture readers do, so a host without it refuses or degrades on its " "own terms instead of raising AttributeError first. Raising a ceiling in "