|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import json |
| 4 | +import os |
4 | 5 | import runpy |
5 | 6 | import re |
6 | 7 | import shlex |
| 8 | +import shutil |
| 9 | +import subprocess |
7 | 10 | import sys |
8 | 11 | from pathlib import Path |
9 | 12 | from types import SimpleNamespace |
|
21 | 24 | ) |
22 | 25 |
|
23 | 26 |
|
| 27 | +def test_runner_imports_frozen_support_with_an_older_checkout(tmp_path: Path) -> None: |
| 28 | + workload = tmp_path / "workload" |
| 29 | + workload.mkdir() |
| 30 | + runner = workload / RUNNER.name |
| 31 | + shutil.copyfile(RUNNER, runner) |
| 32 | + shutil.copyfile(cli_output_fixture.__file__, workload / "cli_output_fixture.py") |
| 33 | + |
| 34 | + historical = tmp_path / "historical" |
| 35 | + legacy_tests = historical / "tests" / "control_plane" |
| 36 | + legacy_tests.mkdir(parents=True) |
| 37 | + for package in (legacy_tests, legacy_tests.parent): |
| 38 | + (package / "__init__.py").touch() |
| 39 | + (legacy_tests / "cli_output_fixture.py").write_text( |
| 40 | + "# Older checkout with no current observation helper.\n", encoding="utf-8" |
| 41 | + ) |
| 42 | + probe_source = workload / "probe.py" |
| 43 | + probe_source.write_text( |
| 44 | + "from pathlib import Path\n" |
| 45 | + "from tests.control_plane.cli_output_fixture import measure_cli_context_for_oracle\n" |
| 46 | + "assert Path(measure_cli_context_for_oracle.__code__.co_filename) == " |
| 47 | + "Path(__file__).with_name('cli_output_fixture.py')\n" |
| 48 | + "print('frozen fixture support loaded')\n" |
| 49 | + "raise SystemExit(0)\n", |
| 50 | + encoding="utf-8", |
| 51 | + ) |
| 52 | + |
| 53 | + result = subprocess.run( |
| 54 | + [ |
| 55 | + sys.executable, str(runner), |
| 56 | + "--test-source", str(probe_source), |
| 57 | + "--semantics-source", str(workload / "unused_semantics.py"), |
| 58 | + "--fixture-root", str(workload / "unused_fixture"), |
| 59 | + "--receipt", str(workload / "unused_receipt.json"), |
| 60 | + ], |
| 61 | + cwd=workload, |
| 62 | + env={ |
| 63 | + **os.environ, |
| 64 | + "PYTHONPATH": os.pathsep.join((str(historical), str(RUNNER.parents[2]))), |
| 65 | + "LOOPX_USAGE_PING": "0", |
| 66 | + }, |
| 67 | + capture_output=True, text=True, encoding="utf-8", timeout=30, check=False, |
| 68 | + ) |
| 69 | + assert result.returncode == 0, result.stderr |
| 70 | + assert result.stdout.strip() == "frozen fixture support loaded" |
| 71 | + |
| 72 | + |
24 | 73 | @pytest.fixture |
25 | 74 | def crowded_turn_probe(monkeypatch: pytest.MonkeyPatch): |
26 | 75 | commands = probe._surface_commands |
|
0 commit comments