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

provider-setup-state.test.ts

159 lines4.7 KB

1import {
2 DEFAULT_SERVER_SETTINGS,
3 ProviderDriverKind,
4 ProviderInstanceId,
5 ServerProvider,
6 resolveProviderInstanceEnabled,
7} from "@t3tools/contracts";
8import * as Schema from "effect/Schema";
9import { describe, expect, it } from "vite-plus/test";
10​
11import { antigravityEnabledPatch, resolveProviderSignInPresentation } from "./provider-setup-state";
12​
13const provider = Schema.decodeSync(ServerProvider)({
14 instanceId: "antigravity",
15 driver: "antigravity",
16 enabled: false,
17 installed: false,
18 version: null,
19 status: "disabled",
20 auth: { status: "unauthenticated" },
21 checkedAt: "2026-09-02T00:00:00.000Z",
22 models: [],
23});
24​
25describe("resolveProviderSignInPresentation", () => {
26 const completedFlow = { phase: "succeeded", message: "Google sign-in is complete." } as const;
27​
28 it("offers sign-in after saved credentials expire, even if the old flow succeeded", () => {
29 expect(
30 resolveProviderSignInPresentation(
31 {
32 enabled: true,
33 auth: { status: "authenticated" },
34 },
35 completedFlow,
36 ),
37 ).toEqual({
38 signedIn: true,
39 showSignOut: true,
40 message: completedFlow.message,
41 });
42​
43 expect(
44 resolveProviderSignInPresentation(
45 {
46 enabled: true,
47 auth: { status: "unauthenticated" },
48 },
49 completedFlow,
50 ),
51 ).toEqual({
52 signedIn: false,
53 showSignOut: false,
54 message: null,
55 });
56 });
57​
58 it("allows credential cleanup without claiming a disabled unknown account is signed in", () => {
59 expect(
60 resolveProviderSignInPresentation(
61 {
62 enabled: false,
63 auth: { status: "unknown" },
64 },
65 completedFlow,
66 ),
67 ).toEqual({
68 signedIn: false,
69 showSignOut: true,
70 message: null,
71 });
72 });
73​
74 it("keeps progress while Google sign-in is still pending", () => {
75 const flow = { phase: "verifying", message: "Checking Google sign-in." } as const;
76 expect(
77 resolveProviderSignInPresentation(
78 {
79 enabled: true,
80 auth: { status: "unauthenticated" },
81 },
82 flow,
83 ),
84 ).toEqual({
85 signedIn: false,
86 showSignOut: false,
87 message: flow.message,
88 });
89 });
90});
91​
92describe("antigravityEnabledPatch", () => {
93 it("enables a legacy instance without losing its executable path or models", () => {
94 const settings = {
95 ...DEFAULT_SERVER_SETTINGS,
96 providers: {
97 ...DEFAULT_SERVER_SETTINGS.providers,
98 antigravity: {
99 ...DEFAULT_SERVER_SETTINGS.providers.antigravity,
100 enabled: false,
101 binaryPath: "/opt/google/agy-acp",
102 customModels: ["gemini-native"],
103 },
104 },
105 };
106 const patch = antigravityEnabledPatch(settings, provider, true);
107 const instance = patch?.providerInstances?.[provider.instanceId];
108​
109 expect(instance).toMatchObject({
110 enabled: true,
111 config: { binaryPath: "/opt/google/agy-acp", customModels: ["gemini-native"] },
112 });
113 expect(instance?.config).not.toHaveProperty("enabled");
114 expect(instance && resolveProviderInstanceEnabled(instance)).toBe(true);
115 expect(settings.providers.antigravity.enabled).toBe(false);
116 });
117​
118 it("keeps separate accounts and environment overrides when enabling a custom instance", () => {
119 const workId = ProviderInstanceId.make("google_work");
120 const personalId = ProviderInstanceId.make("google_personal");
121 const personal = { driver: ProviderDriverKind.make("antigravity"), enabled: true };
122 const settings = {
123 ...DEFAULT_SERVER_SETTINGS,
124 providerInstances: {
125 [personalId]: personal,
126 [workId]: {
127 driver: ProviderDriverKind.make("antigravity"),
128 displayName: "Work Google",
129 enabled: false,
130 config: { enabled: false, binaryPath: "/work/agy-acp", futureSetting: "keep" },
131 environment: [{ name: "WORK_PROXY", value: "http://proxy", sensitive: false }],
132 },
133 },
134 };
135 const patch = antigravityEnabledPatch(settings, { ...provider, instanceId: workId }, true);
136​
137 expect(patch?.providerInstances?.[personalId]).toBe(personal);
138 expect(patch?.providerInstances?.[workId]).toMatchObject({
139 displayName: "Work Google",
140 enabled: true,
141 config: { binaryPath: "/work/agy-acp", futureSetting: "keep" },
142 environment: [{ name: "WORK_PROXY", value: "http://proxy", sensitive: false }],
143 });
144 expect(patch?.providers).toBeUndefined();
145 });
146​
147 it("does not change a different driver", () => {
148 expect(
149 antigravityEnabledPatch(
150 DEFAULT_SERVER_SETTINGS,
151 {
152 ...provider,
153 driver: ProviderDriverKind.make("codex"),
154 },
155 true,
156 ),
157 ).toBeNull();
158 });
159});