Skip to content

[test] Add tests for config.isDynamicTOMLPath and proxy.truncateForLog#3500

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
test/coverage-isDynamicTOMLPath-truncateForLog-ef8f1b8ed68f335b
Draft

[test] Add tests for config.isDynamicTOMLPath and proxy.truncateForLog#3500
github-actions[bot] wants to merge 1 commit intomainfrom
test/coverage-isDynamicTOMLPath-truncateForLog-ef8f1b8ed68f335b

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Test Coverage Improvement: isDynamicTOMLPath and truncateForLog

Functions Analyzed

Package Function Previous Coverage New Coverage Complexity
internal/config isDynamicTOMLPath 0% ~100% Medium
internal/proxy truncateForLog 0% ~100% Low

Why 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 for servers.<n>.guard_policies and len >= 4 for guards.<n>.config).

  • truncateForLog (internal/proxy/graphql.go) — Used by extractSearchQuery for 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.goTestIsDynamicTOMLPath (19 cases)

  • servers.<name>.guard_policies path at minimum length 5
  • servers.<name>.guard_policies path longer than minimum
  • servers.<name>.guard_policies with length 4 (too short → false)
  • ✅ Wrong key[0] and key[2] values
  • guards.<name>.config path at minimum length 4
  • guards.<name>.config with length 3 (too short → false)
  • ✅ Wrong key[0] and key[2] values for guards path
  • nil key, empty key, ordinary config paths (gateway.port, servers.github.command, etc.)

internal/proxy/graphql_test.goTestTruncateForLog (16 cases)

  • maxRunes ≤ 0 returns empty string
  • ✅ Empty string with positive maxRunes returns empty string
  • ✅ String shorter than or equal to maxRunes returned unchanged
  • ✅ ASCII truncation at exact boundary
  • ✅ Unicode (CJK, €, emoji) truncated by rune count, not byte count
  • ✅ Mixed ASCII + Unicode truncated at correct rune boundary

Coverage Report

Before: isDynamicTOMLPath  0%   (0/11 statements)
After:  isDynamicTOMLPath  ~100% (all branches covered)

Before: truncateForLog     0%   (0/5 statements)  
After:  truncateForLog     ~100% (all 3 branches covered)

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

Generated by Test Coverage Improver · ● 9.7M ·

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants