Skip to content
Merged
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
2 changes: 1 addition & 1 deletion hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(self, version, build_data):
if not (root / ".git").exists():
return

tracked = subprocess.check_output(["git", "ls-files", "-z"], cwd=root)
tracked = subprocess.check_output(["git", "ls-files", "-z"], cwd=root, timeout=60)
Comment thread
eowca marked this conversation as resolved.
Resolved

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: Duplicated 60 s literal instead of a named budget

The task asks for the existing 60-second Git budget (GIT_TIMEOUT in src/loopzero/cli.py:34 and src/loopzero/sandbox.py:29). These standalone entry points can't reasonably import loopzero, so copying the value is understandable. However, hatch_build.py:16 and scripts/check_architecture_docs.py:27 each use a bare 60. A module-level GIT_TIMEOUT = 60 in each file would make the shared budget easy to find, and tests could patch it (see the testing finding).

self.build_config.set_exclude_all()
build_data["force_include"].update(
(name, name)
Expand Down
4 changes: 2 additions & 2 deletions scripts/check_architecture_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

def git(root, *args, text=True):
return subprocess.run(["git", *args], cwd=root, check=True,
capture_output=True, text=text).stdout
capture_output=True, text=text, timeout=60).stdout


def interface(text, names):
Expand Down Expand Up @@ -115,7 +115,7 @@ def main():
else:
base = args.base or git(root, "merge-base", "HEAD", "origin/main").strip()
errors = check(root, base)
except (OSError, ValueError, SyntaxError, subprocess.CalledProcessError) as exc:
except (OSError, ValueError, SyntaxError, subprocess.SubprocessError) as exc:
print(f"architecture docs: FAIL ({exc})", file=sys.stderr)
return 1
if errors:
Expand Down
22 changes: 22 additions & 0 deletions tests/test_architecture_docs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Exercise the documentation check as a contributor/CI subprocess in real Git."""
import os
import runpy
import subprocess
import sys
from pathlib import Path
from types import SimpleNamespace

import pytest

Expand Down Expand Up @@ -99,6 +101,26 @@ def test_missing_base_fails_closed(git_repo):
assert run(git_repo, "not-a-revision").returncode == 1


@pytest.mark.parametrize("entry", ["architecture", "sdist"])

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: One parametrized test covers two unrelated entry points through an if/else

Each entry value runs a completely different body, and the sdist hook test sits in the architecture-docs test module. Two plain test functions, test_architecture_git_timeout and test_sdist_hook_git_timeout, would be easier to read and would make failures clearer. They could share the stalled_git fake as a fixture. This is only a structural cleanup.

def test_direct_git_timeout(tmp_path, monkeypatch, capsys, entry):
def stalled_git(argv, *, timeout, **kwargs):

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: Test replaces subprocess.run, so it never runs a stalled Git shim

The acceptance criteria ask for "a stalled local Git shim" that triggers the timeout. This test instead monkeypatches subprocess.run to raise TimeoutExpired right away. It does check that timeout=60 reaches subprocess.run, including through check_output in hatch_build.py:16, and that main() and the hook surface the timeout on their error paths. It never runs a real process, though, so it would not catch a Git call that skips subprocess.run (for example Popen or os.system) or a timeout that fails to kill the child. Smallest fix: keep the mock-based assertions and add one case that puts a git script running sleep first on PATH, then patches the 60-second constant or wraps subprocess.run to pass a short timeout. If the mock is the intended level of coverage, reword the acceptance item to match.

assert timeout == 60
raise subprocess.TimeoutExpired(argv, timeout)

monkeypatch.setattr(subprocess, "run", stalled_git)
if entry == "architecture":
monkeypatch.setattr(sys, "argv", [str(SCRIPT), "--links-only"])
assert runpy.run_path(str(SCRIPT))["main"]() == 1
assert "timed out" in capsys.readouterr().err
else:
monkeypatch.setitem(sys.modules, "hatchling.builders.hooks.plugin.interface",
SimpleNamespace(BuildHookInterface=object))
hook = runpy.run_path(str(SCRIPT.parents[1] / "hatch_build.py"))["TrackedSdistFiles"]
(tmp_path / ".git").mkdir()
with pytest.raises(subprocess.TimeoutExpired):
hook.initialize(SimpleNamespace(root=tmp_path), "", {})


def test_tach_enforces_module_boundaries(tmp_path):
import shutil

Expand Down
Loading