Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(alerts): link score alerts to filtered scores (#17715)

Nikita Kabardinc7516f031863
diff --git a/packages/shared/src/features/monitors/processor/buildMonitorAlertSlackMessage.test.ts b/packages/shared/src/features/monitors/processor/buildMonitorAlertSlackMessage.test.ts
index 0d4d02b40b..9fb3e8454d 100644
--- a/packages/shared/src/features/monitors/processor/buildMonitorAlertSlackMessage.test.ts
+++ b/packages/shared/src/features/monitors/processor/buildMonitorAlertSlackMessage.test.ts
@@ -108,9 +108,9 @@ describe("buildMonitorAlertSlackMessage", () => {
});
});
- it("labels the data button 'View traces' for a scores view", () => {
+ it("labels the data button 'View scores' for a scores view", () => {
const dataPermalink =
- "https://cloud.langfuse.com/project/proj_01/traces?dateRange=1779450930000-1779451230000";
+ "https://cloud.langfuse.com/project/proj_01/scores?dateRange=1779450930000-1779451230000";
const { attachments } = buildMonitorAlertSlackMessage({
...mockMonitorAlert,
view: "scores-numeric",
@@ -121,7 +121,7 @@ describe("buildMonitorAlertSlackMessage", () => {
);
expect(actions.elements).toHaveLength(2);
expect(actions.elements[1]).toMatchObject({
- text: { text: "View traces" },
+ text: { text: "View scores" },
url: dataPermalink,
});
});
@@ -135,14 +135,29 @@ describe("buildMonitorAlertSlackMessage", () => {
expect(actions.elements[0].text.text).toBe("View in Langfuse");
});
+ it("explains an unavailable score link while retaining the alert action", () => {
+ const { attachments } = buildMonitorAlertSlackMessage({
+ ...mockMonitorAlert,
+ view: "scores-numeric",
+ });
+ const blocks = attachments![0].blocks!;
+ expect(blocks[1].text.text).toContain(
+ "A filtered scores link is unavailable",
+ );
+ const actions = blocks.find((block: any) => block.type === "actions");
+ expect(actions.elements).toHaveLength(1);
+ expect(actions.elements[0].url).toBe(mockMonitorAlert.permalink);
+ });
+
// buildAlert only sets dataPermalink for breaching severities, so recovery
// (OK) and NO_DATA notifications arrive here with dataPermalink undefined and
- // must render no "View traces" button — recovery messages stay unchanged.
+ // must render no secondary data button — recovery messages stay unchanged.
it.each(["OK", "NO_DATA"] as const)(
"renders no secondary data button for a %s (non-breach) alert",
(severity) => {
const { attachments } = buildMonitorAlertSlackMessage({
...mockMonitorAlert,
+ view: "scores-numeric",
severity,
dataPermalink: undefined,
});
@@ -151,6 +166,9 @@ describe("buildMonitorAlertSlackMessage", () => {
);
expect(actions.elements).toHaveLength(1);
expect(actions.elements[0].text.text).toBe("View in Langfuse");
+ expect(attachments![0].blocks![1].text.text).not.toContain(
+ "scores link is unavailable",
+ );
},
);
});
diff --git a/packages/shared/src/features/monitors/processor/buildMonitorAlertSlackMessage.ts b/packages/shared/src/features/monitors/processor/buildMonitorAlertSlackMessage.ts
index 00789ed15d..73f235fa29 100644
--- a/packages/shared/src/features/monitors/processor/buildMonitorAlertSlackMessage.ts
+++ b/packages/shared/src/features/monitors/processor/buildMonitorAlertSlackMessage.ts
@@ -16,14 +16,21 @@ const severityVisual: Record<MonitorSeverity, { color: string }> = {
export function buildMonitorAlertSlackMessage(
alert: MonitorAlert,
): SlackMessage {
+ const missingScoreLink =
+ alert.view !== "observations" &&
+ alert.permalink &&
+ !alert.dataPermalink &&
+ (alert.severity === "ALERT" || alert.severity === "WARNING");
return buildColoredAttachmentSlackMessage({
color: severityVisual[alert.severity].color,
title: alert.message.title,
- body: alert.message.body,
+ body: missingScoreLink
+ ? `${alert.message.body}\n\nA filtered scores link is unavailable for this alert. Open the alert to review its filters.`
+ : alert.message.body,
timestamp: alert.timestamp,
url: alert.permalink,
secondaryUrl: alert.dataPermalink,
secondaryLabel:
- alert.view === "observations" ? "View observations" : "View traces",
+ alert.view === "observations" ? "View observations" : "View scores",
});
}
diff --git a/packages/shared/src/features/monitors/processor/buildPermalink.test.ts b/packages/shared/src/features/monitors/processor/buildPermalink.test.ts
index b281e23008..bc3da1144f 100644
--- a/packages/shared/src/features/monitors/processor/buildPermalink.test.ts
+++ b/packages/shared/src/features/monitors/processor/buildPermalink.test.ts
@@ -1,4 +1,9 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
+import {
+ decodeFiltersGeneric,
+ encodeFiltersGeneric,
+} from "../../filters/filterQueryEncoding";
+import type { FilterState } from "../../../types";
const envMock = vi.hoisted(() => ({
env: { NEXTAUTH_URL: undefined as string | undefined },
@@ -49,13 +54,184 @@ describe("buildDataWindowPermalink", () => {
);
});
- it.each(["scores-numeric", "scores-boolean", "scores-categorical"] as const)(
- "links a %s monitor to the traces table windowed by dateRange",
- (view) => {
+ it.each([
+ ["scores-numeric", ["NUMERIC", "BOOLEAN"]],
+ ["scores-boolean", "BOOLEAN"],
+ ["scores-categorical", "CATEGORICAL"],
+ ] as const)(
+ "links a %s monitor to the scores table windowed by dateRange",
+ (view, dataType) => {
envMock.env.NEXTAUTH_URL = "https://cloud.langfuse.com";
- expect(buildDataWindowPermalink("proj_01", view, from, to)).toBe(
- `https://cloud.langfuse.com/project/proj_01/traces?dateRange=${from.getTime()}-${to.getTime()}`,
+ const url = new URL(buildDataWindowPermalink("proj_01", view, from, to)!);
+ expect(url.pathname).toBe("/project/proj_01/scores");
+ expect(url.searchParams.get("dateRange")).toBe(
+ `${from.getTime()}-${to.getTime()}`,
);
+ expect(url.searchParams.get("showAllEnvironments")).toBe("true");
+ expect(decodeFiltersGeneric(url.searchParams.get("filter")!)).toEqual([
+ expect.objectContaining({
+ column: "dataType",
+ value: dataType,
+ }),
+ ]);
+ },
+ );
+
+ it("round-trips score predicates and metadata keys through the table URL", () => {
+ envMock.env.NEXTAUTH_URL = "https://cloud.langfuse.com";
+ const filters: FilterState = [
+ {
+ column: "name",
+ type: "stringOptions",
+ operator: "any of",
+ value: ["Source verified; α, β | γ"],
+ },
+ { column: "value", type: "number", operator: "=", value: 0 },
+ {
+ column: "metadata",
+ type: "stringObject",
+ key: "deployment.region",
+ operator: "=",
+ value: "a&b",
+ },
+ {
+ column: "environment",
+ type: "stringOptions",
+ operator: "none of",
+ value: ["staging"],
+ },
+ ];
+ const url = new URL(
+ buildDataWindowPermalink("proj_01", "scores-numeric", from, to, filters)!,
+ );
+ expect(
+ decodeFiltersGeneric(url.searchParams.get("filter")!).slice(
+ 0,
+ filters.length,
+ ),
+ ).toEqual(filters);
+ expect(url.searchParams.get("showAllEnvironments")).toBe("true");
+ const decoded = decodeFiltersGeneric(url.searchParams.get("filter")!);
+ expect(decodeFiltersGeneric(encodeFiltersGeneric(decoded))).toEqual(
+ decoded,
+ );
+ });
+
+ it.each(["key;name", "key,name", "key%", "%41"])(
+ "omits a link whose metadata key %s cannot survive table canonicalization",
+ (key) => {
+ envMock.env.NEXTAUTH_URL = "https://cloud.langfuse.com";
+ expect(
+ buildDataWindowPermalink("proj_01", "scores-numeric", from, to, [
+ {
+ column: "metadata",
+ type: "stringObject",
+ key,
+ operator: "=",
+ value: "value",
+ },
+ ]),
+ ).toBeUndefined();
+ },
+ );
+
+ it.each([
+ { column: "name", type: "string", operator: "=", value: "\ud800" },
+ {
+ column: "timestamp",
+ type: "datetime",
+ operator: ">=",
+ value: new Date("invalid"),
+ },
+ ] satisfies FilterState)(
+ "omits the data link when a $type filter cannot be encoded",
+ (filter) => {
+ envMock.env.NEXTAUTH_URL = "https://cloud.langfuse.com";
+ expect(
+ buildDataWindowPermalink("proj_01", "scores-numeric", from, to, [
+ filter,
+ ]),
+ ).toBeUndefined();
+ },
+ );
+
+ it.each([
+ ["=", false, 0],
+ ["=", true, 1],
+ ["<>", false, 1],
+ ["<>", true, 0],
+ ] as const)(
+ "preserves boolean score %s %s through its numeric value",
+ (operator, value, expectedValue) => {
+ envMock.env.NEXTAUTH_URL = "https://cloud.langfuse.com";
+ const url = new URL(
+ buildDataWindowPermalink("proj_01", "scores-boolean", from, to, [
+ { column: "booleanValue", type: "boolean", operator, value },
+ {
+ column: "isEvaluatorTest",
+ type: "boolean",
+ operator: "<>",
+ value: true,
+ },
+ ])!,
+ );
+ expect(decodeFiltersGeneric(url.searchParams.get("filter")!)).toEqual(
+ expect.arrayContaining([
+ {
+ column: "value",
+ type: "number",
+ operator: "=",
+ value: expectedValue,
+ },
+ {
+ column: "isEvaluatorTest",
+ type: "boolean",
+ operator: "=",
+ value: false,
+ },
+ ]),
+ );
+ },
+ );
+
+ it.each(["observationName", "traceName", "userId", "tags", "configId"])(
+ "omits the data link when %s cannot be reproduced by the scores table",
+ (column) => {
+ envMock.env.NEXTAUTH_URL = "https://cloud.langfuse.com";
+ expect(
+ buildDataWindowPermalink("proj_01", "scores-numeric", from, to, [
+ { column, type: "string", operator: "=", value: "example" },
+ ]),
+ ).toBeUndefined();
+ },
+ );
+
+ it("omits an oversized link without dropping predicates", () => {
+ envMock.env.NEXTAUTH_URL = "https://cloud.langfuse.com";
+ expect(
+ buildDataWindowPermalink("proj_01", "scores-numeric", from, to, [
+ {
+ column: "name",
+ type: "string",
+ operator: "=",
+ value: "a".repeat(3000),
+ },
+ ]),
+ ).toBeUndefined();
+ });
+
+ it.each([
+ { column: "observationId", type: "string", operator: "=", value: "" },
+ { column: "booleanValue", type: "null", operator: "is null", value: "" },
+ ] satisfies FilterState)(
+ "omits a link when $column has different empty-value semantics",
+ (filter) => {
+ envMock.env.NEXTAUTH_URL = "https://cloud.langfuse.com";
+ expect(
+ buildDataWindowPermalink("proj_01", "scores-numeric", from, to, [
+ filter,
+ ]),
+ ).toBeUndefined();
},
);
diff --git a/packages/shared/src/features/monitors/processor/processor.ts b/packages/shared/src/features/monitors/processor/processor.ts
index d0e967ddc0..153eeb2de3 100644
--- a/packages/shared/src/features/monitors/processor/processor.ts
+++ b/packages/shared/src/features/monitors/processor/processor.ts
@@ -15,6 +15,15 @@ import {
type TriggerDomainWithActions,
} from "../../../server/repositories/automation-repository";
import { executeQuery as defaultExecuteQuery } from "../../query/server/queryExecutor";
+import { getViewDeclaration } from "../../query/dataModel";
+import {
+ decodeFiltersGeneric,
+ encodeFiltersGeneric,
+} from "../../filters/filterQueryEncoding";
+import { scoresTableCols } from "../../../tableDefinitions/scoresTable";
+import { scoresTableUiColumnDefinitions } from "../../../server/tableMappings/mapScoresTable";
+import { COMPATIBLE_FILTER_TYPES } from "../../../server/queries/clickhouse-sql/filterTypeCompatibility";
+import type { FilterState } from "../../../types";
import type { QueryType } from "../../query/types";
import { isValidQuery } from "../isValidQuery";
import {
@@ -408,6 +417,7 @@ function buildAlert(args: {
prev.view,
fromTimestamp,
toTimestamp,
+ prev.filters,
)
: undefined,
message: renderAlertMessage({ monitor: prev, completion: next }),
@@ -441,21 +451,99 @@ export function isBreaching(severity: MonitorSeverity): boolean {
*
* The window is encoded as the table's custom `?dateRange=<fromMs>-<toMs>`
* param (absolute epoch-ms range; the client date-range parser accepts custom
- * ranges directly, bypassing the preset gating). An `observations` monitor
- * links to the observations table; every other view (scores-*) links to the
- * traces table, which is the row-level data users expect to inspect.
+ * ranges directly, bypassing the preset gating). Score views carry their
+ * input predicates and implicit data-type restrictions to the scores table.
+ * A score link is omitted when the destination cannot preserve every filter.
*/
export function buildDataWindowPermalink(
projectId: string,
view: MonitorView,
fromTimestamp: Date,
toTimestamp: Date,
+ filters: FilterState = [],
): string | undefined {
if (!env.NEXTAUTH_URL) return undefined;
const base = env.NEXTAUTH_URL.replace(/\/$/, "");
- const table = view === "observations" ? "observations" : "traces";
const dateRange = `${fromTimestamp.getTime()}-${toTimestamp.getTime()}`;
- return `${base}/project/${projectId}/${table}?dateRange=${dateRange}`;
+ if (view === "observations") {
+ return `${base}/project/${projectId}/observations?dateRange=${dateRange}`;
+ }
+
+ const tableFilters: FilterState = [];
+ const segments = getViewDeclaration(view, "v2").segments.map((filter) => ({
+ ...filter,
+ column: filter.column === "data_type" ? "dataType" : filter.column,
+ }));
+ for (const filter of [...filters, ...segments]) {
+ // Monitor booleans use the numeric 0/1 value. The table's Boolean Value
+ // facet uses string_value, which may be absent on existing boolean scores.
+ if (filter.column === "booleanValue" && filter.type === "boolean") {
+ const value = filter.operator === "=" ? filter.value : !filter.value;
+ tableFilters.push({
+ column: "value",
+ type: "number",
+ operator: "=",
+ value: Number(value),
+ });
+ continue;
+ }
+
+ // Trace-derived dimensions use different joins in the monitor and the
+ // legacy/events-backed scores readers. Only score-owned fields are portable.
+ const mapping = scoresTableUiColumnDefinitions.find(
+ (column) =>
+ column.uiTableId === filter.column &&
+ column.clickhouseTableName === "scores",
+ );
+ const definition = scoresTableCols.find(
+ (column) => column.id === filter.column,
+ );
+ if (
+ !mapping ||
+ mapping.emptyEqualsNull ||
+ !definition ||
+ (filter.type !== "null" &&
+ !COMPATIBLE_FILTER_TYPES[definition.type]?.includes(filter.type))
+ ) {
+ return undefined;
+ }
+
+ if (filter.type === "boolean") {
+ tableFilters.push({
+ ...filter,
+ operator: "=",
+ value: filter.operator === "=" ? filter.value : !filter.value,
+ });
+ } else {
+ tableFilters.push(filter);
+ }
+ }
+
+ let encodedFilters: string;
+ try {
+ encodedFilters = encodeFiltersGeneric(tableFilters);
+ // The table canonicalizes its URL after decoding. Keys containing legacy
+ // delimiters or percent escapes must survive that round-trip unchanged.
+ if (
+ encodeFiltersGeneric(decodeFiltersGeneric(encodedFilters)) !==
+ encodedFilters
+ ) {
+ return undefined;
+ }
+ } catch {
+ return undefined;
+ }
+
+ const query = new URLSearchParams({
+ dateRange,
+ filter: encodedFilters,
+ // Alert filters own the environment scope, including an unrestricted one.
+ showAllEnvironments: "true",
+ });
+ const href = `${base}/project/${projectId}/scores?${query.toString()}`;
+ // Slack button URLs are limited to 3000 characters. Dropping predicates to
+ // shorten a link would show scores outside the evaluated query.
+ return href.length <= 3000 ? href : undefined;
}
/** toMonitorWebhookInputs fans an alert out to one webhook input per matched automation. */
diff --git a/packages/shared/src/server/tableMappings/mapScoresTable.ts b/packages/shared/src/server/tableMappings/mapScoresTable.ts
index 5b521d43ab..1c9a89a8a0 100644
--- a/packages/shared/src/server/tableMappings/mapScoresTable.ts
+++ b/packages/shared/src/server/tableMappings/mapScoresTable.ts
@@ -1,4 +1,5 @@
import { UiColumnMappings } from "../../tableDefinitions";
+import { EvalExecutionMetadataKey } from "../../features/evals/evalExecutionMetadata";
// Lowercased boolean string_value ('true'/'false', '' for non-boolean rows) —
// matches the lowercase options offered by the scores view's Boolean Value
@@ -73,6 +74,12 @@ export const scoresTableUiColumnDefinitions: UiColumnMappings = [
clickhouseSelect: "evaluation_rule_id",
queryPrefix: "s",
},
+ {
+ uiTableName: "Evaluator Test",
+ uiTableId: "isEvaluatorTest",
+ clickhouseTableName: "scores",
+ clickhouseSelect: `toBool(s.metadata['${EvalExecutionMetadataKey.EVALUATOR_TEST}'] = 'true')`,
+ },
{
uiTableName: "Value",
uiTableId: "value",
diff --git a/packages/shared/src/tableDefinitions/scoresTable.ts b/packages/shared/src/tableDefinitions/scoresTable.ts
index 91fb5b47f4..5716606b66 100644
--- a/packages/shared/src/tableDefinitions/scoresTable.ts
+++ b/packages/shared/src/tableDefinitions/scoresTable.ts
@@ -78,6 +78,13 @@ export const scoresTableCols: ColumnDefinition[] = [
internal: "",
options: [],
},
+ {
+ name: "Evaluator Test",
+ id: "isEvaluatorTest",
+ type: "boolean",
+ // ClickHouse-only virtual column; see mapScoresTable.ts.
+ internal: "",
+ },
{
name: "Metadata",
id: "metadata",
diff --git a/web/src/__tests__/server/scores-trpc.servertest.ts b/web/src/__tests__/server/scores-trpc.servertest.ts
index e27a89a18c..aeb9925262 100644
--- a/web/src/__tests__/server/scores-trpc.servertest.ts
+++ b/web/src/__tests__/server/scores-trpc.servertest.ts
@@ -118,6 +118,80 @@ describe("scores trpc", () => {
});
describe("scores.all", () => {
+ it("preserves evaluator-test filters for score rows and counts on both read paths", async () => {
+ const scores = [
+ createTraceScore({
+ project_id: projectId,
+ name: "missing-test-marker",
+ metadata: {},
+ }),
+ createTraceScore({
+ project_id: projectId,
+ name: "false-test-marker",
+ metadata: { evaluator_test: "false" },
+ }),
+ createTraceScore({
+ project_id: projectId,
+ name: "true-test-marker",
+ metadata: { evaluator_test: "true" },
+ }),
+ ];
+ await createScoresCh(scores);
+
+ for (const { operator, value, expectedIds } of [
+ {
+ operator: "=" as const,
+ value: false,
+ expectedIds: [scores[0].id, scores[1].id],
+ },
+ {
+ operator: "=" as const,
+ value: true,
+ expectedIds: [scores[2].id],
+ },
+ {
+ operator: "<>" as const,
+ value: true,
+ expectedIds: [scores[0].id, scores[1].id],
+ },
+ {
+ operator: "<>" as const,
+ value: false,
+ expectedIds: [scores[2].id],
+ },
+ ]) {
+ const payload = {
+ projectId,
+ filter: [
+ {
+ column: "isEvaluatorTest",
+ type: "boolean" as const,
+ operator,
+ value,
+ },
+ ],
+ orderBy: { column: "timestamp", order: "DESC" as const },
+ page: 0,
+ limit: 50,
+ };
+ const [rows, eventRows, count, eventCount] = await Promise.all([
+ caller.scores.all(payload),
+ caller.scores.allFromEvents(payload),
+ caller.scores.countAll({ ...payload, orderBy: null }),
+ caller.scores.countAllFromEvents({ ...payload, orderBy: null }),
+ ]);
+
+ expect(rows.scores.map(({ id }) => id).sort()).toEqual(
+ [...expectedIds].sort(),
+ );
+ expect(eventRows.scores.map(({ id }) => id).sort()).toEqual(
+ [...expectedIds].sort(),
+ );
+ expect(count.totalCount).toBe(expectedIds.length);
+ expect(eventCount.totalCount).toBe(expectedIds.length);
+ }
+ });
+
it("applies search-bar name matching and repeated numeric bounds to v4 rows and counts", async () => {
await createScoresCh(
[
diff --git a/web/src/features/filters/config/scores-config.clienttest.ts b/web/src/features/filters/config/scores-config.clienttest.ts
index 55d244a99f..e56e10f3d3 100644
--- a/web/src/features/filters/config/scores-config.clienttest.ts
+++ b/web/src/features/filters/config/scores-config.clienttest.ts
@@ -1,8 +1,40 @@
// @vitest-environment node
import { getScoreFilterConfig, observationScopeFilter } from "./scores-config";
+import { decodeAndNormalizeFilters } from "../hooks/useSidebarFilterState";
+import { encodeFiltersGeneric, type FilterState } from "@langfuse/shared";
+import { scoresFieldRegistry } from "@/src/features/scores/constants/scoresSearchRegistry";
+import { planCommit } from "@/src/features/search-bar/lib/commit";
describe("getScoreFilterConfig", () => {
+ it("keeps the evaluator-test filter when opening a score URL and editing its search pill", () => {
+ const config = getScoreFilterConfig();
+ const filters: FilterState = [
+ {
+ column: "isEvaluatorTest",
+ type: "boolean",
+ operator: "=",
+ value: false,
+ },
+ ];
+
+ expect(
+ decodeAndNormalizeFilters(
+ encodeFiltersGeneric(filters),
+ config.columnDefinitions,
+ ),
+ ).toEqual(filters);
+ const committed = planCommit(
+ "isEvaluatorTest:false",
+ undefined,
+ scoresFieldRegistry(config),
+ );
+ expect(committed.status).toBe("committed");
+ if (committed.status === "committed") {
+ expect(committed.filters).toEqual(filters);
+ }
+ });
+
it("offers score metadata in the filter sidebar", () => {
const config = getScoreFilterConfig();
diff --git a/web/src/features/filters/config/scores-config.ts b/web/src/features/filters/config/scores-config.ts
index daf775cbb6..c203f19068 100644
--- a/web/src/features/filters/config/scores-config.ts
+++ b/web/src/features/filters/config/scores-config.ts
@@ -48,6 +48,11 @@ const scoreFilterConfig: FilterConfig = {
column: "source",
label: "Source",
},
+ {
+ type: "boolean" as const,
+ column: "isEvaluatorTest",
+ label: "Evaluator Test",
+ },
{
type: "categorical" as const,
column: "dataType",
diff --git a/worker/src/__tests__/monitorProcessor.test.ts b/worker/src/__tests__/monitorProcessor.test.ts
index 0b8878ae36..46ff328b48 100644
--- a/worker/src/__tests__/monitorProcessor.test.ts
+++ b/worker/src/__tests__/monitorProcessor.test.ts
@@ -6,7 +6,11 @@ import {
createOrgProjectAndApiKey,
logger,
} from "@langfuse/shared/src/server";
-import { InvalidRequestError } from "@langfuse/shared";
+import {
+ InvalidRequestError,
+ decodeFiltersGeneric,
+ type FilterState,
+} from "@langfuse/shared";
import {
MonitorProcessor,
type MonitorPublisher,
@@ -46,6 +50,7 @@ type SeedOverrides = Partial<{
windowMs: bigint;
status: MonitorStatus;
view: MonitorView;
+ filters: FilterState;
metric: Metric;
alertThreshold: number;
warningThreshold: number | null;
@@ -148,7 +153,7 @@ async function seedMonitor(projectId: string, seed: MonitorSeed) {
id: seed.id,
projectId,
view: seed.view ?? "OBSERVATIONS",
- filters: [] as unknown as Prisma.InputJsonValue,
+ filters: (seed.filters ?? []) as unknown as Prisma.InputJsonValue,
metric: (seed.metric ?? {
measure: "count",
aggregation: "count",
@@ -1517,8 +1522,19 @@ describe("MonitorProcessor.process evaluation offset", () => {
it("shifts the CH query window back by 30s and stamps it onto the alert payload", async () => {
const monitorId = `m_off_${v4()}`;
+ const filters: FilterState = [
+ {
+ column: "name",
+ type: "stringOptions",
+ operator: "any of",
+ value: ["Source verified"],
+ },
+ { column: "value", type: "number", operator: "=", value: 0 },
+ ];
await seedMonitor(projectId, {
id: monitorId,
+ view: "SCORES_NUMERIC",
+ filters,
severity: MonitorSeveritySchema.enum.UNKNOWN,
lastPublishedAt: runAt,
triggerIds: ["trig_off"],
@@ -1551,7 +1567,11 @@ describe("MonitorProcessor.process evaluation offset", () => {
getTriggers,
);
- const event = makeEvent(projectId, [monitorId]);
+ const event: MonitorQueueEvent = {
+ ...makeEvent(projectId, [monitorId]),
+ view: "scores-numeric",
+ filters,
+ };
await processor.process(event, justAfterRunAt);
const offsetMs = 30_000;
@@ -1571,6 +1591,14 @@ describe("MonitorProcessor.process evaluation offset", () => {
if (sent.type !== "monitor-alert") throw new Error("unexpected envelope");
expect(sent.payload.fromTimestamp.toISOString()).toBe(expectedFrom);
expect(sent.payload.toTimestamp.toISOString()).toBe(expectedTo);
+ const dataUrl = new URL(sent.payload.dataPermalink!);
+ expect(dataUrl.pathname).toBe(`/project/${projectId}/scores`);
+ expect(dataUrl.searchParams.get("dateRange")).toBe(
+ `${new Date(expectedFrom).getTime()}-${new Date(expectedTo).getTime()}`,
+ );
+ expect(decodeFiltersGeneric(dataUrl.searchParams.get("filter")!)).toEqual(
+ expect.arrayContaining(filters),
+ );
// The cadence-boundary stamp stays unshifted — alerts say "fired at runAt".
expect(sent.payload.timestamp.toISOString()).toBe(runAt.toISOString());
});