import assert from "node:assert/strict"; import { mkdir, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { tmpdir } from "node:os"; import { mkdtemp } from "node:fs/promises"; import { describe, it } from "vitest"; import { failureCount, gates, renderReport, reportPath, scanPostmarkOccurrences } from "./verify-transactional-mail-provider-baseline.mjs"; describe("verify-transactional-mail-provider-baseline", () => { it("defines the expected non-E2E gate commands", () => { assert.deepEqual( gates.map((gate) => [gate.id, gate.command, gate.args]), [ ["typecheck", "pnpm", ["run", "typecheck"]], ["lint", "pnpm", ["run", "lint"]], ["vitest-mail-runtime", "pnpm", ["exec", "vitest", "run", "packages/mail/src/mailersend.test.ts"]], ["postmark-scan", "internal", ["scan-postmark"]], ], ); const commandText = gates.map((gate) => [gate.command, ...gate.args].join(" ")).join("\n"); assert.doesNotMatch(commandText, /playwright|cypress|browser|test:e2e|e2e/i); }); it("derives failure counts from non-zero gate output", () => { assert.equal(failureCount("typecheck", "src/a.ts(1,1): error TS2322: wrong\nerror TS7006", ""), 2); assert.equal(failureCount("lint", "✖ 3 problems (2 errors, 1 warning)", ""), 2); assert.equal(failureCount("lint", "2 errors and 0 warnings potentially fixable", ""), 2); assert.equal(failureCount("vitest-mail-runtime", "Tests 4 failed | 10 passed", ""), 4); assert.equal(failureCount("vitest-mail-runtime", "Test Files 3 failed | 20 passed", ""), 3); assert.equal(failureCount("postmark-scan", JSON.stringify({ matchCount: 7, matches: [] }), ""), 7); assert.equal(failureCount("postmark-scan", JSON.stringify({ matchCount: 0, matches: [] }), ""), 0); assert.equal(failureCount("postmark-scan", "not json", ""), 1); }); it("renders Transactional Mail Provider report sections with exitcodes, failure counts, fingerprints, and report path text", () => { const report = renderReport([ { id: "typecheck", command: "pnpm run typecheck", exitCode: 2, durationMs: 123, failureCount: 5, fingerprint: { hash: "abc123", excerpt: "error TS2322" }, }, ]); assert.match(report, /# Transactional Mail Provider Baseline Health/); assert.match(report, /Transactional Mail Provider\ baseline/); assert.doesNotMatch(report, /API Auth Hardening Baseline Health/); assert.match(report, /## typecheck/); assert.match(report, /Exitcode: 2/); assert.match(report, /Failure Count: 5/); assert.match(report, /Output Fingerprint: abc123/); assert.match(reportPath, /\.tc\/baselines\/transactional-mail-provider\/baseline-health\.md$/); }); it("scans Postmark occurrences while ignoring generated and hidden output directories", async () => { const root = await mkdtemp(join(tmpdir(), "transactionalMailProvider-postmark-scan-")); await mkdir(join(root, "app"), { recursive: true }); await mkdir(join(root, "packages", "mail"), { recursive: true }); await mkdir(join(root, ".tc"), { recursive: true }); await mkdir(join(root, "node_modules", "postmark"), { recursive: true }); await mkdir(join(root, "build"), { recursive: true }); await mkdir(join(root, "dist"), { recursive: true }); await mkdir(join(root, ".react-router"), { recursive: true }); await mkdir(join(root, "generated.cache"), { recursive: true }); await writeFile(join(root, "app", "mailer.ts"), "const provider = 'Postmark';\n", "utf8"); await writeFile(join(root, "packages", "mail", "client.ts"), "const provider = 'postmark';\n", "utf8"); await writeFile(join(root, ".tc", "notes.md"), "Postmark ignored\n", "utf8"); await writeFile(join(root, "node_modules", "postmark", "index.js"), "postmark ignored\n", "utf8"); await writeFile(join(root, "build", "bundle.js"), "Postmark ignored\n", "utf8"); await writeFile(join(root, "dist", "bundle.js"), "postmark ignored\n", "utf8"); await writeFile(join(root, ".react-router", "types.d.ts"), "Postmark ignored\n", "utf8"); await writeFile(join(root, "generated.cache", "artifact.txt"), "Postmark ignored\n", "utf8"); const scan = await scanPostmarkOccurrences(root); assert.equal(scan.matchCount, 2); assert.deepEqual( scan.matches.map((match) => match.file), ["app/mailer.ts", "packages/mail/client.ts"], ); assert.match(scan.matches[0].text, /Postmark|postmark/); }); it("ignores only verifier self-files while reporting ordinary app and package Postmark references", async () => { const root = await mkdtemp(join(tmpdir(), "transactionalMailProvider-postmark-allowlist-")); await mkdir(join(root, "app"), { recursive: true }); await mkdir(join(root, "packages", "mail"), { recursive: true }); await mkdir(join(root, "scripts"), { recursive: true }); await writeFile(join(root, "app", "mailer.ts"), "const provider = 'Postmark';\n", "utf8"); await writeFile(join(root, "packages", "mail", "client.ts"), "const provider = 'postmark';\n", "utf8"); await writeFile(join(root, "scripts", "verify-transactional-mail-provider-baseline.mjs"), "Postmark scanner fixture\n", "utf8"); await writeFile( join(root, "scripts", "verify-transactional-mail-provider-baseline.test.mjs"), "Postmark scanner test fixture\n", "utf8", ); await writeFile(join(root, "scripts", "future-runtime-debt.mjs"), "const provider = 'Postmark';\n", "utf8"); const scan = await scanPostmarkOccurrences(root); assert.equal(scan.matchCount, 3); assert.deepEqual( scan.matches.map((match) => match.file), ["app/mailer.ts", "packages/mail/client.ts", "scripts/future-runtime-debt.mjs"], ); }); it("returns zero matches for fixtures without Postmark references", async () => { const root = await mkdtemp(join(tmpdir(), "transactionalMailProvider-postmark-empty-")); await mkdir(join(root, "app"), { recursive: true }); await writeFile(join(root, "app", "mailer.ts"), "const provider = 'mailersend';\n", "utf8"); const scan = await scanPostmarkOccurrences(root); assert.deepEqual(scan, { matchCount: 0, matches: [] }); }); }); ;