feat: 完善 Alpha 详情页布局与提交检查,增加描述生成与验证功能
Deploy production / deploy (push) Successful in 54s

This commit is contained in:
yuxuanhui
2026-09-10 11:45:05 +08:00
parent f67b4d99b7
commit 9334b6f651
12 changed files with 500 additions and 122 deletions
+76 -2
View File
@@ -207,7 +207,9 @@ async def test_ai_uses_independent_model_shared_connection_without_platform_writ
yield FunctionModel(
function=lambda messages, info: ModelResponse(
parts=[
ToolCallPart(info.output_tools[0].name, {"descriptions": {"regular": FIELDS}}),
ToolCallPart(
info.output_tools[0].name, {"descriptions": {"regular": Description(**FIELDS).text()}}
),
]
)
)
@@ -229,7 +231,7 @@ async def test_ai_uses_independent_model_shared_connection_without_platform_writ
"/api/v1/alphas/alpha1/description/generate", json={"snapshot": state["snapshot"]}
)
assert generated.status_code == 200, generated.text
assert generated.json()["descriptions"] == {"regular": FIELDS}
assert generated.json()["descriptions"] == {"regular": Description(**FIELDS).text()}
assert seen == [("https://model.test/v1", "description-model", "responses", "shared-secret")]
assert not platform.calls
async with app.state.sessions() as db:
@@ -336,3 +338,75 @@ def test_description_model_migration_preserves_existing_config(tmp_path):
c["name"] for c in sa.inspect(connection).get_columns("ai_settings")
}
engine.dispose()
@pytest.mark.parametrize("cached", [False, True])
async def test_no_local_references_does_not_block_platform_check(app, logged_in, cached):
platform = await setup(app)
async with app.state.sessions.begin() as db:
result = await db.get(SelfCorrelation, "alpha1")
if cached:
result.result = {"status": "insufficient_data", "candidate_count": 0}
else:
await db.delete(result)
state = (await logged_in.get("/api/v1/alphas/alpha1/submission")).json()
assert state["can_check"] is True
response = await enqueue(logged_in)
assert response.status_code == 202, response.text
await app.state.runner.execute(response.json()["id"])
async with app.state.sessions() as db:
job = await db.get(Job, response.json()["id"])
assert job.status == "completed", job.error
assert ("GET", "/alphas/alpha1/check") in platform.calls
assert not any(path.endswith("/submit") for _, path in platform.calls)
@pytest.mark.parametrize("length", [499, 500, 501])
def test_description_total_character_limit(length):
fields = {**FIELDS, "idea": "x"}
fields["idea"] += "x" * (length - len(Description(**fields).text()))
if length > 500:
with pytest.raises(ValidationError):
Description(**fields)
else:
assert len(Description(**fields).text()) == length
async def test_new_reference_blocks_empty_cached_result_at_enqueue_and_execution(app, logged_in):
platform = await setup(app)
async with app.state.sessions.begin() as db:
(await db.get(SelfCorrelation, "alpha1")).result = {
"status": "insufficient_data",
"candidate_count": 0,
}
response = await enqueue(logged_in)
assert response.status_code == 202
async with app.state.sessions.begin() as db:
await upsert_alpha(db, alpha(id="peer", status="ACTIVE"))
assert not (await logged_in.get("/api/v1/alphas/alpha1/submission")).json()["can_check"]
assert (await enqueue(logged_in)).status_code == 409
await app.state.runner.execute(response.json()["id"])
async with app.state.sessions() as db:
assert (await db.get(Job, response.json()["id"])).status == "failed"
assert not platform.patches
assert ("GET", "/alphas/alpha1/check") not in platform.calls
async def test_complete_text_input_is_written_as_three_paragraphs(app, logged_in):
platform = await setup(app)
text = Description(**FIELDS).text()
response = await enqueue(logged_in, {"regular": text})
assert response.status_code == 202
await app.state.runner.execute(response.json()["id"])
assert platform.patches == [{"regular": {"description": text}}]
assert len(text.split("\n\n")) == 3
state = (await logged_in.get("/api/v1/alphas/alpha1/submission")).json()
assert state["descriptions"] == {"regular": text}
@pytest.mark.parametrize("bad", ["x" * 501, "x" * 100, Description(**FIELDS).text().replace("\n\n", "\n")])
def test_generation_rejects_incomplete_or_oversized_text(bad):
from app.submission import GeneratedDescriptions
with pytest.raises(ValidationError):
GeneratedDescriptions(descriptions={"regular": bad})