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
+3 -2
View File
@@ -1,7 +1,7 @@
"""E2E Tests for COBOL->Java Verification Platform
Run: cd <project-root> && python -m pytest tests/e2e/ -v
Requires: web server on http://127.0.0.1:8000, WSL available,
Requires: web server on http://127.0.0.1:$TEST_PORT, WSL available,
DEEPSEEK_API_KEY set in the environment.
"""
import json, os, sys, time, uuid, shutil
@@ -11,7 +11,8 @@ from pathlib import Path
import pytest
PROJECT = Path(__file__).parent.parent.parent.resolve()
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}"
TASKS_DIR = PROJECT / "tasks"
UPLOADS_DIR = PROJECT / "uploads"
FIXTURES = PROJECT / "tests" / "fixtures"
+21 -15
View File
@@ -7,11 +7,17 @@ import pytest, os, time, json, shutil
from pathlib import Path
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}"
COBOL_GIT = Path(os.environ.get("COBOL_GIT_ROOT", Path(__file__).resolve().parent.parent.parent / "jcl-cobol-git"))
FIXTURES = Path(__file__).parent / "fixtures"
TESTS_DIR = Path(__file__).parent
def _js(js: str) -> str:
"""JS 模板中的 __BASE_URL__ 占位符替换(避免 f-string 花括号转义)"""
return js.replace("__BASE_URL__", BASE_URL)
# Check if worker can process tasks
def _worker_available():
return os.name == "nt" # Always try on Windows (files go to tasks/)
@@ -72,7 +78,7 @@ def test_full_upload_flow(page: Page, test_files: dict):
def test_submit_with_js_fetch(page: Page, test_files: dict):
"""TC-BIZ-01: Submit via Blob → returns 202 + task_id. (Worker not needed)"""
page.goto(BASE_URL)
result = page.evaluate("""
result = page.evaluate(_js("""
(async () => {
const fd = new FormData();
fd.append("runner", "native");
@@ -80,10 +86,10 @@ def test_submit_with_js_fetch(page: Page, test_files: dict):
fd.append("cobol_src", new Blob(["STOP RUN."], {type:"text/plain"}), "test.cbl");
fd.append("java_src", new Blob(["test"], {type:"text/plain"}), "test.java");
fd.append("mapping", new Blob(["program: TEST"], {type:"text/plain"}), "test.yaml");
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 await r.json();
})()
""")
"""))
assert result.get("task_id"), f"No task_id: {result}"
assert result.get("status") == "queued"
@@ -91,7 +97,7 @@ def test_submit_with_js_fetch(page: Page, test_files: dict):
# Quick status check (don't wait for Worker)
status = page.evaluate(f"""
(async () => {{
const r = await fetch("http://127.0.0.1:8000/status/{result["task_id"]}");
const r = await fetch("{BASE_URL}/status/{result["task_id"]}");
return await r.json();
}})()
""")
@@ -102,16 +108,16 @@ def test_result_page_has_fields_table(page: Page):
"""TC-BIZ-03: Result page renders field comparison table."""
page.goto(BASE_URL)
# Submit a task first
result = page.evaluate("""
result = page.evaluate(_js("""
(async () => {
const fd = new FormData();
fd.append("runner", "native");
["copybook","cobol_src","mapping"].forEach(k =>
fd.append(k, new Blob(["test"], {type:"text/plain"}), k+".txt"));
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 await r.json();
})()
""")
"""))
task_id = result.get("task_id","")
if task_id:
page.goto(f"{BASE_URL}/result/{task_id}")
@@ -122,7 +128,7 @@ def test_result_page_has_fields_table(page: Page):
def test_debug_section_api(page: Page):
"""TC-BIZ-04: /fields/{id} returns debug data."""
page.goto(BASE_URL)
result = page.evaluate("""
result = page.evaluate(_js("""
(async () => {
const fd = new FormData();
fd.append("runner", "native");
@@ -130,17 +136,17 @@ def test_debug_section_api(page: Page):
fd.append("cobol_src", new Blob(["STOP RUN."], {type:"text/plain"}), "test.cbl");
fd.append("java_src", new Blob(["test"], {type:"text/plain"}), "test.java");
fd.append("mapping", new Blob(["program: TEST"], {type:"text/plain"}), "test.yaml");
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 await r.json();
})()
""")
"""))
task_id = result.get("task_id", "")
assert task_id, "No task_id returned"
fields_result = page.evaluate(f"""
(async () => {{
const r = await fetch("http://127.0.0.1:8000/fields/{task_id}");
const r = await fetch("{BASE_URL}/fields/{task_id}");
return await r.json();
}})()
""")
@@ -152,7 +158,7 @@ def test_debug_section_api(page: Page):
def test_file_size_limit(page: Page):
"""TC-BIZ-05: Upload >10MB file returns 413."""
page.goto(BASE_URL)
result = page.evaluate("""
result = page.evaluate(_js("""
(async () => {
const fd = new FormData();
const big = new Blob([new Uint8Array(11*1024*1024)], {type:"text/plain"});
@@ -161,10 +167,10 @@ def test_file_size_limit(page: Page):
fd.append("java_src", new Blob(["test"]), "test.java");
fd.append("mapping", new Blob(["test"]), "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 r.status;
})()
""")
"""))
assert result == 413, f"Expected 413, got {result}"
+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"]