🪢 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
fix(api): don't let scores value operator override timestamp filters (#14217)
Niklas Semmler612725c49442
diff --git a/packages/shared/src/server/queries/public-api-filter-builder.ts b/packages/shared/src/server/queries/public-api-filter-builder.tsindex fdd319136b..c10a6127a8 100644--- a/packages/shared/src/server/queries/public-api-filter-builder.ts+++ b/packages/shared/src/server/queries/public-api-filter-builder.ts@@ -244,15 +244,11 @@ export function convertApiProvidedFilterToClickhouseFilter(let filterInstance;switch (columnMapping.filterType) {case "DateTimeFilter": {- // get filter options from the filterOperators- // validate that the user provided operator is in the list of available operators- const availableOperators = z.enum(filterOperators.datetime);- const parsedOperator = availableOperators.safeParse(filter.operator);-- // otherwise fall back to the operator provided in the column mapping- const finalOperator = parsedOperator.success- ? parsedOperator.data- : columnMapping.operator;+ // The operator of a datetime column is fixed in the column mapping+ // (e.g. fromTimestamp => ">=", toTimestamp => "<"). The user-provided+ // `operator` query param targets the value filter and must not+ // override it (#8630).+ const finalOperator = columnMapping.operator;finalOperator &&typeof value === "string" &&diff --git a/web/src/__tests__/server/scores-api-v1.servertest.ts b/web/src/__tests__/server/scores-api-v1.servertest.tsindex e59e6f2520..cc4806bef7 100644--- a/web/src/__tests__/server/scores-api-v1.servertest.ts+++ b/web/src/__tests__/server/scores-api-v1.servertest.ts@@ -1124,6 +1124,66 @@ describe("/api/public/scores API Endpoint", () => {);}});++ // Regression tests for #8630: the value operator must not override+ // the fixed >= / < operators of the fromTimestamp/toTimestamp filters.+ describe("operator combined with timestamp window", () => {+ const fromTimestamp = new Date(+ Date.now() - 24 * 60 * 60 * 1000,+ ).toISOString();+ const toTimestamp = new Date(+ Date.now() + 24 * 60 * 60 * 1000,+ ).toISOString();+ const timestampWindow = `fromTimestamp=${fromTimestamp}&toTimestamp=${toTimestamp}`;++ it("test operator > with timestamp window", async () => {+ const getScore = await makeZodVerifiedAPICall(+ GetScoresResponseV1,+ "GET",+ `/api/public/scores?${queryUserName}&operator=>&value=100&${timestampWindow}`,+ undefined,+ authentication,+ );+ expect(getScore.status).toBe(200);+ expect(getScore.body.meta).toMatchObject({+ page: 1,+ limit: 50,+ totalItems: 1,+ totalPages: 1,+ });+ expect(getScore.body.data).toMatchObject([+ {+ id: scoreId_3,+ name: scoreName,+ value: 100.8,+ },+ ]);+ });++ it("test operator < with timestamp window", async () => {+ const getScore = await makeZodVerifiedAPICall(+ GetScoresResponseV1,+ "GET",+ `/api/public/scores?${queryUserName}&operator=<&value=50&${timestampWindow}`,+ undefined,+ authentication,+ );+ expect(getScore.status).toBe(200);+ expect(getScore.body.meta).toMatchObject({+ page: 1,+ limit: 50,+ totalItems: 1,+ totalPages: 1,+ });+ expect(getScore.body.data).toMatchObject([+ {+ id: scoreId_1,+ name: scoreName,+ value: 10.5,+ },+ ]);+ });+ });});it("should filter scores by score IDs", async () => {diff --git a/web/src/__tests__/server/scores-api-v2.servertest.ts b/web/src/__tests__/server/scores-api-v2.servertest.tsindex 09716d6d88..b44f558dfb 100644--- a/web/src/__tests__/server/scores-api-v2.servertest.ts+++ b/web/src/__tests__/server/scores-api-v2.servertest.ts@@ -1164,6 +1164,66 @@ describe("/api/public/v2/scores API Endpoint", () => {);}});++ // Regression tests for #8630: the value operator must not override+ // the fixed >= / < operators of the fromTimestamp/toTimestamp filters.+ describe("operator combined with timestamp window", () => {+ const fromTimestamp = new Date(+ Date.now() - 24 * 60 * 60 * 1000,+ ).toISOString();+ const toTimestamp = new Date(+ Date.now() + 24 * 60 * 60 * 1000,+ ).toISOString();+ const timestampWindow = `fromTimestamp=${fromTimestamp}&toTimestamp=${toTimestamp}`;++ it("test operator > with timestamp window", async () => {+ const getScore = await makeZodVerifiedAPICall(+ GetScoresResponseV2,+ "GET",+ `/api/public/v2/scores?${queryUserName}&operator=>&value=100&${timestampWindow}`,+ undefined,+ authentication,+ );+ expect(getScore.status).toBe(200);+ expect(getScore.body.meta).toMatchObject({+ page: 1,+ limit: 50,+ totalItems: 1,+ totalPages: 1,+ });+ expect(getScore.body.data).toMatchObject([+ {+ id: scoreId_3,+ name: scoreName,+ value: 100.8,+ },+ ]);+ });++ it("test operator < with timestamp window", async () => {+ const getScore = await makeZodVerifiedAPICall(+ GetScoresResponseV2,+ "GET",+ `/api/public/v2/scores?${queryUserName}&operator=<&value=50&${timestampWindow}`,+ undefined,+ authentication,+ );+ expect(getScore.status).toBe(200);+ expect(getScore.body.meta).toMatchObject({+ page: 1,+ limit: 50,+ totalItems: 1,+ totalPages: 1,+ });+ expect(getScore.body.data).toMatchObject([+ {+ id: scoreId_1,+ name: scoreName,+ value: 10.5,+ },+ ]);+ });+ });});describe("should validate pagination", () => {