TestCmdDoLiveSessionFocusesExistingTab pins the new behavior: when a task's session is already running AND the active backend can locate its tab, `flow do` focuses that tab and exits 0 instead of erroring. No new tab is spawned.
(t *testing.T)
| 177 | } |
| 178 | if *count != 0 { |
| 179 | t.Errorf("iterm spawn count = %d, want 0 (guard should block)", *count) |
| 180 | } |
| 181 | |
| 182 | // --force should bypass the guard (and the focus attempt). iTerm |
| 183 | // runner is still stubbed from above, so spawning will succeed. |
| 184 | if rc := cmdDo([]string{"live-task", "--force"}); rc != 0 { |
| 185 | t.Errorf("cmdDo --force: rc=%d, want 0 (guard bypassed)", rc) |
| 186 | } |
| 187 | if *count != 1 { |
| 188 | t.Errorf("iterm spawn count after --force = %d, want 1", *count) |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | // TestCmdDoCurrentSessionGuard covers the case ps cannot see: a task was |
| 193 | // bound with `do --here`, then `do <task>` is invoked from that same active |
| 194 | // Codex thread. Resuming it would create a second writer and Codex refuses |
| 195 | // the TUI bootstrap, so this must be an idempotent no-op. |
| 196 | func TestCmdDoCurrentSessionGuard(t *testing.T) { |
| 197 | setupFlowRoot(t) |
| 198 | seedTask(t, "current-codex-task") |
| 199 | |
| 200 | const sid = "019ff4b1-6162-7263-974f-f5f1866ad0fe" |
| 201 | db := openFlowDB(t) |
| 202 | if _, err := db.Exec( |
| 203 | `UPDATE tasks SET session_id=?, session_started=?, harness='codex' WHERE slug='current-codex-task'`, |
| 204 | sid, flowdb.NowISO(), |
| 205 | ); err != nil { |
| 206 | t.Fatal(err) |
| 207 | } |
| 208 | db.Close() |
| 209 | |
| 210 | for _, h := range allHarnesses() { |
| 211 | t.Setenv(h.SessionIDEnvVar(), "") |
| 212 | } |
| 213 | t.Setenv("CODEX_THREAD_ID", sid) |
| 214 | spawns, _ := stubITerm(t) |
| 215 | out := captureStdout(t, func() { |
| 216 | if rc := cmdDo([]string{"current-codex-task"}); rc != 0 { |
| 217 | t.Errorf("cmdDo rc=%d, want 0", rc) |
nothing calls this directly
no test coverage detected