@@ -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 } ) ) ;
@@ -249,7 +251,7 @@ describe('cli', () => {
249251
250252 it ( 'loads the requested session and renders the TUI for resume' , async ( ) => {
251253 loadSession . mockReturnValueOnce ( {
252- metadata : { id : 'session-1' } ,
254+ metadata : { id : 'session-1' , directory : process . cwd ( ) } ,
253255 messages : [ ] ,
254256 } ) ;
255257
@@ -260,6 +262,37 @@ describe('cli', () => {
260262 expect ( renderApp ) . toHaveBeenCalledWith ( 'session-1' ) ;
261263 } ) ;
262264
265+ it ( 'allows resume when session has no directory field (legacy session)' , async ( ) => {
266+ loadSession . mockReturnValueOnce ( {
267+ metadata : { id : 'session-1' , directory : undefined } ,
268+ messages : [ ] ,
269+ } ) ;
270+
271+ await commandState . resumeAction ?.( 'session-1' ) ;
272+
273+ expect ( renderApp ) . toHaveBeenCalledWith ( 'session-1' ) ;
274+ expect ( writeError ) . not . toHaveBeenCalled ( ) ;
275+ } ) ;
276+
277+ it ( 'blocks TUI and errors when resuming a session from a different directory' , async ( ) => {
278+ loadSession . mockReturnValueOnce ( {
279+ metadata : { id : 'session-1' , directory : '/other/project' } ,
280+ messages : [ ] ,
281+ } ) ;
282+
283+ await commandState . resumeAction ?.( 'session-1' ) ;
284+
285+ expect ( color ) . toHaveBeenCalledWith (
286+ expect . stringContaining (
287+ 'Cannot resume: session belongs to /other/project' ,
288+ ) ,
289+ 'yellow' ,
290+ ) ;
291+ expect ( writeError ) . toHaveBeenCalledOnce ( ) ;
292+ expect ( process . exitCode ) . toBe ( 1 ) ;
293+ expect ( renderApp ) . not . toHaveBeenCalled ( ) ;
294+ } ) ;
295+
263296 it ( 'reports resume errors and sets exit code' , async ( ) => {
264297 loadSession . mockImplementationOnce ( ( ) => {
265298 throw new Error ( 'Session not found: missing' ) ;
0 commit comments