[test] Add tests for difc.formatIntegrityLevel and difc.formatSecrecyLevel#2329
Closed
github-actions[bot] wants to merge 1 commit intomainfrom
Closed
[test] Add tests for difc.formatIntegrityLevel and difc.formatSecrecyLevel#2329github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
Both functions had zero direct test coverage despite being security-critical helpers used in DIFC violation error messages. Adds 37 test cases covering: - formatIntegrityLevel: all 8 branches (nil/empty tags, merged/merged:scope, approved/approved:scope, unapproved/unapproved:scope, approved-beats-unapproved, merged-beats-all, unknown tag fallback to fmt.Sprintf) - formatSecrecyLevel: all 8 branches (nil/empty tags, bare private, private:scope, empty-scope fallback, longer-scope-wins, multiple-scopes-same-length, scoped-beats-bare, unknown tag fallback to fmt.Sprintf) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
54 tasks
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:
formatIntegrityLevelandformatSecrecyLevelFunction Analyzed
internal/difcformatIntegrityLevel,formatSecrecyLevelinternal/difc/evaluator.go(lines 160–220)TestFormatViolationError)Why These Functions?
Both functions are security-critical helpers used to generate human-readable DIFC violation error messages shown to agents when access is denied. Despite being called on every policy violation, they had zero direct test coverage — they were only touched transitively through
TestFormatViolationError, which doesn't isolate individual branches.formatIntegrityLevelhas 8 meaningful branches (nil/empty input,merged/merged:scope,approved/approved:scope,unapprovedwith guard against downgradingapproved, unknown tag fallback).formatSecrecyLevelhas 8 branches (nil/empty, bareprivate,private:scope, empty-scope edge case, longest-scope selection, tied-length behaviour, scoped beats bare, unknown fallback).Tests Added
merged,approved,unapproved,private,private:scope)approved:all,merged:github,unapproved:all→ base level extracted correctlymergedbeatsapprovedbeatsunapproved; scopedprivatebeats bareprivateunapprovedafterapprovedmust not overwrite the higher levelprivate:scopetags — longest wins; ties keep firstprivate:with empty scope →fmt.Sprintffallbackfmt.Sprintf("%v", tags)Coverage Report
Note on Test Execution
The runtime environment has Go 1.24.13 but the module requires Go 1.25.0, and the module proxy is firewalled, so tests could not be executed locally. The tests are syntactically correct Go in
package difc(same package, accessing unexported functions) and follow all existing project conventions.Generated by Test Coverage Improver
Next run should target
server.logServerGuardPolicies(0% coverage) orserver.executeBackendToolCall(~30% indirect only)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.