Files
open-design/tools/dev/tests/diagnostics.test.ts
PerishFireandGitHub bbdd4e84b5 chore: enforce test directory conventions (#496)
* chore: enforce test directory conventions

Move package, app, and tool tests out of src and add guard enforcement so source directories stay source-only.

* ci: use guard and package-scoped tests

Run the new repository guard in CI and keep test execution aligned with package-scoped commands after removing root aliases.

* ci: align stable release guard check

Use the new repository guard in stable release verification after replacing the residual-JS-only script.

* chore: tighten test layout enforcement

Enforce sibling tests directories, typecheck moved test suites with dedicated configs, and refresh remaining guidance that pointed at src-based tests.

* chore: clarify no-emit test tsconfigs

Explicitly disable declaration-only emit in test tsconfigs so review tooling sees they are no-emit typecheck configs.
2026-05-05 15:34:22 +08:00

45 lines
1.8 KiB
TypeScript

import assert from "node:assert/strict";
import { describe, it } from "node:test";
import {
appendStartupLogDiagnostics,
createStartupLogDiagnostics,
detectLogDiagnostics,
} from "../src/diagnostics.js";
describe("tools-dev diagnostics", () => {
it("detects native addon ABI mismatches", () => {
const diagnostics = detectLogDiagnostics([
"Error: The module '/repo/node_modules/better-sqlite3/build/Release/better_sqlite3.node'",
"was compiled against a different Node.js version using",
"NODE_MODULE_VERSION 127. This version of Node.js requires",
"NODE_MODULE_VERSION 137. Please try re-compiling or re-installing",
]);
assert.equal(diagnostics.length, 1);
assert.match(diagnostics[0].message, /native Node addon ABI mismatch/);
assert.match(diagnostics[0].recommendation, /rebuild better-sqlite3 --pending/);
assert.match(diagnostics[0].recommendation, /pnpm install/);
});
it("does not report diagnostics for unrelated logs", () => {
assert.deepEqual(detectLogDiagnostics(["daemon booting", "ready"]), []);
});
it("appends log tails and recommendations to startup timeout errors", () => {
const error = appendStartupLogDiagnostics(
new Error("daemon did not expose status in time"),
"daemon",
createStartupLogDiagnostics("/tmp/daemon.log", [
"better_sqlite3.node was compiled against a different Node.js version using",
"NODE_MODULE_VERSION 127. This version of Node.js requires NODE_MODULE_VERSION 137.",
]),
);
assert.match(error.message, /daemon did not expose status in time/);
assert.match(error.message, /daemon log tail \(\/tmp\/daemon\.log\)/);
assert.match(error.message, /better_sqlite3\.node/);
assert.match(error.message, /pnpm --filter @open-design\/daemon rebuild better-sqlite3 --pending/);
});
});