Skip to content

test(api): real wiring assertion for chat keepalive correlationId (#14850) - #15254

Merged
diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.52from
yourspraveen:test/14850-keepalive-wiring-assertion
Oct 2, 2026
Merged

diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.52from
yourspraveen:test/14850-keepalive-wiring-assertion

Conversation

@yourspraveen

Copy link
Copy Markdown
Contributor

⚠️ base-red inherited: #15246

Closes #14850

Problem

tests/unit/chat-keepalive-correlation-functional.test.ts calls recordEarlyKeepaliveBytes(correlationId, …) itself before asserting. So it passed whether or not /v1/chat/completions passes correlationId: reqId to withEarlyStreamKeepalive (#14792). It also slept 5 s of real time and polled for up to 20 s.

The file's header justified the self-recording by claiming the test can't see the wrapper's buffer because of a module-instance split. That claim is wrong: the test and the wrapper share one earlyKeepaliveByteBuffer instance, and the wrapper's bytes are visible under the caller's correlation id.

Change (test-only)

  • Wiring assertion (new): calls the real route with an X-Correlation-Id while the upstream is held open, and reads the first frame. It then asserts takeEarlyKeepaliveBytes(correlationId) holds the startup frame. The wrapper only buffers when the route passes correlationId.
  • End-to-end test: kept, minus the self-recording fallback. It releases the upstream, drains the stream, and asserts the persisted call-log row carries the keepalive bytes.
  • No real sleep: the upstream fetch waits on a promise the test releases. The only real wait is the route's own 1 s keepalive threshold for openai/*; the row poll is now capped at 5 s instead of 20 s.

Red / green

RUN="node --import tsx/esm --import ./open-sse/utils/setupPolyfill.ts --import ./tests/_setup/isolateDataDir.ts --test --test-force-exit"
$RUN tests/unit/chat-keepalive-correlation-functional.test.ts
Route correlationId: reqId New wiring test New end-to-end test Original test
present ✔ (1.4 s) ✔ (1.4 s) ✔ (6.0 s)
removed ✖ ✔ ✔ ← tautological

The new test passed 3/3 consecutive runs. Prettier, ESLint and typecheck are clean on the file.

Note for review

The end-to-end test also passes with the route line removed. So the keepalive startup frame reaches streamChunks.client in the persisted row by some other path, not only through the correlation buffer. That's why the wiring assertion, not the end-to-end test, is the regression guard for #14792. I didn't trace that second path here, since it's outside this follow-up's scope.

Thanks @maxmad64bis for #14792.

…egosouzapw#14850)

The previous test re-recorded the keepalive bytes itself before
asserting, so it passed whether or not /v1/chat/completions passes
`correlationId: reqId` to withEarlyStreamKeepalive (diegosouzapw#14792). Its header
also claimed the test could not see the wrapper's buffer because of a
module-instance split; that is not the case: the test and the wrapper
share earlyKeepaliveByteBuffer.

- New wiring test: real route, upstream held open, read the first
  frame, then assert the wrapper buffered its bytes under the caller's
  X-Correlation-Id. Red with the route line removed, green with it.
- End-to-end test kept without the self-recording fallback.
- Upstream held by a promise the test releases instead of a real 5s
  sleep, and the 20s row poll is now 5s. Each test runs in ~1.4s; the
  only real wait is the route's 1s keepalive threshold.

Closes diegosouzapw#14850
@diegosouzapw
diegosouzapw merged commit 82d30cf into diegosouzapw:release/v3.8.52 Oct 2, 2026
15 of 16 checks passed
@diegosouzapw

Copy link
Copy Markdown
Owner

Thanks @yourspraveen — merged into release/v3.8.52; it ships in the next release.

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.

fix(api): chat completions keepalive correlationId test is tautological (follow-up #14792)

2 participants