TestCmdDoFreshAllocatesSessionID verifies the pre-allocation contract: a fresh task gets a UUID written to tasks.session_id and spawns `claude --session-id " "` so the jsonl file claude creates lands at the deterministic path keyed on that UUID.
(t *testing.T)
| 299 | if _, err := db.Exec( |
| 300 | `UPDATE tasks SET session_id=?, session_started=? WHERE slug='open-task'`, |
| 301 | pinnedSID, flowdb.NowISO(), |
| 302 | ); err != nil { |
| 303 | t.Fatal(err) |
| 304 | } |
| 305 | |
| 306 | // App-level liveClaudeSessions sees the UUID as alive. |
| 307 | stubPS(t, " PID COMMAND\n12345 /bin/claude --session-id "+pinnedSID+"\n") |
| 308 | |
| 309 | // iterm focus path: ps yields a row with tty, then osascript |
| 310 | // reports "ok" → FocusSession returns (true, nil). |
| 311 | oldFocusPS := iterm.PSRunner |
| 312 | iterm.PSRunner = func() ([]byte, error) { |
| 313 | return []byte(" PID TTY COMMAND\n12345 ttys012 /bin/claude --session-id " + pinnedSID + "\n"), nil |
| 314 | } |
| 315 | t.Cleanup(func() { iterm.PSRunner = oldFocusPS }) |
| 316 | |
| 317 | oldRunnerOut := iterm.RunnerOutput |
| 318 | iterm.RunnerOutput = func(args []string) ([]byte, error) { return []byte("ok\n"), nil } |
| 319 | t.Cleanup(func() { iterm.RunnerOutput = oldRunnerOut }) |
| 320 | |
| 321 | count, _ := stubITerm(t) |
| 322 | if rc := cmdDo([]string{"open-task"}); rc != 0 { |
| 323 | t.Errorf("cmdDo when focus succeeds: rc=%d, want 0", rc) |
| 324 | } |
| 325 | if *count != 0 { |
| 326 | t.Errorf("iterm spawn count = %d, want 0 (focus should not spawn)", *count) |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | // TestCmdDoLiveSessionDuplicateProcessesWarn covers the duplicate-tab |
| 331 | // detection path. ps reports two claude processes running the same |
| 332 | // session UUID; cmdDo should emit a warning to stderr (so the user |
| 333 | // knows the duplicate exists and that transcript writes may race), |
| 334 | // then proceed to focus the first match. We assert that focus still |
| 335 | // succeeds (rc=0, no spawn) and the duplicate count surfaces in the |
| 336 | // captured stderr. |
| 337 | func TestCmdDoLiveSessionDuplicateProcessesWarn(t *testing.T) { |
| 338 | setupFlowRoot(t) |
| 339 | seedTask(t, "dup-task") |
| 340 | |
| 341 | const pinnedSID = "abcdef12-3456-4789-8abc-def012345678" |
nothing calls this directly
no test coverage detected