1- import { describe , expect , test } from 'vitest'
1+ import { afterAll , beforeAll , describe , expect , test , vi } from 'vitest'
22import { convertContentToDocs } from '../scripts/convert-markdown-for-docs'
33import config from '@/codeql-cli/lib/config.json'
44
55const RELATIVE_LINK_PATH = config . targetDirectory . replace ( 'content' , '' )
66
77describe ( 'convertContentToDocs circular link handling' , ( ) => {
8+ const fetchMock = vi . spyOn ( globalThis , 'fetch' )
9+
10+ beforeAll ( ( ) => {
11+ fetchMock . mockResolvedValue (
12+ new Response ( null , {
13+ status : 302 ,
14+ headers : {
15+ location :
16+ 'https://docs.github.com/enterprise-server@latest/code-security/reference/code-scanning/sarif-files/sarif-support' ,
17+ } ,
18+ } ) ,
19+ )
20+ } )
21+
22+ afterAll ( ( ) => {
23+ vi . restoreAllMocks ( )
24+ } )
25+
826 const testContent = `
927# bqrs interpret
1028
@@ -21,7 +39,8 @@ metadata and generates output in the specified format.
2139
2240This option has no effect when passed to \`codeql bqrs interpret<bqrs-interpret>\`{.interpreted-text role="doc"}.
2341
24- For more information, see \`codeql database analyze<database-analyze>\`{.interpreted-text role="doc"}.
42+ For more information, see \`codeql database analyze<database-analyze>\`{.interpreted-text role="doc"} and
43+ <https://aka.ms/code-scanning-docs/sarif-support> for details about uploading SARIF files.
2544`
2645
2746 test ( 'converts circular links to plain text' , async ( ) => {
@@ -45,6 +64,37 @@ For more information, see \`codeql database analyze<database-analyze>\`{.interpr
4564 )
4665 } )
4766
67+ test ( 'converts aka.ms links' , async ( ) => {
68+ const result = await convertContentToDocs ( testContent , { } , 'bqrs-interpret.md' )
69+
70+ // Should convert aka.ms link to redirect
71+ expect ( result . content ) . toContain (
72+ '[AUTOTITLE](/enterprise-server@latest/code-security/reference/code-scanning/sarif-files/sarif-support)' ,
73+ )
74+
75+ // Should not still contain aka.ms link
76+ expect ( result . content ) . not . toContain ( 'https://aka.ms/' )
77+ } )
78+
79+ test ( 'strips language prefix from aka.ms redirect links' , async ( ) => {
80+ fetchMock . mockResolvedValue (
81+ new Response ( null , {
82+ status : 302 ,
83+ headers : {
84+ location :
85+ 'https://docs.github.com/en/enterprise-server@latest/code-security/reference/code-scanning/sarif-files/sarif-support' ,
86+ } ,
87+ } ) ,
88+ )
89+
90+ const result = await convertContentToDocs ( testContent , { } , 'bqrs-interpret.md' )
91+
92+ // Should strip language prefix from aka.ms redirect link
93+ expect ( result . content ) . toContain (
94+ '[AUTOTITLE](/enterprise-server@latest/code-security/reference/code-scanning/sarif-files/sarif-support)' ,
95+ )
96+ } )
97+
4898 test ( 'handles edge case: no filename provided' , async ( ) => {
4999 const result = await convertContentToDocs ( testContent , { } , '' )
50100
0 commit comments