TestCmdDoAutoLaunchesDetached pins the core --auto behavior: no terminal tab is spawned, the detached supervisor launcher is invoked, and the task's auto-run bookkeeping is recorded with status 'running'.
(t *testing.T)
| 30 | // tab is spawned, the detached supervisor launcher is invoked, and the |
| 31 | // task's auto-run bookkeeping is recorded with status 'running'. |
| 32 | func TestCmdDoAutoLaunchesDetached(t *testing.T) { |
| 33 | root := setupFlowRoot(t) |
| 34 | seedTask(t, "auto-task") |
| 35 | |
| 36 | itermCount, _ := stubITerm(t) |
| 37 | calls, gotSlug, gotWorkDir, gotLog, gotInjection := stubAutoLauncher(t, 4242) |
| 38 | |
| 39 | if rc := cmdDo([]string{"auto-task", "--auto"}); rc != 0 { |
| 40 | t.Fatalf("cmdDo --auto rc=%d, want 0", rc) |
| 41 | } |
| 42 | if *gotInjection != "" { |
| 43 | t.Errorf("injection = %q, want empty (no --with passed)", *gotInjection) |
| 44 | } |
| 45 | if *itermCount != 0 { |
| 46 | t.Errorf("iterm spawn count = %d, want 0 (--auto must not open a tab)", *itermCount) |
| 47 | } |
| 48 | if *calls != 1 { |
| 49 | t.Fatalf("autoLauncher calls = %d, want 1", *calls) |
| 50 | } |
| 51 | if *gotSlug != "auto-task" { |
| 52 | t.Errorf("launcher slug = %q, want auto-task", *gotSlug) |
| 53 | } |
| 54 | if !strings.Contains(*gotLog, "tasks/auto-task/auto-runs/") { |
| 55 | t.Errorf("launcher logPath = %q, want path under tasks/auto-task/auto-runs/", *gotLog) |
| 56 | } |
| 57 | if !strings.HasSuffix(*gotLog, ".log") { |
| 58 | t.Errorf("launcher logPath = %q, want .log suffix", *gotLog) |
| 59 | } |
| 60 | _ = root |
| 61 | _ = gotWorkDir |
| 62 | |
| 63 | db := openFlowDB(t) |
| 64 | task, err := flowdb.GetTask(db, "auto-task") |
| 65 | if err != nil { |
| 66 | t.Fatal(err) |
| 67 | } |
| 68 | if task.Status != "in-progress" { |
| 69 | t.Errorf("status = %q, want in-progress", task.Status) |
| 70 | } |
| 71 | if !task.SessionID.Valid || task.SessionID.String == "" { |
| 72 | t.Error("session_id should be pre-allocated by --auto bootstrap") |
| 73 | } |
| 74 | if task.AutoRunStatus.String != "running" { |
| 75 | t.Errorf("auto_run_status = %q, want running", task.AutoRunStatus.String) |
| 76 | } |
| 77 | if !task.AutoRunPID.Valid || task.AutoRunPID.Int64 != 4242 { |
| 78 | t.Errorf("auto_run_pid = %+v, want 4242", task.AutoRunPID) |
| 79 | } |
| 80 | if !task.AutoRunStarted.Valid { |
| 81 | t.Error("auto_run_started should be set") |
| 82 | } |
| 83 | if task.AutoRunFinished.Valid { |
| 84 | t.Error("auto_run_finished should be NULL while running") |
| 85 | } |
| 86 | if task.AutoRunLog.String == "" { |
| 87 | t.Error("auto_run_log should be recorded") |
| 88 | } |
| 89 | } |
nothing calls this directly
no test coverage detected