From 2577456d033b0029bee7f7b070e4c30871b206d6 Mon Sep 17 00:00:00 2001 From: gavin mcdonough Date: Wed, 17 Jun 2026 13:11:35 -0400 Subject: [PATCH] fix(agent): register --id flag on `agent deploy` deployAgent resolves the agent via getAgentID, which reads cmd.String("id"), but the deploy subcommand never registered the --id flag (unlike config, status, restart, rollback). As a result `lk agent deploy --id CA_XXX` failed at parse time with "flag provided but not defined: --id". Add idFlag(false) to the deploy command's flags, matching the other subcommands. Fixes #830 --- autocomplete/fish_autocomplete | 1 + cmd/lk/agent.go | 1 + cmd/lk/agent_test.go | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/autocomplete/fish_autocomplete b/autocomplete/fish_autocomplete index 327bb34ce..3648cc616 100644 --- a/autocomplete/fish_autocomplete +++ b/autocomplete/fish_autocomplete @@ -81,6 +81,7 @@ complete -c lk -n '__fish_seen_subcommand_from agent a; and __fish_seen_subcomma complete -c lk -n '__fish_seen_subcommand_from agent a; and __fish_seen_subcommand_from config' -f -l help -s h -d 'show help' complete -x -c lk -n '__fish_seen_subcommand_from agent a; and __fish_seen_subcommand_from config; and not __fish_seen_subcommand_from help h' -a 'help' -d 'Shows a list of commands or help for one command' complete -x -c lk -n '__fish_seen_subcommand_from agent a; and not __fish_seen_subcommand_from init create dockerfile config deploy promote status update restart rollback logs tail delete destroy versions list secrets update-secrets private-link start dev console daemon simulate help h' -a 'deploy' -d 'Deploy a new version of the agent' +complete -c lk -n '__fish_seen_subcommand_from agent a; and __fish_seen_subcommand_from deploy' -f -l id -r -d '`ID` of the agent. If unset, and the livekit.toml file is present, will use the id found there.' complete -c lk -n '__fish_seen_subcommand_from agent a; and __fish_seen_subcommand_from deploy' -f -l attributes -r -d '`JSON` literal or file path containing an object of string key-value pairs. Use "-" to read from stdin.' complete -c lk -n '__fish_seen_subcommand_from agent a; and __fish_seen_subcommand_from deploy' -f -l attribute -r -d '`KEY=VALUE` attribute pair, may be repeated. Merged with --attributes, taking precedence on conflicting keys.' complete -c lk -n '__fish_seen_subcommand_from agent a; and __fish_seen_subcommand_from deploy' -f -l secrets -r -d 'KEY=VALUE comma separated secrets. These will be injected as environment variables into the agent. These take precedence over secrets-file.' diff --git a/cmd/lk/agent.go b/cmd/lk/agent.go index 6c64f7397..9b1368479 100644 --- a/cmd/lk/agent.go +++ b/cmd/lk/agent.go @@ -243,6 +243,7 @@ var ( Before: createAgentClient, Action: deployAgent, Flags: []cli.Flag{ + idFlag(false), attributesFlag, attributeFlag, secretsFlag, diff --git a/cmd/lk/agent_test.go b/cmd/lk/agent_test.go index 1bfe40cdc..88c1a4f4e 100644 --- a/cmd/lk/agent_test.go +++ b/cmd/lk/agent_test.go @@ -602,3 +602,21 @@ func TestResolveAttributes(t *testing.T) { }) } } + +// TestAgentDeployRegistersIDFlag is a regression test for #830: `lk agent deploy` +// resolves the agent via getAgentID, which reads cmd.String("id"). The deploy +// subcommand must therefore register the --id flag; it previously omitted it, so +// `lk agent deploy --id ...` failed at flag-parse time with "flag provided but not defined". +func TestAgentDeployRegistersIDFlag(t *testing.T) { + agentCmd := findCommandByName(AgentCommands, "agent") + require.NotNil(t, agentCmd, "top-level 'agent' command must exist") + + deployCmd := findCommandByName(agentCmd.Commands, "deploy") + require.NotNil(t, deployCmd, "'agent deploy' command must exist") + + var names []string + for _, f := range deployCmd.Flags { + names = append(names, f.Names()...) + } + require.Contains(t, names, "id", "'agent deploy' must register the --id flag") +}