Skip to content

Commit d5dacd1

Browse files
authored
test(integration): allow skill reuse across turns (#11)
1 parent 2bb29e7 commit d5dacd1

3 files changed

Lines changed: 51 additions & 2 deletions

File tree

‎tests/support/scenarios/forward.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ def resources(client: Forward, context: Run) -> None:
138138
session_id,
139139
f"请使用技能 {skill_name},读取并返回 EXAMPLE_SKILL_CODE。",
140140
[skill_value],
141-
require_tool=True,
142141
)
143142

144143

‎tests/support/scenarios/managed.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def resources(client: Managed, context: Run) -> None:
121121
session_id,
122122
f"请使用技能 {skill_name},读取并返回 EXAMPLE_SKILL_CODE。",
123123
[skill_value],
124-
require_tool=True,
125124
)
126125

127126

‎tests/test_scenarios_offline.py‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,57 @@ def test_go_example_scenarios_with_http_stub(mode, scenario, monkeypatch, capsys
5252
assert outputs["cleanup"] == "completed"
5353

5454

55+
@pytest.mark.parametrize("mode", ["forward", "managed"])
56+
@pytest.mark.parametrize(
57+
"case,expected_error",
58+
[
59+
("cached_skill", None),
60+
("missing_first_turn_tool", "No actual tool execution"),
61+
("wrong_skill_value", "missing expected values"),
62+
],
63+
)
64+
def test_resource_scenarios_allow_cached_skill_but_still_verify_tools_and_values(
65+
mode, case, expected_error, monkeypatch
66+
):
67+
config = Config(mode, "test-token", f"https://api.test/api/v1/{mode}", timeout=2, poll_interval=0)
68+
run = Run(config)
69+
service = ExampleService(mode)
70+
original_send = service.send
71+
replies = []
72+
73+
def send(session_id, event):
74+
start = len(service.events[session_id])
75+
user_event = original_send(session_id, event)
76+
reply = service.events[session_id][start + 1 :]
77+
second_turn = len(replies) == 1
78+
if second_turn or case == "missing_first_turn_tool":
79+
reply = [item for item in reply if item["type"] not in ("agent.tool_use", "agent.mcp_tool_use")]
80+
if second_turn and case == "wrong_skill_value":
81+
for item in reply:
82+
if item["type"] == "agent.message":
83+
item["content"] = [{"type": "text", "text": "incorrect skill value"}]
84+
service.events[session_id][start + 1 :] = reply
85+
replies.append(reply)
86+
return user_event
87+
88+
monkeypatch.setattr(service, "send", send)
89+
cls, scenarios = (Forward, FORWARD_SCENARIOS) if mode == "forward" else (Managed, MANAGED_SCENARIOS)
90+
with cls(**config.client_options(), http_client=httpx.Client(transport=httpx.MockTransport(service))) as client:
91+
try:
92+
if expected_error is None:
93+
scenarios["resources"](client, run)
94+
assert len(replies) == 2
95+
assert any(item["type"] == "agent.tool_use" for item in replies[0])
96+
assert not any(item["type"] == "agent.tool_use" for item in replies[1])
97+
else:
98+
with pytest.raises(AssertionError, match=expected_error):
99+
scenarios["resources"](client, run)
100+
finally:
101+
run.cleanup()
102+
assert not run.cleanups
103+
assert not service.mounts
104+
105+
55106
def test_turn_assertions_require_final_assistant_output_and_successful_idle():
56107
result = TurnResult()
57108
for event in [

0 commit comments

Comments
 (0)