// THIS LANE'S FILES NEVER NAME THE MACHINE THEY WERE WRITTEN ON (review round // 2, M-A). The repository's history is published by the source mirror; a test // that spelled the account's user name or the hostname would publish it. This // reads the privacy lane's own files and fails if any carries the CURRENT // account's user name or this machine's hostname as a whole word — both // computed now, at test time, and never printed: the failure names the file // and which of the two, nothing else. A test that needs "the current user" // must ask os.userInfo() at run time. // // Run with: node_modules/.bin/tsx --test common/lib/privacy/noOperatorNames.test.ts import { test } from "node:test"; import assert from "node:assert/strict"; import { readdirSync, readFileSync, statSync } from "node:fs"; import os from "node:os"; import path from "node:path"; import { fileURLToPath } from "node:url"; const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", ".."); // The lane's files: whole directories, and single files. const DIRS = ["common/lib/privacy"]; const FILES = [ "common/lib/privacySettings.ts", "common/lib/scrubRuleLine.ts", "common/publish/scrubRuleLine.test.ts", "common/publish/privacyAudit.ts", "common/publish/privacyAudit.test.ts", "common/bin/privacy-audit.ts", "common/components/PrivacyProvider.tsx", "editor/e2e/privacy-audit.spec.ts", "umtool/e2e/privacy-audit.spec.ts", "umtool/lib/privacy.ts", "umtool/lib/privacy.test.ts", "umtool/lib/research/privacySources.test.ts", "editor/app/channels/components/SiteMembershipsSection.test.ts", ]; function files(): string[] { const out: string[] = []; for (const d of DIRS) { for (const name of readdirSync(path.join(ROOT, d))) { const rel = path.join(d, name); if (statSync(path.join(ROOT, rel)).isFile()) out.push(rel); } } return [...out, ...FILES]; } const word = (name: string) => new RegExp(`(? { let user = ""; try { user = os.userInfo().username; } catch { user = ""; } const names: Array<[string, string]> = []; if (user.length >= 3) names.push(["the account's user name", user]); const host = os.hostname(); for (const h of new Set([host, host.split(".")[0]])) if (h.length >= 3 && h !== "localhost") names.push(["this machine's hostname", h]); const bad: string[] = []; const list = files(); assert.ok(list.length > 10, "the lane's files were found"); for (const rel of list) { const text = readFileSync(path.join(ROOT, rel), "utf8"); for (const [what, name] of names) if (word(name).test(text)) bad.push(`${rel}: ${what}`); } assert.deepEqual(bad, []); });