forked from laravel/boost
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodexTest.php
More file actions
187 lines (132 loc) · 6.13 KB
/
CodexTest.php
File metadata and controls
187 lines (132 loc) · 6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
declare(strict_types=1);
namespace Tests\Unit\Install\Agents;
use Illuminate\Support\Facades\File;
use Laravel\Boost\Install\Agents\Codex;
use Laravel\Boost\Install\Contracts\DetectionStrategy;
use Laravel\Boost\Install\Detection\DetectionStrategyFactory;
use Laravel\Boost\Install\Enums\McpInstallationStrategy;
use Laravel\Boost\Install\Enums\Platform;
use Mockery;
beforeEach(function (): void {
$this->strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
$this->strategy = Mockery::mock(DetectionStrategy::class);
});
test('returns correct name', function (): void {
$codex = new Codex($this->strategyFactory);
expect($codex->name())->toBe('codex');
});
test('returns correct display name', function (): void {
$codex = new Codex($this->strategyFactory);
expect($codex->displayName())->toBe('Codex');
});
test('uses FILE-based MCP installation strategy', function (): void {
$codex = new Codex($this->strategyFactory);
expect($codex->mcpInstallationStrategy())->toBe(McpInstallationStrategy::FILE);
});
test('returns correct MCP config path', function (): void {
$codex = new Codex($this->strategyFactory);
expect($codex->mcpConfigPath())->toBe('.codex/config.toml');
});
test('returns correct MCP config key', function (): void {
$codex = new Codex($this->strategyFactory);
expect($codex->mcpConfigKey())->toBe('mcp_servers');
});
test('builds MCP server config with cwd field', function (): void {
$codex = new Codex($this->strategyFactory);
$config = $codex->mcpServerConfig('php', ['artisan', 'boost:mcp']);
expect($config)->toHaveKey('command', 'php')
->toHaveKey('args', ['artisan', 'boost:mcp'])
->toHaveKey('cwd', base_path());
});
test('builds MCP server config with config "boost.executable_paths.current_directory" override', function (): void {
config()->set('boost.executable_paths.current_directory', '/Users/developer/projects/app');
$codex = new Codex($this->strategyFactory);
$config = $codex->mcpServerConfig('php', ['artisan', 'boost:mcp']);
expect($config)->toHaveKey('command', 'php')
->toHaveKey('args', ['artisan', 'boost:mcp'])
->toHaveKey('cwd', '/Users/developer/projects/app');
});
test('builds MCP server config with BOOST_CURRENT_DIRECTORY_EXECUTABLE_PATH env override', function (): void {
putenv('BOOST_CURRENT_DIRECTORY_EXECUTABLE_PATH=/Users/developer/projects/app');
config()->set('boost.executable_paths.current_directory', env('BOOST_CURRENT_DIRECTORY_EXECUTABLE_PATH', base_path()));
$codex = new Codex($this->strategyFactory);
$config = $codex->mcpServerConfig('php', ['artisan', 'boost:mcp']);
expect($config)->toHaveKey('command', 'php')
->toHaveKey('args', ['artisan', 'boost:mcp'])
->toHaveKey('cwd', '/Users/developer/projects/app');
})->after(fn () => putenv('BOOST_CURRENT_DIRECTORY_EXECUTABLE_PATH'));
test('builds MCP server config with env when provided', function (): void {
$codex = new Codex($this->strategyFactory);
$config = $codex->mcpServerConfig('php', ['artisan'], ['APP_ENV' => 'local']);
expect($config)->toHaveKey('command', 'php')
->toHaveKey('args', ['artisan'])
->toHaveKey('cwd')
->toHaveKey('env', ['APP_ENV' => 'local']);
});
test('filters empty values from server config', function (): void {
$codex = new Codex($this->strategyFactory);
$config = $codex->mcpServerConfig('php', [], []);
expect($config)->toHaveKey('command', 'php')
->toHaveKey('cwd')
->not->toHaveKey('args')
->not->toHaveKey('env');
});
test('includes config.toml in project detection', function (): void {
$codex = new Codex($this->strategyFactory);
$detection = $codex->projectDetectionConfig();
expect($detection['files'])->toContain('.codex/config.toml')
->toContain('AGENTS.md');
expect($detection['paths'])->toContain('.codex');
});
test('returns correct guidelines path', function (): void {
$codex = new Codex($this->strategyFactory);
expect($codex->guidelinesPath())->toBe('AGENTS.md');
});
test('returns correct skills path', function (): void {
$codex = new Codex($this->strategyFactory);
expect($codex->skillsPath())->toBe('.agents/skills');
});
test('httpMcpServerConfig returns npx mcp-remote config', function (): void {
$codex = new Codex($this->strategyFactory);
expect($codex->httpMcpServerConfig('https://nightwatch.laravel.com/mcp'))->toBe([
'command' => 'npx',
'args' => ['-y', 'mcp-remote', 'https://nightwatch.laravel.com/mcp'],
]);
});
test('system detection uses which command on Darwin', function (): void {
$codex = new Codex($this->strategyFactory);
$config = $codex->systemDetectionConfig(Platform::Darwin);
expect($config['command'])->toBe('which codex');
});
test('system detection uses which command on Linux', function (): void {
$codex = new Codex($this->strategyFactory);
$config = $codex->systemDetectionConfig(Platform::Linux);
expect($config['command'])->toBe('which codex');
});
test('system detection uses where command on Windows', function (): void {
$codex = new Codex($this->strategyFactory);
$config = $codex->systemDetectionConfig(Platform::Windows);
expect($config['command'])->toBe('cmd /c where codex 2>nul');
});
test('installMcp creates TOML config file', function (): void {
$codex = new Codex($this->strategyFactory);
$capturedContent = '';
File::shouldReceive('ensureDirectoryExists')
->once()
->with('.codex');
File::shouldReceive('exists')
->once()
->with('.codex/config.toml')
->andReturn(false);
File::shouldReceive('put')
->once()
->with(Mockery::any(), Mockery::capture($capturedContent))
->andReturn(true);
$result = $codex->installMcp('laravel_boost', 'php', ['artisan', 'boost:mcp']);
expect($result)->toBeTrue()
->and($capturedContent)->toContain('[mcp_servers.laravel_boost]')
->and($capturedContent)->toContain('command = "php"')
->and($capturedContent)->toContain('args = ["artisan", "boost:mcp"]')
->and($capturedContent)->toContain('cwd = ');
});