fix: ensure positional prompt arguments work with extensions flag (#10077)

Co-authored-by: Allen Hutchison <adh@google.com>
This commit is contained in:
김세은
2025-10-09 05:32:05 +09:00
committed by GitHub
parent b92e3bca50
commit 1962b51d8d
4 changed files with 142 additions and 0 deletions
+125
View File
@@ -2975,6 +2975,121 @@ describe('loadCliConfig interactive', () => {
expect(argv.promptInteractive).toBeUndefined();
});
it('should not be interactive if positional prompt words are provided with extensions flag', async () => {
process.stdin.isTTY = true;
process.argv = ['node', 'script.js', '-e', 'none', 'hello'];
const argv = await parseArguments({} as Settings);
const config = await loadCliConfig(
{},
[],
new ExtensionEnablementManager(
ExtensionStorage.getUserExtensionsDir(),
argv.extensions,
),
'test-session',
argv,
);
expect(config.isInteractive()).toBe(false);
expect(argv.query).toBe('hello');
expect(argv.extensions).toEqual(['none']);
});
it('should handle multiple positional words correctly', async () => {
process.stdin.isTTY = true;
process.argv = ['node', 'script.js', 'hello world how are you'];
const argv = await parseArguments({} as Settings);
const config = await loadCliConfig(
{},
[],
new ExtensionEnablementManager(
ExtensionStorage.getUserExtensionsDir(),
argv.extensions,
),
'test-session',
argv,
);
expect(config.isInteractive()).toBe(false);
expect(argv.query).toBe('hello world how are you');
expect(argv.prompt).toBe('hello world how are you');
});
it('should handle multiple positional words with flags', async () => {
process.stdin.isTTY = true;
process.argv = [
'node',
'script.js',
'--model',
'gemini-1.5-pro',
'write',
'a',
'function',
'to',
'sort',
'array',
];
const argv = await parseArguments({} as Settings);
const config = await loadCliConfig(
{},
[],
new ExtensionEnablementManager(
ExtensionStorage.getUserExtensionsDir(),
argv.extensions,
),
'test-session',
argv,
);
expect(config.isInteractive()).toBe(false);
expect(argv.query).toBe('write a function to sort array');
expect(argv.model).toBe('gemini-1.5-pro');
});
it('should handle empty positional arguments', async () => {
process.stdin.isTTY = true;
process.argv = ['node', 'script.js', ''];
const argv = await parseArguments({} as Settings);
const config = await loadCliConfig(
{},
[],
new ExtensionEnablementManager(
ExtensionStorage.getUserExtensionsDir(),
argv.extensions,
),
'test-session',
argv,
);
expect(config.isInteractive()).toBe(true);
expect(argv.query).toBeUndefined();
});
it('should handle extensions flag with positional arguments correctly', async () => {
process.stdin.isTTY = true;
process.argv = [
'node',
'script.js',
'-e',
'none',
'hello',
'world',
'how',
'are',
'you',
];
const argv = await parseArguments({} as Settings);
const config = await loadCliConfig(
{},
[],
new ExtensionEnablementManager(
ExtensionStorage.getUserExtensionsDir(),
argv.extensions,
),
'test-session',
argv,
);
expect(config.isInteractive()).toBe(false);
expect(argv.query).toBe('hello world how are you');
expect(argv.extensions).toEqual(['none']);
});
it('should be interactive if no positional prompt words are provided with flags', async () => {
process.stdin.isTTY = true;
process.argv = ['node', 'script.js', '--model', 'gemini-1.5-pro'];
@@ -3420,6 +3535,16 @@ describe('parseArguments with positional prompt', () => {
expect(argv.promptInteractive).toBeUndefined();
});
it('should have correct positional argument description', async () => {
// Test that the positional argument has the expected description
const yargsInstance = await import('./config.js');
// This test verifies that the positional 'query' argument is properly configured
// with the description: "Positional prompt. Defaults to one-shot; use -i/--prompt-interactive for interactive."
process.argv = ['node', 'script.js', 'test', 'query'];
const argv = await yargsInstance.parseArguments({} as Settings);
expect(argv.query).toBe('test query');
});
it('should correctly parse a prompt from the --prompt flag', async () => {
process.argv = ['node', 'script.js', '--prompt', 'test prompt'];
const argv = await parseArguments({} as Settings);
+1
View File
@@ -255,6 +255,7 @@ export async function parseArguments(settings: Settings): Promise<CliArgs> {
alias: 'e',
type: 'array',
string: true,
nargs: 1,
description:
'A list of extensions to use. If not provided, all extensions are used.',
coerce: (extensions: string[]) =>