#!/usr/bin/env python3 """Additional real HTTP/PG/Valkey checks; synthetic own keys, no global flush.""" import base64, json, os, sys, time from concurrent.futures import ThreadPoolExecutor from pathlib import Path from threading import Barrier from urllib.parse import urlencode import psycopg, redis sys.path.insert(0,str(Path(__file__).resolve().parents[2]/'tests')) from client import Client,check,timestamp def main(): c=Client('http://api:8080'); peer=Client('http://api-peer:8080'); short=Client('http://api-expiry:8080') url=Path(os.environ['DATABASE_URL_FILE']).read_text().strip() r=redis.Redis.from_url(Path(os.environ['CACHE_URL_FILE']).read_text().strip(),decode_responses=True) a,b,eve,chat=c.bootstrap();key='profile:'+a['id'] def me(actor=a,client=c,expected=200):return client.call('GET','/api/v1/users/me',expected,actor=actor,schema='User' if expected==200 else None) # Profiles contain no secret/session fields; malformed optional state never leaks into HTTP. corrupt=['','null','[]','{}','not-json',json.dumps(dict(a['user'],id=b['id'])),json.dumps(dict(a['user'],display_name=[])),json.dumps(dict(a['user'],created_at='nonsense')),json.dumps(dict(a['user'],username=4)),json.dumps(dict(a['user'],password='DO_NOT_RETURN'))] for value in corrupt: r.set(key,value,ex=60);check(me()['json']==a['user'],'corrupt cache escaped');check(json.loads(r.get(key))==a['user'],'corrupt cache not repaired') r.delete(key);check(me()['json']==a['user'],'cold load mismatch') ttl=r.ttl(key);check(0=2,'1s timeout did not use real PG fallback') print('PASS: HTTP C8 lock=%.1fs processes=%d real profile SELECT=%d elapsed=%.3fs max_http=%.3fs'%(delay,replicas,count,time.monotonic()-start,max(x['elapsed'] for x in results))) print('PASS: grade5 additional integration checks completed') if __name__=='__main__':main()