"""Tests for the preview worker pool resilience. Regression context: a piped worker stderr that nobody drains used to block the worker mid-request once the OS pipe buffer filled, and asyncio's proc.wait() then never resolved even after kill() — wedging one dispatcher per stuck worker until all preview traffic timed out permanently. """ import asyncio import sys import textwrap import time from pathlib import Path from unittest.mock import AsyncMock, Mock import pytest from cista import preview FAKE_WORKER = textwrap.dedent( """ import json import struct import sys import blake3 def read_exact(n): buf = b"" while len(buf) < n: chunk = sys.stdin.buffer.read(n - len(buf)) if not chunk: raise EOFError buf += chunk return buf sys.stdout.buffer.write(b"\\x01") sys.stdout.buffer.flush() while True: header = sys.stdin.buffer.read(8) if not header or len(header) < 8: break meta_len, payload_len = struct.unpack("