@@ -6,7 +6,10 @@ import {
66 writePersistedInstalledPluginIndex ,
77} from "./installed-plugin-index-store.js" ;
88import type { InstalledPluginIndex } from "./installed-plugin-index.js" ;
9- import { loadPluginManifestRegistryForInstalledIndex } from "./manifest-registry-installed.js" ;
9+ import {
10+ loadPluginManifestRegistryForInstalledIndex ,
11+ resolveInstalledManifestRegistryIndexFingerprint ,
12+ } from "./manifest-registry-installed.js" ;
1013import { cleanupTrackedTempDirs , makeTrackedTempDir } from "./test-helpers/fs-fixtures.js" ;
1114
1215const tempDirs : string [ ] = [ ] ;
@@ -70,7 +73,106 @@ function createIndex(rootDir: string): InstalledPluginIndex {
7073 } ;
7174}
7275
76+ function fileSignature ( filePath : string ) {
77+ const stat = fs . statSync ( filePath ) ;
78+ return {
79+ size : stat . size ,
80+ mtimeMs : stat . mtimeMs ,
81+ ctimeMs : stat . ctimeMs ,
82+ } ;
83+ }
84+
85+ function createIndexWithFileSignatures ( rootDir : string ) : InstalledPluginIndex {
86+ const index = createIndex ( rootDir ) ;
87+ return {
88+ ...index ,
89+ plugins : index . plugins . map ( ( record ) => ( {
90+ ...record ,
91+ manifestFile : fileSignature ( record . manifestPath ) ,
92+ } ) ) ,
93+ } ;
94+ }
95+
96+ function deepFreeze < T > ( value : T , seen = new WeakSet < object > ( ) ) : T {
97+ if ( ! value || typeof value !== "object" ) {
98+ return value ;
99+ }
100+ const object = value as object ;
101+ if ( seen . has ( object ) ) {
102+ return value ;
103+ }
104+ seen . add ( object ) ;
105+ for ( const child of Object . values ( value ) ) {
106+ deepFreeze ( child , seen ) ;
107+ }
108+ return Object . freeze ( value ) ;
109+ }
110+
73111describe ( "loadPluginManifestRegistryForInstalledIndex" , ( ) => {
112+ it ( "reuses frozen installed-index fingerprints when file signatures are persisted" , ( ) => {
113+ const rootDir = makeTempDir ( ) ;
114+ writePlugin ( rootDir , "installed" , "installed-" ) ;
115+ const index = deepFreeze ( createIndexWithFileSignatures ( rootDir ) ) ;
116+ const first = resolveInstalledManifestRegistryIndexFingerprint ( index ) ;
117+ const manifestPath = path . join ( rootDir , "openclaw.plugin.json" ) ;
118+ const nextMtime = new Date ( Date . now ( ) + 5000 ) ;
119+ fs . utimesSync ( manifestPath , nextMtime , nextMtime ) ;
120+ const second = resolveInstalledManifestRegistryIndexFingerprint ( index ) ;
121+
122+ expect ( second ) . toBe ( first ) ;
123+ } ) ;
124+
125+ it ( "recomputes installed-index fingerprints for mutable index objects" , ( ) => {
126+ const rootDir = makeTempDir ( ) ;
127+ writePlugin ( rootDir , "installed" , "installed-" ) ;
128+ const index = createIndexWithFileSignatures ( rootDir ) ;
129+ const first = resolveInstalledManifestRegistryIndexFingerprint ( index ) ;
130+ const record = index . plugins [ 0 ] ;
131+ if ( ! record ) {
132+ throw new Error ( "expected index record" ) ;
133+ }
134+ record . manifestHash = "changed" ;
135+ const second = resolveInstalledManifestRegistryIndexFingerprint ( index ) ;
136+
137+ expect ( second ) . not . toBe ( first ) ;
138+ } ) ;
139+
140+ it ( "does not cache shallow-frozen installed-index fingerprints with mutable nested records" , ( ) => {
141+ const rootDir = makeTempDir ( ) ;
142+ writePlugin ( rootDir , "installed" , "installed-" ) ;
143+ const index = createIndexWithFileSignatures ( rootDir ) ;
144+ const record = index . plugins [ 0 ] ;
145+ if ( ! record ) {
146+ throw new Error ( "expected index record" ) ;
147+ }
148+ Object . freeze ( index . installRecords ) ;
149+ Object . freeze ( index . diagnostics ) ;
150+ Object . freeze ( record ) ;
151+ Object . freeze ( index . plugins ) ;
152+ Object . freeze ( index ) ;
153+ const first = resolveInstalledManifestRegistryIndexFingerprint ( index ) ;
154+
155+ const agentHarnesses = record . startup . agentHarnesses as string [ ] ;
156+ agentHarnesses . push ( "changed" ) ;
157+ const second = resolveInstalledManifestRegistryIndexFingerprint ( index ) ;
158+
159+ expect ( second ) . not . toBe ( first ) ;
160+ } ) ;
161+
162+ it ( "does not cache frozen installed-index fingerprints that depend on live file state" , ( ) => {
163+ const rootDir = makeTempDir ( ) ;
164+ writePlugin ( rootDir , "installed" , "installed-" ) ;
165+ const index = deepFreeze ( createIndex ( rootDir ) ) ;
166+ const first = resolveInstalledManifestRegistryIndexFingerprint ( index ) ;
167+
168+ const manifestPath = path . join ( rootDir , "openclaw.plugin.json" ) ;
169+ const nextMtime = new Date ( Date . now ( ) + 5000 ) ;
170+ fs . utimesSync ( manifestPath , nextMtime , nextMtime ) ;
171+ const second = resolveInstalledManifestRegistryIndexFingerprint ( index ) ;
172+
173+ expect ( second ) . not . toBe ( first ) ;
174+ } ) ;
175+
74176 it ( "reconstructs installed-index manifest registries when manifest files change" , ( ) => {
75177 const rootDir = makeTempDir ( ) ;
76178 const manifestPath = path . join ( rootDir , "openclaw.plugin.json" ) ;
0 commit comments