78 lines
3.0 KiB
Python
78 lines
3.0 KiB
Python
import inspect
|
|
|
|
from app.schemas.rag import RAGAskRequest
|
|
from app.services.pmflow_ai_evidence_authority import PMFlowAIEvidenceAuthority
|
|
from app.services.pmflow_ai_static_contract_registry import PMFlowAIStaticContractRegistry
|
|
from app.services.pmflow_ai_turn_runtime_service import (
|
|
PMFlowAITurnRuntimeService,
|
|
_render_source_authority_answer_from_turn_state,
|
|
)
|
|
|
|
|
|
def _service() -> PMFlowAITurnRuntimeService:
|
|
return PMFlowAITurnRuntimeService(object(), tenant_id=1)
|
|
|
|
|
|
def _assistant_identity_state():
|
|
return _service().build_initial_turn_state(
|
|
request=RAGAskRequest(question="说明你的能力边界"),
|
|
route_plan={},
|
|
turn_hypothesis={
|
|
"normalized_goal": "assistant_identity",
|
|
"desired_outcome": "说明助手身份和能力边界",
|
|
"answer_shape": "general_answer",
|
|
"goal_frames": [
|
|
{
|
|
"frame_id": "assistant-profile",
|
|
"operation_kind": "explain_assistant",
|
|
"target_scope": {
|
|
"scope_type": "current_space",
|
|
"binding_strength": "surface",
|
|
"source": "turn_goal_assessment",
|
|
},
|
|
"target_object_requirement": "none",
|
|
"source_policy": "none",
|
|
"answer_shape": "general_answer",
|
|
"confidence": 0.9,
|
|
}
|
|
],
|
|
"operation_gaps": [
|
|
{
|
|
"key": "legacy_external_gap",
|
|
"gap_type": "system_evidence_gap",
|
|
"blocking": True,
|
|
"user_actionable": False,
|
|
"system_action_hint": "external_search",
|
|
"reason": "旧链路误把静态合同问题当成外部查证问题。",
|
|
}
|
|
],
|
|
},
|
|
)
|
|
|
|
|
|
def test_packet_af_source_authority_resolves_static_contract_registry() -> None:
|
|
state = _assistant_identity_state()
|
|
|
|
contract = PMFlowAIStaticContractRegistry().resolve_for_turn_state(state)
|
|
authority = PMFlowAIEvidenceAuthority().decide(state)
|
|
|
|
assert contract is not None
|
|
assert contract.contract_key == "assistant_identity.v1"
|
|
assert authority.contract_key == contract.contract_key
|
|
assert authority.renderer_key == "static_contract"
|
|
assert authority.required_evidence == "static_product_contract"
|
|
assert "external_search" in authority.forbidden_first_actions
|
|
|
|
|
|
def test_packet_af_runtime_renderer_consumes_contract_not_inline_answer() -> None:
|
|
state = _assistant_identity_state()
|
|
contract = PMFlowAIStaticContractRegistry().resolve_for_turn_state(state)
|
|
|
|
answer = _render_source_authority_answer_from_turn_state(turn_state=state)
|
|
|
|
assert contract is not None
|
|
assert not hasattr(contract, "answer")
|
|
assert "我是 PMFlow AI" in answer
|
|
assert "项目操作副驾" in answer
|
|
assert "我是 PMFlow AI" not in inspect.getsource(_render_source_authority_answer_from_turn_state)
|