Skip to content

Commit 5dce3ef

Browse files
committed
fix(simulate): carry --project into the re-open hint
1 parent 0dc4724 commit 5dce3ef

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎cmd/lk/simulate.go‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ func init() {
4747

4848
var (
4949
simulateProjectConfig *config.ProjectConfig
50+
// simulateProjectFlag is the explicit --project name, if any; the hints must
51+
// reproduce it or a re-open resolves against a different project.
52+
simulateProjectFlag string
5053
)
5154

5255
const (
@@ -68,6 +71,7 @@ var simulateCommand = &cli.Command{
6871
return nil, err
6972
}
7073
simulateProjectConfig = pc
74+
simulateProjectFlag = cmd.String("project")
7175
return nil, nil
7276
},
7377
Action: runSimulate,
@@ -582,8 +586,9 @@ func dashboardBaseURL() string {
582586
}
583587

584588
// viewCommandHint returns the command to re-open a simulation run, carrying
585-
// over --server-url when the run lives somewhere other than the default cloud
586-
// API (e.g. staging), so the printed command targets the same environment.
589+
// over --project and --server-url when the run lives somewhere other than the
590+
// default project and cloud API (e.g. staging), so the printed command targets
591+
// the same project and environment.
587592
// The binary name comes from argv[0] so a renamed or path-qualified lk is
588593
// reproduced verbatim.
589594
func viewCommandHint(runID string) string {
@@ -592,6 +597,9 @@ func viewCommandHint(runID string) string {
592597
binary = os.Args[0]
593598
}
594599
hint := binary + " agent simulate --view " + runID
600+
if simulateProjectFlag != "" {
601+
hint += " --project " + simulateProjectFlag
602+
}
595603
if serverURL != cloudAPIServerURL {
596604
hint += " --server-url " + serverURL
597605
}

‎cmd/lk/simulate_test.go‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,27 @@ func TestViewCommandHintCarriesServerURL(t *testing.T) {
7676
"lk agent simulate --view run_123 --server-url https://cloud-api.staging.livekit.io",
7777
viewCommandHint("run_123"))
7878
}
79+
80+
func TestViewCommandHintCarriesProject(t *testing.T) {
81+
origArgs := os.Args
82+
origServerURL := serverURL
83+
origProject := simulateProjectFlag
84+
t.Cleanup(func() {
85+
os.Args = origArgs
86+
serverURL = origServerURL
87+
simulateProjectFlag = origProject
88+
})
89+
os.Args = []string{"lk"}
90+
serverURL = "https://cloud-api.example.com"
91+
simulateProjectFlag = "my-project"
92+
93+
require.Equal(t,
94+
"lk agent simulate --view run_123 --project my-project"+
95+
" --server-url https://cloud-api.example.com",
96+
viewCommandHint("run_123"))
97+
98+
simulateProjectFlag = ""
99+
require.Equal(t,
100+
"lk agent simulate --view run_123 --server-url https://cloud-api.example.com",
101+
viewCommandHint("run_123"))
102+
}

0 commit comments

Comments
 (0)