Skip to content

Conversation

@ps06756
Copy link

@ps06756 ps06756 commented Dec 30, 2025

Summary

Fixes #68

  • Add OpenAIChatCompletionService interface to enable mocking in tests
  • Add NewOpenAICompletionProviderWithService() constructor for test injection
  • Add comprehensive test coverage with 18 test functions and 50+ test cases

Test Coverage

Category Tests
Provider Creation Valid API key, empty API key, custom URL
Input Validation Empty model, empty prompt, empty/nil messages
Model Profile Validation Nil profile, invalid temperature/penalties
Message Transformation User/model/system messages, tool calls, mixed history
Tool Transformation Empty tools, single tool, multiple tools
Edge Cases Unicode, long content, special characters
Concurrent Access Thread-safe validation and transformation

Test Plan

  • All existing tests pass
  • New tests pass (go test ./backend/model/...)
  • Full project builds (go build ./backend/... ./api/go/... ./frontend/cli/... ./shared/...)
  • Full test suite passes

@ps06756
Copy link
Author

ps06756 commented Dec 30, 2025

Let me work on the failing checks and raise a new rev

@ps06756
Copy link
Author

ps06756 commented Jan 3, 2026

@Furisto Can you review this ?

}
}

func TestNewOpenAICompletionProviderWithService(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

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

Can we remove this test? It does not provide much value.

}
}

func TestOpenAICompletionProvider_InvokeModel_ModelProfileValidation(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

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

Would prefer to write a separate test for the Validate function of the model profile and not intermingle it with the InvokeModel test.

// Edge Cases Tests
// =============================================================================

func TestOpenAICompletionProvider_TransformMessages_EdgeCases(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

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

This should be part of the TransformMessages test instead of a separate test for edge cases.

}
}

func TestOpenAICompletionProvider_TransformTools_ManyTools(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

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

Let's drop this test. We already have tests that cover transformation of tools and testing that n+1 works when we already test n does not contribute much value.

var wg sync.WaitGroup
errorChan := make(chan error, 100)

for i := 0; i < 100; i++ {
Copy link
Owner

Choose a reason for hiding this comment

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

Validation of inputs is stateless. What scenario would this cover?

return m.stream
}

func (m *mockChatCompletionService) getCallCount() int {
Copy link
Owner

Choose a reason for hiding this comment

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

When do we call this method?

}
}

func TestOpenAICompletionProvider_ConcurrentTransformMessages(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

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

Why do we need to test concurrent transformation of messages?

}
}

// =============================================================================
Copy link
Owner

Choose a reason for hiding this comment

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

Nit: We do not need the comment. The test name is enough.

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.

Complete Test Coverage for OpenAI Completion Provider

2 participants