Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. πŸ”₯

Omit noise-judged pages from monitor Slack and email alerts (#5633)

Micah Stairsaefefc50a1ec
diff --git a/apps/api/src/services/integrations/slack/messages.ts b/apps/api/src/services/integrations/slack/messages.ts
index 790eee325..fe9ae21b0 100644
--- a/apps/api/src/services/integrations/slack/messages.ts
+++ b/apps/api/src/services/integrations/slack/messages.ts
@@ -20,6 +20,9 @@ type MonitorSlackPayload = {
};
pages: MonitorSlackPage[];
creditsUsed: number | null;
+ // Changed pages left out of `pages` because judging called them noise.
+ // Only set when this list includes every changed page on the check.
+ noiseOmitted?: number;
};
const MAX_PAGE_BLOCKS = 8;
@@ -31,7 +34,10 @@ const MAX_LINK_URL_LEN = 2000;
// Slack mrkdwn requires these three characters escaped in text spans.
export function escapeSlackText(input: string): string {
- return input.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
+ return input
+ .replace(/&/g, "&amp;")
+ .replace(/</g, "&lt;")
+ .replace(/>/g, "&gt;");
}
export function slackLink(url: string, label?: string): string {
@@ -100,7 +106,9 @@ export function buildMonitorAlertMessage(payload: MonitorSlackPayload): {
});
blocks.push({
type: "context",
- elements: [{ type: "mrkdwn", text: truncate(meta, SECTION_TEXT_LIMIT) }],
+ elements: [
+ { type: "mrkdwn", text: truncate(meta, SECTION_TEXT_LIMIT) },
+ ],
});
} else {
// No judged description (e.g. unjudged monitor) β€” the page itself leads.
@@ -127,8 +135,15 @@ export function buildMonitorAlertMessage(payload: MonitorSlackPayload): {
).length;
const counts: string[] = [];
if (summary.changed > 0) {
+ const details: string[] = [];
+ if (meaningfulCount > 0) details.push(`${meaningfulCount} meaningful`);
+ if ((payload.noiseOmitted ?? 0) > 0) {
+ details.push(`${payload.noiseOmitted} noise omitted`);
+ }
counts.push(
- `${summary.changed} changed${meaningfulCount > 0 ? ` (${meaningfulCount} meaningful)` : ""}`,
+ details.length > 0
+ ? `${summary.changed} changed (${details.join(", ")})`
+ : `${summary.changed} changed`,
);
}
if (summary.new > 0) counts.push(`${summary.new} new`);
diff --git a/apps/api/src/services/integrations/slack/slack.test.ts b/apps/api/src/services/integrations/slack/slack.test.ts
index 2e3b9b24f..3782fe913 100644
--- a/apps/api/src/services/integrations/slack/slack.test.ts
+++ b/apps/api/src/services/integrations/slack/slack.test.ts
@@ -3,7 +3,11 @@ import { describe, it, expect, afterEach } from "vitest";
import { config } from "../../../config";
import { encryptSlackToken, decryptSlackToken } from "./crypto";
import { verifySlackSignature } from "./signature";
-import { buildMonitorAlertMessage, escapeSlackText, slackLink } from "./messages";
+import {
+ buildMonitorAlertMessage,
+ escapeSlackText,
+ slackLink,
+} from "./messages";
import { sanitizeRedirectPath } from "./redirect";
const ORIGINAL_ENCRYPTION_KEY = config.SLACK_TOKEN_ENCRYPTION_KEY;
@@ -16,9 +20,7 @@ afterEach(() => {
describe("slack token crypto", () => {
it("round-trips a token with AES-256-GCM when a key is configured", () => {
- config.SLACK_TOKEN_ENCRYPTION_KEY = crypto
- .randomBytes(32)
- .toString("hex");
+ config.SLACK_TOKEN_ENCRYPTION_KEY = crypto.randomBytes(32).toString("hex");
// Opaque placeholder β€” the crypto layer treats the token as bytes, and we
// avoid real Slack bot-token shapes so secret scanners don't flag it.
const token = "slack-bot-token-placeholder";
@@ -37,9 +39,7 @@ describe("slack token crypto", () => {
});
it("throws when a GCM token is read without its key", () => {
- config.SLACK_TOKEN_ENCRYPTION_KEY = crypto
- .randomBytes(32)
- .toString("hex");
+ config.SLACK_TOKEN_ENCRYPTION_KEY = crypto.randomBytes(32).toString("hex");
const stored = encryptSlackToken("bot-token-placeholder");
config.SLACK_TOKEN_ENCRYPTION_KEY = undefined;
expect(() => decryptSlackToken(stored)).toThrow();
@@ -166,6 +166,33 @@ describe("slack message builder", () => {
// Header text is plain_text; the monitor name is not escaped there but the
// fallback text keeps it readable.
expect(serialized).toContain("meaningful");
+ expect(serialized).toContain("2 changed (1 meaningful)");
+ expect(serialized).not.toContain("noise omitted");
+ });
+
+ it("labels noise rows left out of the page list without changing the changed total", () => {
+ const { blocks } = buildMonitorAlertMessage({
+ monitorName: "Docs",
+ dashboardUrl: "https://www.firecrawl.dev/app/monitoring/m1?checkId=c1",
+ checkId: "c1",
+ summary: { changed: 3, new: 1, removed: 0, error: 0, totalPages: 4 },
+ pages: [
+ {
+ url: "https://example.com/price",
+ status: "changed",
+ judgment: { meaningful: true, reason: "Pro price changed" },
+ },
+ { url: "https://example.com/new-page", status: "new", judgment: null },
+ ],
+ creditsUsed: 1,
+ noiseOmitted: 1,
+ });
+
+ const serialized = JSON.stringify(blocks);
+ expect(serialized).toContain("https://example.com/price");
+ expect(serialized).toContain("https://example.com/new-page");
+ expect(serialized).toContain("3 changed (1 meaningful, 1 noise omitted)");
+ expect(serialized).toContain("1 new");
});
it("bounds long page URLs so section blocks stay within Slack's 3000-char limit", () => {
diff --git a/apps/api/src/services/notification/monitoring_alert_pages.ts b/apps/api/src/services/notification/monitoring_alert_pages.ts
new file mode 100644
index 000000000..553a16d00
--- /dev/null
+++ b/apps/api/src/services/notification/monitoring_alert_pages.ts
@@ -0,0 +1,54 @@
+// Human-facing Slack and email alerts share this gate with the all-noise
+// suppression check: judging must be on and the monitor must have a goal.
+// Webhook payloads and in-app summaries keep the full page set.
+
+type AlertPageJudgment = {
+ meaningful: boolean;
+} | null;
+
+type AlertPageLike = {
+ status: string;
+ judgment?: AlertPageJudgment;
+};
+
+function judgingFiltersAlertNoise(monitor: {
+ judge_enabled?: boolean | null;
+ goal?: string | null;
+}): boolean {
+ return Boolean(monitor.judge_enabled && monitor.goal);
+}
+
+// A changed page the judge explicitly called noise. Missing judgments stay:
+// a failed judge must not hide a change. New, removed, and error rows are
+// never noise-filtered, even if a judgment object is present.
+function isExplicitChangedNoise(page: AlertPageLike): boolean {
+ return page.status === "changed" && page.judgment?.meaningful === false;
+}
+
+export function humanFacingAlertPages<T extends AlertPageLike>(
+ monitor: { judge_enabled?: boolean | null; goal?: string | null },
+ pages: T[],
+): T[] {
+ if (!judgingFiltersAlertNoise(monitor)) return pages;
+ return pages.filter(page => !isExplicitChangedNoise(page));
+}
+
+// Notifications load the first 100 check pages, ordered by creation time, while
+// `changed_count` covers the whole check. A noise total from that window is the
+// check total only when every changed page is in the window.
+export function noiseOmittedFromAlertPages(
+ monitor: { judge_enabled?: boolean | null; goal?: string | null },
+ check: { changed_count?: number | null },
+ pages: AlertPageLike[],
+): { noiseOmitted: number; hidePartialNoiseCount: boolean } {
+ if (!judgingFiltersAlertNoise(monitor)) {
+ return { noiseOmitted: 0, hidePartialNoiseCount: false };
+ }
+ const removed = pages.filter(isExplicitChangedNoise).length;
+ const changedSeen = pages.filter(page => page.status === "changed").length;
+ const listComplete = changedSeen >= (check.changed_count ?? 0);
+ if (!listComplete) {
+ return { noiseOmitted: 0, hidePartialNoiseCount: removed > 0 };
+ }
+ return { noiseOmitted: removed, hidePartialNoiseCount: false };
+}
diff --git a/apps/api/src/services/notification/monitoring_email.test.ts b/apps/api/src/services/notification/monitoring_email.test.ts
index d096cfa90..e9c34bc21 100644
--- a/apps/api/src/services/notification/monitoring_email.test.ts
+++ b/apps/api/src/services/notification/monitoring_email.test.ts
@@ -12,7 +12,7 @@ const {
mockResendSend: vi.fn(),
}));
-vi.mock("../monitoring/email_recipients", async (importOriginal) => {
+vi.mock("../monitoring/email_recipients", async importOriginal => {
const actual =
await importOriginal<typeof import("../monitoring/email_recipients")>();
return {
@@ -237,7 +237,10 @@ describe("sendMonitoringEmailSummary", () => {
pages: Array<{
status: string;
meaningful?: boolean | null;
+ url?: string;
+ reason?: string;
}>;
+ judgeEnabled?: boolean;
}) {
return {
monitor: {
@@ -245,7 +248,10 @@ describe("sendMonitoringEmailSummary", () => {
team_id: "team-1",
name: "Test",
goal: opts.goal ?? null,
- judge_enabled: Boolean(opts.goal),
+ judge_enabled:
+ opts.judgeEnabled !== undefined
+ ? opts.judgeEnabled
+ : Boolean(opts.goal),
notification: opts.emailEnabled
? {
email: {
@@ -263,7 +269,7 @@ describe("sendMonitoringEmailSummary", () => {
error_count: opts.pages.filter(p => p.status === "error").length,
} as any,
pages: opts.pages.map((p, i) => ({
- url: `https://example.com/${i}`,
+ url: p.url ?? `https://example.com/${i}`,
status: p.status,
judgment:
p.meaningful === null || p.meaningful === undefined
@@ -271,7 +277,7 @@ describe("sendMonitoringEmailSummary", () => {
: {
meaningful: p.meaningful,
confidence: "high" as const,
- reason: "test",
+ reason: p.reason ?? "test",
fields: [],
},
})),
@@ -347,17 +353,204 @@ describe("sendMonitoringEmailSummary", () => {
});
it("fails open when changed-page list is truncated (would otherwise suppress)", async () => {
+ // Only noise is visible. Delivery depends on the truncated changed_count:
+ // a complete all-noise list would be suppressed.
const args = buildArgs({
goal: "track price changes",
emailEnabled: true,
pages: [
- { status: "changed", meaningful: false },
- { status: "changed", meaningful: false },
+ {
+ status: "changed",
+ meaningful: false,
+ url: "https://example.com/clock",
+ reason: "Only the timestamp moved",
+ },
+ {
+ status: "changed",
+ meaningful: false,
+ url: "https://example.com/ads",
+ reason: "A recommended link rotated",
+ },
],
});
(args.check as any).changed_count = 50;
const result = await sendMonitoringEmailSummary(args);
expect(result.attempted).toBe(true);
+ expect(mockResendSend).toHaveBeenCalled();
+ });
+
+ it("hides window noise without quoting it as the full changed total", async () => {
+ const args = buildArgs({
+ goal: "track price changes",
+ emailEnabled: true,
+ pages: [
+ {
+ status: "changed",
+ meaningful: true,
+ url: "https://example.com/price",
+ reason: "Pro price changed",
+ },
+ {
+ status: "changed",
+ meaningful: false,
+ url: "https://example.com/clock",
+ reason: "Only the timestamp moved",
+ },
+ ],
+ });
+ (args.check as any).changed_count = 50;
+ const result = await sendMonitoringEmailSummary(args);
+ expect(result.attempted).toBe(true);
+ const html = sentHtml();
+ expect(html).toContain("https://example.com/price");
+ expect(html).not.toContain("https://example.com/clock");
+ expect(html).toContain("Changed: 50 (1 meaningful)");
+ expect(html).not.toContain("noise omitted");
+ expect(html).not.toContain("0 noise");
+ });
+
+ function sentHtml(): string {
+ expect(mockResendSend).toHaveBeenCalled();
+ return mockResendSend.mock.calls[0][0].html as string;
+ }
+
+ it("omits noise-judged changed pages from a mixed alert and keeps the tally honest", async () => {
+ const result = await sendMonitoringEmailSummary(
+ buildArgs({
+ goal: "track price changes",
+ emailEnabled: true,
+ pages: [
+ {
+ status: "changed",
+ meaningful: true,
+ url: "https://example.com/price",
+ reason: "Pro price changed",
+ },
+ {
+ status: "changed",
+ meaningful: false,
+ url: "https://example.com/clock",
+ reason: "Only the timestamp moved",
+ },
+ {
+ status: "changed",
+ meaningful: null,
+ url: "https://example.com/unjudged",
+ },
+ {
+ status: "new",
+ meaningful: false,
+ url: "https://example.com/new-page",
+ reason: "A new page stays even when judged noise",
+ },
+ {
+ status: "removed",
+ meaningful: false,
+ url: "https://example.com/removed-page",
+ reason: "A removed page stays even when judged noise",
+ },
+ {
+ status: "error",
+ meaningful: false,
+ url: "https://example.com/error-page",
+ reason: "An error page stays even when judged noise",
+ },
+ ],
+ }),
+ );
+ expect(result.attempted).toBe(true);
+ const html = sentHtml();
+ expect(html).toContain("https://example.com/price");
+ expect(html).toContain("Pro price changed");
+ expect(html).toContain("https://example.com/unjudged");
+ expect(html).toContain("https://example.com/new-page");
+ expect(html).toContain("A new page stays even when judged noise");
+ expect(html).toContain("https://example.com/removed-page");
+ expect(html).toContain("A removed page stays even when judged noise");
+ expect(html).toContain("https://example.com/error-page");
+ expect(html).toContain("An error page stays even when judged noise");
+ expect(html).not.toContain("https://example.com/clock");
+ expect(html).not.toContain("Only the timestamp moved");
+ expect(html).toContain("[noise]");
+ expect(html).toContain(
+ "Changed: 3 (1 meaningful, 3 noise, 1 noise omitted)",
+ );
+ expect(html).toContain("New: 1");
+ expect(html).toContain("Removed: 1");
+ expect(html).toContain("Errors: 1");
+ expect(html).toContain("Top pages:");
+ });
+
+ it("does not list noise pages or an empty page heading when only unseen activity remains", async () => {
+ const args = buildArgs({
+ goal: "track price changes",
+ emailEnabled: true,
+ pages: [
+ {
+ status: "changed",
+ meaningful: false,
+ url: "https://example.com/clock",
+ reason: "Only the timestamp moved",
+ },
+ ],
+ });
+ // The page window is entirely noise, but the check counters report new
+ // pages outside that window, so the email still sends.
+ (args.check as { new_count: number }).new_count = 2;
+ const result = await sendMonitoringEmailSummary(args);
+ expect(result.attempted).toBe(true);
+ const html = sentHtml();
+ expect(html).not.toContain("https://example.com/clock");
+ expect(html).not.toContain("Top pages:");
+ expect(html).toContain("Changed: 1 (0 meaningful, 1 noise omitted)");
+ expect(html).toContain("New: 2");
+ });
+
+ it("still lists noise pages when judging is disabled", async () => {
+ const result = await sendMonitoringEmailSummary(
+ buildArgs({
+ goal: "track price changes",
+ judgeEnabled: false,
+ emailEnabled: true,
+ pages: [
+ {
+ status: "changed",
+ meaningful: false,
+ url: "https://example.com/clock",
+ reason: "Only the timestamp moved",
+ },
+ ],
+ }),
+ );
+ expect(result.attempted).toBe(true);
+ const html = sentHtml();
+ expect(html).toContain("https://example.com/clock");
+ expect(html).toContain("Only the timestamp moved");
+ expect(html).toContain("[noise]");
+ expect(html).toContain("Changed: 1 (0 meaningful, 1 noise)");
+ expect(html).not.toContain("noise omitted");
+ });
+
+ it("still lists noise pages when the goal is empty", async () => {
+ const result = await sendMonitoringEmailSummary(
+ buildArgs({
+ goal: "",
+ judgeEnabled: true,
+ emailEnabled: true,
+ pages: [
+ {
+ status: "changed",
+ meaningful: false,
+ url: "https://example.com/clock",
+ reason: "Only the timestamp moved",
+ },
+ ],
+ }),
+ );
+ expect(result.attempted).toBe(true);
+ const html = sentHtml();
+ expect(html).toContain("https://example.com/clock");
+ expect(html).not.toContain("noise omitted");
});
it("fails open when counters report new/error pages beyond the truncated list", async () => {
diff --git a/apps/api/src/services/notification/monitoring_email.ts b/apps/api/src/services/notification/monitoring_email.ts
index eef58d200..d4d253ded 100644
--- a/apps/api/src/services/notification/monitoring_email.ts
+++ b/apps/api/src/services/notification/monitoring_email.ts
@@ -14,6 +14,10 @@ import {
touchRecipientsNotified,
type MonitorEmailRecipientRow,
} from "../monitoring/email_recipients";
+import {
+ humanFacingAlertPages,
+ noiseOmittedFromAlertPages,
+} from "./monitoring_alert_pages";
const logger = _logger.child({ module: "monitoring-email" });
@@ -85,6 +89,13 @@ export type MonitoringEmailPayload = {
};
pages: MonitoringEmailPage[];
creditsUsed: number | null;
+ // Changed pages removed from `pages` because judging called them noise.
+ // Set only when every changed page is in this list, so the number is the
+ // whole check rather than the 100-page notification window.
+ noiseOmitted?: number;
+ // Noise rows were hidden, but changed pages exist outside this list. The
+ // summary then must not state a noise total.
+ hidePartialNoiseCount?: boolean;
// When omitted, the footer drops the unsubscribe row.
unsubscribeUrl?: string;
};
@@ -163,6 +174,30 @@ export function buildRecipientUnsubscribeUrl(token: string): string {
return buildPublicWebUrl("/monitoring/email/unsubscribe", token);
}
+function formatChangedLine(params: {
+ changed: number;
+ meaningfulCount: number;
+ listedNoiseCount: number;
+ noiseOmitted: number;
+ hasJudgment: boolean;
+ hidePartialNoiseCount: boolean;
+}): string {
+ const { changed, meaningfulCount, listedNoiseCount, noiseOmitted } = params;
+ if (params.hidePartialNoiseCount) {
+ return meaningfulCount > 0
+ ? `Changed: ${changed} (${meaningfulCount} meaningful)`
+ : `Changed: ${changed}`;
+ }
+ if (!params.hasJudgment) return `Changed: ${changed}`;
+ if (noiseOmitted > 0 && listedNoiseCount === 0) {
+ return `Changed: ${changed} (${meaningfulCount} meaningful, ${noiseOmitted} noise omitted)`;
+ }
+ if (noiseOmitted > 0) {
+ return `Changed: ${changed} (${meaningfulCount} meaningful, ${listedNoiseCount} noise, ${noiseOmitted} noise omitted)`;
+ }
+ return `Changed: ${changed} (${meaningfulCount} meaningful, ${listedNoiseCount} noise)`;
+}
+
function buildUnsubscribeFooter(unsubscribeUrl: string): string {
const safe = escapeHtml(unsubscribeUrl);
return `<hr style="border:none;border-top:1px solid #e5e7eb;margin:24px 0 12px;" />
@@ -210,11 +245,19 @@ export function buildHtml(payload: MonitoringEmailPayload): string {
const meaningfulCount = judgedPages.filter(
p => p.judgment!.meaningful,
).length;
- const noiseCount = judgedPages.length - meaningfulCount;
- const changedLine =
- judgedPages.length > 0
- ? `Changed: ${payload.summary.changed} (${meaningfulCount} meaningful, ${noiseCount} noise)`
- : `Changed: ${payload.summary.changed}`;
+ const listedNoiseCount = judgedPages.length - meaningfulCount;
+ const noiseOmitted = payload.noiseOmitted ?? 0;
+ // Counts come from the pages still rendered, plus noise rows removed above
+ // when that removal count covers every changed page. An empty list must not
+ // leave a heading, and a truncated window must not report "0 noise".
+ const changedLine = formatChangedLine({
+ changed: payload.summary.changed,
+ meaningfulCount,
+ listedNoiseCount,
+ noiseOmitted,
+ hasJudgment: judgedPages.length > 0 || noiseOmitted > 0,
+ hidePartialNoiseCount: payload.hidePartialNoiseCount === true,
+ });
return `Hey there,<br/>
<p>Your Firecrawl monitor <strong>${escapeHtml(payload.monitorName)}</strong> detected activity.</p>
@@ -568,6 +611,15 @@ export async function sendMonitoringEmailSummary(params: {
checkId: params.check.id,
});
+ // Suppression already ran on the full page list. The rendered list drops
+ // changed pages the judge called noise; new/removed/error/unjudged stay.
+ const alertPages = humanFacingAlertPages(params.monitor, params.pages);
+ const noiseSummary = noiseOmittedFromAlertPages(
+ params.monitor,
+ params.check,
+ params.pages,
+ );
+
// One email per recipient: unique unsubscribe links + no recipient leakage.
const sendResults = await Promise.all(
resolved.confirmedRecipients.map(async recipient => {
@@ -583,7 +635,9 @@ export async function sendMonitoringEmailSummary(params: {
error: params.check.error_count,
totalPages: params.check.total_pages,
},
- pages: params.pages,
+ pages: alertPages,
+ noiseOmitted: noiseSummary.noiseOmitted,
+ hidePartialNoiseCount: noiseSummary.hidePartialNoiseCount,
creditsUsed: params.check.actual_credits,
unsubscribeUrl: buildRecipientUnsubscribeUrl(recipient.token),
};
diff --git a/apps/api/src/services/notification/monitoring_slack.test.ts b/apps/api/src/services/notification/monitoring_slack.test.ts
index 1e4412f5d..d40b8048a 100644
--- a/apps/api/src/services/notification/monitoring_slack.test.ts
+++ b/apps/api/src/services/notification/monitoring_slack.test.ts
@@ -1,5 +1,31 @@
+const { mockGetInstallation, mockDecrypt, mockPost, mockJoin } = vi.hoisted(
+ () => ({
+ mockGetInstallation: vi.fn(),
+ mockDecrypt: vi.fn(),
+ mockPost: vi.fn(),
+ mockJoin: vi.fn(),
+ }),
+);
+
+vi.mock("../integrations/slack/store", () => ({
+ getSlackInstallationByTeam: (...args: unknown[]) =>
+ mockGetInstallation(...args),
+}));
+
+vi.mock("../integrations/slack/crypto", () => ({
+ decryptSlackToken: (...args: unknown[]) => mockDecrypt(...args),
+}));
+
+vi.mock("../integrations/slack/client", () => ({
+ postSlackMessage: (...args: unknown[]) => mockPost(...args),
+ joinChannel: (...args: unknown[]) => mockJoin(...args),
+}));
+
import { describe, it, expect } from "vitest";
-import { shouldSuppressForNoise } from "./monitoring_slack";
+import {
+ sendMonitoringSlackSummary,
+ shouldSuppressForNoise,
+} from "./monitoring_slack";
import type { MonitorCheckRow, MonitorRow } from "../monitoring/types";
type Page = {
@@ -99,3 +125,233 @@ describe("shouldSuppressForNoise (slack)", () => {
).toBe(false);
});
});
+
+function page(
+ url: string,
+ status: string,
+ meaningful: boolean | null,
+ reason = "because",
+): Page {
+ return {
+ url,
+ status,
+ judgment:
+ meaningful === null ? null : { meaningful, confidence: "high", reason },
+ };
+}
+
+function slackMonitor(overrides: Partial<MonitorRow> = {}): MonitorRow {
+ return {
+ id: "monitor-1",
+ team_id: "team-1",
+ name: "Docs monitor",
+ judge_enabled: true,
+ goal: "track prices",
+ notification: { slack: { enabled: true, channelId: "C123" } },
+ ...overrides,
+ } as MonitorRow;
+}
+
+function slackCheck(overrides: Partial<MonitorCheckRow> = {}): MonitorCheckRow {
+ return {
+ id: "check-1",
+ changed_count: 0,
+ new_count: 0,
+ removed_count: 0,
+ error_count: 0,
+ total_pages: 4,
+ actual_credits: 1,
+ ...overrides,
+ } as MonitorCheckRow;
+}
+
+function postedText(): string {
+ expect(mockPost).toHaveBeenCalledTimes(1);
+ const payload = mockPost.mock.calls[0][0] as {
+ text: string;
+ blocks: unknown[];
+ };
+ return JSON.stringify({ text: payload.text, blocks: payload.blocks });
+}
+
+describe("sendMonitoringSlackSummary page list", () => {
+ beforeEach(() => {
+ mockGetInstallation.mockReset();
+ mockDecrypt.mockReset();
+ mockPost.mockReset();
+ mockJoin.mockReset();
+ mockGetInstallation.mockResolvedValue({ bot_token: "enc" });
+ mockDecrypt.mockReturnValue("xoxb-test");
+ mockPost.mockResolvedValue({ ok: true });
+ mockJoin.mockResolvedValue({ ok: true });
+ });
+
+ it("drops noise-judged changed pages from a mixed alert and labels the gap", async () => {
+ const result = await sendMonitoringSlackSummary({
+ monitor: slackMonitor(),
+ check: slackCheck({
+ changed_count: 3,
+ new_count: 1,
+ removed_count: 1,
+ error_count: 1,
+ }),
+ pages: [
+ page("https://example.com/price", "changed", true, "Pro price changed"),
+ page(
+ "https://example.com/clock",
+ "changed",
+ false,
+ "Only the timestamp moved",
+ ),
+ page("https://example.com/unjudged", "changed", null),
+ page(
+ "https://example.com/new-page",
+ "new",
+ false,
+ "A new page stays even when judged noise",
+ ),
+ page(
+ "https://example.com/removed-page",
+ "removed",
+ false,
+ "A removed page stays even when judged noise",
+ ),
+ page(
+ "https://example.com/error-page",
+ "error",
+ false,
+ "An error page stays even when judged noise",
+ ),
+ ],
+ });
+
+ expect(result).toMatchObject({ attempted: true, success: true });
+ const body = postedText();
+ expect(body).toContain("https://example.com/price");
+ expect(body).toContain("Pro price changed");
+ expect(body).toContain("https://example.com/unjudged");
+ expect(body).toContain("https://example.com/new-page");
+ expect(body).toContain("A new page stays even when judged noise");
+ expect(body).toContain("https://example.com/removed-page");
+ expect(body).toContain("A removed page stays even when judged noise");
+ expect(body).toContain("https://example.com/error-page");
+ expect(body).toContain("An error page stays even when judged noise");
+ expect(body).not.toContain("https://example.com/clock");
+ expect(body).not.toContain("Only the timestamp moved");
+ expect(body).toContain("3 changed (1 meaningful, 1 noise omitted)");
+ expect(body).toContain("1 new");
+ expect(body).toContain("1 removed");
+ expect(body).toContain("1 error");
+ });
+
+ it("does not post when every changed page is noise and nothing else happened", async () => {
+ const result = await sendMonitoringSlackSummary({
+ monitor: slackMonitor(),
+ check: slackCheck({ changed_count: 2 }),
+ pages: [
+ page("https://example.com/clock", "changed", false, "timestamp"),
+ page("https://example.com/ads", "changed", false, "ad rotation"),
+ ],
+ });
+
+ expect(result).toMatchObject({ attempted: false, success: true });
+ expect(mockPost).not.toHaveBeenCalled();
+ });
+
+ it("still posts noise pages when judging is disabled", async () => {
+ const result = await sendMonitoringSlackSummary({
+ monitor: slackMonitor({ judge_enabled: false }),
+ check: slackCheck({ changed_count: 1 }),
+ pages: [
+ page(
+ "https://example.com/clock",
+ "changed",
+ false,
+ "Only the timestamp moved",
+ ),
+ ],
+ });
+
+ expect(result.attempted).toBe(true);
+ const body = postedText();
+ expect(body).toContain("https://example.com/clock");
+ expect(body).toContain("Only the timestamp moved");
+ expect(body).toContain("1 changed");
+ expect(body).not.toContain("noise omitted");
+ });
+
+ it("still posts noise pages when the goal is empty", async () => {
+ const result = await sendMonitoringSlackSummary({
+ monitor: slackMonitor({ goal: "" }),
+ check: slackCheck({ changed_count: 1 }),
+ pages: [page("https://example.com/clock", "changed", false, "timestamp")],
+ });
+
+ expect(result.attempted).toBe(true);
+ const body = postedText();
+ expect(body).toContain("https://example.com/clock");
+ expect(body).not.toContain("noise omitted");
+ });
+
+ it("keeps an unjudged changed page", async () => {
+ const result = await sendMonitoringSlackSummary({
+ monitor: slackMonitor(),
+ check: slackCheck({ changed_count: 1 }),
+ pages: [page("https://example.com/unjudged", "changed", null)],
+ });
+
+ expect(result.attempted).toBe(true);
+ const body = postedText();
+ expect(body).toContain("https://example.com/unjudged");
+ expect(body).not.toContain("noise omitted");
+ expect(body).toContain("1 changed");
+ });
+
+ it("omits a noise page list when the only rows in hand are noise but other activity remains", async () => {
+ const result = await sendMonitoringSlackSummary({
+ monitor: slackMonitor(),
+ check: slackCheck({ changed_count: 1, new_count: 2 }),
+ pages: [
+ page(
+ "https://example.com/clock",
+ "changed",
+ false,
+ "Only the timestamp moved",
+ ),
+ ],
+ });
+
+ expect(result.attempted).toBe(true);
+ const body = postedText();
+ expect(body).not.toContain("https://example.com/clock");
+ expect(body).not.toContain("Only the timestamp moved");
+ expect(body).toContain("1 changed (1 noise omitted)");
+ expect(body).toContain("2 new");
+ });
+
+ it("does not quote a window noise count against the full changed total", async () => {
+ const result = await sendMonitoringSlackSummary({
+ monitor: slackMonitor(),
+ check: slackCheck({ changed_count: 50, new_count: 1 }),
+ pages: [
+ page("https://example.com/price", "changed", true, "Pro price changed"),
+ page(
+ "https://example.com/clock",
+ "changed",
+ false,
+ "Only the timestamp moved",
+ ),
+ page("https://example.com/new-page", "new", false, "Still listed"),
+ ],
+ });
+
+ expect(result.attempted).toBe(true);
+ const body = postedText();
+ expect(body).toContain("https://example.com/price");
+ expect(body).toContain("https://example.com/new-page");
+ expect(body).not.toContain("https://example.com/clock");
+ expect(body).toContain("50 changed (1 meaningful)");
+ expect(body).not.toContain("noise omitted");
+ expect(body).not.toContain("0 noise");
+ });
+});
diff --git a/apps/api/src/services/notification/monitoring_slack.ts b/apps/api/src/services/notification/monitoring_slack.ts
index e3fa6aba5..13357ae67 100644
--- a/apps/api/src/services/notification/monitoring_slack.ts
+++ b/apps/api/src/services/notification/monitoring_slack.ts
@@ -8,6 +8,10 @@ import {
type MonitorSlackPage,
} from "../integrations/slack/messages";
import { buildMonitoringCheckDashboardUrl } from "./monitoring_email";
+import {
+ humanFacingAlertPages,
+ noiseOmittedFromAlertPages,
+} from "./monitoring_alert_pages";
const logger = _logger.child({ module: "monitoring-slack" });
@@ -114,7 +118,8 @@ export async function sendMonitoringSlackSummary(params: {
checkId: params.check.id,
});
- const slackPages: MonitorSlackPage[] = params.pages.map(page => ({
+ const alertPages = humanFacingAlertPages(params.monitor, params.pages);
+ const slackPages: MonitorSlackPage[] = alertPages.map(page => ({
url: page.url,
status: page.status,
judgment: page.judgment
@@ -135,6 +140,11 @@ export async function sendMonitoringSlackSummary(params: {
},
pages: slackPages,
creditsUsed: params.check.actual_credits,
+ noiseOmitted: noiseOmittedFromAlertPages(
+ params.monitor,
+ params.check,
+ params.pages,
+ ).noiseOmitted,
});
let res = await postSlackMessage({ token, channel: channelId, text, blocks });