Files
errors.bitreport.pt/ingest-api/src/lib/noisePolicy.test.ts
T
David SantosandCursor 8773f12b25
CI / Validate Docker build (pull_request) Failing after 12m46s
CI / Lint and typecheck admin-ui (pull_request) Failing after 13m16s
CI / Test api (pull_request) Failing after 13m20s
CI / Test ingest-api (pull_request) Successful in 15m35s
feat(hub): retire WDMI projects from error reporting (BIT-24704)
Block ingest for retired WDMI slugs, purge project data via migration,
remove WDMI runbooks, and add offboard-project helper for future retirements.

Co-authored-by: Cursor <[email protected]>
2026-06-08 14:26:06 +00:00

159 lines
4.8 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { evaluateNoise, NOISE_RULESET_VERSION } from "./noisePolicy.js";
describe("evaluateNoise", () => {
it("matches ResizeObserver browser noise", () => {
const _r = evaluateNoise({
level: "error",
message: "ResizeObserver loop completed with undelivered notifications.",
filePathHint: "",
});
expect(_r).toEqual({
matched: true,
ruleId: "resize_observer_loop",
reason: "filtered_browser_noise",
});
});
it("does not suppress when level maps to critical", () => {
const _r = evaluateNoise({
level: "fatal",
message: "ResizeObserver loop completed with undelivered notifications.",
filePathHint: "",
});
expect(_r).toEqual({ matched: false });
});
it("matches CRM external resource + cloudflare filename", () => {
const _r = evaluateNoise({
level: "error",
message: "Resource failed to load",
filePathHint: "https://cdn.cloudflare.com/beacon.min.js",
});
expect(_r.matched).toBe(true);
if (_r.matched) {
expect(_r.ruleId).toBe("external_resource_cloudflare_beacon");
}
});
it("reads url from browser_info for cloudflare check", () => {
const _r = evaluateNoise({
level: "error",
message: "Resource failed to load",
filePathHint: "",
context: {
browser_info: { url: "https://static.cloudflare.com/x.js" },
},
});
expect(_r.matched).toBe(true);
});
it("exports a semver-ish ruleset version", () => {
expect(NOISE_RULESET_VERSION).toMatch(/^\d+\.\d+\.\d+$/);
});
it("matches Alpine _x_refreshXForScope teardown noise", () => {
const _r = evaluateNoise({
level: "error",
message:
"Uncaught TypeError: Cannot read properties of undefined (reading '_x_refreshXForScope')",
filePathHint: "/data/wwwroot/crm/app/Modules/ErrorMonitoring/Controllers/ErrorMonitoringController.php",
});
expect(_r).toEqual({
matched: true,
ruleId: "alpine_refresh_x_for_scope_teardown",
reason: "filtered_transient_frontend_noise",
});
});
it("does not suppress Alpine teardown noise at critical level", () => {
const _r = evaluateNoise({
level: "critical",
message:
"Uncaught TypeError: Cannot read properties of undefined (reading '_x_refreshXForScope')",
filePathHint: "",
});
expect(_r).toEqual({ matched: false });
});
it("matches reserved BIT-SMOKE- probe messages (direct ingest smoke)", () => {
const _r = evaluateNoise({
level: "error",
message: "Error: BIT-SMOKE-CRM-DIRECT-INGEST",
filePathHint: "/smoke/crm-main.php",
});
expect(_r).toEqual({
matched: true,
ruleId: "bitreport_smoke_marker",
reason: "filtered_intentional_smoke_event",
});
});
it("suppresses BIT-SMOKE- even at critical ingest level", () => {
const _r = evaluateNoise({
level: "critical",
message: "BIT-SMOKE-CRM-DIRECT-INGEST",
filePathHint: "",
});
expect(_r).toEqual({
matched: true,
ruleId: "bitreport_smoke_marker",
reason: "filtered_intentional_smoke_event",
});
});
it("matches BIT-SMOKE- in stack_trace when message omits the marker (CRM PHP smoke)", () => {
const _r = evaluateNoise({
level: "error",
message: "PHP exception",
stackText: "Error: BIT-SMOKE-CRM-MAIN-DIRECT\n#0 smoke",
filePathHint: "/smoke/crm-main.php",
});
expect(_r).toEqual({
matched: true,
ruleId: "bitreport_smoke_marker",
reason: "filtered_intentional_smoke_event",
});
});
it("matches BIT-SMOKE-CRM-DIRECT-FWD message (BIT-933 / crm.php forward)", () => {
const _r = evaluateNoise({
level: "error",
message: "BIT-SMOKE-CRM-DIRECT-FWD",
stackText: "Error: BIT-SMOKE-CRM-DIRECT-FWD\n#0 smoke",
filePathHint: "/smoke/crm.php",
});
expect(_r).toEqual({
matched: true,
ruleId: "bitreport_smoke_marker",
reason: "filtered_intentional_smoke_event",
});
});
it("matches BIT-SMOKE marker when hyphen is unicode non-breaking hyphen (U+2011)", () => {
const _r = evaluateNoise({
level: "error",
message: "BIT\u2011SMOKE\u2011CRM\u2011DIRECT\u2011FWD",
filePathHint: "",
});
expect(_r).toEqual({
matched: true,
ruleId: "bitreport_smoke_marker",
reason: "filtered_intentional_smoke_event",
});
});
it("matches CRM deploy ingest live-check failure ribbon (BIT-931 family)", () => {
const _r = evaluateNoise({
level: "critical",
message: "BIT-SMOKE error hub ingest live check",
filePathHint: "",
});
expect(_r).toEqual({
matched: true,
ruleId: "bitreport_smoke_marker",
reason: "filtered_deploy_ingest_probe_failure",
});
});
});