-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathtest_auto_tier_e2e.py
More file actions
81 lines (64 loc) · 3.51 KB
/
Copy pathtest_auto_tier_e2e.py
File metadata and controls
81 lines (64 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
E2E coverage for Auto routing tier switching (snapshot category ``auto_tier``).
The runtime stages an Auto routing preference instead of applying it immediately: a
request stays "unclaimed" until a later turn using the ``auto`` model mints a usable
model and token pair. These tests observe that staged state through
``model.get_current``, so they assert what the runtime actually recorded rather than
what the SDK serialized.
"""
from __future__ import annotations
import pytest
from copilot.rpc import ModelSwitchAutoTierStatus
from copilot.session import PermissionHandler
from copilot.session_events import AutoTier
from .testharness import E2ETestContext
pytestmark = pytest.mark.asyncio(loop_scope="module")
async def pending_auto_tier(session) -> AutoTier | None:
return (await session.rpc.model.get_current()).pending_auto_tier
class TestAutoTier:
async def test_should_stage_and_reset_auto_tier_preference(self, ctx: E2ETestContext):
session = await ctx.client.create_session(
on_permission_request=PermissionHandler.approve_all,
model="auto",
)
try:
assert await pending_auto_tier(session) is None
staged = await session.set_auto_tier("efficiency")
assert staged.status == ModelSwitchAutoTierStatus.PENDING
assert staged.pending_auto_tier == AutoTier.EFFICIENCY
assert await pending_auto_tier(session) == AutoTier.EFFICIENCY
# A second request replaces the first and reports the one it displaced.
superseded = await session.set_auto_tier("intelligence")
assert superseded.status == ModelSwitchAutoTierStatus.PENDING
assert superseded.pending_auto_tier == AutoTier.INTELLIGENCE
assert superseded.superseded_auto_tier == AutoTier.EFFICIENCY
assert await pending_auto_tier(session) == AutoTier.INTELLIGENCE
# Passing None returns the session to provider-default routing. The status is
# "unchanged" because provider-default was already the committed preference;
# the request's effect is cancelling the staged one.
reset = await session.set_auto_tier(None)
assert reset.status == ModelSwitchAutoTierStatus.UNCHANGED
assert reset.superseded_auto_tier == AutoTier.INTELLIGENCE
assert await pending_auto_tier(session) is None
finally:
await session.disconnect()
async def test_should_preserve_auto_tier_when_set_model_omits_it(self, ctx: E2ETestContext):
session = await ctx.client.create_session(
on_permission_request=PermissionHandler.approve_all,
model="auto",
)
try:
await session.set_auto_tier("balance")
assert await pending_auto_tier(session) == AutoTier.BALANCE
# Omitting the argument leaves the staged preference alone.
await session.set_model("auto")
assert await pending_auto_tier(session) == AutoTier.BALANCE
# Supplying a tier replaces it.
await session.set_model("auto", auto_tier="intelligence")
assert await pending_auto_tier(session) == AutoTier.INTELLIGENCE
# Supplying None clears it. Omission, a value, and None are three distinct
# outcomes, which is why the argument cannot collapse to a plain optional.
await session.set_model("auto", auto_tier=None)
assert await pending_auto_tier(session) is None
finally:
await session.disconnect()