Conversation
Adds internal/server/ensure_guard_initialized_test.go covering all previously untested branches of two functions in unified.go: normalizeScopeKind (7 tests): - nil input, empty map, map without scope_kind field - scope_kind already lowercase, UPPERCASE, mixed-case+whitespace - non-string scope_kind (type assertion skipped) - immutability guarantee (input map is not modified) ensureGuardInitialized (12 tests): - policy nil → evaluator default mode returned - resolveGuardPolicy error propagation - cache hit → LabelAgent not called a second time - LabelAgent error propagation - LabelAgent nil result error - DIFCMode empty → falls back to evaluator default - DIFCMode valid → overrides evaluator default - DIFCMode invalid → error propagated - new session created when none exists - labels from LabelAgent merged into agentRegistry - stale policy hash → cache invalidation triggers re-init - existing session with nil GuardInit initialised correctly - NormalizedPolicy stored with scope_kind lowercased - multiple serverIDs in same session tracked independently - union semantics: tags from multiple guards additive Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
lpcox
added a commit
that referenced
this pull request
Mar 19, 2026
…sue (#2158) ## Summary Adds a **Guard Filtering Summary** section to the repo-assist Monthly Activity Issue so maintainers can see what objects the guard policy blocked during each run. ## What it looks like When the guard filters objects, the monthly activity issue will include: ```markdown ## Guard Filtering Summary | Type | Count | Resources | |------|-------|-----------| | Issues | 7 | #1711, #2049, #2086, #2087, #2089, #2093, #2100 | | PRs | 7 | #2037, #2042, #2061, #2063, #2064, #2092, #2096 | | Other | 2 | actions_list, get_repository_tree | **Policy**: `repos: [github/*], min-integrity: merged` **Total filtered**: 54 items across 17 tool calls ``` When no filtering occurs, it states "No objects were filtered by the guard policy." ## How it works 1. **New section in issue template** — "Guard Filtering Summary" sits between "Future Work" and "Run History" 2. **New step 6** — Agent reads `/tmp/gh-aw/mcp-logs/rpc-messages.jsonl` via bash, parses `DIFC_FILTERED` entries, groups by type (issues/PRs/other), deduplicates across tool calls 3. **Python one-liner** — Extracts resource descriptions, groups into a JSON summary the agent uses to populate the template ## Motivation From [run 23274488766](https://github.com/github/gh-aw-mcpg/actions/runs/23274488766), 54 objects were silently filtered with `min-integrity: merged`. The agent reported "GitHub API access to private repo issues unavailable" without understanding why. This change gives both the agent and maintainers explicit visibility into guard policy impact.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds direct unit tests in internal/server to cover DIFC session initialization behavior and a small policy normalization helper, improving coverage of high-branch logic in UnifiedServer.ensureGuardInitialized and normalizeScopeKind without relying on integration-style tests.
Changes:
- Introduces focused unit tests for
normalizeScopeKindcovering nil/empty inputs, casing/whitespace normalization, type preservation, and non-mutation behavior. - Adds unit tests for
ensureGuardInitializedcovering policy resolution errors, cache-hit behavior, label_agent error/edge cases, DIFCMode parsing/fallback, session state creation, normalized policy persistence, and union semantics for label merging.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Mar 21, 2026
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:
ensureGuardInitialized+normalizeScopeKindFunctions Analyzed
internal/serverunified.goensureGuardInitialized(~100 LOC, high complexity) +normalizeScopeKindcallBackendTooltests)ensureGuardInitializedhas 10+ distinct branches including caching, error propagation, session creation, label merging, and mode parsingWhy These Functions?
ensureGuardInitializedis the core DIFC session-initialization routine. It:LabelAgentcallsDIFCModestrings from guard resultsDespite being central to DIFC enforcement, it had zero direct test coverage – every branch was reachable only via expensive end-to-end
callBackendToolintegration tests that require a live HTTP backend.normalizeScopeKindis a pure helper with no tests at all.Tests Added
normalizeScopeKind(7 tests):nilinput →niloutputscope_kindfield → copy unchangedscope_kindalready lowercase → unchangedscope_kindUPPERCASE→ lowercasedscope_kindmixed-case + whitespace → trimmed and lowercasedscope_kind→ type assertion skipped, value preservedensureGuardInitialized(12 tests):nil→ evaluator default mode returned, no errorresolveGuardPolicyerror → wrapped error propagatedLabelAgentnot called againLabelAgentreturns error → error propagatedLabelAgentreturnsnilresult → error propagatedDIFCModeempty → falls back to evaluator defaultDIFCModevalid non-empty → overrides evaluator defaultDIFCModeinvalid string → error propagatedGuardInitstate written correctlyLabelAgentmerged intoagentRegistryLabelAgentre-callednilGuardInitmap → map created before writingscope_kindlowercased vianormalizeScopeKindserverIDs tracked independently within the same sessionImplementation Notes
Tests use a lightweight
newMinimalUnifiedServerhelper that constructs aUnifiedServerdirectly (without callingNewUnifiedor starting backend servers), making them fast pure-unit tests with no network or process dependencies.Three new test doubles are introduced:
configurableGuard– configurableLabelAgentreturn values per testcountGuard– wrapsconfigurableGuardto countLabelAgentinvocationsnoopBackendCaller– no-opguard.BackendCallerAll names are distinct from existing test types in the package (
mockGuard,writeSinkTestGuard,labelAgentTestGuard).Generated by Test Coverage Improver
Next run candidates:
resolveGuardPolicyGuards-config path,mcp.initializeHTTPSessionerror branches,config.validateStandardServerConfigHTTP+mounts pathWarning
The following domains were blocked by the firewall during workflow execution:
goproxy.ioproxy.golang.orgsum.golang.orgTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.