@@ -69,6 +69,23 @@ async function writeSessionStore(
6969 await fs . writeFile ( storePath , JSON . stringify ( store , null , 2 ) ) ;
7070}
7171
72+ function readMainSessionEntry ( raw : string ) : SessionEntry {
73+ const parsed = JSON . parse ( raw ) as Record < string , SessionEntry > ;
74+ const entry = parsed [ "agent:main" ] ;
75+ if ( ! entry ) {
76+ throw new Error ( "expected agent:main session entry" ) ;
77+ }
78+ return entry ;
79+ }
80+
81+ function readMainSkillsSnapshot ( raw : string ) : NonNullable < SessionEntry [ "skillsSnapshot" ] > {
82+ const snapshot = readMainSessionEntry ( raw ) . skillsSnapshot ;
83+ if ( ! snapshot ) {
84+ throw new Error ( "expected agent:main skills snapshot" ) ;
85+ }
86+ return snapshot ;
87+ }
88+
7289describe ( "doctor session snapshot stale runtime metadata" , ( ) => {
7390 let root = "" ;
7491 let bundledSkillsDir = "" ;
@@ -175,7 +192,7 @@ describe("doctor session snapshot stale runtime metadata", () => {
175192 } ) ;
176193 expect ( sessionSnapshotIssueToHealthFinding ( issue ) ) . toMatchObject ( {
177194 checkId : "core/doctor/session-snapshots" ,
178- severity : "warning " ,
195+ severity : "info " ,
179196 path : storePath ,
180197 target : stalePath ,
181198 requirement : expect . stringContaining ( bundledSkillsDir ) ,
@@ -510,8 +527,9 @@ describe("doctor session snapshot repair (shouldRepair)", () => {
510527 } ) ;
511528
512529 const raw = await fs . readFile ( storePath , "utf-8" ) ;
513- expect ( raw ) . not . toContain ( stalePath ) ;
514- expect ( raw ) . toContain ( path . join ( bundledSkillsDir , "doctor" , "SKILL.md" ) ) ;
530+ const snapshot = readMainSkillsSnapshot ( raw ) ;
531+ expect ( snapshot . prompt ) . not . toContain ( stalePath ) ;
532+ expect ( snapshot . prompt ) . toContain ( path . join ( bundledSkillsDir , "doctor" , "SKILL.md" ) ) ;
515533 expect ( note ) . toHaveBeenCalledTimes ( 1 ) ;
516534 const [ message ] = note . mock . calls [ 0 ] as [ string , string ] ;
517535 expect ( message ) . toContain ( "Repaired" ) ;
@@ -589,9 +607,13 @@ describe("doctor session snapshot repair (shouldRepair)", () => {
589607
590608 const raw = await fs . readFile ( storePath , "utf-8" ) ;
591609 const expectedBaseDir = path . dirname ( path . join ( bundledSkillsDir , "doctor" , "SKILL.md" ) ) ;
592- expect ( raw ) . toContain ( path . join ( bundledSkillsDir , "doctor" , "SKILL.md" ) ) ;
593- expect ( raw ) . toContain ( expectedBaseDir ) ;
594- expect ( raw ) . not . toContain ( path . join ( root , "old-runtime" ) ) ;
610+ const expectedPath = path . join ( bundledSkillsDir , "doctor" , "SKILL.md" ) ;
611+ const snapshot = readMainSkillsSnapshot ( raw ) ;
612+ const skill = snapshot . resolvedSkills ?. [ 0 ] ;
613+ expect ( skill ?. filePath ) . toBe ( expectedPath ) ;
614+ expect ( skill ?. baseDir ) . toBe ( expectedBaseDir ) ;
615+ expect ( skill ?. sourceInfo . path ) . toBe ( expectedPath ) ;
616+ expect ( skill ?. sourceInfo . baseDir ) . toBe ( expectedBaseDir ) ;
595617 expect ( note ) . toHaveBeenCalledTimes ( 1 ) ;
596618 const [ message ] = note . mock . calls [ 0 ] as [ string , string ] ;
597619 expect ( message ) . toContain ( "Repaired" ) ;
@@ -630,9 +652,12 @@ describe("doctor session snapshot repair (shouldRepair)", () => {
630652 } ) ;
631653
632654 const raw = await fs . readFile ( storePath , "utf-8" ) ;
633- expect ( raw ) . toContain ( currentPath ) ;
634- expect ( raw ) . toContain ( path . dirname ( currentPath ) ) ;
635- expect ( raw ) . not . toContain ( path . join ( root , "old-runtime" ) ) ;
655+ const snapshot = readMainSkillsSnapshot ( raw ) ;
656+ const repairedSkill = snapshot . resolvedSkills ?. [ 0 ] ;
657+ expect ( repairedSkill ?. filePath ) . toBe ( currentPath ) ;
658+ expect ( repairedSkill ?. baseDir ) . toBe ( path . dirname ( currentPath ) ) ;
659+ expect ( repairedSkill ?. sourceInfo . path ) . toBe ( currentPath ) ;
660+ expect ( repairedSkill ?. sourceInfo . baseDir ) . toBe ( path . dirname ( currentPath ) ) ;
636661 expect ( note ) . toHaveBeenCalledTimes ( 1 ) ;
637662 const [ message ] = note . mock . calls [ 0 ] as [ string , string ] ;
638663 expect ( message ) . toContain ( "Repaired" ) ;
@@ -797,7 +822,8 @@ describe("doctor session snapshot repair (shouldRepair)", () => {
797822 expect ( backupFiles . length ) . toBe ( 1 ) ;
798823
799824 const backupContent = await fs . readFile ( path . join ( dir , backupFiles [ 0 ] ) , "utf-8" ) ;
800- expect ( backupContent ) . toContain ( stalePath ) ;
825+ const backupSnapshot = readMainSkillsSnapshot ( backupContent ) ;
826+ expect ( backupSnapshot . prompt ) . toContain ( stalePath ) ;
801827 } ) ;
802828
803829 it ( "is idempotent — second repair finds nothing" , async ( ) => {
0 commit comments