From 3de51b2f0d62acfddc42a80c654cd21c21848c31 Mon Sep 17 00:00:00 2001 From: Joe Eli McIlvain Date: Tue, 10 Dec 2024 09:26:54 -0800 Subject: [PATCH] fix: correctly pass through the `forceTool` option inside `KurtCache.generateRawEvents` Prior to this commit, that option was being silently dropped because it was neglected in the new object that gets sent to the internal adapter. This commit introduces a usage of the spread operator to ensure that no such options are dropped (while still allowing the replacement of other options). --- packages/kurt-cache/spec/KurtCache.spec.ts | 8 ++++++++ packages/kurt-cache/src/KurtCache.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/kurt-cache/spec/KurtCache.spec.ts b/packages/kurt-cache/spec/KurtCache.spec.ts index 7b79510..2118838 100644 --- a/packages/kurt-cache/spec/KurtCache.spec.ts +++ b/packages/kurt-cache/spec/KurtCache.spec.ts @@ -200,6 +200,14 @@ class StubAdapter } forceTool?: string }) { + // If there are tools, expect the forceTool to be set, because these tests + // don't use the "optional tools" feature. This lets us ensure that the + // forceTool is set correctly in the tests that use it. + if (Object.keys(options.tools).length > 0) { + expect(options.forceTool).toBeDefined() + } + + // Emit the next canned response. for (const bytes of this.nextCannedResponse()) { yield { bytes } } diff --git a/packages/kurt-cache/src/KurtCache.ts b/packages/kurt-cache/src/KurtCache.ts index 1b637eb..29ed8bc 100644 --- a/packages/kurt-cache/src/KurtCache.ts +++ b/packages/kurt-cache/src/KurtCache.ts @@ -143,8 +143,8 @@ export class KurtCache ), }, adapter.generateRawEvents({ + ...options, messages: adapter.transformToRawMessages(options.messages), - sampling: options.sampling, tools: Object.fromEntries( Object.entries(options.tools).map(([name, tool]) => [ name,