[test] Add tests for server.resolveGuardPolicy and normalizeScopeKind#2092
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
[test] Add tests for server.resolveGuardPolicy and normalizeScopeKind#2092github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
Adds comprehensive test coverage for two under-tested functions in internal/server/unified.go: - normalizeScopeKind: 10 test cases covering nil input, empty map, missing scope_kind field, uppercase/mixed-case normalization, leading/ trailing whitespace trimming, non-string scope_kind values, preservation of other fields, and immutability of the input map. - resolveGuardPolicy: 20 test cases covering all code paths including nil config (legacy), global policy override (with default/custom source, and invalid policy), server not found, nil server config, valid/invalid server guard-policies, Guard field pointing to missing/nil/policy-less/ valid/invalid guard configs. - resolveWriteSinkPolicy: 4 test cases covering no policy, write-sink policy, allow-only policy (nil write-sink), error from resolveGuardPolicy, and nil config. 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:
resolveGuardPolicyandnormalizeScopeKindFunctions Analyzed
internal/serverresolveGuardPolicy,normalizeScopeKind,resolveWriteSinkPolicyinternal/server/unified.goresolveGuardPolicyhas 11 distinct code paths;normalizeScopeKindis a pure normalizer with type-dispatch)Why These Functions?
resolveGuardPolicy(42 lines, 11 code paths) had only 1 of 11 paths tested inguard_policy_parsing_test.go. It drives all DIFC guard policy resolution and is called on every tool invocation when DIFC is enabled.normalizeScopeKindhad zero tests despite being called during guard session initialization.Tests Added
New file:
internal/server/resolve_guard_policy_test.go— 32 test casesnormalizeScopeKind(10 tests)nilinput returnsnilscope_kindfield — other fields preservedscope_kindalready lowercase — unchangedscope_kinduppercase → lowercasedscope_kindwith leading/trailing spaces → trimmedscope_kinduppercase + spaces → trimmed and lowercasedscope_kind→ preserved unchangedscope_kindresolveGuardPolicy(18 tests)cfg→ returns("legacy", nil, nil)"override"source"cli")"env"sourcecfg.Servers→"legacy""legacy"guard-policies→"server"sourceguard-policies(missingmin-integrity) → errorguard-policies, emptyGuardfield →"legacy"Guardset but not incfg.Guards→"legacy"Guardset,cfg.Guards[name]is nil →"legacy"Guardset, guard config has nilPolicy→"legacy"Guardset, guard config has valid AllowOnly policy →"config"sourceGuardset, guard config has valid WriteSink policy →"config"sourceGuardset, guard config has invalid policy (empty) → errorcfg.Serversmap →"legacy"resolveWriteSinkPolicy(4 tests)WriteSinkPolicyresolveGuardPolicy→ nilCoverage Improvement
normalizeScopeKindresolveGuardPolicyresolveWriteSinkPolicyGenerated by Test Coverage Improver
Warning
The following domain was blocked by the firewall during workflow execution:
proxy.golang.orgTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.