"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var test_exports = {};
__export(test_exports, {
  testFilter: () => testFilter
});
module.exports = __toCommonJS(test_exports);
const testFilter = {
  name: "test",
  matches(command) {
    return /\b(jest|vitest|pytest|cargo\s+test|go\s+test|rspec|rake\s+test|mocha|ava|tap|npm\s+test|yarn\s+test|pnpm\s+test|npx\s+vitest|npx\s+jest)\b/.test(command);
  },
  filter(command, rawOutput, level) {
    if (/vitest/i.test(command)) return filterVitest(rawOutput, level);
    if (/jest/i.test(command)) return filterJest(rawOutput, level);
    if (/pytest/i.test(command)) return filterPytest(rawOutput, level);
    if (/cargo\s+test/i.test(command)) return filterCargoTest(rawOutput, level);
    if (/go\s+test/i.test(command)) return filterGoTest(rawOutput, level);
    if (/rspec/i.test(command)) return filterRspec(rawOutput, level);
    if (/rake\s+test/i.test(command)) return filterMinitest(rawOutput, level);
    return filterGenericTest(rawOutput, level);
  }
};
function filterVitest(raw, level) {
  return filterJsTestRunner(raw, level, "vitest");
}
function filterJest(raw, level) {
  return filterJsTestRunner(raw, level, "jest");
}
function filterJsTestRunner(raw, level, runner) {
  const lines = raw.split("\n");
  const summaryLine = lines.find((l) => /Tests:\s+\d+/.test(l) || /\d+\s+passed/.test(l));
  const failedMatch = raw.match(/(\d+)\s+failed/);
  const passedMatch = raw.match(/(\d+)\s+passed/);
  const totalMatch = raw.match(/Tests:\s+(\d+)/);
  const failed = failedMatch ? parseInt(failedMatch[1]) : 0;
  const passed = passedMatch ? parseInt(passedMatch[1]) : 0;
  const total = totalMatch ? parseInt(totalMatch[1]) : failed + passed;
  if (failed === 0) {
    if (level === "ultra") {
      return { output: `\u2713 ${passed}/${total}`, strategy: `${runner}:allpass:ultra` };
    }
    return { output: `PASSED: ${passed}/${total} tests`, strategy: `${runner}:allpass` };
  }
  const failures = [];
  let inFailure = false;
  let failureBlock = [];
  for (const line of lines) {
    if (line.includes("FAIL") && line.includes("\u25CF") || line.includes("\u2715") || line.includes("\u2717") || line.match(/FAIL\s+/)) {
      if (failureBlock.length > 0) failures.push(failureBlock.join("\n"));
      failureBlock = [line];
      inFailure = true;
    } else if (inFailure) {
      if (line.trim() === "" && failureBlock.length > 3) {
        failures.push(failureBlock.join("\n"));
        failureBlock = [];
        inFailure = false;
      } else {
        failureBlock.push(line);
      }
    }
  }
  if (failureBlock.length > 0) failures.push(failureBlock.join("\n"));
  const header = `FAILED: ${failed}/${total} tests`;
  if (level === "ultra") {
    const shortFailures = failures.map((f) => f.split("\n")[0]).slice(0, 5);
    return { output: `${header}
${shortFailures.join("\n")}`, strategy: `${runner}:failures:ultra` };
  }
  const maxFailures = level === "aggressive" ? 3 : 5;
  const shown = failures.slice(0, maxFailures).join("\n\n");
  const extra = failures.length > maxFailures ? `
\u2026+${failures.length - maxFailures} more failures` : "";
  return { output: `${header}

${shown}${extra}`, strategy: `${runner}:failures` };
}
function filterPytest(raw, level) {
  const lines = raw.split("\n");
  const summaryLine = lines.find((l) => /\d+\s+passed/.test(l) || /\d+\s+failed/.test(l));
  const failedMatch = raw.match(/(\d+)\s+failed/);
  const passedMatch = raw.match(/(\d+)\s+passed/);
  const failed = failedMatch ? parseInt(failedMatch[1]) : 0;
  const passed = passedMatch ? parseInt(passedMatch[1]) : 0;
  const total = failed + passed;
  if (failed === 0) {
    if (level === "ultra") return { output: `\u2713 ${passed}/${total}`, strategy: "pytest:allpass:ultra" };
    return { output: `PASSED: ${passed}/${total} tests`, strategy: "pytest:allpass" };
  }
  const failures = [];
  let inFailure = false;
  let block = [];
  for (const line of lines) {
    if (line.startsWith("FAILED") || line.startsWith("___ ") || line.includes("FAILURES ___")) {
      if (block.length > 0) failures.push(block.join("\n"));
      block = [line];
      inFailure = true;
    } else if (inFailure) {
      block.push(line);
      if (block.length > 20) {
        failures.push(block.join("\n"));
        block = [];
        inFailure = false;
      }
    }
  }
  if (block.length > 0) failures.push(block.join("\n"));
  const header = `FAILED: ${failed}/${total} tests`;
  const maxFailures = level === "ultra" ? 2 : level === "aggressive" ? 3 : 5;
  const shown = failures.slice(0, maxFailures).join("\n\n");
  const extra = failures.length > maxFailures ? `
\u2026+${failures.length - maxFailures} more` : "";
  return { output: `${header}

${shown}${extra}`, strategy: "pytest:failures" };
}
function filterCargoTest(raw, level) {
  const lines = raw.split("\n");
  const resultLine = lines.find((l) => l.startsWith("test result:"));
  const failedMatch = raw.match(/(\d+)\s+failed/);
  const passedMatch = raw.match(/(\d+)\s+passed/);
  const failed = failedMatch ? parseInt(failedMatch[1]) : 0;
  const passed = passedMatch ? parseInt(passedMatch[1]) : 0;
  const total = failed + passed;
  if (failed === 0) {
    if (level === "ultra") return { output: `\u2713 ${passed}/${total}`, strategy: "cargo-test:allpass:ultra" };
    return { output: `PASSED: ${passed}/${total} tests`, strategy: "cargo-test:allpass" };
  }
  const failures = [];
  let inFailure = false;
  let block = [];
  for (const line of lines) {
    if (line.includes("FAILED") || line.includes("panicked at") || line.includes("---- ") && line.includes(" ----")) {
      if (block.length > 0) failures.push(block.join("\n"));
      block = [line];
      inFailure = true;
    } else if (inFailure) {
      if (line.startsWith("test ") && line.includes("...")) {
        failures.push(block.join("\n"));
        block = [];
        inFailure = false;
      } else {
        block.push(line);
      }
    }
  }
  if (block.length > 0) failures.push(block.join("\n"));
  const header = `FAILED: ${failed}/${total} tests`;
  const maxFailures = level === "ultra" ? 2 : level === "aggressive" ? 3 : 5;
  const shown = failures.slice(0, maxFailures).join("\n\n");
  const extra = failures.length > maxFailures ? `
\u2026+${failures.length - maxFailures} more` : "";
  return { output: `${header}

${shown}${extra}`, strategy: "cargo-test:failures" };
}
function filterGoTest(raw, level) {
  const lines = raw.split("\n");
  const failLines = lines.filter((l) => l.startsWith("--- FAIL"));
  const passLines = lines.filter((l) => l.startsWith("--- PASS") || l.startsWith("ok"));
  if (failLines.length === 0) {
    const passed = passLines.length || lines.filter((l) => l.startsWith("ok")).length;
    if (level === "ultra") return { output: `\u2713 ${passed} passed`, strategy: "go-test:allpass:ultra" };
    return { output: `PASSED: ${passed} test(s)`, strategy: "go-test:allpass" };
  }
  const failures = [];
  let inFailure = false;
  let block = [];
  for (const line of lines) {
    if (line.startsWith("--- FAIL")) {
      if (block.length > 0) failures.push(block.join("\n"));
      block = [line];
      inFailure = true;
    } else if (inFailure) {
      if (line.startsWith("--- ") || line.startsWith("FAIL") || line.startsWith("ok")) {
        failures.push(block.join("\n"));
        block = [];
        inFailure = false;
      } else {
        block.push(line);
      }
    }
  }
  if (block.length > 0) failures.push(block.join("\n"));
  const header = `FAILED: ${failLines.length} test(s)`;
  const maxFailures = level === "ultra" ? 2 : level === "aggressive" ? 3 : 5;
  const shown = failures.slice(0, maxFailures).join("\n\n");
  const extra = failures.length > maxFailures ? `
\u2026+${failures.length - maxFailures} more` : "";
  return { output: `${header}

${shown}${extra}`, strategy: "go-test:failures" };
}
function filterRspec(raw, level) {
  const lines = raw.split("\n");
  const summaryMatch = raw.match(/(\d+)\s+examples?,\s+(\d+)\s+failures?/);
  if (!summaryMatch) return { output: raw, strategy: "rspec:passthrough" };
  const total = parseInt(summaryMatch[1]);
  const failed = parseInt(summaryMatch[2]);
  if (failed === 0) {
    if (level === "ultra") return { output: `\u2713 ${total}/${total}`, strategy: "rspec:allpass:ultra" };
    return { output: `PASSED: ${total}/${total} examples`, strategy: "rspec:allpass" };
  }
  const failures = lines.filter((l) => l.includes("Failure/Error") || l.includes("expected") || l.includes("got:"));
  const header = `FAILED: ${failed}/${total} examples`;
  const maxLines = level === "ultra" ? 5 : level === "aggressive" ? 10 : 20;
  const shown = failures.slice(0, maxLines).join("\n");
  return { output: `${header}

${shown}`, strategy: "rspec:failures" };
}
function filterMinitest(raw, level) {
  const lines = raw.split("\n");
  const summaryMatch = raw.match(/(\d+)\s+runs?,\s+\d+\s+assertions?,\s+(\d+)\s+failures?/);
  if (!summaryMatch) return { output: raw, strategy: "minitest:passthrough" };
  const total = parseInt(summaryMatch[1]);
  const failed = parseInt(summaryMatch[2]);
  if (failed === 0) {
    if (level === "ultra") return { output: `\u2713 ${total}/${total}`, strategy: "minitest:allpass:ultra" };
    return { output: `PASSED: ${total}/${total} tests`, strategy: "minitest:allpass" };
  }
  const failures = lines.filter((l) => l.includes("Failure:") || l.includes("Error:") || l.includes("Expected"));
  const header = `FAILED: ${failed}/${total} tests`;
  const maxLines = level === "ultra" ? 5 : level === "aggressive" ? 10 : 20;
  const shown = failures.slice(0, maxLines).join("\n");
  return { output: `${header}

${shown}`, strategy: "minitest:failures" };
}
function filterGenericTest(raw, level) {
  const lines = raw.split("\n");
  const failedMatch = raw.match(/(\d+)\s+(?:failed|failing|failure)/i);
  const passedMatch = raw.match(/(\d+)\s+(?:passed|passing|success)/i);
  if (failedMatch && parseInt(failedMatch[1]) === 0 && passedMatch) {
    return { output: `PASSED: ${passedMatch[1]} tests`, strategy: "test:generic:allpass" };
  }
  const important = lines.filter(
    (l) => /fail|error|assert|expect|panic/i.test(l) || /\d+\s+(passed|failed|tests)/i.test(l) || l.startsWith("FAIL") || l.startsWith("ERROR")
  );
  if (important.length > 0 && important.length < lines.length * 0.5) {
    const maxLines = level === "ultra" ? 10 : level === "aggressive" ? 20 : 30;
    return { output: important.slice(0, maxLines).join("\n"), strategy: "test:generic:filtered" };
  }
  return { output: raw, strategy: "test:generic:passthrough" };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  testFilter
});
//# sourceMappingURL=test.js.map
