Skip to content

Audit test

audit_test

MCP tool for agent-optimized test execution.

AuditTestTool

Bases: AXMTool

Run tests with agent-optimized, token-efficient output.

Registered as audit_test via axm.tools entry point.

Source code in packages/axm-audit/src/axm_audit/tools/audit_test.py
class AuditTestTool(AXMTool):
    """Run tests with agent-optimized, token-efficient output.

    Registered as ``audit_test`` via axm.tools entry point.
    """

    @property
    def name(self) -> str:
        """Return tool name for registry lookup."""
        return "audit_test"

    def execute(
        self,
        *,
        path: str = ".",
        mode: str = "failures",
        files: list[str] | None = None,
        markers: list[str] | None = None,
        stop_on_first: bool = True,
        **kwargs: Any,
    ) -> ToolResult:
        """Run tests with agent-optimized output.

        Args:
            path: Path to project root.
            mode: Output mode (compact, failures, delta, targeted).
            files: Specific test files to run.
            markers: Pytest markers to filter.
            stop_on_first: Stop on first failure.

        Returns:
            ToolResult with structured test report.
        """
        try:
            project_path = Path(path).resolve()
            if not project_path.is_dir():
                return ToolResult(
                    success=False, error=f"Not a directory: {project_path}"
                )

            from axm_audit.core.test_runner import run_tests

            valid_modes: set[str] = {"compact", "failures", "delta", "targeted"}
            if mode not in valid_modes:
                return ToolResult(
                    success=False,
                    error=(
                        f"Invalid mode '{mode}'."
                        f" Must be one of: {', '.join(sorted(valid_modes))}"
                    ),
                )

            report = run_tests(
                project_path,
                mode=mode,  # type: ignore[arg-type]
                files=files,
                markers=markers,
                stop_on_first=stop_on_first,
            )

            return ToolResult(success=True, data=dataclasses.asdict(report))
        except Exception as exc:  # noqa: BLE001
            return ToolResult(success=False, error=str(exc))
name property

Return tool name for registry lookup.

execute(*, path='.', mode='failures', files=None, markers=None, stop_on_first=True, **kwargs)

Run tests with agent-optimized output.

Parameters:

Name Type Description Default
path str

Path to project root.

'.'
mode str

Output mode (compact, failures, delta, targeted).

'failures'
files list[str] | None

Specific test files to run.

None
markers list[str] | None

Pytest markers to filter.

None
stop_on_first bool

Stop on first failure.

True

Returns:

Type Description
ToolResult

ToolResult with structured test report.

Source code in packages/axm-audit/src/axm_audit/tools/audit_test.py
def execute(
    self,
    *,
    path: str = ".",
    mode: str = "failures",
    files: list[str] | None = None,
    markers: list[str] | None = None,
    stop_on_first: bool = True,
    **kwargs: Any,
) -> ToolResult:
    """Run tests with agent-optimized output.

    Args:
        path: Path to project root.
        mode: Output mode (compact, failures, delta, targeted).
        files: Specific test files to run.
        markers: Pytest markers to filter.
        stop_on_first: Stop on first failure.

    Returns:
        ToolResult with structured test report.
    """
    try:
        project_path = Path(path).resolve()
        if not project_path.is_dir():
            return ToolResult(
                success=False, error=f"Not a directory: {project_path}"
            )

        from axm_audit.core.test_runner import run_tests

        valid_modes: set[str] = {"compact", "failures", "delta", "targeted"}
        if mode not in valid_modes:
            return ToolResult(
                success=False,
                error=(
                    f"Invalid mode '{mode}'."
                    f" Must be one of: {', '.join(sorted(valid_modes))}"
                ),
            )

        report = run_tests(
            project_path,
            mode=mode,  # type: ignore[arg-type]
            files=files,
            markers=markers,
            stop_on_first=stop_on_first,
        )

        return ToolResult(success=True, data=dataclasses.asdict(report))
    except Exception as exc:  # noqa: BLE001
        return ToolResult(success=False, error=str(exc))