11// Channel plugin catalog tests cover plugin catalog entries and metadata normalization.
2- import { beforeEach , describe , expect , it , vi } from "vitest" ;
2+ import fs from "node:fs" ;
3+ import os from "node:os" ;
4+ import path from "node:path" ;
5+ import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
36import type { PluginChannelCatalogEntry } from "../../plugins/channel-catalog-registry.js" ;
7+ import { clearPluginMetadataLifecycleCaches } from "../../plugins/plugin-metadata-lifecycle.js" ;
48
59const listChannelCatalogEntriesMock = vi . hoisted ( ( ) =>
610 vi . fn < ( ) => PluginChannelCatalogEntry [ ] > ( ( ) => [ ] ) ,
@@ -12,10 +16,37 @@ vi.mock("../../plugins/channel-catalog-registry.js", () => ({
1216
1317import { getChannelPluginCatalogEntry } from "./catalog.js" ;
1418
19+ const tempDirs : string [ ] = [ ] ;
20+
1521beforeEach ( ( ) => {
1622 listChannelCatalogEntriesMock . mockReset ( ) . mockReturnValue ( [ ] ) ;
1723} ) ;
1824
25+ afterEach ( ( ) => {
26+ vi . restoreAllMocks ( ) ;
27+ for ( const tempDir of tempDirs . splice ( 0 ) ) {
28+ fs . rmSync ( tempDir , { recursive : true , force : true } ) ;
29+ }
30+ } ) ;
31+
32+ function writeChannelCatalog ( catalogPath : string , id : string , label : string ) : void {
33+ fs . mkdirSync ( path . dirname ( catalogPath ) , { recursive : true } ) ;
34+ fs . writeFileSync (
35+ catalogPath ,
36+ JSON . stringify ( {
37+ entries : [
38+ {
39+ name : `@example/${ id } ` ,
40+ openclaw : {
41+ channel : { id, label, selectionLabel : label , docsPath : `/channels/${ id } ` , blurb : id } ,
42+ install : { npmSpec : `@example/${ id } ` } ,
43+ } ,
44+ } ,
45+ ] ,
46+ } ) ,
47+ ) ;
48+ }
49+
1950describe ( "channel plugin catalog" , ( ) => {
2051 it ( "keeps third-party channel ids mapped with catalog install trust" , ( ) => {
2152 const options = {
@@ -74,4 +105,35 @@ describe("channel plugin catalog", () => {
74105 } ) ?. origin ,
75106 ) . toBe ( "bundled" ) ;
76107 } ) ;
108+ it ( "reloads external catalog entries after the explicit plugin metadata lifecycle reset" , ( ) => {
109+ const root = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-channel-external-catalog-" ) ) ;
110+ tempDirs . push ( root ) ;
111+ const catalogPath = path . join ( root , "catalog.json" ) ;
112+ const options = { catalogPaths : [ catalogPath ] , workspaceDir : root , env : { } } ;
113+
114+ expect ( getChannelPluginCatalogEntry ( "lifecycle-external" , options ) ) . toBeUndefined ( ) ;
115+ writeChannelCatalog ( catalogPath , "lifecycle-external" , "After external install" ) ;
116+ clearPluginMetadataLifecycleCaches ( ) ;
117+
118+ expect ( getChannelPluginCatalogEntry ( "lifecycle-external" , options ) ?. meta . label ) . toBe (
119+ "After external install" ,
120+ ) ;
121+ } ) ;
122+
123+ it ( "reloads official generated catalog entries after the explicit plugin metadata lifecycle reset" , ( ) => {
124+ const root = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-channel-official-catalog-" ) ) ;
125+ tempDirs . push ( root ) ;
126+ fs . writeFileSync ( path . join ( root , "package.json" ) , JSON . stringify ( { name : "openclaw" } ) ) ;
127+ vi . spyOn ( process , "cwd" ) . mockReturnValue ( root ) ;
128+ const catalogPath = path . join ( root , "dist" , "channel-catalog.json" ) ;
129+ const options = { catalogPaths : [ path . join ( root , "external.json" ) ] , env : { } } ;
130+
131+ expect ( getChannelPluginCatalogEntry ( "lifecycle-official" , options ) ) . toBeUndefined ( ) ;
132+ writeChannelCatalog ( catalogPath , "lifecycle-official" , "After official update" ) ;
133+ clearPluginMetadataLifecycleCaches ( ) ;
134+
135+ expect ( getChannelPluginCatalogEntry ( "lifecycle-official" , options ) ?. meta . label ) . toBe (
136+ "After official update" ,
137+ ) ;
138+ } ) ;
77139} ) ;
0 commit comments