test: complete advisor full-stack acceptance record

This commit is contained in:
Windows
2026-09-11 17:19:40 +08:00
parent 852bafb374
commit 3e4f21388c
2 changed files with 70 additions and 25 deletions
+38 -2
View File
@@ -63,6 +63,32 @@ def token(sub: str) -> str:
)
async def ensure_onboarding(client: httpx.AsyncClient, auth: dict[str, str]) -> None:
"""让独立验收客户满足业务接口的首次登录前置条件。"""
response = await client.get("/api/v1/onboarding/risk-questionnaire", headers=auth)
record("开户问卷状态可查询", "200", str(response.status_code))
if response.status_code != 200:
return
questionnaire = response.json().get("data") or {}
if not questionnaire.get("required"):
record("测试客户已完成开户问卷", "completed", "completed")
return
submission = {
"answers": {
"q1": 12, "q2": 4, "q3": 5, "q4": 4, "q5": 4, "q6": 5,
"q7": 5, "q8": 4, "q9": 4, "q10": 1, "q11": 5, "q12": 4,
"q13": 4,
},
"declaration_accepted": True,
}
response = await client.post(
"/api/v1/onboarding/risk-questionnaire/submissions",
json=submission,
headers={**auth, "Idempotency-Key": uuid.uuid4().hex},
)
record("首次登录问卷提交", "201", str(response.status_code))
class StubGovernance:
async def resolve(self, definition: AgentDefinition, context: RequestContext) -> ResolvedAgentConfig:
del definition, context
@@ -103,7 +129,12 @@ def register_probes(factory: AgentFactory, *, version: str = "acceptance") -> No
allowed_roles=roles,
allowed_portals=("api",),
)
factory.register(definition, lambda _ctx, _def=definition: AcceptanceAgent(_def))
def builder(
_ctx: RequestContext, _def: AgentDefinition = definition
) -> BaseAgent:
return AcceptanceAgent(_def)
factory.register(definition, builder)
def build_registry() -> AgentFactory:
@@ -204,6 +235,7 @@ async def main() -> None:
transport=httpx.ASGITransport(app=app), base_url="http://test", timeout=30
) as client:
auth = {"Authorization": f"Bearer {token(CUSTOMER_ID)}"}
await ensure_onboarding(client, auth)
response = await client.post(
"/api/v1/agent-runs",
@@ -252,8 +284,12 @@ async def main() -> None:
await asyncio.sleep(1.0)
await runtime.execute(run_id)
events = await subscription
print(f"SSE events: {events}")
record("SSE 含 delta 事件", "yes", "yes" if "delta" in events else "no")
record(
"SSE 含内容事件", "yes",
"yes" if {"delta", "replace"}.intersection(events) else "no",
)
record("SSE 终止事件", "done", events[-1] if events else "无事件")
response = await client.get(f"/api/v1/agent-runs/{run_id}", headers=auth)