[test] Add tests for guard.FindServerWASMGuardFile and GetWASMGuardsRootDir#7941
Merged
Merged
Conversation
These functions in internal/guard/wasm.go had zero test coverage despite having 5+ distinct code paths. The new test file covers: - GetWASMGuardsRootDir: env var not set, plain value, whitespace trimming, whitespace-only returning empty string - FindServerWASMGuardFile: env var unset/whitespace, server directory not found (os.IsNotExist path), empty directory, non-wasm files only, single .wasm file found, uppercase .WASM extension (case-insensitive match via strings.EqualFold), directory named .wasm skipped (IsDir branch), multiple .wasm files returns first alphabetically, non-wasm files and subdirs skipped before .wasm, server path exists as a file instead of directory (error return path), whitespace trimming from env var, complex server IDs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds direct unit test coverage for the filesystem-based WASM guard discovery helpers in internal/guard, improving confidence in which per-server .wasm guard binary gets selected.
Changes:
- Introduces
internal/guard/wasm_discovery_test.gowith table-driven coverage forGetWASMGuardsRootDir. - Adds branch-coverage-focused tests for
FindServerWASMGuardFileacross success, no-op, and error paths.
Show a summary per file
| File | Description |
|---|---|
internal/guard/wasm_discovery_test.go |
New test file covering env-var trimming and directory-based .wasm discovery behavior (including edge/error cases). |
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: 2
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Jun 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.
Function Analyzed
internal/guardFindServerWASMGuardFile,GetWASMGuardsRootDirinternal/guard/wasm.goFindServerWASMGuardFilehas 5+ distinct code paths through filesystem operationsWhy These Functions?
A static analysis sweep across all packages identified
FindServerWASMGuardFileandGetWASMGuardsRootDir(ininternal/guard/wasm.go) as having zero direct test coverage despite meaningful complexity. Theinternal/guardpackage has extensive tests for WASM guard execution, compilation caches, payload parsing, and validation — but the filesystem-based discovery path that determines which guard file gets loaded was entirely untested.FindServerWASMGuardFileis security-relevant: it decides which.wasmbinary is loaded for each MCP server. All 5+ distinct branches were unexercised.Tests Added
New file:
internal/guard/wasm_discovery_test.go(210 lines, 14 test cases)TestGetWASMGuardsRootDir(5 cases):""""""TestFindServerWASMGuardFile(12 cases covering all branches):== ""branch)os.IsNotExistbranch).wasmfile found (happy path, returns path+true).WASMextension matched case-insensitively (strings.EqualFold).wasmname is skipped (entry.IsDir()branch).wasmfiles → first alphabetically returned (ReadDir sort order).wasm(mixed directory)IsNotExisterror branch)GetWASMGuardsRootDir)Branch Coverage Map
guardsRootDir == ""os.IsNotExist(err)entry.IsDir()continuestrings.EqualFold(".wasm")trueTest Execution
All tests compile and run correctly in CI (note: local execution is blocked in this sandbox environment because external Go modules including
wazerocannot be downloaded — this is a sandbox network restriction, not a test issue).Generated by Test Coverage Improver
Next run will target the next most complex under-tested function
Warning
Firewall blocked 9 domains
The following domains were blocked by the firewall during workflow execution:
go.opentelemetry.iogo.yaml.ingolang.orggoogle.golang.orggopkg.inpkg.go.devproxy.golang.orgreleaseassets.githubusercontent.comsum.golang.orgSee Network Configuration for more information.