Files
callstack__agent-device/scripts/run-test-app-maestro-suite.mjs
T
2026-05-19 20:49:34 +02:00

82 lines
2.2 KiB
JavaScript

#!/usr/bin/env node
import { execFileSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const binPath = path.join(repoRoot, 'bin', 'agent-device.mjs');
const options = {
platform: 'ios',
session: 'test-app-maestro',
flowDir: path.join(repoRoot, 'examples', 'test-app', 'maestro'),
openTarget: '',
close: false,
passthrough: [],
};
for (let index = 2; index < process.argv.length; index += 1) {
const arg = process.argv[index];
if (arg === '--') {
options.passthrough.push(...process.argv.slice(index + 1));
break;
}
if (arg === '--platform' && process.argv[index + 1]) {
options.platform = process.argv[index + 1];
index += 1;
continue;
}
if (arg === '--session' && process.argv[index + 1]) {
options.session = process.argv[index + 1];
index += 1;
continue;
}
if (arg === '--flow-dir' && process.argv[index + 1]) {
options.flowDir = path.resolve(process.argv[index + 1]);
index += 1;
continue;
}
if (arg === '--open' && process.argv[index + 1]) {
options.openTarget = process.argv[index + 1];
index += 1;
continue;
}
if (arg === '--close') {
options.close = true;
continue;
}
options.passthrough.push(arg);
}
const flows = fs
.readdirSync(options.flowDir)
.filter((entry) => entry.endsWith('.yaml') || entry.endsWith('.yml'))
.sort()
.map((entry) => path.join(options.flowDir, entry));
if (flows.length === 0) {
console.error(`No Maestro flows found in ${options.flowDir}`);
process.exit(1);
}
function runAgentDevice(args) {
execFileSync(process.execPath, [binPath, '--session', options.session, ...args], {
cwd: repoRoot,
stdio: 'inherit',
});
}
if (options.openTarget) {
runAgentDevice(['open', options.openTarget, '--platform', options.platform, ...options.passthrough]);
runAgentDevice(['wait', 'Agent Device Tester', '30000', '--platform', options.platform, ...options.passthrough]);
}
for (const flow of flows) {
runAgentDevice(['replay', flow, '--maestro', '--platform', options.platform, ...options.passthrough]);
}
if (options.close) {
runAgentDevice(['close']);
}