(context: vscode.ExtensionContext)
| 687 | } |
| 688 | |
| 689 | async function debugConnectionCommand(context: vscode.ExtensionContext): Promise<void> { |
| 690 | assert(context, "debugConnectionCommand requires context"); |
| 691 | |
| 692 | const output = getMuxLogChannel(); |
| 693 | output.show(true); |
| 694 | |
| 695 | muxLogInfo("mux: debugConnection start"); |
| 696 | |
| 697 | let discovery: Awaited<ReturnType<typeof discoverServerConfig>>; |
| 698 | try { |
| 699 | discovery = await discoverServerConfig(context); |
| 700 | } catch (error) { |
| 701 | muxLogError("mux: debugConnection discovery failed", { error: formatError(error) }); |
| 702 | void vscode.window.showErrorMessage( |
| 703 | `mux: Failed to discover server config. (${formatError(error)})` |
| 704 | ); |
| 705 | return; |
| 706 | } |
| 707 | |
| 708 | muxLogInfo("mux: debugConnection discovered server config", { |
| 709 | baseUrl: discovery.baseUrl, |
| 710 | baseUrlSource: discovery.baseUrlSource, |
| 711 | authTokenSource: discovery.authTokenSource, |
| 712 | hasAuthToken: Boolean(discovery.authToken), |
| 713 | }); |
| 714 | |
| 715 | const reachable = await checkServerReachable(discovery.baseUrl, { timeoutMs: 2_000 }); |
| 716 | muxLogInfo("mux: debugConnection server reachable", reachable); |
| 717 | |
| 718 | if (reachable.status !== "ok") { |
| 719 | void vscode.window.showErrorMessage( |
| 720 | `mux: Server not reachable at ${discovery.baseUrl}. (${reachable.error})` |
| 721 | ); |
| 722 | return; |
| 723 | } |
| 724 | |
| 725 | const client = createApiClient({ baseUrl: discovery.baseUrl, authToken: discovery.authToken }); |
| 726 | |
| 727 | const auth = await checkAuth(client, { timeoutMs: 2_000 }); |
| 728 | muxLogInfo("mux: debugConnection auth", auth); |
| 729 | |
| 730 | if (auth.status !== "ok") { |
| 731 | const hint = |
| 732 | auth.status === "unauthorized" |
| 733 | ? ' Run "mux: Configure Connection" to update the auth token.' |
| 734 | : ""; |
| 735 | |
| 736 | void vscode.window.showErrorMessage( |
| 737 | `mux: Failed to authenticate at ${discovery.baseUrl}. (${auth.error})${hint}` |
| 738 | ); |
| 739 | return; |
| 740 | } |
| 741 | |
| 742 | let workspaceCount: number | null = null; |
| 743 | try { |
| 744 | const workspaces = await getAllWorkspacesFromApi(client); |
| 745 | workspaceCount = workspaces.length; |
| 746 | muxLogInfo("mux: debugConnection listed workspaces", { count: workspaceCount }); |
no test coverage detected