From 44f486b0dc0089122cae8d328ea930750aaabfda Mon Sep 17 00:00:00 2001 From: Diana Scharf Date: Thu, 19 Nov 2026 11:53:39 +0100 Subject: [PATCH] Expose the workspace url returned by the v1 API The v1 API now returns a url on every workspace that opens it directly in Polyscope (beyondcode/polyscope-website#97). Declaring it on the Workspace resource gives IDE and PHPStan support and a null default when an older API response leaves it out, instead of an undefined property warning. --- src/Resources/Workspace.php | 2 ++ tests/PolyscopeSDKTest.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/Resources/Workspace.php b/src/Resources/Workspace.php index b17d522..69e98cc 100644 --- a/src/Resources/Workspace.php +++ b/src/Resources/Workspace.php @@ -14,6 +14,8 @@ class Workspace extends Resource public ?string $serverId = null; + public ?string $url = null; + public ?string $branch = null; public bool $branchRenamed = false; diff --git a/tests/PolyscopeSDKTest.php b/tests/PolyscopeSDKTest.php index c1efd2f..57a1ffa 100644 --- a/tests/PolyscopeSDKTest.php +++ b/tests/PolyscopeSDKTest.php @@ -151,6 +151,38 @@ public function test_repositories_support_server_filter(): void $this->assertSame('srv-1', $repositories[0]->serverId); } + public function test_listing_workspaces_maps_url(): void + { + $sdk = new Polyscope('token', $http = Mockery::mock(Client::class)); + + $http->shouldReceive('request') + ->once() + ->with('GET', 'v1/workspaces', Mockery::on(function (array $options): bool { + return ($options['timeout'] ?? null) === 30 + && ($options['query']['server_id'] ?? null) === 'srv-1'; + })) + ->andReturn(new Response(200, [], json_encode([ + 'data' => [ + [ + 'id' => 'wt-1', + 'server_id' => 'srv-1', + 'url' => 'https://getpolyscope.com/servers/srv-1/session?workspace=wt-1', + ], + [ + 'id' => 'wt-2', + 'server_id' => 'srv-1', + ], + ], + ], JSON_THROW_ON_ERROR))); + + $workspaces = $sdk->workspaces(['server_id' => 'srv-1']); + + $this->assertCount(2, $workspaces); + $this->assertInstanceOf(Workspace::class, $workspaces[0]); + $this->assertSame('https://getpolyscope.com/servers/srv-1/session?workspace=wt-1', $workspaces[0]->url); + $this->assertNull($workspaces[1]->url); + } + public function test_creating_workspace_returns_workspace_resource(): void { $sdk = new Polyscope('token', $http = Mockery::mock(Client::class)); @@ -169,6 +201,7 @@ public function test_creating_workspace_returns_workspace_resource(): void 'id' => 'wt-1', 'repo_id' => 'repo-1', 'server_id' => 'srv-1', + 'url' => 'https://getpolyscope.com/servers/srv-1/session?workspace=wt-1', 'branch' => 'fix-bug', 'branch_renamed' => false, 'path' => '/code/polyscope/.polyscope/worktrees/fix-bug', @@ -198,6 +231,7 @@ public function test_creating_workspace_returns_workspace_resource(): void $this->assertSame('wt-1', $workspace->id); $this->assertSame('repo-1', $workspace->repoId); $this->assertSame('srv-1', $workspace->serverId); + $this->assertSame('https://getpolyscope.com/servers/srv-1/session?workspace=wt-1', $workspace->url); $this->assertSame('fix-bug', $workspace->branch); $this->assertFalse($workspace->branchRenamed); $this->assertSame('/code/polyscope/.polyscope/worktrees/fix-bug', $workspace->path); @@ -313,6 +347,7 @@ public function test_workspace_show_maps_nested_properties(): void 'id' => 'wt-1', 'repo_id' => 'repo-1', 'server_id' => 'srv-1', + 'url' => 'https://getpolyscope.com/servers/srv-1/session?workspace=wt-1', 'branch' => 'fix-bug', 'branch_renamed' => true, 'path' => '/code/polyscope/.polyscope/worktrees/fix-bug', @@ -349,6 +384,7 @@ public function test_workspace_show_maps_nested_properties(): void $this->assertSame('wt-1', $workspace->id); $this->assertSame('repo-1', $workspace->repoId); $this->assertSame('srv-1', $workspace->serverId); + $this->assertSame('https://getpolyscope.com/servers/srv-1/session?workspace=wt-1', $workspace->url); $this->assertTrue($workspace->branchRenamed); $this->assertSame(12, $workspace->prNumber); $this->assertSame('https://github.com/beyondcode/polyscope/pull/12', $workspace->prUrl);