Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions loopx/chat/coordination.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 2 additions & 5 deletions tests/architecture/test_posix_flag_portability.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \"<flag>\", 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 "
Expand Down
Loading