Download tests/test_session.py from tailot/codex-python: direct link, hf CLI and curl.
- Browser
- Download file 3.43 kB
-
https://huggingface.co/datasets/tailot/codex-python/resolve/c390013d616cbabeec9a91088de377c76e56e532/tests/test_session.py
- Command line
-
hf download hf://datasets/tailot/codex-python@c390013d616cbabeec9a91088de377c76e56e532/tests/test_session.py
-
curl -L -o test_session.py https://huggingface.co/datasets/tailot/codex-python/resolve/c390013d616cbabeec9a91088de377c76e56e532/tests/test_session.py
3.43 kB
| """Tests for PythonWorkspaceSession transactional editing, verification, and rollback.""" | |
| from __future__ import annotations | |
| from pathlib import Path | |
| from lingologos_python.session import PythonWorkspaceSession | |
| def test_verify_clean_workspace_reaches_verified_assurance_3(sample_pkg: Path) -> None: | |
| session = PythonWorkspaceSession(sample_pkg) | |
| res = session.verify("src/mathops.py") | |
| assert res.verdict == "VERIFIED" | |
| assert res.assurance == 3 | |
| assert res.committed is False | |
| def test_edit_file_commits_only_when_verified(sample_pkg: Path) -> None: | |
| session = PythonWorkspaceSession(sample_pkg) | |
| res = session.edit_file( | |
| "src/mathops.py", | |
| "return left + right", | |
| "return int(left) + int(right)", | |
| commit=True, | |
| ) | |
| assert res.verdict == "VERIFIED" | |
| assert res.assurance == 3 | |
| assert res.committed is True | |
| assert "return int(left) + int(right)" in (sample_pkg / "src" / "mathops.py").read_text( | |
| encoding="utf-8" | |
| ) | |
| def test_edit_file_does_not_touch_disk_when_tests_fail(sample_pkg: Path) -> None: | |
| session = PythonWorkspaceSession(sample_pkg) | |
| before = (sample_pkg / "src" / "mathops.py").read_text(encoding="utf-8") | |
| res = session.edit_file( | |
| "src/mathops.py", | |
| "return left + right", | |
| "return left - right", | |
| commit=True, | |
| ) | |
| after = (sample_pkg / "src" / "mathops.py").read_text(encoding="utf-8") | |
| assert res.verdict == "UNKNOWN" | |
| assert res.reason == "GATE_REJECTED" | |
| assert res.committed is False | |
| assert before == after | |
| def test_edit_file_refuses_protected_and_traversal_paths(sample_pkg: Path) -> None: | |
| (sample_pkg / ".env").write_text("KEY=1\n", encoding="utf-8") | |
| session = PythonWorkspaceSession(sample_pkg) | |
| env_res = session.edit_file(".env", "KEY=1", "KEY=2", commit=True) | |
| assert env_res.verdict == "UNKNOWN" | |
| assert env_res.reason == "PROTECTED_PATH" | |
| assert env_res.committed is False | |
| assert (sample_pkg / ".env").read_text(encoding="utf-8") == "KEY=1\n" | |
| esc_res = session.edit_file("../outside.py", "a = 1", "a = 2", commit=True) | |
| assert esc_res.verdict == "UNKNOWN" | |
| assert esc_res.reason in ("PROTECTED_PATH", "NOT_APPLIED") | |
| assert esc_res.committed is False | |
| def test_create_and_delete_file_transactions(sample_pkg: Path) -> None: | |
| session = PythonWorkspaceSession(sample_pkg) | |
| created = session.create_file( | |
| "src/helper.py", | |
| '"""Extra module."""\n\n\ndef square(x: int) -> int:\n return x * x\n', | |
| commit=True, | |
| ) | |
| assert created.verdict == "VERIFIED" | |
| assert created.committed is True | |
| assert (sample_pkg / "src" / "helper.py").is_file() | |
| deleted = session.delete_file("src/helper.py", commit=True) | |
| assert deleted.verdict == "VERIFIED" | |
| assert deleted.committed is True | |
| assert not (sample_pkg / "src" / "helper.py").exists() | |
| def test_retry_loop_stops_on_identical_failure_stall(sample_pkg: Path) -> None: | |
| session = PythonWorkspaceSession(sample_pkg) | |
| def repeated_bad_edit(attempt: int, last_result: object) -> tuple[str, str]: | |
| return ("return left + right", "return left - right") | |
| final, attempts = session.run_retry_loop("src/mathops.py", repeated_bad_edit, max_attempts=5) | |
| assert final.verdict == "UNKNOWN" | |
| assert len(attempts) == 2 | |
| assert any(c.get("role") == "adversary_loop" for c in final.dossier.get("checkers", [])) | |