From aea1a453544b865127118b27a5a7a6014f45ad2b Mon Sep 17 00:00:00 2001 From: Yusuke-KOMIYAMA Date: Tue, 17 Nov 2026 11:22:37 +0900 Subject: [PATCH] =?UTF-8?q?fix(test):=20.venv=20=E3=81=AE=20Python=20?= =?UTF-8?q?=E3=81=A7=E6=B5=81=E3=81=97=E3=81=A6=E3=82=82=20test=5Fscan=20?= =?UTF-8?q?=E3=81=AE=E5=81=BD=E3=81=AE=20runner=20=E3=81=8C=20semgrep=20?= =?UTF-8?q?=E3=82=92=E8=AA=8D=E8=AD=98=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit リポジトリの .venv/bin/python で installer の試験を流すと、test_scan の 20 件が失敗し、1 件がエラーになっていた。 .venv/bin には semgrep があるが、PATH には無い。そのため scan._exe は semgrep をフルパス (…/.venv/bin/semgrep)で返す。一方、試験の偽の runner は argv[0] を裸の名前でしか照合しないので、 semgrep を知らない道具として rc 127 を返し、スキャンは「incomplete」(exit 51)になっていた。 CI とシステムの Python では semgrep が PATH にあるか無いかのどちらかなので、この問題は表に出なかった。 偽の runner は argv[0] をファイル名(basename)にそろえてから、応答と calls への記録をする。 本体の scan.py は変えない(フルパスで実行するのは install.sh の .venv の想定どおり)。 回帰試験: scan._exe がフルパスを返すようにして semgrep が ok になることを確かめる試験を足した。 修正を外すとこの試験は失敗する。 検証: システムの Python 3.15 で 789 件 OK(skip 14)。.venv の Python で 789 件 OK(skip 2)。 修正前の .venv の Python では、test_scan が 20 failures、1 error だった。 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BW1YQk71jLXY2FaSzMnnYJ --- installer/tests/test_scan.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/installer/tests/test_scan.py b/installer/tests/test_scan.py index 06e84ec..a54775d 100644 --- a/installer/tests/test_scan.py +++ b/installer/tests/test_scan.py @@ -49,6 +49,9 @@ def fake_runner(trivy_json=TRIVY_CLEAN, semgrep_json=SEMGREP_EMPTY, gitleaks_jso sbom_rc=0, trivy_fail_target=None, zap_rc=0, zap_out=None, probe=None): """Return a runner that answers canned output per tool and records argv in `calls`.""" def _run(argv): + # scan._exe gives the full path of a tool found next to the interpreter but not on PATH (semgrep in + # .venv/bin when the suite runs on .venv/bin/python); answer and record by the bare name. + argv = [Path(argv[0]).name, *argv[1:]] if argv else argv if calls is not None: calls.append(list(argv)) tool = argv[0] @@ -790,6 +793,20 @@ def test_semgrep_runs_all_four_spec_packs_with_error_flag(self): self.assertIn("--error", argv) self.assertIn("--json", argv) + def test_a_tool_resolved_to_a_full_path_is_still_faked(self): + # Running the suite on .venv/bin/python, where semgrep sits beside the interpreter but not on PATH, + # used to make 20 scan tests fail and 1 error: the fake runner did not know "/…/.venv/bin/semgrep". + calls = [] + real_exe = scan._exe + scan._exe = lambda name: f"/opt/grdm/.venv/bin/{name}" + try: + code, data, _ = self.run_scan(fake_runner(semgrep_json=SEMGREP_WARNING, semgrep_rc=1, calls=calls)) + finally: + scan._exe = real_exe + self.assertEqual(code, exit_codes.OK) + self.assertEqual([t["result"] for t in data["tools"] if t["name"] == "semgrep"], ["ok"]) + self.assertTrue(any(c[:2] == ["semgrep", "scan"] for c in calls)) + def test_trivy_enumerates_every_compose_image_plus_checkouts_plus_repo(self): self.write_compose({ "web": hardened("grdm-dev/web:abc123", ports=["127.0.0.1:5000:5000"], networks=["grdm", "grdm-edge"]),