import fs from "node:fs";
import path from "node:path";
export function aggregateStatus(statuses) {
    if (statuses.includes("failed"))
        return "failed";
    if (statuses.includes("warning"))
        return "warning";
    if (statuses.length > 0 && statuses.every((status) => status === "skipped"))
        return "skipped";
    return "passed";
}
export function formatE2EStartMessage(runId, mode) {
    return `VisionClaw E2E started\n\nRun ID: ${runId}\nMode: ${mode}`;
}
export function formatE2ESummary(result) {
    const counts = countStatuses(result.suites);
    const lines = [
        `VisionClaw E2E ${result.mode} completed: ${result.status}`,
        "",
        `Run ID: ${result.runId}`,
        `Duration: ${(result.durationMs / 1000).toFixed(1)}s`,
        "",
        "Suites:",
        ...result.suites.map((suite) => `- ${suite.name}: ${suite.status} (${suite.tests.length} tests)`),
        "",
        `Totals: passed=${counts.passed}, warning=${counts.warning}, failed=${counts.failed}, skipped=${counts.skipped}`,
        `Artifacts: ${result.artifactsDir}`,
        "",
        `Cleanup: /e2e cleanup ${result.runId}`,
    ];
    const skipped = result.suites.flatMap((suite) => suite.tests.filter((test) => test.status === "skipped"));
    if (skipped.length > 0) {
        lines.push("", "Skipped tests:");
        for (const test of skipped.slice(0, 8)) {
            lines.push(`- ${test.id}: ${test.message ?? "skipped"}${setupHintForSkippedTest(test)}`);
        }
    }
    if (result.cleanup.status === "failed" || result.cleanup.status === "warning") {
        lines.push("", `Cleanup needs attention. Run: /e2e cleanup ${result.runId}`);
    }
    const failures = result.suites.flatMap((suite) => suite.tests.filter((test) => test.status === "failed"));
    if (failures.length > 0) {
        lines.push("", "Failed tests:");
        for (const failure of failures.slice(0, 5)) {
            lines.push(`- ${failure.id}: ${failure.error?.message ?? failure.message ?? "failed"}`);
        }
    }
    return lines.join("\n");
}
export function writeReports(result) {
    fs.mkdirSync(result.artifactsDir, { recursive: true });
    fs.writeFileSync(path.join(result.artifactsDir, "report.json"), `${JSON.stringify(result, null, 2)}\n`, "utf-8");
    fs.writeFileSync(path.join(result.artifactsDir, "summary.md"), `${formatE2ESummary(result)}\n`, "utf-8");
}
function setupHintForSkippedTest(test) {
    if (test.id === "google.calendar.guest_can_see_event") {
        if (test.message?.includes("Guest email not configured")) {
            return " — set E2E_GOOGLE_MEET_GUEST_EMAIL or config e2e.google.meetGuestEmail, then run /e2e setup google-guest <guest-email>";
        }
        if (test.message?.includes("Guest OAuth token missing") || test.message?.includes("Guest calendar client unavailable")) {
            return " — run /e2e setup google-guest <guest-email> to enable Google Meet guest verification";
        }
    }
    if (test.id === "google.meet.guest_can_open_join_page") {
        return " — configure e2e.google.meetGuestBrowserProfileDir to enable browser join-page verification";
    }
    return "";
}
function countStatuses(suites) {
    const counts = { passed: 0, failed: 0, skipped: 0, warning: 0 };
    for (const suite of suites) {
        for (const test of suite.tests)
            counts[test.status]++;
    }
    return counts;
}
//# sourceMappingURL=reporter.js.map