mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-13 11:00:50 +00:00
refactor: dedupe cli config cron and install flows
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import type { FindExtraGatewayServicesOptions } from "../../daemon/inspect.js";
|
||||
import { findExtraGatewayServices } from "../../daemon/inspect.js";
|
||||
import type { ServiceConfigAudit } from "../../daemon/service-audit.js";
|
||||
import { auditGatewayServiceConfig } from "../../daemon/service-audit.js";
|
||||
import type { GatewayServiceRuntime } from "../../daemon/service-runtime.js";
|
||||
import { resolveGatewayService } from "../../daemon/service.js";
|
||||
import { resolveGatewayBindHost } from "../../gateway/net.js";
|
||||
import {
|
||||
@@ -54,19 +55,7 @@ export type DaemonStatus = {
|
||||
environment?: Record<string, string>;
|
||||
sourcePath?: string;
|
||||
} | null;
|
||||
runtime?: {
|
||||
status?: string;
|
||||
state?: string;
|
||||
subState?: string;
|
||||
pid?: number;
|
||||
lastExitStatus?: number;
|
||||
lastExitReason?: string;
|
||||
lastRunResult?: string;
|
||||
lastRunTime?: string;
|
||||
detail?: string;
|
||||
cachedLabel?: boolean;
|
||||
missingUnit?: boolean;
|
||||
};
|
||||
runtime?: GatewayServiceRuntime;
|
||||
configAudit?: ServiceConfigAudit;
|
||||
};
|
||||
config?: {
|
||||
|
||||
Reference in New Issue
Block a user