(t *testing.T)
| 213 | } |
| 214 | |
| 215 | func TestMessages(t *testing.T) { |
| 216 | now := time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC) |
| 217 | |
| 218 | // newConversation creates a started conversation with a mock clock and |
| 219 | // testAgent. Tests that Send() messages must use sendAndAdvance. |
| 220 | newConversation := func(ctx context.Context, t *testing.T, opts ...func(*st.PTYConversationConfig)) (*st.PTYConversation, *testAgent, *quartz.Mock) { |
| 221 | t.Helper() |
| 222 | |
| 223 | writeCounter := 0 |
| 224 | agent := &testAgent{} |
| 225 | // Default onWrite: each write produces a unique screen so that |
| 226 | // writeStabilize can detect screen changes. |
| 227 | agent.onWrite = func(data []byte) { |
| 228 | writeCounter++ |
| 229 | agent.screen = fmt.Sprintf("__write_%d", writeCounter) |
| 230 | } |
| 231 | mClock := quartz.NewMock(t) |
| 232 | mClock.Set(now) |
| 233 | cfg := st.PTYConversationConfig{ |
| 234 | Clock: mClock, |
| 235 | AgentIO: agent, |
| 236 | SnapshotInterval: 100 * time.Millisecond, |
| 237 | ScreenStabilityLength: 200 * time.Millisecond, |
| 238 | Logger: slog.New(slog.NewTextHandler(io.Discard, nil)), |
| 239 | } |
| 240 | for _, opt := range opts { |
| 241 | opt(&cfg) |
| 242 | } |
| 243 | if a, ok := cfg.AgentIO.(*testAgent); ok { |
| 244 | agent = a |
| 245 | } |
| 246 | |
| 247 | c := st.NewPTY(ctx, cfg, &testEmitter{}) |
| 248 | c.Start(ctx) |
| 249 | |
| 250 | return c, agent, mClock |
| 251 | } |
| 252 | |
| 253 | // threshold = 3 (200ms / 100ms = 2, + 1 = 3) |
| 254 | const threshold = 3 |
| 255 | const interval = 100 * time.Millisecond |
| 256 | |
| 257 | t.Run("messages are copied", func(t *testing.T) { |
| 258 | c, _, _ := newConversation(context.Background(), t) |
| 259 | messages := c.Messages() |
| 260 | assertMessages(t, c, []st.ConversationMessage{ |
| 261 | {Id: 0, Message: "", Role: st.ConversationRoleAgent}, |
| 262 | }) |
| 263 | |
| 264 | messages[0].Message = "modification" |
| 265 | |
| 266 | assertMessages(t, c, []st.ConversationMessage{ |
| 267 | {Id: 0, Message: "", Role: st.ConversationRoleAgent}, |
| 268 | }) |
| 269 | }) |
| 270 | |
| 271 | t.Run("whitespace-padding", func(t *testing.T) { |
| 272 | c, _, _ := newConversation(context.Background(), t) |
nothing calls this directly
no test coverage detected