From 904986fc2b83ac8216700ae8c1efd09206fccabe Mon Sep 17 00:00:00 2001 From: nullStack65 <112618179+nullStack65@users.noreply.github.com> Date: Thu, 19 Nov 2026 02:54:48 +0000 Subject: [PATCH 1/2] feat: sender line in the thread hover card, Tailscale HTTPS on by default The sidebar hover card gains a line naming who the thread came from, with the same labels as the sender badge and From filter, the launching thread's title for agent work, and "Sender unknown" when nothing says. Desktop Tailscale HTTPS is now on by default. Only an explicit off is stored, so machines that never stored a choice turn it on. Without Tailscale it stays inert, and the settings row shows a status line. Co-Authored-By: Claude Opus 5.5 --- .../src/backend/DesktopServerExposure.test.ts | 2 +- .../src/settings/DesktopAppSettings.test.ts | 10 +++- .../src/settings/DesktopAppSettings.ts | 5 +- .../components/Sidebar.drag.browser.test.tsx | 2 + apps/web/src/components/Sidebar.tsx | 21 +++++++ .../ConnectionsSettings.logic.test.ts | 34 +++++++++++ .../settings/ConnectionsSettings.logic.ts | 36 +++++++++--- .../settings/ConnectionsSettings.tsx | 57 +++++++++---------- .../components/sidebar/SidebarThreadRow.tsx | 23 ++++++++ docs/user/remote-access.md | 6 +- .../src/state/threadAttribution.test.ts | 33 ++++++++++- .../src/state/threadAttribution.ts | 24 ++++++++ 12 files changed, 208 insertions(+), 45 deletions(-) diff --git a/apps/desktop/src/backend/DesktopServerExposure.test.ts b/apps/desktop/src/backend/DesktopServerExposure.test.ts index c222237dffa7..5625b3826e79 100644 --- a/apps/desktop/src/backend/DesktopServerExposure.test.ts +++ b/apps/desktop/src/backend/DesktopServerExposure.test.ts @@ -253,7 +253,7 @@ describe("DesktopServerExposure", () => { mode: "network-accessible", endpointUrl: "http://192.168.1.20:4173", advertisedHost: "192.168.1.20", - tailscaleServeEnabled: false, + tailscaleServeEnabled: true, tailscaleServePort: 443, }); diff --git a/apps/desktop/src/settings/DesktopAppSettings.test.ts b/apps/desktop/src/settings/DesktopAppSettings.test.ts index 04406f63c6b3..16690c27e4b5 100644 --- a/apps/desktop/src/settings/DesktopAppSettings.test.ts +++ b/apps/desktop/src/settings/DesktopAppSettings.test.ts @@ -4,6 +4,7 @@ import { assert, describe, it } from "@effect/vitest"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; import * as Layer from "effect/Layer"; +import * as Option from "effect/Option"; import * as PlatformError from "effect/PlatformError"; import * as Schema from "effect/Schema"; import * as Tracer from "effect/Tracer"; @@ -295,6 +296,7 @@ describe("DesktopSettings", () => { yield* settings.setMainWindowBounds({ x: -1200, y: 40, width: 400, height: 360 }, true); yield* settings.setServerExposureMode("network-accessible"); + yield* settings.setTailscaleServe({ enabled: false, port: Option.none() }); const persisted = yield* decodeDesktopSettingsPatch( yield* fileSystem.readFileString(environment.desktopSettingsPath), @@ -303,6 +305,7 @@ describe("DesktopSettings", () => { mainWindowBounds: { x: -1200, y: 40, width: 400, height: 360 }, mainWindowMaximized: true, serverExposureMode: "network-accessible", + tailscaleServeEnabled: false, } satisfies typeof DesktopSettingsPatch.Type); const restored = yield* Effect.gen(function* () { @@ -311,6 +314,7 @@ describe("DesktopSettings", () => { }).pipe(Effect.provide(DesktopAppSettings.layer)); assert.deepEqual(restored.mainWindowBounds, persisted.mainWindowBounds); assert.isTrue(restored.mainWindowMaximized); + assert.isFalse(restored.tailscaleServeEnabled); }), ), ); @@ -381,7 +385,8 @@ describe("DesktopSettings", () => { mainWindowBounds: null, mainWindowMaximized: false, serverExposureMode: "local-only", - tailscaleServeEnabled: false, + // A file without the key is a machine that never turned Tailscale HTTPS off. + tailscaleServeEnabled: true, tailscaleServePort: 443, updateChannel: "nightly", updateChannelConfiguredByUser: false, @@ -410,7 +415,8 @@ describe("DesktopSettings", () => { mainWindowBounds: null, mainWindowMaximized: false, serverExposureMode: "local-only", - tailscaleServeEnabled: false, + // A file without the key is a machine that never turned Tailscale HTTPS off. + tailscaleServeEnabled: true, tailscaleServePort: 443, updateChannel: "latest", updateChannelConfiguredByUser: true, diff --git a/apps/desktop/src/settings/DesktopAppSettings.ts b/apps/desktop/src/settings/DesktopAppSettings.ts index e81da7066064..302f1472a187 100644 --- a/apps/desktop/src/settings/DesktopAppSettings.ts +++ b/apps/desktop/src/settings/DesktopAppSettings.ts @@ -74,7 +74,8 @@ export const DEFAULT_DESKTOP_SETTINGS: DesktopSettings = { mainWindowBounds: null, mainWindowMaximized: false, serverExposureMode: "local-only", - tailscaleServeEnabled: false, + // Closura fleet default. Only an explicit off is stored; Serve stays inert without Tailscale. + tailscaleServeEnabled: true, tailscaleServePort: DEFAULT_TAILSCALE_SERVE_PORT, updateChannel: "latest", updateChannelConfiguredByUser: false, @@ -231,7 +232,7 @@ function normalizeDesktopSettingsDocument( mainWindowMaximized: mainWindowBounds !== null && parsed.mainWindowMaximized === true, serverExposureMode: parsed.serverExposureMode === "network-accessible" ? "network-accessible" : "local-only", - tailscaleServeEnabled: parsed.tailscaleServeEnabled === true, + tailscaleServeEnabled: parsed.tailscaleServeEnabled ?? defaultSettings.tailscaleServeEnabled, tailscaleServePort: normalizeTailscaleServePort(parsed.tailscaleServePort), updateChannel: updateChannelConfiguredByUser ? Option.getOrElse(parsedUpdateChannel, () => defaultSettings.updateChannel) diff --git a/apps/web/src/components/Sidebar.drag.browser.test.tsx b/apps/web/src/components/Sidebar.drag.browser.test.tsx index f3402f20a4bc..58b4b4548cf1 100644 --- a/apps/web/src/components/Sidebar.drag.browser.test.tsx +++ b/apps/web/src/components/Sidebar.drag.browser.test.tsx @@ -120,6 +120,8 @@ it("keeps focus in the search box when a click picks a search result", async () projectDisplayName={null} environmentLabel={null} environmentMachine="server" + senderLabel={null} + senderByAgent={false} providerEntryByInstanceId={new Map()} isHighlighted={false} isRouteActive={false} diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 3461a2ae8c7c..81aca58f2852 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -1,9 +1,11 @@ import { SidebarThreadFilterMenu } from "./sidebar/SidebarThreadFilterMenu"; import { matchesThreadListFilter, threadListFilterOf } from "./sidebar/threadListFilter.logic"; import { + launchingThreadIdOf, resolveMachineOwners, resolveThreadAttributions, threadAttributionKey, + threadSenderLine, } from "@t3tools/client-runtime/state/thread-attribution"; import { matchesOlderSettledGroup, @@ -1138,6 +1140,19 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve const threadAttributions = resolveThreadAttributions(threads, machineOwners); const attributionOf = (thread: Pick) => threadAttributions.get(threadAttributionKey(thread)) ?? "unknown"; + // Ids are unique across machines, and an agent often launches work on another one. + const threadTitleById = new Map( + threads.map((thread) => [thread.id, thread.title]), + ); + const senderLineOf = (thread: EnvironmentThreadShell) => { + const attribution = threadAttributions.get(threadAttributionKey(thread)); + if (attribution === undefined) return null; + const launcherId = launchingThreadIdOf(thread); + return threadSenderLine( + attribution, + launcherId === null ? null : (threadTitleById.get(launcherId) ?? null), + ); + }; // Search always looks across every inbox, sender and environment. const listFilterApplies = threadSearchQuery.trim().length === 0; const inboxThreads = listFilterApplies @@ -3304,6 +3319,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve const threadKey = scopedThreadKey( scopeThreadRef(thread.environmentId, thread.id), ); + const senderLine = senderLineOf(thread); return ( { }); }); +describe("tailscaleHttpsRow", () => { + const url = "https://laptop.tail.ts.net"; + const on = { mode: "local-only", tailscaleServeEnabled: true } as const; + const off = { mode: "local-only", tailscaleServeEnabled: false } as const; + + it("keeps the switch on while Serve is on, even before Tailscale answers or exists", () => { + expect([ + tailscaleHttpsRow(on, { status: "available", httpBaseUrl: url }), + tailscaleHttpsRow(on, { status: "unavailable", httpBaseUrl: url }), + tailscaleHttpsRow(on, null), + ]).toEqual([ + { checked: true, showsSwitch: true, description: `On at ${url}` }, + { + checked: true, + showsSwitch: true, + description: `On. Waiting for Tailscale Serve to answer at ${url}`, + }, + { + checked: true, + showsSwitch: true, + description: "On. Starts once Tailscale is installed and signed in on this machine.", + }, + ]); + }); + + it("offers turning on only with a MagicDNS name to serve", () => { + expect(tailscaleHttpsRow(off, { status: "unavailable", httpBaseUrl: url }).showsSwitch).toBe( + true, + ); + expect(tailscaleHttpsRow(off, null).showsSwitch).toBe(false); + }); +}); + const baseWslState: DesktopWslState = { enabled: false, distro: null, diff --git a/apps/web/src/components/settings/ConnectionsSettings.logic.ts b/apps/web/src/components/settings/ConnectionsSettings.logic.ts index f78ef2934719..a2c526ae629f 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.logic.ts +++ b/apps/web/src/components/settings/ConnectionsSettings.logic.ts @@ -61,14 +61,36 @@ export function isQrShareableEndpoint(endpoint: AdvertisedEndpoint): boolean { return endpoint.status !== "unavailable" && endpoint.reachability !== "loopback"; } -/** Desktop skips Tailscale probing until network/Serve is enabled to avoid macOS prompts; absence then - * means unchecked. */ -export function missingTailscaleEndpointDescription( +/** + * The Tailscale HTTPS switch and its status line. Serve is on by default and does nothing until + * Tailscale runs and is signed in. Turning it on needs the MagicDNS name, so off needs one to show + * the switch. Desktop skips Tailscale probing while Serve and network access are off to avoid + * macOS prompts, so no endpoint then says nothing about Tailscale. + */ +export function tailscaleHttpsRow( state: Pick | null, -): string { - return state && state.mode !== "network-accessible" && !state.tailscaleServeEnabled - ? "Turn on Network access to detect Tailscale." - : "Start Tailscale to set up HTTPS access through MagicDNS."; + endpoint: Pick | null, +): { readonly checked: boolean; readonly showsSwitch: boolean; readonly description: string } { + if (state?.tailscaleServeEnabled) { + return { + checked: true, + showsSwitch: true, + description: !endpoint + ? "On. Starts once Tailscale is installed and signed in on this machine." + : endpoint.status === "available" + ? `On at ${endpoint.httpBaseUrl}` + : `On. Waiting for Tailscale Serve to answer at ${endpoint.httpBaseUrl}`, + }; + } + return { + checked: false, + showsSwitch: endpoint !== null, + description: endpoint + ? `Off. Turn on to serve this backend at ${endpoint.httpBaseUrl}` + : state && state.mode !== "network-accessible" + ? "Off. Turn on Network access to detect Tailscale." + : "Off. Start Tailscale to set up HTTPS access through MagicDNS.", + }; } export function resolveTailscaleServeBaseUrl( diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsx index bb99f1bc1e83..8ba35fc465af 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.tsx +++ b/apps/web/src/components/settings/ConnectionsSettings.tsx @@ -31,7 +31,7 @@ import { applyWslEnableSelection, connectDeviceName, isWslSettingsRowVisible, - missingTailscaleEndpointDescription, + tailscaleHttpsRow, resolveLocalVersionStatusLabel, resolveTailscaleServeBaseUrl, } from "./ConnectionsSettings.logic"; @@ -1097,35 +1097,32 @@ function ConnectionsSettingsContent({ ); }; - const renderTailscaleRow = () => ( - { - if (checked) { - handleStartTailscaleServeSetup(tailscaleHttpsEndpoint); - return; - } - handleStartTailscaleServeDisable(tailscaleHttpsEndpoint); - }} - aria-label="Enable Tailscale HTTPS" - /> - ) : null - } - managed={tailscaleHttpsEndpoint?.status === "available" ? undefined : remoteClientsDenial} - /> - ); + const renderTailscaleRow = () => { + const row = tailscaleHttpsRow(desktopServerExposureState, tailscaleHttpsEndpoint); + return ( + { + if (!checked) { + setDisableTailscaleServeDialogOpen(true); + return; + } + if (tailscaleHttpsEndpoint) handleStartTailscaleServeSetup(tailscaleHttpsEndpoint); + }} + aria-label="Enable Tailscale HTTPS" + /> + ) : null + } + managed={row.checked ? undefined : remoteClientsDenial} + /> + ); + }; const newestPairingLink = visibleDesktopPairingLinks.find( (pairingLink) => pairingLink.id === newestPairingLinkId, ); diff --git a/apps/web/src/components/sidebar/SidebarThreadRow.tsx b/apps/web/src/components/sidebar/SidebarThreadRow.tsx index d9e17f4df974..991db4b02bb7 100644 --- a/apps/web/src/components/sidebar/SidebarThreadRow.tsx +++ b/apps/web/src/components/sidebar/SidebarThreadRow.tsx @@ -243,6 +243,8 @@ function SidebarThreadTooltip({ projectDisplayName, environmentLabel, environmentMachine, + senderLabel, + senderByAgent, providerEntry, providerEntryByInstanceId, showInstanceBadge, @@ -257,6 +259,8 @@ function SidebarThreadTooltip({ projectDisplayName: string | null; environmentLabel: string | null; environmentMachine: EnvironmentMachineKind; + senderLabel: string | null; + senderByAgent: boolean; providerEntry: SidebarProviderEntry | null; providerEntryByInstanceId: ReadonlyMap; showInstanceBadge: boolean; @@ -301,6 +305,16 @@ function SidebarThreadTooltip({
{environmentLabel}
) : null} + {senderLabel ? ( +
+ {senderByAgent ? ( + + ) : ( + + )} +
{senderLabel}
+
+ ) : null} {thread.branch ? (
@@ -602,6 +616,9 @@ type SidebarThreadRowProps = { jumpLabel: string | null; currentEnvironmentId: string | null; attribution: ThreadAttribution; + /** The hover card's sender line; null when this client hasn't resolved the thread. */ + senderLabel: string | null; + senderByAgent: boolean; environmentLabel: string | null; environmentMachine: EnvironmentMachineKind; scratchMachineLabel: string | null; @@ -873,6 +890,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP projectDisplayName={props.projectDisplayName} environmentLabel={props.environmentLabel} environmentMachine={props.environmentMachine} + senderLabel={props.senderLabel} + senderByAgent={props.senderByAgent} providerEntry={providerEntry} providerEntryByInstanceId={props.providerEntryByInstanceId} showInstanceBadge={showInstanceBadge} @@ -1684,6 +1703,8 @@ export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props projectDisplayName: string | null; environmentLabel: string | null; environmentMachine: EnvironmentMachineKind; + senderLabel: string | null; + senderByAgent: boolean; providerEntryByInstanceId: ReadonlyMap; isHighlighted: boolean; isRouteActive: boolean; @@ -1862,6 +1883,8 @@ export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props projectDisplayName={props.projectDisplayName} environmentLabel={props.environmentLabel} environmentMachine={props.environmentMachine} + senderLabel={props.senderLabel} + senderByAgent={props.senderByAgent} providerEntry={providerEntry} providerEntryByInstanceId={props.providerEntryByInstanceId} showInstanceBadge={showInstanceBadge} diff --git a/docs/user/remote-access.md b/docs/user/remote-access.md index 5c0d896731b4..6776b8a2a67b 100644 --- a/docs/user/remote-access.md +++ b/docs/user/remote-access.md @@ -195,8 +195,10 @@ Mobile keeps its manual environment selection. ### Tailscale HTTPS -Join both devices to the same tailnet. In the desktop app, enable **Tailscale -HTTPS** in **Settings → Sharing & access**. Turn it off there to remove that route. +Join both devices to the same tailnet. The desktop app turns on **Tailscale +HTTPS** by default, and **Settings → Sharing & access** shows its status. It does +nothing until Tailscale is installed and signed in. Turn it off there to remove +that route; the app keeps that choice. Your tailnet needs MagicDNS and HTTPS certificates enabled; see [Tailscale's HTTPS setup](https://tailscale.com/docs/how-to/set-up-https-certificates). diff --git a/packages/client-runtime/src/state/threadAttribution.test.ts b/packages/client-runtime/src/state/threadAttribution.test.ts index d4753ebeb90b..cc19d4c25256 100644 --- a/packages/client-runtime/src/state/threadAttribution.test.ts +++ b/packages/client-runtime/src/state/threadAttribution.test.ts @@ -1,7 +1,12 @@ import { EnvironmentId, makeThreadInbox, ThreadId, type ThreadInbox } from "@t3tools/contracts"; import { describe, expect, it } from "vite-plus/test"; -import { resolveThreadAttributions, type AttributableThread } from "./threadAttribution.ts"; +import { + launchingThreadIdOf, + resolveThreadAttributions, + threadSenderLine, + type AttributableThread, +} from "./threadAttribution.ts"; const asus = EnvironmentId.make("asus"); const air = EnvironmentId.make("air"); @@ -84,4 +89,30 @@ describe("thread attribution", () => { b: "unknown", }); }); + + it("names the launching thread for agent work, and says plainly when the sender is unknown", () => { + const launched = ( + inbox: ThreadInbox | null, + options: { parent?: string; createdBy?: string }, + ) => launchingThreadIdOf(thread("t", inbox, options)); + expect([ + launched(makeThreadInbox({ actor: bot }), { parent: "p" }), + launched(makeThreadInbox({ actor: { kind: "agent", id: "agent" } }), { parent: "p" }), + launched(null, { parent: "p", createdBy: "agent" }), + launched(makeThreadInbox({ actor: kameron }), { parent: "p" }), + ]).toEqual(["lead", "p", "p", null]); + expect([ + threadSenderLine("kameron", "Fleet rollout"), + threadSenderLine("jeff-agents", "Fleet rollout"), + threadSenderLine("jeff-agents", null), + threadSenderLine("unknown", "Fleet rollout"), + threadSenderLine("unknown", null), + ]).toEqual([ + { label: "Kameron", byAgent: false }, + { label: "Jeff's agents, from “Fleet rollout”", byAgent: true }, + { label: "Jeff's agents", byAgent: true }, + { label: "An agent, from “Fleet rollout”", byAgent: true }, + { label: "Sender unknown", byAgent: false }, + ]); + }); }); diff --git a/packages/client-runtime/src/state/threadAttribution.ts b/packages/client-runtime/src/state/threadAttribution.ts index 180d4874c3ff..08668b50c9fb 100644 --- a/packages/client-runtime/src/state/threadAttribution.ts +++ b/packages/client-runtime/src/state/threadAttribution.ts @@ -107,3 +107,27 @@ export function resolveThreadAttributions( } return resolved; } + +/** The thread an agent launched this one from: the agent origin's thread, else its parent. */ +export function launchingThreadIdOf(thread: AttributableThread): string | null { + const origin = thread.source.inbox?.origin; + // Launches without a calling thread record the bare id "agent". + if (origin?.kind === "agent" && origin.id !== "agent") return origin.id; + return origin?.kind === "agent" || thread.source.createdBy === "agent" + ? thread.lineage.parentThreadId + : null; +} + +/** The sentence form of an attribution, naming the launching thread for agent work. */ +export function threadSenderLine( + attribution: ThreadAttribution, + launcherTitle: string | null, +): { readonly label: string; readonly byAgent: boolean } { + const from = launcherTitle ? `, from “${launcherTitle}”` : ""; + if (attribution === "unknown") + return launcherTitle + ? { label: `An agent${from}`, byAgent: true } + : { label: "Sender unknown", byAgent: false }; + const byAgent = attribution.endsWith("-agents"); + return { label: `${THREAD_ATTRIBUTION_LABELS[attribution]}${byAgent ? from : ""}`, byAgent }; +} From 911060ce81adca596c96f1e71c81e6e3651ff0d4 Mon Sep 17 00:00:00 2001 From: nullStack65 <112618179+nullStack65@users.noreply.github.com> Date: Thu, 19 Nov 2026 03:15:47 +0000 Subject: [PATCH 2/2] fix: honest Tailscale HTTPS status, and turning it back on works anywhere Review round 1 on PR #94. The switch now always shows and follows the saved setting, so an explicit off can be undone without first turning on Network access; setup opens even before Tailscale reports a MagicDNS name. Status lines no longer promise a wait the server may never end. A test pins that an explicit off on a local-only machine never runs `tailscale`, and the settings tests say what a missing key means. Co-Authored-By: Claude Opus 5.5 --- .../src/backend/DesktopServerExposure.test.ts | 21 ++++++++++ .../src/settings/DesktopAppSettings.test.ts | 4 +- .../ConnectionsSettings.logic.test.ts | 41 ++++++------------- .../settings/ConnectionsSettings.logic.ts | 35 +++++++--------- .../settings/ConnectionsSettings.tsx | 41 +++++++++---------- 5 files changed, 70 insertions(+), 72 deletions(-) diff --git a/apps/desktop/src/backend/DesktopServerExposure.test.ts b/apps/desktop/src/backend/DesktopServerExposure.test.ts index 5625b3826e79..ddebbf7fb6fb 100644 --- a/apps/desktop/src/backend/DesktopServerExposure.test.ts +++ b/apps/desktop/src/backend/DesktopServerExposure.test.ts @@ -181,6 +181,27 @@ describe("DesktopServerExposure", () => { ); }); + it.effect("reads Tailscale by default, and never after Serve is turned off locally", () => { + let statusReads = 0; + return withHarness( + lanNetworkInterfaces, + Effect.gen(function* () { + const serverExposure = yield* DesktopServerExposure.DesktopServerExposure; + yield* serverExposure.configureFromSettings({ port: 4173 }); + yield* serverExposure.getAdvertisedEndpoints; + assert.equal(statusReads, 1); + + yield* serverExposure.setTailscaleServeEnabled({ enabled: false }); + yield* serverExposure.getAdvertisedEndpoints; + assert.equal(statusReads, 1); + }), + {}, + layerMockSpawner("{}", () => { + statusReads += 1; + }), + ); + }); + it.effect("falls back to local-only without losing the requested network preference", () => withHarness( emptyNetworkInterfaces, diff --git a/apps/desktop/src/settings/DesktopAppSettings.test.ts b/apps/desktop/src/settings/DesktopAppSettings.test.ts index 16690c27e4b5..bb07e2cc998e 100644 --- a/apps/desktop/src/settings/DesktopAppSettings.test.ts +++ b/apps/desktop/src/settings/DesktopAppSettings.test.ts @@ -385,7 +385,7 @@ describe("DesktopSettings", () => { mainWindowBounds: null, mainWindowMaximized: false, serverExposureMode: "local-only", - // A file without the key is a machine that never turned Tailscale HTTPS off. + // A missing key reads as on; an off saved before it became the default left no key. tailscaleServeEnabled: true, tailscaleServePort: 443, updateChannel: "nightly", @@ -415,7 +415,7 @@ describe("DesktopSettings", () => { mainWindowBounds: null, mainWindowMaximized: false, serverExposureMode: "local-only", - // A file without the key is a machine that never turned Tailscale HTTPS off. + // A missing key reads as on; an off saved before it became the default left no key. tailscaleServeEnabled: true, tailscaleServePort: 443, updateChannel: "latest", diff --git a/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts b/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts index 6edc09046776..25f0766dec4c 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts +++ b/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts @@ -76,34 +76,19 @@ describe("resolveTailscaleServeBaseUrl", () => { describe("tailscaleHttpsRow", () => { const url = "https://laptop.tail.ts.net"; - const on = { mode: "local-only", tailscaleServeEnabled: true } as const; - const off = { mode: "local-only", tailscaleServeEnabled: false } as const; - - it("keeps the switch on while Serve is on, even before Tailscale answers or exists", () => { - expect([ - tailscaleHttpsRow(on, { status: "available", httpBaseUrl: url }), - tailscaleHttpsRow(on, { status: "unavailable", httpBaseUrl: url }), - tailscaleHttpsRow(on, null), - ]).toEqual([ - { checked: true, showsSwitch: true, description: `On at ${url}` }, - { - checked: true, - showsSwitch: true, - description: `On. Waiting for Tailscale Serve to answer at ${url}`, - }, - { - checked: true, - showsSwitch: true, - description: "On. Starts once Tailscale is installed and signed in on this machine.", - }, - ]); - }); - - it("offers turning on only with a MagicDNS name to serve", () => { - expect(tailscaleHttpsRow(off, { status: "unavailable", httpBaseUrl: url }).showsSwitch).toBe( - true, - ); - expect(tailscaleHttpsRow(off, null).showsSwitch).toBe(false); + const on = { tailscaleServeEnabled: true } as const; + const off = { tailscaleServeEnabled: false } as const; + + it("follows the saved setting, not whether Serve answers", () => { + expect( + [ + tailscaleHttpsRow(on, { status: "available", httpBaseUrl: url }), + tailscaleHttpsRow(on, { status: "unavailable", httpBaseUrl: url }), + tailscaleHttpsRow(on, null), + tailscaleHttpsRow(off, { status: "available", httpBaseUrl: url }), + tailscaleHttpsRow(off, null), + ].map((row) => row.checked), + ).toEqual([true, true, true, false, false]); }); }); diff --git a/apps/web/src/components/settings/ConnectionsSettings.logic.ts b/apps/web/src/components/settings/ConnectionsSettings.logic.ts index a2c526ae629f..3cef6e51083c 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.logic.ts +++ b/apps/web/src/components/settings/ConnectionsSettings.logic.ts @@ -63,33 +63,28 @@ export function isQrShareableEndpoint(endpoint: AdvertisedEndpoint): boolean { /** * The Tailscale HTTPS switch and its status line. Serve is on by default and does nothing until - * Tailscale runs and is signed in. Turning it on needs the MagicDNS name, so off needs one to show - * the switch. Desktop skips Tailscale probing while Serve and network access are off to avoid - * macOS prompts, so no endpoint then says nothing about Tailscale. + * Tailscale runs here, signed in with MagicDNS. Desktop skips Tailscale probing while Serve and + * network access are off to avoid macOS prompts, so no endpoint then says nothing about Tailscale. */ export function tailscaleHttpsRow( - state: Pick | null, + state: Pick | null, endpoint: Pick | null, -): { readonly checked: boolean; readonly showsSwitch: boolean; readonly description: string } { - if (state?.tailscaleServeEnabled) { +): { readonly checked: boolean; readonly description: string } { + if (!state?.tailscaleServeEnabled) { return { - checked: true, - showsSwitch: true, - description: !endpoint - ? "On. Starts once Tailscale is installed and signed in on this machine." - : endpoint.status === "available" - ? `On at ${endpoint.httpBaseUrl}` - : `On. Waiting for Tailscale Serve to answer at ${endpoint.httpBaseUrl}`, + checked: false, + description: endpoint + ? `Off. Turn on to serve this backend at ${endpoint.httpBaseUrl}` + : "Off. Turn on to serve this backend over Tailscale HTTPS.", }; } return { - checked: false, - showsSwitch: endpoint !== null, - description: endpoint - ? `Off. Turn on to serve this backend at ${endpoint.httpBaseUrl}` - : state && state.mode !== "network-accessible" - ? "Off. Turn on Network access to detect Tailscale." - : "Off. Start Tailscale to set up HTTPS access through MagicDNS.", + checked: true, + description: !endpoint + ? "On. Inactive until Tailscale runs here, signed in with MagicDNS." + : endpoint.status === "available" + ? `On at ${endpoint.httpBaseUrl}` + : `On, but ${endpoint.httpBaseUrl} doesn't answer. Tailscale Serve needs HTTPS certificates on the tailnet and its port free.`, }; } diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsx index 8ba35fc465af..42fc24e013c3 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.tsx +++ b/apps/web/src/components/settings/ConnectionsSettings.tsx @@ -370,8 +370,10 @@ function ConnectionsSettingsContent({ | { readonly kind: "wsl-only"; readonly nextValue: boolean }; const [pendingWslChange, setPendingWslChange] = useState(null); const isWslConfirmDialogOpen = pendingWslChange !== null; - const [pendingTailscaleServeEndpoint, setPendingTailscaleServeEndpoint] = - useState(null); + // Setup can start before Tailscale reports a MagicDNS name, so the endpoint may be null. + const [pendingTailscaleServeSetup, setPendingTailscaleServeSetup] = useState<{ + readonly endpoint: AdvertisedEndpoint | null; + } | null>(null); const [disableTailscaleServeDialogOpen, setDisableTailscaleServeDialogOpen] = useState(false); const [tailscaleServePortInput, setTailscaleServePortInput] = useState( String(DEFAULT_TAILSCALE_SERVE_PORT), @@ -469,7 +471,7 @@ function ConnectionsSettingsContent({ parsedTailscaleServePort <= 65_535; const pendingTailscaleServeBaseUrl = resolveTailscaleServeBaseUrl( - pendingTailscaleServeEndpoint, + pendingTailscaleServeSetup?.endpoint ?? null, parsedTailscaleServePort, isTailscaleServePortValid, ); @@ -525,7 +527,7 @@ function ConnectionsSettingsContent({ port: parsedTailscaleServePort, }); refreshDesktopNetworkAccessState(); - setPendingTailscaleServeEndpoint(null); + setPendingTailscaleServeSetup(null); }); if (settled._tag === "Failure") { const error = Cause.squash(settled.cause); @@ -543,11 +545,11 @@ function ConnectionsSettingsContent({ setIsUpdatingTailscaleServe(false); }; - const handleStartTailscaleServeSetup = (endpoint: AdvertisedEndpoint) => { + const handleStartTailscaleServeSetup = (endpoint: AdvertisedEndpoint | null) => { setTailscaleServePortInput( String(desktopServerExposureState?.tailscaleServePort ?? DEFAULT_TAILSCALE_SERVE_PORT), ); - setPendingTailscaleServeEndpoint(endpoint); + setPendingTailscaleServeSetup({ endpoint }); }; const handleConfirmTailscaleServeDisable = async () => { @@ -1104,20 +1106,15 @@ function ConnectionsSettingsContent({ title={searchableSetting("tailscale-https").title} description={row.description} control={ - row.showsSwitch ? ( - { - if (!checked) { - setDisableTailscaleServeDialogOpen(true); - return; - } - if (tailscaleHttpsEndpoint) handleStartTailscaleServeSetup(tailscaleHttpsEndpoint); - }} - aria-label="Enable Tailscale HTTPS" - /> - ) : null + { + if (checked) handleStartTailscaleServeSetup(tailscaleHttpsEndpoint); + else setDisableTailscaleServeDialogOpen(true); + }} + aria-label="Enable Tailscale HTTPS" + /> } managed={row.checked ? undefined : remoteClientsDenial} /> @@ -1621,10 +1618,10 @@ function ConnectionsSettingsContent({ { if (isUpdatingTailscaleServe) return; - if (!open) setPendingTailscaleServeEndpoint(null); + if (!open) setPendingTailscaleServeSetup(null); }} >