Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Comment thread
eowca marked this conversation as resolved.
Resolved
`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
Expand Down
8 changes: 5 additions & 3 deletions src/loopzero/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Make the exempt host-variable set a named module constant

The set {"PATH", "LANG", "LC_ALL", "TERM", "HEAVY_SLOT_GRANTED_CORES"} is rebuilt on every call inside settings_fingerprint. The same names are repeated in docs/ARCHITECTURE.md and the test. A module-level constant next to SANDBOX_ENV, for example RECEIPT_PORTABLE_ENV = frozenset(...), would give one place to update and let the test import it. This avoids the code, docs and tests drifting apart. It's non-blocking.

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()

Expand Down
14 changes: 7 additions & 7 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3032,24 +3032,24 @@ 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"
payload = json.loads(receipt.read_bytes())
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

Expand Down
27 changes: 17 additions & 10 deletions tests/test_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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")
Expand Down