@@ -15,6 +15,7 @@ import (
1515 "github.com/coder/agentapi/lib/httpapi"
1616 "github.com/coder/agentapi/lib/logctx"
1717 "github.com/coder/agentapi/lib/msgfmt"
18+ "github.com/stretchr/testify/assert"
1819 "github.com/stretchr/testify/require"
1920)
2021
@@ -631,3 +632,50 @@ func TestServer_CORSPreflightOrigins(t *testing.T) {
631632 })
632633 }
633634}
635+
636+ func TestServer_SSEMiddleware_Events (t * testing.T ) {
637+ t .Parallel ()
638+ ctx := logctx .WithLogger (context .Background (), slog .New (slog .NewTextHandler (os .Stdout , nil )))
639+ srv , err := httpapi .NewServer (ctx , httpapi.ServerConfig {
640+ AgentType : msgfmt .AgentTypeClaude ,
641+ Process : nil ,
642+ Port : 0 ,
643+ ChatBasePath : "/chat" ,
644+ AllowedHosts : []string {"*" },
645+ AllowedOrigins : []string {"*" },
646+ })
647+ require .NoError (t , err )
648+ tsServer := httptest .NewServer (srv .Handler ())
649+ t .Cleanup (tsServer .Close )
650+
651+ t .Run ("events" , func (t * testing.T ) {
652+ t .Parallel ()
653+ resp , err := tsServer .Client ().Get (tsServer .URL + "/events" )
654+ require .NoError (t , err )
655+ t .Cleanup (func () {
656+ _ = resp .Body .Close ()
657+ })
658+ assertSSEHeaders (t , resp )
659+ })
660+
661+ t .Run ("internal/screen" , func (t * testing.T ) {
662+ t .Parallel ()
663+
664+ resp , err := tsServer .Client ().Get (tsServer .URL + "/internal/screen" )
665+ require .NoError (t , err )
666+ t .Cleanup (func () {
667+ _ = resp .Body .Close ()
668+ })
669+ assertSSEHeaders (t , resp )
670+ })
671+ }
672+
673+ func assertSSEHeaders (t testing.TB , resp * http.Response ) {
674+ t .Helper ()
675+ assert .Equal (t , "no-cache, no-store, must-revalidate" , resp .Header .Get ("Cache-Control" ))
676+ assert .Equal (t , "no-cache" , resp .Header .Get ("Pragma" ))
677+ assert .Equal (t , "0" , resp .Header .Get ("Expires" ))
678+ assert .Equal (t , "no" , resp .Header .Get ("X-Accel-Buffering" ))
679+ assert .Equal (t , "no" , resp .Header .Get ("X-Proxy-Buffering" ))
680+ assert .Equal (t , "keep-alive" , resp .Header .Get ("Connection" ))
681+ }
0 commit comments