Files
errors.bitreport.pt/ingest-api/src/lib/noisePolicy.test.ts
T
nelson-baptista b8ca70709e
CI / Test ingest-api (pull_request) Successful in 24s
CI / Test api (pull_request) Successful in 26s
CI / Lint and typecheck admin-ui (pull_request) Successful in 1m58s
CI / Validate Docker build (pull_request) Successful in 3m33s
fix(ingest): filter BIT-<id> smoke-test probes in noise policy (BIT-32681)
Hand-sent pipe-liveness probes referenced by a BIT task id (e.g.
`BIT-32663 smoke test` or `[BIT-30527] ... smoke test`) were not matched
by the ingest noise policy: they lack the reserved `BIT-SMOKE-` token and
the bracket-only fleet-audit regex, so they passed ingest and opened a
false-positive Error Loop issue (BIT-32681 / ERRCLUSTER a513bc4e4505).

- noisePolicy.ts: add `_BIT_ID_SMOKE_PROBE_RE` matching bare and bracketed
  `BIT-<id> ... smoke test` forms; filtered at every severity under the
  existing `bitreport_smoke_marker` rule. Bump ruleset 1.0.7 -> 1.0.8.
- noisePolicy.test.ts: cover bare, bracketed, critical-level, and a
  negative case (`Smoke detector sensor offline` stays unfiltered).
- paperclip_fleet_error_reporting_audit_once.py: relax `_SYNTHETIC_EVENT_RE`
  to the same bare/bracketed shape so ingest and fleet audit agree.
- docs/operations/ingest-hardening-runbook.md: document the new probe shape.

Verified locally: ingest-api vitest 44 passed | 14 skipped; typecheck clean;
reporter context contract ok; fleet audit py_compile ok.

Paperclip-Agent: José Alves (urlKey jos-alves; id 11179220-3cec-4f0f-880d-2771ff64fce8)
Paperclip-Issue: BIT-32681
Paperclip-Run: 64667793-6ac7-404b-80bc-f369f0c4f9e0
2026-11-20 09:42:08 +00:00

207 lines
6.1 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 bare 'BIT-<id> smoke test' pipe-liveness probe (BIT-32681)", () => {
const _r = evaluateNoise({
level: "error",
message: "BIT-32663 smoke test",
filePathHint: "",
});
expect(_r).toEqual({
matched: true,
ruleId: "bitreport_smoke_marker",
reason: "filtered_intentional_smoke_event",
});
});
it("matches bracketed '[BIT-<id>] ... smoke test' probe (fleet-audit synthetic form)", () => {
const _r = evaluateNoise({
level: "error",
message: "[BIT-30527] paperclip-chat pipe-liveness smoke test",
filePathHint: "",
});
expect(_r).toEqual({
matched: true,
ruleId: "bitreport_smoke_marker",
reason: "filtered_intentional_smoke_event",
});
});
it("suppresses 'BIT-<id> smoke test' probe even at critical level", () => {
const _r = evaluateNoise({
level: "critical",
message: "BIT-32663 smoke test",
filePathHint: "",
});
expect(_r).toEqual({
matched: true,
ruleId: "bitreport_smoke_marker",
reason: "filtered_intentional_smoke_event",
});
});
it("does not match a real error that merely contains 'smoke' without the BIT-<id> probe shape", () => {
const _r = evaluateNoise({
level: "error",
message: "Smoke detector sensor offline",
filePathHint: "",
});
expect(_r).toEqual({ matched: false });
});
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",
});
});
});