SSH hints across the CLI, dashboard and docs used different, sometimes broken, workspace names. This makes them consistent with minimal, non-breaking changes and no new syntax: - Plain `ssh` hostnames: `<agent>.<workspace>.<owner>.<suffix>` (or `<workspace>.<suffix>` for single-agent workspaces). Works with `config-ssh` (with or without `--no-wildcard`) and Coder Connect. - `coder` CLI arguments: `[<owner>/]<workspace>[.<agent>]`, with the owner unless the workspace was given by its bare name. Built on #31192, which is now merged into `main`. ## Changes - **`coder ping` multi-agent error**: now suggests `coder ping <workspace>.<agent>` instead of listing agents without a runnable command. Owner-qualified and UUID inputs retain `<owner>/<workspace>`. JSON-mode errors leave stdout empty, and ping still does not autostart stopped workspaces. - **`coder ssh` multi-agent error**: when run directly (no `--ssh-host-prefix`/`--hostname-suffix`), it suggested `ssh coder.dogfood.matifali`, which never resolves without a matching SSH config entry or Coder Connect. For an agent named `dev`, it now suggests `coder ssh dogfood.dev`, or `coder ssh bob/dogfood.dev` if the workspace was given as `owner/name` or by ID. Here `.dev` selects the agent; it is not an SSH hostname suffix. The ProxyCommand path used by `config-ssh` and the IDE plugins still suggests the full hostname. - **`coder show` / `coder create`**: the access column dropped the owner, so `coder show bob/dogfood` or `coder show <id>` suggested `coder ssh dogfood.dev`. It now keeps the owner unless the workspace was given by its bare name. - **`coder config-ssh`**: the example `ssh <workspace>.coder` is ambiguous for multi-agent workspaces. It now names an agent, `ssh <agent>.<workspace>.<owner>.coder`, reading a stopped workspace’s known agents from its latest successful start using the same template version. With `--no-wildcard`, the hint reuses the workspace snapshot and resources used to write the Host entries. - **Dashboard "Connect via SSH"**: rendered `...<owner>.undefined` when the deployment has no hostname suffix. It now falls back to `coder ssh <owner>/<workspace>` for single-agent workspaces, or `coder ssh <owner>/<workspace>.<agent>` otherwise. With a hostname suffix, owned single-agent workspaces show `ssh <workspace>.<suffix>` unless that hostname collides with the deployment’s legacy prefix block. Prefix collisions, shared workspaces and multi-agent workspaces retain the full agent/workspace/owner hostname. The count includes agents across all resources and devcontainers. Commands remain undefined while the SSH config loads, with a spinner instead of a premature fallback. If the initial load fails, it displays the error while keeping the CLI command available. - **Docs**: workspace access docs said `config-ssh` prints `ssh coder.<workspace>`; it prints `ssh <workspace>.coder`. Added the multi-agent hostname, noted it in the Desktop docs, and updated the Gateway host and the networking page to `<workspace>.coder`. ## Before / after ```console $ coder ssh dogfood error: multiple agents found, please specify the agent name, available agents: [coder dev] Try running: $ ssh dev.dogfood.matifali # before: does not resolve $ coder ssh dogfood.dev # after: dev is the agent name ``` ## Compatibility Hostname parsing (`findWorkspaceAndAgentByHostname`, `normalizeWorkspaceInput`) is unchanged, so every hostname that resolves today still does. The VS Code, JetBrains Gateway and Toolbox plugins write their own `Host` entries and run `coder ssh --stdio --ssh-host-prefix <prefix>`, so they don't reach the changed hints. `TestSSH_AgentHostnames` connects with their `<prefix>--<owner>--<workspace>.<agent>` form, and with the `<agent>.<workspace>.<owner>` forms used by `config-ssh` and the dashboard. ## Verification CLI/resource race tests pass, including the complete original `TestSSH` suite and the new agent-hostname round trips. `TestConfigSSH_Example` checks running two-agent and stopped one-/two-agent workspaces whose import defaults differ, with and without `--no-wildcard`. It verifies the hint has a matching generated Host entry and reuses workspace history once per stopped workspace. `TestShow` covers bare names, owner-qualified names and UUIDs; `TestCreate/CreateForOtherUser` checks the owner-qualified preview. Mutation checks confirmed the new assertions fail when the protected behavior is removed. `TestPing_AgentSuggestions` covers bare names, owner-qualified names, UUIDs and JSON-mode errors with a shared fixture. The tests fail without the new hints; an owner-omission control also fails the qualified/UUID cases. The original network-heavy `TestPing` suite remains unchanged and passes its normal race run. Normal and strict new-code Go lint, frontend checks/lint/typechecking, all eleven SSHButton stories, and docs checks pass. Browser checks verified copied SSH/CLI commands and keyboard dismissal; screenshots were visually inspected. The single-agent follow-up adds 25 command-copy cases covering ownership, agents across resources, subagents, and zero/unknown counts. All 53 affected SSHButton, AgentRow, and AgentDevcontainerCard stories pass, with browser validation of both real callers and regression/mutation controls for the command-selection guards. <details> <summary>CI follow-up and validation commands</summary> After #31192 merged, the parent commits were dropped and the remaining eleven commits were rebased onto the merge commit `fb6d287528`. Range-diff and full-tree comparisons confirm no implementation changes. Revalidated the complete SSH/ping/config race suite and strict lint after that rebase. Latest rebase preserves the implementation and carries the docs edits to main’s renamed `docs/workspaces/` paths. The SSHButton documentation links and preview URL use the new routes. Revalidated the full SSH/ping/config CLI race suite, strict lint, 25 frontend tests, 53 stories, and docs/manifest/redirect checks. The local shell’s Oh My Zsh update prompt interrupted the first race run; the unchanged suite passed with `DISABLE_AUTO_UPDATE=true` scoped to the test process. Latest review follow-up: connection commands remain undefined during initial loading, and each instruction is gated on its own command. A cached SSH suffix remains usable after a failed refetch; a story captures that state. Rebased directly onto `main` at `fb6d287528` after #31192 merged. The P2 follow-up preserves native hostnames that collide with legacy prefix blocks, uses workspace-specific history for stopped agents, and retains safe precreated devcontainer names. Earlier stress runs of the unmodified `TestSSH` suite exceeded the 6,144 MiB guard under 35-repeat stress. Its existing scenarios remain unchanged. The three added agent-qualified hostname cases have independent full SSH round-trip coverage in `TestSSH_AgentHostnames`, with a shared fixture. The current top-PR changed-test selector chooses seven tests without the unrelated `TestSSH` scenarios, and the complete selected set passes 35 repetitions at parallelism 16 with the same memory guard. No test cases, repetitions, parallelism or memory checks were removed. ```sh go test -race -tags=testsmallbatch ./cli ./cli/cliui -run '^TestSSH$|^TestSSH_AgentHostnames$|TestPing|TestConfigSSH|TestShow|TestCreate|Test_agentSSHSuggestion|Test_suggestWithOwner|TestWorkspaceResources|Test_noWildcardHostNames|Test_previousStartResources|TestCommandHelp' -count=1 -parallel=4 GOMEMLIMIT=6GiB golangci-lint run --allow-serial-runners --concurrency=4 --new-from-rev=origin/main ./cli/... GOMEMLIMIT=6GiB make lint/go/new-code GO_LINT_CONCURRENCY=4 CODER_TEST_MEMORY_LIMIT_MIB=6144 TS_DEBUG_DISCO=true TS_DEBUG_DERP=true go test -tags=testsmallbatch -p=4 -count=35 -parallel=16 -shuffle=1 -timeout=10m -run '^(TestConfigSSH_Example|TestCreate|TestPing_AgentSuggestions|TestSSH_AgentHostnames|TestShow|Test_agentSSHSuggestion|Test_suggestWithOwner)(/.*)?$' ./cli cd site pnpm check pnpm lint pnpm test src/modules/resources/SSHButton/SSHButton.test.tsx pnpm test:storybook src/modules/resources/SSHButton/SSHButton.stories.tsx src/modules/resources/AgentRow.stories.tsx src/modules/resources/AgentDevcontainerCard.stories.tsx --run ``` </details> Follow-up to #19943. Tracks [CLI-67](https://linear.app/codercom/issue/CLI-67/fix-coder-ssh-suggestions-for-multi-agent-workspaces). Preview: https://coder.com/docs/@fix%2Fssh-multi-agent-hint/workspaces/workspace-access > 🤖 This PR was created with the help of Coder Agents, and has been reviewed by my human. 🧑💻
498 lines
18 KiB
Go
498 lines
18 KiB
Go
package cli_test
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/v2/agent/agentcontainers"
|
|
"github.com/coder/coder/v2/cli/clitest"
|
|
"github.com/coder/coder/v2/cli/cliui"
|
|
"github.com/coder/coder/v2/coderd/coderdtest"
|
|
"github.com/coder/coder/v2/codersdk"
|
|
"github.com/coder/coder/v2/testutil"
|
|
"github.com/coder/coder/v2/testutil/expecter"
|
|
)
|
|
|
|
func TestShow(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("Exists", func(t *testing.T) {
|
|
t.Parallel()
|
|
logger := testutil.Logger(t)
|
|
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
|
|
owner := coderdtest.CreateFirstUser(t, client)
|
|
member, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
|
|
version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, completeWithAgent())
|
|
coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
|
|
template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID)
|
|
workspace := coderdtest.CreateWorkspace(t, member, template.ID)
|
|
build := coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
|
|
|
|
for _, tc := range []struct {
|
|
name string
|
|
identifier string
|
|
wantSSH string
|
|
}{
|
|
{
|
|
name: "Name",
|
|
identifier: workspace.Name,
|
|
wantSSH: "coder ssh " + workspace.Name,
|
|
},
|
|
{
|
|
name: "OwnerAndName",
|
|
identifier: workspace.OwnerName + "/" + workspace.Name,
|
|
wantSSH: "coder ssh " + workspace.OwnerName + "/" + workspace.Name,
|
|
},
|
|
{
|
|
name: "UUID",
|
|
identifier: workspace.ID.String(),
|
|
wantSSH: "coder ssh " + workspace.OwnerName + "/" + workspace.Name,
|
|
},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
inv, root := clitest.New(t, "show", tc.identifier)
|
|
clitest.SetupConfig(t, member, root)
|
|
doneChan := make(chan struct{})
|
|
stdout := expecter.NewAttachedToInvocation(t, inv)
|
|
stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv)
|
|
ctx := testutil.Context(t, testutil.WaitShort)
|
|
go func() {
|
|
defer close(doneChan)
|
|
err := inv.WithContext(ctx).Run()
|
|
assert.NoError(t, err)
|
|
}()
|
|
matches := []struct {
|
|
match string
|
|
write string
|
|
}{
|
|
{match: fmt.Sprintf("%s/%s", workspace.OwnerName, workspace.Name)},
|
|
{match: fmt.Sprintf("(%s since ", build.Status)},
|
|
{match: fmt.Sprintf("%s:%s", workspace.TemplateName, workspace.LatestBuild.TemplateVersionName)},
|
|
{match: "compute.main"},
|
|
{match: "smith (linux, i386)"},
|
|
{match: tc.wantSSH},
|
|
}
|
|
for _, m := range matches {
|
|
stdout.ExpectMatch(ctx, m.match)
|
|
if len(m.write) > 0 {
|
|
stdin.WriteLine(m.write)
|
|
}
|
|
}
|
|
_ = testutil.TryReceive(ctx, t, doneChan)
|
|
})
|
|
}
|
|
})
|
|
|
|
// Regression test: workspace names that are valid dashless UUIDs
|
|
// (32 hex chars) should be looked up by name, not parsed as a
|
|
// UUID and fetched by ID (which 404s).
|
|
t.Run("WorkspaceWithUUIDLikeName", func(t *testing.T) {
|
|
t.Parallel()
|
|
logger := testutil.Logger(t)
|
|
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
|
|
owner := coderdtest.CreateFirstUser(t, client)
|
|
member, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
|
|
version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, completeWithAgent())
|
|
coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
|
|
template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID)
|
|
|
|
// This name is a valid 32-char hex string (dashless UUID).
|
|
const wsName = "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6"
|
|
workspace := coderdtest.CreateWorkspace(t, member, template.ID, func(cwr *codersdk.CreateWorkspaceRequest) {
|
|
cwr.Name = wsName
|
|
})
|
|
build := coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
|
|
|
|
args := []string{
|
|
"show",
|
|
wsName,
|
|
}
|
|
inv, root := clitest.New(t, args...)
|
|
clitest.SetupConfig(t, member, root)
|
|
doneChan := make(chan struct{})
|
|
stdout := expecter.NewAttachedToInvocation(t, inv)
|
|
stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv)
|
|
ctx := testutil.Context(t, testutil.WaitShort)
|
|
go func() {
|
|
defer close(doneChan)
|
|
err := inv.WithContext(ctx).Run()
|
|
assert.NoError(t, err)
|
|
}()
|
|
matches := []struct {
|
|
match string
|
|
write string
|
|
}{
|
|
{match: fmt.Sprintf("%s/%s", workspace.OwnerName, workspace.Name)},
|
|
{match: fmt.Sprintf("(%s since ", build.Status)},
|
|
{match: fmt.Sprintf("%s:%s", workspace.TemplateName, workspace.LatestBuild.TemplateVersionName)},
|
|
{match: "compute.main"},
|
|
{match: "smith (linux, i386)"},
|
|
{match: "coder ssh " + workspace.Name},
|
|
}
|
|
for _, m := range matches {
|
|
stdout.ExpectMatch(ctx, m.match)
|
|
if len(m.write) > 0 {
|
|
stdin.WriteLine(m.write)
|
|
}
|
|
}
|
|
_ = testutil.TryReceive(ctx, t, doneChan)
|
|
})
|
|
}
|
|
|
|
func TestShowDevcontainers_Golden(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
mainAgentID := uuid.MustParse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")
|
|
agentID := mainAgentID
|
|
|
|
testCases := []struct {
|
|
name string
|
|
showDetails bool
|
|
devcontainers []codersdk.WorkspaceAgentDevcontainer
|
|
listeningPorts map[uuid.UUID]codersdk.WorkspaceAgentListeningPortsResponse
|
|
}{
|
|
{
|
|
name: "running_devcontainer_with_agent",
|
|
devcontainers: []codersdk.WorkspaceAgentDevcontainer{
|
|
{
|
|
ID: uuid.MustParse("11111111-1111-1111-1111-111111111111"),
|
|
Name: "web-dev",
|
|
WorkspaceFolder: "/workspaces/web-dev",
|
|
ConfigPath: "/workspaces/web-dev/.devcontainer/devcontainer.json",
|
|
Status: codersdk.WorkspaceAgentDevcontainerStatusRunning,
|
|
Dirty: false,
|
|
Container: &codersdk.WorkspaceAgentContainer{
|
|
ID: "container-web-dev",
|
|
FriendlyName: "quirky_lovelace",
|
|
Image: "mcr.microsoft.com/devcontainers/typescript-node:1.0.0",
|
|
Running: true,
|
|
Status: "running",
|
|
CreatedAt: time.Now().Add(-1 * time.Hour),
|
|
Labels: map[string]string{
|
|
agentcontainers.DevcontainerConfigFileLabel: "/workspaces/web-dev/.devcontainer/devcontainer.json",
|
|
agentcontainers.DevcontainerLocalFolderLabel: "/workspaces/web-dev",
|
|
},
|
|
},
|
|
Agent: &codersdk.WorkspaceAgentDevcontainerAgent{
|
|
ID: uuid.MustParse("22222222-2222-2222-2222-222222222222"),
|
|
Name: "web-dev",
|
|
Directory: "/workspaces/web-dev",
|
|
},
|
|
},
|
|
},
|
|
listeningPorts: map[uuid.UUID]codersdk.WorkspaceAgentListeningPortsResponse{
|
|
uuid.MustParse("22222222-2222-2222-2222-222222222222"): {
|
|
Ports: []codersdk.WorkspaceAgentListeningPort{
|
|
{
|
|
ProcessName: "node",
|
|
Network: "tcp",
|
|
Port: 3000,
|
|
},
|
|
{
|
|
ProcessName: "webpack-dev-server",
|
|
Network: "tcp",
|
|
Port: 8080,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "running_devcontainer_without_agent",
|
|
devcontainers: []codersdk.WorkspaceAgentDevcontainer{
|
|
{
|
|
ID: uuid.MustParse("33333333-3333-3333-3333-333333333333"),
|
|
Name: "web-server",
|
|
WorkspaceFolder: "/workspaces/web-server",
|
|
ConfigPath: "/workspaces/web-server/.devcontainer/devcontainer.json",
|
|
Status: codersdk.WorkspaceAgentDevcontainerStatusRunning,
|
|
Dirty: false,
|
|
Container: &codersdk.WorkspaceAgentContainer{
|
|
ID: "container-web-server",
|
|
FriendlyName: "amazing_turing",
|
|
Image: "nginx:latest",
|
|
Running: true,
|
|
Status: "running",
|
|
CreatedAt: time.Now().Add(-30 * time.Minute),
|
|
Labels: map[string]string{
|
|
agentcontainers.DevcontainerConfigFileLabel: "/workspaces/web-server/.devcontainer/devcontainer.json",
|
|
agentcontainers.DevcontainerLocalFolderLabel: "/workspaces/web-server",
|
|
},
|
|
},
|
|
Agent: nil, // No agent for this running container.
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "stopped_devcontainer",
|
|
devcontainers: []codersdk.WorkspaceAgentDevcontainer{
|
|
{
|
|
ID: uuid.MustParse("44444444-4444-4444-4444-444444444444"),
|
|
Name: "api-dev",
|
|
WorkspaceFolder: "/workspaces/api-dev",
|
|
ConfigPath: "/workspaces/api-dev/.devcontainer/devcontainer.json",
|
|
Status: codersdk.WorkspaceAgentDevcontainerStatusStopped,
|
|
Dirty: false,
|
|
Container: &codersdk.WorkspaceAgentContainer{
|
|
ID: "container-api-dev",
|
|
FriendlyName: "clever_darwin",
|
|
Image: "mcr.microsoft.com/devcontainers/go:1.0.0",
|
|
Running: false,
|
|
Status: "exited",
|
|
CreatedAt: time.Now().Add(-2 * time.Hour),
|
|
Labels: map[string]string{
|
|
agentcontainers.DevcontainerConfigFileLabel: "/workspaces/api-dev/.devcontainer/devcontainer.json",
|
|
agentcontainers.DevcontainerLocalFolderLabel: "/workspaces/api-dev",
|
|
},
|
|
},
|
|
Agent: nil, // No agent for stopped container.
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "starting_devcontainer",
|
|
devcontainers: []codersdk.WorkspaceAgentDevcontainer{
|
|
{
|
|
ID: uuid.MustParse("55555555-5555-5555-5555-555555555555"),
|
|
Name: "database-dev",
|
|
WorkspaceFolder: "/workspaces/database-dev",
|
|
ConfigPath: "/workspaces/database-dev/.devcontainer/devcontainer.json",
|
|
Status: codersdk.WorkspaceAgentDevcontainerStatusStarting,
|
|
Dirty: false,
|
|
Container: &codersdk.WorkspaceAgentContainer{
|
|
ID: "container-database-dev",
|
|
FriendlyName: "nostalgic_hawking",
|
|
Image: "mcr.microsoft.com/devcontainers/postgres:1.0.0",
|
|
Running: false,
|
|
Status: "created",
|
|
CreatedAt: time.Now().Add(-5 * time.Minute),
|
|
Labels: map[string]string{
|
|
agentcontainers.DevcontainerConfigFileLabel: "/workspaces/database-dev/.devcontainer/devcontainer.json",
|
|
agentcontainers.DevcontainerLocalFolderLabel: "/workspaces/database-dev",
|
|
},
|
|
},
|
|
Agent: nil, // No agent yet while starting.
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "error_devcontainer",
|
|
devcontainers: []codersdk.WorkspaceAgentDevcontainer{
|
|
{
|
|
ID: uuid.MustParse("66666666-6666-6666-6666-666666666666"),
|
|
Name: "failed-dev",
|
|
WorkspaceFolder: "/workspaces/failed-dev",
|
|
ConfigPath: "/workspaces/failed-dev/.devcontainer/devcontainer.json",
|
|
Status: codersdk.WorkspaceAgentDevcontainerStatusError,
|
|
Dirty: false,
|
|
Error: "Failed to pull image mcr.microsoft.com/devcontainers/go:latest: timeout after 5m0s",
|
|
Container: nil, // No container due to error.
|
|
Agent: nil, // No agent due to error.
|
|
},
|
|
},
|
|
},
|
|
|
|
{
|
|
name: "mixed_devcontainer_states",
|
|
devcontainers: []codersdk.WorkspaceAgentDevcontainer{
|
|
{
|
|
ID: uuid.MustParse("88888888-8888-8888-8888-888888888888"),
|
|
Name: "frontend",
|
|
WorkspaceFolder: "/workspaces/frontend",
|
|
Status: codersdk.WorkspaceAgentDevcontainerStatusRunning,
|
|
Container: &codersdk.WorkspaceAgentContainer{
|
|
ID: "container-frontend",
|
|
FriendlyName: "vibrant_tesla",
|
|
Image: "node:18",
|
|
Running: true,
|
|
Status: "running",
|
|
CreatedAt: time.Now().Add(-30 * time.Minute),
|
|
},
|
|
Agent: &codersdk.WorkspaceAgentDevcontainerAgent{
|
|
ID: uuid.MustParse("99999999-9999-9999-9999-999999999999"),
|
|
Name: "frontend",
|
|
Directory: "/workspaces/frontend",
|
|
},
|
|
},
|
|
{
|
|
ID: uuid.MustParse("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"),
|
|
Name: "backend",
|
|
WorkspaceFolder: "/workspaces/backend",
|
|
Status: codersdk.WorkspaceAgentDevcontainerStatusStopped,
|
|
Container: &codersdk.WorkspaceAgentContainer{
|
|
ID: "container-backend",
|
|
FriendlyName: "peaceful_curie",
|
|
Image: "python:3.11",
|
|
Running: false,
|
|
Status: "exited",
|
|
CreatedAt: time.Now().Add(-1 * time.Hour),
|
|
},
|
|
Agent: nil,
|
|
},
|
|
{
|
|
ID: uuid.MustParse("bbbbbbbb-cccc-dddd-eeee-ffffffffffff"),
|
|
Name: "error-container",
|
|
WorkspaceFolder: "/workspaces/error-container",
|
|
Status: codersdk.WorkspaceAgentDevcontainerStatusError,
|
|
Error: "Container build failed: dockerfile syntax error on line 15",
|
|
Container: nil,
|
|
Agent: nil,
|
|
},
|
|
},
|
|
listeningPorts: map[uuid.UUID]codersdk.WorkspaceAgentListeningPortsResponse{
|
|
uuid.MustParse("99999999-9999-9999-9999-999999999999"): {
|
|
Ports: []codersdk.WorkspaceAgentListeningPort{
|
|
{
|
|
ProcessName: "vite",
|
|
Network: "tcp",
|
|
Port: 5173,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "running_devcontainer_with_agent_and_error",
|
|
devcontainers: []codersdk.WorkspaceAgentDevcontainer{
|
|
{
|
|
ID: uuid.MustParse("cccccccc-dddd-eeee-ffff-000000000000"),
|
|
Name: "problematic-dev",
|
|
WorkspaceFolder: "/workspaces/problematic-dev",
|
|
ConfigPath: "/workspaces/problematic-dev/.devcontainer/devcontainer.json",
|
|
Status: codersdk.WorkspaceAgentDevcontainerStatusRunning,
|
|
Dirty: false,
|
|
Error: "Warning: Container started but healthcheck failed",
|
|
Container: &codersdk.WorkspaceAgentContainer{
|
|
ID: "container-problematic",
|
|
FriendlyName: "cranky_mendel",
|
|
Image: "mcr.microsoft.com/devcontainers/python:1.0.0",
|
|
Running: true,
|
|
Status: "running",
|
|
CreatedAt: time.Now().Add(-15 * time.Minute),
|
|
Labels: map[string]string{
|
|
agentcontainers.DevcontainerConfigFileLabel: "/workspaces/problematic-dev/.devcontainer/devcontainer.json",
|
|
agentcontainers.DevcontainerLocalFolderLabel: "/workspaces/problematic-dev",
|
|
},
|
|
},
|
|
Agent: &codersdk.WorkspaceAgentDevcontainerAgent{
|
|
ID: uuid.MustParse("dddddddd-eeee-ffff-aaaa-111111111111"),
|
|
Name: "problematic-dev",
|
|
Directory: "/workspaces/problematic-dev",
|
|
},
|
|
},
|
|
},
|
|
listeningPorts: map[uuid.UUID]codersdk.WorkspaceAgentListeningPortsResponse{
|
|
uuid.MustParse("dddddddd-eeee-ffff-aaaa-111111111111"): {
|
|
Ports: []codersdk.WorkspaceAgentListeningPort{
|
|
{
|
|
ProcessName: "python",
|
|
Network: "tcp",
|
|
Port: 8000,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "long_error_message",
|
|
devcontainers: []codersdk.WorkspaceAgentDevcontainer{
|
|
{
|
|
ID: uuid.MustParse("eeeeeeee-ffff-0000-1111-222222222222"),
|
|
Name: "long-error-dev",
|
|
WorkspaceFolder: "/workspaces/long-error-dev",
|
|
ConfigPath: "/workspaces/long-error-dev/.devcontainer/devcontainer.json",
|
|
Status: codersdk.WorkspaceAgentDevcontainerStatusError,
|
|
Dirty: false,
|
|
Error: "Failed to build devcontainer: dockerfile parse error at line 25: unknown instruction 'INSTALL', did you mean 'RUN apt-get install'? This is a very long error message that should be truncated when detail flag is not used",
|
|
Container: nil,
|
|
Agent: nil,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "long_error_message_with_detail",
|
|
showDetails: true,
|
|
devcontainers: []codersdk.WorkspaceAgentDevcontainer{
|
|
{
|
|
ID: uuid.MustParse("eeeeeeee-ffff-0000-1111-222222222222"),
|
|
Name: "long-error-dev",
|
|
WorkspaceFolder: "/workspaces/long-error-dev",
|
|
ConfigPath: "/workspaces/long-error-dev/.devcontainer/devcontainer.json",
|
|
Status: codersdk.WorkspaceAgentDevcontainerStatusError,
|
|
Dirty: false,
|
|
Error: "Failed to build devcontainer: dockerfile parse error at line 25: unknown instruction 'INSTALL', did you mean 'RUN apt-get install'? This is a very long error message that should be truncated when detail flag is not used",
|
|
Container: nil,
|
|
Agent: nil,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
tc := tc
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var allAgents []codersdk.WorkspaceAgent
|
|
mainAgent := codersdk.WorkspaceAgent{
|
|
ID: mainAgentID,
|
|
Name: "main",
|
|
OperatingSystem: "linux",
|
|
Architecture: "amd64",
|
|
Status: codersdk.WorkspaceAgentConnected,
|
|
Health: codersdk.WorkspaceAgentHealth{Healthy: true},
|
|
Version: "v2.15.0",
|
|
}
|
|
allAgents = append(allAgents, mainAgent)
|
|
|
|
for _, dc := range tc.devcontainers {
|
|
if dc.Agent != nil {
|
|
devcontainerAgent := codersdk.WorkspaceAgent{
|
|
ID: dc.Agent.ID,
|
|
ParentID: uuid.NullUUID{UUID: mainAgentID, Valid: true},
|
|
Name: dc.Agent.Name,
|
|
OperatingSystem: "linux",
|
|
Architecture: "amd64",
|
|
Status: codersdk.WorkspaceAgentConnected,
|
|
Health: codersdk.WorkspaceAgentHealth{Healthy: true},
|
|
Version: "v2.15.0",
|
|
}
|
|
allAgents = append(allAgents, devcontainerAgent)
|
|
}
|
|
}
|
|
|
|
resources := []codersdk.WorkspaceResource{
|
|
{
|
|
Type: "compute",
|
|
Name: "main",
|
|
Agents: allAgents,
|
|
},
|
|
}
|
|
options := cliui.WorkspaceResourcesOptions{
|
|
WorkspaceName: "test-workspace",
|
|
ServerVersion: "v2.15.0",
|
|
ShowDetails: tc.showDetails,
|
|
Devcontainers: map[uuid.UUID]codersdk.WorkspaceAgentListContainersResponse{
|
|
agentID: {
|
|
Devcontainers: tc.devcontainers,
|
|
},
|
|
},
|
|
ListeningPorts: tc.listeningPorts,
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
err := cliui.WorkspaceResources(&buf, resources, options)
|
|
require.NoError(t, err)
|
|
|
|
replacements := map[string]string{}
|
|
clitest.TestGoldenFile(t, "TestShowDevcontainers_Golden/"+tc.name, buf.Bytes(), replacements)
|
|
})
|
|
}
|
|
}
|