Skip to content

Commit 144d261

Browse files
committed
address flake in TestOpenAPISchema
1 parent f7b7793 commit 144d261

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

cmd/server/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func runServer(ctx context.Context, logger *slog.Logger, argsToPass []string) er
9191
fmt.Println(srv.GetOpenAPI())
9292
return nil
9393
}
94+
srv.StartSnapshotLoop(ctx)
9495
logger.Info("Starting server on port", "port", port)
9596
processExitCh := make(chan error, 1)
9697
go func() {

lib/httpapi/server.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func (s *Server) GetOpenAPI() string {
5252
return string(prettyJSON)
5353
}
5454

55+
// That's about 40 frames per second. It's slightly less
56+
// because the action of taking a snapshot takes time too.
57+
const snapshotInterval = 25 * time.Millisecond
58+
5559
// NewServer creates a new server instance
5660
func NewServer(ctx context.Context, agentType mf.AgentType, process *termexec.Process, port int) *Server {
5761
router := chi.NewMux()
@@ -72,9 +76,6 @@ func NewServer(ctx context.Context, agentType mf.AgentType, process *termexec.Pr
7276
formatMessage := func(message string, userInput string) string {
7377
return mf.FormatAgentMessage(agentType, message, userInput)
7478
}
75-
// That's about 40 frames per second. It's slightly less
76-
// because the action of taking a snapshot takes time too.
77-
snapshotInterval := 25 * time.Millisecond
7879
conversation := st.NewConversation(ctx, st.ConversationConfig{
7980
AgentIO: process,
8081
GetTime: func() time.Time {
@@ -84,17 +85,7 @@ func NewServer(ctx context.Context, agentType mf.AgentType, process *termexec.Pr
8485
ScreenStabilityLength: 2 * time.Second,
8586
FormatMessage: formatMessage,
8687
})
87-
conversation.StartSnapshotLoop(ctx)
8888
emitter := NewEventEmitter(1024)
89-
go func() {
90-
for {
91-
emitter.UpdateStatusAndEmitChanges(conversation.Status())
92-
emitter.UpdateMessagesAndEmitChanges(conversation.Messages())
93-
emitter.UpdateScreenAndEmitChanges(conversation.Screen())
94-
time.Sleep(snapshotInterval)
95-
}
96-
}()
97-
9889
s := &Server{
9990
router: router,
10091
api: api,
@@ -112,6 +103,18 @@ func NewServer(ctx context.Context, agentType mf.AgentType, process *termexec.Pr
112103
return s
113104
}
114105

106+
func (s *Server) StartSnapshotLoop(ctx context.Context) {
107+
s.conversation.StartSnapshotLoop(ctx)
108+
go func() {
109+
for {
110+
s.emitter.UpdateStatusAndEmitChanges(s.conversation.Status())
111+
s.emitter.UpdateMessagesAndEmitChanges(s.conversation.Messages())
112+
s.emitter.UpdateScreenAndEmitChanges(s.conversation.Screen())
113+
time.Sleep(snapshotInterval)
114+
}
115+
}()
116+
}
117+
115118
// registerRoutes sets up all API endpoints
116119
func (s *Server) registerRoutes() {
117120
// GET /status endpoint

lib/httpapi/server_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
func normalizeSchema(t *testing.T, schema any) any {
2020
t.Helper()
2121
switch val := (schema).(type) {
22+
case *any:
23+
normalizeSchema(t, *val)
2224
case []any:
2325
for i := range val {
2426
normalizeSchema(t, &val[i])

0 commit comments

Comments
 (0)