#!/usr/bin/env python3
"""Test ASR processor with large file and short timeout to see debug output."""

import sys
import os
import subprocess
import tempfile
import time

# Use large file
test_video = "../test_video/1636719d-c31f-78ac-f1dd-8ab0b0b36c66.mov"

print(f"Testing: {test_video}")
size_gb = os.path.getsize(test_video) / (1024**3)
print(f"Size: {size_gb:.2f} GB")

# Create temp output
temp_dir = tempfile.mkdtemp(prefix="asr_debug_large_")
output_path = os.path.join(temp_dir, "output.json")

# Use debug version
cmd = [
    "/opt/homebrew/bin/python3.11",
    "scripts/asr_processor_debug.py",
    test_video,
    output_path,
    "--uuid",
    "debug_large_test",
]

print(f"Running command with 10-second timeout...")
print(f"Temp dir: {temp_dir}")

# Run with short timeout to capture initial debug output
timeout = 10
start = time.time()

proc = subprocess.Popen(
    cmd,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    text=True,
)

try:
    stdout, stderr = proc.communicate(timeout=timeout)
    elapsed = time.time() - start
    success = proc.returncode == 0
    timeout_hit = False
except subprocess.TimeoutExpired:
    elapsed = time.time() - start
    success = False
    timeout_hit = True
    proc.kill()
    stdout, stderr = proc.communicate()

print(f"\nElapsed: {elapsed:.1f}s")
print(f"Success: {success}")
print(f"Timeout: {timeout_hit}")

print("\n=== STDERR (first 2000 chars) ===")
print(stderr[:2000])

print("\n=== STDOUT ===")
print(stdout)

print(f"\nTemp directory: {temp_dir}")
