fix: 清除错误默认模型与端口硬编码,文档机器路径占位符化

This commit is contained in:
hangshuo652
2026-08-25 22:35:35 +08:00
parent 8e81f960af
commit c6fa6b1aeb
19 changed files with 85 additions and 57 deletions
+14 -8
View File
@@ -1,11 +1,15 @@
"""
Playwright E2E tests for COBOL-Java Migration Platform Web UI.
Server must be running: python -m uvicorn web.api:app --host 127.0.0.1 --port 8000
Server must be running: python -m uvicorn web.api:app --host 127.0.0.1 --port $TEST_PORT
(端口经 TEST_PORT 环境变量配置, 默认 8000)
"""
import os
import pytest
from playwright.sync_api import Page, expect, sync_playwright
BASE_URL = "http://127.0.0.1:8000"
TEST_PORT = int(os.environ.get("TEST_PORT", "8000"))
BASE_URL = f"http://127.0.0.1:{TEST_PORT}"
@pytest.fixture(scope="module")
@@ -53,13 +57,14 @@ def test_form_elements_present(page: Page):
def test_submit_empty_form(page: Page):
"""验证空表单提交返回 422 (缺少必填字段)"""
page.goto(BASE_URL)
result = page.evaluate("""
js = """
(async () => {
const fd = new FormData();
const r = await fetch('http://127.0.0.1:8000/verify', { method: 'POST', body: fd });
const r = await fetch('__BASE_URL__/verify', { method: 'POST', body: fd });
return r.status;
})()
""")
""".replace("__BASE_URL__", BASE_URL)
result = page.evaluate(js)
assert result == 422
@@ -73,7 +78,7 @@ def test_submit_with_files(page: Page):
page.set_input_files("input[name=mapping]",
"tests/fixtures/simple.yaml")
# 用 evaluate 直接调 API 绕过 webkitdirectory 限制
result = page.evaluate("""
js = """
(async () => {
const fd = new FormData();
fd.append('copybook', new Blob(['test'], {type:'text/plain'}), 'test.cpy');
@@ -81,10 +86,11 @@ def test_submit_with_files(page: Page):
fd.append('java_src', new Blob(['test'], {type:'text/plain'}), 'test.java');
fd.append('mapping', new Blob(['test'], {type:'text/plain'}), 'test.yaml');
fd.append('runner', 'native');
const r = await fetch('http://127.0.0.1:8000/verify', { method: 'POST', body: fd });
const r = await fetch('__BASE_URL__/verify', { method: 'POST', body: fd });
return { status: r.status, body: await r.json() };
})()
""")
""".replace("__BASE_URL__", BASE_URL)
result = page.evaluate(js)
assert result["status"] == 202
assert "task_id" in result["body"]