Skip to content

Commit 0e65e1a

Browse files
committed
test: add edge case tests for URL detection in OpenAICompatibleEmbedder
- Add tests for URLs with 'embeddings' in non-endpoint contexts - Add tests for URLs with 'deployments' in non-endpoint contexts - Verify actual endpoint URLs are still correctly identified - Addresses PR review feedback for better test coverage
1 parent 0ae8e65 commit 0e65e1a

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/services/code-index/embedders/__tests__/openai-compatible.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,53 @@ describe("OpenAICompatibleEmbedder", () => {
665665
const isFullUrl = (embedder as any).isFullEndpointUrl(url)
666666
expect(isFullUrl).toBe(expected)
667667
})
668+
669+
// Edge cases where 'embeddings' or 'deployments' appear in non-endpoint contexts
670+
it("should return false for URLs with 'embeddings' in non-endpoint contexts", () => {
671+
const testUrls = [
672+
"https://api.example.com/embeddings-service/v1",
673+
"https://embeddings.example.com/api",
674+
"https://api.example.com/v1/embeddings-api",
675+
"https://my-embeddings-provider.com/v1",
676+
]
677+
678+
testUrls.forEach((url) => {
679+
const embedder = new OpenAICompatibleEmbedder(url, testApiKey, testModelId)
680+
const isFullUrl = (embedder as any).isFullEndpointUrl(url)
681+
expect(isFullUrl).toBe(false)
682+
})
683+
})
684+
685+
it("should return false for URLs with 'deployments' in non-endpoint contexts", () => {
686+
const testUrls = [
687+
"https://deployments.example.com/api",
688+
"https://api.deployments.com/v1",
689+
"https://my-deployments-service.com/api/v1",
690+
"https://deployments-manager.example.com",
691+
]
692+
693+
testUrls.forEach((url) => {
694+
const embedder = new OpenAICompatibleEmbedder(url, testApiKey, testModelId)
695+
const isFullUrl = (embedder as any).isFullEndpointUrl(url)
696+
expect(isFullUrl).toBe(false)
697+
})
698+
})
699+
700+
it("should correctly identify actual endpoint URLs", () => {
701+
const endpointUrls = [
702+
"https://api.example.com/v1/embeddings",
703+
"https://api.example.com/v1/embeddings?api-version=2024",
704+
"https://myresource.openai.azure.com/openai/deployments/mymodel/embeddings",
705+
"https://api.example.com/embed",
706+
"https://api.example.com/embed?version=1",
707+
]
708+
709+
endpointUrls.forEach((url) => {
710+
const embedder = new OpenAICompatibleEmbedder(url, testApiKey, testModelId)
711+
const isFullUrl = (embedder as any).isFullEndpointUrl(url)
712+
expect(isFullUrl).toBe(true)
713+
})
714+
})
668715
})
669716

670717
describe("direct HTTP requests", () => {

0 commit comments

Comments
 (0)