@devries-cameron20 / t3code Mirror · read-only / commits / cfb78cf433
Fork 0

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 23, 04:15 UTC

fix(server): warn when connect unlink leaves the relay record (#17743)

Co-authored-by: macodev00 <macodev00@users.noreply.github.com>

maco committed Oct 18, 2026 at 21:25 UTC cfb78cf433e52c2d1f4333c9540f3ffc2aa38a63
2 files changed +75 -1
apps/server/src/cli/connect.test.ts
+65
@@ -192,3 +192,68 @@ it.effect("keeps disconnect causes in structured logs and out of console warning
192 ),
193 );
194 });
195 +
196 +/** Captures console lines from a successful local disconnect report. */
197 +const captureDisconnectReport = (input: {
198 + readonly clearAuthorization: boolean;
199 + readonly liveResult: {
200 + readonly status: "succeeded";
201 + };
202 + readonly relayResult: Exit.Exit<
203 + { readonly status: "not-authenticated" } | { readonly status: "revoked" },
204 + unknown
205 + >;
206 +}) => {
207 + const lines: Array<{ readonly stream: "log" | "warn"; readonly text: string }> = [];
208 + const testConsole = {
209 + ...globalThis.console,
210 + log: (...args: ReadonlyArray<unknown>) => {
211 + lines.push({ stream: "log", text: args.map(String).join(" ") });
212 + },
213 + warn: (...args: ReadonlyArray<unknown>) => {
214 + lines.push({ stream: "warn", text: args.map(String).join(" ") });
215 + },
216 + } satisfies Console.Console;
217 +
218 + return reportCloudDisconnectResults(input).pipe(
219 + Effect.provideService(Console.Console, testConsole),
220 + Effect.provide(Logger.layer([Logger.make(() => undefined)], { mergeWithExisting: false })),
221 + Effect.as(lines),
222 + );
223 +};
224 +
225 +it.effect("warns to deregister when unlink has no stored CLI authorization", () =>
226 + Effect.gen(function* () {
227 + const lines = yield* captureDisconnectReport({
228 + clearAuthorization: false,
229 + liveResult: { status: "succeeded" },
230 + relayResult: Exit.succeed({ status: "not-authenticated" }),
231 + });
232 +
233 + assert.deepEqual(
234 + lines.map((line) => line.stream),
235 + ["log", "warn"],
236 + );
237 + assert.equal(lines[0]?.text, "T3 Connect is disabled locally.");
238 + assert.include(lines[1]?.text, "The relay-side environment record was not revoked.");
239 + assert.include(lines[1]?.text, "T3 Connect page of your T3 account");
240 + assert.include(lines[1]?.text, "`t3 connect login`");
241 + assert.notInclude(lines.map((line) => line.text).join("\n"), "Revoked the relay-side");
242 + }),
243 +);
244 +
245 +it.effect("points a failed relay unlink at retry and account deregistration", () =>
246 + Effect.gen(function* () {
247 + const lines = yield* captureDisconnectReport({
248 + clearAuthorization: false,
249 + liveResult: { status: "succeeded" },
250 + relayResult: Exit.fail("relay unreachable"),
251 + });
252 + const warning = lines.find((line) => line.stream === "warn")?.text ?? "";
253 +
254 + assert.equal(lines[0]?.text, "T3 Connect is disabled locally.");
255 + assert.include(warning, "Run `t3 connect unlink` again when the relay is reachable");
256 + assert.include(warning, "deregister it from the T3 Connect page of your T3 account");
257 + assert.notInclude(warning, "relay unreachable");
258 + }),
259 +);
apps/server/src/cli/connect.ts
+10 -1
@@ -349,6 +349,11 @@ const unlinkRelayEnvironment = Effect.fn("cloud.cli.unlink_relay_environment")(f
349 : ({ status: "not-linked" } satisfies RelayUnlinkResult);
350 });
351
352 +/**
353 + * Prints the local disconnect outcome, then whether the relay record was revoked.
354 + * A missing CLI login or a failed relay DELETE leaves that record registered, so
355 + * those outcomes warn to deregister it from the T3 Connect account page.
356 + */
357 export const reportCloudDisconnectResults = Effect.fn("cloud.cli.report_disconnect_results")(
358 function* (input: {
359 readonly clearAuthorization: boolean;
@@ -377,7 +382,11 @@ export const reportCloudDisconnectResults = Effect.fn("cloud.cli.report_disconne
382 yield* Console.warn(
383 input.clearAuthorization
384 ? "Could not revoke the relay-side environment record before signing out.\nThe stored CLI authorization was still removed locally."
380 - : "Could not revoke the relay-side environment record yet.\nRun `t3 connect unlink` again when the relay is reachable.",
385 + : "Could not revoke the relay-side environment record yet.\nRun `t3 connect unlink` again when the relay is reachable, or deregister it from the T3 Connect page of your T3 account.",
386 + );
387 + } else if (input.relayResult.value.status === "not-authenticated") {
388 + yield* Console.warn(
389 + "The relay-side environment record was not revoked.\nDeregister it from the T3 Connect page of your T3 account, or run `t3 connect login` and retry.",
390 );
391 } else if (input.relayResult.value.status === "revoked") {
392 yield* Console.log("Revoked the relay-side environment record.");