Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion apps/desktop/src/backend/DesktopServerExposure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -253,7 +274,7 @@ describe("DesktopServerExposure", () => {
mode: "network-accessible",
endpointUrl: "http://192.168.1.20:4173",
advertisedHost: "192.168.1.20",
tailscaleServeEnabled: false,
tailscaleServeEnabled: true,
tailscaleServePort: 443,
});

Expand Down
10 changes: 8 additions & 2 deletions apps/desktop/src/settings/DesktopAppSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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),
Expand All @@ -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* () {
Expand All @@ -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);
}),
),
);
Expand Down Expand Up @@ -381,7 +385,8 @@ describe("DesktopSettings", () => {
mainWindowBounds: null,
mainWindowMaximized: false,
serverExposureMode: "local-only",
tailscaleServeEnabled: false,
// A missing key reads as on; an off saved before it became the default left no key.
tailscaleServeEnabled: true,
tailscaleServePort: 443,
updateChannel: "nightly",
updateChannelConfiguredByUser: false,
Expand Down Expand Up @@ -410,7 +415,8 @@ describe("DesktopSettings", () => {
mainWindowBounds: null,
mainWindowMaximized: false,
serverExposureMode: "local-only",
tailscaleServeEnabled: false,
// A missing key reads as on; an off saved before it became the default left no key.
tailscaleServeEnabled: true,
tailscaleServePort: 443,
updateChannel: "latest",
updateChannelConfiguredByUser: true,
Expand Down
5 changes: 3 additions & 2 deletions apps/desktop/src/settings/DesktopAppSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/components/Sidebar.drag.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
21 changes: 21 additions & 0 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -1138,6 +1140,19 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
const threadAttributions = resolveThreadAttributions(threads, machineOwners);
const attributionOf = (thread: Pick<EnvironmentThreadShell, "environmentId" | "id">) =>
threadAttributions.get(threadAttributionKey(thread)) ?? "unknown";
// Ids are unique across machines, and an agent often launches work on another one.
const threadTitleById = new Map<string, string>(
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
Expand Down Expand Up @@ -3304,6 +3319,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
const threadKey = scopedThreadKey(
scopeThreadRef(thread.environmentId, thread.id),
);
const senderLine = senderLineOf(thread);
return (
<SidebarSearchResultRow
isSettled={settledThreadKeys.has(threadKey)}
Expand All @@ -3318,6 +3334,8 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
) ?? null
}
environmentLabel={environmentLabelById.get(thread.environmentId) ?? null}
senderLabel={senderLine?.label ?? null}
senderByAgent={senderLine?.byAgent ?? false}
environmentMachine={
environmentMachineById.get(thread.environmentId) ?? "server"
}
Expand Down Expand Up @@ -3452,6 +3470,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
: isCard
? "card"
: "slim";
const senderLine = senderLineOf(thread);
return (
<SortableThreadRow
key={threadKey}
Expand Down Expand Up @@ -3513,6 +3532,8 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
}
currentEnvironmentId={primaryEnvironmentId}
attribution={attributionOf(thread)}
senderLabel={senderLine?.label ?? null}
senderByAgent={senderLine?.byAgent ?? false}
environmentLabel={
environmentLabelById.get(thread.environmentId) ?? null
}
Expand Down
19 changes: 19 additions & 0 deletions apps/web/src/components/settings/ConnectionsSettings.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
resolveAccessEnvironmentId,
resolveTailscaleServeBaseUrl,
selectQrEndpointOption,
tailscaleHttpsRow,
togglePairingScopeSelection,
} from "./ConnectionsSettings.logic";

Expand Down Expand Up @@ -73,6 +74,24 @@ describe("resolveTailscaleServeBaseUrl", () => {
});
});

describe("tailscaleHttpsRow", () => {
const url = "https://laptop.tail.ts.net";
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]);
});
});

const baseWslState: DesktopWslState = {
enabled: false,
distro: null,
Expand Down
33 changes: 25 additions & 8 deletions apps/web/src/components/settings/ConnectionsSettings.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,31 @@ 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(
state: Pick<DesktopServerExposureState, "mode" | "tailscaleServeEnabled"> | 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.";
/**
* The Tailscale HTTPS switch and its status line. Serve is on by default and does nothing until
* 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<DesktopServerExposureState, "tailscaleServeEnabled"> | null,
endpoint: Pick<AdvertisedEndpoint, "status" | "httpBaseUrl"> | null,
): { readonly checked: boolean; readonly description: string } {
if (!state?.tailscaleServeEnabled) {
return {
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: 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.`,
};
}

export function resolveTailscaleServeBaseUrl(
Expand Down
58 changes: 26 additions & 32 deletions apps/web/src/components/settings/ConnectionsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
applyWslEnableSelection,
connectDeviceName,
isWslSettingsRowVisible,
missingTailscaleEndpointDescription,
tailscaleHttpsRow,
resolveLocalVersionStatusLabel,
resolveTailscaleServeBaseUrl,
} from "./ConnectionsSettings.logic";
Expand Down Expand Up @@ -370,8 +370,10 @@ function ConnectionsSettingsContent({
| { readonly kind: "wsl-only"; readonly nextValue: boolean };
const [pendingWslChange, setPendingWslChange] = useState<PendingWslChange | null>(null);
const isWslConfirmDialogOpen = pendingWslChange !== null;
const [pendingTailscaleServeEndpoint, setPendingTailscaleServeEndpoint] =
useState<AdvertisedEndpoint | null>(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),
Expand Down Expand Up @@ -469,7 +471,7 @@ function ConnectionsSettingsContent({
parsedTailscaleServePort <= 65_535;

const pendingTailscaleServeBaseUrl = resolveTailscaleServeBaseUrl(
pendingTailscaleServeEndpoint,
pendingTailscaleServeSetup?.endpoint ?? null,
parsedTailscaleServePort,
isTailscaleServePortValid,
);
Expand Down Expand Up @@ -525,7 +527,7 @@ function ConnectionsSettingsContent({
port: parsedTailscaleServePort,
});
refreshDesktopNetworkAccessState();
setPendingTailscaleServeEndpoint(null);
setPendingTailscaleServeSetup(null);
});
if (settled._tag === "Failure") {
const error = Cause.squash(settled.cause);
Expand All @@ -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 () => {
Expand Down Expand Up @@ -1097,35 +1099,27 @@ function ConnectionsSettingsContent({
);
};

const renderTailscaleRow = () => (
<SettingsRow
title={searchableSetting("tailscale-https").title}
description={
tailscaleHttpsEndpoint
? tailscaleHttpsEndpoint.status === "available"
? tailscaleHttpsEndpoint.httpBaseUrl
: "Use Tailscale Serve to expose this backend through a MagicDNS HTTPS URL."
: missingTailscaleEndpointDescription(desktopServerExposureState)
}
control={
tailscaleHttpsEndpoint ? (
const renderTailscaleRow = () => {
const row = tailscaleHttpsRow(desktopServerExposureState, tailscaleHttpsEndpoint);
return (
<SettingsRow
title={searchableSetting("tailscale-https").title}
description={row.description}
control={
<Switch
checked={tailscaleHttpsEndpoint.status === "available"}
checked={row.checked}
disabled={isUpdatingTailscaleServe}
onCheckedChange={(checked) => {
if (checked) {
handleStartTailscaleServeSetup(tailscaleHttpsEndpoint);
return;
}
handleStartTailscaleServeDisable(tailscaleHttpsEndpoint);
if (checked) handleStartTailscaleServeSetup(tailscaleHttpsEndpoint);
else setDisableTailscaleServeDialogOpen(true);
}}
aria-label="Enable Tailscale HTTPS"
/>
) : null
}
managed={tailscaleHttpsEndpoint?.status === "available" ? undefined : remoteClientsDenial}
/>
);
}
managed={row.checked ? undefined : remoteClientsDenial}
/>
);
};
const newestPairingLink = visibleDesktopPairingLinks.find(
(pairingLink) => pairingLink.id === newestPairingLinkId,
);
Expand Down Expand Up @@ -1624,10 +1618,10 @@ function ConnectionsSettingsContent({
</AlertDialogPopup>
</AlertDialog>
<Dialog
open={pendingTailscaleServeEndpoint !== null}
open={pendingTailscaleServeSetup !== null}
onOpenChange={(open) => {
if (isUpdatingTailscaleServe) return;
if (!open) setPendingTailscaleServeEndpoint(null);
if (!open) setPendingTailscaleServeSetup(null);
}}
>
<DialogPopup className="max-w-md">
Expand Down
Loading
Loading