@@ -50,24 +50,24 @@ func (m *multiRequestCapturingBackend) headersAt(i int) http.Header {
5050 return m .all [i ].Clone ()
5151}
5252
53- // sessionCorrelationIntegrationSetup holds the shared objects for an
53+ // correlationTestEnv holds the shared objects for a session-correlation
5454// integration test: the proxy, auditor, backend(s), and sequence
55- // counter. Tests build one via newSessionCorrelationIntegrationSetup
56- // and tear it down with stop.
57- type sessionCorrelationIntegrationSetup struct {
55+ // counter. Tests build one via newCorrelationTestEnv and tear it down
56+ // with stop.
57+ type correlationTestEnv struct {
5858 pt * ProxyTest
5959 auditor * capturingAuditor
6060 seq * audit.SequenceCounter
61- // llmBackend expects headers to be injected as these requests are
62- // expected to be seen by the AI Gateway and then correlated back
63- // to the audit event
61+ // injectBackend expects headers to be injected as these requests
62+ // are expected to be seen by the AI Gateway and then correlated
63+ // back to the audit event.
6464 injectBackend * multiRequestCapturingBackend
6565 // otherBackend does not expect headers to be injected as these
6666 // requests should not be routed through the AI Gateway.
6767 otherBackend * multiRequestCapturingBackend
6868}
6969
70- func (s * sessionCorrelationIntegrationSetup ) stop () {
70+ func (s * correlationTestEnv ) stop () {
7171 s .pt .Stop ()
7272 if s .injectBackend != nil {
7373 s .injectBackend .close ()
@@ -77,12 +77,12 @@ func (s *sessionCorrelationIntegrationSetup) stop() {
7777 }
7878}
7979
80- // newSessionCorrelationIntegrationSetup builds a proxy that allows
81- // traffic to two httptest backends: one that matches an inject target
82- // and one that does not (simulating a generic allowed domain like
83- // github.com). Both backends capture all received request headers.
84- // A capturingAuditor records every audit event for later inspection.
85- func newSessionCorrelationIntegrationSetup (t * testing.T , sessionID string ) * sessionCorrelationIntegrationSetup {
80+ // newCorrelationTestEnv builds a proxy that allows traffic to two
81+ // httptest backends: one that matches an inject target and one that
82+ // does not (simulating a generic allowed domain like github.com).
83+ // Both backends capture all received request headers. A
84+ // capturingAuditor records every audit event for later inspection.
85+ func newCorrelationTestEnv (t * testing.T , sessionID string ) * correlationTestEnv {
8686 t .Helper ()
8787
8888 inject := newMultiRequestCapturingBackend ()
@@ -117,7 +117,7 @@ func newSessionCorrelationIntegrationSetup(t *testing.T, sessionID string) *sess
117117 WithAuditor (aud ),
118118 ).Start ()
119119
120- return & sessionCorrelationIntegrationSetup {
120+ return & correlationTestEnv {
121121 pt : pt ,
122122 auditor : aud ,
123123 seq : seq ,
@@ -132,7 +132,7 @@ func newSessionCorrelationIntegrationSetup(t *testing.T, sessionID string) *sess
132132// the forwarded header.
133133func TestIntegration_LLMRequestAuditAndHeadersAgree (t * testing.T ) {
134134 const sessionID = "e5f6a7b8-0000-0000-0000-000000000000"
135- s := newSessionCorrelationIntegrationSetup (t , sessionID )
135+ s := newCorrelationTestEnv (t , sessionID )
136136 defer s .stop ()
137137
138138 resp , err := s .pt .proxyClient .Get (s .injectBackend .server .URL + "/v1/messages" )
@@ -164,7 +164,7 @@ func TestIntegration_LLMRequestAuditAndHeadersAgree(t *testing.T) {
164164// audited (with a sequence number) but does NOT receive correlation
165165// headers.
166166func TestIntegration_NonLLMRequestAuditedWithoutHeaders (t * testing.T ) {
167- s := newSessionCorrelationIntegrationSetup (t , "test-session" )
167+ s := newCorrelationTestEnv (t , "test-session" )
168168 defer s .stop ()
169169
170170 resp , err := s .pt .proxyClient .Get (s .otherBackend .server .URL + "/pulls" )
@@ -426,7 +426,7 @@ func TestIntegration_SequenceGapRevealsAgenticLoop(t *testing.T) {
426426// sequence number, and the audit event still agrees with the header.
427427func TestIntegration_SpoofedHeadersOverwrittenWithCorrectSequence (t * testing.T ) {
428428 const sessionID = "real-session-uuid"
429- s := newSessionCorrelationIntegrationSetup (t , sessionID )
429+ s := newCorrelationTestEnv (t , sessionID )
430430 defer s .stop ()
431431
432432 req , err := http .NewRequest (http .MethodPost , s .injectBackend .server .URL + "/v1/messages" , nil )
@@ -455,11 +455,13 @@ func TestIntegration_SpoofedHeadersOverwrittenWithCorrectSequence(t *testing.T)
455455 )
456456}
457457
458- // TestIntegration_DisabledCorrelationNoHeadersNoPreallocatedSequence
459- // verifies that when session correlation is disabled, the proxy does
460- // not inject headers and does not pre-allocate sequence numbers (the
461- // auditor falls back to its own counter instead).
462- func TestIntegration_DisabledCorrelationNoHeadersNoPreallocatedSequence (t * testing.T ) {
458+ // TestIntegration_DisabledCorrelationNoHeaders verifies that when
459+ // session correlation is disabled, the proxy does not inject
460+ // correlation headers even for requests that match an inject target.
461+ // Note: the sequence counter is a value type on the proxy server and
462+ // always increments regardless of the correlation setting, so we only
463+ // assert on the absence of headers here.
464+ func TestIntegration_DisabledCorrelationNoHeaders (t * testing.T ) {
463465 backend := newMultiRequestCapturingBackend ()
464466 defer backend .close ()
465467
@@ -471,13 +473,11 @@ func TestIntegration_DisabledCorrelationNoHeadersNoPreallocatedSequence(t *testi
471473 pt := NewProxyTest (t ,
472474 WithCertManager (t .TempDir ()),
473475 WithAllowedDomain (backendURL .Hostname ()),
474- // Correlation disabled; no sequence counter.
475476 WithSessionCorrelation (config.SessionCorrelationConfig {
476477 Enabled : false ,
477478 InjectTargets : []config.InjectTarget {{Domain : backendURL .Hostname ()}},
478479 }),
479480 WithSessionID ("should-not-appear" ),
480- // Explicitly do NOT set WithSequenceCounter; seqCounter is nil.
481481 WithAuditor (aud ),
482482 ).Start ()
483483 defer pt .Stop ()
@@ -487,18 +487,18 @@ func TestIntegration_DisabledCorrelationNoHeadersNoPreallocatedSequence(t *testi
487487 defer resp .Body .Close () //nolint:errcheck
488488 require .Equal (t , http .StatusOK , resp .StatusCode )
489489
490- // No correlation headers.
490+ // No correlation headers injected .
491491 require .Equal (t , 1 , backend .requestCount ())
492492 header := backend .headersAt (0 )
493- assert .Empty (t , header .Get (config .SessionIDHeaderName ))
494- assert .Empty (t , header .Get (config .SequenceNumberHeaderName ))
493+ assert .Empty (t , header .Get (config .SessionIDHeaderName ),
494+ "session ID header must not be injected when correlation is disabled" )
495+ assert .Empty (t , header .Get (config .SequenceNumberHeaderName ),
496+ "sequence number header must not be injected when correlation is disabled" )
495497
496- // Audit event recorded but without a pre-allocated sequence
497- // number (nil), because no SequenceCounter was provided.
498+ // Request is still audited.
498499 events := aud .getRequests ()
499500 require .Len (t , events , 1 )
500- assert .Equal (t , int32 (0 ), events [0 ].SequenceNumber ,
501- "no sequence counter means no pre-allocated sequence number" )
501+ require .True (t , events [0 ].Allowed )
502502}
503503
504504// TestIntegration_ConcurrentRequestsUniqueSequenceNumbers sends
@@ -509,7 +509,7 @@ func TestIntegration_ConcurrentRequestsUniqueSequenceNumbers(t *testing.T) {
509509 const sessionID = "concurrent-session"
510510 const numRequests = 10
511511
512- s := newSessionCorrelationIntegrationSetup (t , sessionID )
512+ s := newCorrelationTestEnv (t , sessionID )
513513 defer s .stop ()
514514
515515 var wg sync.WaitGroup
0 commit comments