@@ -34,12 +34,83 @@ func TestCopySessionIDRegistered(t *testing.T) {
3434func TestCopySessionIDCopiesActiveSession (t * testing.T ) {
3535 m := newTestModel ()
3636 m .sessionID = "sess-abc123"
37+ m .sessionLive = true
3738 runCopySessionID (m )
3839 if ! m .copyFlashing () {
3940 t .Error ("copying a session id must arm the ✓ Copied flash" )
4041 }
4142}
4243
44+ // A session id stamped by the connect-time session event is not a live
45+ // session yet: no prompt was sent, so the id may point at a placeholder
46+ // the operator never created. /copy-session-id must stay unavailable.
47+ func TestCopySessionIDUnavailableBeforeFirstPrompt (t * testing.T ) {
48+ m := newTestModel ()
49+ m .sessionID = "sess-connect-stamp" // wire session frame, no prompt sent
50+ runCopySessionID (m )
51+ if m .copyFlashing () {
52+ t .Error ("pre-session copy must not arm the ✓ Copied flash" )
53+ }
54+ if n := len (m .notices ); n == 0 {
55+ t .Fatal ("pre-session copy must record a visible note" )
56+ } else if got := m .notices [n - 1 ]; ! strings .Contains (got , "no session" ) || ! strings .Contains (got , "prompt" ) {
57+ t .Errorf ("note = %q, want a warning naming the session and a prompt hint" , got )
58+ }
59+ }
60+
61+ // The first prompt creates the session: the command becomes usable.
62+ func TestCopySessionIDAvailableAfterFirstPrompt (t * testing.T ) {
63+ m := newTestModel ()
64+ m .sessionID = "sess-abc123"
65+ m .sessionLive = true // armed by sendPrompt
66+ runCopySessionID (m )
67+ if ! m .copyFlashing () {
68+ t .Error ("after a prompt the session id must copy" )
69+ }
70+ }
71+
72+ // /new tears the session down: the command goes dormant again until the
73+ // next prompt creates the replacement session.
74+ func TestCopySessionIDDormantAfterNewSession (t * testing.T ) {
75+ m := newTestModel ()
76+ m .sessionID = "sess-old"
77+ m .sessionLive = true
78+ m .startFreshSession ()
79+ if m .sessionLive {
80+ t .Error ("startFreshSession must clear sessionLive" )
81+ }
82+ }
83+
84+ // Hidden surfaces: the slash popup and /help must not offer the command
85+ // before the session exists — unavailable means not discoverable.
86+ func TestCopySessionIDHiddenPreSession (t * testing.T ) {
87+ m := newTestModel ()
88+ m .sessionID = "sess-connect-stamp"
89+ m .openCmdAC ("" )
90+ for _ , it := range m .ac .items {
91+ if it .ID == "/copy-session-id" {
92+ t .Error ("AC popup must not offer /copy-session-id before the session exists" )
93+ }
94+ }
95+ if strings .Contains (m .buildHelpCard (), "/copy-session-id" ) {
96+ t .Error ("/help must not list /copy-session-id before the session exists" )
97+ }
98+ m .sessionLive = true
99+ m .openCmdAC ("" )
100+ found := false
101+ for _ , it := range m .ac .items {
102+ if it .ID == "/copy-session-id" {
103+ found = true
104+ }
105+ }
106+ if ! found {
107+ t .Error ("AC popup must offer /copy-session-id once the session is live" )
108+ }
109+ if ! strings .Contains (m .buildHelpCard (), "/copy-session-id" ) {
110+ t .Error ("/help must list /copy-session-id once the session is live" )
111+ }
112+ }
113+
43114func TestCopySessionIDWithoutSession (t * testing.T ) {
44115 m := newTestModel ()
45116 if cmd := m .copySessionID (); cmd == nil {
0 commit comments