mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-13 01:16:05 +00:00
fix(daemon): keep unsupported service status readable
Fixes #25621.\n\nKeep gateway status readable on unsupported service-manager platforms by returning a conservative read-only service adapter, while lifecycle mutations still reject clearly. Includes regression coverage for resolver, status, summary, and lifecycle behavior.\n\nVerified with focused Vitest/oxlint/diff checks, autoreview, and Azure Crabbox check:changed on lanes core/coreTests.
This commit is contained in:
@@ -40,9 +40,21 @@ describe("resolveGatewayService", () => {
|
||||
expect(service.loadedText).toBe(loadedText);
|
||||
});
|
||||
|
||||
it("throws for unsupported platforms", () => {
|
||||
it("returns a read-only unsupported-platform adapter", async () => {
|
||||
setPlatform("aix");
|
||||
expect(() => resolveGatewayService()).toThrow("Gateway service install not supported on aix");
|
||||
const service = resolveGatewayService();
|
||||
|
||||
await expect(service.readCommand(process.env)).resolves.toBeNull();
|
||||
await expect(service.isLoaded({ env: process.env })).rejects.toThrow(
|
||||
"Gateway service install not supported on aix",
|
||||
);
|
||||
await expect(service.readRuntime(process.env)).resolves.toEqual({
|
||||
status: "unknown",
|
||||
detail: "Gateway service install not supported on aix",
|
||||
});
|
||||
await expect(service.restart({ env: process.env, stdout: process.stdout })).rejects.toThrow(
|
||||
"Gateway service install not supported on aix",
|
||||
);
|
||||
});
|
||||
|
||||
it("guards mutating service adapters when config was written by a newer OpenClaw", async () => {
|
||||
|
||||
@@ -264,6 +264,33 @@ export function describeGatewayServiceRestart(
|
||||
|
||||
type SupportedGatewayServicePlatform = "darwin" | "linux" | "win32";
|
||||
|
||||
function createUnsupportedGatewayServiceError(): Error {
|
||||
return new Error(`Gateway service install not supported on ${process.platform}`);
|
||||
}
|
||||
|
||||
async function rejectUnsupportedGatewayService(): Promise<never> {
|
||||
throw createUnsupportedGatewayServiceError();
|
||||
}
|
||||
|
||||
function createUnsupportedGatewayService(): GatewayService {
|
||||
return {
|
||||
label: "Gateway service",
|
||||
loadedText: "available",
|
||||
notLoadedText: "not installed",
|
||||
stage: rejectUnsupportedGatewayService,
|
||||
install: rejectUnsupportedGatewayService,
|
||||
uninstall: rejectUnsupportedGatewayService,
|
||||
stop: rejectUnsupportedGatewayService,
|
||||
restart: rejectUnsupportedGatewayService,
|
||||
isLoaded: rejectUnsupportedGatewayService,
|
||||
readCommand: async () => null,
|
||||
readRuntime: async () => ({
|
||||
status: "unknown",
|
||||
detail: createUnsupportedGatewayServiceError().message,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
const GATEWAY_SERVICE_REGISTRY: Record<SupportedGatewayServicePlatform, GatewayService> = {
|
||||
darwin: {
|
||||
label: "LaunchAgent",
|
||||
@@ -344,5 +371,5 @@ export function resolveGatewayService(): GatewayService {
|
||||
if (isSupportedGatewayServicePlatform(process.platform)) {
|
||||
return withFutureConfigGuard(GATEWAY_SERVICE_REGISTRY[process.platform]);
|
||||
}
|
||||
throw new Error(`Gateway service install not supported on ${process.platform}`);
|
||||
return createUnsupportedGatewayService();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user