@@ -17,6 +17,7 @@ const mocks = vi.hoisted(() => {
1717 return {
1818 defaultRuntime,
1919 getRuntimeConfig : vi . fn ( ) ,
20+ listMarketplacePlugins : vi . fn ( ) ,
2021 loadConfiguredHostedOfficialExternalPluginCatalogEntries : vi . fn ( ) ,
2122 } ;
2223} ) ;
@@ -42,6 +43,10 @@ vi.mock("../plugins/official-external-plugin-catalog.js", async (importOriginal)
4243 } ;
4344} ) ;
4445
46+ vi . mock ( "../plugins/marketplace.js" , ( ) => ( {
47+ listMarketplacePlugins : mocks . listMarketplacePlugins ,
48+ } ) ) ;
49+
4550async function createTimelinePath ( ) : Promise < string > {
4651 const dir = await mkdtemp ( path . join ( tmpdir ( ) , "openclaw-marketplace-entries-" ) ) ;
4752 return path . join ( dir , "timeline.jsonl" ) ;
@@ -311,3 +316,75 @@ describe("plugins marketplace entries", () => {
311316 expect ( JSON . stringify ( event ) ) . not . toContain ( "token=leak" ) ;
312317 } ) ;
313318} ) ;
319+
320+ describe ( "plugins marketplace list" , ( ) => {
321+ const source = "owner/repo" ;
322+ const manifest = {
323+ name : "QA Marketplace" ,
324+ version : "1.0.0" ,
325+ plugins : [ { name : "demo" , source : { kind : "path" , path : "./plugins/demo" } } ] ,
326+ } ;
327+
328+ beforeEach ( ( ) => {
329+ mocks . defaultRuntime . error . mockClear ( ) ;
330+ mocks . defaultRuntime . exit . mockClear ( ) ;
331+ mocks . defaultRuntime . log . mockClear ( ) ;
332+ mocks . defaultRuntime . writeJson . mockClear ( ) ;
333+ mocks . listMarketplacePlugins . mockReset ( ) ;
334+ } ) ;
335+
336+ function mockMarketplaceListResult ( result : { ok : boolean ; error ?: string } ) {
337+ mocks . listMarketplacePlugins . mockImplementationOnce (
338+ async ( { logger } : { logger ?: { info ?: ( message : string ) => void } } ) => {
339+ logger ?. info ?.( `Cloning marketplace source ${ source } ...` ) ;
340+ return result . ok
341+ ? { ok : true , sourceLabel : source , manifest }
342+ : { ok : false , error : result . error } ;
343+ } ,
344+ ) ;
345+ }
346+
347+ it ( "keeps remote source progress out of JSON output" , async ( ) => {
348+ mockMarketplaceListResult ( { ok : true } ) ;
349+ const { runPluginMarketplaceListCommand } = await import ( "./plugins-cli.runtime.js" ) ;
350+
351+ await runPluginMarketplaceListCommand ( source , { json : true } ) ;
352+
353+ expect ( mocks . listMarketplacePlugins ) . toHaveBeenCalledOnce ( ) ;
354+ expect ( mocks . defaultRuntime . log ) . not . toHaveBeenCalled ( ) ;
355+ expect ( mocks . defaultRuntime . error ) . not . toHaveBeenCalled ( ) ;
356+ expect ( mocks . defaultRuntime . writeJson ) . toHaveBeenCalledExactlyOnceWith ( {
357+ source,
358+ name : manifest . name ,
359+ version : manifest . version ,
360+ plugins : manifest . plugins ,
361+ } ) ;
362+ } ) ;
363+
364+ it ( "preserves remote source progress and marketplace entries in human output" , async ( ) => {
365+ mockMarketplaceListResult ( { ok : true } ) ;
366+ const { runPluginMarketplaceListCommand } = await import ( "./plugins-cli.runtime.js" ) ;
367+
368+ await runPluginMarketplaceListCommand ( source , { } ) ;
369+
370+ const output = mocks . defaultRuntime . log . mock . calls . map ( ( [ line ] ) => String ( line ) ) ;
371+ expect ( output [ 0 ] ) . toBe ( `Cloning marketplace source ${ source } ...` ) ;
372+ expect ( output . join ( "\n" ) ) . toContain ( "demo" ) ;
373+ expect ( mocks . defaultRuntime . writeJson ) . not . toHaveBeenCalled ( ) ;
374+ expect ( mocks . defaultRuntime . error ) . not . toHaveBeenCalled ( ) ;
375+ } ) ;
376+
377+ it ( "preserves remote source failure diagnostics without polluting JSON stdout" , async ( ) => {
378+ mockMarketplaceListResult ( { ok : false , error : "mock git remote unavailable" } ) ;
379+ const { runPluginMarketplaceListCommand } = await import ( "./plugins-cli.runtime.js" ) ;
380+
381+ await expect ( runPluginMarketplaceListCommand ( source , { json : true } ) ) . rejects . toThrow ( "exit 1" ) ;
382+
383+ expect ( mocks . defaultRuntime . log ) . not . toHaveBeenCalled ( ) ;
384+ expect ( mocks . defaultRuntime . error ) . toHaveBeenCalledExactlyOnceWith (
385+ "mock git remote unavailable" ,
386+ ) ;
387+ expect ( mocks . defaultRuntime . exit ) . toHaveBeenCalledExactlyOnceWith ( 1 ) ;
388+ expect ( mocks . defaultRuntime . writeJson ) . not . toHaveBeenCalled ( ) ;
389+ } ) ;
390+ } ) ;
0 commit comments