Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/cli/src/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { Settings } from './settings.js';
import * as ServerConfig from '@google/gemini-cli-core';
import { isWorkspaceTrusted } from './trustedFolders.js';
import { ExtensionManager } from './extension-manager.js';
import { RESUME_LATEST } from '../utils/sessionUtils.js';

vi.mock('./trustedFolders.js', () => ({
isWorkspaceTrusted: vi
Expand Down Expand Up @@ -482,6 +483,20 @@ describe('parseArguments', () => {
}
});

it('should return RESUME_LATEST constant when --resume is passed without a value', async () => {
const originalIsTTY = process.stdin.isTTY;
process.stdin.isTTY = true; // Make it interactive to avoid validation error
process.argv = ['node', 'script.js', '--resume'];

try {
const argv = await parseArguments({} as Settings);
expect(argv.resume).toBe(RESUME_LATEST);
expect(argv.resume).toBe('latest');
} finally {
process.stdin.isTTY = originalIsTTY;
}
});

it('should support comma-separated values for --allowed-tools', async () => {
process.argv = [
'node',
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { getCliVersion } from '../utils/version.js';
import { loadSandboxConfig } from './sandboxConfig.js';
import { resolvePath } from '../utils/resolvePath.js';
import { appEvents } from '../utils/events.js';
import { RESUME_LATEST } from '../utils/sessionUtils.js';

import { isWorkspaceTrusted } from './trustedFolders.js';
import { createPolicyEngineConfig } from './policy.js';
Expand All @@ -61,7 +62,7 @@ export interface CliArgs {
experimentalAcp: boolean | undefined;
extensions: string[] | undefined;
listExtensions: boolean | undefined;
resume: string | 'latest' | undefined;
resume: string | typeof RESUME_LATEST | undefined;
listSessions: boolean | undefined;
deleteSession: string | undefined;
includeDirectories: string[] | undefined;
Expand Down Expand Up @@ -189,7 +190,7 @@ export async function parseArguments(settings: Settings): Promise<CliArgs> {
// When --resume not passed at all: this `coerce` function is not called at all, and
// `yargsInstance.argv.resume` is undefined.
if (value === '') {
return 'latest';
return RESUME_LATEST;
}
return value;
},
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/src/utils/sessionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ import {
import * as fs from 'node:fs/promises';
import path from 'node:path';

/**
* Constant for the resume "latest" identifier.
* Used when --resume is passed without a value to select the most recent session.
*/
export const RESUME_LATEST = 'latest';

/**
* Session information for display and selection purposes.
*/
Expand Down Expand Up @@ -267,7 +273,7 @@ export class SessionSelector {
async resolveSession(resumeArg: string): Promise<SessionSelectionResult> {
let selectedSession: SessionInfo;

if (resumeArg === 'latest') {
if (resumeArg === RESUME_LATEST) {
const sessions = await this.listSessions();

if (sessions.length === 0) {
Expand Down
Loading