diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 49620cba..f8afff13 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -110,10 +110,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 6f725e28..731604d8 100644 --- a/src/loopzero/sandbox.py +++ b/src/loopzero/sandbox.py @@ -253,9 +253,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 5c136d5d..435939fa 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -3032,12 +3032,14 @@ 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): 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"}.items(): + worker_env.setenv(name, value) assert run(capsys, "check")[0] == 0 receipt = wt / ".loopzero/checks.json" @@ -3045,11 +3047,9 @@ def test_ready_checks_transferred_whole_job_receipt(wt, gh, capsys, head, tmp_pa if worker == "legacy": # Older producers serialize these results without a settings fingerprint. 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": + receipt.write_text(json.dumps(payload)) + assert run(capsys, "ready")[0] == int(worker == "legacy") + if worker == "legacy": assert run(capsys, "check")[0] == 0 assert run(capsys, "ready")[0] == 0 diff --git a/tests/test_sandbox.py b/tests/test_sandbox.py index 674e4d8a..39910fd3 100644 --- a/tests/test_sandbox.py +++ b/tests/test_sandbox.py @@ -749,23 +749,25 @@ def cache(config, *, clean=False, verify_reuse=False): @pytest.mark.parametrize('change', ['other', 'input', 'shared', 'command', 'network', 'environment', 'version', 'failed', 'boolean_exit_code', 'dirty_receipt', 'keyless', - 'dirty_tree', 'legacy', 'grant']) -def test_declared_input_reuse(git_repo, bwrap_log, monkeypatch, fetched_base, change): + 'dirty_tree', 'legacy', 'grant', 'host_environment']) +def test_declared_input_reuse(git_repo, bwrap_log, monkeypatch, fetched_base, change, cache_check): cfg = make_config(checks=('echo one', 'echo two'), inputs={'echo one': ('*.md',), 'echo two': ('*.md',), '*': ('shared',)}) - if change == 'grant': - cfg = replace(cfg, env_allowlist=(*cfg.env_allowlist, "HEAVY_SLOT_GRANTED_CORES")) - monkeypatch.setenv("HEAVY_SLOT_GRANTED_CORES", "2") + original_path = os.environ["PATH"] + host_env = {"HEAVY_SLOT_GRANTED_CORES": "2"} + if change == 'host_environment': + host_env.update(PATH="/opt/tools:" + original_path, LANG="en_US.UTF-8", LC_ALL="en_US.UTF-8", TERM="dumb") + if change in {'grant', 'host_environment'}: + cfg = replace(cfg, env_allowlist=tuple(dict.fromkeys((*cfg.env_allowlist, *host_env)))) + for key, value in host_env.items(): + monkeypatch.setenv(key, value) for inputs in ({}, {'*': ()}, {'*': ('uv.lock',)}): assert sandbox._input_key(replace(cfg, inputs=inputs), git_repo, 'unlisted', fetched_base) is None whole = replace(cfg, inputs={'*': ('.',)}) key = sandbox._input_key(whole, git_repo, 'unlisted', fetched_base) assert key is not None - _save_report(git_repo, sandbox.run_checks(cfg, git_repo)) + cache_check(cfg) receipt = git_repo / '.loopzero/checks.json' - git(git_repo, 'config', 'core.excludesFile', str(git_repo / '.git/info/exclude')) - with (git_repo / '.git/info/exclude').open('a') as stream: - stream.write('\n.loopzero/\n') if change in {'other', 'input', 'shared', 'dirty_tree'}: path = 'README.md' if change in {'input', 'dirty_tree'} else 'src.py' if change == 'other' else change (git_repo / path).write_text('new content') @@ -780,7 +782,12 @@ def test_declared_input_reuse(git_repo, bwrap_log, monkeypatch, fetched_base, ch elif change == 'environment': monkeypatch.setenv('LZ_KEEP', 'changed') assert _current_check_report(git_repo, cfg, fetched_base) is None - elif change == 'grant': + elif change in {'grant', 'host_environment'}: + for key in host_env.keys() - {"PATH", "LANG", "HEAVY_SLOT_GRANTED_CORES"}: + monkeypatch.delenv(key) + if change == 'host_environment': + monkeypatch.setenv("PATH", original_path) + monkeypatch.setenv("LANG", "C") monkeypatch.setenv("HEAVY_SLOT_GRANTED_CORES", "4") assert _current_check_report(git_repo, cfg, fetched_base) is not None monkeypatch.delenv("HEAVY_SLOT_GRANTED_CORES")