🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
test: isolate cache mutation suites and skip webhook retry waits (#17232)
Tobias Wochinger38ef29d6b11a
diff --git a/web/src/__tests__/server/admin-api-keys.servertest.ts b/web/src/__tests__/server/admin-api-keys.servertest.tsindex ba59dc5361..94fdd7c90a 100644--- a/web/src/__tests__/server/admin-api-keys.servertest.ts+++ b/web/src/__tests__/server/admin-api-keys.servertest.ts@@ -1,6 +1,9 @@+import { randomUUID } from "node:crypto";+import { vi } from "vitest";import type { NextApiRequest, NextApiResponse } from "next";import { createMocks } from "node-mocks-http";import { env } from "@/src/env.mjs";+import type * as SharedServer from "@langfuse/shared/src/server";import {API_KEY_CACHE_PATTERN,createApiKeyCacheKey,@@ -9,12 +12,24 @@ import {import handler from "../../pages/api/admin/api-keys";import {clearRedisKeysByPatternSafely,+ createRedisTestClient,ensureRedisReady,getRedisValue,setRedisValue,type RedisTestClient,} from "@/src/__tests__/server/redis-test-utils";+vi.mock("@langfuse/shared/src/server", async (importOriginal) => {+ const actual = await importOriginal<typeof SharedServer>();+ const { randomUUID } = await import("node:crypto");+ return {+ ...actual,+ redis: actual.createNewRedisInstance({+ keyPrefix: `admin-api-keys-test:${randomUUID()}:`,+ }),+ };+});+describe("Admin API keys route", () => {const ADMIN_API_KEY = "test-admin-api-key";const originalAdminApiKey = env.ADMIN_API_KEY;@@ -46,9 +61,14 @@ describe("Admin API keys route", () => {await clearRedisKeysByPatternSafely(redisClient, "other-cache:*");});- afterAll(() => {+ afterAll(async () => {(env as any).ADMIN_API_KEY = originalAdminApiKey;(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalCloudRegion;+ redis?.disconnect();+ const actual = await vi.importActual<typeof SharedServer>(+ "@langfuse/shared/src/server",+ );+ actual.redis?.disconnect();});it("invalidates all cached API keys without deleting other redis entries", async () => {@@ -74,19 +94,32 @@ describe("Admin API keys route", () => {},});- await handler(req, res);+ const otherClient = createRedisTestClient({ keyPrefix: "" });+ const otherApiKey = createApiKeyCacheKey(randomUUID());+ try {+ await setRedisValue(otherClient, otherApiKey, "other-suite");+ await handler(req, res);- expect(res._getStatusCode()).toBe(200);- const responseBody = res._getJSONData();- expect(responseBody).toEqual({- message: "All cached API keys invalidated",- invalidatedCount: expect.any(Number),- });- expect(responseBody.invalidatedCount).toBeGreaterThanOrEqual(2);- expect(await getRedisValue(redisClient, existingApiKeyCacheKey)).toBeNull();- expect(await getRedisValue(redisClient, missingApiKeyCacheKey)).toBeNull();- expect(await getRedisValue(redisClient, "other-cache:existing-key")).toBe(- "untouched",- );+ expect(await getRedisValue(otherClient, otherApiKey)).toBe("other-suite");+ expect(res._getStatusCode()).toBe(200);+ const responseBody = res._getJSONData();+ expect(responseBody).toEqual({+ message: "All cached API keys invalidated",+ invalidatedCount: expect.any(Number),+ });+ expect(responseBody.invalidatedCount).toBeGreaterThanOrEqual(2);+ expect(+ await getRedisValue(redisClient, existingApiKeyCacheKey),+ ).toBeNull();+ expect(+ await getRedisValue(redisClient, missingApiKeyCacheKey),+ ).toBeNull();+ expect(await getRedisValue(redisClient, "other-cache:existing-key")).toBe(+ "untouched",+ );+ } finally {+ await otherClient.del(otherApiKey);+ otherClient.disconnect();+ }});});diff --git a/web/src/__tests__/server/api-auth.servertest.ts b/web/src/__tests__/server/api-auth.servertest.tsindex 45dd820825..3673894347 100644--- a/web/src/__tests__/server/api-auth.servertest.ts+++ b/web/src/__tests__/server/api-auth.servertest.ts@@ -37,10 +37,12 @@ describe("Authenticate API calls", () => {};let testApiKey: TestApiKeyFixture;+ const cacheKeyPrefix = `api-auth-test:${v4()}:`;const createRedisClient = (): RedisTestClient => {return createRedisTestClient({maxRetriesPerRequest: null,+ keyPrefix: cacheKeyPrefix,});};@@ -419,6 +421,24 @@ describe("Authenticate API calls", () => {redis.disconnect();}, 20_000);+ it("clears only this suite's API-key cache entries", async () => {+ const otherClient = createRedisTestClient({ keyPrefix: "" });+ const ownKey = `api-key:${v4()}`;+ const otherKey = `api-key:${v4()}`;+ try {+ await setRedisValue(redis, ownKey, "owned");+ await setRedisValue(otherClient, otherKey, "other-suite");++ await clearApiKeyCacheSafely(redis);++ expect(await getRedisValue(redis, ownKey)).toBeNull();+ expect(await getRedisValue(otherClient, otherKey)).toBe("other-suite");+ } finally {+ await otherClient.del(otherKey);+ otherClient.disconnect();+ }+ });+it("should create new api key and read from cache", async () => {const legacySecretKey = ["legacy", "secret", "key", v4()].join("-");const legacyPublicKey = `legacy-public-key-${v4()}`;diff --git a/worker/src/__tests__/webhooks.test.ts b/worker/src/__tests__/webhooks.test.tsindex 785ba64f30..d79abb72ab 100644--- a/worker/src/__tests__/webhooks.test.ts+++ b/worker/src/__tests__/webhooks.test.ts@@ -9,6 +9,7 @@ import {vi,} from "vitest";import { v4 } from "uuid";+import { backOff } from "exponential-backoff";import {ActionExecutionStatus,JobConfigState,@@ -32,6 +33,18 @@ import { setupServer } from "msw/node";import { http, HttpResponse } from "msw";import { executeWebhook } from "../queues/webhooks";+vi.mock("exponential-backoff", async (importOriginal) => {+ const actual = await importOriginal<typeof import("exponential-backoff")>();+ return {+ ...actual,+ // State-transition tests exercise every HTTP attempt without waiting between them.+ // The endpoint-error test restores the real delays to cover the production policy.+ backOff: vi.fn((...args: Parameters<typeof actual.backOff>) =>+ actual.backOff(args[0], { ...args[1], startingDelay: 0 }),+ ),+ };+});+// Mock webhook server for testing HTTP requestsclass WebhookTestServer {private server;@@ -459,6 +472,11 @@ describe("Webhook Integration Tests", () => {});it("should handle webhook endpoint returning error", async () => {+ const actual = await vi.importActual<+ typeof import("exponential-backoff")+ >("exponential-backoff");+ vi.mocked(backOff).mockImplementationOnce(actual.backOff);+ vi.mocked(backOff).mockClear();const fullPrompt = await prisma.prompt.findUnique({where: { id: promptId },});@@ -519,6 +537,11 @@ describe("Webhook Integration Tests", () => {await executeWebhook(webhookInput, { skipValidation: true });+ expect(backOff).toHaveBeenCalledWith(expect.any(Function), {+ numOfAttempts: 4,+ });+ expect(webhookServer.getReceivedRequests()).toHaveLength(4);+// Verify execution was marked as errorconst execution = await prisma.automationExecution.findUnique({where: { id: executionId },