Skip to content

Commit 7e6914f

Browse files
committed
fix(raft): report missing CLI in channel status
1 parent 24bc614 commit 7e6914f

2 files changed

Lines changed: 64 additions & 7 deletions

File tree

‎extensions/raft/src/channel.test.ts‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
import { describe, expect, it } from "vitest";
1+
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
2+
import { beforeEach, describe, expect, it, vi } from "vitest";
23
import { raftPlugin } from "./channel.js";
34

5+
const detectBinaryMock = vi.hoisted(() => vi.fn());
6+
7+
vi.mock("openclaw/plugin-sdk/setup-tools", async (importOriginal) => ({
8+
...(await importOriginal<typeof import("openclaw/plugin-sdk/setup-tools")>()),
9+
detectBinary: detectBinaryMock,
10+
}));
11+
412
describe("Raft channel plugin", () => {
13+
beforeEach(() => {
14+
detectBinaryMock.mockReset();
15+
});
16+
517
it("declares a wake-only direct channel", () => {
618
expect(raftPlugin.meta).toMatchObject({
719
id: "raft",
@@ -13,4 +25,42 @@ describe("Raft channel plugin", () => {
1325
expect(raftPlugin.message).toBeUndefined();
1426
expect(raftPlugin.outbound).toBeUndefined();
1527
});
28+
29+
it.each([
30+
{
31+
detected: true,
32+
expected: { ok: true, cliFound: true, error: null },
33+
},
34+
{
35+
detected: false,
36+
expected: {
37+
ok: false,
38+
cliFound: false,
39+
error: "Raft CLI not found on the Gateway PATH",
40+
},
41+
},
42+
])(
43+
"maps CLI detection to a coherent status outcome when detected=$detected",
44+
async ({ detected, expected }) => {
45+
detectBinaryMock.mockResolvedValueOnce(detected);
46+
const cfg = {
47+
channels: {
48+
raft: {
49+
profile: "test-profile",
50+
},
51+
},
52+
} as OpenClawConfig;
53+
const account = raftPlugin.config.resolveAccount(cfg, "default");
54+
55+
const result = await raftPlugin.status!.probeAccount!({
56+
account,
57+
timeoutMs: 1_000,
58+
cfg,
59+
});
60+
61+
expect(detectBinaryMock).toHaveBeenCalledOnce();
62+
expect(detectBinaryMock).toHaveBeenCalledWith("raft");
63+
expect(result).toEqual(expected);
64+
},
65+
);
1666
});

‎extensions/raft/src/channel.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import { raftChannelConfigSchema } from "./config-schema.js";
1919
import { startRaftGatewayAccount } from "./gateway.js";
2020
import { raftSetupPlugin } from "./setup.js";
2121

22-
type RaftProbe = {
23-
cliFound: boolean;
24-
};
22+
type RaftProbe =
23+
| { ok: true; cliFound: true; error: null }
24+
| { ok: false; cliFound: false; error: string };
2525

2626
export const raftPlugin: ChannelPlugin<ResolvedRaftAccount, RaftProbe> = createChatChannelPlugin({
2727
base: {
@@ -61,9 +61,16 @@ export const raftPlugin: ChannelPlugin<ResolvedRaftAccount, RaftProbe> = createC
6161
status: createComputedAccountStatusAdapter<ResolvedRaftAccount, RaftProbe>({
6262
defaultRuntime: createDefaultChannelRuntimeState("default"),
6363
buildChannelSummary: ({ snapshot }) => buildBaseChannelStatusSummary(snapshot),
64-
probeAccount: async () => ({
65-
cliFound: await detectBinary("raft"),
66-
}),
64+
probeAccount: async () => {
65+
const cliFound = await detectBinary("raft");
66+
return cliFound
67+
? { ok: true, cliFound: true, error: null }
68+
: {
69+
ok: false,
70+
cliFound: false,
71+
error: "Raft CLI not found on the Gateway PATH",
72+
};
73+
},
6774
formatCapabilitiesProbe: ({ probe }) => [
6875
{
6976
text: `Raft CLI: ${probe.cliFound ? "found" : "missing"}`,

0 commit comments

Comments
 (0)