d48cda4081
CI / Test (ubuntu-latest, Node 18.x, bun) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, npm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, pnpm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, yarn) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 20.x, bun) (push) Failing after 17m13s
CI / Test (ubuntu-latest, Node 20.x, npm) (push) Failing after 18m42s
CI / Test (ubuntu-latest, Node 20.x, pnpm) (push) Failing after 15m0s
CI / Test (ubuntu-latest, Node 20.x, yarn) (push) Failing after 49m44s
CI / Test (ubuntu-latest, Node 22.x, bun) (push) Failing after 51m55s
CI / Test (ubuntu-latest, Node 22.x, pnpm) (push) Failing after 21m57s
CI / Test (ubuntu-latest, Node 22.x, npm) (push) Failing after 37m39s
CI / Test (ubuntu-latest, Node 22.x, yarn) (push) Failing after 34m7s
CI / Validate Components (push) Failing after 37m15s
CI / Python Tests (push) Failing after 10m1s
CI / Security Scan (push) Failing after 10m1s
CI / Lint (push) Failing after 17m12s
CI / Coverage (push) Failing after 20m19s
CI / Test (macos-latest, Node 18.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, yarn) (push) Has been cancelled
115 lines
3.8 KiB
JavaScript
115 lines
3.8 KiB
JavaScript
'use strict';
|
|
const assert = require('assert');
|
|
const { splitShellSegments } = require('../../scripts/lib/shell-split');
|
|
|
|
console.log('=== Testing shell-split.js ===\n');
|
|
|
|
let passed = 0;
|
|
let failed = 0;
|
|
|
|
function test(desc, fn) {
|
|
try {
|
|
fn();
|
|
console.log(` ✓ ${desc}`);
|
|
passed++;
|
|
} catch (e) {
|
|
console.log(` ✗ ${desc}: ${e.message}`);
|
|
failed++;
|
|
}
|
|
}
|
|
|
|
// Basic operators
|
|
console.log('Basic operators:');
|
|
test('&& splits into two segments', () => {
|
|
assert.deepStrictEqual(splitShellSegments('echo hi && echo bye'), ['echo hi', 'echo bye']);
|
|
});
|
|
test('|| splits into two segments', () => {
|
|
assert.deepStrictEqual(splitShellSegments('echo hi || echo bye'), ['echo hi', 'echo bye']);
|
|
});
|
|
test('; splits into two segments', () => {
|
|
assert.deepStrictEqual(splitShellSegments('echo hi; echo bye'), ['echo hi', 'echo bye']);
|
|
});
|
|
test('single & splits (background)', () => {
|
|
assert.deepStrictEqual(splitShellSegments('sleep 1 & echo hi'), ['sleep 1', 'echo hi']);
|
|
});
|
|
|
|
// Redirection operators should NOT split
|
|
console.log('\nRedirection operators (should NOT split):');
|
|
test('2>&1 stays as one segment', () => {
|
|
const segs = splitShellSegments('cmd 2>&1 | grep error');
|
|
assert.strictEqual(segs.length, 1);
|
|
});
|
|
test('&> stays as one segment', () => {
|
|
const segs = splitShellSegments('cmd &> /dev/null');
|
|
assert.strictEqual(segs.length, 1);
|
|
});
|
|
test('>& stays as one segment', () => {
|
|
const segs = splitShellSegments('cmd >& /dev/null');
|
|
assert.strictEqual(segs.length, 1);
|
|
});
|
|
|
|
// Quoting
|
|
console.log('\nQuoting:');
|
|
test('double-quoted && not split', () => {
|
|
const segs = splitShellSegments('tmux new -d "cd /app && echo hi"');
|
|
assert.strictEqual(segs.length, 1);
|
|
});
|
|
test('single-quoted && not split', () => {
|
|
const segs = splitShellSegments("tmux new -d 'cd /app && echo hi'");
|
|
assert.strictEqual(segs.length, 1);
|
|
});
|
|
test('double-quoted ; not split', () => {
|
|
const segs = splitShellSegments('echo "hello; world"');
|
|
assert.strictEqual(segs.length, 1);
|
|
});
|
|
|
|
// Escaped quotes
|
|
console.log('\nEscaped quotes:');
|
|
test('escaped double quote inside double quotes', () => {
|
|
const segs = splitShellSegments('echo "hello \\"world\\"" && echo bye');
|
|
assert.strictEqual(segs.length, 2);
|
|
});
|
|
test('escaped single quote inside single quotes', () => {
|
|
const segs = splitShellSegments("echo 'hello \\'world\\'' && echo bye");
|
|
assert.strictEqual(segs.length, 2);
|
|
});
|
|
|
|
// Escaped operators outside quotes
|
|
console.log('\nEscaped operators outside quotes:');
|
|
test('escaped && outside quotes not split', () => {
|
|
const segs = splitShellSegments('tmux new-session -d bash -lc cd /app \\&\\& npm run dev');
|
|
assert.strictEqual(segs.length, 1);
|
|
});
|
|
test('escaped ; outside quotes not split', () => {
|
|
const segs = splitShellSegments('echo hello \\; echo bye');
|
|
assert.strictEqual(segs.length, 1);
|
|
});
|
|
|
|
// Complex real-world cases
|
|
console.log('\nReal-world cases:');
|
|
test('tmux new-session with quoted compound command', () => {
|
|
const segs = splitShellSegments('tmux new-session -d -s dev "cd /app && npm run dev"');
|
|
assert.strictEqual(segs.length, 1);
|
|
assert.ok(segs[0].includes('tmux'));
|
|
assert.ok(segs[0].includes('npm run dev'));
|
|
});
|
|
test('chained: tmux ls then bare dev', () => {
|
|
const segs = splitShellSegments('tmux ls; npm run dev');
|
|
assert.strictEqual(segs.length, 2);
|
|
assert.strictEqual(segs[1], 'npm run dev');
|
|
});
|
|
test('background dev server', () => {
|
|
const segs = splitShellSegments('npm run dev & echo started');
|
|
assert.strictEqual(segs.length, 2);
|
|
assert.strictEqual(segs[0], 'npm run dev');
|
|
});
|
|
test('empty string returns empty array', () => {
|
|
assert.deepStrictEqual(splitShellSegments(''), []);
|
|
});
|
|
test('single command no operators', () => {
|
|
assert.deepStrictEqual(splitShellSegments('npm run dev'), ['npm run dev']);
|
|
});
|
|
|
|
console.log(`\n=== Results: ${passed} passed, ${failed} failed ===`);
|
|
if (failed > 0) process.exit(1);
|