Skip to content

[test] Add tests for delegation.validatePersistedState - #16675

Merged
lpcox merged 1 commit into
mainfrom
test-coverage/validate-persisted-state-dddc70c924306481
Nov 18, 2026
Merged

lpcox merged 1 commit into
mainfrom
test-coverage/validate-persisted-state-dddc70c924306481

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Function Analyzed

  • Package: internal/delegation
  • Function: validatePersistedState
  • Previous Coverage: 89.7%
  • New Coverage: 100.0%
  • Complexity: High (reasoned estimate based on version/generation gates, schema validation, identity validation, duplicate detection, and deterministic sorting)

Why This Function?

validatePersistedState is security-critical recovery logic that validates persisted delegation identities before any runtime indexes are rebuilt. The baseline report showed several untested duplicate-detection branches despite existing end-to-end recovery tests.

Tests Added

  • Happy-path validation and deterministic handle sorting
  • Unsupported state version and generation mismatch errors
  • Persisted schema validation errors
  • Identity validation against the active envelope
  • Duplicate invocation key, identity handle, and executor bearer rejection
  • Table-driven subtests using the package's existing valid envelope fixtures

Coverage Report

Before: 89.7% function coverage
After:  100.0% function coverage
Improvement: +10.3 percentage points
Overall coverage after: 97.6%

Test Execution

  • go test -count=1 -coverprofile=/tmp/gh-aw/agent/coverage-after.out ./... — passed
  • go test -count=1 ./internal/delegation -run 'TestValidatePersistedState' -v — passed
  • make agent-finished — Go formatting, build, lint fallback, unit tests, and integration tests passed; the Rust guard step was blocked because the runner could not download crates.io metadata due to an external TLS certificate mismatch, and golangci-lint was not installed.

No production code was changed.

Warning

Firewall blocked 4 domains

The following domains were blocked by the firewall during workflow execution:

  • example.com
  • nonexistent.local
  • slow.example.com
  • thishostdoesnotexist12345.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "example.com"
    - "nonexistent.local"
    - "slow.example.com"
    - "thishostdoesnotexist12345.com"

See Network Configuration for more information.

Generated by Test Coverage Improver · copilot · routed: gpt56 xhigh · ~8 AIC · ⊞ 5K · ◷

@lpcox
lpcox marked this pull request as ready for review November 18, 2026 15:32
Copilot AI adaptive review requested due to automatic review settings November 18, 2026 15:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active issues were identified, and the focused table-driven tests cover successful validation, deterministic sorting, rejection paths, and duplicate identity detection.

No open issues 🎉

What changed in this PR

Adds focused unit coverage for internal/delegation.validatePersistedState, improving confidence in persisted delegation-state recovery validation without changing production behavior.

Changes:

  • Covers successful validation and deterministic identity sorting.
  • Covers version, generation, schema, and envelope-validation failures.
  • Covers duplicate invocation keys, identity handles, and executor bearers.
File Description
internal/​delegation/​validate_persisted_state_test.go Adds comprehensive table-driven tests for successful persisted-state validation, deterministic sorting, rejection paths, and duplicate identity detection.

Review effort: Lite (adaptive)

@github-actions

Copy link
Copy Markdown
Contributor Author

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default AWF (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads data ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) refused BLOCKED ⚠️
C CLI reads data ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment) refused BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) refused BLOCKED ⚠️

Overall: INCONCLUSIVE

⚠️ Part B: all 6 targeted write tools (add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request) were absent from the 23-tool catalog exposed by the gateway-backed github CLI (only read tools like list_issues, get_file_contents, issue_read, pull_request_read, etc. are registered). This proves gh-aw's GITHUB_READ_ONLY=1 backend config blocked write registration, but does not independently confirm mcpg's own DIFC/guard write-blocking layer, since no write tool call ever reached a write-capable backend.

⚠️ Parts D/E: gh auth status showed 'You are not logged into any GitHub hosts' — gh is unauthenticated in this environment, so REST/GraphQL write attempts were not attempted per safety rules (would only yield uninformative 401s). The CLI-proxy read surface (Part C) was still exercised successfully via the gateway-backed github CLI on PATH.

No writes leaked. No destructive/irreversible operations were attempted.

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

@lpcox
lpcox merged commit cfff38e into main Nov 18, 2026
28 checks passed
@lpcox
lpcox deleted the test-coverage/validate-persisted-state-dddc70c924306481 branch November 18, 2026 16:02
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.

2 participants