TestCmdDoConcurrentFreshTasks verifies two concurrent cmdDo calls on a fresh task don't corrupt DB state. The BEGIN IMMEDIATE lock serializes the txs: the winner allocates a UUID and writes it; the loser sees session_id already set and falls through to the resume path (spawning `claude --resume <win
(t *testing.T)
| 597 | _, getScript := stubITerm(t) |
| 598 | if rc := cmdDo([]string{"stale-task", "--fresh"}); rc != 0 { |
| 599 | t.Fatalf("rc=%d", rc) |
| 600 | } |
| 601 | db = openFlowDB(t) |
| 602 | task, _ := flowdb.GetTask(db, "stale-task") |
| 603 | if task.SessionID.String != pinnedSID { |
| 604 | t.Errorf("session_id after --fresh: got %q, want %s", task.SessionID.String, pinnedSID) |
| 605 | } |
| 606 | script := getScript() |
| 607 | if strings.Contains(script, "--resume") { |
| 608 | t.Errorf("--fresh should not spawn --resume: %s", script) |
| 609 | } |
| 610 | if !strings.Contains(script, "--session-id "+pinnedSID) { |
| 611 | t.Errorf("--fresh should spawn with --session-id %s: %s", pinnedSID, script) |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | func TestCmdDoDoneTaskRefused(t *testing.T) { |
| 616 | setupFlowRoot(t) |
| 617 | seedTask(t, "closed-task") |
| 618 | |
| 619 | // Done implies a session_id (invariant). Pre-seed one before flipping. |
| 620 | db := openFlowDB(t) |
| 621 | if _, err := db.Exec( |
| 622 | `UPDATE tasks SET status='done', session_id=?, session_started=?, updated_at=? WHERE slug='closed-task'`, |
| 623 | fakeSessionID("closed-task"), flowdb.NowISO(), flowdb.NowISO(), |
| 624 | ); err != nil { |
| 625 | t.Fatal(err) |
| 626 | } |
| 627 | db.Close() |
nothing calls this directly
no test coverage detected