Files
SnapOtter/tests/e2e-docker/analytics-disabled.spec.ts
T
SnapOtterandGitHub ae6a4c8b7c fix: error-only Sentry telemetry, storm-proof capture, and crash fixes (#476)
Removes Sentry tracing entirely (BullMQ idle polling burned 4.8M transactions in 2 days at the baked 0.1 rate), decouples PostHog sampling, and replaces the type-only error scrub with a vetted-field sanitizer plus SafeError/ToolInputError contracts. One classified capture path with per-signature throttles and a per-process ceiling makes storms impossible (NODE-1E was 4,541 events from one 30s loop). Browser errors move to a dedicated web Sentry project with their own source maps. Adds the SNAPOTTER_TELEMETRY runtime kill switch and silences test fleets.

Crash fixes: remote 204/304 SSRF process kill (NODE-20), conversion-preset boot crash loop (NODE-21), Redis version preflight + unhandled subscribe rejection (NODE-1T), Sign PDF on plain-http origins (NODE-1K/1M), wavesurfer/pdf.js teardown rejections (NODE-1P/1N), bundle-import ZlibError to 400 (NODE-1Z), chart-maker input errors declassified (NODE-1H/1J), asset requests skip the session DB lookup (NODE-1D).
2026-07-10 21:41:49 +08:00

84 lines
2.5 KiB
TypeScript

import { expect, test } from "@playwright/test";
// Tests for behavior when analytics is disabled at build time.
// Skip automatically if the container was built with analytics enabled.
// biome-ignore lint/suspicious/noUndeclaredEnvVars: e2e test env var
const BASE_URL = process.env.API_URL ?? "http://localhost:1349";
async function loginFresh(page: import("@playwright/test").Page) {
await page.goto("/login");
await page.getByLabel("Username").fill("admin");
await page.getByLabel("Password").fill("admin");
await page.getByRole("button", { name: /login/i }).click();
}
test.describe("Analytics disabled by build-time config", () => {
test.use({ storageState: { cookies: [], origins: [] } });
test.beforeEach(async ({ request: _request }, testInfo) => {
const res = await fetch(`${BASE_URL}/api/v1/config/analytics`);
const config = await res.json();
if (config.enabled) {
testInfo.skip();
}
});
test("config endpoint returns disabled with empty fields", async ({ request }) => {
const res = await request.get("/api/v1/config/analytics");
expect(res.ok()).toBeTruthy();
const config = await res.json();
expect(config).toEqual({
enabled: false,
posthogApiKey: "",
posthogHost: "",
sentryDsn: "",
sentryDsnWeb: "",
posthogSampleRate: 0,
instanceId: "",
});
});
test("login goes directly to home (no consent screen)", async ({ page }) => {
await loginFresh(page);
await page.waitForURL("/", { timeout: 30_000 });
await expect(page).toHaveURL("/");
});
test("no outbound network requests to PostHog or Sentry", async ({ page }) => {
const analyticsRequests: string[] = [];
await page.route("**/*", (route) => {
const url = route.request().url();
let host = "";
try {
host = new URL(url).hostname.toLowerCase();
} catch {
// non-URL scheme
}
if (
host === "posthog.com" ||
host.endsWith(".posthog.com") ||
host === "sentry.io" ||
host.endsWith(".sentry.io")
) {
analyticsRequests.push(url);
}
return route.continue();
});
await loginFresh(page);
await page.waitForURL("/", { timeout: 30_000 });
await page.goto("/resize");
await page.waitForTimeout(2_000);
await page.goto("/compress");
await page.waitForTimeout(2_000);
await page.goto("/");
await page.waitForTimeout(2_000);
expect(analyticsRequests).toEqual([]);
});
});