feat: added recursive goal mapping and tests
ref: N25B-400
This commit is contained in:
@@ -527,3 +527,53 @@ async def test_send_experiment_control_unknown(agent):
|
||||
agent.send.assert_awaited()
|
||||
msg = agent.send.call_args[0][0]
|
||||
assert msg.thread == ""
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_mapping_recursive_goals(agent):
|
||||
"""Verify that nested subgoals are correctly registered in the mapping."""
|
||||
import uuid
|
||||
|
||||
# 1. Setup IDs
|
||||
parent_goal_id = uuid.uuid4()
|
||||
child_goal_id = uuid.uuid4()
|
||||
|
||||
# 2. Create the child goal
|
||||
child_goal = Goal(
|
||||
id=child_goal_id,
|
||||
name="child_goal",
|
||||
description="I am a subgoal",
|
||||
plan=Plan(id=uuid.uuid4(), name="p_child", steps=[]),
|
||||
)
|
||||
|
||||
# 3. Create the parent goal and put the child goal inside its plan steps
|
||||
parent_goal = Goal(
|
||||
id=parent_goal_id,
|
||||
name="parent_goal",
|
||||
description="I am a parent",
|
||||
plan=Plan(id=uuid.uuid4(), name="p_parent", steps=[child_goal]), # Nested here
|
||||
)
|
||||
|
||||
# 4. Build the program
|
||||
phase = Phase(
|
||||
id=uuid.uuid4(),
|
||||
name="phase1",
|
||||
norms=[],
|
||||
goals=[parent_goal], # Only the parent is top-level
|
||||
triggers=[],
|
||||
)
|
||||
prog = Program(phases=[phase])
|
||||
|
||||
# 5. Execute mapping
|
||||
msg = InternalMessage(to="me", thread="new_program", body=prog.model_dump_json())
|
||||
await agent.handle_message(msg)
|
||||
|
||||
# 6. Assertions
|
||||
# Check parent
|
||||
assert str(parent_goal_id) in agent._goal_map
|
||||
assert agent._goal_map[str(parent_goal_id)] == "parent_goal"
|
||||
|
||||
# Check child (This confirms the recursion worked)
|
||||
assert str(child_goal_id) in agent._goal_map
|
||||
assert agent._goal_map[str(child_goal_id)] == "child_goal"
|
||||
assert agent._goal_reverse_map["child_goal"] == str(child_goal_id)
|
||||
|
||||
Reference in New Issue
Block a user