fix(enterprise): update external agent instructions in cli (#19411)

### Description

The command for agent instructions was incorrectly displayed in the CLI.
This commit is contained in:
Kacper Sawicki
2025-08-19 13:54:42 +00:00
committed by GitHub
parent d79a7797c2
commit c4290201c3
2 changed files with 15 additions and 15 deletions
+2 -3
View File
@@ -243,15 +243,14 @@ func fetchExternalAgents(inv *serpent.Invocation, client *codersdk.Client, works
// formatExternalAgent formats the instructions for an external agent.
func formatExternalAgent(workspaceName string, externalAgents []externalAgent) string {
var output strings.Builder
_, _ = output.WriteString(fmt.Sprintf("\nPlease run the following commands to attach external agent to the workspace %s:\n\n", cliui.Keyword(workspaceName)))
_, _ = output.WriteString(fmt.Sprintf("\nPlease run the following command to attach external agent to the workspace %s:\n\n", cliui.Keyword(workspaceName)))
for i, agent := range externalAgents {
if len(externalAgents) > 1 {
_, _ = output.WriteString(fmt.Sprintf("For agent %s:\n", cliui.Keyword(agent.AgentName)))
}
_, _ = output.WriteString(fmt.Sprintf("%s\n", pretty.Sprint(cliui.DefaultStyles.Code, fmt.Sprintf("export CODER_AGENT_TOKEN=%s", agent.AuthToken))))
_, _ = output.WriteString(fmt.Sprintf("%s\n", pretty.Sprint(cliui.DefaultStyles.Code, fmt.Sprintf("curl -fsSL %s | sh", agent.InitScript))))
_, _ = output.WriteString(fmt.Sprintf("%s\n", pretty.Sprint(cliui.DefaultStyles.Code, agent.InitScript)))
if i < len(externalAgents)-1 {
_, _ = output.WriteString("\n")
+13 -12
View File
@@ -162,11 +162,11 @@ func TestExternalWorkspaces(t *testing.T) {
pty.WriteLine("yes")
// Expect the external agent instructions
pty.ExpectMatch("Please run the following commands to attach external agent")
pty.ExpectMatch("export CODER_AGENT_TOKEN=")
pty.ExpectMatch("curl -fsSL")
pty.ExpectMatch("Please run the following command to attach external agent")
pty.ExpectRegexMatch("curl -fsSL .* | CODER_AGENT_TOKEN=.* sh")
<-doneChan
ctx := testutil.Context(t, testutil.WaitLong)
testutil.TryReceive(ctx, t, doneChan)
// Verify the workspace was created
ws, err := member.WorkspaceByOwnerAndName(context.Background(), codersdk.Me, "my-external-workspace", codersdk.WorkspaceOptions{})
@@ -392,11 +392,12 @@ func TestExternalWorkspaces(t *testing.T) {
assert.NoError(t, errC)
close(done)
}()
pty.ExpectMatch("Please run the following commands to attach external agent to the workspace")
pty.ExpectMatch("export CODER_AGENT_TOKEN=")
pty.ExpectMatch("curl -fsSL")
pty.ExpectMatch("Please run the following command to attach external agent to the workspace")
pty.ExpectRegexMatch("curl -fsSL .* | CODER_AGENT_TOKEN=.* sh")
cancelFunc()
<-done
ctx = testutil.Context(t, testutil.WaitLong)
testutil.TryReceive(ctx, t, done)
})
t.Run("AgentInstructionsJSON", func(t *testing.T) {
@@ -545,11 +546,11 @@ func TestExternalWorkspaces(t *testing.T) {
pty.ExpectMatch("external-agent (linux, amd64)")
// Expect the external agent instructions
pty.ExpectMatch("Please run the following commands to attach external agent")
pty.ExpectMatch("export CODER_AGENT_TOKEN=")
pty.ExpectMatch("curl -fsSL")
pty.ExpectMatch("Please run the following command to attach external agent")
pty.ExpectRegexMatch("curl -fsSL .* | CODER_AGENT_TOKEN=.* sh")
<-doneChan
ctx := testutil.Context(t, testutil.WaitLong)
testutil.TryReceive(ctx, t, doneChan)
// Verify the workspace was created
ws, err := member.WorkspaceByOwnerAndName(context.Background(), codersdk.Me, "my-external-workspace", codersdk.WorkspaceOptions{})