(t *testing.T)
| 1359 | } |
| 1360 | |
| 1361 | func TestInitialPromptSent(t *testing.T) { |
| 1362 | discardLogger := slog.New(slog.NewTextHandler(io.Discard, nil)) |
| 1363 | |
| 1364 | t.Run("initialPromptSent is set when initial prompt is sent", func(t *testing.T) { |
| 1365 | ctx, cancel := context.WithTimeout(context.Background(), testTimeout) |
| 1366 | t.Cleanup(cancel) |
| 1367 | |
| 1368 | tmpDir := t.TempDir() |
| 1369 | stateFile := tmpDir + "/state.json" |
| 1370 | |
| 1371 | mClock := quartz.NewMock(t) |
| 1372 | agent := &testAgent{screen: "loading..."} |
| 1373 | writeCounter := 0 |
| 1374 | agent.onWrite = func(data []byte) { |
| 1375 | writeCounter++ |
| 1376 | agent.screen = fmt.Sprintf("__write_%d", writeCounter) |
| 1377 | } |
| 1378 | |
| 1379 | cfg := st.PTYConversationConfig{ |
| 1380 | Clock: mClock, |
| 1381 | SnapshotInterval: 1 * time.Second, |
| 1382 | ScreenStabilityLength: 0, |
| 1383 | AgentIO: agent, |
| 1384 | ReadyForInitialPrompt: func(message string) bool { |
| 1385 | return message == "ready" |
| 1386 | }, |
| 1387 | InitialPrompt: []st.MessagePart{st.MessagePartText{Content: "test prompt"}}, |
| 1388 | Logger: discardLogger, |
| 1389 | StatePersistenceConfig: st.StatePersistenceConfig{ |
| 1390 | StateFile: stateFile, |
| 1391 | LoadState: false, |
| 1392 | SaveState: true, |
| 1393 | }, |
| 1394 | } |
| 1395 | |
| 1396 | c := st.NewPTY(ctx, cfg, &testEmitter{}) |
| 1397 | c.Start(ctx) |
| 1398 | |
| 1399 | // Agent becomes ready and initial prompt is sent |
| 1400 | agent.setScreen("ready") |
| 1401 | advanceUntil(ctx, t, mClock, func() bool { |
| 1402 | return len(c.Messages()) >= 2 |
| 1403 | }) |
| 1404 | |
| 1405 | // Save state and verify initialPromptSent is persisted |
| 1406 | agent.setScreen("response") |
| 1407 | advanceFor(ctx, t, mClock, 2*time.Second) |
| 1408 | |
| 1409 | err := c.SaveState() |
| 1410 | require.NoError(t, err) |
| 1411 | |
| 1412 | data, err := os.ReadFile(stateFile) |
| 1413 | require.NoError(t, err) |
| 1414 | |
| 1415 | var agentState st.AgentState |
| 1416 | err = json.Unmarshal(data, &agentState) |
| 1417 | require.NoError(t, err) |
| 1418 |
nothing calls this directly
no test coverage detected