Skip to content

Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.

refactor(httpapi): reuse domain.TerminalRunStatus instead of roomRunTerminal (#498)

fx-kurumi3d8d9717d061
diff --git a/internal/domain/terminal_run_status_test.go b/internal/domain/terminal_run_status_test.go
new file mode 100644
index 00000000..eb7406bc
--- /dev/null
+++ b/internal/domain/terminal_run_status_test.go
@@ -0,0 +1,26 @@
+package domain
+
+import "testing"
+
+// TestTerminalRunStatus pins the terminal-status set shared by engine,
+// httpapi (rooms and space lanes) and notification callers.
+func TestTerminalRunStatus(t *testing.T) {
+ cases := map[string]bool{
+ "succeeded": true,
+ "failed": true,
+ "cancelled": true,
+ " failed\n": true,
+ "": false,
+ "queued": false,
+ "running": false,
+ "waiting": false,
+ "pending": false,
+ "Succeeded": false,
+ "cancelling": false,
+ }
+ for status, want := range cases {
+ if got := TerminalRunStatus(status); got != want {
+ t.Errorf("TerminalRunStatus(%q) = %v, want %v", status, got, want)
+ }
+ }
+}
diff --git a/internal/httpapi/room_runs.go b/internal/httpapi/room_runs.go
index 8cd03d85..96b5df06 100644
--- a/internal/httpapi/room_runs.go
+++ b/internal/httpapi/room_runs.go
@@ -19,14 +19,6 @@ import (
// busy room cannot turn every poll into dozens of run loads.
const roomRunWatchLimit = 12
-func roomRunTerminal(status string) bool {
- switch status {
- case "succeeded", "failed", "cancelled":
- return true
- }
- return false
-}
-
// roomProgressID is deterministic, so several API instances reconciling the
// same run write the same row instead of duplicating the message.
func roomProgressID(parts ...string) string {
@@ -104,7 +96,7 @@ func roomRunMessages(room domain.ChatRoom, dispatch domain.ChatMessage, run doma
}
out = append(out, msg)
}
- if roomRunTerminal(run.Status) {
+ if domain.TerminalRunStatus(run.Status) {
msg := base
msg.ID = roomProgressID(run.ID, "", "final", run.Status)
msg.Kind = domain.ChatKindProgress
@@ -192,7 +184,7 @@ func roomRunProgress(m *domain.ChatMessage, run domain.Run) {
func roomApprovalResolved(m domain.ChatMessage, run domain.Run) bool {
nr := run.Nodes[m.NodeID]
- return nr == nil || nr.Status != "waiting_approval" || nr.Attempt != m.Attempt || roomRunTerminal(run.Status)
+ return nr == nil || nr.Status != "waiting_approval" || nr.Attempt != m.Attempt || domain.TerminalRunStatus(run.Status)
}
// syncRoomRuns reconciles unfinished runs dispatched from this room and
@@ -294,7 +286,7 @@ func (h *roomsHandlers) syncRoomRuns(room domain.ChatRoom, messages []domain.Cha
}
}
roomRunProgress(m, run)
- if roomRunTerminal(run.Status) {
+ if domain.TerminalRunStatus(run.Status) {
m.RunFinal = run.Status
m.RunCurrent = nil
_ = h.repo.PutMessage(*m)
diff --git a/internal/httpapi/space_lanes.go b/internal/httpapi/space_lanes.go
index 95389b30..b8d314c3 100644
--- a/internal/httpapi/space_lanes.go
+++ b/internal/httpapi/space_lanes.go
@@ -181,7 +181,7 @@ func (h *spacesHandlers) laneWorkspace(run domain.Run) spaceLaneWorkspace {
break
}
switch {
- case !roomRunTerminal(run.Status) && run.Status != "":
+ case !domain.TerminalRunStatus(run.Status) && run.Status != "":
ws.State = "running"
case !run.WorkspaceCleanedAt.IsZero():
ws.State = "cleaned"
diff --git a/internal/httpapi/space_room_cases_test.go b/internal/httpapi/space_room_cases_test.go
index a88e3721..d36ea962 100644
--- a/internal/httpapi/space_room_cases_test.go
+++ b/internal/httpapi/space_room_cases_test.go
@@ -162,8 +162,7 @@ func TestRoomRunProjectionCacheAndTargets(t *testing.T) {
if len(projected) != 3 || projected[0].Author != "Agent Name" || projected[2].Body != "运行失败" {
t.Fatalf("projected: %#v", projected)
}
- if !roomRunTerminal("succeeded") || roomRunTerminal("running") ||
- roomProgressID("a") != roomProgressID("a") || roomTrim("abc", 2) != "ab…" ||
+ if roomProgressID("a") != roomProgressID("a") || roomTrim("abc", 2) != "ab…" ||
roomRejectTarget(wf, "approve") != "bad" {
t.Fatal("room run helpers")
}