|
| 1 | +import { Logger } from 'mycoder-agent'; |
1 | 2 | import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest'; |
2 | 3 |
|
3 | 4 | import { command } from '../../src/commands/config.js'; |
| 5 | +import type { ConfigOptions } from '../../src/commands/config.js'; |
| 6 | +import type { ArgumentsCamelCase } from 'yargs'; |
4 | 7 | import { getConfig, updateConfig } from '../../src/settings/config.js'; |
5 | | -import { Logger } from 'mycoder-agent'; |
6 | 8 |
|
7 | 9 | // Mock dependencies |
8 | 10 | vi.mock('../../src/settings/config.js', () => ({ |
@@ -30,107 +32,124 @@ vi.mock('../../src/utils/nameToLogIndex.js', () => ({ |
30 | 32 |
|
31 | 33 | // Skip tests for now - they need to be rewritten for the new command structure |
32 | 34 | describe.skip('Config Command', () => { |
33 | | - let mockLogger: { info: any; error: any }; |
34 | | - |
| 35 | + let mockLogger: { info: jest.Mock; error: jest.Mock }; |
| 36 | + |
35 | 37 | beforeEach(() => { |
36 | 38 | mockLogger = { |
37 | 39 | info: vi.fn(), |
38 | 40 | error: vi.fn(), |
39 | 41 | }; |
40 | | - vi.mocked(Logger).mockImplementation(() => mockLogger as any); |
| 42 | + vi.mocked(Logger).mockImplementation(() => mockLogger as unknown as Logger); |
41 | 43 | vi.mocked(getConfig).mockReturnValue({ githubMode: false }); |
42 | | - vi.mocked(updateConfig).mockImplementation((config) => ({ githubMode: false, ...config })); |
| 44 | + vi.mocked(updateConfig).mockImplementation((config) => ({ |
| 45 | + githubMode: false, |
| 46 | + ...config, |
| 47 | + })); |
43 | 48 | }); |
44 | 49 |
|
45 | 50 | afterEach(() => { |
46 | 51 | vi.resetAllMocks(); |
47 | 52 | }); |
48 | 53 |
|
49 | 54 | it('should list all configuration values', async () => { |
50 | | - await command.handler!({ |
| 55 | + await command.handler!({ |
51 | 56 | _: ['config', 'config', 'list'], |
52 | 57 | logLevel: 'info', |
53 | 58 | interactive: false, |
54 | | - command: 'list' |
| 59 | + command: 'list', |
55 | 60 | } as any); |
56 | 61 |
|
57 | 62 | expect(getConfig).toHaveBeenCalled(); |
58 | 63 | expect(mockLogger.info).toHaveBeenCalledWith('Current configuration:'); |
59 | | - expect(mockLogger.info).toHaveBeenCalledWith(expect.stringContaining('githubMode')); |
| 64 | + expect(mockLogger.info).toHaveBeenCalledWith( |
| 65 | + expect.stringContaining('githubMode'), |
| 66 | + ); |
60 | 67 | }); |
61 | 68 |
|
62 | 69 | it('should get a configuration value', async () => { |
63 | | - await command.handler!({ |
| 70 | + await command.handler!({ |
64 | 71 | _: ['config', 'config', 'get', 'githubMode'], |
65 | 72 | logLevel: 'info', |
66 | 73 | interactive: false, |
67 | 74 | command: 'get', |
68 | | - key: 'githubMode' |
| 75 | + key: 'githubMode', |
69 | 76 | } as any); |
70 | 77 |
|
71 | 78 | expect(getConfig).toHaveBeenCalled(); |
72 | | - expect(mockLogger.info).toHaveBeenCalledWith(expect.stringContaining('githubMode')); |
| 79 | + expect(mockLogger.info).toHaveBeenCalledWith( |
| 80 | + expect.stringContaining('githubMode'), |
| 81 | + ); |
73 | 82 | }); |
74 | 83 |
|
75 | 84 | it('should show error when getting non-existent key', async () => { |
76 | | - await command.handler!({ |
| 85 | + await command.handler!({ |
77 | 86 | _: ['config', 'config', 'get', 'nonExistentKey'], |
78 | 87 | logLevel: 'info', |
79 | 88 | interactive: false, |
80 | 89 | command: 'get', |
81 | | - key: 'nonExistentKey' |
| 90 | + key: 'nonExistentKey', |
82 | 91 | } as any); |
83 | 92 |
|
84 | | - expect(mockLogger.error).toHaveBeenCalledWith(expect.stringContaining("not found")); |
| 93 | + expect(mockLogger.error).toHaveBeenCalledWith( |
| 94 | + expect.stringContaining('not found'), |
| 95 | + ); |
85 | 96 | }); |
86 | 97 |
|
87 | 98 | it('should set a configuration value', async () => { |
88 | | - await command.handler!({ |
| 99 | + await command.handler!({ |
89 | 100 | _: ['config', 'config', 'set', 'githubMode', 'true'], |
90 | 101 | logLevel: 'info', |
91 | 102 | interactive: false, |
92 | 103 | command: 'set', |
93 | 104 | key: 'githubMode', |
94 | | - value: 'true' |
| 105 | + value: 'true', |
95 | 106 | } as any); |
96 | 107 |
|
97 | 108 | expect(updateConfig).toHaveBeenCalledWith({ githubMode: true }); |
98 | | - expect(mockLogger.info).toHaveBeenCalledWith(expect.stringContaining('Updated')); |
| 109 | + expect(mockLogger.info).toHaveBeenCalledWith( |
| 110 | + expect.stringContaining('Updated'), |
| 111 | + ); |
99 | 112 | }); |
100 | 113 |
|
101 | 114 | it('should handle missing key for set command', async () => { |
102 | | - await command.handler!({ |
| 115 | + await command.handler!({ |
103 | 116 | _: ['config', 'config', 'set'], |
104 | 117 | logLevel: 'info', |
105 | 118 | interactive: false, |
106 | 119 | command: 'set', |
107 | | - key: undefined |
| 120 | + key: undefined, |
108 | 121 | } as any); |
109 | 122 |
|
110 | | - expect(mockLogger.error).toHaveBeenCalledWith(expect.stringContaining('Key is required')); |
| 123 | + expect(mockLogger.error).toHaveBeenCalledWith( |
| 124 | + expect.stringContaining('Key is required'), |
| 125 | + ); |
111 | 126 | }); |
112 | 127 |
|
113 | 128 | it('should handle missing value for set command', async () => { |
114 | | - await command.handler!({ |
| 129 | + await command.handler!({ |
115 | 130 | _: ['config', 'config', 'set', 'githubMode'], |
116 | 131 | logLevel: 'info', |
117 | 132 | interactive: false, |
118 | 133 | command: 'set', |
119 | 134 | key: 'githubMode', |
120 | | - value: undefined |
| 135 | + value: undefined, |
121 | 136 | } as any); |
122 | 137 |
|
123 | | - expect(mockLogger.error).toHaveBeenCalledWith(expect.stringContaining('Value is required')); |
| 138 | + expect(mockLogger.error).toHaveBeenCalledWith( |
| 139 | + expect.stringContaining('Value is required'), |
| 140 | + ); |
124 | 141 | }); |
125 | 142 |
|
126 | 143 | it('should handle unknown command', async () => { |
127 | | - await command.handler!({ |
| 144 | + await command.handler!({ |
128 | 145 | _: ['config', 'config', 'unknown'], |
129 | 146 | logLevel: 'info', |
130 | 147 | interactive: false, |
131 | | - command: 'unknown' as any |
| 148 | + command: 'unknown' as any, |
132 | 149 | } as any); |
133 | 150 |
|
134 | | - expect(mockLogger.error).toHaveBeenCalledWith(expect.stringContaining('Unknown config command')); |
| 151 | + expect(mockLogger.error).toHaveBeenCalledWith( |
| 152 | + expect.stringContaining('Unknown config command'), |
| 153 | + ); |
135 | 154 | }); |
136 | 155 | }); |
0 commit comments