Skip to content

Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA

TypeScript
4.2 KB
Raw Blame
/**
 * Two MEDIUM false positives from the gstack-evals runs (gstack 1.91.299-301):
 * pii.phone.e164 on `4294967296` (2^32, a PRNG constant) and pii.email on
 * `[email protected]` (a package@version filename). Each guard is
 * pinned in both directions: the false positive is clean, and the real shape
 * next to it still reports.
 */
import { describe, test, expect } from "bun:test";
import { scan } from "../lib/redact-engine";
import { isNumericConstant, looksLikeAtFilename } from "../lib/redact-patterns";

const flags = (id: string, s: string): boolean =>
  scan(s, { repoVisibility: "private" }).findings.some((f) => f.id === id);

describe("pii.phone.e164 and bare numeric constants", () => {
  // Value: protects=a bare power of two (or one less) and the common 32-bit hash/PRNG constants raise no phone finding; fails_when=the guard is
  // removed and `4294967296` reports pii.phone.e164 again; why_new=no constant guard existed; seam=none (scan); no_claim=other constants not listed
  test("powers of two, their max values and hash/PRNG constants are not phone numbers", () => {
    for (const s of [
      "const RANGE = 4294967296;",
      "mask = 4294967295",
      "INT32_MAX 2147483647",
      "x % 2147483648",
      "1073741824 bytes",
      "2^49 is 562949953421312",
      "h *= 2654435761",
      "seed ^= 2654435769",
      "a = 1103515245",
      "basis 2166136261",
      "mt init 1812433253",
      "p = 4294967291",
    ]) {
      expect([s, flags("pii.phone.e164", s)]).toEqual([s, false]);
    }
    expect(isNumericConstant("4294967296")).toBe(true);
    expect(isNumericConstant("4294967297")).toBe(false);
  });

  // Value: protects=the same digits written as a phone number (a +, spaces, dashes, parens) and ordinary bare numbers still report; fails_when=the
  // guard exempts by digits alone or by length, so +14294967296 or 429-496-7296 goes quiet; why_new=pins the narrowness of the new guard;
  // seam=none (scan); no_claim=international formats beyond the ones listed
  test("real phone numbers still report, including the constant's digits in phone form", () => {
    for (const s of [
      "tel: +14294967296",
      "call 429-496-7296",
      "reach +1 429 496 7296",
      "phone (429) 496-7296",
      "p 429.496.7296",
      "call 4294967297 now",
      "ring +44 20 7946 0958",
      "office 4155550123",
    ]) {
      expect([s, flags("pii.phone.e164", s)]).toEqual([s, true]);
    }
  });
});

describe("pii.email and package@version filenames", () => {
  // Value: protects=a filename with an @ (package@version, or a name ending in a file extension that is not a TLD) raises no email finding;
  // fails_when=the guard is removed and [email protected] reports pii.email again; why_new=no filename guard existed; seam=none (scan);
  // no_claim=extensions outside the closed list
  test("package@version and @-named files are not email addresses", () => {
    for (const s of [
      "results in [email protected]",
      "npm pack wrote [email protected]",
      "config [email protected]",
      "cache [email protected]",
      "pin [email protected]",
      "notes [email protected]",
    ]) {
      expect([s, flags("pii.email", s)]).toEqual([s, false]);
    }
    expect(looksLikeAtFilename("[email protected]")).toBe(true);
  });

  // Value: protects=real addresses still report, including numeric domain labels (163.com, 1.2.com), TLDs that double as file extensions (.sh, .md,
  // .py, .zip) and a file named after an address; fails_when=the guard treats any digit label, any extension-like TLD or any trailing extension as a
  // filename; why_new=pins the narrowness of the new guard; seam=none (scan); no_claim=every IANA TLD
  test("real addresses still report, numeric domains and extension-shaped TLDs included", () => {
    for (const s of [
      "mail [email protected]",
      "reach [email protected]",
      "ops [email protected]",
      "docs [email protected]",
      "py [email protected]",
      "files [email protected]",
      "contact [email protected]",
      "reach [email protected]",
      "export [email protected]",
      "log at [email protected]",
      "uploaded [email protected]",
      "archive [email protected]",
    ]) {
      expect([s, flags("pii.email", s)]).toEqual([s, true]);
    }
  });
});