The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { assert, it } from "@effect/vitest"; |
| 2 | import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts"; |
| 3 | |
| 4 | import { decideProviderSessionTransition } from "./ProviderSessionTransitionPolicy.ts"; |
| 5 | |
| 6 | const driver = ProviderDriverKind.make("codex"); |
| 7 | const instanceId = ProviderInstanceId.make("codex"); |
| 8 | const base = { |
| 9 | driver, |
| 10 | continuationIdentity: { driverKind: driver, continuationKey: "codex:account:one" }, |
| 11 | modelSelection: { instanceId, model: "gpt-5.1-codex" }, |
| 12 | runtimeMode: "full-access" as const, |
| 13 | interactionMode: "default" as const, |
| 14 | workspace: "/repo", |
| 15 | }; |
| 16 | |
| 17 | it("reuses compatible sessions and treats interaction mode as turn-scoped", () => { |
| 18 | assert.deepEqual( |
| 19 | decideProviderSessionTransition({ |
| 20 | current: base, |
| 21 | target: { ...base, interactionMode: "plan", available: true }, |
| 22 | }), |
| 23 | { type: "reuse" }, |
| 24 | ); |
| 25 | }); |
| 26 | |
| 27 | it("uses the adapter's selection transition classification", () => { |
| 28 | assert.deepEqual( |
| 29 | decideProviderSessionTransition({ |
| 30 | current: base, |
| 31 | target: { |
| 32 | ...base, |
| 33 | modelSelection: { ...base.modelSelection, model: "gpt-5.2-codex" }, |
| 34 | available: true, |
| 35 | }, |
| 36 | selectionTransition: { type: "apply_on_next_turn" }, |
| 37 | }), |
| 38 | { type: "switch_model_in_session" }, |
| 39 | ); |
| 40 | assert.deepEqual( |
| 41 | decideProviderSessionTransition({ |
| 42 | current: { |
| 43 | ...base, |
| 44 | }, |
| 45 | target: { |
| 46 | ...base, |
| 47 | modelSelection: { ...base.modelSelection, model: "gpt-5.2-codex" }, |
| 48 | available: true, |
| 49 | }, |
| 50 | selectionTransition: { type: "restart_session" }, |
| 51 | }), |
| 52 | { type: "restart_and_resume" }, |
| 53 | ); |
| 54 | }); |
| 55 | |
| 56 | it("restarts compatible instances for workspace or runtime changes", () => { |
| 57 | assert.deepEqual( |
| 58 | decideProviderSessionTransition({ |
| 59 | current: base, |
| 60 | target: { ...base, workspace: "/other", available: true }, |
| 61 | }), |
| 62 | { type: "restart_and_resume" }, |
| 63 | ); |
| 64 | }); |
| 65 | |
| 66 | it("preserves handoff and missing-classification outcomes across workspace changes", () => { |
| 67 | const target = { |
| 68 | ...base, |
| 69 | modelSelection: { ...base.modelSelection, model: "gpt-5.2-codex" }, |
| 70 | workspace: "/other", |
| 71 | available: true, |
| 72 | }; |
| 73 | assert.deepEqual( |
| 74 | decideProviderSessionTransition({ |
| 75 | current: base, |
| 76 | target, |
| 77 | selectionTransition: { type: "create_with_handoff" }, |
| 78 | }), |
| 79 | { type: "create_with_handoff" }, |
| 80 | ); |
| 81 | assert.deepEqual(decideProviderSessionTransition({ current: base, target }), { |
| 82 | type: "reject", |
| 83 | reason: "The provider adapter did not classify the selection change.", |
| 84 | }); |
| 85 | }); |
| 86 | |
| 87 | it("uses portable handoff for incompatible continuation identities", () => { |
| 88 | assert.deepEqual( |
| 89 | decideProviderSessionTransition({ |
| 90 | current: base, |
| 91 | target: { |
| 92 | ...base, |
| 93 | modelSelection: { |
| 94 | ...base.modelSelection, |
| 95 | instanceId: ProviderInstanceId.make("codex_other"), |
| 96 | }, |
| 97 | continuationIdentity: { driverKind: driver, continuationKey: "codex:account:other" }, |
| 98 | available: true, |
| 99 | }, |
| 100 | }), |
| 101 | { type: "create_with_handoff" }, |
| 102 | ); |
| 103 | }); |