Files
pi2d/test/cli/helpers.ts
T
yuez 7e780515ac feat(cli)!: merge the daemon into pi2 as the daemon subcommand
`pi2 daemon [start] [flags]` now starts the web-console daemon. The
`pi2d` executable, its bin entry and its entry module are removed: the
daemon keeps its lock -> token -> plugin socket -> listen -> daemon.json
lifecycle, its single stdout line (`pi2 daemon listening on ...`) and the
signal handling that leaves managed nvim instances running.

Service files are renamed to `pi2.service` / `com.pi2.daemon`, and the
smoke and e2e harnesses start the daemon through `pi2 daemon`.

BREAKING CHANGE: the `pi2d` command no longer exists; use `pi2 daemon`
(or `pi2 daemon start`). Existing systemd/launchd units installed under
the old names must be reinstalled with `pi2 install-service --write`.
2026-10-22 15:47:48 +08:00

56 lines
1.8 KiB
TypeScript

/** Shared helpers for the CLI specs (temp dirs, silent logger, bare config). */
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import type { Config, Limits } from "../../src/config.js";
import type { Logger } from "../../src/core/interfaces.js";
export const TEST_LIMITS: Limits = {
maxBodyBytes: 8 * 1024 * 1024,
maxFrameBytes: 8 * 1024 * 1024,
maxConnections: 64,
};
export function tempDir(prefix = "pi2-daemon-cli-"): string {
return mkdtempSync(join(tmpdir(), prefix));
}
export function removeDir(dir: string): void {
rmSync(dir, { recursive: true, force: true });
}
export function testConfig(overrides: Partial<Config> = {}): Config {
const base: Config = {
host: "127.0.0.1",
port: 0,
staticDir: "/nonexistent-web-dist",
corsOrigins: [],
limits: TEST_LIMITS,
tokenPath: "/tmp/pi2-daemon-cli-test.sock.token",
deviceStorePath: "/tmp/pi2-daemon-cli-test-devices.json",
};
return { ...base, ...overrides, limits: { ...base.limits, ...(overrides.limits ?? {}) } };
}
export const silentLogger: Logger = {
debug: () => undefined,
info: () => undefined,
warn: () => undefined,
error: () => undefined,
child: () => silentLogger,
};
export function setRuntimeEnv(dir: string): void {
process.env.PI2_RUNTIME_DIR = join(dir, "run");
process.env.PI2_DATA_DIR = join(dir, "data");
process.env.PI2_STATE_DIR = join(dir, "state");
process.env.PI2_PORT = "0";
process.env.PI2_STATIC_DIR = join(dir, "web");
}
export function clearRuntimeEnv(): void {
for (const key of ["PI2_RUNTIME_DIR", "PI2_DATA_DIR", "PI2_STATE_DIR", "PI2_PORT", "PI2_STATIC_DIR"]) {
delete process.env[key];
}
}