Explorar el Código

test(multiplexer): document and cover Windows path normalization (#568)

Add 'why' comments at both normalization sites (MSYS2/sh -lc backslash corruption) and a unit test asserting win32 backslash→forward-slash normalization in buildOpencodeAttachCommand.
Michael Henke hace 4 semanas
padre
commit
ed22b36413
Se han modificado 3 ficheros con 35 adiciones y 2 borrados
  1. 1 0
      src/multiplexer/herdr/index.ts
  2. 31 2
      src/multiplexer/shared.test.ts
  3. 3 0
      src/multiplexer/shared.ts

+ 1 - 0
src/multiplexer/herdr/index.ts

@@ -83,6 +83,7 @@ export class HerdrMultiplexer implements Multiplexer {
         '--direction',
         this.paneDirection,
         '--cwd',
+        // Normalize Windows backslashes→/ so sh -lc (MSYS2) doesn't corrupt --cwd (issue #568)
         process.platform === 'win32'
           ? directory.replace(/\\/g, '/')
           : directory,

+ 31 - 2
src/multiplexer/shared.test.ts

@@ -41,8 +41,7 @@ describe('gracefulClosePane', () => {
       };
     });
 
-    const { gracefulClosePane } =
-      await importShared();
+    const { gracefulClosePane } = await importShared();
     const ok = await gracefulClosePane('tmux', '%1', {
       ctrlC: ['send-keys', '-t', '%1', 'C-c'],
       close: ['kill-pane', '-t', '%1'],
@@ -103,3 +102,33 @@ describe('gracefulClosePane', () => {
     expect(ok).toBe(false);
   });
 });
+
+describe('buildOpencodeAttachCommand', () => {
+  test('normalizes Windows backslash paths to forward slashes', async () => {
+    const original = process.platform;
+    Object.defineProperty(process, 'platform', {
+      value: 'win32',
+      configurable: true,
+    });
+    try {
+      const { buildOpencodeAttachCommand } = await importShared();
+      const cmd = buildOpencodeAttachCommand(
+        'sess',
+        'url',
+        'C:\\Users\\foo\\repo',
+      );
+      expect(cmd).toContain('C:/Users/foo/repo');
+    } finally {
+      Object.defineProperty(process, 'platform', {
+        value: original,
+        configurable: true,
+      });
+    }
+  });
+
+  test('leaves non-Windows paths unchanged', async () => {
+    const { buildOpencodeAttachCommand } = await importShared();
+    const cmd = buildOpencodeAttachCommand('sess', 'url', '/home/user/repo');
+    expect(cmd).toContain('/home/user/repo');
+  });
+});

+ 3 - 0
src/multiplexer/shared.ts

@@ -17,6 +17,9 @@ export function buildOpencodeAttachCommand(
   serverUrl: string,
   directory: string,
 ): string {
+  // Normalize backslashes to forward slashes on Windows: when the command runs
+  // under sh -lc (MSYS2/Git Bash), backslashes are treated as escape chars and
+  // corrupt the --dir path (issue #568).
   const attachDir =
     process.platform === 'win32' ? directory.replace(/\\/g, '/') : directory;
   return [