Skip to content

test: add unit tests for pkg/providers/embeddings package#202

Open
mason5052 wants to merge 1 commit intovxcontrol:masterfrom
mason5052:test/embeddings-provider-coverage
Open

test: add unit tests for pkg/providers/embeddings package#202
mason5052 wants to merge 1 commit intovxcontrol:masterfrom
mason5052:test/embeddings-provider-coverage

Conversation

@mason5052
Copy link
Contributor

Description of Change

Problem: The pkg/providers/embeddings package has no unit test coverage. This package provides the embedding provider factory supporting 7 providers (OpenAI, Ollama, Mistral, Jina, Huggingface, GoogleAI, VoyageAI) used for vector store operations.

Solution: Add unit tests for the New() factory function covering all 7 supported providers, the "none" provider, unsupported provider error handling, custom URL/key/model configuration, and IsAvailable() behavior for both valid and nil embedders.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Security update
  • Test update
  • Documentation update
  • Configuration change

Areas Affected

  • Core Services (Frontend UI / Backend API)
  • AI Agents (Researcher / Developer / Executor)
  • Security Tools Integration
  • Memory System (Vector Store / Knowledge Base)
  • Monitoring Stack (Grafana / OpenTelemetry)
  • Analytics & Reporting
  • External Integrations (LLM Providers / Search Engines / Security APIs)
  • Documentation
  • Infrastructure / DevOps

Testing and Verification

Test Configuration

  • PentAGI Version: v1.2.0 (master)
  • Go Version: 1.24.1
  • Host OS: Windows 11

Test Steps

  1. Run go test ./pkg/providers/embeddings/... -v

Test Results

=== RUN   TestNew_OpenAI
--- PASS: TestNew_OpenAI (0.00s)
=== RUN   TestNew_OpenAI_WithCustomURL
--- PASS: TestNew_OpenAI_WithCustomURL (0.00s)
=== RUN   TestNew_Ollama
--- PASS: TestNew_Ollama (0.00s)
=== RUN   TestNew_Mistral
--- PASS: TestNew_Mistral (0.00s)
=== RUN   TestNew_Jina
--- PASS: TestNew_Jina (0.00s)
=== RUN   TestNew_Huggingface
--- PASS: TestNew_Huggingface (0.00s)
=== RUN   TestNew_GoogleAI
--- PASS: TestNew_GoogleAI (0.00s)
=== RUN   TestNew_VoyageAI
--- PASS: TestNew_VoyageAI (0.00s)
=== RUN   TestNew_None
--- PASS: TestNew_None (0.00s)
=== RUN   TestNew_UnsupportedProvider
--- PASS: TestNew_UnsupportedProvider (0.00s)
=== RUN   TestNew_AllProviders_TableDriven
--- PASS: TestNew_AllProviders_TableDriven (0.00s)
=== RUN   TestIsAvailable_NilEmbedder
--- PASS: TestIsAvailable_NilEmbedder (0.00s)
PASS
ok  	pentagi/pkg/providers/embeddings	4.256s

Checklist

  • Code follows project coding standards
  • Tests added for changes
  • All tests pass
  • go fmt and go vet run
  • Changes are backward compatible

Add unit tests for the embedding provider factory function covering all
7 supported providers (OpenAI, Ollama, Mistral, Jina, Huggingface,
GoogleAI, VoyageAI), the none provider, unsupported provider error
handling, custom URL/key/model configuration, and IsAvailable behavior.
Copilot AI review requested due to automatic review settings March 12, 2026 18:05
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds initial unit test coverage for the pkg/providers/embeddings factory to ensure all supported embedding providers (and error/none cases) are exercised.

Changes:

  • Introduces embedder_test.go with per-provider tests for New() across all supported providers.
  • Adds coverage for custom OpenAI URL/key/model configuration, the "none" provider behavior, and unsupported provider error handling.
  • Adds a test for IsAvailable() when the underlying embedder is nil.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +23
e, err := New(cfg)
require.NoError(t, err)
assert.NotNil(t, e)
assert.True(t, e.IsAvailable())
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

assert.NotNil(t, e) doesn't stop the test, and the next line dereferences e via e.IsAvailable(). If New ever returns a nil embedder with a nil error (or the code changes), this will panic rather than produce a clean test failure. Use require.NotNil(t, e) (or guard the dereference) in this and the other tests in this file where e is used after an assert.NotNil.

Copilot uses AI. Check for mistakes.
Comment on lines +128 to +133
e, err := New(cfg)
assert.Error(t, err)
assert.Contains(t, err.Error(), "unsupported embedding provider")
assert.NotNil(t, e)
assert.False(t, e.IsAvailable())
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

In this test, assert.Error(t, err) and assert.Contains(t, err.Error(), ...) are used back-to-back. Since assert.Error doesn't stop execution, a nil err would cause a panic when calling err.Error(). Prefer require.Error(t, err) (or guard err before dereferencing) so failures are reported cleanly.

Copilot uses AI. Check for mistakes.
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.

2 participants