11import { describe , it , expect , vi } from 'vitest'
22import { renderContent } from '@/content-render/index'
33
4+ const { mockWarn } = vi . hoisted ( ( ) => ( { mockWarn : vi . fn ( ) } ) )
5+ vi . mock ( '@/observability/logger' , ( ) => ( {
6+ createLogger : ( ) => ( {
7+ info : vi . fn ( ) ,
8+ warn : mockWarn ,
9+ error : vi . fn ( ) ,
10+ debug : vi . fn ( ) ,
11+ } ) ,
12+ } ) )
13+
414describe ( 'code-header plugin' , ( ) => {
515 describe ( 'copilot language code blocks' , ( ) => {
616 it ( 'should render basic copilot code block without header (no copy meta)' , async ( ) => {
@@ -126,18 +136,17 @@ Improve the variable names in this function
126136
127137 describe ( 'edge cases' , ( ) => {
128138 it ( 'should handle missing reference gracefully and fall back to current code only' , async ( ) => {
129- // Mock console.warn to capture warning
130- const consoleWarnSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
139+ mockWarn . mockClear ( )
131140
132141 const markdown =
133142 '```copilot copy prompt ref=nonexistent-id\nImprove the variable names in this function\n```'
134143
135144 const html = await renderContent ( markdown )
136145
137- // Should warn about missing reference
138- expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
139- expect . stringContaining ( "Can't find referenced code block with id= nonexistent-id" ) ,
140- )
146+ // Should warn about missing reference via structured logger
147+ expect ( mockWarn ) . toHaveBeenCalledWith ( 'Cannot find referenced code block' , {
148+ ref : ' nonexistent-id' ,
149+ } )
141150
142151 // Should still render with prompt button using current code only
143152 expect ( html ) . toContain ( 'https://github.com/copilot?prompt=' )
@@ -149,8 +158,7 @@ Improve the variable names in this function
149158 // Should not crash or fail
150159 expect ( html ) . toContain ( 'code-example' )
151160
152- // Restore console.warn
153- consoleWarnSpy . mockRestore ( )
161+ mockWarn . mockClear ( )
154162 } )
155163
156164 it ( 'should not process annotated code blocks' , async ( ) => {
0 commit comments