fix(mcp): Restructure pinned_path error builder to clear unused-variable analysis - #23
Merged
Merged
Conversation
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.
Summary
Fixes GitHub code-scanning alert #2 (CodeQL,
rust/unused-variable) atcrates/ctxctl/src/mcp.rs:459— thekeyparameter ofpinned_pathwas reported unused because the analyzer did not credit its capture into the inline-formatescapeclosure.Change
escapenow takeskey,raw, anddetailas explicit closure parameters instead of capturing them; all 4 call sites insidepinned_pathpasskey/rawexplicitly. Format template unchanged.Byte-identity verification (TDD)
Added characterization tests pinning the exact full error bytes for the reachable rejection branches:
pinned_path_error_strings_are_byte_stable— pins absolute (invalid argument \file`: /etc/passwd: absolute paths are not allowed; path escapes workspace root) and traversal (invalid argument `file`: ../outside.txt: path escapes workspace root`) outputs verbatim; written red against placeholder strings first, then corrected.pinned_path_rejects_drive_relative_component(cfg(windows)) — pins the previously untestedunsupported absolute-like component;branch.Existing fragment-pinning tests stay green unchanged:
absolute_file_arg_is_rejected,traversal_file_arg_is_rejected,symlinked_escape_is_rejected(unit) andabsolute_path_file_arg_is_rejected, traversal test intests/mcp_test.rs. The symlink branch shares the same format template with only its unchanged literaldetaildiffering, so pinned bytes cover it transitively.Sweep
Scanned
crates/for other closures capturing-and-inlining-formatting outer variables. One same-class pattern remains atmcp.rs(require_str'sok_or_else(|| format!("missing or empty argument: {key}"))), but CodeQL does not flag it; left untouched per minimal scope. No other candidates found.Gates
cargo fmt --check— passcargo clippy --all-features -- -D warnings— passcargo test— all suites pass