From 33355cf5d9eac2782ea7b5cba959010539f290a9 Mon Sep 17 00:00:00 2001 From: ysyneu Date: Mon, 15 Jun 2026 11:47:42 +0800 Subject: [PATCH 1/2] fix(incident): accept --channel-id on incident list for flag consistency `incident list` only accepted --channel, but every sibling channel command (channel info --channel-id, channel escalate-rule-list --channel-id, ...) uses --channel-id. An ai-sre agent that transferred the flag name across commands ran `incident list --channel-id ` and got "unknown flag", wasting a turn. Make --channel-id the canonical flag (matching the siblings) and keep --channel as a deprecated alias bound to the same variable so existing callers keep working. Add tests asserting both flags forward to /incident/list as channel_ids. --- internal/cli/incident.go | 6 ++++++ internal/cli/incident_test.go | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/internal/cli/incident.go b/internal/cli/incident.go index 52d9908..589fc23 100644 --- a/internal/cli/incident.go +++ b/internal/cli/incident.go @@ -124,7 +124,13 @@ func newIncidentListCmd() *cobra.Command { cmd.Flags().StringVar(&severity, "severity", "", "Filter: Critical,Warning,Info") registerEnumFlag(cmd, "progress", "Triggered", "Processing", "Closed") registerEnumFlag(cmd, "severity", severityEnum...) + // --channel-id is the canonical name, matching the sibling channel + // commands (channel info --channel-id, channel escalate-rule-list + // --channel-id). --channel is kept as a deprecated alias so existing + // callers keep working; both bind to the same variable. + cmd.Flags().Int64Var(&channelID, "channel-id", 0, "Filter by channel ID") cmd.Flags().Int64Var(&channelID, "channel", 0, "Filter by channel ID") + _ = cmd.Flags().MarkDeprecated("channel", "use --channel-id instead") cmd.Flags().StringVar(&query, "query", "", "Free-text search across title/labels/content (also resolves a 24-char incident ID or 6-char incident num to a direct lookup)") cmd.Flags().StringVar(&nums, "nums", "", "Comma-separated short incident ids (num, the 6-char id shown in the UI) to filter by") cmd.Flags().StringVar(&since, "since", "24h", "Start time (duration, date, datetime, or unix timestamp; --since→--until window must be < 31 days)") diff --git a/internal/cli/incident_test.go b/internal/cli/incident_test.go index 6345754..b8967a5 100644 --- a/internal/cli/incident_test.go +++ b/internal/cli/incident_test.go @@ -1,6 +1,7 @@ package cli import ( + "fmt" "testing" ) @@ -26,3 +27,38 @@ func TestCommandIncidentSimilarLimitReachesWire(t *testing.T) { t.Errorf("incident_id = %#v, want inc-1", stub.lastBody["incident_id"]) } } + +// TestCommandIncidentListChannelIDFlag verifies that `incident list` accepts +// the canonical --channel-id flag (consistent with the sibling channel +// commands, e.g. `channel info --channel-id`) and forwards it to /incident/list +// as channel_ids. An agent that transferred --channel-id from those commands +// previously hit "unknown flag: --channel-id" and wasted a turn. +func TestCommandIncidentListChannelIDFlag(t *testing.T) { + saveAndResetGlobals(t) + stub := newGFStub(t) + + if _, err := execCommand("incident", "list", "--channel-id", "123"); err != nil { + t.Fatalf("execCommand --channel-id: %v", err) + } + if stub.lastPath != "/incident/list" { + t.Fatalf("path = %q, want /incident/list", stub.lastPath) + } + if got, want := fmt.Sprint(stub.lastBody["channel_ids"]), "[123]"; got != want { + t.Fatalf("channel_ids = %q, want %q", got, want) + } +} + +// TestCommandIncidentListChannelDeprecatedAlias guards the back-compat alias: +// the original --channel flag must keep working and resolve to the same +// channel_ids wire field, so existing callers are not broken by the rename. +func TestCommandIncidentListChannelDeprecatedAlias(t *testing.T) { + saveAndResetGlobals(t) + stub := newGFStub(t) + + if _, err := execCommand("incident", "list", "--channel", "456"); err != nil { + t.Fatalf("execCommand --channel: %v", err) + } + if got, want := fmt.Sprint(stub.lastBody["channel_ids"]), "[456]"; got != want { + t.Fatalf("channel_ids = %q, want %q", got, want) + } +} From b7966f61030c20b620b79f7e10bb0653e2732515 Mon Sep 17 00:00:00 2001 From: ysyneu Date: Mon, 15 Jun 2026 12:18:56 +0800 Subject: [PATCH 2/2] fix(incident): rename --channel to --channel-id on incident list `incident list` used --channel while every sibling channel command uses --channel-id (channel info --channel-id, channel escalate-rule-list --channel-id, ...). Rename the flag to --channel-id for consistency. --channel is removed (not aliased); only --channel-id exists. --- internal/cli/incident.go | 8 ++------ internal/cli/incident_test.go | 15 --------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/internal/cli/incident.go b/internal/cli/incident.go index 589fc23..90e4b3a 100644 --- a/internal/cli/incident.go +++ b/internal/cli/incident.go @@ -124,13 +124,9 @@ func newIncidentListCmd() *cobra.Command { cmd.Flags().StringVar(&severity, "severity", "", "Filter: Critical,Warning,Info") registerEnumFlag(cmd, "progress", "Triggered", "Processing", "Closed") registerEnumFlag(cmd, "severity", severityEnum...) - // --channel-id is the canonical name, matching the sibling channel - // commands (channel info --channel-id, channel escalate-rule-list - // --channel-id). --channel is kept as a deprecated alias so existing - // callers keep working; both bind to the same variable. + // --channel-id matches the sibling channel commands (channel info + // --channel-id, channel escalate-rule-list --channel-id). cmd.Flags().Int64Var(&channelID, "channel-id", 0, "Filter by channel ID") - cmd.Flags().Int64Var(&channelID, "channel", 0, "Filter by channel ID") - _ = cmd.Flags().MarkDeprecated("channel", "use --channel-id instead") cmd.Flags().StringVar(&query, "query", "", "Free-text search across title/labels/content (also resolves a 24-char incident ID or 6-char incident num to a direct lookup)") cmd.Flags().StringVar(&nums, "nums", "", "Comma-separated short incident ids (num, the 6-char id shown in the UI) to filter by") cmd.Flags().StringVar(&since, "since", "24h", "Start time (duration, date, datetime, or unix timestamp; --since→--until window must be < 31 days)") diff --git a/internal/cli/incident_test.go b/internal/cli/incident_test.go index b8967a5..61156a7 100644 --- a/internal/cli/incident_test.go +++ b/internal/cli/incident_test.go @@ -47,18 +47,3 @@ func TestCommandIncidentListChannelIDFlag(t *testing.T) { t.Fatalf("channel_ids = %q, want %q", got, want) } } - -// TestCommandIncidentListChannelDeprecatedAlias guards the back-compat alias: -// the original --channel flag must keep working and resolve to the same -// channel_ids wire field, so existing callers are not broken by the rename. -func TestCommandIncidentListChannelDeprecatedAlias(t *testing.T) { - saveAndResetGlobals(t) - stub := newGFStub(t) - - if _, err := execCommand("incident", "list", "--channel", "456"); err != nil { - t.Fatalf("execCommand --channel: %v", err) - } - if got, want := fmt.Sprint(stub.lastBody["channel_ids"]), "[456]"; got != want { - t.Fatalf("channel_ids = %q, want %q", got, want) - } -}