"""Run against pnpm dev:taro. Verify admin -> API -> Web, then restore local config.""" import json from pathlib import Path from playwright.sync_api import sync_playwright, expect with sync_playwright() as playwright: browser = playwright.chromium.launch() context = browser.new_context(viewport={'width': 390, 'height': 844}) page = context.new_page() errors, external = [], [] page.on('pageerror', lambda error: errors.append(str(error))) page.on('request', lambda request: external.append(request.url) if '/api/' in request.url and not request.url.startswith('http://localhost:10087/') else None) page.goto('http://localhost:10087/#/pages/home/index', wait_until='domcontentloaded') expect(page.locator('.hub-root')).to_be_visible(timeout=30000) admin = browser.new_page() admin.goto('http://localhost:10088/', wait_until='domcontentloaded') admin.locator('#password').fill('taro-preview-local') admin.locator('#login button').click() expect(admin.locator('#editor')).to_be_visible() original = json.loads(admin.locator('#json').input_value()) # Clean up the prior interrupted diagnostic, without resetting other fields. if original['copy']['homeBrand'] == 'Taro-isolation-check': seed = json.loads((Path(__file__).resolve().parents[1] / 'api/seed/catalog.json').read_text(encoding='utf8')) original['copy']['homeBrand'] = seed['config']['copy']['homeBrand'] try: changed = json.loads(json.dumps(original)) changed['copy']['homeBrand'] = 'Taro-isolation-check' admin.locator('#json').fill(json.dumps(changed, ensure_ascii=False)) admin.locator('#save').click() expect(page.locator('.hub-logo-text')).to_have_text('Taro-isolation-check', timeout=15000) page.evaluate("location.hash='#/pages/social/index'") page.wait_for_timeout(1500) assert not external, external assert not errors, errors print('PASS standalone admin login/save, live config update, no external business API requests') finally: current = json.loads(admin.locator('#json').input_value()) original['version'] = current['version'] admin.locator('#json').fill(json.dumps(original, ensure_ascii=False)) with admin.expect_response(lambda response: response.url.endswith('/api/admin/config') and response.request.method == 'PUT') as saved: admin.locator('#save').click() assert saved.value.ok browser.close()