diff --git a/internal/cli/incident.go b/internal/cli/incident.go index 1804d0d..3ba4498 100644 --- a/internal/cli/incident.go +++ b/internal/cli/incident.go @@ -280,7 +280,7 @@ func newIncidentGetCmd() *cobra.Command { return &cobra.Command{ Use: "get [ ...]", Short: "Get incident details", - Long: curatedLong("Get details for one or more incidents by ID.", "Incidents", "List"), + Long: curatedLong("Get details for one or more incidents by ID.", "Incidents", "ListByIDs"), Args: requireArgs("incident_id"), RunE: func(cmd *cobra.Command, args []string) error { return runCommand(cmd, args, func(ctx *RunContext) error { @@ -296,7 +296,9 @@ func newIncidentGetCmd() *cobra.Command { ids = append(ids, fullID) } - result, _, err := ctx.Client.Incidents.List(cmdContext(ctx.Cmd), &flashduty.ListIncidentsRequest{ + // /incident/list requires a start_time/end_time window; lookup by id + // goes through /incident/list-by-ids, which takes ids alone. + result, _, err := ctx.Client.Incidents.ListByIDs(cmdContext(ctx.Cmd), &flashduty.ListIncidentsByIDsRequest{ IncidentIDs: ids, }) if err != nil { diff --git a/internal/cli/incident_short_id_test.go b/internal/cli/incident_short_id_test.go index 0323978..f3e6e34 100644 --- a/internal/cli/incident_short_id_test.go +++ b/internal/cli/incident_short_id_test.go @@ -141,22 +141,22 @@ func TestIncidentDetailFullIDSkipsResolve(t *testing.T) { } } -// TestIncidentGetShortIDResolves: `get <6-hex>` resolves the short id, then -// fetches by the resolved full id via incident_ids. +// TestIncidentGetShortIDResolves: `get <6-hex>` resolves the short id via +// /incident/list, then fetches by the resolved full id via /incident/list-by-ids. func TestIncidentGetShortIDResolves(t *testing.T) { saveAndResetGlobals(t) stub := newGFStub(t) + var paths []string stub.dataForPath = func(path string, body map[string]any) any { - // Both the resolve and the final fetch hit /incident/list; the canned - // row is fine for either. + paths = append(paths, path) return incidentListData(incidentItem(testFullID, testShortID, "kafka backlog")) } if _, err := execCommand("incident", "get", testShortID); err != nil { t.Fatalf("execCommand: %v", err) } - if stub.requests != 2 { - t.Fatalf("requests = %d, want 2 (resolve + fetch)", stub.requests) + if want := []string{"/incident/list", "/incident/list-by-ids"}; !equalStrings(paths, want) { + t.Fatalf("paths = %v, want %v (resolve + fetch)", paths, want) } // Resolve sent nums; final fetch sent the resolved full id via incident_ids. @@ -169,6 +169,30 @@ func TestIncidentGetShortIDResolves(t *testing.T) { } } +// TestIncidentGetFullIDUsesListByIDs: a full id skips the resolve and fetches +// through /incident/list-by-ids. /incident/list rejects a request without a +// start_time/end_time window, so the id lookup must not go through it. +func TestIncidentGetFullIDUsesListByIDs(t *testing.T) { + saveAndResetGlobals(t) + stub := newGFStub(t) + var paths []string + stub.dataForPath = func(path string, body map[string]any) any { + paths = append(paths, path) + return incidentListData(incidentItem(testFullID, testShortID, "kafka backlog")) + } + + if _, err := execCommand("incident", "get", testFullID); err != nil { + t.Fatalf("execCommand: %v", err) + } + if want := []string{"/incident/list-by-ids"}; !equalStrings(paths, want) { + t.Fatalf("paths = %v, want %v", paths, want) + } + ids, _ := stub.bodies[0]["incident_ids"].([]any) + if len(ids) != 1 || ids[0] != testFullID { + t.Errorf("incident_ids = %#v, want [%q]", stub.bodies[0]["incident_ids"], testFullID) + } +} + // TestIncidentListNumsReachesWire: --nums is split and sent as the nums array. func TestIncidentListNumsReachesWire(t *testing.T) { saveAndResetGlobals(t)