Skip to content

Commit 0878e31

Browse files
Add the home dir command to the preprocessor
1 parent eca0673 commit 0878e31

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**AI-Powered Windows Crash Dump Analysis Platform**
44

5-
[![Tests](https://img.shields.io/badge/tests-1,853%20total-brightgreen?style=flat-square)](https://github.com/CapulusCodeNinja/mcp_nexus)
5+
[![Tests](https://img.shields.io/badge/tests-1,862%20total-brightgreen?style=flat-square)](https://github.com/CapulusCodeNinja/mcp_nexus)
66
[![Coverage](https://img.shields.io/badge/coverage-62.62%25-good?style=flat-square)](https://github.com/CapulusCodeNinja/mcp_nexus)
77
[![Build](https://img.shields.io/badge/build-0%20warnings-brightgreen?style=flat-square)](https://github.com/CapulusCodeNinja/mcp_nexus)
88
[![License](https://img.shields.io/badge/license-Apache%202.0-blue?style=flat-square)](LICENSE)
@@ -317,7 +317,7 @@ dotnet test --filter "Notification"
317317

318318
### Test Statistics
319319

320-
-**1,853 total tests** (1,853 passing)
320+
-**1,862 total tests** (1,862 passing)
321321
-**62.62% line coverage** with comprehensive analysis testing
322322
-**0 warnings** in build (clean codebase)
323323
-**17+ test categories** covering all major functionality including Extensions

mcp_nexus/Utilities/CommandPreprocessor.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,32 @@ public string PreprocessCommand(string command)
114114
}
115115

116116
// Handle !homedir (set home directory for extensions and configuration) - ensure directory exists
117+
// Convert backslashes to forward slashes to work around CDB's path handling quirks
117118
else if (result.StartsWith("!homedir", StringComparison.OrdinalIgnoreCase))
118119
{
119-
var match = Regex.Match(result, @"^!homedir\s+(.+)$", RegexOptions.IgnoreCase);
120+
var match = Regex.Match(result, @"^(!homedir\s+)(.+)$", RegexOptions.IgnoreCase);
120121
if (match.Success)
121122
{
122-
var path = match.Groups[1].Value.Trim().Trim('"').Trim('\'');
123+
var commandPrefix = match.Groups[1].Value;
124+
var pathArg = match.Groups[2].Value;
125+
var hasQuotes = pathArg.StartsWith('"') && pathArg.EndsWith('"');
126+
var path = pathArg.Trim().Trim('"').Trim('\'');
127+
128+
// Ensure directory exists before converting slashes
123129
EnsureDirectoryExists(path);
130+
131+
// Convert backslashes to forward slashes (CDB handles these better)
132+
var pathWithForwardSlashes = path.Replace('\\', '/');
133+
134+
// Reconstruct command with forward slashes
135+
if (hasQuotes)
136+
{
137+
result = $"{commandPrefix}\"{pathWithForwardSlashes}\"";
138+
}
139+
else
140+
{
141+
result = $"{commandPrefix}{pathWithForwardSlashes}";
142+
}
124143
}
125144
}
126145

mcp_nexus_tests/Utilities/CommandPreprocessorTests.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ public void PreprocessCommand_WithExistingDirectory_DoesNotFail()
202202
}
203203

204204
[Theory]
205-
[InlineData("!homedir C:\\my\\home\\dir", "!homedir C:\\my\\home\\dir")]
206-
[InlineData("!homedir \"C:\\my\\home\\dir\"", "!homedir \"C:\\my\\home\\dir\"")]
207-
[InlineData("!homedir /mnt/c/my/home/dir", "!homedir C:\\my\\home\\dir")]
208-
[InlineData("!homedir /mnt/analysis/test-path", "!homedir C:\\analysis\\test-path")]
209-
[InlineData("!homedir /mnt/share/folder", "!homedir C:\\share\\folder")]
210-
[InlineData("!homedir \"/mnt/share/folder\"", "!homedir \"C:\\share\\folder\"")]
211-
[InlineData("!HOMEDIR C:\\test", "!HOMEDIR C:\\test")]
205+
[InlineData("!homedir C:\\my\\home\\dir", "!homedir C:/my/home/dir")]
206+
[InlineData("!homedir \"C:\\my\\home\\dir\"", "!homedir \"C:/my/home/dir\"")]
207+
[InlineData("!homedir /mnt/c/my/home/dir", "!homedir C:/my/home/dir")]
208+
[InlineData("!homedir /mnt/analysis/test-path", "!homedir C:/analysis/test-path")]
209+
[InlineData("!homedir /mnt/share/folder", "!homedir C:/share/folder")]
210+
[InlineData("!homedir \"/mnt/share/folder\"", "!homedir \"C:/share/folder\"")]
211+
[InlineData("!HOMEDIR C:\\test", "!HOMEDIR C:/test")]
212212
public void PreprocessCommand_Homedir_ConvertsWslPaths(string input, string expected)
213213
{
214214
// Arrange
@@ -235,6 +235,7 @@ public void PreprocessCommand_Homedir_CreatesDirectoryIfNotExists()
235235
// Arrange
236236
var tempDir = Path.Combine(Path.GetTempPath(), "test_homedir_" + Guid.NewGuid().ToString("N")[..8]);
237237
var input = $"!homedir {tempDir}";
238+
var expectedPath = tempDir.Replace('\\', '/');
238239

239240
try
240241
{
@@ -248,7 +249,7 @@ public void PreprocessCommand_Homedir_CreatesDirectoryIfNotExists()
248249
var result = m_CommandPreprocessor.PreprocessCommand(input);
249250

250251
// Assert
251-
Assert.Equal($"!homedir {tempDir}", result);
252+
Assert.Equal($"!homedir {expectedPath}", result);
252253
Assert.True(Directory.Exists(tempDir), "Directory should be created automatically");
253254
}
254255
finally
@@ -267,6 +268,7 @@ public void PreprocessCommand_Homedir_WithExistingDirectory_DoesNotFail()
267268
// Arrange
268269
var tempDir = Path.Combine(Path.GetTempPath(), "test_homedir_existing_" + Guid.NewGuid().ToString("N")[..8]);
269270
var input = $"!homedir \"{tempDir}\"";
271+
var expectedPath = tempDir.Replace('\\', '/');
270272

271273
try
272274
{
@@ -277,7 +279,7 @@ public void PreprocessCommand_Homedir_WithExistingDirectory_DoesNotFail()
277279
var result = m_CommandPreprocessor.PreprocessCommand(input);
278280

279281
// Assert
280-
Assert.Equal($"!homedir \"{tempDir}\"", result);
282+
Assert.Equal($"!homedir \"{expectedPath}\"", result);
281283
Assert.True(Directory.Exists(tempDir), "Directory should still exist");
282284
}
283285
finally

0 commit comments

Comments
 (0)