Files
webmail/lib/__tests__/collector-validator.ts
T
Linus Rath 3d5b02b75f fix: stop a page reporting once consent goes, and let nothing on disk aim the desktop app's telemetry
A review found that an open page kept sending to a DSN after consent was
taken back, that a state file or config file could name where telemetry
goes, and that `BULWARK_TELEMETRY=off` did nothing on the desktop build.
A due heartbeat now waits a random 30 s to 10 min, a refusal from the
collector isn't retried, crash files go at sign-out and account switch,
and server builds parse stacks as they did.

Existing assertions changed in the desktop telemetry tests: the catch-up
wait is now a range, the endpoint comes from the shell, and the platform
is `desktop` against the collector's patched branch.
2026-11-03 17:38:04 +01:00

27 lines
1.5 KiB
TypeScript

// Not a test: loads the collector's real validator for the tests that check against it.
import { spawnSync } from 'node:child_process';
import { existsSync, mkdtempSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
export interface CollectorValidator {
validate(input: unknown): { schema: string; build: string | null; platform: string; version: string; os_family: string; node_version: string | null } | null;
validateErrorBatch(input: unknown): { errors: { name: string; count: string; days: number; version: string; frames: unknown[] }[] } | null;
}
/**
* The validator on the branch the desktop app ships against, read from git so it doesn't
* matter what the dashboard checkout has out. Null where there's no dashboard repo (CI).
*/
export async function loadCollectorValidator(): Promise<CollectorValidator | null> {
const repo = process.env.BULWARK_DASHBOARD_DIR ?? 'C:/Users/info/Downloads/jmap-webmail/repos/dashboard';
const ref = process.env.BULWARK_DASHBOARD_REF ?? 'feat/desktop-platform';
if (!existsSync(repo)) return null;
const shown = spawnSync('git', ['-C', repo, 'show', `${ref}:telemetry-collector/src/validate.ts`], { encoding: 'utf8' });
if (shown.status !== 0) throw new Error(`no validator at ${ref}: ${shown.stderr}`);
const file = path.join(mkdtempSync(path.join(tmpdir(), 'bw-validator-')), 'validate.ts');
writeFileSync(file, shown.stdout);
return await import(/* @vite-ignore */ pathToFileURL(file).href) as CollectorValidator;
}