-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
quickfix: evaluarion results repository scope missed a filter (#302)
Most of the times it does not matter because we filter in almost all methods by other means. But in the credits calculations it does matter.
- Loading branch information
Showing
10 changed files
with
330 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/core/src/repositories/documentVersionsRepository/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { beforeEach, describe, expect, it } from 'vitest' | ||
|
||
import { Providers } from '../../constants' | ||
import { createProject, helpers } from '../../tests/factories' | ||
import { DocumentVersionsRepository } from './index' | ||
|
||
describe('DocumentVersionsRepository', () => { | ||
let repository: DocumentVersionsRepository | ||
let workspace1Id: number | ||
let commit1Id: number | ||
|
||
beforeEach(async () => { | ||
const { workspace: workspace1, commit: commit1 } = await createProject({ | ||
providers: [{ type: Providers.OpenAI, name: 'OpenAI' }], | ||
documents: { | ||
foo: helpers.createPrompt({ | ||
provider: 'OpenAI', | ||
}), | ||
bar: helpers.createPrompt({ | ||
provider: 'OpenAI', | ||
}), | ||
}, | ||
}) | ||
|
||
await createProject({ | ||
providers: [{ type: Providers.OpenAI, name: 'OpenAI' }], | ||
documents: { | ||
jon: helpers.createPrompt({ | ||
provider: 'OpenAI', | ||
}), | ||
arya: helpers.createPrompt({ | ||
provider: 'OpenAI', | ||
}), | ||
}, | ||
}) | ||
|
||
workspace1Id = workspace1.id | ||
commit1Id = commit1.id | ||
|
||
repository = new DocumentVersionsRepository(workspace1Id) | ||
}) | ||
|
||
describe('findAll', () => { | ||
it('only returns documents from the specified workspace', async () => { | ||
const result = await repository.findAll() | ||
expect(result.ok).toBe(true) | ||
|
||
const documents = result.unwrap() | ||
expect(documents).toHaveLength(2) | ||
expect(documents.map((d) => d.path)).toEqual(['foo', 'bar']) | ||
expect(documents.every((d) => d.commitId === commit1Id)).toBe(true) | ||
}) | ||
|
||
it('returns an empty array for a different workspace', async () => { | ||
const differentWorkspaceRepository = new DocumentVersionsRepository(999) // Non-existent workspace ID | ||
const result = await differentWorkspaceRepository.findAll() | ||
expect(result.ok).toBe(true) | ||
|
||
const documents = result.unwrap() | ||
expect(documents).toHaveLength(0) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
packages/core/src/repositories/evaluationResultsRepository/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
import { Providers } from '../../browser' | ||
import { | ||
createDocumentLog, | ||
createEvaluationResult, | ||
createLlmAsJudgeEvaluation, | ||
createProject, | ||
createProviderLog, | ||
helpers, | ||
} from '../../tests/factories' | ||
import { EvaluationResultsRepository } from './index' | ||
|
||
describe('EvaluationResultsRepository', () => { | ||
describe('findAll', () => { | ||
it('should return only results from the specified workspace', async () => { | ||
// Create projects for each workspace | ||
const { | ||
workspace: workspace1, | ||
documents: [document1], | ||
commit: commit1, | ||
providers: [provider1], | ||
} = await createProject({ | ||
providers: [{ type: Providers.OpenAI, name: 'openai' }], | ||
documents: { | ||
foo: helpers.createPrompt({ | ||
provider: 'openai', | ||
}), | ||
}, | ||
}) | ||
const { | ||
workspace: workspace2, | ||
documents: [document2], | ||
commit: commit2, | ||
providers: [provider2], | ||
} = await createProject({ | ||
providers: [{ type: Providers.OpenAI, name: 'openai' }], | ||
documents: { | ||
bar: helpers.createPrompt({ | ||
provider: 'openai', | ||
}), | ||
}, | ||
}) | ||
|
||
// Create evaluations for each workspace | ||
const evaluation1 = await createLlmAsJudgeEvaluation({ | ||
workspace: workspace1, | ||
}) | ||
const evaluation2 = await createLlmAsJudgeEvaluation({ | ||
workspace: workspace2, | ||
}) | ||
|
||
// Create document logs for each project | ||
const documentLog1 = await createDocumentLog({ | ||
document: document1!, | ||
commit: commit1, | ||
}) | ||
const documentLog2 = await createDocumentLog({ | ||
document: document2!, | ||
commit: commit2, | ||
}) | ||
|
||
await createProviderLog({ | ||
documentLogUuid: documentLog1.documentLog.uuid, | ||
providerId: provider1!.id, | ||
providerType: Providers.OpenAI, | ||
}) | ||
await createProviderLog({ | ||
documentLogUuid: documentLog2.documentLog.uuid, | ||
providerId: provider2!.id, | ||
providerType: Providers.OpenAI, | ||
}) | ||
|
||
// Create evaluation results for each workspace | ||
await createEvaluationResult({ | ||
documentLog: documentLog1.documentLog, | ||
evaluation: evaluation1, | ||
result: 'Result 1', | ||
}) | ||
await createEvaluationResult({ | ||
documentLog: documentLog2.documentLog, | ||
evaluation: evaluation2, | ||
result: 'Result 2', | ||
}) | ||
|
||
// Initialize repositories for each workspace | ||
const repo1 = new EvaluationResultsRepository(workspace1.id) | ||
const repo2 = new EvaluationResultsRepository(workspace2.id) | ||
|
||
// Fetch results for each workspace | ||
const results1 = await repo1.findAll() | ||
const results2 = await repo2.findAll() | ||
|
||
// Assert that each repository only returns results for its workspace | ||
expect(results1.ok).toBe(true) | ||
expect(results2.ok).toBe(true) | ||
|
||
const data1 = results1.unwrap() | ||
const data2 = results2.unwrap() | ||
|
||
expect(data1.length).toBe(1) | ||
expect(data2.length).toBe(1) | ||
|
||
expect(data1[0]?.result).toBe('Result 1') | ||
expect(data2[0]?.result).toBe('Result 2') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.