feat: send include_related from WorkspaceByOwnerAndName options (#29908)

Stacked on #29855.

Wires `WorkspaceOptions.IncludeRelated` through
`codersdk.Client.WorkspaceByOwnerAndName`. The method now applies
`params.asRequestOption()` (matching `Client.Workspace`), so the
`include_related` query parameter is sent to the server. Previously it
only forwarded `include_deleted` and silently dropped `IncludeRelated`.

- `include_deleted` behavior is unchanged: `asRequestOption` sets it
when true; the server treats an omitted value the same as `false`.
- Updated the `TemplateOnly` and `LatestBuildOnly` subtests of
`TestWorkspaceByOwnerAndNameIncludeRelated` to drive narrowing through
the SDK method and its options, exercising the wiring end to end.
Option-level encoding is already covered by
`TestWorkspaceOptionsAsRequestOption`.

_This PR was created by Coder Agents on behalf of @spikecurtis._
This commit is contained in:
Spike Curtis authored and GitHub committed 2026-10-26 12:59:53 +01:00
1 parent b9e76bd827
commit 9fe52826da
2 files changed
+16 -10

No files matched your search

+9 -4
View File
@@ -48,6 +48,7 @@ import (
"github.com/coder/coder/v2/coderd/workspacestats"
"github.com/coder/coder/v2/coderd/wsbuilder"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/wsrelated"
"github.com/coder/coder/v2/cryptorand"
"github.com/coder/coder/v2/provisioner/echo"
"github.com/coder/coder/v2/provisionersdk/proto"
@@ -6620,8 +6621,10 @@ func TestWorkspaceByOwnerAndNameIncludeRelated(t *testing.T) {
t.Run("TemplateOnly", func(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitLong)
w, code := get(ctx, t, "template")
require.Equal(t, http.StatusOK, code)
cfg, err := wsrelated.Parse("template")
require.NoError(t, err)
w, err := client.WorkspaceByOwnerAndName(ctx, codersdk.Me, workspace.Name, codersdk.WorkspaceOptions{IncludeRelated: &cfg})
require.NoError(t, err)
require.Equal(t, workspace.ID, w.ID)
// The build was not requested, so it is omitted (zero value).
require.Equal(t, uuid.Nil, w.LatestBuild.ID)
@@ -6632,8 +6635,10 @@ func TestWorkspaceByOwnerAndNameIncludeRelated(t *testing.T) {
t.Run("LatestBuildOnly", func(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitLong)
w, code := get(ctx, t, "latest_build.*")
require.Equal(t, http.StatusOK, code)
cfg, err := wsrelated.Parse("latest_build.*")
require.NoError(t, err)
w, err := client.WorkspaceByOwnerAndName(ctx, codersdk.Me, workspace.Name, codersdk.WorkspaceOptions{IncludeRelated: &cfg})
require.NoError(t, err)
require.Equal(t, workspace.ID, w.ID)
// The build was requested, so it is populated.
require.Equal(t, workspace.LatestBuild.ID, w.LatestBuild.ID)
+7 -6
View File
@@ -654,7 +654,7 @@ func (c *Client) Workspaces(ctx context.Context, filter WorkspaceFilter) (Worksp
}
// WorkspaceByOwnerAndName returns a workspace by the owner's UUID and the workspace's name.
func (c *Client) WorkspaceByOwnerAndName(ctx context.Context, owner string, name string, params WorkspaceOptions) (Workspace, error) {
func (c *Client) WorkspaceByOwnerAndName(ctx context.Context, owner string, name string, opts ...WorkspaceOptions) (Workspace, error) {
// These identifiers must remain individual path segments during URL resolution.
if err := validateWorkspacePathSegment(owner); err != nil {
return Workspace{}, xerrors.Errorf("invalid workspace owner: %w", err)
@@ -662,11 +662,12 @@ func (c *Client) WorkspaceByOwnerAndName(ctx context.Context, owner string, name
if err := validateWorkspacePathSegment(name); err != nil {
return Workspace{}, xerrors.Errorf("invalid workspace name: %w", err)
}
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/users/%s/workspace/%s", owner, name), nil, func(r *http.Request) {
q := r.URL.Query()
q.Set("include_deleted", fmt.Sprintf("%t", params.IncludeDeleted))
r.URL.RawQuery = q.Encode()
})
reqOpts := make([]RequestOption, 0, len(opts)+1)
reqOpts = append(reqOpts, WithQueryParam("include_deleted", "false"))
for _, o := range opts {
reqOpts = append(reqOpts, o.asRequestOption())
}
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/users/%s/workspace/%s", owner, name), nil, reqOpts...)
if err != nil {
return Workspace{}, err
}