From eaea47aa841ae4b0d4235164ceaf4a27ae5edbfc Mon Sep 17 00:00:00 2001 From: Amy Chisholm Date: Wed, 4 Sep 2024 13:27:41 -0700 Subject: [PATCH] fix: change `ctx` to `t` where applicable --- .../aws-bedrock/bedrock-command.test.js | 100 ++++++++-------- .../aws-bedrock/bedrock-response.test.js | 110 +++++++++--------- .../chat-completion-message.test.js | 46 ++++---- .../chat-completion-summary.test.js | 38 +++--- .../llm-events/aws-bedrock/embedding.test.js | 16 +-- .../unit/llm-events/aws-bedrock/error.test.js | 12 +- .../unit/llm-events/aws-bedrock/event.test.js | 8 +- .../aws-bedrock/stream-handler.test.js | 68 +++++------ .../langchain/chat-completion-message.test.js | 16 +-- .../langchain/chat-completion-summary.test.js | 4 +- test/unit/llm-events/langchain/event.test.js | 36 +++--- test/unit/llm-events/langchain/tool.test.js | 10 +- .../langchain/vector-search-result.test.js | 12 +- .../langchain/vector-search.test.js | 10 +- .../openai/chat-completion-message.test.js | 32 ++--- .../openai/chat-completion-summary.test.js | 8 +- test/unit/llm-events/openai/embedding.test.js | 24 ++-- 17 files changed, 275 insertions(+), 275 deletions(-) diff --git a/test/unit/llm-events/aws-bedrock/bedrock-command.test.js b/test/unit/llm-events/aws-bedrock/bedrock-command.test.js index 3b368d9d41..639d11ef54 100644 --- a/test/unit/llm-events/aws-bedrock/bedrock-command.test.js +++ b/test/unit/llm-events/aws-bedrock/bedrock-command.test.js @@ -86,8 +86,8 @@ test.beforeEach((ctx) => { } }) -test('non-conforming command is handled gracefully', async (ctx) => { - const cmd = new BedrockCommand(ctx.nr.input) +test('non-conforming command is handled gracefully', async (t) => { + const cmd = new BedrockCommand(t.nr.input) for (const model of [ 'Ai21', 'Claude', @@ -107,9 +107,9 @@ test('non-conforming command is handled gracefully', async (ctx) => { assert.equal(cmd.temperature, undefined) }) -test('ai21 minimal command works', async (ctx) => { - ctx.nr.updatePayload(structuredClone(ai21)) - const cmd = new BedrockCommand(ctx.nr.input) +test('ai21 minimal command works', async (t) => { + t.nr.updatePayload(structuredClone(ai21)) + const cmd = new BedrockCommand(t.nr.input) assert.equal(cmd.isAi21(), true) assert.equal(cmd.maxTokens, undefined) assert.equal(cmd.modelId, ai21.modelId) @@ -118,12 +118,12 @@ test('ai21 minimal command works', async (ctx) => { assert.equal(cmd.temperature, undefined) }) -test('ai21 complete command works', async (ctx) => { +test('ai21 complete command works', async (t) => { const payload = structuredClone(ai21) payload.body.maxTokens = 25 payload.body.temperature = 0.5 - ctx.nr.updatePayload(payload) - const cmd = new BedrockCommand(ctx.nr.input) + t.nr.updatePayload(payload) + const cmd = new BedrockCommand(t.nr.input) assert.equal(cmd.isAi21(), true) assert.equal(cmd.maxTokens, 25) assert.equal(cmd.modelId, payload.modelId) @@ -132,9 +132,9 @@ test('ai21 complete command works', async (ctx) => { assert.equal(cmd.temperature, payload.body.temperature) }) -test('claude minimal command works', async (ctx) => { - ctx.nr.updatePayload(structuredClone(claude)) - const cmd = new BedrockCommand(ctx.nr.input) +test('claude minimal command works', async (t) => { + t.nr.updatePayload(structuredClone(claude)) + const cmd = new BedrockCommand(t.nr.input) assert.equal(cmd.isClaude(), true) assert.equal(cmd.maxTokens, undefined) assert.equal(cmd.modelId, claude.modelId) @@ -143,12 +143,12 @@ test('claude minimal command works', async (ctx) => { assert.equal(cmd.temperature, undefined) }) -test('claude complete command works', async (ctx) => { +test('claude complete command works', async (t) => { const payload = structuredClone(claude) payload.body.max_tokens_to_sample = 25 payload.body.temperature = 0.5 - ctx.nr.updatePayload(payload) - const cmd = new BedrockCommand(ctx.nr.input) + t.nr.updatePayload(payload) + const cmd = new BedrockCommand(t.nr.input) assert.equal(cmd.isClaude(), true) assert.equal(cmd.maxTokens, 25) assert.equal(cmd.modelId, payload.modelId) @@ -157,9 +157,9 @@ test('claude complete command works', async (ctx) => { assert.equal(cmd.temperature, payload.body.temperature) }) -test('claude3 minimal command works', async (ctx) => { - ctx.nr.updatePayload(structuredClone(claude3)) - const cmd = new BedrockCommand(ctx.nr.input) +test('claude3 minimal command works', async (t) => { + t.nr.updatePayload(structuredClone(claude3)) + const cmd = new BedrockCommand(t.nr.input) assert.equal(cmd.isClaude3(), true) assert.equal(cmd.maxTokens, undefined) assert.equal(cmd.modelId, claude3.modelId) @@ -168,12 +168,12 @@ test('claude3 minimal command works', async (ctx) => { assert.equal(cmd.temperature, undefined) }) -test('claude3 complete command works', async (ctx) => { +test('claude3 complete command works', async (t) => { const payload = structuredClone(claude3) payload.body.max_tokens = 25 payload.body.temperature = 0.5 - ctx.nr.updatePayload(payload) - const cmd = new BedrockCommand(ctx.nr.input) + t.nr.updatePayload(payload) + const cmd = new BedrockCommand(t.nr.input) assert.equal(cmd.isClaude3(), true) assert.equal(cmd.maxTokens, 25) assert.equal(cmd.modelId, payload.modelId) @@ -182,9 +182,9 @@ test('claude3 complete command works', async (ctx) => { assert.equal(cmd.temperature, payload.body.temperature) }) -test('cohere minimal command works', async (ctx) => { - ctx.nr.updatePayload(structuredClone(cohere)) - const cmd = new BedrockCommand(ctx.nr.input) +test('cohere minimal command works', async (t) => { + t.nr.updatePayload(structuredClone(cohere)) + const cmd = new BedrockCommand(t.nr.input) assert.equal(cmd.isCohere(), true) assert.equal(cmd.maxTokens, undefined) assert.equal(cmd.modelId, cohere.modelId) @@ -193,12 +193,12 @@ test('cohere minimal command works', async (ctx) => { assert.equal(cmd.temperature, undefined) }) -test('cohere complete command works', async (ctx) => { +test('cohere complete command works', async (t) => { const payload = structuredClone(cohere) payload.body.max_tokens = 25 payload.body.temperature = 0.5 - ctx.nr.updatePayload(payload) - const cmd = new BedrockCommand(ctx.nr.input) + t.nr.updatePayload(payload) + const cmd = new BedrockCommand(t.nr.input) assert.equal(cmd.isCohere(), true) assert.equal(cmd.maxTokens, 25) assert.equal(cmd.modelId, payload.modelId) @@ -207,9 +207,9 @@ test('cohere complete command works', async (ctx) => { assert.equal(cmd.temperature, payload.body.temperature) }) -test('cohere embed minimal command works', async (ctx) => { - ctx.nr.updatePayload(structuredClone(cohereEmbed)) - const cmd = new BedrockCommand(ctx.nr.input) +test('cohere embed minimal command works', async (t) => { + t.nr.updatePayload(structuredClone(cohereEmbed)) + const cmd = new BedrockCommand(t.nr.input) assert.equal(cmd.isCohereEmbed(), true) assert.equal(cmd.maxTokens, undefined) assert.equal(cmd.modelId, cohereEmbed.modelId) @@ -218,9 +218,9 @@ test('cohere embed minimal command works', async (ctx) => { assert.equal(cmd.temperature, undefined) }) -test('llama2 minimal command works', async (ctx) => { - ctx.nr.updatePayload(structuredClone(llama2)) - const cmd = new BedrockCommand(ctx.nr.input) +test('llama2 minimal command works', async (t) => { + t.nr.updatePayload(structuredClone(llama2)) + const cmd = new BedrockCommand(t.nr.input) assert.equal(cmd.isLlama(), true) assert.equal(cmd.maxTokens, undefined) assert.equal(cmd.modelId, llama2.modelId) @@ -229,12 +229,12 @@ test('llama2 minimal command works', async (ctx) => { assert.equal(cmd.temperature, undefined) }) -test('llama2 complete command works', async (ctx) => { +test('llama2 complete command works', async (t) => { const payload = structuredClone(llama2) payload.body.max_gen_length = 25 payload.body.temperature = 0.5 - ctx.nr.updatePayload(payload) - const cmd = new BedrockCommand(ctx.nr.input) + t.nr.updatePayload(payload) + const cmd = new BedrockCommand(t.nr.input) assert.equal(cmd.isLlama(), true) assert.equal(cmd.maxTokens, 25) assert.equal(cmd.modelId, payload.modelId) @@ -243,9 +243,9 @@ test('llama2 complete command works', async (ctx) => { assert.equal(cmd.temperature, payload.body.temperature) }) -test('llama3 minimal command works', async (ctx) => { - ctx.nr.updatePayload(structuredClone(llama3)) - const cmd = new BedrockCommand(ctx.nr.input) +test('llama3 minimal command works', async (t) => { + t.nr.updatePayload(structuredClone(llama3)) + const cmd = new BedrockCommand(t.nr.input) assert.equal(cmd.isLlama(), true) assert.equal(cmd.maxTokens, undefined) assert.equal(cmd.modelId, llama3.modelId) @@ -254,12 +254,12 @@ test('llama3 minimal command works', async (ctx) => { assert.equal(cmd.temperature, undefined) }) -test('llama3 complete command works', async (ctx) => { +test('llama3 complete command works', async (t) => { const payload = structuredClone(llama3) payload.body.max_gen_length = 25 payload.body.temperature = 0.5 - ctx.nr.updatePayload(payload) - const cmd = new BedrockCommand(ctx.nr.input) + t.nr.updatePayload(payload) + const cmd = new BedrockCommand(t.nr.input) assert.equal(cmd.isLlama(), true) assert.equal(cmd.maxTokens, 25) assert.equal(cmd.modelId, payload.modelId) @@ -268,9 +268,9 @@ test('llama3 complete command works', async (ctx) => { assert.equal(cmd.temperature, payload.body.temperature) }) -test('titan minimal command works', async (ctx) => { - ctx.nr.updatePayload(structuredClone(titan)) - const cmd = new BedrockCommand(ctx.nr.input) +test('titan minimal command works', async (t) => { + t.nr.updatePayload(structuredClone(titan)) + const cmd = new BedrockCommand(t.nr.input) assert.equal(cmd.isTitan(), true) assert.equal(cmd.maxTokens, undefined) assert.equal(cmd.modelId, titan.modelId) @@ -279,14 +279,14 @@ test('titan minimal command works', async (ctx) => { assert.equal(cmd.temperature, undefined) }) -test('titan complete command works', async (ctx) => { +test('titan complete command works', async (t) => { const payload = structuredClone(titan) payload.body.textGenerationConfig = { maxTokenCount: 25, temperature: 0.5 } - ctx.nr.updatePayload(payload) - const cmd = new BedrockCommand(ctx.nr.input) + t.nr.updatePayload(payload) + const cmd = new BedrockCommand(t.nr.input) assert.equal(cmd.isTitan(), true) assert.equal(cmd.maxTokens, 25) assert.equal(cmd.modelId, payload.modelId) @@ -295,9 +295,9 @@ test('titan complete command works', async (ctx) => { assert.equal(cmd.temperature, payload.body.textGenerationConfig.temperature) }) -test('titan embed minimal command works', async (ctx) => { - ctx.nr.updatePayload(structuredClone(titanEmbed)) - const cmd = new BedrockCommand(ctx.nr.input) +test('titan embed minimal command works', async (t) => { + t.nr.updatePayload(structuredClone(titanEmbed)) + const cmd = new BedrockCommand(t.nr.input) assert.equal(cmd.isTitanEmbed(), true) assert.equal(cmd.maxTokens, undefined) assert.equal(cmd.modelId, titanEmbed.modelId) diff --git a/test/unit/llm-events/aws-bedrock/bedrock-response.test.js b/test/unit/llm-events/aws-bedrock/bedrock-response.test.js index 11103bc2ac..b4047c7324 100644 --- a/test/unit/llm-events/aws-bedrock/bedrock-response.test.js +++ b/test/unit/llm-events/aws-bedrock/bedrock-response.test.js @@ -94,9 +94,9 @@ test.beforeEach((ctx) => { } }) -test('non-conforming response is handled gracefully', async (ctx) => { - delete ctx.nr.response.response.headers - const res = new BedrockResponse(ctx.nr) +test('non-conforming response is handled gracefully', async (t) => { + delete t.nr.response.response.headers + const res = new BedrockResponse(t.nr) assert.deepStrictEqual(res.completions, []) assert.equal(res.finishReason, undefined) assert.deepStrictEqual(res.headers, undefined) @@ -105,131 +105,131 @@ test('non-conforming response is handled gracefully', async (ctx) => { assert.equal(res.statusCode, 200) }) -test('ai21 malformed responses work', async (ctx) => { - ctx.nr.bedrockCommand.isAi21 = () => true - const res = new BedrockResponse(ctx.nr) +test('ai21 malformed responses work', async (t) => { + t.nr.bedrockCommand.isAi21 = () => true + const res = new BedrockResponse(t.nr) assert.deepStrictEqual(res.completions, []) assert.equal(res.finishReason, undefined) - assert.deepStrictEqual(res.headers, ctx.nr.response.response.headers) + assert.deepStrictEqual(res.headers, t.nr.response.response.headers) assert.equal(res.id, undefined) assert.equal(res.requestId, 'aws-request-1') assert.equal(res.statusCode, 200) }) -test('ai21 complete responses work', async (ctx) => { - ctx.nr.bedrockCommand.isAi21 = () => true - ctx.nr.updatePayload(structuredClone(ai21)) - const res = new BedrockResponse(ctx.nr) +test('ai21 complete responses work', async (t) => { + t.nr.bedrockCommand.isAi21 = () => true + t.nr.updatePayload(structuredClone(ai21)) + const res = new BedrockResponse(t.nr) assert.deepStrictEqual(res.completions, ['ai21-response']) assert.equal(res.finishReason, 'done') - assert.deepStrictEqual(res.headers, ctx.nr.response.response.headers) + assert.deepStrictEqual(res.headers, t.nr.response.response.headers) assert.equal(res.id, 'ai21-response-1') assert.equal(res.requestId, 'aws-request-1') assert.equal(res.statusCode, 200) }) -test('claude malformed responses work', async (ctx) => { - ctx.nr.bedrockCommand.isClaude = () => true - const res = new BedrockResponse(ctx.nr) +test('claude malformed responses work', async (t) => { + t.nr.bedrockCommand.isClaude = () => true + const res = new BedrockResponse(t.nr) assert.deepStrictEqual(res.completions, []) assert.equal(res.finishReason, undefined) - assert.deepStrictEqual(res.headers, ctx.nr.response.response.headers) + assert.deepStrictEqual(res.headers, t.nr.response.response.headers) assert.equal(res.id, undefined) assert.equal(res.requestId, 'aws-request-1') assert.equal(res.statusCode, 200) }) -test('claude complete responses work', async (ctx) => { - ctx.nr.bedrockCommand.isClaude = () => true - ctx.nr.updatePayload(structuredClone(claude)) - const res = new BedrockResponse(ctx.nr) +test('claude complete responses work', async (t) => { + t.nr.bedrockCommand.isClaude = () => true + t.nr.updatePayload(structuredClone(claude)) + const res = new BedrockResponse(t.nr) assert.deepStrictEqual(res.completions, ['claude-response']) assert.equal(res.finishReason, 'done') - assert.deepStrictEqual(res.headers, ctx.nr.response.response.headers) + assert.deepStrictEqual(res.headers, t.nr.response.response.headers) assert.equal(res.id, undefined) assert.equal(res.requestId, 'aws-request-1') assert.equal(res.statusCode, 200) }) -test('cohere malformed responses work', async (ctx) => { - ctx.nr.bedrockCommand.isCohere = () => true - const res = new BedrockResponse(ctx.nr) +test('cohere malformed responses work', async (t) => { + t.nr.bedrockCommand.isCohere = () => true + const res = new BedrockResponse(t.nr) assert.deepStrictEqual(res.completions, []) assert.equal(res.finishReason, undefined) - assert.deepStrictEqual(res.headers, ctx.nr.response.response.headers) + assert.deepStrictEqual(res.headers, t.nr.response.response.headers) assert.equal(res.id, undefined) assert.equal(res.requestId, 'aws-request-1') assert.equal(res.statusCode, 200) }) -test('cohere complete responses work', async (ctx) => { - ctx.nr.bedrockCommand.isCohere = () => true - ctx.nr.updatePayload(structuredClone(cohere)) - const res = new BedrockResponse(ctx.nr) +test('cohere complete responses work', async (t) => { + t.nr.bedrockCommand.isCohere = () => true + t.nr.updatePayload(structuredClone(cohere)) + const res = new BedrockResponse(t.nr) assert.deepStrictEqual(res.completions, ['cohere-response']) assert.equal(res.finishReason, 'done') - assert.deepStrictEqual(res.headers, ctx.nr.response.response.headers) + assert.deepStrictEqual(res.headers, t.nr.response.response.headers) assert.equal(res.id, 'cohere-response-1') assert.equal(res.requestId, 'aws-request-1') assert.equal(res.statusCode, 200) }) -test('llama malformed responses work', async (ctx) => { - ctx.nr.bedrockCommand.isLlama = () => true - const res = new BedrockResponse(ctx.nr) +test('llama malformed responses work', async (t) => { + t.nr.bedrockCommand.isLlama = () => true + const res = new BedrockResponse(t.nr) assert.deepStrictEqual(res.completions, []) assert.equal(res.finishReason, undefined) - assert.deepStrictEqual(res.headers, ctx.nr.response.response.headers) + assert.deepStrictEqual(res.headers, t.nr.response.response.headers) assert.equal(res.id, undefined) assert.equal(res.requestId, 'aws-request-1') assert.equal(res.statusCode, 200) }) -test('llama complete responses work', async (ctx) => { - ctx.nr.bedrockCommand.isLlama = () => true - ctx.nr.updatePayload(structuredClone(llama)) - const res = new BedrockResponse(ctx.nr) +test('llama complete responses work', async (t) => { + t.nr.bedrockCommand.isLlama = () => true + t.nr.updatePayload(structuredClone(llama)) + const res = new BedrockResponse(t.nr) assert.deepStrictEqual(res.completions, ['llama-response']) assert.equal(res.finishReason, 'done') - assert.deepStrictEqual(res.headers, ctx.nr.response.response.headers) + assert.deepStrictEqual(res.headers, t.nr.response.response.headers) assert.equal(res.id, undefined) assert.equal(res.requestId, 'aws-request-1') assert.equal(res.statusCode, 200) }) -test('titan malformed responses work', async (ctx) => { - ctx.nr.bedrockCommand.isTitan = () => true - const res = new BedrockResponse(ctx.nr) +test('titan malformed responses work', async (t) => { + t.nr.bedrockCommand.isTitan = () => true + const res = new BedrockResponse(t.nr) assert.deepStrictEqual(res.completions, []) assert.equal(res.finishReason, undefined) - assert.deepStrictEqual(res.headers, ctx.nr.response.response.headers) + assert.deepStrictEqual(res.headers, t.nr.response.response.headers) assert.equal(res.id, undefined) assert.equal(res.requestId, 'aws-request-1') assert.equal(res.statusCode, 200) }) -test('titan complete responses work', async (ctx) => { - ctx.nr.bedrockCommand.isTitan = () => true - ctx.nr.updatePayload(structuredClone(titan)) - const res = new BedrockResponse(ctx.nr) +test('titan complete responses work', async (t) => { + t.nr.bedrockCommand.isTitan = () => true + t.nr.updatePayload(structuredClone(titan)) + const res = new BedrockResponse(t.nr) assert.deepStrictEqual(res.completions, ['titan-response']) assert.equal(res.finishReason, 'done') - assert.deepStrictEqual(res.headers, ctx.nr.response.response.headers) + assert.deepStrictEqual(res.headers, t.nr.response.response.headers) assert.equal(res.id, undefined) assert.equal(res.requestId, 'aws-request-1') assert.equal(res.statusCode, 200) }) -test('should only set data from raw response on error', (ctx) => { - ctx.nr.response.$response = { ...ctx.nr.response.response } - delete ctx.nr.response.response - delete ctx.nr.response.output - ctx.nr.isError = true - const res = new BedrockResponse(ctx.nr) +test('should only set data from raw response on error', (t) => { + t.nr.response.$response = { ...t.nr.response.response } + delete t.nr.response.response + delete t.nr.response.output + t.nr.isError = true + const res = new BedrockResponse(t.nr) assert.deepStrictEqual(res.completions, []) assert.equal(res.id, undefined) assert.equal(res.finishReason, undefined) - assert.deepStrictEqual(res.headers, ctx.nr.response.$response.headers) + assert.deepStrictEqual(res.headers, t.nr.response.$response.headers) assert.equal(res.requestId, 'aws-request-1') assert.equal(res.statusCode, 200) }) diff --git a/test/unit/llm-events/aws-bedrock/chat-completion-message.test.js b/test/unit/llm-events/aws-bedrock/chat-completion-message.test.js index d4c8400007..4e484e84e6 100644 --- a/test/unit/llm-events/aws-bedrock/chat-completion-message.test.js +++ b/test/unit/llm-events/aws-bedrock/chat-completion-message.test.js @@ -90,9 +90,9 @@ test.beforeEach((ctx) => { } }) -test('create creates a non-response instance', async (ctx) => { - ctx.nr.agent.llm.tokenCountCallback = () => 3 - const event = new LlmChatCompletionMessage(ctx.nr) +test('create creates a non-response instance', async (t) => { + t.nr.agent.llm.tokenCountCallback = () => 3 + const event = new LlmChatCompletionMessage(t.nr) assert.equal(event.is_response, false) assert.equal(event['llm.conversation_id'], 'conversation-1') assert.equal(event.completion_id, 'completion-1') @@ -103,11 +103,11 @@ test('create creates a non-response instance', async (ctx) => { assert.equal(event.token_count, 3) }) -test('create creates a titan response instance', async (ctx) => { - ctx.nr.bedrockCommand.isTitan = () => true - ctx.nr.content = 'a response' - ctx.nr.isResponse = true - const event = new LlmChatCompletionMessage(ctx.nr) +test('create creates a titan response instance', async (t) => { + t.nr.bedrockCommand.isTitan = () => true + t.nr.content = 'a response' + t.nr.isResponse = true + const event = new LlmChatCompletionMessage(t.nr) assert.equal(event.is_response, true) assert.equal(event['llm.conversation_id'], 'conversation-1') assert.equal(event.completion_id, 'completion-1') @@ -117,12 +117,12 @@ test('create creates a titan response instance', async (ctx) => { assert.match(event.id, /[\w-]{36}-0/) }) -test('create creates a cohere response instance', async (ctx) => { - ctx.nr.bedrockCommand.isCohere = () => true - ctx.nr.content = 'a response' - ctx.nr.isResponse = true - ctx.nr.bedrockResponse.id = 42 - const event = new LlmChatCompletionMessage(ctx.nr) +test('create creates a cohere response instance', async (t) => { + t.nr.bedrockCommand.isCohere = () => true + t.nr.content = 'a response' + t.nr.isResponse = true + t.nr.bedrockResponse.id = 42 + const event = new LlmChatCompletionMessage(t.nr) assert.equal(event.is_response, true) assert.equal(event['llm.conversation_id'], 'conversation-1') assert.equal(event.completion_id, 'completion-1') @@ -132,12 +132,12 @@ test('create creates a cohere response instance', async (ctx) => { assert.match(event.id, /42-0/) }) -test('create creates a ai21 response instance when response.id is undefined', async (ctx) => { - ctx.nr.bedrockCommand.isAi21 = () => true - ctx.nr.content = 'a response' - ctx.nr.isResponse = true - delete ctx.nr.bedrockResponse.id - const event = new LlmChatCompletionMessage(ctx.nr) +test('create creates a ai21 response instance when response.id is undefined', async (t) => { + t.nr.bedrockCommand.isAi21 = () => true + t.nr.content = 'a response' + t.nr.isResponse = true + delete t.nr.bedrockResponse.id + const event = new LlmChatCompletionMessage(t.nr) assert.equal(event.is_response, true) assert.equal(event['llm.conversation_id'], 'conversation-1') assert.equal(event.completion_id, 'completion-1') @@ -147,9 +147,9 @@ test('create creates a ai21 response instance when response.id is undefined', as assert.match(event.id, /[\w-]{36}-0/) }) -test('should not capture content when `ai_monitoring.record_content.enabled` is false', async (ctx) => { - const { agent } = ctx.nr +test('should not capture content when `ai_monitoring.record_content.enabled` is false', async (t) => { + const { agent } = t.nr agent.config.ai_monitoring.record_content.enabled = false - const event = new LlmChatCompletionMessage(ctx.nr) + const event = new LlmChatCompletionMessage(t.nr) assert.equal(event.content, undefined, 'content should be empty') }) diff --git a/test/unit/llm-events/aws-bedrock/chat-completion-summary.test.js b/test/unit/llm-events/aws-bedrock/chat-completion-summary.test.js index 2b99216bcb..0bc79f281f 100644 --- a/test/unit/llm-events/aws-bedrock/chat-completion-summary.test.js +++ b/test/unit/llm-events/aws-bedrock/chat-completion-summary.test.js @@ -79,10 +79,10 @@ test.beforeEach((ctx) => { } }) -test('creates a basic summary', async (ctx) => { - ctx.nr.bedrockResponse.inputTokenCount = 0 - ctx.nr.bedrockResponse.outputTokenCount = 0 - const event = new LlmChatCompletionSummary(ctx.nr) +test('creates a basic summary', async (t) => { + t.nr.bedrockResponse.inputTokenCount = 0 + t.nr.bedrockResponse.outputTokenCount = 0 + const event = new LlmChatCompletionSummary(t.nr) assert.equal(event['llm.conversation_id'], 'conversation-1') assert.equal(event.duration, 100) assert.equal(event['request.max_tokens'], 25) @@ -91,9 +91,9 @@ test('creates a basic summary', async (ctx) => { assert.equal(event['response.number_of_messages'], 2) }) -test('creates an ai21 summary', async (ctx) => { - ctx.nr.bedrockCommand.isAi21 = () => true - const event = new LlmChatCompletionSummary(ctx.nr) +test('creates an ai21 summary', async (t) => { + t.nr.bedrockCommand.isAi21 = () => true + const event = new LlmChatCompletionSummary(t.nr) assert.equal(event['llm.conversation_id'], 'conversation-1') assert.equal(event.duration, 100) assert.equal(event['request.max_tokens'], 25) @@ -102,9 +102,9 @@ test('creates an ai21 summary', async (ctx) => { assert.equal(event['response.number_of_messages'], 2) }) -test('creates an claude summary', async (ctx) => { - ctx.nr.bedrockCommand.isClaude = () => true - const event = new LlmChatCompletionSummary(ctx.nr) +test('creates an claude summary', async (t) => { + t.nr.bedrockCommand.isClaude = () => true + const event = new LlmChatCompletionSummary(t.nr) assert.equal(event['llm.conversation_id'], 'conversation-1') assert.equal(event.duration, 100) assert.equal(event['request.max_tokens'], 25) @@ -113,9 +113,9 @@ test('creates an claude summary', async (ctx) => { assert.equal(event['response.number_of_messages'], 2) }) -test('creates a cohere summary', async (ctx) => { - ctx.nr.bedrockCommand.isCohere = () => true - const event = new LlmChatCompletionSummary(ctx.nr) +test('creates a cohere summary', async (t) => { + t.nr.bedrockCommand.isCohere = () => true + const event = new LlmChatCompletionSummary(t.nr) assert.equal(event['llm.conversation_id'], 'conversation-1') assert.equal(event.duration, 100) assert.equal(event['request.max_tokens'], 25) @@ -124,9 +124,9 @@ test('creates a cohere summary', async (ctx) => { assert.equal(event['response.number_of_messages'], 2) }) -test('creates a llama2 summary', async (ctx) => { - ctx.nr.bedrockCommand.isLlama2 = () => true - const event = new LlmChatCompletionSummary(ctx.nr) +test('creates a llama2 summary', async (t) => { + t.nr.bedrockCommand.isLlama2 = () => true + const event = new LlmChatCompletionSummary(t.nr) assert.equal(event['llm.conversation_id'], 'conversation-1') assert.equal(event.duration, 100) assert.equal(event['request.max_tokens'], 25) @@ -135,9 +135,9 @@ test('creates a llama2 summary', async (ctx) => { assert.equal(event['response.number_of_messages'], 2) }) -test('creates a titan summary', async (ctx) => { - ctx.nr.bedrockCommand.isTitan = () => true - const event = new LlmChatCompletionSummary(ctx.nr) +test('creates a titan summary', async (t) => { + t.nr.bedrockCommand.isTitan = () => true + const event = new LlmChatCompletionSummary(t.nr) assert.equal(event['llm.conversation_id'], 'conversation-1') assert.equal(event.duration, 100) assert.equal(event['request.max_tokens'], 25) diff --git a/test/unit/llm-events/aws-bedrock/embedding.test.js b/test/unit/llm-events/aws-bedrock/embedding.test.js index 4fe6ac1c02..801e7f64a4 100644 --- a/test/unit/llm-events/aws-bedrock/embedding.test.js +++ b/test/unit/llm-events/aws-bedrock/embedding.test.js @@ -62,22 +62,22 @@ test.beforeEach((ctx) => { } }) -test('creates a basic embedding', async (ctx) => { - const event = new LlmEmbedding(ctx.nr) +test('creates a basic embedding', async (t) => { + const event = new LlmEmbedding(t.nr) assert.equal(event.input, 'who are you') assert.equal(event.duration, 1.008) assert.equal(event.token_count, undefined) }) -test('should not capture input when `ai_monitoring.record_content.enabled` is false', async (ctx) => { - const { agent } = ctx.nr +test('should not capture input when `ai_monitoring.record_content.enabled` is false', async (t) => { + const { agent } = t.nr agent.config.ai_monitoring.record_content.enabled = false - const event = new LlmEmbedding(ctx.nr) + const event = new LlmEmbedding(t.nr) assert.equal(event.input, undefined, 'input should be empty') }) -test('should capture token_count when callback is defined', async (ctx) => { - ctx.nr.agent.llm.tokenCountCallback = () => 3 - const event = new LlmEmbedding(ctx.nr) +test('should capture token_count when callback is defined', async (t) => { + t.nr.agent.llm.tokenCountCallback = () => 3 + const event = new LlmEmbedding(t.nr) assert.equal(event.token_count, 3) }) diff --git a/test/unit/llm-events/aws-bedrock/error.test.js b/test/unit/llm-events/aws-bedrock/error.test.js index 6314199125..e589b384ba 100644 --- a/test/unit/llm-events/aws-bedrock/error.test.js +++ b/test/unit/llm-events/aws-bedrock/error.test.js @@ -25,8 +25,8 @@ test.beforeEach((ctx) => { } }) -test('create creates a new instance', (ctx) => { - const err = new LlmError(ctx.nr) +test('create creates a new instance', (t) => { + const err = new LlmError(t.nr) assert.equal(err['http.statusCode'], 400) assert.equal(err['error.message'], 'No soup for you') assert.equal(err['error.code'], 'SoupRule') @@ -34,10 +34,10 @@ test('create creates a new instance', (ctx) => { assert.ok(!err.embedding_id) }) -test('create error with embedding_id', (ctx) => { - delete ctx.nr.summary - ctx.nr.embedding = { id: 'embedding-id' } - const err = new LlmError(ctx.nr) +test('create error with embedding_id', (t) => { + delete t.nr.summary + t.nr.embedding = { id: 'embedding-id' } + const err = new LlmError(t.nr) assert.equal(err['http.statusCode'], 400) assert.equal(err['error.message'], 'No soup for you') assert.equal(err['error.code'], 'SoupRule') diff --git a/test/unit/llm-events/aws-bedrock/event.test.js b/test/unit/llm-events/aws-bedrock/event.test.js index 9792abd860..1d062b0bee 100644 --- a/test/unit/llm-events/aws-bedrock/event.test.js +++ b/test/unit/llm-events/aws-bedrock/event.test.js @@ -55,8 +55,8 @@ test.beforeEach((ctx) => { } }) -test('create creates a new instance', async (ctx) => { - const event = new LlmEvent(ctx.nr) +test('create creates a new instance', async (t) => { + const event = new LlmEvent(t.nr) assert.ok(event) assert.match(event.id, /[a-z0-9]{7}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}/) assert.equal(event.vendor, 'bedrock') @@ -72,8 +72,8 @@ test('create creates a new instance', async (ctx) => { assert.equal(event.omit, undefined) }) -test('serializes the event', (ctx) => { - const event = new LlmEvent(ctx.nr) +test('serializes the event', (t) => { + const event = new LlmEvent(t.nr) event.serialize() assert.ok(!event.bedrockCommand) assert.ok(!event.bedrockResponse) diff --git a/test/unit/llm-events/aws-bedrock/stream-handler.test.js b/test/unit/llm-events/aws-bedrock/stream-handler.test.js index 39b136f988..a9762dfafe 100644 --- a/test/unit/llm-events/aws-bedrock/stream-handler.test.js +++ b/test/unit/llm-events/aws-bedrock/stream-handler.test.js @@ -74,20 +74,20 @@ test.beforeEach((ctx) => { /* eslint-enable prettier/prettier */ }) -test('unrecognized or unhandled model uses original stream', async (ctx) => { - ctx.nr.modelId = 'amazon.titan-embed-text-v1' - const handler = new StreamHandler(ctx.nr) +test('unrecognized or unhandled model uses original stream', async (t) => { + t.nr.modelId = 'amazon.titan-embed-text-v1' + const handler = new StreamHandler(t.nr) assert.equal(handler.generator.name, undefined) - assert.equal(handler.generator, ctx.nr.stream) + assert.equal(handler.generator, t.nr.stream) }) -test('handles claude streams', async (ctx) => { - ctx.nr.passThroughParams.bedrockCommand.isClaude = () => true - ctx.nr.chunks = [ +test('handles claude streams', async (t) => { + t.nr.passThroughParams.bedrockCommand.isClaude = () => true + t.nr.chunks = [ { completion: '1', stop_reason: null }, - { completion: '2', stop_reason: 'done', ...ctx.nr.metrics } + { completion: '2', stop_reason: 'done', ...t.nr.metrics } ] - const handler = new StreamHandler(ctx.nr) + const handler = new StreamHandler(t.nr) assert.equal(handler.generator.name, 'handleClaude') for await (const event of handler.generator()) { @@ -119,14 +119,14 @@ test('handles claude streams', async (ctx) => { assert.equal(br.statusCode, 200) }) -test('handles claude3streams', async (ctx) => { - ctx.nr.passThroughParams.bedrockCommand.isClaude3 = () => true - ctx.nr.chunks = [ +test('handles claude3streams', async (t) => { + t.nr.passThroughParams.bedrockCommand.isClaude3 = () => true + t.nr.chunks = [ { type: 'content_block_delta', delta: { type: 'text_delta', text: '42' } }, { type: 'message_delta', delta: { stop_reason: 'done' } }, - { type: 'message_stop', ...ctx.nr.metrics } + { type: 'message_stop', ...t.nr.metrics } ] - const handler = new StreamHandler(ctx.nr) + const handler = new StreamHandler(t.nr) assert.equal(handler.generator.name, 'handleClaude3') for await (const event of handler.generator()) { @@ -153,13 +153,13 @@ test('handles claude3streams', async (ctx) => { assert.equal(br.statusCode, 200) }) -test('handles cohere streams', async (ctx) => { - ctx.nr.passThroughParams.bedrockCommand.isCohere = () => true - ctx.nr.chunks = [ +test('handles cohere streams', async (t) => { + t.nr.passThroughParams.bedrockCommand.isCohere = () => true + t.nr.chunks = [ { generations: [{ text: '1', finish_reason: null }] }, - { generations: [{ text: '2', finish_reason: 'done' }], ...ctx.nr.metrics } + { generations: [{ text: '2', finish_reason: 'done' }], ...t.nr.metrics } ] - const handler = new StreamHandler(ctx.nr) + const handler = new StreamHandler(t.nr) assert.equal(handler.generator.name, 'handleCohere') for await (const event of handler.generator()) { @@ -198,18 +198,18 @@ test('handles cohere streams', async (ctx) => { assert.equal(br.statusCode, 200) }) -test('handles cohere embedding streams', async (ctx) => { - ctx.nr.passThroughParams.bedrockCommand.isCohereEmbed = () => true - ctx.nr.chunks = [ +test('handles cohere embedding streams', async (t) => { + t.nr.passThroughParams.bedrockCommand.isCohereEmbed = () => true + t.nr.chunks = [ { embeddings: [ [1, 2], [3, 4] ], - ...ctx.nr.metrics + ...t.nr.metrics } ] - const handler = new StreamHandler(ctx.nr) + const handler = new StreamHandler(t.nr) assert.equal(handler.generator.name, 'handleCohereEmbed') for await (const event of handler.generator()) { @@ -248,13 +248,13 @@ test('handles cohere embedding streams', async (ctx) => { assert.equal(br.statusCode, 200) }) -test('handles llama streams', async (ctx) => { - ctx.nr.passThroughParams.bedrockCommand.isLlama = () => true - ctx.nr.chunks = [ +test('handles llama streams', async (t) => { + t.nr.passThroughParams.bedrockCommand.isLlama = () => true + t.nr.chunks = [ { generation: '1', stop_reason: null }, - { generation: '2', stop_reason: 'done', ...ctx.nr.metrics } + { generation: '2', stop_reason: 'done', ...t.nr.metrics } ] - const handler = new StreamHandler(ctx.nr) + const handler = new StreamHandler(t.nr) assert.equal(handler.generator.name, 'handleLlama') for await (const event of handler.generator()) { @@ -286,13 +286,13 @@ test('handles llama streams', async (ctx) => { assert.equal(br.statusCode, 200) }) -test('handles titan streams', async (ctx) => { - ctx.nr.passThroughParams.bedrockCommand.isTitan = () => true - ctx.nr.chunks = [ +test('handles titan streams', async (t) => { + t.nr.passThroughParams.bedrockCommand.isTitan = () => true + t.nr.chunks = [ { outputText: '1', completionReason: null }, - { outputText: '2', completionReason: 'done', ...ctx.nr.metrics } + { outputText: '2', completionReason: 'done', ...t.nr.metrics } ] - const handler = new StreamHandler(ctx.nr) + const handler = new StreamHandler(t.nr) assert.equal(handler.generator.name, 'handleTitan') for await (const event of handler.generator()) { diff --git a/test/unit/llm-events/langchain/chat-completion-message.test.js b/test/unit/llm-events/langchain/chat-completion-message.test.js index f01cba0eb7..78dfe19f9b 100644 --- a/test/unit/llm-events/langchain/chat-completion-message.test.js +++ b/test/unit/llm-events/langchain/chat-completion-message.test.js @@ -52,9 +52,9 @@ test.beforeEach((ctx) => { ctx.nr.metadata = { foo: 'foo' } }) -test('creates entity', async (ctx) => { +test('creates entity', async (t) => { const msg = new LangChainCompletionMessage({ - ...ctx.nr, + ...t.nr, sequence: 1, content: 'hello world' }) @@ -73,18 +73,18 @@ test('creates entity', async (ctx) => { assert.match(msg.completion_id, /[a-z0-9-]{36}/) }) -test('assigns id correctly', async (ctx) => { - let msg = new LangChainCompletionMessage({ ...ctx.nr, runId: '', sequence: 1 }) +test('assigns id correctly', async (t) => { + let msg = new LangChainCompletionMessage({ ...t.nr, runId: '', sequence: 1 }) assert.match(msg.id, /[a-z0-9-]{36}-1/) - msg = new LangChainCompletionMessage({ ...ctx.nr, runId: '123456', sequence: 42 }) + msg = new LangChainCompletionMessage({ ...t.nr, runId: '123456', sequence: 42 }) assert.equal(msg.id, '123456-42') }) -test('respects record_content setting', async (ctx) => { - ctx.nr.agent.config.ai_monitoring.record_content.enabled = false +test('respects record_content setting', async (t) => { + t.nr.agent.config.ai_monitoring.record_content.enabled = false const search = new LangChainCompletionMessage({ - ...ctx.nr, + ...t.nr, sequence: 1, content: 'hello world' }) diff --git a/test/unit/llm-events/langchain/chat-completion-summary.test.js b/test/unit/llm-events/langchain/chat-completion-summary.test.js index 324ae08fc6..83d770fcad 100644 --- a/test/unit/llm-events/langchain/chat-completion-summary.test.js +++ b/test/unit/llm-events/langchain/chat-completion-summary.test.js @@ -50,8 +50,8 @@ test.beforeEach((ctx) => { ctx.nr.metadata = { foo: 'foo' } }) -test('creates entity', async (ctx) => { - const msg = new LangChainCompletionSummary(ctx.nr) +test('creates entity', async (t) => { + const msg = new LangChainCompletionSummary(t.nr) assert.match(msg.id, /[a-z0-9-]{36}/) assert.equal(msg.appName, 'test-app') assert.equal(msg['llm.conversation_id'], 'test-conversation') diff --git a/test/unit/llm-events/langchain/event.test.js b/test/unit/llm-events/langchain/event.test.js index edfa42da85..2fe2d064d8 100644 --- a/test/unit/llm-events/langchain/event.test.js +++ b/test/unit/llm-events/langchain/event.test.js @@ -50,8 +50,8 @@ test.beforeEach((ctx) => { ctx.nr.metadata = { foo: 'foo' } }) -test('constructs default instance', async (ctx) => { - const event = new LangChainEvent(ctx.nr) +test('constructs default instance', async (t) => { + const event = new LangChainEvent(t.nr) assert.match(event.id, /[a-z0-9-]{36}/) assert.equal(event.appName, 'test-app') assert.equal(event['llm.conversation_id'], 'test-conversation') @@ -65,46 +65,46 @@ test('constructs default instance', async (ctx) => { assert.equal(event.virtual_llm, true) }) -test('params.virtual is handled correctly', async (ctx) => { - const event = new LangChainEvent({ ...ctx.nr, virtual: false }) +test('params.virtual is handled correctly', async (t) => { + const event = new LangChainEvent({ ...t.nr, virtual: false }) assert.equal(event.virtual_llm, false) try { - const _ = new LangChainEvent({ ...ctx.nr, virtual: 'false' }) + const _ = new LangChainEvent({ ...t.nr, virtual: 'false' }) assert.fail(_) } catch (error) { assert.equal(error.message, 'params.virtual must be a primitive boolean') } }) -test('langchainMeta is parsed correctly', async (ctx) => { - const event = new LangChainEvent(ctx.nr) +test('langchainMeta is parsed correctly', async (t) => { + const event = new LangChainEvent(t.nr) event.langchainMeta = 'foobar' assert.deepStrictEqual(event['metadata.foo'], 'foo') assert.equal(Object.keys(event).filter((k) => k.startsWith('metadata.')).length, 1) }) -test('metadata is parsed correctly', async (ctx) => { - const event = new LangChainEvent(ctx.nr) +test('metadata is parsed correctly', async (t) => { + const event = new LangChainEvent(t.nr) assert.equal(event['llm.foo'], 'bar') assert.equal(event['llm.bar'], 'baz') assert.ok(!event.customKey) }) -test('sets tags from array', async (ctx) => { - ctx.nr.tags = ['foo', 'bar'] - const msg = new LangChainEvent(ctx.nr) +test('sets tags from array', async (t) => { + t.nr.tags = ['foo', 'bar'] + const msg = new LangChainEvent(t.nr) assert.equal(msg.tags, 'foo,bar') }) -test('sets tags from string', async (ctx) => { - ctx.nr.tags = 'foo,bar' - const msg = new LangChainEvent(ctx.nr) +test('sets tags from string', async (t) => { + t.nr.tags = 'foo,bar' + const msg = new LangChainEvent(t.nr) assert.equal(msg.tags, 'foo,bar') }) -test('sets error property', async (ctx) => { - ctx.nr.error = true - const msg = new LangChainEvent(ctx.nr) +test('sets error property', async (t) => { + t.nr.error = true + const msg = new LangChainEvent(t.nr) assert.equal(msg.error, true) }) diff --git a/test/unit/llm-events/langchain/tool.test.js b/test/unit/llm-events/langchain/tool.test.js index f01547f4cc..639a4a7b22 100644 --- a/test/unit/llm-events/langchain/tool.test.js +++ b/test/unit/llm-events/langchain/tool.test.js @@ -59,8 +59,8 @@ test.beforeEach((ctx) => { ctx.nr.output = 'output' }) -test('constructs default instance', async (ctx) => { - const event = new LangChainTool(ctx.nr) +test('constructs default instance', async (t) => { + const event = new LangChainTool(t.nr) assert.equal(event.input, 'input') assert.equal(event.output, 'output') assert.equal(event.name, 'test-tool') @@ -76,9 +76,9 @@ test('constructs default instance', async (ctx) => { assert.equal(event.vendor, 'langchain') }) -test('respects record_content setting', async (ctx) => { - ctx.nr.agent.config.ai_monitoring.record_content.enabled = false - const event = new LangChainTool(ctx.nr) +test('respects record_content setting', async (t) => { + t.nr.agent.config.ai_monitoring.record_content.enabled = false + const event = new LangChainTool(t.nr) assert.equal(event.input, undefined) assert.equal(event.output, undefined) }) diff --git a/test/unit/llm-events/langchain/vector-search-result.test.js b/test/unit/llm-events/langchain/vector-search-result.test.js index e7e4526a7a..7189d32d90 100644 --- a/test/unit/llm-events/langchain/vector-search-result.test.js +++ b/test/unit/llm-events/langchain/vector-search-result.test.js @@ -56,15 +56,15 @@ test.beforeEach((ctx) => { ctx.nr.metadata = { foo: 'foo' } }) -test('create entity', async (ctx) => { +test('create entity', async (t) => { const search = new LangChainVectorSearch({ - ...ctx.nr, + ...t.nr, query: 'hello world', k: 1 }) const searchResult = new LangChainVectorSearchResult({ - ...ctx.nr, + ...t.nr, sequence: 1, pageContent: 'hello world', search_id: search.id @@ -84,10 +84,10 @@ test('create entity', async (ctx) => { assert.equal(searchResult.search_id, search.id) }) -test('respects record_content setting', async (ctx) => { - ctx.nr.agent.config.ai_monitoring.record_content.enabled = false +test('respects record_content setting', async (t) => { + t.nr.agent.config.ai_monitoring.record_content.enabled = false const search = new LangChainVectorSearchResult({ - ...ctx.nr, + ...t.nr, sequence: 1, pageContent: 'hello world' }) diff --git a/test/unit/llm-events/langchain/vector-search.test.js b/test/unit/llm-events/langchain/vector-search.test.js index 0eb9631d7a..73c04a938f 100644 --- a/test/unit/llm-events/langchain/vector-search.test.js +++ b/test/unit/llm-events/langchain/vector-search.test.js @@ -53,9 +53,9 @@ test.beforeEach((ctx) => { ctx.nr.runId = 'run-1' }) -test('create entity', async (ctx) => { +test('create entity', async (t) => { const search = new LangChainVectorSearch({ - ...ctx.nr, + ...t.nr, query: 'hello world', k: 1 }) @@ -74,10 +74,10 @@ test('create entity', async (ctx) => { assert.equal(search['response.number_of_documents'], 0) }) -test('respects record_content setting', async (ctx) => { - ctx.nr.agent.config.ai_monitoring.record_content.enabled = false +test('respects record_content setting', async (t) => { + t.nr.agent.config.ai_monitoring.record_content.enabled = false const search = new LangChainVectorSearch({ - ...ctx.nr, + ...t.nr, k: 1, query: 'hello world' }) diff --git a/test/unit/llm-events/openai/chat-completion-message.test.js b/test/unit/llm-events/openai/chat-completion-message.test.js index bfaa49ab28..f727cd35d7 100644 --- a/test/unit/llm-events/openai/chat-completion-message.test.js +++ b/test/unit/llm-events/openai/chat-completion-message.test.js @@ -20,8 +20,8 @@ test.afterEach((ctx) => { helper.unloadAgent(ctx.nr.agent) }) -test('should create a LlmChatCompletionMessage event', (ctx, end) => { - const { agent } = ctx.nr +test('should create a LlmChatCompletionMessage event', (t, end) => { + const { agent } = t.nr const api = helper.getAgentApi() helper.runInTransaction(agent, (tx) => { api.startSegment('fakeSegment', false, () => { @@ -43,8 +43,8 @@ test('should create a LlmChatCompletionMessage event', (ctx, end) => { }) }) -test('should create a LlmChatCompletionMessage from response choices', (ctx, end) => { - const { agent } = ctx.nr +test('should create a LlmChatCompletionMessage from response choices', (t, end) => { + const { agent } = t.nr const api = helper.getAgentApi() helper.runInTransaction(agent, (tx) => { api.startSegment('fakeSegment', false, () => { @@ -70,8 +70,8 @@ test('should create a LlmChatCompletionMessage from response choices', (ctx, end }) }) -test('should set conversation_id from custom attributes', (ctx, end) => { - const { agent } = ctx.nr +test('should set conversation_id from custom attributes', (t, end) => { + const { agent } = t.nr const api = helper.getAgentApi() const conversationId = 'convo-id' helper.runInTransaction(agent, () => { @@ -87,8 +87,8 @@ test('should set conversation_id from custom attributes', (ctx, end) => { }) }) -test('respects record_content', (ctx, end) => { - const { agent } = ctx.nr +test('respects record_content', (t, end) => { + const { agent } = t.nr const api = helper.getAgentApi() const conversationId = 'convo-id' agent.config.ai_monitoring.record_content.enabled = false @@ -106,8 +106,8 @@ test('respects record_content', (ctx, end) => { }) }) -test('should use token_count from tokenCountCallback for prompt message', (ctx, end) => { - const { agent } = ctx.nr +test('should use token_count from tokenCountCallback for prompt message', (t, end) => { + const { agent } = t.nr const api = helper.getAgentApi() const expectedCount = 4 function cb(model, content) { @@ -136,8 +136,8 @@ test('should use token_count from tokenCountCallback for prompt message', (ctx, }) }) -test('should use token_count from tokenCountCallback for completion messages', (ctx, end) => { - const { agent } = ctx.nr +test('should use token_count from tokenCountCallback for completion messages', (t, end) => { + const { agent } = t.nr const api = helper.getAgentApi() const expectedCount = 4 function cb(model, content) { @@ -166,8 +166,8 @@ test('should use token_count from tokenCountCallback for completion messages', ( }) }) -test('should not set token_count if not set in usage nor a callback registered', (ctx, end) => { - const { agent } = ctx.nr +test('should not set token_count if not set in usage nor a callback registered', (t, end) => { + const { agent } = t.nr const api = helper.getAgentApi() helper.runInTransaction(agent, () => { api.startSegment('fakeSegment', false, () => { @@ -189,8 +189,8 @@ test('should not set token_count if not set in usage nor a callback registered', }) }) -test('should not set token_count if not set in usage nor a callback registered returns count', (ctx, end) => { - const { agent } = ctx.nr +test('should not set token_count if not set in usage nor a callback registered returns count', (t, end) => { + const { agent } = t.nr const api = helper.getAgentApi() function cb() { // empty cb diff --git a/test/unit/llm-events/openai/chat-completion-summary.test.js b/test/unit/llm-events/openai/chat-completion-summary.test.js index f1e7b907bc..ca9e24823a 100644 --- a/test/unit/llm-events/openai/chat-completion-summary.test.js +++ b/test/unit/llm-events/openai/chat-completion-summary.test.js @@ -20,8 +20,8 @@ test.afterEach((ctx) => { helper.unloadAgent(ctx.nr.agent) }) -test('should properly create a LlmChatCompletionSummary event', (ctx, end) => { - const { agent } = ctx.nr +test('should properly create a LlmChatCompletionSummary event', (t, end) => { + const { agent } = t.nr const api = helper.getAgentApi() helper.runInTransaction(agent, (tx) => { api.startSegment('fakeSegment', false, () => { @@ -55,8 +55,8 @@ test('should set error to true', (ctx, end) => { }) }) -test('should set `llm.` attributes from custom attributes', (ctx, end) => { - const { agent } = ctx.nr +test('should set `llm.` attributes from custom attributes', (t, end) => { + const { agent } = t.nr const api = helper.getAgentApi() const conversationId = 'convo-id' helper.runInTransaction(agent, () => { diff --git a/test/unit/llm-events/openai/embedding.test.js b/test/unit/llm-events/openai/embedding.test.js index bc291dd510..ca8f3d75ae 100644 --- a/test/unit/llm-events/openai/embedding.test.js +++ b/test/unit/llm-events/openai/embedding.test.js @@ -20,8 +20,8 @@ test.afterEach((ctx) => { helper.unloadAgent(ctx.nr.agent) }) -test('should properly create a LlmEmbedding event', (ctx, end) => { - const { agent } = ctx.nr +test('should properly create a LlmEmbedding event', (t, end) => { + const { agent } = t.nr const req = { input: 'This is my test input', model: 'gpt-3.5-turbo-0613' @@ -57,8 +57,8 @@ test('should properly create a LlmEmbedding event', (ctx, end) => { expected: '1,2,3,4,5,6' } ].forEach(({ type, value, expected }) => { - test(`should properly serialize input when it is a ${type}`, (ctx, end) => { - const { agent } = ctx.nr + test(`should properly serialize input when it is a ${type}`, (t, end) => { + const { agent } = t.nr const embeddingEvent = new LlmEmbedding({ agent, segment: null, @@ -70,8 +70,8 @@ test('should properly create a LlmEmbedding event', (ctx, end) => { }) }) -test('should set error to true', (ctx, end) => { - const { agent } = ctx.nr +test('should set error to true', (t, end) => { + const { agent } = t.nr const req = { input: 'This is my test input', model: 'gpt-3.5-turbo-0613' @@ -94,8 +94,8 @@ test('should set error to true', (ctx, end) => { }) }) -test('respects record_content', (ctx, end) => { - const { agent } = ctx.nr +test('respects record_content', (t, end) => { + const { agent } = t.nr const req = { input: 'This is my test input', model: 'gpt-3.5-turbo-0613' @@ -116,8 +116,8 @@ test('respects record_content', (ctx, end) => { }) }) -test('should calculate token count from tokenCountCallback', (ctx, end) => { - const { agent } = ctx.nr +test('should calculate token count from tokenCountCallback', (t, end) => { + const { agent } = t.nr const req = { input: 'This is my test input', model: 'gpt-3.5-turbo-0613' @@ -146,8 +146,8 @@ test('should calculate token count from tokenCountCallback', (ctx, end) => { }) }) -test('should not set token count when not present in usage nor tokenCountCallback', (ctx, end) => { - const { agent } = ctx.nr +test('should not set token count when not present in usage nor tokenCountCallback', (t, end) => { + const { agent } = t.nr const req = { input: 'This is my test input', model: 'gpt-3.5-turbo-0613'