"""Read-only acceptance for local simulated system settings.""" import json from pathlib import Path import urllib.request from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.firefox.options import Options from selenium.webdriver.firefox.service import Service from selenium.webdriver.support.ui import WebDriverWait,Select BASE='http://127.0.0.1:8088';ROOT=Path(__file__).resolve().parents[1] options=Options();options.add_argument('--headless');options.binary_location='/snap/firefox/current/usr/lib/firefox/firefox' driver=webdriver.Firefox(options=options,service=Service('/snap/bin/geckodriver'));driver.set_window_size(1440,1100);wait=WebDriverWait(driver,30,poll_frequency=.1) def body():return driver.find_element(By.TAG_NAME,'body').text def fits():assert driver.execute_script('return document.documentElement.scrollWidth<=window.innerWidth') try: driver.get(BASE);wait.until(lambda d:d.find_element(By.TAG_NAME,'h1').text=='来源与目录');driver.find_element(By.XPATH,"//nav//button[contains(.,'系统设置')]").click();wait.until(lambda d:d.find_element(By.TAG_NAME,'h1').text=='系统设置');wait.until(lambda d:'6. 监控与安全' in d.find_element(By.TAG_NAME,'body').text) for expected in ['本地模拟','文档工程师可调整','管理员设置已锁定','1. 当前环境','2. WeKnora环境','3. 解析器与模型','4. 发布目标','5. OSS备份','6. 监控与安全','测试WeKnora','生产WeKnora','MinerU','Embedding模型','LLM模型','Rerank模型','Wiki生成模型','图谱抽取模型','PostgreSQL','Elasticsearch','对象存储','Neo4j','生产发布请求','关闭','备份Bucket','文档状态刷新间隔','15秒','解析停滞判定','30分钟','保存模拟设置']: assert expected in body(),expected selects=driver.find_elements(By.CSS_SELECTOR,'.safe-setting-grid select');Select(selects[0]).select_by_visible_text('30秒');Select(selects[2]).select_by_visible_text('1小时');driver.find_element(By.XPATH,"//button[.='保存模拟设置']").click();wait.until(lambda d:'模拟设置已保存' in body()) assert all(button.get_attribute('disabled') for button in driver.find_elements(By.XPATH,"//button[contains(.,'管理员')]") ) assert not driver.find_elements(By.CSS_SELECTOR,'input[type="password"]') capabilities=json.load(urllib.request.urlopen(BASE+'/api/v1/release-capabilities',timeout=10))['data'];assert capabilities['production_release_requests_enabled'] is False for width in (1440,1024,768):driver.set_window_size(width,1000);fits() driver.set_window_size(1440,1100);driver.get_full_page_screenshot_as_file(str(ROOT/'tmp/SYSTEM_SETTINGS_SIMULATION_FIREFOX.png')) result={'mode':'simulation','sections':6,'safe_settings_change':'pass','admin_controls_locked':True,'password_inputs':0,'production_release_requests_enabled':False,'root_overflow':False,'external_write_requests':0} (ROOT/'tmp/system-settings-simulation-acceptance.json').write_text(json.dumps(result,ensure_ascii=False,indent=2));print(json.dumps(result,ensure_ascii=False)) finally:driver.quit()