mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-02 01:11:24 -07:00
fix(cli): gracefully handle --resume when no sessions exist (#21429)
This commit is contained in:
@@ -341,6 +341,29 @@ describe('SessionSelector', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw SessionError with NO_SESSIONS_FOUND when resolving latest with no sessions', async () => {
|
||||
// Empty chats directory — no session files
|
||||
const chatsDir = path.join(tmpDir, 'chats');
|
||||
await fs.mkdir(chatsDir, { recursive: true });
|
||||
|
||||
const emptyConfig = {
|
||||
storage: {
|
||||
getProjectTempDir: () => tmpDir,
|
||||
},
|
||||
getSessionId: () => 'current-session-id',
|
||||
} as Partial<Config> as Config;
|
||||
|
||||
const sessionSelector = new SessionSelector(emptyConfig);
|
||||
|
||||
await expect(sessionSelector.resolveSession('latest')).rejects.toSatisfy(
|
||||
(error) => {
|
||||
expect(error).toBeInstanceOf(SessionError);
|
||||
expect((error as SessionError).code).toBe('NO_SESSIONS_FOUND');
|
||||
return true;
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('should not list sessions with only system messages', async () => {
|
||||
const sessionIdWithUser = randomUUID();
|
||||
const sessionIdSystemOnly = randomUUID();
|
||||
|
||||
@@ -463,7 +463,7 @@ export class SessionSelector {
|
||||
const sessions = await this.listSessions();
|
||||
|
||||
if (sessions.length === 0) {
|
||||
throw new Error('No previous sessions found for this project.');
|
||||
throw SessionError.noSessionsFound();
|
||||
}
|
||||
|
||||
// Sort by startTime (oldest first, so newest sessions get highest numbers)
|
||||
|
||||
Reference in New Issue
Block a user