fix: 清除错误默认模型与端口硬编码,文档机器路径占位符化
This commit is contained in:
+21
-15
@@ -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}"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user