Open History to see the last commit
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("restarts compatible instances for workspace or runtime changes", () => {
67 assert.deepEqual(
68 decideProviderSessionTransition({
69 current: base,
70 target: { ...base, workspace: "/other", available: true },
71 }),
72 { type: "restart_and_resume" },
73 );
74});
75
76it("preserves handoff and missing-classification outcomes across workspace changes", () => {
77 const target = {
78 ...base,
79 modelSelection: { ...base.modelSelection, model: "gpt-5.2-codex" },
80 workspace: "/other",
81 available: true,
82 };
83 assert.deepEqual(
84 decideProviderSessionTransition({
85 current: base,
86 target,
87 selectionTransition: { type: "create_with_handoff" },
88 }),
89 { type: "create_with_handoff" },
90 );
91 assert.deepEqual(decideProviderSessionTransition({ current: base, target }), {
92 type: "reject",
93 reason: "The provider adapter did not classify the selection change.",
94 });
95});
96
97it("uses portable handoff for incompatible continuation identities", () => {
98 assert.deepEqual(
99 decideProviderSessionTransition({
100 current: base,
101 target: {
102 ...base,
103 modelSelection: {
104 ...base.modelSelection,
105 instanceId: ProviderInstanceId.make("codex_other"),
106 },
107 continuationIdentity: { driverKind: driver, continuationKey: "codex:account:other" },
108 available: true,
109 },
110 }),
111 { type: "create_with_handoff" },
112 );
113});