From c068188a8e5c277f7bc8671557a7568864b57515 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Wed, 7 Jan 2026 12:47:58 -0600 Subject: [PATCH] tests: output store path even for success Useful when trying to double check the contents of a test directory even when the tests are passing. ie: stub a test and see the stuff you want to assert/validate. Signed-off-by: Austin Horstman --- tests/tests.py | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/tests/tests.py b/tests/tests.py index 7847cf9f3..ffc125557 100755 --- a/tests/tests.py +++ b/tests/tests.py @@ -92,6 +92,23 @@ class TestRunner: # Can happen if fzf is not found or the user cancels (non-zero exit) return [] + def _get_store_path(self, test: str, nix_args: list[str]) -> str | None: + """Retrieve the store path of a test.""" + try: + store_cmd = [ + "nix", "build", "--no-link", "--json", "--reference-lock-file", "flake.lock", + f"./tests#{test}", *nix_args + ] + result = _run_command(store_cmd, cwd=self.repo_root, check=False) + if result.returncode == 0: + import json + build_info = json.loads(result.stdout) + if build_info: + return build_info[0]["outputs"]["out"] + except Exception: + pass + return None + def run_tests(self, tests_to_run: list[str], nix_args: list[str]) -> bool: """Run the selected tests and report the outcome.""" if not tests_to_run: @@ -112,6 +129,11 @@ class TestRunner: # For this command, we want output to go directly to the terminal result = subprocess.run(cmd, check=True, cwd=self.repo_root, capture_output=True, text=True) print(f"{SUCCESS_EMOJI} Test passed: {test}") + + store_path = self._get_store_path(test, nix_args) + if store_path: + print(f"{INFO_EMOJI} Test directory available at: {store_path}/tested/", file=sys.stderr) + except subprocess.CalledProcessError as e: failed_tests.append(test) print(f"{FAILURE_EMOJI} Test failed: {test}", file=sys.stderr) @@ -138,20 +160,9 @@ class TestRunner: except Exception: print(f"{INFO_EMOJI} Build directory available at: {build_dir}", file=sys.stderr) - try: - store_cmd = [ - "nix", "build", "--no-link", "--json", "--reference-lock-file", "flake.lock", - f"./tests#{test}", *nix_args - ] - result = _run_command(store_cmd, cwd=self.repo_root, check=False) - if result.returncode == 0: - import json - build_info = json.loads(result.stdout) - if build_info: - store_path = build_info[0]["outputs"]["out"] - print(f"{INFO_EMOJI} Test directory available at: {store_path}/tested/", file=sys.stderr) - except Exception: - pass + store_path = self._get_store_path(test, nix_args) + if store_path: + print(f"{INFO_EMOJI} Test directory available at: {store_path}/tested/", file=sys.stderr) print("\n--- Summary ---") if not failed_tests: