Conversation
…owOnlyPolicy Comprehensive table-driven tests covering all branches of the three guard policy parsing functions in internal/config/guard_policy.go, which had zero test coverage: - ParsePolicyMap: nil/empty map, modern allow-only/write-sink format, legacy repos+min-integrity format, error paths, key precedence - ParseServerGuardPolicy: nil/empty raw, top-level parse, server-ID nested lookup, single-key fallback, error propagation - BuildAllowOnlyPolicy: no-op nil return, repo-without-owner error, multiple-scope error, missing integrity, invalid integrity, all four valid integrity values, public/owner/owner+repo scopes, whitespace trimming Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds comprehensive Go test coverage for security-critical guard policy parsing/building helpers in internal/config, targeting historically untested branching/error paths.
Changes:
- Introduces table-driven tests for
ParsePolicyMap,ParseServerGuardPolicy, andBuildAllowOnlyPolicy. - Adds focused tests for legacy-vs-modern parsing behaviors and precedence rules.
- Validates acceptance of all supported
min-integrityvalues and key edge cases (trimming, conflicts, missing fields).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+571
to
+590
| // TestParseServerGuardPolicy_PreferServerIDOverSingleKey verifies that | ||
| // a policy nested under the exact server ID is preferred over the single-key | ||
| // fallback when both are available. | ||
| func TestParseServerGuardPolicy_PreferServerIDOverSingleKey(t *testing.T) { | ||
| // The server-id key "github" contains a valid policy. | ||
| // The single-key fallback would also find "github" since it's the only key. | ||
| raw := map[string]interface{}{ | ||
| "github": map[string]interface{}{ | ||
| "allow-only": map[string]interface{}{ | ||
| "repos": "public", | ||
| "min-integrity": "none", | ||
| }, | ||
| }, | ||
| } | ||
| got, err := ParseServerGuardPolicy("github", raw) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, got) | ||
| require.NotNil(t, got.AllowOnly) | ||
| assert.Equal(t, "public", got.AllowOnly.Repos) | ||
| } |
There was a problem hiding this comment.
TestParseServerGuardPolicy_PreferServerIDOverSingleKey doesn’t actually verify precedence between the server-ID lookup and the single-key fallback: with a single key equal to serverID, both paths parse the same nested map and yield the same result. Consider rewriting it to assert an observable difference (or rename/remove it) so the test name/comment match what’s being validated.
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: Guard Policy Parsing Functions
Functions Analyzed
internal/configParsePolicyMap,ParseServerGuardPolicy,BuildAllowOnlyPolicyWhy These Functions?
All three functions in
internal/config/guard_policy.gohad zero test coverage despite being security-critical code that:AllowOnlypolicies from CLI/env-var parametersThey each have significant branching logic (7–10+ branches) with error paths that were completely untested.
Tests Added
TestParsePolicyMap(11 cases): nil/empty map, modernallow-only/write-sinkformats, legacyrepos+min-integrity/repos+integrityformat, error pathsTestParseServerGuardPolicy(12 cases): nil/empty raw, top-level direct parse, server-ID nested lookup, single-key fallback, multi-key no-match, error propagationTestBuildAllowOnlyPolicy(11 cases): no-op nil return, repo-without-owner, multiple-scope conflict, missing/invalid integrity, all valid scopes (public/owner/owner+repo), whitespace trimmingTestBuildAllowOnlyPolicy_AllIntegrityValues: Parameterized check that all 4 valid integrity levels (none,unapproved,approved,merged) are acceptedTestParsePolicyMap_LegacyMinIntegrityTakesPrecedence: Verifiesmin-integritywins overintegritywhen both presentTestParseServerGuardPolicy_PreferServerIDOverSingleKey: Verifies server-ID lookup is preferredTestParseServerGuardPolicy_TopLevelPolicyNotNestedUnderServerID: Verifies top-level parse pathCoverage Report
Notes
Tests are structurally valid (verified with
gofmt) and follow existing patterns fromguard_policy_test.go(same package, testify assert/require, table-driven). Full execution and CI coverage confirmation will occur in this PR's CI run.Generated by Test Coverage Improver
Next run will target:
internal/guard.LabelResponseorinternal/guard.callWasmFunction