@@ -390,5 +390,94 @@ describe('KnowledgeGraphManager', () => {
390390 expect ( JSON . parse ( lines [ 0 ] ) ) . toHaveProperty ( 'type' , 'entity' ) ;
391391 expect ( JSON . parse ( lines [ 1 ] ) ) . toHaveProperty ( 'type' , 'relation' ) ;
392392 } ) ;
393+
394+ it ( 'should strip type field from entities when loading from file' , async ( ) => {
395+ // Create entities and relations (these get saved with type field)
396+ await manager . createEntities ( [
397+ { name : 'Alice' , entityType : 'person' , observations : [ 'test observation' ] } ,
398+ { name : 'Bob' , entityType : 'person' , observations : [ ] } ,
399+ ] ) ;
400+ await manager . createRelations ( [
401+ { from : 'Alice' , to : 'Bob' , relationType : 'knows' } ,
402+ ] ) ;
403+
404+ // Verify file contains type field (order may vary)
405+ const fileContent = await fs . readFile ( testFilePath , 'utf-8' ) ;
406+ const fileLines = fileContent . split ( '\n' ) . filter ( line => line . trim ( ) ) ;
407+ const fileItems = fileLines . map ( line => JSON . parse ( line ) ) ;
408+ const fileEntity = fileItems . find ( item => item . type === 'entity' ) ;
409+ const fileRelation = fileItems . find ( item => item . type === 'relation' ) ;
410+ expect ( fileEntity ) . toBeDefined ( ) ;
411+ expect ( fileEntity ) . toHaveProperty ( 'type' , 'entity' ) ;
412+ expect ( fileRelation ) . toBeDefined ( ) ;
413+ expect ( fileRelation ) . toHaveProperty ( 'type' , 'relation' ) ;
414+
415+ // Create new manager instance to force reload from file
416+ const manager2 = new KnowledgeGraphManager ( testFilePath ) ;
417+ const graph = await manager2 . readGraph ( ) ;
418+
419+ // Verify loaded entities don't have type field
420+ expect ( graph . entities ) . toHaveLength ( 2 ) ;
421+ graph . entities . forEach ( entity => {
422+ expect ( entity ) . not . toHaveProperty ( 'type' ) ;
423+ expect ( entity ) . toHaveProperty ( 'name' ) ;
424+ expect ( entity ) . toHaveProperty ( 'entityType' ) ;
425+ expect ( entity ) . toHaveProperty ( 'observations' ) ;
426+ } ) ;
427+
428+ // Verify loaded relations don't have type field
429+ expect ( graph . relations ) . toHaveLength ( 1 ) ;
430+ graph . relations . forEach ( relation => {
431+ expect ( relation ) . not . toHaveProperty ( 'type' ) ;
432+ expect ( relation ) . toHaveProperty ( 'from' ) ;
433+ expect ( relation ) . toHaveProperty ( 'to' ) ;
434+ expect ( relation ) . toHaveProperty ( 'relationType' ) ;
435+ } ) ;
436+ } ) ;
437+
438+ it ( 'should strip type field from searchNodes results' , async ( ) => {
439+ await manager . createEntities ( [
440+ { name : 'Alice' , entityType : 'person' , observations : [ 'works at Acme' ] } ,
441+ ] ) ;
442+ await manager . createRelations ( [
443+ { from : 'Alice' , to : 'Alice' , relationType : 'self' } ,
444+ ] ) ;
445+
446+ // Create new manager instance to force reload from file
447+ const manager2 = new KnowledgeGraphManager ( testFilePath ) ;
448+ const result = await manager2 . searchNodes ( 'Alice' ) ;
449+
450+ // Verify search results don't have type field
451+ expect ( result . entities ) . toHaveLength ( 1 ) ;
452+ expect ( result . entities [ 0 ] ) . not . toHaveProperty ( 'type' ) ;
453+ expect ( result . entities [ 0 ] . name ) . toBe ( 'Alice' ) ;
454+
455+ expect ( result . relations ) . toHaveLength ( 1 ) ;
456+ expect ( result . relations [ 0 ] ) . not . toHaveProperty ( 'type' ) ;
457+ expect ( result . relations [ 0 ] . from ) . toBe ( 'Alice' ) ;
458+ } ) ;
459+
460+ it ( 'should strip type field from openNodes results' , async ( ) => {
461+ await manager . createEntities ( [
462+ { name : 'Alice' , entityType : 'person' , observations : [ ] } ,
463+ { name : 'Bob' , entityType : 'person' , observations : [ ] } ,
464+ ] ) ;
465+ await manager . createRelations ( [
466+ { from : 'Alice' , to : 'Bob' , relationType : 'knows' } ,
467+ ] ) ;
468+
469+ // Create new manager instance to force reload from file
470+ const manager2 = new KnowledgeGraphManager ( testFilePath ) ;
471+ const result = await manager2 . openNodes ( [ 'Alice' , 'Bob' ] ) ;
472+
473+ // Verify open results don't have type field
474+ expect ( result . entities ) . toHaveLength ( 2 ) ;
475+ result . entities . forEach ( entity => {
476+ expect ( entity ) . not . toHaveProperty ( 'type' ) ;
477+ } ) ;
478+
479+ expect ( result . relations ) . toHaveLength ( 1 ) ;
480+ expect ( result . relations [ 0 ] ) . not . toHaveProperty ( 'type' ) ;
481+ } ) ;
393482 } ) ;
394483} ) ;
0 commit comments