@@ -14,6 +14,11 @@ describe("auto-update-checker", () => {
1414 let checkForUpdates : typeof import ( "../lib/auto-update-checker.js" ) . checkForUpdates ;
1515 let checkAndNotify : typeof import ( "../lib/auto-update-checker.js" ) . checkAndNotify ;
1616 let clearUpdateCache : typeof import ( "../lib/auto-update-checker.js" ) . clearUpdateCache ;
17+ let logger : {
18+ debug : ReturnType < typeof vi . fn > ;
19+ info : ReturnType < typeof vi . fn > ;
20+ warn : ReturnType < typeof vi . fn > ;
21+ } ;
1722
1823 const mockPackageJson = { version : "4.12.0" } ;
1924
@@ -22,6 +27,14 @@ describe("auto-update-checker", () => {
2227 vi . useFakeTimers ( ) ;
2328 vi . setSystemTime ( new Date ( "2026-01-30T12:00:00Z" ) ) ;
2429 mockPackageJson . version = "4.12.0" ;
30+ logger = {
31+ debug : vi . fn ( ) ,
32+ info : vi . fn ( ) ,
33+ warn : vi . fn ( ) ,
34+ } ;
35+ vi . doMock ( "../lib/logger.js" , ( ) => ( {
36+ createLogger : ( ) => logger ,
37+ } ) ) ;
2538
2639 fs = await import ( "node:fs" ) ;
2740 vi . mocked ( fs . readFileSync ) . mockImplementation ( ( path : unknown ) => {
@@ -228,6 +241,27 @@ describe("auto-update-checker", () => {
228241 } ) ;
229242
230243 describe ( "checkForUpdates" , ( ) => {
244+ it ( "logs debug details when package metadata cannot be parsed" , async ( ) => {
245+ vi . mocked ( fs . readFileSync ) . mockImplementation ( ( path : unknown ) => {
246+ if ( String ( path ) . includes ( "package.json" ) ) {
247+ return "{" ;
248+ }
249+ throw new Error ( "File not found" ) ;
250+ } ) ;
251+ vi . mocked ( globalThis . fetch ) . mockResolvedValue ( {
252+ ok : true ,
253+ json : async ( ) => ( { version : "5.0.0" } ) ,
254+ } as Response ) ;
255+
256+ const result = await checkForUpdates ( true ) ;
257+
258+ expect ( result . currentVersion ) . toBe ( "0.0.0" ) ;
259+ expect ( logger . debug ) . toHaveBeenCalledWith (
260+ "Failed to read current package version" ,
261+ expect . objectContaining ( { error : expect . any ( String ) } ) ,
262+ ) ;
263+ } ) ;
264+
231265 it ( "uses cache when check is recent" , async ( ) => {
232266 const cacheData = {
233267 lastCheck : Date . now ( ) - 1000 * 60 * 60 ,
@@ -252,6 +286,31 @@ describe("auto-update-checker", () => {
252286 expect ( result . latestVersion ) . toBe ( "5.0.0" ) ;
253287 } ) ;
254288
289+ it ( "logs debug details when cached update JSON is unreadable" , async ( ) => {
290+ vi . mocked ( fs . existsSync ) . mockReturnValue ( true ) ;
291+ vi . mocked ( fs . readFileSync ) . mockImplementation ( ( path : unknown ) => {
292+ if ( String ( path ) . includes ( "package.json" ) ) {
293+ return JSON . stringify ( mockPackageJson ) ;
294+ }
295+ if ( String ( path ) . includes ( "update-check-cache.json" ) ) {
296+ return "{" ;
297+ }
298+ throw new Error ( "File not found" ) ;
299+ } ) ;
300+ vi . mocked ( globalThis . fetch ) . mockResolvedValue ( {
301+ ok : true ,
302+ json : async ( ) => ( { version : "5.0.0" } ) ,
303+ } as Response ) ;
304+
305+ await checkForUpdates ( ) ;
306+
307+ expect ( logger . debug ) . toHaveBeenCalledWith (
308+ "Failed to load update cache" ,
309+ expect . objectContaining ( { error : expect . any ( String ) } ) ,
310+ ) ;
311+ expect ( globalThis . fetch ) . toHaveBeenCalled ( ) ;
312+ } ) ;
313+
255314 it ( "handles cached null latestVersion without update" , async ( ) => {
256315 const cacheData = {
257316 lastCheck : Date . now ( ) - 1000 * 60 * 60 ,
0 commit comments