"""Stress test: genera una conversación larga y la procesa con shcortex-cli."""
import subprocess
import time
import os

ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

def generate_large_conversation(num_turns=100):
    lines = []
    for i in range(num_turns):
        speaker = "Alice" if i % 2 == 0 else "Bob"
        line = f"{speaker}: This is a long conversation turn {i+1} with many words to ensure we exceed the threshold and trigger compression."
        lines.append(line)
    return "\n".join(lines)

def run_stress_test(text, model="nemotron-3-super:cloud"):
    start = time.perf_counter()
    out = subprocess.check_output(
        ["cargo", "run", "-p", "shcortex-cli", "--", "bench-latency", text, "What is the main topic?", "--model", model],
        text=True, encoding="utf-8", cwd=ROOT
    )
    latency = time.perf_counter() - start
    return out.strip(), latency

def main():
    text = generate_large_conversation(100)
    tokens = text.split()
    print(f"Generated {len(tokens)} tokens.")
    out, lat = run_stress_test(text)
    print(f"Latency: {lat*1000:.2f} ms")
    print("--- Output ---")
    print(out[:500])

if __name__ == "__main__":
    main()
