"CLI-Anything: Making ALL Software Agent-Native" -- CLI-Hub: https://clianything.cc/
Python
test: add real unit and e2e tests mocking subprocess for intelwatch wrapper
Recognity59ffac6659b4
diff --git a/intelwatch/agent-harness/cli_anything/intelwatch/tests/test_core.py b/intelwatch/agent-harness/cli_anything/intelwatch/tests/test_core.pyindex 837d1c6b6..90e1d62e3 100644--- a/intelwatch/agent-harness/cli_anything/intelwatch/tests/test_core.py+++ b/intelwatch/agent-harness/cli_anything/intelwatch/tests/test_core.py@@ -1,3 +1,52 @@-def test_basic_import():- import cli_anything.intelwatch.intelwatch_cli- assert True+import sys+import subprocess+from unittest.mock import patch+from click.testing import CliRunner+import cli_anything.intelwatch.intelwatch_cli as intelwatch_cli+import unittest++class TestIntelwatchCli(unittest.TestCase):+ def test_argument_forwarding(self):+ """Test that arguments are correctly forwarded to subprocess.call."""+ runner = CliRunner()++ with patch('cli_anything.intelwatch.intelwatch_cli.subprocess.call') as mock_call, \+ patch('cli_anything.intelwatch.intelwatch_cli.sys.exit') as mock_exit:++ mock_call.return_value = 0++ # Use standalone_mode=False to avoid click's internal sys.exit() catching+ result = runner.invoke(intelwatch_cli.main, ['--query', 'recognity', '--format', 'json'], standalone_mode=False)++ mock_call.assert_called_once_with(['npx', 'intelwatch', '--query', 'recognity', '--format', 'json'])+ mock_exit.assert_called_once_with(0)++ def test_exit_code_propagation(self):+ """Test that non-zero exit codes are correctly propagated."""+ runner = CliRunner()++ with patch('cli_anything.intelwatch.intelwatch_cli.subprocess.call') as mock_call, \+ patch('cli_anything.intelwatch.intelwatch_cli.sys.exit') as mock_exit:++ mock_call.return_value = 2++ runner.invoke(intelwatch_cli.main, ['invalid-command'], standalone_mode=False)++ mock_exit.assert_called_once_with(2)++ def test_npx_not_found(self):+ """Test behavior when npx is not installed (FileNotFoundError)."""+ runner = CliRunner()++ with patch('cli_anything.intelwatch.intelwatch_cli.subprocess.call') as mock_call, \+ patch('cli_anything.intelwatch.intelwatch_cli.sys.exit') as mock_exit:++ mock_call.side_effect = FileNotFoundError()++ result = runner.invoke(intelwatch_cli.main, [], standalone_mode=False)++ self.assertIn("Error: 'npx' command not found", result.output)+ mock_exit.assert_called_once_with(1)++if __name__ == '__main__':+ unittest.main()diff --git a/intelwatch/agent-harness/cli_anything/intelwatch/tests/test_full_e2e.py b/intelwatch/agent-harness/cli_anything/intelwatch/tests/test_full_e2e.pyindex 273f32a50..a7b0ee53c 100644--- a/intelwatch/agent-harness/cli_anything/intelwatch/tests/test_full_e2e.py+++ b/intelwatch/agent-harness/cli_anything/intelwatch/tests/test_full_e2e.py@@ -1,3 +1,31 @@-def test_e2e_mock():- # E2E test placeholder since Intelwatch relies on network access via npx- assert True+import subprocess+import sys+import unittest+from unittest.mock import patch+from click.testing import CliRunner+import cli_anything.intelwatch.intelwatch_cli as intelwatch_cli++class TestE2E(unittest.TestCase):+ def test_e2e_harness(self):+ """E2E test simulation.++ This simulates an end-to-end run without actually hitting the network+ or requiring npx installed in the CI environment.+ """+ runner = CliRunner()++ with patch('cli_anything.intelwatch.intelwatch_cli.subprocess.call') as mock_call, \+ patch('cli_anything.intelwatch.intelwatch_cli.sys.exit') as mock_exit:++ # Simulate a successful call+ mock_call.return_value = 0++ # Run a simulated query+ result = runner.invoke(intelwatch_cli.main, ['--domain', 'recognity.fr', '--format', 'json'], standalone_mode=False)++ # Verify the integration points+ mock_call.assert_called_once_with(['npx', 'intelwatch', '--domain', 'recognity.fr', '--format', 'json'])+ mock_exit.assert_called_once_with(0)++if __name__ == '__main__':+ unittest.main()