11// Verifies current plugin registry contribution snapshots.
2- import { afterEach , describe , expect , it } from "vitest" ;
2+ import fs from "node:fs" ;
3+ import { afterEach , describe , expect , it , vi } from "vitest" ;
34import type { OpenClawConfig } from "../config/types.openclaw.js" ;
45import { setCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-snapshot.js" ;
56import { clearCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-state.js" ;
@@ -8,6 +9,7 @@ import type { InstalledPluginIndex } from "./installed-plugin-index.js";
89import type { PluginManifestRecord } from "./manifest-registry.js" ;
910import type { PluginMetadataSnapshot } from "./plugin-metadata-snapshot.types.js" ;
1011import { loadPluginManifestRegistryForPluginRegistry } from "./plugin-registry-contributions.js" ;
12+ import { loadPluginRegistrySnapshotWithMetadata } from "./plugin-registry-snapshot.js" ;
1113
1214afterEach ( ( ) => {
1315 clearCurrentPluginMetadataSnapshot ( ) ;
@@ -141,7 +143,7 @@ describe("loadPluginManifestRegistryForPluginRegistry current snapshot", () => {
141143 expect ( loadPluginManifestRegistryForPluginRegistry ( { config, env } ) . plugins ) . toEqual ( [ ] ) ;
142144 } ) ;
143145
144- it ( "does not reuse current metadata for explicit registry inputs or diagnostics" , ( ) => {
146+ it ( "keeps explicit registry inputs authoritative and reuses current diagnostics" , ( ) => {
145147 const config : OpenClawConfig = { } ;
146148 const env = {
147149 HOME : "/tmp/openclaw-test-home" ,
@@ -190,11 +192,26 @@ describe("loadPluginManifestRegistryForPluginRegistry current snapshot", () => {
190192 } ) ,
191193 { config, env, workspaceDir } ,
192194 ) ;
195+ const readDirectory = vi . spyOn ( fs , "readdirSync" ) ;
196+ const readFile = vi . spyOn ( fs , "readFileSync" ) ;
197+ const statFile = vi . spyOn ( fs , "statSync" ) ;
193198
194199 expect (
195200 loadPluginManifestRegistryForPluginRegistry ( { config, env, workspaceDir } ) . plugins . map (
196201 ( plugin ) => plugin . id ,
197202 ) ,
198- ) . toEqual ( [ ] ) ;
203+ ) . toEqual ( [ "enabled" ] ) ;
204+ expect (
205+ loadPluginRegistrySnapshotWithMetadata ( { config, env, workspaceDir } ) . diagnostics ,
206+ ) . toEqual ( [
207+ {
208+ level : "info" ,
209+ code : "persisted-registry-missing" ,
210+ message : "missing" ,
211+ } ,
212+ ] ) ;
213+ expect ( readDirectory ) . not . toHaveBeenCalled ( ) ;
214+ expect ( readFile ) . not . toHaveBeenCalled ( ) ;
215+ expect ( statFile ) . not . toHaveBeenCalled ( ) ;
199216 } ) ;
200217} ) ;
0 commit comments