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" ;
23import { 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+
412describe ( "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} ) ;
0 commit comments