[test] Add tests for logger.formatJSONWithoutFields and isEffectivelyEmpty#9793
[test] Add tests for logger.formatJSONWithoutFields and isEffectivelyEmpty#9793github-actions[bot] wants to merge 2 commits into
Conversation
Add a dedicated rpc_format_test.go file that directly tests the formatJSONWithoutFields and isEffectivelyEmpty functions in the logger package. These functions were previously only tested indirectly through the RPC logging infrastructure (formatRPCMessageMarkdown). The new tests: - TestFormatJSONWithoutFields_Direct: 10 cases covering invalid JSON (plain text, empty string, JSON arrays, truncated JSON), field removal edge cases (nil/empty lists, nonexistent fields, remove-all), and empty/non-empty detection of params:null patterns - TestIsEffectivelyEmpty_Direct: 8 cases covering nil/empty maps, params:null, params with various zero-like values (string, bool), and multi-field cases - TestFormatJSONWithoutFields_OutputIsCompact: verifies prettified JSON input is always compacted to a single line with no extra whitespace Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds direct logger formatting tests, though much overlaps existing coverage and valid JSON output is not fully asserted.
Changes:
- Adds table-driven JSON formatting and empty-state tests.
- Tests compact output for formatted JSON.
Show a summary per file
| File | Description |
|---|---|
internal/logger/rpc_format_test.go |
Adds direct tests for logger JSON formatting helpers. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Medium
| if !tt.wantIsValidJSON { | ||
| assert.Equal(t, tt.wantFormatted, gotFormatted, "formatted string mismatch for invalid JSON") | ||
| } else { | ||
| // For valid JSON output, verify it's still valid JSON and not just whitespace | ||
| assert.NotEmpty(t, gotFormatted, "valid JSON result should not be empty string") |
| // TestFormatJSONWithoutFields_Direct tests formatJSONWithoutFields directly, | ||
| // independently of the RPC logging infrastructure. | ||
| func TestFormatJSONWithoutFields_Direct(t *testing.T) { |
🔒 mcpg Read-Only Stress — gVisorSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Gateway tool list: 22 read-only tools exposed; all write tools absent (gateway-filtered). Overall: PASS References: §29851616859
|
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: PASS
References: §29851616717
|
🔒 mcpg Read-Only Stress — docker-sbxSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: PASS
References: §29851616749
|
|
@copilot address review feedback |
Addressed in 46b23b8. I consolidated the duplicated helper coverage into the existing direct tests, removed |
Test Coverage Improvement: logger.formatJSONWithoutFields
Function Analyzed
internal/loggerformatJSONWithoutFieldsandisEffectivelyEmptyinternal/logger/rpc_format.goformatJSONWithoutFields), indirect-only (isEffectivelyEmpty)json.Marshalerror branch that is unreachable by design)Why This Function?
The functions
formatJSONWithoutFieldsandisEffectivelyEmptyinrpc_format.gohad no dedicated test file. They were only exercised indirectly throughformatRPCMessageMarkdowntests inrpc_logger_test.go. Direct tests improve:nilfield lists, JSON arrays (treated as invalid), prettified-input compaction, andparams: false/\"\"(zero-like but non-nil) are now explicitly documented and verifiedreturn jsonStr, false, falseinsideif err := json.Marshal(data); err != nil— this branch is unreachable becausemap[string]interface{}values are always JSON-serializable after successfuljson.UnmarshalTests Added
TestFormatJSONWithoutFields_Direct— 10 table-driven cases:TestIsEffectivelyEmpty_Direct— 8 table-driven cases:params: null(empty),params: \"\"/params: false(non-nil → not empty)params: null(not empty)TestFormatJSONWithoutFields_OutputIsCompact— verifies prettified JSON input is always compacted to a single lineCoverage Report
Test Execution
All tests pass:
Generated by Test Coverage Improver
Next run will target the next most complex under-tested function
Warning
Firewall blocked 7 domains
The following domains were blocked by the firewall during workflow execution:
awmgmcpggo.opentelemetry.iogo.yaml.ingolang.orggoogle.golang.orggopkg.inproxy.golang.orgSee Network Configuration for more information.