"""Black-box attachment checks against real PostgreSQL and private SeaweedFS.""" from concurrent.futures import ThreadPoolExecutor import base64 import hashlib import json import os from pathlib import Path import socket import struct import subprocess import sys import tempfile import threading import time import uuid import zlib import httpx from stack import ROOT, docker, instance, ready, ready_replicas, replicas OUT=ROOT/'evidence' OUT.mkdir(exist_ok=True) result={} def sql(q): return docker('compose','exec','-T','db','psql','-U','messenger','-d','messenger','-Atc',q) def inside(code): return docker('compose','exec','-T','api','python','-c',code) def user(c): name='test_'+uuid.uuid4().hex[:20] password='synthetic-password-123' r=c.post('/api/v1/users',json={'username':name,'display_name':'Files','password':password}); assert r.status_code==201,r.text uid=r.json()['id'] r=c.post('/api/v1/auth/sessions',auth=(name,password)); assert r.status_code==201,r.text return uid,{'Authorization':'Bearer '+r.json()['token']} def newchat(c,h,members): r=c.post('/api/v1/chats',headers=h,json={'title':'Attachments','member_ids':members}) assert r.status_code==201,r.text return r.json()['id'] def restore(c): docker('compose','up','-d','--no-deps','--scale','api=2','api'); ready_replicas(); ready(c) deadline=time.monotonic()+15 while time.monotonic()