Skip to content

Commit f11725b

Browse files
authored
Merge pull request #550 from escoffier-labs/fix/545-python310-regression
fix(tests): keep sweep import probe portable on Python 3.10
2 parents 6f2d467 + e46de2e commit f11725b

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

tests/test_repos_sweep_health_cmd.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,31 +209,37 @@ def test_repos_sweep_failed_repo_does_not_block_other_repo(tmp_path, capsys):
209209
assert sweep["failed_count"] == 1
210210

211211

212-
def test_repos_sweep_injects_src_pythonpath_for_built_in_commands(tmp_path, monkeypatch, capsys):
212+
def test_repos_sweep_injects_src_pythonpath_so_brigade_resolves_under_no_site_packages(tmp_path, monkeypatch, capsys):
213213
# Regression for issue #542: _run_sweep_command must prepend src/ (parents[2]),
214-
# not src/brigade (parents[1]), so a built-in `python -m brigade ...` command
215-
# imports the package from the injected PYTHONPATH alone. `-S` disables
216-
# site-packages so the subprocess can only resolve `brigade` via PYTHONPATH.
214+
# not src/brigade (parents[1]), so a subprocess launched with site-packages
215+
# disabled can resolve the `brigade` package from the injected PYTHONPATH alone.
216+
# This proves package discovery without booting the full Brigade CLI under
217+
# `python -S`, which is what regressed Python 3.10 CI in PR #545: `find_spec`
218+
# locates the package on sys.path without executing its __init__, so the
219+
# subprocess exits nonzero only when the spec is missing.
217220
repo = tmp_path / "repo-alpha"
218221
_init_repo(repo)
219222
_seed_workspace(tmp_path, repo)
223+
discovery_check = (
224+
"import importlib.util, sys; sys.exit(0 if importlib.util.find_spec('brigade') is not None else 1)"
225+
)
220226
monkeypatch.setattr(
221227
repos_cmd,
222228
"_sweep_commands",
223229
lambda: [
224230
repos_cmd.SweepCommand(
225-
"work-brief-no-site",
226-
[sys.executable, "-S", "-m", "brigade", "work", "brief", "--json"],
231+
"brigade-discovery-no-site",
232+
[sys.executable, "-S", "-c", discovery_check],
227233
),
228234
],
229235
)
230236

231237
assert repos_cmd.sweep_run(target=tmp_path, repo_ids=["alpha"], json_output=True) == 0
232238
sweep = json.loads(capsys.readouterr().out)
233239
commands = {command["label"]: command for command in sweep["repos"][0]["commands"]}
234-
assert commands["work-brief-no-site"]["status"] == "completed"
235-
assert commands["work-brief-no-site"]["exit_code"] == 0
236-
assert "No module named brigade" not in commands["work-brief-no-site"]["stderr_summary"]
240+
assert commands["brigade-discovery-no-site"]["status"] == "completed"
241+
assert commands["brigade-discovery-no-site"]["exit_code"] == 0
242+
assert "No module named brigade" not in commands["brigade-discovery-no-site"]["stderr_summary"]
237243

238244

239245
def test_repos_sweep_records_nonzero_and_timeout_commands(tmp_path, monkeypatch, capsys):

0 commit comments

Comments
 (0)