@@ -47,6 +47,13 @@ const inspectPortConnections = vi.fn<(port: number) => Promise<PortConnections>>
4747 } ) ,
4848) ;
4949const readLastGatewayErrorLine = vi . fn ( async ( _env ?: NodeJS . ProcessEnv ) => null ) ;
50+ const loadInstalledPluginIndexInstallRecords = vi . fn <
51+ ( params ?: {
52+ env ?: NodeJS . ProcessEnv ;
53+ stateDir ?: string ;
54+ filePath ?: string ;
55+ } ) => Promise < Record < string , unknown > >
56+ > ( async ( _params ?) => ( { } ) ) ;
5057const readGatewayRestartHandoffSync = vi . fn <
5158 ( _env ?: NodeJS . ProcessEnv ) => GatewayRestartHandoff | null
5259> ( ( ) => null ) ;
@@ -196,6 +203,14 @@ vi.mock("./probe.js", () => ({
196203 probeGatewayStatus : ( opts : unknown ) => callGatewayStatusProbe ( opts ) ,
197204} ) ) ;
198205
206+ vi . mock ( "../../plugins/installed-plugin-index-record-reader.js" , ( ) => ( {
207+ loadInstalledPluginIndexInstallRecords : ( params ?: {
208+ env ?: NodeJS . ProcessEnv ;
209+ stateDir ?: string ;
210+ filePath ?: string ;
211+ } ) => loadInstalledPluginIndexInstallRecords ( params ) ,
212+ } ) ) ;
213+
199214vi . mock ( "./restart-health.js" , ( ) => ( {
200215 inspectGatewayRestart : ( opts : unknown ) => inspectGatewayRestart ( opts ) ,
201216} ) ) ;
@@ -230,6 +245,8 @@ describe("gatherDaemonStatus", () => {
230245 createConfigIOCalls . mockClear ( ) ;
231246 findStaleOpenClawUpdateLaunchdJobs . mockReset ( ) ;
232247 findStaleOpenClawUpdateLaunchdJobs . mockResolvedValue ( [ ] ) ;
248+ loadInstalledPluginIndexInstallRecords . mockClear ( ) ;
249+ loadInstalledPluginIndexInstallRecords . mockResolvedValue ( { } ) ;
233250 loadGatewayTlsRuntime . mockClear ( ) ;
234251 inspectGatewayRestart . mockClear ( ) ;
235252 inspectPortConnections . mockClear ( ) ;
@@ -396,6 +413,8 @@ describe("gatherDaemonStatus", () => {
396413 expect ( probeInput . tlsFingerprint ) . toBeUndefined ( ) ;
397414 expect ( status . gateway ?. probeUrl ) . toBe ( "wss://override.example:18790" ) ;
398415 expect ( status . rpc ?. url ) . toBe ( "wss://override.example:18790" ) ;
416+ expect ( loadInstalledPluginIndexInstallRecords ) . not . toHaveBeenCalled ( ) ;
417+ expect ( status . pluginVersionDrift ) . toBeUndefined ( ) ;
399418 } ) ;
400419
401420 it ( "uses fallback network details when interface discovery throws during status inspection" , async ( ) => {
@@ -587,7 +606,9 @@ describe("gatherDaemonStatus", () => {
587606 } ) ;
588607
589608 expect ( inspectPortConnections ) . not . toHaveBeenCalled ( ) ;
609+ expect ( loadInstalledPluginIndexInstallRecords ) . not . toHaveBeenCalled ( ) ;
590610 expect ( status . connections ) . toBeUndefined ( ) ;
611+ expect ( status . pluginVersionDrift ) . toBeUndefined ( ) ;
591612 } ) ;
592613
593614 it ( "uses the fast config path for plain same-file status reads" , async ( ) => {
@@ -900,4 +921,101 @@ describe("gatherDaemonStatus", () => {
900921 staleGatewayPids : [ 9000 ] ,
901922 } ) ;
902923 } ) ;
924+
925+ it ( "compares plugin drift against the running gateway version from the probe, not the CLI VERSION" , async ( ) => {
926+ // Gateway is still running an older version than the invoking CLI.
927+ // An npm plugin pinned to the running gateway version must NOT be
928+ // reported as drifted just because the CLI package is newer.
929+ callGatewayStatusProbe . mockResolvedValueOnce ( {
930+ ok : true ,
931+ url : "ws://127.0.0.1:19001" ,
932+ error : null ,
933+ server : { version : "2026.5.4" , connId : "c1" } ,
934+ } as never ) ;
935+ loadInstalledPluginIndexInstallRecords . mockResolvedValueOnce ( {
936+ whatsapp : {
937+ source : "npm" ,
938+ resolvedName : "@openclaw/whatsapp" ,
939+ resolvedVersion : "2026.5.4" ,
940+ } ,
941+ } as never ) ;
942+
943+ const status = await gatherDaemonStatus ( {
944+ rpc : { } ,
945+ probe : true ,
946+ deep : true ,
947+ } ) ;
948+
949+ expect ( status . pluginVersionDrift ?. gatewayVersion ) . toBe ( "2026.5.4" ) ;
950+ expect ( status . pluginVersionDrift ?. drifts ) . toEqual ( [ ] ) ;
951+ } ) ;
952+
953+ it ( "flags drift against the running gateway version when an npm plugin lags behind it" , async ( ) => {
954+ callGatewayStatusProbe . mockResolvedValueOnce ( {
955+ ok : true ,
956+ url : "ws://127.0.0.1:19001" ,
957+ error : null ,
958+ server : { version : "2026.5.4" , connId : "c1" } ,
959+ } as never ) ;
960+ loadInstalledPluginIndexInstallRecords . mockResolvedValueOnce ( {
961+ whatsapp : {
962+ source : "npm" ,
963+ resolvedName : "@openclaw/whatsapp" ,
964+ resolvedVersion : "2026.5.3" ,
965+ } ,
966+ } as never ) ;
967+
968+ const status = await gatherDaemonStatus ( {
969+ rpc : { } ,
970+ probe : true ,
971+ deep : true ,
972+ } ) ;
973+
974+ expect ( status . pluginVersionDrift ?. gatewayVersion ) . toBe ( "2026.5.4" ) ;
975+ expect ( status . pluginVersionDrift ?. drifts . map ( ( d ) => d . pluginId ) ) . toEqual ( [ "whatsapp" ] ) ;
976+ } ) ;
977+
978+ it ( "reads install records from the merged daemon service environment, not the CLI process env" , async ( ) => {
979+ await gatherDaemonStatus ( {
980+ rpc : { } ,
981+ probe : true ,
982+ deep : true ,
983+ } ) ;
984+
985+ // The mock daemon service command sets OPENCLAW_STATE_DIR=/tmp/openclaw-daemon,
986+ // distinct from the CLI process OPENCLAW_STATE_DIR=/tmp/openclaw-cli. Drift
987+ // detection must inspect the daemon profile's install records.
988+ expect ( loadInstalledPluginIndexInstallRecords ) . toHaveBeenCalledWith (
989+ expect . objectContaining ( {
990+ env : expect . objectContaining ( {
991+ OPENCLAW_STATE_DIR : "/tmp/openclaw-daemon" ,
992+ } ) ,
993+ } ) ,
994+ ) ;
995+ } ) ;
996+
997+ it ( "reads install records and computes drift outside deep mode" , async ( ) => {
998+ loadInstalledPluginIndexInstallRecords . mockResolvedValueOnce ( {
999+ whatsapp : {
1000+ source : "npm" ,
1001+ resolvedName : "@openclaw/whatsapp" ,
1002+ resolvedVersion : "2026.5.3" ,
1003+ } ,
1004+ } as never ) ;
1005+
1006+ const status = await gatherDaemonStatus ( {
1007+ rpc : { } ,
1008+ probe : true ,
1009+ deep : false ,
1010+ } ) ;
1011+
1012+ expect ( loadInstalledPluginIndexInstallRecords ) . toHaveBeenCalledWith (
1013+ expect . objectContaining ( {
1014+ env : expect . objectContaining ( {
1015+ OPENCLAW_STATE_DIR : "/tmp/openclaw-daemon" ,
1016+ } ) ,
1017+ } ) ,
1018+ ) ;
1019+ expect ( status . pluginVersionDrift ?. drifts . map ( ( d ) => d . pluginId ) ) . toEqual ( [ "whatsapp" ] ) ;
1020+ } ) ;
9031021} ) ;
0 commit comments