(t *testing.T)
| 1035 | // regardless of --force. The session-id uniqueness is structural; |
| 1036 | // no escape hatch. |
| 1037 | func TestCmdDoHereRejectsCurrentSessionAlreadyBoundElsewhere(t *testing.T) { |
| 1038 | setupFlowRoot(t) |
| 1039 | seedTask(t, "owner-task") |
| 1040 | seedTask(t, "intruder-task") |
| 1041 | |
| 1042 | const sid = "f00ba111-2222-4333-8444-555555555555" |
| 1043 | db := openFlowDB(t) |
| 1044 | if _, err := db.Exec( |
| 1045 | `UPDATE tasks SET session_id=?, session_started=?, status='in-progress' WHERE slug='owner-task'`, |
| 1046 | sid, flowdb.NowISO(), |
| 1047 | ); err != nil { |
| 1048 | t.Fatal(err) |
| 1049 | } |
| 1050 | db.Close() |
| 1051 | t.Setenv("CLAUDE_CODE_SESSION_ID", sid) |
| 1052 | |
| 1053 | // Without --force. |
| 1054 | if rc := cmdDo([]string{"intruder-task", "--here"}); rc != 1 { |
| 1055 | t.Errorf("rc=%d, want 1 when current session bound elsewhere", rc) |
| 1056 | } |
| 1057 | // Even with --force the structural invariant should hold. |
| 1058 | if rc := cmdDo([]string{"intruder-task", "--here", "--force"}); rc != 1 { |
| 1059 | t.Errorf("--force rc=%d, want 1 (no override of duplicate-session check)", rc) |
| 1060 | } |
| 1061 | |
| 1062 | // owner-task still owns the session. |
| 1063 | db = openFlowDB(t) |
| 1064 | owner, _ := flowdb.GetTask(db, "owner-task") |
| 1065 | if owner.SessionID.String != sid { |
| 1066 | t.Errorf("owner-task session_id changed: got %q, want %s", owner.SessionID.String, sid) |
nothing calls this directly
no test coverage detected