@@ -2,6 +2,7 @@ type RunAction = (model: string, prompt: string) => Promise<void>;
22type ResumeAction = ( sessionId : string ) => Promise < void > ;
33
44const {
5+ color,
56 createSystemMessage,
67 executeTool,
78 loadSession,
@@ -12,6 +13,7 @@ const {
1213 write,
1314 writeError,
1415} = vi . hoisted ( ( ) => ( {
16+ color : vi . fn ( ( text : string ) => text ) ,
1517 createSystemMessage : vi . fn ( ( ) => ( {
1618 role : 'system' ,
1719 content : 'system prompt' ,
@@ -38,7 +40,7 @@ vi.mock('./utils', () => ({
3840 ollama : { streamChat } ,
3941 screen : { reset : mockReset } ,
4042 session : { loadSession } ,
41- terminal : { write, writeError } ,
43+ terminal : { color , write, writeError } ,
4244 tools : { TOOLS : [ 'mock-tool' ] , executeTool } ,
4345} ) ) ;
4446vi . mock ( './tui' , ( ) => ( { renderApp } ) ) ;
@@ -260,6 +262,25 @@ describe('cli', () => {
260262 expect ( renderApp ) . toHaveBeenCalledWith ( 'session-1' ) ;
261263 } ) ;
262264
265+ it ( 'blocks TUI and errors when resuming a session from a different directory' , async ( ) => {
266+ loadSession . mockReturnValueOnce ( {
267+ metadata : { id : 'session-1' , directory : '/other/project' } ,
268+ messages : [ ] ,
269+ } ) ;
270+
271+ await commandState . resumeAction ?.( 'session-1' ) ;
272+
273+ expect ( color ) . toHaveBeenCalledWith (
274+ expect . stringContaining (
275+ 'Cannot resume: session belongs to /other/project' ,
276+ ) ,
277+ 'yellow' ,
278+ ) ;
279+ expect ( writeError ) . toHaveBeenCalledOnce ( ) ;
280+ expect ( process . exitCode ) . toBe ( 1 ) ;
281+ expect ( renderApp ) . not . toHaveBeenCalled ( ) ;
282+ } ) ;
283+
263284 it ( 'reports resume errors and sets exit code' , async ( ) => {
264285 loadSession . mockImplementationOnce ( ( ) => {
265286 throw new Error ( 'Session not found: missing' ) ;
0 commit comments