|
18 | 18 | use Polyscope\Laravel\Resources\Workspace; |
19 | 19 | use Polyscope\Laravel\Resources\WorkspaceDiff; |
20 | 20 | use Polyscope\Laravel\Resources\WorkspaceMessages; |
| 21 | +use RuntimeException; |
21 | 22 |
|
22 | 23 | class PolyscopeSDKTest extends TestCase |
23 | 24 | { |
@@ -205,6 +206,64 @@ public function test_creating_workspace_returns_workspace_resource(): void |
205 | 206 | $this->assertSame([], $workspace->linkedWorktreeIds); |
206 | 207 | } |
207 | 208 |
|
| 209 | + public function test_repository_resource_can_create_workspace_without_manual_repository_id(): void |
| 210 | + { |
| 211 | + $sdk = new Polyscope('token', $http = Mockery::mock(Client::class)); |
| 212 | + |
| 213 | + $http->shouldReceive('request') |
| 214 | + ->once() |
| 215 | + ->with('POST', 'v1/workspaces', [ |
| 216 | + 'timeout' => 30, |
| 217 | + 'json' => [ |
| 218 | + 'prompt' => 'Fix bug', |
| 219 | + 'server_id' => 'srv-1', |
| 220 | + 'repository_id' => 'repo-1', |
| 221 | + ], |
| 222 | + ]) |
| 223 | + ->andReturn(new Response(201, [], json_encode([ |
| 224 | + 'data' => [ |
| 225 | + 'id' => 'wt-1', |
| 226 | + 'repo_id' => 'repo-1', |
| 227 | + 'branch' => 'fix-bug', |
| 228 | + 'status' => 'active', |
| 229 | + ], |
| 230 | + ], JSON_THROW_ON_ERROR))); |
| 231 | + |
| 232 | + $repository = new \Polyscope\Laravel\Resources\Repository([ |
| 233 | + 'id' => 'repo-1', |
| 234 | + 'name' => 'polyscope', |
| 235 | + 'path' => '/code/polyscope', |
| 236 | + ], $sdk); |
| 237 | + |
| 238 | + $workspace = $repository->createWorkspace([ |
| 239 | + 'prompt' => 'Fix bug', |
| 240 | + 'server_id' => 'srv-1', |
| 241 | + ]); |
| 242 | + |
| 243 | + $this->assertInstanceOf(Workspace::class, $workspace); |
| 244 | + $this->assertSame('wt-1', $workspace->id); |
| 245 | + $this->assertSame('repo-1', $workspace->repoId); |
| 246 | + } |
| 247 | + |
| 248 | + public function test_repository_resource_rejects_mismatched_repository_id_when_creating_workspace(): void |
| 249 | + { |
| 250 | + $this->expectException(RuntimeException::class); |
| 251 | + $this->expectExceptionMessage('The provided repository_id does not match this repository resource.'); |
| 252 | + |
| 253 | + $sdk = new Polyscope('token'); |
| 254 | + |
| 255 | + $repository = new \Polyscope\Laravel\Resources\Repository([ |
| 256 | + 'id' => 'repo-1', |
| 257 | + 'name' => 'polyscope', |
| 258 | + 'path' => '/code/polyscope', |
| 259 | + ], $sdk); |
| 260 | + |
| 261 | + $repository->createWorkspace([ |
| 262 | + 'repository_id' => 'repo-2', |
| 263 | + 'prompt' => 'Fix bug', |
| 264 | + ]); |
| 265 | + } |
| 266 | + |
208 | 267 | public function test_workspace_show_maps_nested_properties(): void |
209 | 268 | { |
210 | 269 | $sdk = new Polyscope('token', $http = Mockery::mock(Client::class)); |
|
0 commit comments