astral-sh/ruff · error · RuntimeError

Could not find mdtest executable after successful compilatio

Error message

Could not find mdtest executable after successful compilation

What it means

mdtest.py is the Python harness wrapping ty_python_semantic's markdown test suite. It compiles the 'mdtest' test target with 'cargo test --package ty_python_semantic --no-run --test=mdtest --message-format=json', then scans cargo's JSON output from the end for a message whose target name is 'mdtest' with a non-null 'executable' path. This RuntimeError means cargo reported a successful build but no such message was found, so the harness cannot locate the test binary to run.

Source

Thrown at crates/ty_python_semantic/mdtest.py:129

            if json_output:
                self._get_executable_path_from_json(json_output)

        if message_on_success:
            self.console.print("[dim]Tests compiled successfully[/dim]")
        return True

    def _get_executable_path_from_json(self, json_output: str) -> None:
        for json_line in json_output.splitlines()[::-1]:
            try:
                data = json.loads(json_line)
            except json.JSONDecodeError:
                continue
            if data.get("target", {}).get("name") == "mdtest" and data["executable"]:
                self.mdtest_executable = Path(data["executable"])
                break
        else:
            raise RuntimeError(
                "Could not find mdtest executable after successful compilation"
            )

    def _run_mdtest(
        self, arguments: list[str] | None = None, *, capture_output: bool = False
    ) -> subprocess.CompletedProcess:
        assert self.mdtest_executable is not None

        arguments = arguments or []
        return subprocess.run(
            [self.mdtest_executable, *arguments],
            cwd=CRATE_ROOT,
            env=dict(
                os.environ,
                CLICOLOR_FORCE="1",
                INSTA_FORCE_PASS="1",
                INSTA_OUTPUT="none",
                MDTEST_EXTERNAL="1" if self.enable_external else "0",

View on GitHub (pinned to d1087a4b9e)

Solutions

  1. Verify the test target is still named 'mdtest' in crates/ty_python_semantic/Cargo.toml.
  2. Force recompilation so cargo re-emits artifact messages: cargo clean -p ty_python_semantic, then rerun the script.
  3. Bypass the wrapper and run the harness directly: cargo nextest run -p ty_python_semantic --test mdtest (or cargo test -p ty_python_semantic --test mdtest).
  4. If you use a cargo alias/wrapper, run the script with a stock cargo first on PATH.

Example fix

# before
python crates/ty_python_semantic/mdtest.py   # RuntimeError: Could not find mdtest executable after successful compilation

# after
cargo clean -p ty_python_semantic
python crates/ty_python_semantic/mdtest.py
# or run the same binary without the wrapper:
cargo nextest run -p ty_python_semantic --test mdtest
Defensive patterns

Strategy: try-catch

Validate before calling

import json, subprocess

meta = json.loads(subprocess.check_output(
    ['cargo', 'metadata', '--no-deps'], text=True
))
targets = [
    t['name']
    for pkg in meta['packages']
    if pkg['name'] == 'ty_python_semantic'
    for t in pkg['targets']
]
assert 'mdtest' in targets, 'mdtest test target missing from ty_python_semantic'

Try / catch

try:
    wrapper.run()
except RuntimeError as e:
    if 'mdtest executable' in str(e):
        subprocess.run([
            'cargo', 'test', '-p', 'ty_python_semantic',
            '--test', 'mdtest', '--nocapture',
        ])
    else:
        raise

Prevention

When it happens

Trigger: The test target named 'mdtest' was renamed or removed from crates/ty_python_semantic/Cargo.toml; a cargo wrapper, alias, or toolchain configuration altered or suppressed the JSON compiler-artifact messages the script parses.

Common situations: After renaming the mdtest test target; unusual cargo setups (sccache-style wrappers, custom CARGO wrappers on PATH) that change message emission; cargo version behavior changes around --message-format=json.

Related errors


AI-assisted analysis of astral-sh/ruff@d1087a4b9e (2026-08-20). Data as JSON: /api/errors/9af87bd6a064a23f. Report an issue: GitHub.