Skip to content

test(cli): add comprehensive v2 CLI integration test suite - #304

Merged
frankbria merged 3 commits into
mainfrom
feature/v2-cli-integration-tests
Jan 28, 2026
Merged

test(cli): add comprehensive v2 CLI integration test suite#304
frankbria merged 3 commits into
mainfrom
feature/v2-cli-integration-tests

Conversation

@frankbria

@frankbria frankbria commented Jan 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds 57 integration tests across 15 test classes covering the full v2 CLI surface area
  • Tests run against real SQLite databases using CliRunner (no mocks)
  • Covers: init, status, summary, PRD (10 tests), tasks (8), work (6), batch (3), blocker (6), checkpoint (6), patch, schedule (3), templates (2), review, and a full golden-path E2E flow

Test plan

  • uv run pytest tests/cli/test_v2_cli_integration.py -v — 57 passed in ~24s
  • CI passes on this branch

Summary by CodeRabbit

  • Tests
    • Added a comprehensive v2 CLI integration test suite covering init, version, status, summary, PRD, tasks, work, batch, blocker, checkpoint, patch, schedule, templates, review, and related flows.
    • Includes AI-driven scenarios (LLM/agent paths), extensive end-to-end and golden-path validations, fixtures for temporary workspaces, and checks for outputs, exit codes, ID extraction, and filesystem side effects.

✏️ Tip: You can customize this high-level summary in your review settings.

57 tests across 15 classes covering the full CLI surface area:
init, status, summary, PRD, tasks, work, batch, blocker,
checkpoint, patch, schedule, templates, review, and golden-path E2E.

Uses CliRunner against real SQLite databases (no mocks).
@coderabbitai

coderabbitai Bot commented Jan 28, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a new end-to-end v2 CLI integration test module exercising Typer-based commands, AI-driven flows, and workspace fixtures; tests run against a real SQLite-backed workspace and include mock LLM provider scenarios and golden-path E2E coverage.

Changes

Cohort / File(s) Summary
V2 CLI Integration Tests
tests/cli/test_v2_cli_integration.py
New comprehensive test module (~884 lines) adding fixtures (temp_repo, workspace_path, prd_file, workspace_with_*) and many test classes covering version/init/status/summary/prd/tasks/work/batch/blocker/checkpoint/patch/schedule/templates/review flows. Includes AI-driven task generation and agent execution tests injecting a MockProvider, canned LLM responses, E2E golden-path scenarios, assertions on exit codes, outputs, regex-extracted IDs, and filesystem side effects (created files).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐰 I hopped through tests both crisp and neat,
I coaxed the CLI to dance and meet,
With mockwise prompts and files to write,
The golden path sprang into light,
A rabbit's cheer — the suite runs bright.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: adding a comprehensive v2 CLI integration test suite with 57 tests across 15 test classes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/v2-cli-integration-tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor

Code Review: v2 CLI Integration Test Suite

This is an excellent addition to the test suite! The comprehensive coverage across 57 integration tests provides strong validation of the CLI surface area. Here are my findings:


✅ Strengths

  1. Excellent Coverage: Tests 15 CLI command groups with a golden-path E2E flow
  2. Real-World Testing: Uses actual SQLite databases (no mocks) - much more reliable than mocks
  3. Well-Organized: Clear fixture chain (temp_repo → workspace_path → workspace_with_prd → ...)
  4. Convention Compliance: Properly marked with pytestmark = pytest.mark.v2 per repo guidelines
  5. Good Structure: Class-based organization with descriptive method names

🐛 Minor Issues to Fix

1. Unchecked CLI Invocations (Silent Failures)

Several tests invoke CLI commands without verifying the result, which could mask failures:

  • Line 342: test_stop() - runner.invoke(\["work", "start", ...\]) not checked
  • Line 362: test_status_shows_run() - same issue
  • Line 462: test_resolve() - runner.invoke(\["blocker", "answer", ...\]) not checked
  • Lines 500, 511, 522, 534 in TestCheckpointCommands

Recommendation: Add assertion checks or use assert ...exit_code == 0 to catch setup failures early.

2. Flaky ID Extraction Pattern

The regex pattern [0-9a-f]{8} used in multiple tests (lines 197, 432, 445, 459) could match unintended hex strings that aren't IDs.

Example (line 197):

ids = re.findall(r"[0-9a-f]{8,}", show_result.output)
if ids:
    # Uses first match, might not be actual PRD ID

Recommendation: Use a more specific pattern or extract IDs via the core API (as done in test_prd_versions).

3. Overly Permissive Exit Code Assertions

Some tests accept multiple exit codes without verifying expected behavior:

  • Line 203: assert result.exit_code in (0, 1) - prd delete could succeed or prompt for confirmation
  • Line 225: assert result.exit_code in (0, 1, 2) - prd update may not exist as a command

Recommendation: Check output content to understand why the command exited with a specific code.


💡 Suggestions for Enhancement

1. Add Parameterization for Similar Tests

Tests like test_list_empty and test_list_shows could use @pytest.mark.parametrize to reduce duplication:

@pytest.mark.parametrize("create_checkpoint,expected_in_output", [(False, ""), (True, "my-cp")])
def test_checkpoint_list(create_checkpoint, expected_in_output, workspace_path):
    if create_checkpoint:
        runner.invoke(app, ["checkpoint", "create", "my-cp", "-w", str(workspace_path)])
    result = runner.invoke(app, ["checkpoint", "list", "-w", str(workspace_path)])
    assert result.exit_code == 0
    if expected_in_output:
        assert expected_in_output in result.output

2. Strengthen Test Assertions

In test_tasks_delete_all (line 305), verify that tasks are actually deleted:

# After delete, verify no tasks remain
result = runner.invoke(app, ["tasks", "list", "-w", str(workspace_with_tasks)])
assert "0 tasks" in result.output or "no tasks" in result.output.lower()

3. Add Negative Test Cases

Consider adding tests for edge cases:

  • Invalid command arguments
  • Malformed PRD files
  • Workspace corruption scenarios
  • Concurrent command execution

4. Improve Test Documentation

Add docstrings to test methods explaining what they validate, especially for complex flows like the E2E test.


⚡ Performance Considerations

  • Runtime: ~24s for 57 tests is reasonable for integration tests
  • No Parallelization: Tests run sequentially by default; consider pytest-xdist for faster CI runs
  • Fixture Overhead: The fixture chain is efficient, but create_or_load_workspace is called multiple times per test

Recommendation: For large test suites, add:

# In pyproject.toml
[tool.pytest.ini_options]
addopts = "-nauto"  # Auto-detect CPU cores for parallel execution

🔒 Security Notes

  • Path Validation: Tests use tmp_path fixtures, so no security concerns with file paths
  • No Input Validation Tests: Consider adding tests for malicious inputs in PRD/content fields (though CLI entry point handles this)

📊 Coverage Assessment

Well-Covered (✅):

  • Init, Status, Summary, PRD (10 tests), Tasks (8), Work (6), Blocker (6), Checkpoint (6), Schedule (3), Templates (2)
  • Golden-path E2E flow

Could Be Strengthened (⚠️):

  • Error handling paths (many tests only check success cases)
  • prd update command (test may be for a non-existent command)
  • Edge cases (concurrent operations, corrupted state)

Summary

This is a solid foundation for CLI integration testing. The tests are well-structured and comprehensive. Addressing the unchecked CLI invocations and improving ID extraction reliability would make the suite more robust. The suggestions above are optional enhancements—this PR is ready to merge as-is after fixing the unchecked invocations.

Great work! 🎉

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@tests/cli/test_v2_cli_integration.py`:
- Around line 10-11: Remove the unused import Path from the top-level import
list (the line importing Path) in tests/cli/test_v2_cli_integration.py; the
tmp_path pytest fixture already yields pathlib.Path objects so delete the "Path"
import to resolve the F401 linter error and run the tests to confirm no other
references to Path remain.

Comment thread tests/cli/test_v2_cli_integration.py Outdated
@github-actions

Copy link
Copy Markdown
Contributor

Code review posted: #304 (comment)

New%20session%20-%202026-01-28T02%3A53%3A29.105Z
opencode session  |  github run

6 new tests exercise the LLM code paths through the CLI:
- Task generation via LLM (with valid JSON, overwrite, and fallback)
- Agent execution dry-run (planner + executor)
- Agent execution creating a file (verifies file on disk)
- Full AI golden path E2E (generate → plan → execute)

Uses MockProvider injected via monkeypatch on get_provider,
with canned plan JSON and file content responses.
@macroscopeapp

macroscopeapp Bot commented Jan 28, 2026

Copy link
Copy Markdown
Contributor

Add v2 CLI integration test suite to validate init, tasks, work, PRD, and AI agent flows using pytest and Typer CliRunner in tests/cli/test_v2_cli_integration.py

Introduce a pytest-based v2 CLI integration suite with fixtures for temp repos and workspaces, coverage for core commands and end-to-end flows, and AI-path tests driven by a mocked LLM provider in tests/cli/test_v2_cli_integration.py.

📍Where to Start

Start with the top-level test flow definitions in tests/cli/test_v2_cli_integration.py, then review the mock_llm fixture and _make_mock_provider helper used by AI-path tests.


Macroscope summarized 0350031.

@github-actions

Copy link
Copy Markdown
Contributor

Code Review: v2 CLI Integration Test Suite

Excellent addition to the test coverage! The comprehensive test suite provides strong validation of the CLI surface area. Here are my findings:


✅ Strengths

  1. Excellent Coverage: 15 CLI command groups with golden-path E2E flows
  2. Real-World Testing: Uses actual SQLite databases (no mocks) for Part 1 tests
  3. Well-Organized: Clear fixture chain and class-based organization
  4. AI Integration: Part 2 adds valuable LLM code path tests with MockProvider
  5. Convention Compliance: Properly marked with

🐛 Issues to Address

1. Remove Unused Import

Line 10 imports which is not used:

Fix: Remove this line (already flagged by CodeRabbit).

2. Unchecked CLI Invocations

Several tests invoke CLI commands without checking exit codes, which could mask failures:

  • Line 342: - not checked
  • Line 462: - not checked
  • Lines 500, 511, 522, 534: - setup calls not checked

Recommendation: Add assertions or verify results:

3. Fragile ID Extraction Pattern

The regex (lines 197, 432, 445, 459) could match unintended hex strings:

Recommendation: Use core API for reliable ID extraction (as done in ):

4. Overly Permissive Exit Code Assertions

Some tests accept multiple exit codes without verifying expected behavior:

  • Line 203: - unclear if succeeded or prompted
  • Line 225: - may not exist

Recommendation: Check output to understand why specific exit codes occur:


💡 Enhancement Suggestions

1. Add Parameterization for Similar Tests

Tests like and could use :

2. Strengthen Test Assertions

In (line 305), verify tasks are actually deleted:

3. Add Negative Test Cases

Consider edge cases:

  • Invalid command arguments
  • Malformed PRD files
  • Workspace corruption scenarios
  • Concurrent command execution

4. Add Test Method Docstrings

Document what each test validates, especially for complex flows like E2E tests.


⚡ Performance Notes

  • Runtime: ~24s for 57 tests is reasonable for integration tests

  • No Parallelization: Consider for faster CI:

  • Fixture Efficiency: The fixture chain is good, but is called multiple times per test


🔒 Security Assessment

✅ No concerns - tests use fixtures and mock provider with fake API key.


📊 Coverage Summary

Well-Covered (✅):

  • Init, Status, Summary, PRD (10 tests), Tasks (8), Work (6), Blocker (6), Checkpoint (6), Schedule (3), Templates (2)
  • AI integration tests (MockProvider)
  • Golden-path E2E flows

Could Be Strengthened (⚠️):

  • Error handling paths (many tests only check success)
  • Edge cases (concurrent ops, corrupted state, invalid inputs)
  • command (may not exist)

Summary

This is a solid foundation for CLI integration testing. The tests are well-structured and comprehensive. Addressing the unchecked CLI invocations and fixing the unused import would make the suite more robust. The enhancement suggestions are optional—this PR is close to merge-ready after addressing the critical issues.

Great work on the comprehensive coverage! 🎉

@github-actions

Copy link
Copy Markdown
Contributor

I've reviewed PR #304 and posted a comprehensive code review comment. The review covers:

Key findings:

  • ✅ Excellent test coverage with 15 CLI command groups and AI integration tests
  • 🐛 Critical issue: Unused Path import on line 10 that needs removal
  • 🐛 Unchecked CLI invocations: Several tests invoke commands without verifying exit codes, which could mask failures
  • 🐛 Fragile ID extraction: The regex [0-9a-f]{8} could match unintended strings

Recommendations include:

  • Fix the unused import
  • Add assertions for setup CLI commands in TestWorkCommands, TestBlockerCommands, and TestCheckpointCommands
  • Use core API for reliable ID extraction instead of regex patterns
  • Strengthen overly permissive exit code assertions

Optional enhancements:

  • Add parameterization for similar tests
  • Strengthen test assertions
  • Add negative test cases for edge scenarios
  • Consider pytest-xdist for faster CI runs

The test suite is well-structured and provides solid coverage. After addressing the critical issues (especially the unused import and unchecked invocations), this PR will be ready to merge.

Review comment posted: #304 (comment)

New%20session%20-%202026-01-28T02%3A57%3A11.906Z
opencode session  |  github run

@github-actions

Copy link
Copy Markdown
Contributor

Code Review: v2 CLI Integration Test Suite

This PR adds excellent comprehensive CLI integration coverage! The test suite is well-structured and aligns well with the v2 architecture. However, there's one critical issue that must be addressed before merging.


🔴 Critical Issue (Must Fix)

Unused Import Fails CI

Line 10: from pathlib import Path is imported but never used. This causes ruff check to fail with F401 error.

The tmp_path pytest fixture already yields pathlib.Path objects directly, so this import is unnecessary.

Fix: Remove line 10 entirely.


✅ Strengths

  1. Excellent Coverage: 57 tests across 15 CLI command groups + AI integration tests
  2. Real-World Testing: Uses actual SQLite databases (no mocks) for reliability
  3. Well-Organized: Clear fixture chain (temp_repoworkspace_pathworkspace_with_prd → ...)
  4. Convention Compliance: Properly marked with pytestmark = pytest.mark.v2 per repo guidelines
  5. AI Integration: Part 2 adds valuable MockProvider tests for LLM code paths

🐛 Minor Issues (Recommended to Address)

1. Unchecked CLI Invocations (Could Mask Failures)

Several tests invoke setup CLI commands without verifying results:

  • Line 342 (TestWorkCommands.test_stop): runner.invoke(["work", "start", ...]) not checked
  • Line 362 (test_status_shows_run): Same pattern
  • Line 462 (TestBlockerCommands.test_resolve): runner.invoke(["blocker", "answer", ...]) not checked
  • Lines 500, 511, 522, 534 (TestCheckpointCommands): Setup runner.invoke calls not checked

Impact: If a setup command fails silently, the actual test assertion might pass for the wrong reasons.

Recommendation: Add exit code checks or use the assertion pattern:

setup_result = runner.invoke(app, ["work", "start", tid, "-w", str(workspace_with_ready_tasks)])
assert setup_result.exit_code == 0, f"Setup failed: {setup_result.output}"

2. Fragile ID Extraction Pattern

Lines 197, 432, 445, 459: Using re.findall(r"[0-9a-f]{8,}", output) to extract IDs could match unintended hex strings that aren't actual IDs.

Example (line 197):

ids = re.findall(r"[0-9a-f]{8,}", show_result.output)
if ids:
    # Uses first match - might not be the PRD ID!

Recommendation: Use core API for reliable ID extraction (as done correctly in test_prd_versions):

ws = create_or_load_workspace(workspace_with_prd)
prd_record = prd.get_latest(ws)
assert prd_record is not None
# Use prd_record.id directly

3. Overly Permissive Exit Code Assertions

Some tests accept multiple exit codes without verifying expected behavior:

  • Line 203: assert result.exit_code in (0, 1) - Unclear if prd delete succeeded or prompted for confirmation
  • Line 225: assert result.exit_code in (0, 1, 2) - prd update may not exist as a command

Recommendation: Check output content to understand why specific exit codes occur:

assert result.exit_code == 0 or "confirm" in result.output.lower()

💡 Enhancement Suggestions (Optional)

1. Add Parameterization to Reduce Duplication

Tests like test_checkpoint_list_empty and test_checkpoint_list_shows_checkpoint could use @pytest.mark.parametrize:

@pytest.mark.parametrize("create_checkpoint,expected_in_output", [(False, ""), (True, "my-cp")])
def test_checkpoint_list(create_checkpoint, expected_in_output, workspace_path):
    if create_checkpoint:
        runner.invoke(app, ["checkpoint", "create", "my-cp", "-w", str(workspace_path)])
    result = runner.invoke(app, ["checkpoint", "list", "-w", str(workspace_path)])
    assert result.exit_code == 0
    if expected_in_output:
        assert expected_in_output in result.output

2. Strengthen Test Assertions

Line 305 (test_tasks_delete_all): Verify tasks are actually deleted:

result = runner.invoke(app, ["tasks", "list", "-w", str(workspace_with_tasks)])
assert "0 tasks" in result.output or "no tasks" in result.output.lower()

3. Add Negative Test Cases

Consider edge cases for robustness:

  • Invalid command arguments (e.g., non-existent task IDs with valid hex format)
  • Malformed PRD files
  • Workspace corruption scenarios
  • Concurrent command execution

4. Consider Test Parallelization

Current runtime (~24s for 57 tests) is reasonable, but could be faster with pytest-xdist:

[tool.pytest.ini_options]
addopts = "-nauto"  # Auto-detect CPU cores

📊 Coverage Summary

Well-Covered (✅):

  • Init, Status, Summary, PRD (10 tests), Tasks (8), Work (6), Blocker (6), Checkpoint (6), Schedule (3), Templates (2)
  • AI integration tests with MockProvider
  • Golden-path E2E flows

Could Be Strengthened (⚠️):

  • Error handling paths (many tests only check success cases)
  • prd update command (test may be for a non-existent command)
  • Edge cases (concurrent ops, corrupted state, invalid inputs)

🔒 Security Assessment

✅ No security concerns - tests use tmp_path fixtures safely and MockProvider with fake API keys.


Summary

This is a solid foundation for CLI integration testing. The tests are comprehensive, well-structured, and align with the v2 architecture.

Must fix before merge: Remove the unused Path import (line 10) to resolve the CI failure.

Recommended after that: Address the unchecked CLI invocations to prevent silent test failures.

The enhancement suggestions are optional - this PR provides excellent coverage as-is. Great work! 🎉

@github-actions

Copy link
Copy Markdown
Contributor

I've posted a comprehensive code review to PR #304. The review covers:

Key findings:

  • ✅ Excellent test coverage with 57 tests across 15 CLI command groups
  • 🔴 Critical issue: Unused Path import on line 10 that causes CI to fail
  • 🐛 Unchecked CLI invocations: Several setup commands don't verify exit codes
  • 🐛 Fragile ID extraction: Regex pattern could match unintended hex strings
  • 🐛 Overly permissive exit codes: Some tests accept multiple exit codes without verifying behavior

Recommendations:

  1. Must fix: Remove the unused Path import to resolve CI failure
  2. Recommended: Add assertions for setup CLI commands in TestWorkCommands, TestBlockerCommands, and TestCheckpointCommands
  3. Recommended: Use core API for reliable ID extraction instead of regex patterns
  4. Optional: Add parameterization, strengthen assertions, add negative test cases, consider pytest-xdist

Review posted: #304 (comment)

New%20session%20-%202026-01-28T03%3A00%3A10.438Z
opencode session  |  github run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant