Skip to content

Refactor logger persistence wrappers and document env expansion semantics#10086

Merged
lpcox merged 3 commits into
mainfrom
copilot/refactor-semantic-function-clustering
Jul 26, 2026
Merged

Refactor logger persistence wrappers and document env expansion semantics#10086
lpcox merged 3 commits into
mainfrom
copilot/refactor-semantic-function-clustering

Conversation

Copilot AI commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Semantic clustering flagged low-effort cleanup opportunities: thin persistence wrappers in logger internals and potential confusion between two env-expansion paths with different failure semantics. This PR applies those targeted refactors without changing behavior.

  • Logger internals: remove thin writeToFile indirection

    • In internal/logger/tools_logger.go, inlined writeToFile() into LogTools by calling writeJSON(tl.data, 0644) directly.
    • In internal/logger/observed_url_domains_logger.go, removed writeToFile() and inlined serialization + writeJSON(..., 0600) at write sites (init + changed-domain flush path).
  • Env expansion docs: clarify intentional semantic split

    • In internal/envutil/expand_env_args.go, added a cross-reference note to internal/config/expand.go clarifying:
      • envutil expansion passes through missing env vars unchanged
      • config expansion fails on undefined ${VAR}
  • Test alignment with refactor

    • Updated internal/logger/tools_logger_test.go to validate the same file-write success/error paths through writeJSON(...) directly after removing writeToFile().
// Before
return tl.writeToFile()

// After
return tl.writeJSON(tl.data, 0644)

Copilot AI changed the title [WIP] Refactor semantic function clustering analysis based on report Refactor logger persistence wrappers and document env expansion semantics Jul 25, 2026
Copilot finished work on behalf of lpcox July 25, 2026 23:18
Copilot AI requested a review from lpcox July 25, 2026 23:18
@lpcox
lpcox marked this pull request as ready for review July 26, 2026 16:05
Copilot AI review requested due to automatic review settings July 26, 2026 16:05

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.

Pull request overview

Refactors logger persistence paths without intended behavior changes and clarifies environment-expansion semantics.

Changes:

  • Inlines JSON persistence calls in logger implementations.
  • Updates related persistence tests.
  • Documents differing undefined-variable behavior.
Show a summary per file
File Description
internal/logger/tools_logger.go Removes the persistence wrapper.
internal/logger/tools_logger_test.go Tests writeJSON directly.
internal/logger/observed_url_domains_logger.go Inlines serialization and persistence.
internal/envutil/expand_env_args.go Clarifies environment-expansion semantics.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (2)

internal/logger/tools_logger_test.go:258

  • This direct writeJSON test still has the stale TestWriteToFile_WriteFileFails name and comment, even though writeToFile no longer exists. Rename both references to keep test failures searchable against the current symbol.
	err := tl.writeJSON(tl.data, 0644)

internal/logger/tools_logger_test.go:280

  • This test was switched to writeJSON, but the enclosing name and comment still reference the deleted writeToFile method. Rename them to reflect the code path now being tested.
	err := tl.writeJSON(tl.data, 0644)
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Medium


// Write the updated data to file
return tl.writeToFile()
return tl.writeJSON(tl.data, 0644)
Comment thread internal/logger/tools_logger_test.go Outdated
@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — gVisor

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: gVisor (runsc) kernel-level isolation

Part Surface Op Result Expected Status
A MCP reads (list_issues, list_prs, get_file, list_commits) data returned ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) Error[-32602]: unknown tool (gateway allowlist) BLOCKED
C CLI reads (list_issues, get_file_contents) data returned ALLOWED
D CLI REST writes (reaction/star/issue/comment/file) gh: GH_TOKEN not set (auth refused) BLOCKED
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh: GH_TOKEN not set (auth refused) BLOCKED

Overall: PASS

Notes:

  • Gateway exposes exactly 22 read-only tools; all write tools are stripped from the allowlist (enforced via MCP unknown tool error, not backend config).
  • gh CLI has no GH_TOKEN in this runtime, so all REST/GraphQL write attempts fail at authentication.
  • Run: §30179095007

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

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@lpcox

lpcox commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

@copilot Fix the code for all comments in this review thread.

When a review comment includes a suggested change, apply the suggestion exactly.

Do not make changes beyond what is described in the linked review thread.

Copilot AI commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Fix the code for all comments in this review thread.

When a review comment includes a suggested change, apply ...

Implemented the requested fixes from that review thread in commit 30d3e48: updated the jsonFileSink usage example in internal/logger/fileutil.go to show direct writeJSON usage, and renamed the three tools_logger_test.go tests/comments to TestWriteJSON_* so names match the implementation under test.

@github-actions

Copy link
Copy Markdown
Contributor

🔒 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 (issues/PRs/file/commits) data returned ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) Error [-32602]: unknown tool for all 7 BLOCKED
C CLI reads (list_issues, get_file_contents) data returned ALLOWED
D CLI REST writes (6 attempts) gh unauthenticated — no GH_TOKEN BLOCKED
E CLI GraphQL mutations (3 attempts) gh unauthenticated — no GH_TOKEN BLOCKED

Overall: PASS

Note on Part B enforcement: Gateway enforces read-only by only exposing 22 read-only tools (get_*, list_*, search_*, *_read). Write tools absent entirely; attempts return MCP error -32602: unknown tool.

References: §30210811727

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

@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — docker-sbx

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: docker-sbx (KVM-isolated microVM)

Part Surface Op Result Expected Status
A MCP reads (list_issues, list_prs, get_file, list_commits) data returned ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) unknown tool [-32602] for all 7 BLOCKED
C CLI reads via github CLI data returned ALLOWED
D CLI REST writes via gh gh unauthenticated (no GH_TOKEN) — all blocked BLOCKED
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh unauthenticated — all blocked BLOCKED

Overall: PASS

Note on Part B: Write tools absent from gateway tool set (MCP [-32602] unknown tool for all 7 write attempts).

Note on Parts D & E: gh has no GH_TOKEN in this sandbox; REST and GraphQL writes blocked at auth layer.

References: §30210811698

🔒 mcpg read-only stress (docker-sbx runtime) by Read-Only Stress: docker-sbx runtime

@lpcox
lpcox merged commit 653c850 into main Jul 26, 2026
37 of 38 checks passed
@lpcox
lpcox deleted the copilot/refactor-semantic-function-clustering branch July 26, 2026 21:15
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.

[refactor] Semantic Function Clustering Analysis — Refactoring Opportunities

3 participants