free-claude-code/smoke/test_voice_live.py
Ali Khokhar 462a9430bb
Add local live smoke test suite (#148)
## Summary
- add an opt-in local `smoke/` pytest suite for API, auth, providers,
CLI, IDE-shaped requests, messaging, voice, tools, and thinking stream
contracts
- keep smoke tests out of normal CI collection with `testpaths =
["tests"]`
- write sanitized smoke artifacts under `.smoke-results/`

## Verification
- `uv run ruff format`
- `uv run ruff check`
- `uv run ty check`
- `uv run ty check smoke`
- `FCC_LIVE_SMOKE=1 FCC_SMOKE_TARGETS=all FCC_SMOKE_RUN_VOICE=1 uv run
pytest smoke -n 0 -m live -s --tb=short` -> 17 passed, 9 skipped
- `uv run pytest` -> 904 passed

## Notes
- Skipped live checks require local credentials/tools/services, such as
provider models, Telegram/Discord targets, voice backend, or Claude CLI.
- `claude-pick` smoke was intentionally removed.
2026-04-23 19:06:09 -07:00

52 lines
1.5 KiB
Python

from __future__ import annotations
import math
import os
import wave
from pathlib import Path
import pytest
from messaging.transcription import transcribe_audio
from smoke.lib.config import SmokeConfig
pytestmark = [pytest.mark.live, pytest.mark.smoke_target("voice")]
def test_voice_transcription_backend_when_explicitly_enabled(
smoke_config: SmokeConfig, tmp_path: Path
) -> None:
if not smoke_config.settings.voice_note_enabled:
pytest.skip("VOICE_NOTE_ENABLED is false")
if os.getenv("FCC_SMOKE_RUN_VOICE") != "1":
pytest.skip("set FCC_SMOKE_RUN_VOICE=1 to run transcription smoke")
wav_path = tmp_path / "smoke-tone.wav"
_write_tone_wav(wav_path)
try:
text = transcribe_audio(
wav_path,
"audio/wav",
whisper_model=smoke_config.settings.whisper_model,
whisper_device=smoke_config.settings.whisper_device,
)
except ImportError as exc:
pytest.skip(str(exc))
assert isinstance(text, str)
assert text.strip()
def _write_tone_wav(path: Path) -> None:
sample_rate = 16000
duration_s = 0.25
amplitude = 8000
frames = bytearray()
for i in range(int(sample_rate * duration_s)):
sample = int(amplitude * math.sin(2 * math.pi * 440 * i / sample_rate))
frames.extend(sample.to_bytes(2, byteorder="little", signed=True))
with wave.open(str(path), "wb") as wav:
wav.setnchannels(1)
wav.setsampwidth(2)
wav.setframerate(sample_rate)
wav.writeframes(bytes(frames))