@@ -409,4 +409,74 @@ describe('markdown-url-support', () => {
409409 expect ( cached ?. markdown ?. content ) . toBe ( mdContent ) ;
410410 expect ( cached ?. markdown ?. source ) . toBe ( 'md-url' ) ;
411411 } ) ;
412+
413+ it ( 'auto-detects page/index.md preference and tries it first in later batches' , async ( ) => {
414+ // 3 pages, all served at page/index.md (not page.md). With concurrency=1,
415+ // each page is a separate batch, so after page 1+2 the check should
416+ // detect the page/index.md pattern and try it first for page 3.
417+ const md = '# Page\n\nContent here.' ;
418+ const requestLog : string [ ] = [ ] ;
419+
420+ server . use (
421+ // page.md forms — all 404
422+ http . get ( 'http://test.local/docs/a.md' , ( ) => {
423+ requestLog . push ( '/docs/a.md' ) ;
424+ return new HttpResponse ( 'Not found' , { status : 404 } ) ;
425+ } ) ,
426+ http . get ( 'http://test.local/docs/b.md' , ( ) => {
427+ requestLog . push ( '/docs/b.md' ) ;
428+ return new HttpResponse ( 'Not found' , { status : 404 } ) ;
429+ } ) ,
430+ http . get ( 'http://test.local/docs/c.md' , ( ) => {
431+ requestLog . push ( '/docs/c.md' ) ;
432+ return new HttpResponse ( 'Not found' , { status : 404 } ) ;
433+ } ) ,
434+ // index.md forms — all succeed
435+ http . get ( 'http://test.local/docs/a/index.md' , ( ) => {
436+ requestLog . push ( '/docs/a/index.md' ) ;
437+ return new HttpResponse ( md , {
438+ status : 200 ,
439+ headers : { 'Content-Type' : 'text/markdown' } ,
440+ } ) ;
441+ } ) ,
442+ http . get ( 'http://test.local/docs/b/index.md' , ( ) => {
443+ requestLog . push ( '/docs/b/index.md' ) ;
444+ return new HttpResponse ( md , {
445+ status : 200 ,
446+ headers : { 'Content-Type' : 'text/markdown' } ,
447+ } ) ;
448+ } ) ,
449+ http . get ( 'http://test.local/docs/c/index.md' , ( ) => {
450+ requestLog . push ( '/docs/c/index.md' ) ;
451+ return new HttpResponse ( md , {
452+ status : 200 ,
453+ headers : { 'Content-Type' : 'text/markdown' } ,
454+ } ) ;
455+ } ) ,
456+ ) ;
457+
458+ const content = `# Docs
459+ > Summary
460+ ## Links
461+ - [A](http://test.local/docs/a): A
462+ - [B](http://test.local/docs/b): B
463+ - [C](http://test.local/docs/c): C
464+ ` ;
465+ const ctx = makeCtx ( { content } ) ;
466+ // Force concurrency=1 so each page is its own batch
467+ ctx . options . maxConcurrency = 1 ;
468+ const result = await check . run ( ctx ) ;
469+
470+ expect ( result . status ) . toBe ( 'pass' ) ;
471+
472+ // Pages A and B: tried page.md first (default order), got 404, then page/index.md
473+ // Page C: after detecting page/index.md preference, should try page/index.md first
474+ // So /docs/c.md should NOT appear in the request log
475+ expect ( requestLog ) . toContain ( '/docs/a.md' ) ;
476+ expect ( requestLog ) . toContain ( '/docs/a/index.md' ) ;
477+ expect ( requestLog ) . toContain ( '/docs/b.md' ) ;
478+ expect ( requestLog ) . toContain ( '/docs/b/index.md' ) ;
479+ expect ( requestLog ) . not . toContain ( '/docs/c.md' ) ;
480+ expect ( requestLog ) . toContain ( '/docs/c/index.md' ) ;
481+ } ) ;
412482} ) ;
0 commit comments