Skip to content

Commit c429020

Browse files
authored
fix(enterprise): update external agent instructions in cli (#19411)
### Description The command for agent instructions was incorrectly displayed in the CLI.
1 parent d79a779 commit c429020

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

enterprise/cli/externalworkspaces.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,14 @@ func fetchExternalAgents(inv *serpent.Invocation, client *codersdk.Client, works
243243
// formatExternalAgent formats the instructions for an external agent.
244244
func formatExternalAgent(workspaceName string, externalAgents []externalAgent) string {
245245
var output strings.Builder
246-
_, _ = output.WriteString(fmt.Sprintf("\nPlease run the following commands to attach external agent to the workspace %s:\n\n", cliui.Keyword(workspaceName)))
246+
_, _ = output.WriteString(fmt.Sprintf("\nPlease run the following command to attach external agent to the workspace %s:\n\n", cliui.Keyword(workspaceName)))
247247

248248
for i, agent := range externalAgents {
249249
if len(externalAgents) > 1 {
250250
_, _ = output.WriteString(fmt.Sprintf("For agent %s:\n", cliui.Keyword(agent.AgentName)))
251251
}
252252

253-
_, _ = output.WriteString(fmt.Sprintf("%s\n", pretty.Sprint(cliui.DefaultStyles.Code, fmt.Sprintf("export CODER_AGENT_TOKEN=%s", agent.AuthToken))))
254-
_, _ = output.WriteString(fmt.Sprintf("%s\n", pretty.Sprint(cliui.DefaultStyles.Code, fmt.Sprintf("curl -fsSL %s | sh", agent.InitScript))))
253+
_, _ = output.WriteString(fmt.Sprintf("%s\n", pretty.Sprint(cliui.DefaultStyles.Code, agent.InitScript)))
255254

256255
if i < len(externalAgents)-1 {
257256
_, _ = output.WriteString("\n")

enterprise/cli/externalworkspaces_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ func TestExternalWorkspaces(t *testing.T) {
162162
pty.WriteLine("yes")
163163

164164
// Expect the external agent instructions
165-
pty.ExpectMatch("Please run the following commands to attach external agent")
166-
pty.ExpectMatch("export CODER_AGENT_TOKEN=")
167-
pty.ExpectMatch("curl -fsSL")
165+
pty.ExpectMatch("Please run the following command to attach external agent")
166+
pty.ExpectRegexMatch("curl -fsSL .* | CODER_AGENT_TOKEN=.* sh")
168167

169-
<-doneChan
168+
ctx := testutil.Context(t, testutil.WaitLong)
169+
testutil.TryReceive(ctx, t, doneChan)
170170

171171
// Verify the workspace was created
172172
ws, err := member.WorkspaceByOwnerAndName(context.Background(), codersdk.Me, "my-external-workspace", codersdk.WorkspaceOptions{})
@@ -392,11 +392,12 @@ func TestExternalWorkspaces(t *testing.T) {
392392
assert.NoError(t, errC)
393393
close(done)
394394
}()
395-
pty.ExpectMatch("Please run the following commands to attach external agent to the workspace")
396-
pty.ExpectMatch("export CODER_AGENT_TOKEN=")
397-
pty.ExpectMatch("curl -fsSL")
395+
pty.ExpectMatch("Please run the following command to attach external agent to the workspace")
396+
pty.ExpectRegexMatch("curl -fsSL .* | CODER_AGENT_TOKEN=.* sh")
398397
cancelFunc()
399-
<-done
398+
399+
ctx = testutil.Context(t, testutil.WaitLong)
400+
testutil.TryReceive(ctx, t, done)
400401
})
401402

402403
t.Run("AgentInstructionsJSON", func(t *testing.T) {
@@ -545,11 +546,11 @@ func TestExternalWorkspaces(t *testing.T) {
545546
pty.ExpectMatch("external-agent (linux, amd64)")
546547

547548
// Expect the external agent instructions
548-
pty.ExpectMatch("Please run the following commands to attach external agent")
549-
pty.ExpectMatch("export CODER_AGENT_TOKEN=")
550-
pty.ExpectMatch("curl -fsSL")
549+
pty.ExpectMatch("Please run the following command to attach external agent")
550+
pty.ExpectRegexMatch("curl -fsSL .* | CODER_AGENT_TOKEN=.* sh")
551551

552-
<-doneChan
552+
ctx := testutil.Context(t, testutil.WaitLong)
553+
testutil.TryReceive(ctx, t, doneChan)
553554

554555
// Verify the workspace was created
555556
ws, err := member.WorkspaceByOwnerAndName(context.Background(), codersdk.Me, "my-external-workspace", codersdk.WorkspaceOptions{})

0 commit comments

Comments
 (0)