Skip to content

test(proxy): integration tests for session correlation audit and header agreement#199

Open
SasSwart wants to merge 8 commits into
mainfrom
sasswart/test-session-correlation-integration
Open

test(proxy): integration tests for session correlation audit and header agreement#199
SasSwart wants to merge 8 commits into
mainfrom
sasswart/test-session-correlation-integration

Conversation

@SasSwart
Copy link
Copy Markdown
Contributor

@SasSwart SasSwart commented May 1, 2026

PR Map

  1. feat(audit): session ID generation, sequence counter, and BoundaryLog wiring #196
  2. feat(config): session correlation header injection configuration #197
  3. feat(proxy): inject session ID and sequence number headers on matching requests #198
  4. 👉🏼 test(proxy): integration tests for session correlation audit and header agreement #199

RFC: Bridge ↔ Boundaries Correlation

Integration tests for session correlation, requested during review of #196. The existing unit tests in #198 verify header injection and audit capture independently; these tests verify both sides together across realistic multi-request scenarios.

Depends on #201.

Changes

  • proxy/proxy_session_correlation_integration_test.go: New test file with 8 integration tests and supporting helpers.

Test scenarios

Test What it verifies
LLMRequestAuditAndHeadersAgree Audit sequence number == forwarded header value on inject-target requests
NonLLMRequestAuditedWithoutHeaders Allowed non-inject-target requests are audited but carry no correlation headers
DeniedRequestAuditedNeverForwarded Denied requests consume a sequence number but are never forwarded
MixedRequestsSequenceOrdering Interleaved LLM, non-LLM, and denied requests advance the counter monotonically
SequenceGapRevealsAgenticLoop Gap between two LLM sequence numbers equals the count of intermediate tool-use requests
SpoofedHeadersOverwrittenWithCorrectSequence Client-supplied headers are replaced; audit event still agrees with header
DisabledCorrelationNoHeadersNoPreallocatedSequence Disabled correlation means no headers and no pre-allocated sequence number
ConcurrentRequestsUniqueSequenceNumbers 10 concurrent requests each get a unique, dense sequence number

Test helpers

  • multiRequestCapturingBackend: like the existing headerCapturingBackend but records headers from every request (not just the last), needed for multi-request scenarios.
  • sessionCorrelationIntegrationSetup: shared setup that wires a proxy with two httptest backends (LLM inject target + non-LLM), a capturingAuditor, and a shared SequenceCounter.

Note

This PR was authored by Coder Agents.

@SasSwart SasSwart force-pushed the sasswart/feat-proxy-inject-session-headers branch 2 times, most recently from d8635fb to 79d6485 Compare May 7, 2026 14:33
@SasSwart SasSwart force-pushed the sasswart/test-session-correlation-integration branch from ae01776 to 4a1655f Compare May 7, 2026 17:21
@SasSwart SasSwart changed the base branch from sasswart/feat-proxy-inject-session-headers to sasswart/refactor-unify-inject-target-matching May 12, 2026 10:11
Base automatically changed from sasswart/refactor-unify-inject-target-matching to sasswart/feat-proxy-inject-session-headers May 12, 2026 12:24
Base automatically changed from sasswart/feat-proxy-inject-session-headers to main May 13, 2026 08:56
@SasSwart SasSwart marked this pull request as draft May 13, 2026 09:39
@SasSwart SasSwart marked this pull request as draft May 13, 2026 09:39
@SasSwart SasSwart marked this pull request as draft May 13, 2026 09:39
Copy link
Copy Markdown
Contributor Author

@SasSwart SasSwart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things to address before I can request external review.

Comment thread proxy/proxy_session_correlation_integration_test.go
// integration test: the proxy, auditor, backend(s), and sequence
// counter. Tests build one via newSessionCorrelationIntegrationSetup
// and tear it down with stop.
type sessionCorrelationIntegrationSetup struct {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a fan of this name. What is a setup?

Comment thread proxy/proxy_session_correlation_integration_test.go Outdated
// counter. Tests build one via newSessionCorrelationIntegrationSetup
// and tear it down with stop.
type sessionCorrelationIntegrationSetup struct {
pt *ProxyTest
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like a smell that this wraps ProxyTest.

Comment thread proxy/proxy_session_correlation_integration_test.go Outdated
Comment on lines +220 to +224
events := aud.getRequests()
require.Len(t, events, 1)
require.False(t, events[0].Allowed)
require.NotNil(t, events[0].SequenceNumber)
assert.Equal(t, int32(0), events[0].SequenceNumber)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do this set of assertions in almost every test. do we need a helper? would that shorten the tests?

Comment thread proxy/proxy_session_correlation_integration_test.go Outdated
Comment thread proxy/proxy_session_correlation_integration_test.go Outdated
Comment thread proxy/proxy_session_correlation_integration_test.go Outdated
InjectTargets: []config.InjectTarget{{Domain: llmURL.Hostname()}},
}),
WithSessionID("should-not-appear"),
// Explicitly do NOT set WithSequenceCounter; seqCounter is nil.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we still set seqCounter even when correlation is disabled? This might not be a valid way to test.

@SasSwart SasSwart marked this pull request as ready for review May 13, 2026 12:14
@SasSwart SasSwart requested a review from dannykopping May 14, 2026 07:39
SasSwart added 7 commits May 14, 2026 10:25
…er agreement

Add integration tests that verify the core invariants of session
correlation across the proxy, auditor, and forwarded request headers
working together. These tests fill the gap identified during review
of the session correlation PR stack (#196, #197, #198) where unit
tests verified each component in isolation but did not verify them
in concert.

New test file: proxy/proxy_session_correlation_integration_test.go

Tests added:
- LLMRequestAuditAndHeadersAgree: audit sequence number matches
  the forwarded header value on inject-target requests.
- NonLLMRequestAuditedWithoutHeaders: allowed non-inject-target
  requests are audited but carry no correlation headers.
- DeniedRequestAuditedNeverForwarded: denied requests consume a
  sequence number but are never forwarded.
- MixedRequestsSequenceOrdering: interleaved LLM, non-LLM, and
  denied requests all advance the counter monotonically.
- SequenceGapRevealsAgenticLoop: gap between two LLM sequence
  numbers precisely equals intermediate tool-use requests.
- SpoofedHeadersOverwrittenWithCorrectSequence: client-supplied
  headers are replaced and the audit event still agrees.
- DisabledCorrelationNoHeadersNoPreallocatedSequence: disabled
  correlation means no headers and no pre-allocated sequence.
- ConcurrentRequestsUniqueSequenceNumbers: concurrent requests
  each get a unique, dense sequence number.
…ames and sequence number type

Modified integration tests to reflect changes in session correlation header names and updated the sequence number type from uint64 to int32. Adjusted assertions in tests to ensure consistency with the new data types and header configurations, enhancing clarity and correctness in the test suite.
- Remove '// ---------- Integration Tests ----------' section separator
- Rename 'hdr'/'Hdr' variables to 'header'/'Header' for clarity
- Rename 'llm'/'llmBackend' to 'injectBackend'/'inject'/'backend'
  to reflect the actual concept (inject target) rather than a
  specific use case (LLM)
- Update comments to match the new naming

Generated by Coder Agents
…n integration tests

- Enhanced comments for clarity regarding the purpose of `injectBackend` and `otherBackend`.
- Removed unnecessary comments to streamline the test code.
- Adjusted formatting for consistency and readability in the `sessionCorrelationIntegrationSetup` struct.

These changes aim to improve the maintainability and understanding of the integration tests related to session correlation.
- Rename sessionCorrelationIntegrationSetup to correlationTestEnv
  and newSessionCorrelationIntegrationSetup to newCorrelationTestEnv
  for brevity and clarity.
- Rename TestIntegration_DisabledCorrelationNoHeadersNoPreallocatedSequence
  to TestIntegration_DisabledCorrelationNoHeaders. The sequence counter
  is a value type on the proxy server and always increments regardless
  of the correlation setting, so the previous name and assertions about
  'no pre-allocated sequence number' were misleading. The test now
  focuses on what actually differs: no headers are injected.
- Remove misleading 'auditor falls back to its own counter' comment.

Generated by Coder Agents
PR #201 was merged to main, replacing config.InjectTarget struct with
[]string rule specs (rulesengine syntax). Update the integration test
file to use the []string format, and sync config/, proxy/proxy.go,
and other test files from main to fix the build.

Generated by Coder Agents
@SasSwart SasSwart force-pushed the sasswart/test-session-correlation-integration branch from 11b11c0 to f578460 Compare May 14, 2026 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant