diff options
| author | Arya Gummadi <[email protected]> | 2025-08-12 15:10:22 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-12 22:10:22 +0000 |
| commit | 8d6eb8c322890b5cdf20d4a30dd17afb1541f5aa (patch) | |
| tree | 34c8c86d69aa96405c2c1024c45cef76d1675ece /packages/cli/src/config/config.integration.test.ts | |
| parent | 11377915dbf42064ed9a8d9e31b46adc565ae021 (diff) | |
feat: add --approval-mode parameter (#6024)
Co-authored-by: Jacob Richman <[email protected]>
Diffstat (limited to 'packages/cli/src/config/config.integration.test.ts')
| -rw-r--r-- | packages/cli/src/config/config.integration.test.ts | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/packages/cli/src/config/config.integration.test.ts b/packages/cli/src/config/config.integration.test.ts index 87a74578..45ed6d82 100644 --- a/packages/cli/src/config/config.integration.test.ts +++ b/packages/cli/src/config/config.integration.test.ts @@ -261,4 +261,149 @@ describe('Configuration Integration Tests', () => { expect(config.getExtensionContextFilePaths()).toEqual(contextFiles); }); }); + + describe('Approval Mode Integration Tests', () => { + let parseArguments: typeof import('./config').parseArguments; + + beforeEach(async () => { + // Import the argument parsing function for integration testing + const { parseArguments: parseArgs } = await import('./config'); + parseArguments = parseArgs; + }); + + it('should parse --approval-mode=auto_edit correctly through the full argument parsing flow', async () => { + const originalArgv = process.argv; + + try { + process.argv = [ + 'node', + 'script.js', + '--approval-mode', + 'auto_edit', + '-p', + 'test', + ]; + + const argv = await parseArguments(); + + // Verify that the argument was parsed correctly + expect(argv.approvalMode).toBe('auto_edit'); + expect(argv.prompt).toBe('test'); + expect(argv.yolo).toBe(false); + } finally { + process.argv = originalArgv; + } + }); + + it('should parse --approval-mode=yolo correctly through the full argument parsing flow', async () => { + const originalArgv = process.argv; + + try { + process.argv = [ + 'node', + 'script.js', + '--approval-mode', + 'yolo', + '-p', + 'test', + ]; + + const argv = await parseArguments(); + + expect(argv.approvalMode).toBe('yolo'); + expect(argv.prompt).toBe('test'); + expect(argv.yolo).toBe(false); // Should NOT be set when using --approval-mode + } finally { + process.argv = originalArgv; + } + }); + + it('should parse --approval-mode=default correctly through the full argument parsing flow', async () => { + const originalArgv = process.argv; + + try { + process.argv = [ + 'node', + 'script.js', + '--approval-mode', + 'default', + '-p', + 'test', + ]; + + const argv = await parseArguments(); + + expect(argv.approvalMode).toBe('default'); + expect(argv.prompt).toBe('test'); + expect(argv.yolo).toBe(false); + } finally { + process.argv = originalArgv; + } + }); + + it('should parse legacy --yolo flag correctly', async () => { + const originalArgv = process.argv; + + try { + process.argv = ['node', 'script.js', '--yolo', '-p', 'test']; + + const argv = await parseArguments(); + + expect(argv.yolo).toBe(true); + expect(argv.approvalMode).toBeUndefined(); // Should NOT be set when using --yolo + expect(argv.prompt).toBe('test'); + } finally { + process.argv = originalArgv; + } + }); + + it('should reject invalid approval mode values during argument parsing', async () => { + const originalArgv = process.argv; + + try { + process.argv = ['node', 'script.js', '--approval-mode', 'invalid_mode']; + + // Should throw during argument parsing due to yargs validation + await expect(parseArguments()).rejects.toThrow(); + } finally { + process.argv = originalArgv; + } + }); + + it('should reject conflicting --yolo and --approval-mode flags', async () => { + const originalArgv = process.argv; + + try { + process.argv = [ + 'node', + 'script.js', + '--yolo', + '--approval-mode', + 'default', + ]; + + // Should throw during argument parsing due to conflict validation + await expect(parseArguments()).rejects.toThrow(); + } finally { + process.argv = originalArgv; + } + }); + + it('should handle backward compatibility with mixed scenarios', async () => { + const originalArgv = process.argv; + + try { + // Test that no approval mode arguments defaults to no flags set + process.argv = ['node', 'script.js', '-p', 'test']; + + const argv = await parseArguments(); + + expect(argv.approvalMode).toBeUndefined(); + expect(argv.yolo).toBe(false); + expect(argv.prompt).toBe('test'); + } finally { + process.argv = originalArgv; + } + }); + }); }); |
