支持自部署需求管理、交付流程与飞书集成

This commit is contained in:
xyt committed 2026-11-25 12:40:33 +08:00
1 parent 2149aeb6ed
commit 51a2e548f2
152 files changed
+8652 -6394

No files matched your search

+148
View File
@@ -0,0 +1,148 @@
"""Chunk failure recovery and Escape regressions on an isolated local instance."""
import asyncio
import json
import os
import re
from pathlib import Path
from urllib.parse import urlparse
from playwright.async_api import async_playwright, expect
origin = os.environ['APP_URL']
assert urlparse(origin).hostname == '127.0.0.1'
assert Path(os.environ['DATA_DIR']).name.startswith('demand-scope-browser-db-')
output = Path('/private/tmp/demand-template-resilience-qa')
output.mkdir(exist_ok=True)
async def main():
checks = []
async with async_playwright() as p:
browser = await p.chromium.launch(headless=True, channel='chrome')
context = await browser.new_context(viewport={'width': 1440, 'height': 1000})
async def post(path, data):
response = await context.request.post(origin + path, data=data, headers={'Origin': origin})
assert response.ok, (response.status, await response.text())
return await response.json()
await post('/api/auth/login', {'username': 'scope_qa', 'password': os.environ['INITIAL_ADMIN_PASSWORD']})
await post('/api/auth/password', {'currentPassword': os.environ['INITIAL_ADMIN_PASSWORD'], 'newPassword': os.environ['QA_PASSWORD']})
errors = []
async def start_form():
page = await context.new_page()
page.on('pageerror', lambda error: errors.append(str(error)))
await page.goto(origin)
await page.wait_for_load_state('networkidle')
await page.get_by_role('button', name=re.compile('登记新需求$')).first.click()
await page.get_by_label('需求标题', exact=False).fill('模板容错回归')
await page.get_by_role('button', name=re.compile('业务背景与目标')).click()
await page.get_by_label('业务背景与现有处理方式', exact=False).fill('保留未保存的业务说明')
return page
async def expect_form(page):
await expect(page.get_by_role('dialog')).to_have_count(1)
await expect(page.get_by_role('alertdialog')).not_to_be_attached()
await expect(page.get_by_label('业务背景与现有处理方式', exact=False)).to_have_value('保留未保存的业务说明')
await expect(page.get_by_role('button', name='查看需求说明模板', exact=True)).to_be_focused()
page = await start_form()
reference = 'https://example.feishu.cn/docx/template-error-recovery'
await page.get_by_label('需求说明文档链接(选填)', exact=True).fill(reference)
await page.get_by_label('选择文件附件', exact=True).set_input_files({'name': '保留的说明.txt', 'mimeType': 'text/plain', 'buffer': '附件内容不丢失'.encode()})
await expect(page.get_by_role('link', name='保留的说明.txt', exact=True)).to_be_visible()
await expect(page.get_by_role('button', name='上传文件', exact=True)).to_be_enabled()
chunks = {'fail': True, 'blocked': 0}
async def fail_chunks(route):
if chunks['fail']:
chunks['blocked'] += 1
await route.abort('failed')
else:
await route.continue_()
await page.route('**/_next/static/chunks/*.js', fail_chunks)
await page.get_by_role('button', name='查看需求说明模板', exact=True).click()
await expect(page.get_by_role('alert')).to_contain_text('模板预览未能加载,请重试。已填内容仍然保留。')
assert chunks['blocked'] > 0
await expect(page.get_by_role('dialog', include_hidden=True)).to_have_count(2)
await page.screenshot(path=str(output / 'chunk-error-desktop.png'), animations='disabled')
blocked = chunks['blocked']
await page.get_by_role('button', name='重新加载', exact=True).click()
await expect(page.get_by_role('alert')).to_contain_text('模板预览未能加载')
assert chunks['blocked'] > blocked, 'retry must request failed chunks again'
await page.set_viewport_size({'width': 390, 'height': 844})
await page.screenshot(path=str(output / 'chunk-error-mobile.png'), animations='disabled')
assert await page.locator('.template-modal').evaluate('(el)=>el.scrollWidth<=el.clientWidth+1')
await page.keyboard.press('Escape')
await expect_form(page)
await expect(page.get_by_label('需求说明文档链接(选填)', exact=True)).to_have_value(reference)
await expect(page.get_by_role('link', name='保留的说明.txt', exact=True)).to_be_attached()
await page.get_by_role('button', name='查看需求说明模板', exact=True).click()
await expect(page.get_by_role('alert')).to_contain_text('模板预览未能加载')
chunks['fail'] = False
await page.get_by_role('button', name='重新加载', exact=True).click()
await expect(page.get_by_role('article')).to_contain_text('二、背景与目标')
await page.get_by_role('button', name='返回填写', exact=True).click()
await expect_form(page)
await page.get_by_role('button', name='保存草稿', exact=True).click()
await expect(page.get_by_role('heading', name='模板容错回归', exact=True)).to_be_attached()
records = await (await context.request.get(origin + '/api/demands')).json()
record = records['demands'][0]
assert record['fields']['background'] == '保留未保存的业务说明'
assert record['fields']['references'] == reference
assert record['attachments'][0]['name'] == '保留的说明.txt'
download = await context.request.get(origin + '/api/attachments/' + record['attachments'][0]['id'])
assert download.ok and await download.body() == '附件内容不丢失'.encode()
checks.append('failed chunks stay inside the preview; repeated retry, close, reopen and successful retry preserve text, links and attachment bytes')
await page.unroute_all(behavior='wait')
await page.close()
page = await start_form()
entered, release, finished = asyncio.Event(), asyncio.Event(), asyncio.Event()
async def hold_response(route):
entered.set()
await release.wait()
try:
await route.continue_()
finally:
finished.set()
await page.route('**/api/documents/**?format=json', hold_response)
await page.get_by_role('button', name='查看需求说明模板', exact=True).click()
await asyncio.wait_for(entered.wait(), timeout=5)
await expect(page.get_by_text('正在加载模板…', exact=True)).to_be_visible()
await page.keyboard.press('Escape')
await expect_form(page)
release.set()
await asyncio.wait_for(finished.wait(), timeout=5)
await page.unroute_all(behavior='wait')
await page.wait_for_load_state('networkidle')
await expect_form(page)
checks.append('Escape before the first body response closes only the preview and late responses do not reopen it')
await page.get_by_role('button', name='查看需求说明模板', exact=True).click()
await expect(page.get_by_role('article')).to_contain_text('二、背景与目标')
await page.get_by_role('button', name='返回填写', exact=True).click()
await expect_form(page)
for _ in range(4):
await page.get_by_role('button', name='查看需求说明模板', exact=True).click()
await expect(page.get_by_role('heading', name='需求说明模板', exact=True)).to_be_visible()
# Do not wait for article/API completion: this caught the regression.
await page.keyboard.press('Escape')
await expect_form(page)
await page.keyboard.press('Escape')
await expect(page.get_by_role('alertdialog')).to_contain_text('放弃未保存的修改?')
await page.get_by_role('button', name='继续填写', exact=True).click()
await expect(page.get_by_label('业务背景与现有处理方式', exact=False)).to_have_value('保留未保存的业务说明')
checks.append('rapid Escape after reopening never triggers form exit; Escape on the form still asks before discarding input')
await page.close()
page = await context.new_page()
await page.goto(origin)
await page.wait_for_load_state('networkidle')
await page.get_by_role('button', name='流程与规范', exact=True).click()
await page.get_by_role('button', name='查看数据来源模板', exact=True).click()
await expect(page.get_by_role('article')).to_contain_text('数据从哪里来')
await page.get_by_role('button', name='关闭模板预览', exact=True).click()
await expect(page.get_by_role('button', name='查看数据来源模板', exact=True)).to_be_focused()
checks.append('closing previews from the template directory restores focus to the originating button')
assert not errors, errors
print(json.dumps({'result': 'passed', 'checks': checks, 'screenshots': str(output)}, ensure_ascii=False), flush=True)
await browser.close()
asyncio.run(main())