const test = require('node:test'); const assert = require('node:assert/strict'); const { shellQuote, sshBlock, sshConfigPathWord, sshIncludeTarget, sshConfigWord, windowsCommandWord } = require('./extension'); test('posix ssh config words use shell quoting', () => { assert.equal( sshConfigWord('/Users/palav/My App/dosh', 'darwin'), "'/Users/palav/My App/dosh'" ); assert.equal(shellQuote("say 'hi'"), "'say '\\''hi'\\'''"); }); test('windows ssh config words use Windows command quoting', () => { assert.equal( sshConfigWord('C:\\Program Files\\Dosh\\dosh.exe', 'win32'), '"C:\\Program Files\\Dosh\\dosh.exe"' ); assert.equal( windowsCommandWord('C:\\path\\before"quote'), '"C:\\path\\before\\"quote"' ); assert.equal( windowsCommandWord('C:\\Program Files\\Dosh\\'), '"C:\\Program Files\\Dosh\\\\"' ); }); test('ssh block quotes proxy command for the target platform', () => { const block = sshBlock({ alias: 'dosh-work', host: 'work host', executable: 'C:\\Program Files\\Dosh\\dosh.exe', targetHost: '127.0.0.1', targetPort: 22, doshPort: 50000, platform: 'win32' }); assert.match( block, /ProxyCommand "C:\\Program Files\\Dosh\\dosh\.exe" --dosh-port 50000 proxy-stdio "work host" %h %p/ ); assert.doesNotMatch(block, /'C:\\Program Files\\Dosh\\dosh\.exe'/); }); test('ssh include target stays relative for generated config beside main config', () => { assert.equal( sshIncludeTarget('/Users/palav/.ssh/config', '/Users/palav/.ssh/config.dosh', 'darwin'), 'config.dosh' ); }); test('ssh include target uses absolute path for custom generated config location', () => { assert.equal( sshIncludeTarget( '/Users/palav/.ssh/config', '/Users/palav/Library/Application Support/Dosh/config.dosh', 'darwin' ), '"/Users/palav/Library/Application Support/Dosh/config.dosh"' ); }); test('ssh include target handles Windows custom generated config paths', () => { assert.equal( sshIncludeTarget( 'C:\\Users\\palav\\.ssh\\config', 'C:\\Users\\palav\\AppData\\Roaming\\Dosh Remote\\config.dosh', 'win32' ), '"C:/Users/palav/AppData/Roaming/Dosh Remote/config.dosh"' ); assert.equal( sshConfigPathWord('C:\\Users\\palav\\.ssh\\config.dosh', 'win32'), 'C:/Users/palav/.ssh/config.dosh' ); });