Skip to content

Commit 17115e5

Browse files
committed
carry --server-url over to the printed --view command on simulate exit
1 parent ece95b9 commit 17115e5

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

cmd/lk/simulate.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,17 @@ func dashboardBaseURL() string {
559559
return dashboardURL
560560
}
561561

562+
// viewCommandHint returns the command to re-open a simulation run, carrying
563+
// over --server-url when the run lives somewhere other than the default cloud
564+
// API (e.g. staging), so the printed command targets the same environment.
565+
func viewCommandHint(runID string) string {
566+
hint := "lk agent simulate --view " + runID
567+
if serverURL != cloudAPIServerURL {
568+
hint += " --server-url " + serverURL
569+
}
570+
return hint
571+
}
572+
562573
func simulationDashboardURL(projectID, runID string) string {
563574
if projectID == "" || runID == "" {
564575
return ""

cmd/lk/simulate_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
// A user finishing a simulation is told how to re-open it with --view. If they
10+
// pointed the original command at a non-default API server (e.g. staging), the
11+
// suggested command must carry the same --server-url or it would look up the
12+
// run in the wrong environment.
13+
func TestViewCommandHint(t *testing.T) {
14+
origServerURL := serverURL
15+
t.Cleanup(func() { serverURL = origServerURL })
16+
17+
t.Run("omits server-url when using the default cloud API", func(t *testing.T) {
18+
serverURL = cloudAPIServerURL
19+
assert.Equal(t, "lk agent simulate --view SR_abc123", viewCommandHint("SR_abc123"))
20+
})
21+
22+
t.Run("carries over a custom server-url", func(t *testing.T) {
23+
serverURL = "https://cloud-api.staging.livekit.io"
24+
assert.Equal(t,
25+
"lk agent simulate --view SR_abc123 --server-url https://cloud-api.staging.livekit.io",
26+
viewCommandHint("SR_abc123"))
27+
})
28+
}

cmd/lk/simulate_tui.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ func runSimulateTUI(config *simulateConfig) error {
8080
}
8181

8282
if m.config.mode == modeView {
83-
fmt.Fprintf(os.Stderr, "To re-open this simulation, run: lk agent simulate --view %s\n", m.config.viewModeRunID)
83+
fmt.Fprintf(os.Stderr, "To re-open this simulation, run: %s\n", viewCommandHint(m.config.viewModeRunID))
8484
} else if m.runID != "" && !m.runFinished {
8585
cancelSimulationRun(config.client, m.runID)
8686
} else if m.runID != "" {
87-
fmt.Fprintf(os.Stderr, "To re-open this simulation, run: lk agent simulate --view %s\n", m.runID)
87+
fmt.Fprintf(os.Stderr, "To re-open this simulation, run: %s\n", viewCommandHint(m.runID))
8888
}
8989

9090
if runErr != nil {

0 commit comments

Comments
 (0)