@@ -3,7 +3,7 @@ import os from "node:os";
33import path from "node:path" ;
44import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
55import type { InstalledPluginIndex } from "./installed-plugin-index.js" ;
6- import type { PluginManifestRecord , PluginManifestRegistry } from "./manifest-registry.js" ;
6+ import type { PluginManifestRegistry } from "./manifest-registry.js" ;
77import {
88 clearLoadPluginMetadataSnapshotMemo ,
99 loadPluginMetadataSnapshot ,
@@ -75,41 +75,24 @@ function makeIndex(pluginId = "demo"): InstalledPluginIndex {
7575}
7676
7777function makeManifestRegistry ( pluginId = "demo" ) : PluginManifestRegistry {
78- const plugin : PluginManifestRecord = {
79- id : pluginId ,
80- name : pluginId ,
81- channels : [ ] ,
82- providers : [ pluginId ] ,
83- cliBackends : [ ] ,
84- skills : [ ] ,
85- hooks : [ ] ,
86- commandAliases : [ { name : `${ pluginId } -command` } ] ,
87- rootDir : `/plugins/${ pluginId } ` ,
88- source : `/plugins/${ pluginId } /index.js` ,
89- manifestPath : `/plugins/${ pluginId } /openclaw.plugin.json` ,
90- origin : "global" ,
78+ return {
79+ plugins : [
80+ {
81+ id : pluginId ,
82+ name : pluginId ,
83+ channels : [ ] ,
84+ providers : [ pluginId ] ,
85+ cliBackends : [ ] ,
86+ skills : [ ] ,
87+ hooks : [ ] ,
88+ rootDir : `/plugins/${ pluginId } ` ,
89+ source : `/plugins/${ pluginId } /index.js` ,
90+ manifestPath : `/plugins/${ pluginId } /openclaw.plugin.json` ,
91+ origin : "global" ,
92+ } ,
93+ ] ,
94+ diagnostics : [ ] ,
9195 } ;
92- return { plugins : [ plugin ] , diagnostics : [ ] } ;
93- }
94-
95- function requireFirstPlugin (
96- snapshot : ReturnType < typeof loadPluginMetadataSnapshot > ,
97- ) : PluginManifestRecord {
98- const plugin = snapshot . plugins [ 0 ] ;
99- if ( ! plugin ) {
100- throw new Error ( "expected metadata snapshot to include a plugin" ) ;
101- }
102- return plugin ;
103- }
104-
105- function requireFirstCommandAlias (
106- plugin : PluginManifestRecord ,
107- ) : NonNullable < PluginManifestRecord [ "commandAliases" ] > [ number ] {
108- const commandAlias = plugin . commandAliases ?. [ 0 ] ;
109- if ( ! commandAlias ) {
110- throw new Error ( "expected metadata snapshot plugin to include a command alias" ) ;
111- }
112- return commandAlias ;
11396}
11497
11598describe ( "loadPluginMetadataSnapshot process memo" , ( ) => {
@@ -137,19 +120,16 @@ describe("loadPluginMetadataSnapshot process memo", () => {
137120 } ) ;
138121
139122 const first = loadPluginMetadataSnapshot ( { config : { } , env : { } , stateDir } ) ;
140- const firstPlugin = requireFirstPlugin ( first ) ;
141- firstPlugin . providers . push ( "first-mutated" ) ;
142- requireFirstCommandAlias ( firstPlugin ) . name = "first-command-mutated" ;
123+ expect ( first . plugins [ 0 ] ) . toBeDefined ( ) ;
124+ first . plugins [ 0 ] ?. providers . push ( "first-mutated" ) ;
143125 const second = loadPluginMetadataSnapshot ( { config : { } , env : { } , stateDir } ) ;
144- const secondPlugin = requireFirstPlugin ( second ) ;
145- secondPlugin . providers . push ( "second-mutated" ) ;
146- requireFirstCommandAlias ( secondPlugin ) . name = "second-command-mutated" ;
126+ expect ( second . plugins [ 0 ] ) . toBeDefined ( ) ;
127+ second . plugins [ 0 ] ?. providers . push ( "second-mutated" ) ;
147128 const third = loadPluginMetadataSnapshot ( { config : { } , env : { } , stateDir } ) ;
148129
149130 expect ( loadPluginRegistrySnapshotWithMetadata ) . toHaveBeenCalledOnce ( ) ;
150131 expect ( loadPluginManifestRegistryForInstalledIndex ) . toHaveBeenCalledOnce ( ) ;
151132 expect ( third . plugins [ 0 ] ?. providers ) . toEqual ( [ "demo" ] ) ;
152- expect ( third . plugins [ 0 ] ?. commandAliases ?. [ 0 ] ?. name ) . toBe ( "demo-command" ) ;
153133 expect ( second . manifestRegistry . plugins [ 0 ] ) . toBe ( second . plugins [ 0 ] ) ;
154134 expect ( second . byPluginId . get ( "demo" ) ) . toBe ( second . plugins [ 0 ] ) ;
155135 } ) ;
0 commit comments