@@ -191,6 +191,7 @@ describe('[DocFetcher] When using markdown caching', () => {
191191 headers : {
192192 get : jest . fn ( ) . mockImplementation ( ( name ) => {
193193 if ( name === 'etag' ) return '"mock-etag"' ;
194+ if ( name === 'x-local-cache-status' ) return 'hit' ;
194195 return null ;
195196 } )
196197 } ,
@@ -239,6 +240,7 @@ describe('[DocFetcher] When using markdown caching', () => {
239240 headers : {
240241 get : jest . fn ( ) . mockImplementation ( ( name ) => {
241242 if ( name === 'etag' ) return '"mock-etag-2"' ;
243+ if ( name === 'x-local-cache-status' ) return 'miss' ;
242244 return null ;
243245 } )
244246 } ,
@@ -268,6 +270,54 @@ describe('[DocFetcher] When using markdown caching', () => {
268270 expect . stringContaining ( '# Test Page' )
269271 ) ;
270272 } ) ;
273+
274+ it ( 'should regenerate markdown when HTML cache is missed' , async ( ) => {
275+ // Setup mock response for HTML fetch with cache miss
276+ const mockResponse = {
277+ ok : true ,
278+ status : 200 ,
279+ statusText : 'OK' ,
280+ headers : {
281+ get : jest . fn ( ) . mockImplementation ( ( name ) => {
282+ if ( name === 'etag' ) return '"mock-etag-3"' ;
283+ if ( name === 'x-local-cache-status' ) return 'miss' ; // Explicitly set cache miss
284+ return null ;
285+ } )
286+ } ,
287+ text : jest . fn ( ) . mockResolvedValue ( '<html><body><div class="md-content" data-md-component="content"><h1>Updated Page</h1><p>Updated content</p></div></body></html>' )
288+ } ;
289+
290+ // Setup mock for cacache.get.info - even if markdown exists in cache, it should be regenerated on HTML cache miss
291+ mockCacacheGetInfo . mockResolvedValueOnce ( { integrity : 'sha512-test' } ) ;
292+ mockCacacheGet . mockResolvedValueOnce ( {
293+ data : Buffer . from ( '# Old Page\n\nOld content' , 'utf8' ) ,
294+ metadata : null ,
295+ integrity : 'sha512-test' ,
296+ size : 28
297+ } ) ;
298+
299+ // Configure the fetch mock
300+ mockFetch . mockResolvedValueOnce ( mockResponse ) ;
301+
302+ // Call the function
303+ const result = await fetchDocPage ( 'https://docs.powertools.aws.dev/lambda/python/latest/core/logger/' ) ;
304+
305+ // Verify the result contains the new markdown (not the cached version)
306+ expect ( result ) . toContain ( '# Updated Page' ) ;
307+ expect ( result ) . toContain ( 'Updated content' ) ;
308+ expect ( result ) . not . toContain ( 'Old Page' ) ;
309+ expect ( result ) . not . toContain ( 'Old content' ) ;
310+
311+ // Verify that the HTML was fetched
312+ expect ( mockFetch ) . toHaveBeenCalledTimes ( 1 ) ;
313+
314+ // Verify that cacache was used to save the new markdown
315+ expect ( cacache . put ) . toHaveBeenCalledWith (
316+ path . join ( cacheConfig . basePath , 'markdown-cache' ) ,
317+ 'python/latest/core/logger-mock-etag-3' ,
318+ expect . stringContaining ( '# Updated Page' )
319+ ) ;
320+ } ) ;
271321
272322 it ( 'should use content hash when ETag is not available' , async ( ) => {
273323 // Setup mock response for HTML fetch without ETag
0 commit comments