Skip to content

test: Add integration tests for task import functions (beads, GitHub Issues) #152

@frankbria

Description

@frankbria

Summary

The task import functions in lib/task_sources.sh lack integration tests for the actual import logic. Current tests only verify detection (whether tools are available) but skip testing the parsing and import functionality.

Current Test Gap Analysis

Function Current Tests Gap
fetch_beads_tasks() 0 No tests - JSON parsing, text fallback, status filtering untested
fetch_github_tasks() 0 No tests - JSON parsing, label filtering untested
get_beads_count() 1 Only tests unavailable case, not actual counting
get_github_issue_count() 1 Only tests unavailable case, not actual counting
import_tasks_from_sources() 1 Only tests PRD source, not beads/github sources

Context

PR #150 fixed several bugs in fetch_beads_tasks():

  • Fixed bd list arguments (non-existent --filter flag)
  • Fixed jq != bash escaping issue
  • Added status-respecting fallback for text parsing
  • Added jq guards for missing id/title fields

These fixes were only manually tested. Integration tests would prevent regressions.

Proposed Tests

1. Beads Import Tests (fetch_beads_tasks)

# Test JSON parsing with mocked bd command
@test "fetch_beads_tasks parses JSON output correctly" {
    # Mock bd to return JSON
    bd() { echo '[{"id":"proj-001","title":"Fix bug","status":"open"}]'; }
    export -f bd
    ...
}

# Test text fallback parsing
@test "fetch_beads_tasks falls back to text parsing when JSON fails" {
    # Mock bd to return text format
    bd() { echo "○ proj-001 [● P2] [task] - Fix authentication bug"; }
    ...
}

# Test status filtering
@test "fetch_beads_tasks respects filterStatus parameter" { ... }

# Test empty results
@test "fetch_beads_tasks handles empty JSON array" { ... }

# Test malformed JSON fallback
@test "fetch_beads_tasks falls back to text on malformed JSON" { ... }

# Test missing fields (jq guards)
@test "fetch_beads_tasks filters entries with missing id" { ... }
@test "fetch_beads_tasks filters entries with missing title" { ... }

2. GitHub Import Tests (fetch_github_tasks)

# Test JSON parsing
@test "fetch_github_tasks parses issue JSON correctly" {
    # Mock gh to return JSON
    gh() { echo '[{"number":123,"title":"Add feature"}]'; }
    ...
}

# Test label filtering
@test "fetch_github_tasks filters by label" { ... }

# Test limit parameter
@test "fetch_github_tasks respects limit parameter" { ... }

# Test empty results
@test "fetch_github_tasks handles no matching issues" { ... }

3. Combined Import Tests (import_tasks_from_sources)

# Test beads source
@test "import_tasks_from_sources imports from beads" { ... }

# Test github source  
@test "import_tasks_from_sources imports from github" { ... }

# Test multiple sources
@test "import_tasks_from_sources combines beads and github" { ... }

4. Count Function Tests

@test "get_beads_count returns correct count from JSON" { ... }
@test "get_github_issue_count returns correct count" { ... }

Implementation Approach

  1. Create mock command helpers in tests/helpers/:

    • mock_bd() - Returns configurable JSON/text output
    • mock_gh() - Returns configurable issue JSON
  2. Add fixture data in tests/helpers/fixtures.bash:

    • Sample beads JSON responses
    • Sample beads text output
    • Sample GitHub issue JSON
  3. Create test file: tests/integration/test_task_imports.bats

Acceptance Criteria

  • fetch_beads_tasks() has tests for JSON parsing, text fallback, status filtering, and edge cases
  • fetch_github_tasks() has tests for JSON parsing, label filtering, and edge cases
  • import_tasks_from_sources() tested with beads and github sources
  • Count functions tested with actual data
  • All tests use mocked commands (no external dependencies)
  • Tests cover the PR fix: beads task import uses correct bd list arguments #150 fixes to prevent regression

Labels

  • testing
  • enhancement
  • good first issue

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions