TypeScript
fix(server): warn when connect unlink leaves the relay record (#17743)
macocfb78cf433e5
diff --git a/apps/server/src/cli/connect.test.ts b/apps/server/src/cli/connect.test.tsindex 514a9b56a2a..f7bbcd23e67 100644--- a/apps/server/src/cli/connect.test.ts+++ b/apps/server/src/cli/connect.test.ts@@ -192,3 +192,68 @@ it.effect("keeps disconnect causes in structured logs and out of console warning),);});++/** Captures console lines from a successful local disconnect report. */+const captureDisconnectReport = (input: {+ readonly clearAuthorization: boolean;+ readonly liveResult: {+ readonly status: "succeeded";+ };+ readonly relayResult: Exit.Exit<+ { readonly status: "not-authenticated" } | { readonly status: "revoked" },+ unknown+ >;+}) => {+ const lines: Array<{ readonly stream: "log" | "warn"; readonly text: string }> = [];+ const testConsole = {+ ...globalThis.console,+ log: (...args: ReadonlyArray<unknown>) => {+ lines.push({ stream: "log", text: args.map(String).join(" ") });+ },+ warn: (...args: ReadonlyArray<unknown>) => {+ lines.push({ stream: "warn", text: args.map(String).join(" ") });+ },+ } satisfies Console.Console;++ return reportCloudDisconnectResults(input).pipe(+ Effect.provideService(Console.Console, testConsole),+ Effect.provide(Logger.layer([Logger.make(() => undefined)], { mergeWithExisting: false })),+ Effect.as(lines),+ );+};++it.effect("warns to deregister when unlink has no stored CLI authorization", () =>+ Effect.gen(function* () {+ const lines = yield* captureDisconnectReport({+ clearAuthorization: false,+ liveResult: { status: "succeeded" },+ relayResult: Exit.succeed({ status: "not-authenticated" }),+ });++ assert.deepEqual(+ lines.map((line) => line.stream),+ ["log", "warn"],+ );+ assert.equal(lines[0]?.text, "T3 Connect is disabled locally.");+ assert.include(lines[1]?.text, "The relay-side environment record was not revoked.");+ assert.include(lines[1]?.text, "T3 Connect page of your T3 account");+ assert.include(lines[1]?.text, "`t3 connect login`");+ assert.notInclude(lines.map((line) => line.text).join("\n"), "Revoked the relay-side");+ }),+);++it.effect("points a failed relay unlink at retry and account deregistration", () =>+ Effect.gen(function* () {+ const lines = yield* captureDisconnectReport({+ clearAuthorization: false,+ liveResult: { status: "succeeded" },+ relayResult: Exit.fail("relay unreachable"),+ });+ const warning = lines.find((line) => line.stream === "warn")?.text ?? "";++ assert.equal(lines[0]?.text, "T3 Connect is disabled locally.");+ assert.include(warning, "Run `t3 connect unlink` again when the relay is reachable");+ assert.include(warning, "deregister it from the T3 Connect page of your T3 account");+ assert.notInclude(warning, "relay unreachable");+ }),+);diff --git a/apps/server/src/cli/connect.ts b/apps/server/src/cli/connect.tsindex 74ea4aaa441..9de28623c31 100644--- a/apps/server/src/cli/connect.ts+++ b/apps/server/src/cli/connect.ts@@ -349,6 +349,11 @@ const unlinkRelayEnvironment = Effect.fn("cloud.cli.unlink_relay_environment")(f: ({ status: "not-linked" } satisfies RelayUnlinkResult);});+/**+ * Prints the local disconnect outcome, then whether the relay record was revoked.+ * A missing CLI login or a failed relay DELETE leaves that record registered, so+ * those outcomes warn to deregister it from the T3 Connect account page.+ */export const reportCloudDisconnectResults = Effect.fn("cloud.cli.report_disconnect_results")(function* (input: {readonly clearAuthorization: boolean;@@ -377,7 +382,11 @@ export const reportCloudDisconnectResults = Effect.fn("cloud.cli.report_disconneyield* Console.warn(input.clearAuthorization? "Could not revoke the relay-side environment record before signing out.\nThe stored CLI authorization was still removed locally."- : "Could not revoke the relay-side environment record yet.\nRun `t3 connect unlink` again when the relay is reachable.",+ : "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.",+ );+ } else if (input.relayResult.value.status === "not-authenticated") {+ yield* Console.warn(+ "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.",);} else if (input.relayResult.value.status === "revoked") {yield* Console.log("Revoked the relay-side environment record.");