generated from kgod/ai-review-template
55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
"""队列护栏测试:/create 幂等不重置队列、旧格式 profile 惰性初始化。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from test_api import BASE, active_component, event
|
|
from test_enrichment_flow import (
|
|
continue_enriching,
|
|
created_session,
|
|
skip_current,
|
|
submit_to,
|
|
)
|
|
from test_enrichment_records import (
|
|
INTERNSHIP_ENTRY,
|
|
choose,
|
|
confirm_active,
|
|
latest_patch_revision,
|
|
)
|
|
|
|
|
|
def test_create_idempotent_with_queue_initialized(client: TestClient):
|
|
session_id, body = created_session(client)
|
|
body = continue_enriching(client, session_id, body)
|
|
body = submit_to(client, session_id, body, "record_fields", dict(INTERNSHIP_ENTRY)).json()
|
|
body = confirm_active(client, session_id, body)
|
|
assert latest_patch_revision(body) == 2
|
|
|
|
# 重复创建:幂等返回,不重置队列与 revision
|
|
duplicate = client.post(f"{BASE}/sessions/{session_id}/create", json={})
|
|
assert duplicate.status_code == 200, duplicate.text
|
|
assert duplicate.json()["created"] is False
|
|
|
|
# 队列仍停留在 AddAnother,可正常推进到 project
|
|
body = choose(client, session_id, body, "next")
|
|
assert active_component(body)["data"]["module"] == "project"
|
|
|
|
|
|
def test_legacy_session_without_enrichment_keys_lazy_initializes(client: TestClient):
|
|
# 创建后的 profile 不含 records/tags/enrichment 键(等同旧会话格式),
|
|
# 首个 continue_enriching 应惰性建队列并正常走完整链路。
|
|
session_id, body = created_session(client)
|
|
body = continue_enriching(client, session_id, body)
|
|
assert active_component(body)["data"]["component"] == "record_fields"
|
|
assert active_component(body)["data"]["module"] == "internship"
|
|
|
|
for _ in range(5):
|
|
body = skip_current(client, session_id, body)
|
|
assert body["stage"] == "RESUME_ENRICHING"
|
|
assert active_component(body)["data"]["component"] == "custom_card_picker"
|
|
|
|
body = choose(client, session_id, body, "finish")
|
|
assert body["stage"] == "CONTENT_READY"
|
|
assert active_component(body)["data"]["component"] == "content_ready_card"
|