diff --git a/tests/architecture/posix_flag_ceilings.json b/tests/architecture/posix_flag_ceilings.json index 8a69273a3d..5871757f1a 100644 --- a/tests/architecture/posix_flag_ceilings.json +++ b/tests/architecture/posix_flag_ceilings.json @@ -2,7 +2,11 @@ "schema": "loopx_posix_flag_ceilings_v0", "baseline_commit": "b4216d8c79f7f31785cf3bb6845f6847fcf0a6a6", "note": "Per-file ceiling on bare `os.O_NOFOLLOW` / `os.O_DIRECTORY` / `os.O_NONBLOCK` references under loopx/. A ceiling is a maximum, not a target: the guard fails when a file exceeds it or a new file appears, and accepts a lower measurement, so retiring one of these sites needs no edit here. Lower or drop an entry whenever a file is fixed, so the ceiling does not describe an older tree than the code.", + "reasons": { + "loopx/chat/coordination.py": "Six bare flag references are protected by the capability refusal at line 85: the descriptor-relative open is refused when os.open is not in os.supports_dir_fd or any required flag attribute is missing. Unsupported hosts therefore degrade before evaluating these bare references." + }, "ceiling": { + "loopx/chat/coordination.py": 6, "loopx/cli_commands/quota_capture.py": 2, "loopx/control_plane/collaboration/result_files.py": 6, "loopx/control_plane/effect_runtime.py": 2, diff --git a/tests/architecture/test_posix_flag_portability.py b/tests/architecture/test_posix_flag_portability.py index 86a8da7427..febc4576c5 100644 --- a/tests/architecture/test_posix_flag_portability.py +++ b/tests/architecture/test_posix_flag_portability.py @@ -27,6 +27,8 @@ from pathlib import Path from typing import Any +import pytest + REPO_ROOT = Path(__file__).resolve().parents[2] LOOPX_ROOT = REPO_ROOT / "loopx" CEILINGS_FIXTURE = Path(__file__).with_name("posix_flag_ceilings.json") @@ -103,7 +105,10 @@ def test_no_module_exceeds_its_bare_posix_flag_ceiling() -> None: 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()}, + { + path: [f"{path}:{line}: {what}" for line, what in detail["observed"]] + for path, detail in exceeded.items() + }, indent=2, ) + ". Read the flag with `getattr(os, \"\", 0)` the way the peer, completion " @@ -113,6 +118,42 @@ def test_no_module_exceeds_its_bare_posix_flag_ceiling() -> None: ) +def test_ceiling_failure_reports_offending_path_and_use_site( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + """A synthetic violation reports use sites rather than crashing its formatter.""" + loopx_root = tmp_path / "loopx" + loopx_root.mkdir() + (loopx_root / "offender.py").write_text( + "import os\nfirst = os.O_NOFOLLOW\nsecond = os.O_DIRECTORY\n", + encoding="utf-8", + ) + fixture = tmp_path / "posix_flag_ceilings.json" + fixture.write_text( + json.dumps( + { + "schema": CEILINGS_SCHEMA, + "baseline_commit": "a" * 40, + "ceiling": {"loopx/offender.py": 1}, + } + ), + encoding="utf-8", + ) + monkeypatch.setitem(globals(), "REPO_ROOT", tmp_path) + monkeypatch.setitem(globals(), "LOOPX_ROOT", loopx_root) + monkeypatch.setitem(globals(), "CEILINGS_FIXTURE", fixture) + + with pytest.raises(AssertionError) as failure: + test_no_module_exceeds_its_bare_posix_flag_ceiling() + + message = str(failure.value) + assert "bare POSIX-only os flags grew" in message + assert "loopx/offender.py:2: os.O_NOFOLLOW" in message + assert "loopx/offender.py:3: os.O_DIRECTORY" in message + assert 'Read the flag with `getattr(os, "", 0)`' in message + assert "Raising a ceiling in posix_flag_ceilings.json needs a recorded reason." in message + + def test_fixed_readers_keep_no_bare_posix_flag() -> None: """The readers whose fallback this guard protects stay at zero.""" observed = observed_ceiling()