Fix redundant CD detection for SSH runtime #432
Merged
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.
Problem
The bash tool was not properly detecting redundant
cdcommands when using SSH runtime. The original code usedpath.resolve()which only works for local filesystem paths, causing it to fail when paths were on a remote SSH server.Root Cause
path.resolve()is a Node.js API that only understands the local filesystem and can't normalize remote SSH paths correctly.Solution
Delegate path normalization to the Runtime interface instead of having the bash tool understand different runtime types.
normalizePath()method to Runtime interface: Each runtime can handle its own path semanticspath.resolve()for local pathsconfig.runtime.normalizePath()This maintains better separation of concerns - the bash tool doesn't need to know about SSH vs Local runtime specifics.
Test Coverage
Added 6 comprehensive tests specifically for SSH runtime:
cd /home/user/project)cd .)cd ~/project)cd ~)cd /path/)All 52 tests pass (46 existing + 6 new)
Changes
src/runtime/Runtime.ts: AddednormalizePath()interface method (+19 lines)src/runtime/LocalRuntime.ts: Implemented for local paths (+10 lines)src/runtime/SSHRuntime.ts: Implemented for remote POSIX paths (+35 lines)src/services/tools/bash.ts: Simplified to delegate to runtime (-59 lines)src/services/tools/bash.test.ts: Added SSH runtime test suite (+136 lines)Before vs After
Before (Broken)
After (Fixed)
Benefits