mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-23 19:08:22 -06: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:
@@ -1,6 +1,7 @@
|
||||
// Daemon lifecycle core tests cover service lifecycle transitions and platform adapters.
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import type { GatewayService } from "../../daemon/service.js";
|
||||
import {
|
||||
defaultRuntime,
|
||||
resetLifecycleRuntimeLogs,
|
||||
@@ -85,6 +86,26 @@ function stubServiceGatewayTokenEnv() {
|
||||
});
|
||||
}
|
||||
|
||||
async function withUnsupportedGatewayService(
|
||||
run: (unsupportedService: GatewayService) => Promise<void>,
|
||||
) {
|
||||
const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("aix");
|
||||
try {
|
||||
const { resolveGatewayService } = await import("../../daemon/service.js");
|
||||
await run(resolveGatewayService());
|
||||
} finally {
|
||||
platformSpy.mockRestore();
|
||||
}
|
||||
}
|
||||
|
||||
function expectUnsupportedServiceCheckFailure() {
|
||||
const payload = readJsonLog<{ ok?: boolean; error?: string }>();
|
||||
expect(payload.ok).toBe(false);
|
||||
expect(payload.error).toContain(
|
||||
"Gateway service check failed: Error: Gateway service install not supported on aix",
|
||||
);
|
||||
}
|
||||
|
||||
describe("runServiceRestart token drift", () => {
|
||||
beforeAll(async () => {
|
||||
({ runServiceRestart, runServiceStart, runServiceStop } = await import("./lifecycle-core.js"));
|
||||
@@ -110,6 +131,75 @@ describe("runServiceRestart token drift", () => {
|
||||
stubEmptyGatewayEnv();
|
||||
});
|
||||
|
||||
it("rejects unsupported-platform start before not-loaded recovery", async () => {
|
||||
const onNotLoaded = vi.fn(async () => ({
|
||||
result: "started" as const,
|
||||
message: "should not run",
|
||||
loaded: true,
|
||||
}));
|
||||
|
||||
await withUnsupportedGatewayService(async (unsupportedService) => {
|
||||
await expect(
|
||||
runServiceStart({
|
||||
serviceNoun: "Gateway",
|
||||
service: unsupportedService,
|
||||
renderStartHints: () => ["openclaw gateway install"],
|
||||
opts: { json: true },
|
||||
onNotLoaded,
|
||||
}),
|
||||
).rejects.toThrow("__exit__:1");
|
||||
});
|
||||
|
||||
expect(onNotLoaded).not.toHaveBeenCalled();
|
||||
expectUnsupportedServiceCheckFailure();
|
||||
});
|
||||
|
||||
it("rejects unsupported-platform stop before unmanaged fallback", async () => {
|
||||
const onNotLoaded = vi.fn(async () => ({
|
||||
result: "stopped" as const,
|
||||
message: "should not run",
|
||||
}));
|
||||
|
||||
await withUnsupportedGatewayService(async (unsupportedService) => {
|
||||
await expect(
|
||||
runServiceStop({
|
||||
serviceNoun: "Gateway",
|
||||
service: unsupportedService,
|
||||
opts: { json: true },
|
||||
onNotLoaded,
|
||||
}),
|
||||
).rejects.toThrow("__exit__:1");
|
||||
});
|
||||
|
||||
expect(onNotLoaded).not.toHaveBeenCalled();
|
||||
expectUnsupportedServiceCheckFailure();
|
||||
});
|
||||
|
||||
it("rejects unsupported-platform restart before unmanaged fallback", async () => {
|
||||
const onNotLoaded = vi.fn(async () => ({
|
||||
result: "restarted" as const,
|
||||
message: "should not run",
|
||||
}));
|
||||
const postRestartCheck = vi.fn(async () => {});
|
||||
|
||||
await withUnsupportedGatewayService(async (unsupportedService) => {
|
||||
await expect(
|
||||
runServiceRestart({
|
||||
serviceNoun: "Gateway",
|
||||
service: unsupportedService,
|
||||
renderStartHints: () => ["openclaw gateway install"],
|
||||
opts: { json: true },
|
||||
onNotLoaded,
|
||||
postRestartCheck,
|
||||
}),
|
||||
).rejects.toThrow("__exit__:1");
|
||||
});
|
||||
|
||||
expect(onNotLoaded).not.toHaveBeenCalled();
|
||||
expect(postRestartCheck).not.toHaveBeenCalled();
|
||||
expectUnsupportedServiceCheckFailure();
|
||||
});
|
||||
|
||||
it("prints the container restart hint when restart is requested for a not-loaded service", async () => {
|
||||
service.isLoaded.mockResolvedValue(false);
|
||||
vi.stubEnv("OPENCLAW_CONTAINER_HINT", "openclaw-demo-container");
|
||||
|
||||
Reference in New Issue
Block a user