Skip to content

Commit

Permalink
feat: github action for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeherby committed Feb 4, 2024
1 parent a0e583c commit d5f5880
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 19 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Node.js CI

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
project: [ui, server]
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install dependencies
run: npm install
working-directory: ${{ matrix.project }}
- name: Run lint
run: npm run lint
working-directory: ${{ matrix.project }}
- name: Build
run: npm run build
working-directory: ${{ matrix.project }}
2 changes: 0 additions & 2 deletions server/src/repositories/ingest-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,4 @@ export class IngestRepository {
return await collection.updateOne({ 'feedback.id': feedbackId },
{ $set: setOperation });
}


}
4 changes: 2 additions & 2 deletions server/src/services/langchain-to-langtrace-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export class LangchainToLangtraceService {
return langchainData.run_id;
}

async updateTrace(trace_id: string, langchainData: TraceData): Promise<boolean> {
async updateTrace(traceId: string, langchainData: TraceData): Promise<boolean> {
this.convertToDates(langchainData);

const updateResult = await this.repository.updateTrace(trace_id, langchainData);
const updateResult = await this.repository.updateTrace(traceId, langchainData);
return updateResult.matchedCount > 0;
}

Expand Down
44 changes: 29 additions & 15 deletions server/src/services/trace-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ describe('TraceService', () => {
let service: TraceService;
let mockRepository: jest.Mocked<ApiRepository>;

const mockProjectId = 'projectId';

beforeEach(() => {
mockRepository = new ApiRepository() as any;
service = new TraceService();
Expand All @@ -26,7 +28,12 @@ describe('TraceService', () => {
run_type: '',
session_name: '',
start_time: '',
'run_id': mockTraceId, name: 'Test Trace'
'run_id': mockTraceId,
name: 'Test Trace',
execution_order: 0,
trace_id: null,
dotted_order: null,

};


Expand All @@ -42,17 +49,26 @@ describe('TraceService', () => {
mockRepository.getTraces.mockResolvedValue(expectedResult);

mockRepository.getFeedbackCounts.mockResolvedValue(
[{ key: 'useful', counts: { 'true': 0, 'false': 0 } }]);
[{
key: 'useful',
feedbackType: 'value',
counts: { 'true': 0, 'false': 0 }
}]
);

mockRepository.getLatencyPercentile.mockResolvedValue( [
mockRepository.getLatencyPercentile.mockResolvedValue([
{ percentile: 0, latency: 0 } as TracePercentile,
]
);

const result = await service.getTopLevelTraces();
const result = await service.getTopLevelTraces(mockProjectId);

expect(result).toEqual({
feedback_counts: [{ key: 'useful', counts: { 'true': 0, 'false': 0 } }],
feedback_counts: [{
key: 'useful',
feedbackType: 'value',
counts: { 'true': 0, 'false': 0 }
}],
latency_percentiles: [{ percentile: 0, latency: 0 }],
traces: expectedResult
} satisfies TracesResponse);
Expand All @@ -66,30 +82,28 @@ describe('TraceService', () => {
it('should return null if no trace is found', async () => {
mockRepository.getTraceTreeById.mockResolvedValue([]);

const result = await service.getTraceTreeByRunId(mockTraceId);
const result = await service.getTraceTreeByRunId(mockProjectId, mockTraceId);

expect(result).toBeNull();
expect(mockRepository.getTraceTreeById).toHaveBeenCalledWith(mockTraceId);
expect(mockRepository.getTraceTreeById).toHaveBeenCalledWith(mockProjectId, mockTraceId);
});

it('should throw an error if multiple traces are found', async () => {
mockRepository.getTraceTreeById.mockResolvedValue([mockTraceDocument, mockTraceDocument]);

await expect(service.getTraceTreeByRunId(mockTraceId)).rejects.toThrow('Trace not found');
expect(mockRepository.getTraceTreeById).toHaveBeenCalledWith(mockTraceId);
await expect(service.getTraceTreeByRunId(mockProjectId, mockTraceId))
.rejects.toThrow('Trace not found');
expect(mockRepository.getTraceTreeById).toHaveBeenCalledWith(mockProjectId, mockTraceId);
});

it('should return a trace document if exactly one trace is found', async () => {

mockRepository.getTraceTreeById.mockResolvedValue([mockTraceDocument]);

const result = await service.getTraceTreeByRunId(mockTraceId);
const result = await service.getTraceTreeByRunId(mockProjectId, mockTraceId);

expect(result).toEqual(mockTraceDocument);
expect(mockRepository.getTraceTreeById).toHaveBeenCalledWith(mockTraceId);
expect(mockRepository.getTraceTreeById).toHaveBeenCalledWith(mockProjectId, mockTraceId);
});
});


})
;
});

0 comments on commit d5f5880

Please sign in to comment.