Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ProviderSessionTransitionPolicy.test.ts

136 lines3.9 KB

1import { assert, it } from "@effect/vitest";
2import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
3​
4import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
5import { decideProviderSessionTransition } from "./ProviderSessionTransitionPolicy.ts";
6​
7const driver = ProviderDriverKind.make("codex");
8const instanceId = ProviderInstanceId.make("codex");
9const base = {
10 driver,
11 continuationIdentity: { driverKind: driver, continuationKey: "codex:account:one" },
12 modelSelection: { instanceId, model: "gpt-5.1-codex" },
13 runtimeMode: "full-access" as const,
14 interactionMode: "default" as const,
15 workspace: "/repo",
16 capabilities: CodexProviderCapabilitiesV2,
17};
18​
19it("reuses compatible sessions and treats interaction mode as turn-scoped", () => {
20 assert.deepEqual(
21 decideProviderSessionTransition({
22 current: base,
23 target: { ...base, interactionMode: "plan", available: true },
24 }),
25 { type: "reuse" },
26 );
27});
28​
29it("uses the adapter's selection transition classification", () => {
30 assert.deepEqual(
31 decideProviderSessionTransition({
32 current: base,
33 target: {
34 ...base,
35 modelSelection: { ...base.modelSelection, model: "gpt-5.2-codex" },
36 available: true,
37 },
38 selectionTransition: { type: "apply_on_next_turn" },
39 }),
40 { type: "switch_model_in_session" },
41 );
42 assert.deepEqual(
43 decideProviderSessionTransition({
44 current: {
45 ...base,
46 capabilities: {
47 ...base.capabilities,
48 sessions: { ...base.capabilities.sessions, supportsModelSwitchInSession: false },
49 },
50 },
51 target: {
52 ...base,
53 capabilities: {
54 ...base.capabilities,
55 sessions: { ...base.capabilities.sessions, supportsModelSwitchInSession: false },
56 },
57 modelSelection: { ...base.modelSelection, model: "gpt-5.2-codex" },
58 available: true,
59 },
60 selectionTransition: { type: "restart_session" },
61 }),
62 { type: "restart_and_resume" },
63 );
64});
65​
66it("treats provider option changes as selection changes", () => {
67 assert.deepEqual(
68 decideProviderSessionTransition({
69 current: {
70 ...base,
71 modelSelection: {
72 ...base.modelSelection,
73 options: [{ id: "reasoningEffort", value: "medium" }],
74 },
75 },
76 target: {
77 ...base,
78 modelSelection: {
79 ...base.modelSelection,
80 options: [{ id: "reasoningEffort", value: "high" }],
81 },
82 available: true,
83 },
84 selectionTransition: { type: "apply_on_next_turn" },
85 }),
86 { type: "switch_model_in_session" },
87 );
88});
89​
90it("restarts compatible instances for workspace or runtime changes", () => {
91 assert.deepEqual(
92 decideProviderSessionTransition({
93 current: base,
94 target: { ...base, workspace: "/other", available: true },
95 }),
96 { type: "restart_and_resume" },
97 );
98});
99​
100it("uses portable handoff for incompatible continuation identities", () => {
101 assert.deepEqual(
102 decideProviderSessionTransition({
103 current: base,
104 target: {
105 ...base,
106 modelSelection: {
107 ...base.modelSelection,
108 instanceId: ProviderInstanceId.make("codex_other"),
109 },
110 continuationIdentity: { driverKind: driver, continuationKey: "codex:account:other" },
111 available: true,
112 },
113 }),
114 { type: "create_with_handoff" },
115 );
116});
117​
118it("uses portable handoff for cross-driver transitions", () => {
119 const claudeDriver = ProviderDriverKind.make("claude");
120 assert.deepEqual(
121 decideProviderSessionTransition({
122 current: base,
123 target: {
124 ...base,
125 driver: claudeDriver,
126 continuationIdentity: { driverKind: claudeDriver, continuationKey: "claude:account:one" },
127 modelSelection: {
128 instanceId: ProviderInstanceId.make("claude"),
129 model: "claude-opus-4-1",
130 },
131 available: true,
132 },
133 }),
134 { type: "create_with_handoff" },
135 );
136});