(t *testing.T)
| 1194 | } |
| 1195 | |
| 1196 | func TestInitialPromptReadiness(t *testing.T) { |
| 1197 | discardLogger := slog.New(slog.NewTextHandler(io.Discard, nil)) |
| 1198 | |
| 1199 | t.Run("agent not ready - status is changing until agent becomes ready", func(t *testing.T) { |
| 1200 | ctx, cancel := context.WithTimeout(context.Background(), testTimeout) |
| 1201 | t.Cleanup(cancel) |
| 1202 | mClock := quartz.NewMock(t) |
| 1203 | agent := &testAgent{screen: "loading..."} |
| 1204 | cfg := st.PTYConversationConfig{ |
| 1205 | Clock: mClock, |
| 1206 | SnapshotInterval: 1 * time.Second, |
| 1207 | ScreenStabilityLength: 0, |
| 1208 | AgentIO: agent, |
| 1209 | ReadyForInitialPrompt: func(message string) bool { |
| 1210 | return message == "ready" |
| 1211 | }, |
| 1212 | InitialPrompt: []st.MessagePart{st.MessagePartText{Content: "initial prompt here"}}, |
| 1213 | Logger: discardLogger, |
| 1214 | } |
| 1215 | |
| 1216 | c := st.NewPTY(ctx, cfg, &testEmitter{}) |
| 1217 | c.Start(ctx) |
| 1218 | |
| 1219 | // Take a snapshot with "loading...". Threshold is 1 (stability 0 / interval 1s = 0 + 1 = 1). |
| 1220 | advanceFor(ctx, t, mClock, 1*time.Second) |
| 1221 | |
| 1222 | // Screen is stable but agent is not ready. Status must be |
| 1223 | // "changing" so that Send() rejects instead of blocking. |
| 1224 | assert.Equal(t, st.ConversationStatusChanging, c.Status()) |
| 1225 | }) |
| 1226 | |
| 1227 | t.Run("agent becomes ready - prompt enqueued and status changes to changing", func(t *testing.T) { |
| 1228 | ctx, cancel := context.WithTimeout(context.Background(), testTimeout) |
| 1229 | t.Cleanup(cancel) |
| 1230 | mClock := quartz.NewMock(t) |
| 1231 | agent := &testAgent{screen: "loading..."} |
| 1232 | cfg := st.PTYConversationConfig{ |
| 1233 | Clock: mClock, |
| 1234 | SnapshotInterval: 1 * time.Second, |
| 1235 | ScreenStabilityLength: 0, |
| 1236 | AgentIO: agent, |
| 1237 | ReadyForInitialPrompt: func(message string) bool { |
| 1238 | return message == "ready" |
| 1239 | }, |
| 1240 | InitialPrompt: []st.MessagePart{st.MessagePartText{Content: "initial prompt here"}}, |
| 1241 | Logger: discardLogger, |
| 1242 | } |
| 1243 | |
| 1244 | c := st.NewPTY(ctx, cfg, &testEmitter{}) |
| 1245 | c.Start(ctx) |
| 1246 | |
| 1247 | // Agent not ready initially, status should be changing. |
| 1248 | advanceFor(ctx, t, mClock, 1*time.Second) |
| 1249 | assert.Equal(t, st.ConversationStatusChanging, c.Status()) |
| 1250 | // Agent becomes ready, prompt gets enqueued, status becomes "changing" |
| 1251 | agent.setScreen("ready") |
| 1252 | advanceFor(ctx, t, mClock, 1*time.Second) |
| 1253 | assert.Equal(t, st.ConversationStatusChanging, c.Status()) |
nothing calls this directly
no test coverage detected