From 76aefa23e1289efb7cdcc9813868d2a288040fa5 Mon Sep 17 00:00:00 2001 From: starmen1265 Date: Fri, 13 Mar 2026 23:43:06 +0800 Subject: [PATCH] test(04-05): add failing tests for CLI process subcommand - Test process --help shows usage - Test process calls Pipeline.run() - Test invalid URL returns error - Test --output-dir flag - Test --no-skip flag Co-Authored-By: Claude Opus 4.6 --- tests/test_cli/__init__.py | 1 + tests/test_cli/test_process_command.py | 145 +++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 tests/test_cli/__init__.py create mode 100644 tests/test_cli/test_process_command.py diff --git a/tests/test_cli/__init__.py b/tests/test_cli/__init__.py new file mode 100644 index 0000000..a09c1d8 --- /dev/null +++ b/tests/test_cli/__init__.py @@ -0,0 +1 @@ +"""CLI Tests - Tests for command-line interface""" diff --git a/tests/test_cli/test_process_command.py b/tests/test_cli/test_process_command.py new file mode 100644 index 0000000..66711a8 --- /dev/null +++ b/tests/test_cli/test_process_command.py @@ -0,0 +1,145 @@ +"""Tests for CLI 'process' subcommand + +Tests: +1. `kb-workflow process --help` shows usage +2. `kb-workflow process ` calls Pipeline.run() +3. Invalid URL returns appropriate error +4. --output-dir flag sets custom output directory +""" + +import pytest +import sys +from unittest.mock import patch, MagicMock, AsyncMock +from pathlib import Path + +# Add kb-workflow to path for imports +sys.path.insert(0, '/home/starmen1265/work/kb-skills/kb-workflow') + + +class TestProcessCommandHelp: + """Test 1: `kb-workflow process --help` shows usage""" + + def test_process_help_shows_usage(self, capsys): + """`kb-workflow process --help` shows usage information""" + import kb_workflow + + # Mock sys.argv + with patch.object(sys, 'argv', ['kb-workflow', 'process', '--help']): + with pytest.raises(SystemExit) as exc_info: + kb_workflow.main() + # --help exits with 0 + assert exc_info.value.code == 0 + + captured = capsys.readouterr() + # Should show process command in help + assert 'process' in captured.out.lower() or 'url' in captured.out.lower() + + +class TestProcessCommandCallsPipeline: + """Test 2: `kb-workflow process ` calls Pipeline.run()""" + + def test_process_url_calls_pipeline_run(self, capsys): + """`kb-workflow process ` calls Pipeline.run()""" + import kb_workflow + + with patch.object(kb_workflow, 'process_command') as mock_process: + mock_process.return_value = {"success": True, "content_dir": "/tmp/content"} + + with patch.object(sys, 'argv', ['kb-workflow', 'process', 'https://www.bilibili.com/video/BV1test']): + kb_workflow.main() + + # process_command should be called with the URL + mock_process.assert_called_once() + call_args = mock_process.call_args + assert 'https://www.bilibili.com/video/BV1test' in str(call_args) + + def test_process_url_with_output_dir(self, capsys): + """`kb-workflow process --output-dir /custom` passes output_dir""" + import kb_workflow + + with patch.object(kb_workflow, 'process_command') as mock_process: + mock_process.return_value = {"success": True, "content_dir": "/custom"} + + with patch.object(sys, 'argv', [ + 'kb-workflow', 'process', + 'https://www.bilibili.com/video/BV1test', + '--output-dir', '/custom/output' + ]): + kb_workflow.main() + + call_kwargs = mock_process.call_args[1] + assert call_kwargs.get('output_dir') == '/custom/output' + + +class TestProcessCommandInvalidUrl: + """Test 3: Invalid URL returns appropriate error""" + + def test_process_invalid_url_returns_error(self, capsys): + """`kb-workflow process ` returns appropriate error""" + import kb_workflow + + with patch.object(kb_workflow, 'process_command') as mock_process: + mock_process.return_value = { + "success": False, + "error": "Failed to parse URL: invalid-url" + } + + with patch.object(sys, 'argv', ['kb-workflow', 'process', 'invalid-url']): + kb_workflow.main() + + # process_command should be called + mock_process.assert_called_once() + + +class TestProcessCommandFlags: + """Test 4: --output-dir flag sets custom output directory""" + + def test_output_dir_flag_sets_custom_directory(self): + """--output-dir flag sets custom output directory""" + import kb_workflow + + with patch.object(kb_workflow, 'process_command') as mock_process: + mock_process.return_value = {"success": True} + + with patch.object(sys, 'argv', [ + 'kb-workflow', 'process', + 'https://www.bilibili.com/video/BV1test', + '-o', '/tmp/custom' + ]): + kb_workflow.main() + + call_kwargs = mock_process.call_args[1] + assert call_kwargs.get('output_dir') == '/tmp/custom' + + def test_skip_completed_default_true(self): + """skip_completed defaults to True""" + import kb_workflow + + with patch.object(kb_workflow, 'process_command') as mock_process: + mock_process.return_value = {"success": True} + + with patch.object(sys, 'argv', [ + 'kb-workflow', 'process', + 'https://www.bilibili.com/video/BV1test' + ]): + kb_workflow.main() + + call_kwargs = mock_process.call_args[1] + assert call_kwargs.get('skip_completed') is True + + def test_no_skip_flag_disables_skip_completed(self): + """--no-skip flag disables skip_completed""" + import kb_workflow + + with patch.object(kb_workflow, 'process_command') as mock_process: + mock_process.return_value = {"success": True} + + with patch.object(sys, 'argv', [ + 'kb-workflow', 'process', + 'https://www.bilibili.com/video/BV1test', + '--no-skip' + ]): + kb_workflow.main() + + call_kwargs = mock_process.call_args[1] + assert call_kwargs.get('skip_completed') is False