Skip to content

[CrystalShards] Implement pending worker test specs #31

@jwaldrip

Description

@jwaldrip

Problem

Worker specs exist but are marked pending, resulting in no test coverage for workers.

Impact

  • Cannot verify worker behavior in CI
  • Regression risk when modifying workers
  • No confidence in worker reliability

Files Requiring Implementation

1. spec/workers/index_shard_worker_spec.cr

Currently has 3 pending tests:

  • "processes shard metadata correctly"
  • "enqueues BuildDocsWorker after indexing"
  • "handles errors gracefully"

2. spec/workers/build_docs_worker_spec.cr

Status: Check if tests exist and are pending

3. spec/workers/update_dependencies_worker_spec.cr

Status: Check if tests exist and are pending

Requirements

Test Coverage Needed

  • Success paths: Worker completes successfully
  • Error handling: Worker handles failures gracefully
  • External dependencies: Mock GitHub API, MinIO, Redis
  • Worker chaining: Verify workers enqueue next workers
  • Idempotency: Same job run multiple times produces same result

Mocking Strategy

# Mock GitHub API
class MockGitHubClient
  def get_shard_yml(repo : String, ref : String) : String
    # Return fixture data
  end
end

# Mock MinIO
class MockMinIOClient
  def upload(bucket : String, key : String, data : IO) : Nil
    # Track uploads for assertions
  end
end

# Use test Redis instance
Mosquito.configure do |settings|
  settings.redis_url = ENV["TEST_REDIS_URL"]
end

Test Structure

describe IndexShardWorker do
  it "processes shard metadata correctly" do
    worker = IndexShardWorker.new
    worker.shard_name = "example"
    worker.version = "1.0.0"
    
    # Mock external calls
    # Run worker
    # Assert database records created
    # Assert metadata extracted correctly
  end
  
  it "enqueues BuildDocsWorker after indexing" do
    # Run IndexShardWorker
    # Assert BuildDocsWorker was enqueued
  end
  
  it "handles errors gracefully" do
    # Mock failure condition
    # Run worker
    # Assert error logged
    # Assert job marked as failed
  end
end

Implementation Steps

  1. Remove pending blocks from all worker specs
  2. Implement mock classes for external dependencies
  3. Write assertions for each test case
  4. Run tests locally and verify they pass
  5. Add tests to CI pipeline

Priority

MEDIUM - Improves confidence in worker reliability

Application

CrystalShards.org

Acceptance Criteria

  • All pending blocks removed from worker specs
  • IndexShardWorker tests implemented and passing
  • BuildDocsWorker tests implemented and passing
  • UpdateDependenciesWorker tests implemented and passing
  • External dependencies properly mocked
  • Test coverage > 80% for worker code
  • Tests pass in CI pipeline
  • Test documentation added for future maintainers

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions