import { aggregateStatus } from "./reporter.js";
export async function runTest(suite, id, name, fn) {
    const started = Date.now();
    try {
        const result = await fn();
        return {
            id,
            name,
            suite,
            durationMs: Date.now() - started,
            ...result,
        };
    }
    catch (err) {
        return {
            id,
            name,
            suite,
            status: "failed",
            durationMs: Date.now() - started,
            error: {
                name: err instanceof Error ? err.name : undefined,
                message: err instanceof Error ? err.message : String(err),
                stack: err instanceof Error ? err.stack : undefined,
                classification: classifyError(err),
            },
        };
    }
}
export function buildSuiteResult(id, name, started, tests) {
    return {
        id,
        name,
        status: aggregateStatus(tests.map((test) => test.status)),
        durationMs: Date.now() - started,
        tests,
    };
}
export function ok(message, details) {
    return { status: "passed", message, details };
}
export function skipped(message, details) {
    return { status: "skipped", message, details };
}
export function warning(message, details) {
    return { status: "warning", message, details };
}
function classifyError(err) {
    const message = err instanceof Error ? err.message : String(err);
    if (/not configured|not found|missing/i.test(message))
        return "missing_config";
    if (/scope|insufficient/i.test(message))
        return "missing_scope";
    if (/permission|accessibility|screen recording|denied/i.test(message))
        return "permission_denied";
    if (/network|timeout|fetch/i.test(message))
        return "network_error";
    return "unknown";
}
//# sourceMappingURL=suite-utils.js.map