import assert from "node:assert/strict"; import { describe, it } from "vitest"; import { failureCount, gateFailureCount, gates, renderReport, reportPath } from "./verify-observability-console-baseline.mjs"; describe("verify-observability-console-baseline", () => { it("defines the expected non-E2E observability gate commands", () => { assert.deepEqual( gates.map((gate) => [gate.id, gate.command, gate.args]), [ ["typecheck", "pnpm", ["run", "typecheck"]], ["lint", "pnpm", ["run", "lint"]], [ "vitest-observability-boundary", "pnpm", [ "exec", "vitest", "run", "apps/api/src/middleware/request-id.test.ts", "apps/api/src/middleware/error-envelope.test.ts", "apps/worker/src/runtime.test.ts", "apps/worker/test/forced-failure.test.ts", ], ], ["console-inventory", "pnpm", ["exec", "tsx", "scripts/observability/scan-console.ts", "--check"]], ], ); }); it("does not count normal successful gate output as a failure", () => { assert.equal(failureCount("typecheck", "Done in 12.3s", ""), 0); assert.equal(failureCount("lint", "No lint warnings or errors\nDone in 6.1s", ""), 0); assert.equal(failureCount("vitest-observability-boundary", "Test Files 4 passed\nTests 38 passed", ""), 0); }); it("derives failure counts from failed 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-observability-boundary", "Tests 4 failed | 10 passed", ""), 4); assert.equal(failureCount("vitest-observability-boundary", "Test Files 3 failed | 20 passed", ""), 3); assert.equal(failureCount("console-inventory", "Console inventory matches: 17\napp/a.ts:1: console.log('x')", ""), 17); assert.equal(failureCount("console-inventory", "scan-console: 3 hit(s) across 2 file(s). Wrote docs/observability/console-migration-inventory.md", ""), 3); assert.equal(failureCount("console-inventory", "Console inventory matches: 0", ""), 0); assert.equal(failureCount("console-inventory", "scan-console: 0 hit(s) across 0 file(s). Wrote docs/observability/console-migration-inventory.md", ""), 0); assert.equal(failureCount("unknown-gate", "unexpected output", ""), 1); }); it("falls back to one failure when a gate exits non-zero without parseable errors", () => { assert.equal(gateFailureCount("typecheck", "Build failed without a TS code", "", 1), 1); assert.equal(gateFailureCount("lint", "Parsing error: unexpected token", "", 1), 1); assert.equal(gateFailureCount("vitest-observability-boundary", "Unhandled error between tests", "", 1), 1); assert.equal(gateFailureCount("typecheck", "Done in 12.3s", "", 0), 0); }); it("renders observability console report sections with exitcodes, failure counts and fingerprints", () => { const report = renderReport([ { id: "typecheck", command: "pnpm run typecheck", exitCode: 0, durationMs: 123, failureCount: 0, fingerprint: { hash: "abc123", excerpt: "Done in 12.3s" }, }, ]); assert.match(report, /# Observability Console Baseline Health/); assert.match(report, /## typecheck/); assert.match(report, /Exitcode: 0/); assert.match(report, /Failure Count: 0/); assert.match(report, /Output Fingerprint: abc123/); assert.match(reportPath, /\.tc\/baselines\/observability-console\/baseline-health\.md$/); }); });