TestCmdDoLiveSessionDuplicateProcessesWarn covers the duplicate-tab detection path. ps reports two claude processes running the same session UUID; cmdDo should emit a warning to stderr (so the user knows the duplicate exists and that transcript writes may race), then proceed to focus the first match
(t *testing.T)
| 221 | t.Errorf("cmdDo output = %q", out) |
| 222 | } |
| 223 | if *spawns != 0 { |
| 224 | t.Errorf("spawn count = %d, want 0", *spawns) |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | func TestCmdDoExplicitHarnessSelectsCodexForNewTask(t *testing.T) { |
| 229 | setupFlowRoot(t) |
| 230 | seedTask(t, "explicit-codex") |
| 231 | for _, h := range allHarnesses() { |
| 232 | t.Setenv(h.SessionIDEnvVar(), "") |
| 233 | } |
| 234 | // Exercise the important cross-harness case: Claude is ambient, but the |
| 235 | // user explicitly asks flow to open this *new* task in Codex. |
| 236 | t.Setenv("CLAUDE_CODE_SESSION_ID", "658bf2be-5ae3-4842-a8a4-e0d0b785514d") |
| 237 | const sid = "019ff4b1-6162-7263-974f-f5f1866ad0fe" |
| 238 | stubCodexProbe(t, sid) |
| 239 | _, script := stubITerm(t) |
| 240 | |
| 241 | if rc := cmdDo([]string{"explicit-codex", "--harness", "codex"}); rc != 0 { |
| 242 | t.Fatalf("cmdDo rc=%d", rc) |
| 243 | } |
| 244 | db := openFlowDB(t) |
| 245 | defer db.Close() |
| 246 | task, err := flowdb.GetTask(db, "explicit-codex") |
| 247 | if err != nil { |
| 248 | t.Fatal(err) |
| 249 | } |
| 250 | if task.Harness.String != "codex" || task.SessionID.String != sid { |
| 251 | t.Errorf("task = harness=%q session=%q, want codex/%q", task.Harness.String, task.SessionID.String, sid) |
| 252 | } |
| 253 | if !strings.Contains(script(), "codex resume "+sid) { |
| 254 | t.Errorf("spawn script did not resume Codex: %q", script()) |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | func TestCmdDoExplicitHarnessRefusesStartedTask(t *testing.T) { |
| 259 | setupFlowRoot(t) |
| 260 | seedTask(t, "started-task") |
| 261 | db := openFlowDB(t) |
| 262 | if _, err := db.Exec( |
| 263 | `UPDATE tasks SET harness='claude', session_id=?, session_started=? WHERE slug='started-task'`, |
| 264 | "658bf2be-5ae3-4842-a8a4-e0d0b785514d", flowdb.NowISO(), |
| 265 | ); err != nil { |
| 266 | t.Fatal(err) |
| 267 | } |
| 268 | db.Close() |
| 269 | _, _ = stubITerm(t) |
| 270 | stderr := captureStderr(t) |
| 271 | if rc := cmdDo([]string{"started-task", "--harness", "codex"}); rc == 0 { |
| 272 | t.Fatal("cmdDo succeeded, want explicit harness refusal") |
| 273 | } |
| 274 | if got := stderr(); !strings.Contains(got, "only selects the first session") { |
| 275 | t.Errorf("stderr = %q", got) |
nothing calls this directly
no test coverage detected