Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 33 additions & 11 deletions src/utils/execution-runtimes/withMacHeavyTestLane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,42 @@ const lockBusy = 75;
// The runner argv and shell scripts used by Harness package commands.
const heavyRunner = /\bplaywright\s+test\b|\btest:(?:e2e|native|package|all)\b/;
const vitestE2e = /\bvitest\s+run\b[^;\n&|]*\.e2e\.test\./;
const shellExclusion = /(^|\s)--exclude(?:=|[ \t]+)(?:"[^"\n]*"|'[^'\n]*'|[^\s;&|]+)/g;
const shellToken = /(?:\\[\s\S]|"(?:\\[\s\S]|[^"\\])*"|'[^']*'|[^\s"'\\;&|])+|[\n;&|]/g;
const shellQuotes = /\\([\s\S])|"((?:\\[\s\S]|[^"\\])*)"|'([^']*)'/g;
const shellContinuation = '\\\n';

export function isHeavyTestCommand(args: readonly string[]): boolean {
if (args[0] === 'bun' && args[1] === 'scripts/run-checks.ts') return true;
if ((args[0] === 'sh' || args[0] === '/bin/sh') && args[1] === '-c') {
const script = args[2] ?? '';
return heavyRunner.test(script) || vitestE2e.test(script.replace(shellExclusion, '$1'));
}
if (heavyRunner.test(args.join(' '))) return true;
const filters = args.filter(
(arg, index) =>
arg !== '--exclude' && !arg.startsWith('--exclude=') && args[index - 1] !== '--exclude'
);
return vitestE2e.test(filters.join(' '));
const shell = (args[0] === 'sh' || args[0] === '/bin/sh') && args[1] === '-c';
const words = shell ? shellCommandWords(args[2] ?? '') : args;
const command = words
.filter(
(word, index) =>
word !== '--exclude' && !word.startsWith('--exclude=') && words[index - 1] !== '--exclude'
)
.join(' ');
return heavyRunner.test(command) || vitestE2e.test(command);
}

// Normalize static shell words without evaluating expansions or dropping command separators.
function shellCommandWords(script: string): string[] {
return (script.match(shellToken) ?? [])
.filter((word) => !/^(?:\\\n)+$/.test(word))
.map((word) =>
word.replace(
shellQuotes,
(match, escaped, doubleQuoted: string | undefined, singleQuoted) => {
if (escaped !== undefined) return escaped === '\n' ? '' : escaped;
return (
doubleQuoted?.replace(/\\[\s\S]/g, (pair) =>
pair === shellContinuation ? '' : pair
) ??
singleQuoted ??
match
);
}
)
);
}

/** Apply the same lane budget across worktrees and resource homes for the OS account. */
Expand Down
21 changes: 20 additions & 1 deletion test/utils/execution-runtimes/with-mac-heavy-test-lane.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ test('recognizes the standard suite commands without queuing routine type checks
['sh', '-c', 'bun run --cwd packages/hub check && bun run --cwd packages/hub test:e2e'],
['vitest', 'run', 'test/resources-cli.e2e.test.ts'],
['/bin/sh', '-c', "vitest run --exclude='test/desktop e2e/*.e2e.test.ts' test/cli.e2e.test.ts"],
['sh', '-c', "vitest run '--exclude=*.e2e.test.ts' 'test/cli.e2e.test.ts'"],
['sh', '-c', 'vitest run --exclude "*.e2e.test.ts" test/queue.test.ts\nbun run test:e2e'],
['vitest', 'run', '--exclude', 'test/**/*.e2e.test.ts', 'test/cli.e2e.test.ts']
];
expect(commands.every(isHeavyTestCommand)).toBe(true);
Expand All @@ -25,7 +27,24 @@ test('recognizes the standard suite commands without queuing routine type checks
['/bin/sh', '-c', 'vitest run --exclude "test/**/*.e2e.test.ts" test/queue.test.ts'],
['sh', '-c', "vitest run --exclude='test/desktop e2e/*.e2e.test.ts' test/queue.test.ts"],
['vitest', 'run', '--exclude', 'test/desktop e2e/*.e2e.test.ts', 'test/queue.test.ts'],
['vitest', 'run', '--exclude=test/**/*.e2e.test.ts', 'test/queue.test.ts']
['vitest', 'run', '--exclude=test/**/*.e2e.test.ts', 'test/queue.test.ts'],
['vitest', 'run', '--exclude', 'test/fixtures/test:e2e/*.test.ts', 'test/queue.test.ts'],
['vitest', 'run', '--exclude=test/fixtures/test:e2e/*.test.ts', 'test/queue.test.ts'],
['sh', '-c', 'vitest run --exclude "test/fixtures/test:e2e/*.test.ts" test/queue.test.ts'],
['/bin/sh', '-c', "vitest run --exclude='test/fixtures/test:e2e/*.test.ts' test/queue.test.ts"],
['sh', '-c', 'vitest run "--exclude=**/*.e2e.test.ts" test/queue.test.ts'],
[
'/bin/sh',
'-c',
"vitest run '--exclude' 'test/fixtures/test:e2e/*.test.ts' test/queue.test.ts"
],
['sh', '-c', "vitest run '--exclude='test/fixtures/test:e2e/*.test.ts test/queue.test.ts"],
[
'/bin/sh',
'-c',
"vitest run --exclude \\\n 'test/fixtures/test:e2e/*.test.ts' test/queue.test.ts"
],
['sh', '-c', 'vitest run "--exclu\\\nde=**/*.e2e.test.ts" test/queue.test.ts']
];
for (const command of unitCommands)
expect(isHeavyTestCommand(command), command.join(' ')).toBe(false);
Expand Down
Loading