Files
SnapOtter/tests/unit/api/analytics-allowlist.test.ts
T
SnapOtterandGitHub 86251434b5 feat(telemetry): Sentry + PostHog quality pass (#546)
Comprehensive telemetry quality improvements across Sentry and PostHog, grounded in an audit of the live data plus current best-practice research.

Sentry: job_id/instance_id tags, operational fingerprinting, PII-safe settings context on bug events, web tag population + extension-noise filtering, an early-crash buffer, http status/method kept on breadcrumbs, and a gated-off-by-default performance-tracing re-enable (tracesSampler that zeroes db/redis/queue-poll root spans + drops the Redis integration) with worker job spans and canonical-host cron monitors.

PostHog: history_change SPA pageviews, instance_id super property for fleet rollups, enriched tool_used (formats, byte sizes, is_batch, execution_hint, real error_kind taxonomy), the previously-dead result_saved/batch_processed/ai_bundle_prompted events fired, search click-through, editor + Automate authoring + auth instrumentation, a before_send PII boundary, and minimal opt-in landing-site pageviews.
2026-07-17 01:51:48 +00:00

73 lines
2.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { sanitizeEventProperties } from "../../../apps/api/src/lib/analytics-allowlist.js";
describe("sanitizeEventProperties", () => {
it("keeps the enriched allow-listed keys for tool_used and drops free-text/PII", () => {
const out = sanitizeEventProperties("tool_used", {
tool_id: "resize",
status: "failed",
duration_ms: 12,
category: "image",
is_ai_tool: false,
is_batch: true,
input_format: "heic",
output_format: "png",
bytes_in: 4096,
bytes_out: 2048,
execution_hint: "fast",
error_kind: "input",
error_code: "corrupt-header",
error_message: "stack with /uploads/secret.docx",
params: { watermark_text: "CONFIDENTIAL" },
});
expect(out).toEqual({
tool_id: "resize",
status: "failed",
duration_ms: 12,
category: "image",
is_ai_tool: false,
is_batch: true,
input_format: "heic",
output_format: "png",
bytes_in: 4096,
bytes_out: 2048,
execution_hint: "fast",
error_kind: "input",
error_code: "corrupt-header",
});
expect(out).not.toHaveProperty("error_message");
expect(out).not.toHaveProperty("params");
});
it("drops non-primitive values", () => {
const out = sanitizeEventProperties("ai_bundle_action", {
bundle_id: "ocr",
action: "installed",
duration_ms: { nested: 1 } as unknown as number,
});
expect(out).toEqual({ bundle_id: "ocr", action: "installed" });
});
it("returns no properties for an unknown event", () => {
const out = sanitizeEventProperties("totally_new_event", { anything: "x" });
expect(out).toEqual({});
});
it("keeps only allow-listed keys for instance_started", () => {
const out = sanitizeEventProperties("instance_started", {
arch: "arm64",
os_platform: "linux",
deploy_mode: "embedded",
gpu_present: false,
hostname: "leaked-hostname",
});
expect(out).toEqual({
arch: "arm64",
os_platform: "linux",
deploy_mode: "embedded",
gpu_present: false,
});
expect(out).not.toHaveProperty("hostname");
});
});