Skip to content

Commit ee1d294

Browse files
committed
fix: improve status message formatting
1 parent 45b9c13 commit ee1d294

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

internal/commands/handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (h *Handler) status(targets []string) string {
111111
if len(lines) == 0 {
112112
return "没有匹配的目标。"
113113
}
114-
return strings.Join(lines, "\n")
114+
return strings.Join(lines, "\n\n")
115115
}
116116

117117
func (h *Handler) list() string {
@@ -196,7 +196,7 @@ func formatSnapshot(snapshot jobs.Snapshot, now time.Time) string {
196196
value += ",下次约 " + relativeFuture(snapshot.NextAttempt, now)
197197
}
198198
if snapshot.LastError != "" {
199-
value += ";最近失败:" + truncate(snapshot.LastError, 100)
199+
value += "\n\n最近失败:" + truncate(snapshot.LastError, 100)
200200
}
201201
return prefix + value
202202
case jobs.StateSucceeded:

internal/commands/handler_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package commands
22

33
import (
4+
"context"
45
"reflect"
56
"testing"
7+
"time"
8+
9+
"codex-queue-bot/internal/config"
10+
"codex-queue-bot/internal/jobs"
611
)
712

813
func TestParseCommandAndTargets(t *testing.T) {
@@ -15,3 +20,37 @@ func TestParseCommandAndTargets(t *testing.T) {
1520
t.Fatalf("splitTargets = %#v, want %#v", got, want)
1621
}
1722
}
23+
24+
func TestFormatSnapshotSeparatesFailureDetails(t *testing.T) {
25+
snapshot := jobs.Snapshot{
26+
Name: "backup",
27+
State: jobs.StateRunning,
28+
Attempts: 53,
29+
LastError: "codex exit failed: exit status 1",
30+
}
31+
32+
want := "backup:挤队中,第 53 次\n\n最近失败:codex exit failed: exit status 1"
33+
if got := formatSnapshot(snapshot, time.Now()); got != want {
34+
t.Fatalf("formatSnapshot = %q, want %q", got, want)
35+
}
36+
}
37+
38+
func TestStatusSeparatesTargetsWithBlankLine(t *testing.T) {
39+
manager := jobs.New(
40+
context.Background(),
41+
[]config.Target{{Name: "primary"}, {Name: "backup"}},
42+
nil,
43+
nil,
44+
nil,
45+
time.Second,
46+
time.Second,
47+
1,
48+
"开蹬",
49+
)
50+
handler := New(manager, nil, nil, nil)
51+
52+
want := "primary:未启动\n\nbackup:未启动"
53+
if got := handler.status(nil); got != want {
54+
t.Fatalf("status = %q, want %q", got, want)
55+
}
56+
}

0 commit comments

Comments
 (0)