fix(copilot): handle deprecated function role and move integration test

- Add 'function' to role check in determine_x_initiator() so legacy
  function-call format is treated as agent continuation (no premium charge)
- Move test_github_copilot_billing.py from tests/llm_responses_api_testing/
  to tests/integration/github_copilot/ (real API calls belong in integration,
  not alongside mock-only tests)
- Add unit test for legacy function role
This commit is contained in:
jtstothard 2026-04-28 11:52:38 +01:00
parent 0628d4f3e1
commit 5a65a6b713
3 changed files with 10 additions and 2 deletions

View file

@ -188,8 +188,8 @@ def determine_x_initiator(messages_or_input: Union[list, str]) -> str:
# No role = agent-initiated (Responses API role-less item types)
if role is None:
return "agent"
# assistant or tool role = agent continuation
if role in ("assistant", "tool"):
# assistant, tool, or legacy function role = agent continuation
if role in ("assistant", "tool", "function"):
return "agent"
return "user"

View file

@ -129,5 +129,13 @@ class TestDetermineXInitiator:
def test_string_input_returns_user(self):
assert determine_x_initiator("What is 2+2?") == "user"
def test_legacy_function_role_returns_agent(self):
"""Deprecated role:function must be treated as agent continuation."""
messages = [
{"role": "user", "content": "Call a function"},
{"role": "function", "content": "result", "name": "my_fn"},
]
assert determine_x_initiator(messages) == "agent"
def test_empty_list_returns_user(self):
assert determine_x_initiator([]) == "user"