Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion e2e/edge_case_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ func TestJSONOnAckCommand(t *testing.T) {
id := extractIncidentID(t, r.Stdout)
t.Cleanup(func() { runCLI(t, "incident", "close", id) })

// ack is served by the generated twin; --json wraps the OK line as {"message":"..."}.
r = runCLI(t, "incident", "ack", id, "--json")
requireSuccess(t, r)
requireValidJSON(t, r.Stdout)
requireContains(t, r.Stdout, "Acknowledged")
requireContains(t, r.Stdout, "OK: POST /incident/ack")
}

// Test 307: --json on close command
Expand Down
3 changes: 2 additions & 1 deletion e2e/incident_extended_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ func TestIncidentAckSingleID(t *testing.T) {
id := extractIncidentID(t, r.Stdout)
t.Cleanup(func() { runCLI(t, "incident", "close", id) })

// Served by the generated twin (positional id → incident_ids).
r = runCLI(t, "incident", "ack", id)
requireSuccess(t, r)
requireContains(t, r.Stdout, "Acknowledged 1 incident(s).")
requireContains(t, r.Stdout, "OK: POST /incident/ack")
}

// Test 204: close single ID
Expand Down
4 changes: 2 additions & 2 deletions e2e/incident_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ func TestIncidentLifecycle(t *testing.T) {
requireContains(t, r.Stdout, "Triggered")
requireContains(t, r.Stdout, name)

// Step 3: Ack
// Step 3: Ack (served by the generated twin; positional id → incident_ids).
r = runCLI(t, "incident", "ack", id)
requireSuccess(t, r)
requireContains(t, r.Stdout, "Acknowledged 1 incident(s).")
requireContains(t, r.Stdout, "OK: POST /incident/ack")

// Step 4: Get - should be Processing
r = runCLI(t, "incident", "get", id)
Expand Down
33 changes: 2 additions & 31 deletions internal/cli/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func newAlertCmd() *cobra.Command {
cmd.AddCommand(newAlertGetCmd())
cmd.AddCommand(newAlertEventsCmd())
cmd.AddCommand(newAlertTimelineCmd())
cmd.AddCommand(newAlertMergeCmd())
// merge is registered via the generated layer (positional alert-ids fold to
// alert_ids). Flag-name change: --incident (curated) → --incident-id (generated).
return cmd
}

Expand Down Expand Up @@ -303,33 +304,3 @@ func resolveAlertFeedOperators(rc *RunContext, items []flashduty.FeedItem) map[i
}
return out
}

func newAlertMergeCmd() *cobra.Command {
var incidentID, comment string

cmd := &cobra.Command{
Use: "merge <alert_id> [<alert_id2> ...]",
Short: "Merge alerts into an incident",
Args: requireArgs("alert_id"),
RunE: func(cmd *cobra.Command, args []string) error {
return runCommand(cmd, args, func(ctx *RunContext) error {
if _, err := ctx.Client.Alerts.WriteMerge(cmdContext(ctx.Cmd), &flashduty.AlertMergeRequest{
AlertIDs: ctx.Args,
IncidentID: incidentID,
Comment: comment,
}); err != nil {
return err
}

ctx.WriteResult(fmt.Sprintf("Merged %d alert(s) into incident %s.", len(ctx.Args), incidentID))
return nil
})
},
}

cmd.Flags().StringVar(&incidentID, "incident", "", "Target incident ID")
cmd.Flags().StringVar(&comment, "comment", "", "Merge comment")
_ = cmd.MarkFlagRequired("incident")

return cmd
}
15 changes: 10 additions & 5 deletions internal/cli/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ func TestCommandIncidentUnack(t *testing.T) {
saveAndResetGlobals(t)
stub := newGFStub(t)

// unack is served by the generated twin (positional ids → incident_ids).
out, err := execCommand("incident", "unack", "inc-1", "inc-2")
if err != nil {
t.Fatalf("[incident-unack] unexpected error: %v", err)
Expand All @@ -440,7 +441,7 @@ func TestCommandIncidentUnack(t *testing.T) {
if got, want := strings.Join(stub.bodyStrings("incident_ids"), ","), "inc-1,inc-2"; got != want {
t.Fatalf("[incident-unack] expected ids %q, got %q", want, got)
}
if !strings.Contains(out, "Unacknowledged 2 incident(s).") {
if !strings.Contains(out, "OK: POST /incident/unack") {
t.Fatalf("[incident-unack] unexpected output:\n%s", out)
}
}
Expand All @@ -449,6 +450,7 @@ func TestCommandIncidentWake(t *testing.T) {
saveAndResetGlobals(t)
stub := newGFStub(t)

// wake is served by the generated twin (positional id → incident_ids).
out, err := execCommand("incident", "wake", "inc-1")
if err != nil {
t.Fatalf("[incident-wake] unexpected error: %v", err)
Expand All @@ -459,7 +461,7 @@ func TestCommandIncidentWake(t *testing.T) {
if got, want := strings.Join(stub.bodyStrings("incident_ids"), ","), "inc-1"; got != want {
t.Fatalf("[incident-wake] expected ids %q, got %q", want, got)
}
if !strings.Contains(out, "Restored notifications for 1 incident(s).") {
if !strings.Contains(out, "OK: POST /incident/wake") {
t.Fatalf("[incident-wake] unexpected output:\n%s", out)
}
}
Expand Down Expand Up @@ -500,13 +502,15 @@ func TestCommandIncidentCommentAllows1024UnicodeRunes(t *testing.T) {
}
}

// TestCommandIncidentLifecycleRejectsMoreThan100IDs covers the curated
// commands that still enforce the 100-id batch cap client-side. unack and wake
// were dropped in favor of their generated twins, which carry no client-side
// cap (the backend enforces the limit), so they are intentionally absent here.
func TestCommandIncidentLifecycleRejectsMoreThan100IDs(t *testing.T) {
commands := []struct {
name string
args []string
}{
{name: "unack", args: []string{"incident", "unack"}},
{name: "wake", args: []string{"incident", "wake"}},
{name: "comment", args: []string{"incident", "comment", "--comment", "too many"}},
{name: "remove", args: []string{"incident", "remove"}},
}
Expand Down Expand Up @@ -612,6 +616,7 @@ func TestCommandIncidentDisableMerge(t *testing.T) {
saveAndResetGlobals(t)
stub := newGFStub(t)

// disable-merge is served by the generated twin (positional ids → incident_ids).
out, err := execCommand("incident", "disable-merge", "inc-1", "inc-2")
if err != nil {
t.Fatalf("[incident-disable-merge] unexpected error: %v", err)
Expand All @@ -622,7 +627,7 @@ func TestCommandIncidentDisableMerge(t *testing.T) {
if got, want := strings.Join(stub.bodyStrings("incident_ids"), ","), "inc-1,inc-2"; got != want {
t.Fatalf("[incident-disable-merge] expected ids %q, got %q", want, got)
}
if !strings.Contains(out, "Disabled auto-merge for 2 incident(s).") {
if !strings.Contains(out, "OK: POST /incident/disable-merge") {
t.Fatalf("[incident-disable-merge] unexpected output:\n%s", out)
}
}
Expand Down
7 changes: 4 additions & 3 deletions internal/cli/gen_positional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
// the variadic marker; an *_id scalar op renders the single id; the override and
// int cases render their pinned field.
func TestGenPositionalUseLine(t *testing.T) {
// (a) and (b) read the generated constructors directly (the curated commands
// own the live `incident ack`/`incident info` path-names, so the generated
// twins are dropped at registration but still constructible for assertion).
// (a) and (b) call the generated constructors directly so the Use-line
// assertions stay independent of registration order. `incident ack` now
// surfaces the generated twin (curated shadow dropped); `incident info` was
// always generated-only (the curated leaf is named `detail`).
ack := genIncidentsAckCmd()
if got := ack.Use; got != "ack <incident-id> [<id2>...]" {
t.Errorf("ack twin Use = %q, want %q", got, "ack <incident-id> [<id2>...]")
Expand Down
127 changes: 3 additions & 124 deletions internal/cli/incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,18 @@ func newIncidentCmd() *cobra.Command {
cmd.AddCommand(newIncidentGetCmd())
cmd.AddCommand(newIncidentCreateCmd())
cmd.AddCommand(newIncidentUpdateCmd())
cmd.AddCommand(newIncidentAckCmd())
cmd.AddCommand(newIncidentUnackCmd())
// ack, unack, wake, reopen, and disable-merge are registered via the
// generated layer (positional ids fold to incident_ids; flags are a superset
// of the dropped curated shadows).
cmd.AddCommand(newIncidentCloseCmd())
cmd.AddCommand(newIncidentWakeCmd())
cmd.AddCommand(newIncidentTimelineCmd())
cmd.AddCommand(newIncidentAlertsCmd())
cmd.AddCommand(newIncidentSimilarCmd())
cmd.AddCommand(newIncidentMergeCmd())
cmd.AddCommand(newIncidentSnoozeCmd())
cmd.AddCommand(newIncidentReopenCmd())
cmd.AddCommand(newIncidentReassignCmd())
cmd.AddCommand(newIncidentAddResponderCmd())
cmd.AddCommand(newIncidentCommentCmd())
cmd.AddCommand(newIncidentDisableMergeCmd())
cmd.AddCommand(newIncidentRemoveCmd())
cmd.AddCommand(newIncidentWarRoomCmd())
cmd.AddCommand(newIncidentFeedCmd())
Expand Down Expand Up @@ -441,53 +439,6 @@ func newIncidentUpdateCmd() *cobra.Command {
return cmd
}

func newIncidentAckCmd() *cobra.Command {
return &cobra.Command{
Use: "ack <id> [<id2> ...]",
Short: "Acknowledge incidents",
Args: requireArgs("incident_id"),
RunE: func(cmd *cobra.Command, args []string) error {
return runCommand(cmd, args, func(ctx *RunContext) error {
if _, err := ctx.Client.Incidents.Ack(cmdContext(ctx.Cmd), &flashduty.AckIncidentRequest{
IncidentIDs: ctx.Args,
}); err != nil {
return err
}
ctx.WriteResult(fmt.Sprintf("Acknowledged %d incident(s).", len(ctx.Args)))
return nil
})
},
}
}

func newIncidentUnackCmd() *cobra.Command {
return &cobra.Command{
Use: "unack <id> [<id2> ...]",
Short: "Cancel incident acknowledgement",
Long: `Cancel acknowledgement for one or more incidents.

Use this when an incident was acknowledged by mistake and should return to the
unacknowledged state. The command accepts up to 100 incident IDs.`,
Example: ` flashduty incident unack inc_123
flashduty incident unack inc_123 inc_456`,
Args: requireArgs("incident_id"),
RunE: func(cmd *cobra.Command, args []string) error {
if err := validateIncidentIDBatch(args); err != nil {
return err
}
return runCommand(cmd, args, func(ctx *RunContext) error {
if _, err := ctx.Client.Incidents.Unack(cmdContext(ctx.Cmd), &flashduty.UnackIncidentRequest{
IncidentIDs: ctx.Args,
}); err != nil {
return err
}
ctx.WriteResult(fmt.Sprintf("Unacknowledged %d incident(s).", len(ctx.Args)))
return nil
})
},
}
}

func newIncidentCloseCmd() *cobra.Command {
return &cobra.Command{
Use: "close <id> [<id2> ...]",
Expand All @@ -507,34 +458,6 @@ func newIncidentCloseCmd() *cobra.Command {
}
}

func newIncidentWakeCmd() *cobra.Command {
return &cobra.Command{
Use: "wake <id> [<id2> ...]",
Short: "Restore notifications for snoozed incidents",
Long: `Wake one or more snoozed incidents.

This cancels snooze and restores normal incident notifications. The command
accepts up to 100 incident IDs.`,
Example: ` flashduty incident wake inc_123
flashduty incident wake inc_123 inc_456`,
Args: requireArgs("incident_id"),
RunE: func(cmd *cobra.Command, args []string) error {
if err := validateIncidentIDBatch(args); err != nil {
return err
}
return runCommand(cmd, args, func(ctx *RunContext) error {
if _, err := ctx.Client.Incidents.Wake(cmdContext(ctx.Cmd), &flashduty.WakeIncidentRequest{
IncidentIDs: ctx.Args,
}); err != nil {
return err
}
ctx.WriteResult(fmt.Sprintf("Restored notifications for %d incident(s).", len(ctx.Args)))
return nil
})
},
}
}

func newIncidentTimelineCmd() *cobra.Command {
return &cobra.Command{
Use: "timeline <id>",
Expand Down Expand Up @@ -784,25 +707,6 @@ func newIncidentSnoozeCmd() *cobra.Command {
return cmd
}

func newIncidentReopenCmd() *cobra.Command {
return &cobra.Command{
Use: "reopen <id> [<id2> ...]",
Short: "Reopen closed incidents",
Args: requireArgs("incident_id"),
RunE: func(cmd *cobra.Command, args []string) error {
return runCommand(cmd, args, func(ctx *RunContext) error {
if _, err := ctx.Client.Incidents.Reopen(cmdContext(ctx.Cmd), &flashduty.ReopenIncidentRequest{
IncidentIDs: ctx.Args,
}); err != nil {
return err
}
ctx.WriteResult(fmt.Sprintf("Reopened %d incident(s).", len(ctx.Args)))
return nil
})
},
}
}

func newIncidentReassignCmd() *cobra.Command {
var person string

Expand Down Expand Up @@ -952,31 +856,6 @@ webhook reply behavior.`,
return cmd
}

func newIncidentDisableMergeCmd() *cobra.Command {
return &cobra.Command{
Use: "disable-merge <id> [<id2> ...]",
Short: "Disable automatic merging for incidents",
Long: `Disable automatic alert merging for one or more incidents.

Use this when an incident should stay isolated and must not absorb additional
matching alerts automatically. The command accepts up to 100 incident IDs.`,
Example: ` flashduty incident disable-merge inc_123
flashduty incident disable-merge inc_123 inc_456`,
Args: requireArgs("incident_id"),
RunE: func(cmd *cobra.Command, args []string) error {
return runCommand(cmd, args, func(ctx *RunContext) error {
if _, err := ctx.Client.Incidents.DisableMerge(cmdContext(ctx.Cmd), &flashduty.DisableIncidentMergeRequest{
IncidentIDs: ctx.Args,
}); err != nil {
return err
}
ctx.WriteResult(fmt.Sprintf("Disabled auto-merge for %d incident(s).", len(ctx.Args)))
return nil
})
},
}
}

func newIncidentRemoveCmd() *cobra.Command {
var force bool

Expand Down