@@ -273,6 +273,42 @@ describe('CpuStates', () => {
273273 expect ( await cpuStates . getActiveTimeString ( ) ) . toEqual ( ' 0 states' ) ;
274274 } ) ;
275275
276+ it ( 'captures states for periodic refreshs but does not add to history' , async ( ) => {
277+ const debugConsoleOutput : string [ ] = [ ] ;
278+ ( vscode . debug . activeDebugConsole . appendLine as jest . Mock ) . mockImplementation ( line => debugConsoleOutput . push ( line ) ) ;
279+
280+ // Initial stopped event to capture initial states.
281+ ( debugSession . customRequest as jest . Mock ) . mockResolvedValueOnce ( {
282+ address : '0xE0001004' ,
283+ data : new Uint8Array ( [ 0x01 , 0x00 , 0x00 , 0x00 ] ) . buffer
284+ } ) ;
285+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
286+ ( tracker as any ) . _onStopped . fire ( createStoppedEvent ( gdbtargetDebugSession , 'step' , 0 ) ) ;
287+ await waitForMs ( 0 ) ;
288+
289+ // Capture initial history and clear console while keeping object unchanged for above callback.
290+ cpuStates . showStatesHistory ( ) ;
291+ const initialHistoryLength = debugConsoleOutput . length ;
292+
293+ // Refresh event to add states but not history entry.
294+ ( debugSession . customRequest as jest . Mock ) . mockResolvedValueOnce ( {
295+ address : '0xE0001004' ,
296+ data : new Uint8Array ( [ 0x04 , 0x00 , 0x00 , 0x00 ] ) . buffer
297+ } ) ;
298+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
299+ ( gdbtargetDebugSession . refreshTimer as any ) . _onRefresh . fire ( gdbtargetDebugSession ) ;
300+ await waitForMs ( 0 ) ;
301+
302+ // Diff is 4 - 1 = 3 states, but no new history entry.
303+ expect ( cpuStates . activeCpuStates ?. states ) . toEqual ( BigInt ( 3 ) ) ;
304+ expect ( await cpuStates . getActiveTimeString ( ) ) . toEqual ( ' 3 states' ) ;
305+ cpuStates . showStatesHistory ( ) ;
306+ // Expecting same output length, i.e. no additional lines due to added history entries.
307+ expect ( debugConsoleOutput . length ) . toEqual ( 2 * initialHistoryLength ) ;
308+ // Match snapshot to notice any unexpected changes.
309+ expect ( debugConsoleOutput ) . toMatchSnapshot ( ) ;
310+ } ) ;
311+
276312 it ( 'fires refresh events on active stack item change' , async ( ) => {
277313 const delays : number [ ] = [ ] ;
278314 const listener = ( delay : number ) => delays . push ( delay ) ;
0 commit comments