Skip to content

[test-improver] Improve tests for middleware jqschema - #16558

Merged
lpcox merged 2 commits into
mainfrom
test-improver/middleware-jqschema-assertions-8933955947d6a783
Nov 15, 2026
Merged

lpcox merged 2 commits into
mainfrom
test-improver/middleware-jqschema-assertions-8933955947d6a783

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

File analyzed

internal/middleware/jqschema_test.go (implementation: internal/middleware/jqschema.go)

Improvements

Several applyJqSchema context tests used conditional assertions (if err != nil { assert... }). They passed whether or not an error was returned, so they verified almost nothing. applyJqSchema checks ctx.Err() before inferring, so a cancelled or expired context always fails deterministically. The tests now assert that:

  • handles context cancellation (TestApplyJqSchema_ErrorCases): require.ErrorIs(err, context.Canceled) and a nil result.
  • respects short context timeout renamed to respects an expired context deadline (TestApplyJqSchema_TimeoutBehavior): uses a deadline already in the past, so the outcome is deterministic. Asserts context.DeadlineExceeded and a nil result. The previous 1ns timeout was racy.
  • canceled context returns error (TestApplyJqSchema_ContextTimeout): require.ErrorIs(err, context.Canceled), the schema inference failed prefix, and a nil result.
  • payloadMetadataToMap: manual if !ok { t.Fatalf(...) } replaced with require.True.

Test-only change. No implementation changes.

Coverage

internal/middleware statement coverage: 97.2% before and after. The gain is in assertion strength, not line count.

Verification

  • gofmt -l internal/middleware/: clean
  • go vet ./internal/middleware/: clean
  • go test -count=3 ./internal/middleware/: pass
  • go test -race -count=1 ./internal/middleware/: pass
  • make agent-finished: Go format, build, vet, and all unit and integration packages pass. It stopped at the Rust guard step (test-rust), which could not fetch crates from crates.io in this sandbox (TLS certificate mismatch). The Rust step is unrelated to this change. golangci-lint was not installed, so lint was skipped.

Notes

I also reviewed internal/proxy/enclave_test.go. It has t.Fatalf inside HTTP handler goroutines, but baseline proxy coverage is already 96.7%, and the two uncovered enclave blocks are unreachable dead code, so I did not change it.

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 Improver · copilot · routed: haiku55 xhigh · ~14 AIC · ⊞ 3K · ◷

Replace weak conditional assertions in applyJqSchema context tests with
deterministic checks. applyJqSchema checks ctx.Err() before inference, so
cancelled and expired contexts always fail; the tests previously passed
whether or not an error was returned.

- Use require.ErrorIs for context.Canceled / context.DeadlineExceeded
- Assert the nil result on failure
- Replace manual t.Fatalf in payloadMetadataToMap with require.True

Co-authored-by: Copilot <[email protected]>
@lpcox
lpcox marked this pull request as ready for review November 15, 2026 03:39
Copilot AI adaptive review requested due to automatic review settings November 15, 2026 03:39

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 review issues are present, and the test-only changes strengthen deterministic coverage without altering production behavior.

No open issues 🎉

What changed in this PR

This test-only PR strengthens applyJqSchema middleware tests by replacing conditional assertions with deterministic checks for context cancellation, expired deadlines, and payload metadata validation. It improves regression detection without changing production behavior.

Changes:

  • Asserts context.Canceled and context.DeadlineExceeded with nil results.
  • Replaces the race-prone 1 ns timeout with an already-expired deadline.
  • Uses require.True for payload metadata type validation.
File Description
internal/​middleware/​jqschema_test.go Strengthens context cancellation and deadline assertions and simplifies payload metadata type validation in middleware tests.

Review effort: Lite (dynamic)

@github-actions

This comment has been minimized.

@lpcox

lpcox commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Copilot AI commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

@copilot address review feedback and fix linting errors https://github.com/github/gh-aw-mcpg/actions/runs/43655468686/job/132687909750?pr=16558

Fixed the lint error by switching to require.ErrorContains. make lint passes with 0 issues; focused middleware tests pass. Commit: 9ebccff.

Copilot AI requested a review from lpcox November 15, 2026 04:03
@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 (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads (issues/PRs/file/commits) data returned ALLOWED ✅
B MCP writes (issue_write/star_repository/add_issue_comment/create_branch/create_or_update_file/create_pull_request) all 6 absent from catalog (\"unknown tool\", code -32602) BLOCKED ⚠️
C CLI reads (same probes via proxied github CLI) data returned ALLOWED ✅
D CLI REST writes not attempted — gh unauthenticated BLOCKED ⚠️
E CLI GraphQL mutations not attempted — gh unauthenticated BLOCKED ⚠️

Overall: INCONCLUSIVE

No write leaked in any probe (reads all succeeded, writes all refused/unavailable). Part B is ⚠️ because the gateway tool catalog exposed only 23 read-only tools — none of the 6 targeted write tools were present at all, so the refusal (\"unknown tool\") proves backend/toolset configuration, not an independent gateway-level DIFC/permission check (per the test's own methodology, absence-only refusal cannot confirm gateway enforcement). Parts D/E are ⚠️ because gh auth status showed no authenticated host in this environment, so REST/GraphQL writes could not be attempted to validate the token-scope boundary. No destructive, irreversible, or benign-leak action was performed.

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

@lpcox
lpcox merged commit c3a70ec into main Nov 15, 2026
30 checks passed
@lpcox
lpcox deleted the test-improver/middleware-jqschema-assertions-8933955947d6a783 branch November 15, 2026 04:22
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.

3 participants