[test] Add tests for guard.callWasmFunction buffer retry logic#6359
Merged
lpcox merged 2 commits intoMay 23, 2026
Conversation
Implement TestBufferRetryLogic which was previously skipped with a TODO. The test exercises all major branches of callWasmFunction: - Function not exported from WASM module - Module has no memory section - Input exceeds 8MB maximum - Buffer doubling exhausts 16MB cap (→ exceeds-maximum error) - Size-hint retry path: WASM returns 5MB hint, retries and succeeds - Failed guard (prior trap) refuses further calls Three new WASM binary fixtures are introduced: - alwaysNeg2GuardWasm: exports label_agent+memory, always returns -2/no hint - retryWithHint5MBGuardWasm: returns -2 with 5MB hint until buffer is large enough - funcNoMemoryGuardWasm: exports label_agent but has no memory section Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds concrete unit tests for internal/guard.(*WasmGuard).callWasmFunction to cover its adaptive buffer-retry behavior and key error paths, replacing the previously skipped TODO test. This improves confidence in the guard’s size-hint protocol handling, buffer growth strategy, and permanent-failure semantics after traps.
Changes:
- Added three minimal WASM binary fixtures to deterministically exercise retry behaviors (no-hint doubling, size-hint retry, and “no memory” module).
- Implemented
TestBufferRetryLogicsubtests covering: missing export, missing memory, max input rejection, buffer cap exhaustion, size-hint retry success, and failed-guard immediate refusal.
Show a summary per file
| File | Description |
|---|---|
internal/guard/wasm_test.go |
Adds new WASM fixtures and replaces the skipped retry-logic test with subtests validating callWasmFunction retry/error behavior. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced May 23, 2026
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.
Test Coverage Improvement:
callWasmFunctionFunction Analyzed
internal/guardcallWasmFunction(inwasm_parse.go)t.Skip'd withTODO)Why This Function?
TestBufferRetryLogicwas explicitly skipped inwasm_test.gowith:callWasmFunctionwas recently added as part of the oversized WASMcall_backendresponse handling (size-hint protocol + larger guard buffers). It has high cyclomatic complexity with a 3-attempt retry loop, two distinct growth strategies (hint-based and doubling), a hard 16MB ceiling, and permanent-failure semantics on WASM traps.Tests Added
"not exported from WASM module"error"WASM module has no memory"error"input too large"error (fires before any WASM call)"exceeds maximum"error after 3 retries (4MB→8MB→16MB→32MB>cap)"unavailable after a previous trap"error wrapping originalNew WASM Fixtures
Three new minimal WASM binary fixtures added alongside the test:
alwaysNeg2GuardWasmlabel_agent+memory; always returns −2 with no hintretryWithHint5MBGuardWasmfuncNoMemoryGuardWasmlabel_agentbut has no memory sectionTest Execution
Tests were verified to parse correctly with
gofmt -e. Full execution requires Go 1.25.0 toolchain (the environment only has 1.24.13 with a blocked module proxy).Generated by Test Coverage Improver
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
proxy.golang.orgSee Network Configuration for more information.