test: add unit and integration test suite

Add 34 tests (27 unit, 7 integration) using node:test runner:

Unit tests:
- pickServer(), findRoot(), pathToUri(), uriToPath()
- isLspCommand(), listCommands()
- formatHover(), formatDefinition(), formatReferences(), formatDiagnostics()

Integration tests:
- daemon lifecycle (status/stop) on isolated socket
- CLI --no-daemon queries (hover, documentSymbol, diagnostics)

Supporting changes:
- socketPath() honors PI_LSP_SOCKET_PATH env var for test isolation
- test fixtures for valid and broken TypeScript files
- npm test / test:unit / test:integration scripts
This commit is contained in:
2026-04-30 10:36:54 -04:00
parent e131e0e8cd
commit aa7309b363
11 changed files with 698 additions and 2 deletions

View File

@@ -45,7 +45,10 @@ export type DaemonResponse =
// Socket Path - Per-user socket; XDG_RUNTIME_DIR when available (tmpfs,
// auto-cleaned on logout), tmpdir() otherwise. We include the uid so two
// users on the same box don't collide on a shared tmpdir.
// `PI_LSP_SOCKET_PATH` env var overrides everything — used by tests to
// isolate test daemons from session daemons.
export function socketPath(): string {
if (process.env.PI_LSP_SOCKET_PATH) return process.env.PI_LSP_SOCKET_PATH;
const uid =
typeof process.getuid === "function" ? String(process.getuid()) : "0";
const dir = process.env.XDG_RUNTIME_DIR ?? os.tmpdir();