@@ -3,8 +3,13 @@ import { render } from 'ink-testing-library';
33
44import { test } from '../utils' ;
55
6+ const resetSystemMessage = vi . hoisted ( ( ) => vi . fn ( ) ) ;
7+
68vi . mock ( '../utils' , async ( ) => ( {
79 ...( await vi . importActual ( '../utils' ) ) ,
10+ agents : {
11+ resetSystemMessage,
12+ } ,
813 config : {
914 loadConfig : vi . fn ( ( ) => ( {
1015 host : 'http://localhost:11434' ,
@@ -32,15 +37,17 @@ vi.mock('./Chat', () => ({
3237 Chat : ( {
3338 onCommand,
3439 onModeChange,
40+ sessionId,
3541 } : {
3642 model : string ;
3743 onCommand : ( command : string ) => void ;
3844 mode : string ;
3945 onModeChange : ( mode : string ) => void ;
46+ sessionId : number ;
4047 } ) => {
4148 capturedCallbacks . onCommand = onCommand ;
4249 capturedCallbacks . onModeChange = onModeChange ;
43- return < Text > { '>' } </ Text > ;
50+ return < Text > { `> session: ${ String ( sessionId ) } ` } </ Text > ;
4451 } ,
4552} ) ) ;
4653
@@ -82,6 +89,7 @@ describe('App', () => {
8289 capturedCallbacks . onSelect = null ;
8390 capturedCallbacks . onClose = null ;
8491 capturedCallbacks . onToggleMode = null ;
92+ resetSystemMessage . mockClear ( ) ;
8593 } ) ;
8694
8795 it ( 'renders title' , ( ) => {
@@ -134,6 +142,20 @@ describe('App', () => {
134142 expect ( lastFrame ( ) ) . not . toContain ( 'ModelPicker' ) ;
135143 } ) ;
136144
145+ it ( 'resets the chat session when /clear is issued' , async ( ) => {
146+ const { lastFrame, rerender } = render ( < App /> ) ;
147+
148+ expect ( lastFrame ( ) ) . toContain ( 'session:0' ) ;
149+
150+ capturedCallbacks . onCommand ?.( '/clear' ) ;
151+ rerender ( < App /> ) ;
152+ await test . tick ( ) ;
153+
154+ expect ( resetSystemMessage ) . toHaveBeenCalledOnce ( ) ;
155+ expect ( lastFrame ( ) ) . toContain ( 'session:1' ) ;
156+ expect ( lastFrame ( ) ) . not . toContain ( 'ModelPicker' ) ;
157+ } ) ;
158+
137159 it ( 'toggles mode via Footer onToggleMode callback (3-state cycle)' , async ( ) => {
138160 const { lastFrame, rerender } = render ( < App /> ) ;
139161
0 commit comments