Skip to content

Commit

Permalink
fix an issue with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
ctawiah committed Feb 3, 2025
1 parent e4e8ec5 commit dc4c97f
Showing 1 changed file with 112 additions and 16 deletions.
128 changes: 112 additions & 16 deletions packages/sdk/server-ai/__tests__/LDAIConfigTrackerImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ beforeEach(() => {
});

it('tracks duration', () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, version, testContext);
const tracker = new LDAIConfigTrackerImpl(
mockLdClient,
configKey,
variationKey,
version,
testContext,
);
tracker.trackDuration(1000);

expect(mockTrack).toHaveBeenCalledWith(
Expand All @@ -33,7 +39,13 @@ it('tracks duration', () => {
});

it('tracks duration of async function', async () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, version, testContext);
const tracker = new LDAIConfigTrackerImpl(
mockLdClient,
configKey,
variationKey,
version,
testContext,
);
jest.spyOn(global.Date, 'now').mockReturnValueOnce(1000).mockReturnValueOnce(2000);

const result = await tracker.trackDurationOf(async () => 'test-result');
Expand All @@ -48,7 +60,13 @@ it('tracks duration of async function', async () => {
});

it('tracks time to first token', () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, version, testContext);
const tracker = new LDAIConfigTrackerImpl(
mockLdClient,
configKey,
variationKey,
version,
testContext,
);
tracker.trackTimeToFirstToken(1000);

expect(mockTrack).toHaveBeenCalledWith(
Expand All @@ -60,7 +78,13 @@ it('tracks time to first token', () => {
});

it('tracks positive feedback', () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, version, testContext);
const tracker = new LDAIConfigTrackerImpl(
mockLdClient,
configKey,
variationKey,
version,
testContext,
);
tracker.trackFeedback({ kind: LDFeedbackKind.Positive });

expect(mockTrack).toHaveBeenCalledWith(
Expand All @@ -72,7 +96,13 @@ it('tracks positive feedback', () => {
});

it('tracks negative feedback', () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, version, testContext);
const tracker = new LDAIConfigTrackerImpl(
mockLdClient,
configKey,
variationKey,
version,
testContext,
);
tracker.trackFeedback({ kind: LDFeedbackKind.Negative });

expect(mockTrack).toHaveBeenCalledWith(
Expand All @@ -84,7 +114,13 @@ it('tracks negative feedback', () => {
});

it('tracks success', () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, version, testContext);
const tracker = new LDAIConfigTrackerImpl(
mockLdClient,
configKey,
variationKey,
version,
testContext,
);
tracker.trackSuccess();

expect(mockTrack).toHaveBeenCalledWith(
Expand All @@ -96,7 +132,13 @@ it('tracks success', () => {
});

it('tracks OpenAI usage', async () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, version, testContext);
const tracker = new LDAIConfigTrackerImpl(
mockLdClient,
configKey,
variationKey,
version,
testContext,
);
jest.spyOn(global.Date, 'now').mockReturnValueOnce(1000).mockReturnValueOnce(2000);

const TOTAL_TOKENS = 100;
Expand Down Expand Up @@ -148,7 +190,13 @@ it('tracks OpenAI usage', async () => {
});

it('tracks error when OpenAI metrics function throws', async () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, version, testContext);
const tracker = new LDAIConfigTrackerImpl(
mockLdClient,
configKey,
variationKey,
version,
testContext,
);
jest.spyOn(global.Date, 'now').mockReturnValueOnce(1000).mockReturnValueOnce(2000);

const error = new Error('OpenAI API error');
Expand Down Expand Up @@ -181,7 +229,13 @@ it('tracks error when OpenAI metrics function throws', async () => {
});

it('tracks Bedrock conversation with successful response', () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, version, testContext);
const tracker = new LDAIConfigTrackerImpl(
mockLdClient,
configKey,
variationKey,
version,
testContext,
);

const TOTAL_TOKENS = 100;
const PROMPT_TOKENS = 49;
Expand Down Expand Up @@ -236,7 +290,13 @@ it('tracks Bedrock conversation with successful response', () => {
});

it('tracks Bedrock conversation with error response', () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, version, testContext);
const tracker = new LDAIConfigTrackerImpl(
mockLdClient,
configKey,
variationKey,
version,
testContext,
);

const response = {
$metadata: { httpStatusCode: 400 },
Expand All @@ -261,7 +321,13 @@ it('tracks Bedrock conversation with error response', () => {
});

it('tracks tokens', () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, version, testContext);
const tracker = new LDAIConfigTrackerImpl(
mockLdClient,
configKey,
variationKey,
version,
testContext,
);

const TOTAL_TOKENS = 100;
const PROMPT_TOKENS = 49;
Expand Down Expand Up @@ -296,7 +362,13 @@ it('tracks tokens', () => {
});

it('only tracks non-zero token counts', () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, version, testContext);
const tracker = new LDAIConfigTrackerImpl(
mockLdClient,
configKey,
variationKey,
version,
testContext,
);

tracker.trackTokens({
total: 0,
Expand Down Expand Up @@ -327,15 +399,27 @@ it('only tracks non-zero token counts', () => {
});

it('returns empty summary when no metrics tracked', () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, version, testContext);
const tracker = new LDAIConfigTrackerImpl(
mockLdClient,
configKey,
variationKey,
version,
testContext,
);

const summary = tracker.getSummary();

expect(summary).toEqual({});
});

it('summarizes tracked metrics', () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, version, testContext);
const tracker = new LDAIConfigTrackerImpl(
mockLdClient,
configKey,
variationKey,
version,
testContext,
);

tracker.trackDuration(1000);
tracker.trackTokens({
Expand Down Expand Up @@ -363,7 +447,13 @@ it('summarizes tracked metrics', () => {
});

it('tracks duration when async function throws', async () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, version, testContext);
const tracker = new LDAIConfigTrackerImpl(
mockLdClient,
configKey,
variationKey,
version,
testContext,
);
jest.spyOn(global.Date, 'now').mockReturnValueOnce(1000).mockReturnValueOnce(2000);

const error = new Error('test error');
Expand All @@ -382,7 +472,13 @@ it('tracks duration when async function throws', async () => {
});

it('tracks error', () => {
const tracker = new LDAIConfigTrackerImpl(mockLdClient, configKey, variationKey, version, testContext);
const tracker = new LDAIConfigTrackerImpl(
mockLdClient,
configKey,
variationKey,
version,
testContext,
);
tracker.trackError();

expect(mockTrack).toHaveBeenCalledWith(
Expand Down

0 comments on commit dc4c97f

Please sign in to comment.