#!/usr/bin/env python3
"""Fake ``pw-record`` for tests — never touches a real microphone.

Writes a small, fixed, silent PCM16 buffer to stdout and exits, so
``start_capture`` tests can assert the subprocess actually ran with the
expected argv and produced bytes, with no real hardware involved. A
``--target missing-node`` invocation fails instead, so a test can exercise
the "capture device unavailable" path.
"""

from __future__ import annotations

import sys

FAKE_PCM = b"\x00\x00" * 64  # 64 silent S16_LE samples


def main() -> int:
    args = sys.argv[1:]
    if "--target" in args:
        target = args[args.index("--target") + 1]
        if target == "missing-node":
            print("fake pw-record: node 'missing-node' not found", file=sys.stderr)
            return 1
    sys.stdout.buffer.write(FAKE_PCM)
    sys.stdout.buffer.flush()
    return 0


if __name__ == "__main__":
    sys.exit(main())
