mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: fall back to name lookup for UUID-shaped workspace names (#24340)
`namedWorkspace` in `cli/root.go` parsed workspace identifiers with `uuid.Parse` first and returned immediately on success, even when no workspace had that UUID as its actual ID. This caused 404 errors for any workspace whose name was a valid 32-char hex string (dashless UUID). - Add `codersdk.ResolveWorkspace`: tries UUID lookup first, falls back to name lookup on 404. `NameValid` guard skips the fallback for standard dashed UUIDs (36 chars > 32-char name limit). - Export `codersdk.SplitWorkspaceIdentifier`, replacing the duplicate `splitNamedWorkspace` in `cli/root.go` (uses `strings.Cut`). - Delete `namedWorkspace` from `cli/root.go`; all 28 call sites now use `client.ResolveWorkspace` directly. - Delete `namedWorkspace` and `splitNameAndOwner` from `codersdk/toolsdk/bash.go`; inline `client.ResolveWorkspace`. - Simplify `GetWorkspace` tool handler to a single `ResolveWorkspace` call. - Unit tests via httptest mock cover UUID, name, owner/name, UUID-like fallback, not-found, server error, transport error, and invalid identifier paths. - Integration tests in `cli/show_test.go` and `codersdk/toolsdk` for workspaces with UUID-like names. > Generated with Coder Agents
This commit is contained in:
+7
-7
@@ -109,7 +109,7 @@ func (r *RootCmd) scheduleShow() *serpent.Command {
|
||||
if len(inv.Args) == 1 {
|
||||
// If the argument contains a slash, we assume it's a full owner/name reference
|
||||
if strings.Contains(inv.Args[0], "/") {
|
||||
_, workspaceName, err := splitNamedWorkspace(inv.Args[0])
|
||||
_, workspaceName, err := codersdk.SplitWorkspaceIdentifier(inv.Args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -161,7 +161,7 @@ func (r *RootCmd) scheduleStart() *serpent.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
workspace, err := namedWorkspace(inv.Context(), client, inv.Args[0])
|
||||
workspace, err := client.ResolveWorkspace(inv.Context(), inv.Args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -206,7 +206,7 @@ func (r *RootCmd) scheduleStart() *serpent.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
updated, err := namedWorkspace(inv.Context(), client, inv.Args[0])
|
||||
updated, err := client.ResolveWorkspace(inv.Context(), inv.Args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -234,7 +234,7 @@ func (r *RootCmd) scheduleStop() *serpent.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
workspace, err := namedWorkspace(inv.Context(), client, inv.Args[0])
|
||||
workspace, err := client.ResolveWorkspace(inv.Context(), inv.Args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -261,7 +261,7 @@ func (r *RootCmd) scheduleStop() *serpent.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
updated, err := namedWorkspace(inv.Context(), client, inv.Args[0])
|
||||
updated, err := client.ResolveWorkspace(inv.Context(), inv.Args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -293,7 +293,7 @@ func (r *RootCmd) scheduleExtend() *serpent.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
workspace, err := namedWorkspace(inv.Context(), client, inv.Args[0])
|
||||
workspace, err := client.ResolveWorkspace(inv.Context(), inv.Args[0])
|
||||
if err != nil {
|
||||
return xerrors.Errorf("get workspace: %w", err)
|
||||
}
|
||||
@@ -325,7 +325,7 @@ func (r *RootCmd) scheduleExtend() *serpent.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
updated, err := namedWorkspace(inv.Context(), client, inv.Args[0])
|
||||
updated, err := client.ResolveWorkspace(inv.Context(), inv.Args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user