Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
/**
* Verify that the runtime dependencies declared in package.json match those
* actually required by the source tree — no undeclared deps, no phantom deps.
*/
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "@suaveplan/testing/runner";
const PKG_ROOT = join(import.meta.dirname, "..");
const pkg = JSON.parse(
readFileSync(join(PKG_ROOT, "package.json"), "utf-8")
) as {
dependencies: Record<string, string>;
devDependencies: Record<string, string>;
};
describe("dep-graph", () => {
it("has zod as a runtime dep", { timeout: 5000 }, () => {
expect(pkg.dependencies["zod"]).toBeDefined();
});
it("has tslib as a runtime dep", { timeout: 5000 }, () => {
expect(pkg.dependencies["tslib"]).toBeDefined();
});
it("has @opentelemetry/api as a runtime dep", { timeout: 5000 }, () => {
expect(pkg.dependencies["@opentelemetry/api"]).toBeDefined();
});
it("does NOT have @suaveplan/error as a runtime dep (leaf package)", {
timeout: 5000,
}, () => {
expect(pkg.dependencies["@suaveplan/error"]).toBeUndefined();
});
it("does NOT have @suaveplan/types as a runtime dep (leaf package)", {
timeout: 5000,
}, () => {
expect(pkg.dependencies["@suaveplan/types"]).toBeUndefined();
});
it("has vitest as a devDep only", { timeout: 5000 }, () => {
expect(pkg.devDependencies["vitest"]).toBeDefined();
expect(pkg.dependencies["vitest"]).toBeUndefined();
});
it("has @vitest/coverage-istanbul as a devDep only", {
timeout: 5000,
}, () => {
expect(pkg.devDependencies["@vitest/coverage-istanbul"]).toBeDefined();
expect(pkg.dependencies["@vitest/coverage-istanbul"]).toBeUndefined();
});
});

View File

@@ -0,0 +1,63 @@
/**
* Enforce that production source files do not use disallowed globals
* (Math.random, Date.now, crypto.randomUUID) that would make the library
* non-deterministic or platform-dependent.
*/
import { readdirSync, readFileSync, statSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "@suaveplan/testing/runner";
const SRC_ROOT = join(import.meta.dirname, "../src");
const DISALLOWED = [
/\bMath\.random\b/,
/\bDate\.now\b/,
/\bcrypto\.randomUUID\b/,
];
// The tokenize strategy uses a module-level counter (no randomness).
// No files need to be approved for random usage.
const APPROVED_FILES: string[] = [];
function walkTs(dir: string): string[] {
const result: string[] = [];
for (const entry of readdirSync(dir)) {
const full = join(dir, entry);
if (statSync(full).isDirectory()) {
result.push(...walkTs(full));
} else if (entry.endsWith(".ts")) {
result.push(full);
}
}
return result;
}
function getSourceFiles(): string[] {
return walkTs(SRC_ROOT).filter(
(f) => !f.includes(".test.") && !f.includes(".bench.")
);
}
describe("no-disallowed globals", () => {
const sourceFiles = getSourceFiles();
it("found at least one source file to check", { timeout: 5000 }, () => {
expect(sourceFiles.length).toBeGreaterThan(0);
});
for (const pattern of DISALLOWED) {
it(`no source file uses ${pattern.source}`, { timeout: 5000 }, () => {
const violations: string[] = [];
for (const file of sourceFiles) {
const relative = file.replace(`${SRC_ROOT}/`, "");
if (APPROVED_FILES.some((ap) => file.endsWith(ap))) continue;
const content = readFileSync(file, "utf-8");
if (pattern.test(content)) {
violations.push(relative);
}
}
expect(violations).toEqual([]);
});
}
});

View File

@@ -0,0 +1,8 @@
// Ensure `globalThis.crypto` is available in bare-Node vitest runs.
import { webcrypto } from "node:crypto";
type WritableGlobal = { crypto?: Crypto };
const g = globalThis as WritableGlobal;
if (g.crypto === undefined) {
g.crypto = webcrypto as unknown as Crypto;
}

View File

@@ -0,0 +1,51 @@
/**
* Verify tree-shaking readiness:
* - sideEffects: false is set in package.json
* - At least 5 named subpath exports are declared
*/
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "@suaveplan/testing/runner";
const PKG_ROOT = join(import.meta.dirname, "..");
const pkg = JSON.parse(
readFileSync(join(PKG_ROOT, "package.json"), "utf-8")
) as {
sideEffects: boolean | string[];
exports: Record<string, unknown>;
};
describe("tree-shake", () => {
it("sideEffects is false", { timeout: 5000 }, () => {
expect(pkg.sideEffects).toBe(false);
});
it("has at least 4 subpath exports (excluding package.json)", {
timeout: 5000,
}, () => {
const subpaths = Object.keys(pkg.exports).filter(
(k) => k !== "./package.json"
);
expect(subpaths.length).toBeGreaterThanOrEqual(4);
});
it("root export '.' is declared", { timeout: 5000 }, () => {
expect(pkg.exports["."]).toBeDefined();
});
it("'./masker' subpath export is declared", { timeout: 5000 }, () => {
expect(pkg.exports["./masker"]).toBeDefined();
});
it("'./strategies' subpath export is declared", { timeout: 5000 }, () => {
expect(pkg.exports["./strategies"]).toBeDefined();
});
it("'./errors' subpath export is declared", { timeout: 5000 }, () => {
expect(pkg.exports["./errors"]).toBeDefined();
});
it("'./schemas' subpath export is declared", { timeout: 5000 }, () => {
expect(pkg.exports["./schemas"]).toBeDefined();
});
});