@@ -142,6 +142,52 @@ runner
142142
143143 await store . delete ( 'agent' ) ;
144144 expect . toEqual ( await store . exists ( 'agent' ) , false ) ;
145+ } )
146+
147+ . test ( 'exists() returns false when directory exists but meta.json is missing' , async ( ) => {
148+ const dir = createDir ( 'exists-no-meta' ) ;
149+ const store = new JSONStore ( dir ) ;
150+ // Create agent directory without meta.json
151+ fs . mkdirSync ( path . join ( dir , 'agent' ) , { recursive : true } ) ;
152+ expect . toEqual ( await store . exists ( 'agent' ) , false ) ;
153+ } )
154+
155+ . test ( 'exists() returns false when meta.json is corrupted JSON' , async ( ) => {
156+ const dir = createDir ( 'exists-corrupt' ) ;
157+ const store = new JSONStore ( dir ) ;
158+ const agentDir = path . join ( dir , 'agent' ) ;
159+ fs . mkdirSync ( agentDir , { recursive : true } ) ;
160+ fs . writeFileSync ( path . join ( agentDir , 'meta.json' ) , '{not valid json!!!' , 'utf-8' ) ;
161+ expect . toEqual ( await store . exists ( 'agent' ) , false ) ;
162+ } )
163+
164+ . test ( 'exists() returns false when meta.json lacks metadata field' , async ( ) => {
165+ const dir = createDir ( 'exists-no-metadata' ) ;
166+ const store = new JSONStore ( dir ) ;
167+ const agentDir = path . join ( dir , 'agent' ) ;
168+ fs . mkdirSync ( agentDir , { recursive : true } ) ;
169+ fs . writeFileSync (
170+ path . join ( agentDir , 'meta.json' ) ,
171+ JSON . stringify ( { agentId : 'agent' , templateId : 'tpl' } ) ,
172+ 'utf-8'
173+ ) ;
174+ expect . toEqual ( await store . exists ( 'agent' ) , false ) ;
175+ } )
176+
177+ . test ( 'exists() returns true when meta.json is complete' , async ( ) => {
178+ const dir = createDir ( 'exists-complete' ) ;
179+ const store = new JSONStore ( dir ) ;
180+ await store . saveInfo ( 'agent' , {
181+ agentId : 'agent' ,
182+ templateId : 'tpl' ,
183+ createdAt : new Date ( ) . toISOString ( ) ,
184+ lineage : [ ] ,
185+ configVersion : 'test' ,
186+ messageCount : 0 ,
187+ lastSfpIndex : 0 ,
188+ metadata : { templateId : 'tpl' } ,
189+ } ) ;
190+ expect . toEqual ( await store . exists ( 'agent' ) , true ) ;
145191 } ) ;
146192
147193export async function run ( ) {
0 commit comments