Repository navigation
fix(test): size TestDetectionScansUntruncatedResponse for the race detector - #1207
Merged
github-actions[bot] merged 1 commit intoSep 4, 2026
Merged
Conversation
…tector The test added in #1174 failed in both Unit Tests and End-to-End Tests, and the defect is its payload sizing rather than anything it guards. To place a secret past the storage cut it padded the response to storage.DefaultMaxResponseSize+10_000 (~75KB), relying on the 64KB default cap. security.Detector.Scan costs ~5.5us/byte, and the race detector multiplies that by ~24x (measured: 114-137us/byte at 1K-75K). So the scan took ~9.5s against the 5s poll deadline in waitForDetectionMetadata. Because runAsyncDetection only writes metadata on a hit, an over-budget scan surfaces as "timed out waiting for detection metadata" rather than a failed assertion, which is why it read as a logic failure. CI runs -race in both workflows; a plain local run does not. Set the cap explicitly with SetMaxResponseSize(1024) and pad to 4KB instead. The seam is identical - the AWS key sits at bytes [4113, 4133), 3089 bytes past the 1024-byte cut - and truncateResponse honours any positive maxSize with no minimum floor. Runtime drops from ~9.5s to ~0.5s per subtest. Verified: - 5/5 runs under -race, 0.45-0.50s per subtest against the 5s deadline - negative control: moving the detectionSource capture back to after truncateForStorage in both handlers still fails the test at the smaller payload, so it is not passing vacuously - second control: stubbing truncateForStorage to a no-op fails the NotContains assertion, proving the key is genuinely past the cut - whole internal/runtime package green under -race, under the unit-tests.yml invocation and under the e2e-tests.yml -short invocation - headroom measured under CPU oversubscription: still passes at 8x slowdown (2.96-3.76s), breaks only around 10.8x TestDefaultResponseCapAppliesWithoutConfig continues to cover the 64KB default separately, so no coverage is lost.
3 tasks done
Deploying mcpproxy-docs with
|
| Latest commit: |
ba5434f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://dde9fb27.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-activity-truncation-test.mcpproxy-docs.pages.dev |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Follow-up to #1174. Related #1173
Description
TestDetectionScansUntruncatedResponse, added in #1174, fails in bothUnit TestsandEnd-to-End Tests. The defect is the test's payload sizing, not the behaviour it guards — the production change in #1174 is correct and unmodified here.To put a secret past the storage cut, the test padded the response to
storage.DefaultMaxResponseSize+10_000(~75KB) so it could rely on the 64KB default cap.security.Detector.Scancosts ~5.5 µs/byte, and the race detector multiplies that by ~24x (measured 114–137 µs/byte across 1K–75K payloads). The scan therefore took ~9.5s against the 5s poll deadline inwaitForDetectionMetadata.Two things made this read as a logic failure rather than a slow one:
runAsyncDetectionwrites metadata only when something is detected, so an over-budget scan and a scan of the wrong (truncated) text produce the identical symptom:timed out waiting for detection metadata.-racein both workflows; a plain localgo testdoes not. Without-racethe same test passes in 0.48s.What this changes
Test-only, three hunks in one file:
svc.SetMaxResponseSize(1024)in both subtests, instead of leaning on the 64KB default4096bytes instead ofDefaultMaxResponseSize+10_000The seam is identical. The AWS key sits at bytes
[4113, 4133), i.e. 3089 bytes past the 1024-byte cut, andtruncateResponsehonours any positivemaxSizewith no minimum floor. Runtime drops from ~9.5s to ~0.5s per subtest.TestDefaultResponseCapAppliesWithoutConfigstill covers the 64KB default separately, so no coverage is lost.Testing
I have tested these changes locally
I have added/updated tests that prove my fix is effective or my feature works
All existing tests pass
5/5 runs under
-race: 0.45–0.50s per subtest against the 5s deadlineNegative control — moving the
detectionSourcecapture back to aftertruncateForStoragein both handlers still fails the test at the smaller payload (10.07s, both subtests, same timeout message). It is not passing vacuously.Second control — stubbing
truncateForStoragetoreturn response, falsefails theNotContainsassertion, proving the key really is past the cut and the assertion is live.Whole
internal/runtimepackage green under plain-race, under theunit-tests.ymlinvocation, and under thee2e-tests.yml-shortinvocation. No data races.Headroom measured, not assumed: under graded CPU oversubscription the test still passes at an 8x slowdown (2.96–3.76s) and breaks only around 10.8x.
GOMAXPROCS=1changes nothing (0.47s vs 0.46s) — the scan is single-goroutine CPU-bound, so only single-core speed matters.Noted for later, not fixed here
internal/security/mask_test.go:TestMaskTextStaysCheapOnAPayloadFullOfSecretsbuilds a 64KB payload under a hard2 * time.Secondwall-clock assertion. It is safe today —MaskTextcosts ~3.8 µs/byte under-race, ~36x cheaper per byte thanScan, leaving ~8x headroom — but it is the same fragile shape, and it converts into this failure immediately if anyone ever routes masking throughScan.