diff --git a/tests/test_cli.py b/tests/test_cli.py index 83409f3..16a160a 100755 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -873,26 +873,49 @@ def test_command_count_does_not_crash(self): assert "conflicting option string" not in result.stderr def test_scan_with_format_long_does_not_crash(self): - """``codelens scan . --format json`` must not raise argparse error.""" + """``codelens scan --format json`` must not raise argparse error. + + Uses a tiny throwaway workspace (not ``.``) so the scan finishes + fast — this test only verifies the ``--format`` argparse path, it + does not need to scan a real codebase. + """ import subprocess - result = subprocess.run( - [sys.executable, os.path.join(SCRIPT_DIR, "codelens.py"), - "scan", ".", "--format", "json"], - capture_output=True, text=True, timeout=60, - ) + import shutil + ws = tempfile.mkdtemp() + try: + with open(os.path.join(ws, "trivial.py"), "w") as f: + f.write("x = 1\n") + result = subprocess.run( + [sys.executable, os.path.join(SCRIPT_DIR, "codelens.py"), + "scan", ws, "--format", "json"], + capture_output=True, text=True, timeout=60, + ) + finally: + shutil.rmtree(ws, ignore_errors=True) assert "argparse.ArgumentError" not in result.stderr, ( f"argparse error:\n{result.stderr[:500]}" ) assert "conflicting option string" not in result.stderr def test_scan_with_format_short_does_not_crash(self): - """``codelens scan . -f json`` must not raise argparse error.""" + """``codelens scan -f json`` must not raise argparse error. + + Uses a tiny throwaway workspace (not ``.``) so the scan finishes + fast — this test only verifies the ``-f`` argparse path. + """ import subprocess - result = subprocess.run( - [sys.executable, os.path.join(SCRIPT_DIR, "codelens.py"), - "scan", ".", "-f", "json"], - capture_output=True, text=True, timeout=60, - ) + import shutil + ws = tempfile.mkdtemp() + try: + with open(os.path.join(ws, "trivial.py"), "w") as f: + f.write("x = 1\n") + result = subprocess.run( + [sys.executable, os.path.join(SCRIPT_DIR, "codelens.py"), + "scan", ws, "-f", "json"], + capture_output=True, text=True, timeout=60, + ) + finally: + shutil.rmtree(ws, ignore_errors=True) assert "argparse.ArgumentError" not in result.stderr, ( f"argparse error:\n{result.stderr[:500]}" ) diff --git a/tests/test_hybrid_engine.py b/tests/test_hybrid_engine.py index 113160a..cbbd545 100755 --- a/tests/test_hybrid_engine.py +++ b/tests/test_hybrid_engine.py @@ -266,10 +266,10 @@ def test_deep_unsupported_command_sets_hint(self): # is the post-#199 entry point. search is NOT in the --deep # supported list. proc = subprocess.run( - [sys.executable, "scripts/codelens.py", + [sys.executable, os.path.join(SCRIPT_DIR, "codelens.py"), "search", "--mode", "symbol", "foo", ws, "--deep", "--format", "json"], capture_output=True, text=True, timeout=60, - env={**os.environ, "PYTHONPATH": "scripts"}, + env={**os.environ, "PYTHONPATH": SCRIPT_DIR}, ) # Should not crash, and should include the hint