diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 186e8acb..e24ac24b 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -113,10 +113,11 @@ loading the delivery [commands](../src/loopzero/cli.py), which implement the con at that head with the current commands and check settings digest. A settings change or an older receipt without the digest requires a fresh check. The digest covers execution and stage reuse settings without recording raw - environment values. It excludes only inherited `HEAVY_SLOT_GRANTED_CORES` - for local sandbox receipts. Explicit settings, delegated runner environments - and stage reuse keys still bind the grant. Waiters check for policy changes - on every poll. + environment values. For local sandbox receipts it omits inherited `PATH`, + `LANG`, `LC_ALL`, `TERM`, and `HEAVY_SLOT_GRANTED_CORES` so readiness can + run in a different host environment. Explicit settings, delegated runner + environments, and stage reuse keys still bind these values. Waiters check + for policy changes on every poll. Local readiness and hosted eligibility carry a review forward only across a first-parent chain of verified merges from the configured PR base. They reconstruct each merge in an isolated Git repository and compare its tree diff --git a/src/loopzero/sandbox.py b/src/loopzero/sandbox.py index 663784be..64ab10f1 100644 --- a/src/loopzero/sandbox.py +++ b/src/loopzero/sandbox.py @@ -254,9 +254,11 @@ def settings_fingerprint(config: Config, worktree: Path, *, base: str | None = N settings = _execution_settings(config, base) if config.check_runner and settings["runner_executable"] is None: return None - if not config.check_runner and "HEAVY_SLOT_GRANTED_CORES" not in config.env: - # The inherited local worker limit is transient. Stage reuse still binds it. - settings["environment"].pop("HEAVY_SLOT_GRANTED_CORES", None) + if not config.check_runner: + # Inherited host settings can differ at readiness. Stage reuse still binds them. + host_env = {"PATH", "LANG", "LC_ALL", "TERM", "HEAVY_SLOT_GRANTED_CORES"} + for name in host_env - dict(config.env).keys(): + settings["environment"].pop(name, None) payload = [settings, config.inputs] return hashlib.sha256(json.dumps(payload, sort_keys=True).encode()).hexdigest() diff --git a/tests/test_cli.py b/tests/test_cli.py index b016c7ff..0518f421 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -3125,26 +3125,29 @@ def test_ready_matches_effective_inherited_check_environment(capsys, monkeypatch assert code == 1 and "not ready: check receipt has an incompatible settings fingerprint." in out -@pytest.mark.parametrize("worker", ["legacy", "different-path", "matching"]) +@pytest.mark.parametrize("worker", ["legacy", "different-environment", "matching"]) def test_ready_checks_transferred_whole_job_receipt(wt, gh, capsys, head, tmp_path, monkeypatch, worker): + policy = WORKFLOW.replace( + '[checks]', '[checks]\nenv_allowlist = ["PATH", "LANG", "LC_ALL", "TERM", "HEAVY_SLOT_GRANTED_CORES"]') + publish_workflow(wt, policy.replace('[delivery]', '[checks.inputs]\n"*" = ["."]\n\n[delivery]')) arm_approved_ready_pr(gh, head, wt, readiness={"local_exit": None}, isDraft=False) with monkeypatch.context() as worker_env: - if worker == "different-path": + if worker == "different-environment": worker_env.setenv("PATH", str(tmp_path / "worker-bin"), prepend=":") + for name, value in {"LANG": "en_US.UTF-8", "LC_ALL": "en_US.UTF-8", + "TERM": "dumb", "HEAVY_SLOT_GRANTED_CORES": "2"}.items(): + worker_env.setenv(name, value) assert run(capsys, "check")[0] == 0 - receipt = wt / ".loopzero/checks.json" - payload = json.loads(receipt.read_bytes()) if worker == "legacy": - # Older producers serialize these results without a settings fingerprint. + receipt = wt / ".loopzero/checks.json" + payload = json.loads(receipt.read_bytes()) del payload["settings_sha256"] - # Whole-job transport preserves the producer's fields. - receipt.write_text(json.dumps(payload)) - assert run(capsys, "ready")[0] == (0 if worker == "matching" else 1) - - if worker != "matching": - assert run(capsys, "check")[0] == 0 - assert run(capsys, "ready")[0] == 0 + receipt.write_text(json.dumps(payload)) + assert run(capsys, "ready")[0] == int(worker == "legacy") + assert run(capsys, "check")[0] == 0 + assert all(bool(stage.reused_from) == (worker == "matching") for stage in cli._load_report(wt).results) + assert run(capsys, "ready")[0] == 0 def test_ready_ignores_forged_markers(wt: Path, gh: FakeGh, capsys, head) -> None: