import json,sqlite3,urllib.request,urllib.error from pathlib import Path root=Path(__file__).resolve().parent.parent dbfile=root/'integration-work/hd-test-gpu/huobao.sqlite3' assert dbfile.is_file() and dbfile.parent.name=='hd-test-gpu' with sqlite3.connect(dbfile) as db:db.execute('UPDATE ai_service_configs SET settings=? WHERE id=6',(json.dumps({'temperature':0.8,'custom_value':'keep','gpu':'gpu1'}),)) base='http://127.0.0.1:18882/api/v1/ai-configs/6' def put(body): req=urllib.request.Request(base,data=json.dumps(body).encode(),headers={'Content-Type':'application/json'},method='PUT') with urllib.request.urlopen(req) as r:assert r.status==200 put({'gpu':'gpu3'}) with sqlite3.connect(dbfile) as db:assert json.loads(db.execute('SELECT settings FROM ai_service_configs WHERE id=6').fetchone()[0])=={'temperature':0.8,'custom_value':'keep','gpu':'gpu3'} put({'temperature':None,'gpu':'auto'}) with sqlite3.connect(dbfile) as db:assert json.loads(db.execute('SELECT settings FROM ai_service_configs WHERE id=6').fetchone()[0])=={'custom_value':'keep'} print('PASS: GPU updates preserve temperature and custom settings; clearing both removes only those fields')