@@ -270,6 +270,64 @@ describe("plugins cli update", () => {
270270 expect ( writeConfigFile ) . not . toHaveBeenCalled ( ) ;
271271 } ) ;
272272
273+ it . each ( [
274+ { id : "missing-plugin" , args : [ ] } ,
275+ { id : "missing-plugin" , args : [ "--dry-run" ] } ,
276+ { id : "constructor" , args : [ ] } ,
277+ { id : "@acme/missing-plugin@beta" , args : [ ] } ,
278+ ] ) ( "rejects untracked update target $id $args" , async ( { id, args } ) => {
279+ const config = { } as OpenClawConfig ;
280+ primeUpdateConfigSnapshot ( { config } ) ;
281+ updateNpmInstalledPlugins . mockResolvedValue ( {
282+ config,
283+ changed : false ,
284+ outcomes : [ { pluginId : id , status : "skipped" , message : `No install record for "${ id } ".` } ] ,
285+ } ) ;
286+
287+ await expect ( runPluginsCommand ( [ "plugins" , "update" , id , ...args ] ) ) . rejects . toThrow (
288+ "__exit__:1" ,
289+ ) ;
290+
291+ expect ( runtimeErrors . at ( - 1 ) ) . toContain ( `No tracked plugin or hook pack found for "${ id } ".` ) ;
292+ expect ( updateNpmInstalledPlugins ) . not . toHaveBeenCalled ( ) ;
293+ expect ( updateNpmInstalledHookPacks ) . not . toHaveBeenCalled ( ) ;
294+ expect ( writeConfigFile ) . not . toHaveBeenCalled ( ) ;
295+ } ) ;
296+
297+ it ( "rejects an npm update target shared by multiple tracked plugins" , async ( ) => {
298+ const config = {
299+ plugins : {
300+ installs : {
301+ alpha : {
302+ source : "npm" ,
303+ spec : "@acme/shared" ,
304+ installPath : "/tmp/alpha" ,
305+ resolvedName : "@acme/shared" ,
306+ } ,
307+ beta : {
308+ source : "npm" ,
309+ spec : "@acme/shared" ,
310+ installPath : "/tmp/beta" ,
311+ resolvedName : "@acme/shared" ,
312+ } ,
313+ } ,
314+ } ,
315+ } as OpenClawConfig ;
316+ primeUpdateConfigSnapshot ( { config } ) ;
317+ setInstalledPluginIndexInstallRecords ( config . plugins ?. installs ?? { } ) ;
318+
319+ await expect ( runPluginsCommand ( [ "plugins" , "update" , "@acme/shared@beta" ] ) ) . rejects . toThrow (
320+ "__exit__:1" ,
321+ ) ;
322+
323+ expect ( runtimeErrors . at ( - 1 ) ) . toContain (
324+ 'No tracked plugin or hook pack found for "@acme/shared@beta".' ,
325+ ) ;
326+ expect ( updateNpmInstalledPlugins ) . not . toHaveBeenCalled ( ) ;
327+ expect ( updateNpmInstalledHookPacks ) . not . toHaveBeenCalled ( ) ;
328+ expect ( writeConfigFile ) . not . toHaveBeenCalled ( ) ;
329+ } ) ;
330+
273331 it ( "updates tracked hook packs through plugins update" , async ( ) => {
274332 const cfg = { } as OpenClawConfig ;
275333 const nextConfig = cfg ;
@@ -303,8 +361,9 @@ describe("plugins cli update", () => {
303361 await runPluginsCommand ( [ "plugins" , "update" , "demo-hooks" ] ) ;
304362
305363 const hookUpdateParams = expectSingleCallParams ( updateNpmInstalledHookPacks ) ;
306- expect ( hookUpdateParams . config ) . toBe ( cfg ) ;
364+ expect ( hookUpdateParams . config ) . toEqual ( { ... cfg , plugins : { installs : { } } } ) ;
307365 expect ( hookUpdateParams . hookIds ) . toEqual ( [ "demo-hooks" ] ) ;
366+ expect ( updateNpmInstalledPlugins ) . not . toHaveBeenCalled ( ) ;
308367 expect ( writeConfigFile ) . toHaveBeenCalledWith ( nextConfig ) ;
309368 expect ( replaceConfigFile ) . toHaveBeenCalledWith (
310369 expect . objectContaining ( { nextConfig, baseHash : "update-config" } ) ,
@@ -973,12 +1032,12 @@ describe("plugins cli update", () => {
9731032 await runPluginsCommand ( [ "plugins" , "update" , "demo-hooks" ] ) ;
9741033
9751034 expect ( runtimeErrors ) . toEqual ( [ ] ) ;
976- const pluginUpdateParams = expectSingleCallParams ( updateNpmInstalledPlugins ) ;
977- expect ( pluginUpdateParams . config ) . toEqual ( {
1035+ const hookUpdateParams = expectSingleCallParams ( updateNpmInstalledHookPacks ) ;
1036+ expect ( hookUpdateParams . config ) . toEqual ( {
9781037 ...cfg ,
9791038 plugins : { installs : { } } ,
9801039 } ) ;
981- expect ( updateNpmInstalledHookPacks ) . toHaveBeenCalledOnce ( ) ;
1040+ expect ( updateNpmInstalledPlugins ) . not . toHaveBeenCalled ( ) ;
9821041 expect ( writeConfigFile ) . not . toHaveBeenCalled ( ) ;
9831042 } ) ;
9841043
0 commit comments