refactor: dedupe cli config cron and install flows

This commit is contained in:
Peter Steinberger
2026-03-02 19:48:38 +00:00
parent 9d30159fcd
commit b1c30f0ba9
80 changed files with 1379 additions and 2027 deletions

View File

@@ -15,6 +15,32 @@ vi.mock("../../infra/ports.js", () => ({
const originalPlatform = process.platform;
async function inspectUnknownListenerFallback(params: {
runtime: { status: "running"; pid: number } | { status: "stopped" };
includeUnknownListenersAsStale: boolean;
}) {
Object.defineProperty(process, "platform", { value: "win32", configurable: true });
classifyPortListener.mockReturnValue("unknown");
const service = {
readRuntime: vi.fn(async () => params.runtime),
} as unknown as GatewayService;
inspectPortUsage.mockResolvedValue({
port: 18789,
status: "busy",
listeners: [{ pid: 10920, command: "unknown" }],
hints: [],
});
const { inspectGatewayRestart } = await import("./restart-health.js");
return inspectGatewayRestart({
service,
port: 18789,
includeUnknownListenersAsStale: params.includeUnknownListenersAsStale,
});
}
describe("inspectGatewayRestart", () => {
beforeEach(() => {
inspectPortUsage.mockReset();
@@ -71,24 +97,8 @@ describe("inspectGatewayRestart", () => {
});
it("treats unknown listeners as stale on Windows when enabled", async () => {
Object.defineProperty(process, "platform", { value: "win32", configurable: true });
classifyPortListener.mockReturnValue("unknown");
const service = {
readRuntime: vi.fn(async () => ({ status: "stopped" })),
} as unknown as GatewayService;
inspectPortUsage.mockResolvedValue({
port: 18789,
status: "busy",
listeners: [{ pid: 10920, command: "unknown" }],
hints: [],
});
const { inspectGatewayRestart } = await import("./restart-health.js");
const snapshot = await inspectGatewayRestart({
service,
port: 18789,
const snapshot = await inspectUnknownListenerFallback({
runtime: { status: "stopped" },
includeUnknownListenersAsStale: true,
});
@@ -96,24 +106,8 @@ describe("inspectGatewayRestart", () => {
});
it("does not treat unknown listeners as stale when fallback is disabled", async () => {
Object.defineProperty(process, "platform", { value: "win32", configurable: true });
classifyPortListener.mockReturnValue("unknown");
const service = {
readRuntime: vi.fn(async () => ({ status: "stopped" })),
} as unknown as GatewayService;
inspectPortUsage.mockResolvedValue({
port: 18789,
status: "busy",
listeners: [{ pid: 10920, command: "unknown" }],
hints: [],
});
const { inspectGatewayRestart } = await import("./restart-health.js");
const snapshot = await inspectGatewayRestart({
service,
port: 18789,
const snapshot = await inspectUnknownListenerFallback({
runtime: { status: "stopped" },
includeUnknownListenersAsStale: false,
});
@@ -121,24 +115,8 @@ describe("inspectGatewayRestart", () => {
});
it("does not apply unknown-listener fallback while runtime is running", async () => {
Object.defineProperty(process, "platform", { value: "win32", configurable: true });
classifyPortListener.mockReturnValue("unknown");
const service = {
readRuntime: vi.fn(async () => ({ status: "running", pid: 10920 })),
} as unknown as GatewayService;
inspectPortUsage.mockResolvedValue({
port: 18789,
status: "busy",
listeners: [{ pid: 10920, command: "unknown" }],
hints: [],
});
const { inspectGatewayRestart } = await import("./restart-health.js");
const snapshot = await inspectGatewayRestart({
service,
port: 18789,
const snapshot = await inspectUnknownListenerFallback({
runtime: { status: "running", pid: 10920 },
includeUnknownListenersAsStale: true,
});