[test] Add tests for config.isDynamicTOMLPath and proxy.truncateForLog#3500
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
[test] Add tests for config.isDynamicTOMLPath and proxy.truncateForLog#3500github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
Both functions had 0% test coverage. This PR adds comprehensive table-driven tests covering all branches: - isDynamicTOMLPath: 19 test cases covering servers/guard_policies (min len 5), guards/config (min len 4), boundary lengths, wrong prefix/segment values, nil/empty keys, and ordinary paths. - truncateForLog: 16 test cases covering maxRunes ≤ 0 early-exit, strings within limit (unchanged), ASCII truncation, Unicode rune boundary correctness (multi-byte CJK, €, emoji). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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:
isDynamicTOMLPathandtruncateForLogFunctions Analyzed
internal/configisDynamicTOMLPathinternal/proxytruncateForLogWhy These Functions?
Both functions had 0% test coverage as confirmed by static analysis:
isDynamicTOMLPath(internal/config/config_core.go) — Guards the unknown-field validation gate during TOML loading. Incorrect logic here would either reject valid guard configurations or allow unrecognized fields through, creating a security/correctness risk. It has two distinct conditional paths with multiple sub-conditions (len >= 5 forservers.<n>.guard_policiesand len >= 4 forguards.<n>.config).truncateForLog(internal/proxy/graphql.go) — Used byextractSearchQueryfor safe debug logging of GraphQL queries. The function must correctly handle Unicode by counting runes (not bytes), making its correctness non-trivial despite its small size.Tests Added
internal/config/config_core_test.go—TestIsDynamicTOMLPath(19 cases)servers.<name>.guard_policiespath at minimum length 5servers.<name>.guard_policiespath longer than minimumservers.<name>.guard_policieswith length 4 (too short → false)key[0]andkey[2]valuesguards.<name>.configpath at minimum length 4guards.<name>.configwith length 3 (too short → false)key[0]andkey[2]values for guards pathnilkey, empty key, ordinary config paths (gateway.port,servers.github.command, etc.)internal/proxy/graphql_test.go—TestTruncateForLog(16 cases)maxRunes ≤ 0returns empty stringmaxRunesreturns empty stringmaxRunesreturned unchangedCoverage Report
Note: exact numbers cannot be verified in this environment due to Go 1.25.0 toolchain requirement; gofmt passes and no syntax errors detected.
Generated by Test Coverage Improver
Next run will target the next most complex under-tested function