Skip to content

Commit c20d6ef

Browse files
donjor-agent[bot]donjor
authored andcommitted
fix(web): client-only Connections hides managed-server controls (#1867)
## Problem In client-only mode, Connections shows controls for a server this desktop does not manage: Local environment, Network access, and Tailscale HTTPS. The upstream gate keys on `environment:maintain`, which a standard pairing grants, and the local-environment flag defaults to on. ## Change New gate `canManageLocalBackendFork` requires all three: - `environment:maintain` scope - not client-only - local environment on **Callers:** - Connections rows - Settings search - `LocalEnvironmentSetting`: off in client-only **Rename:** one fork file holds both client-only gates. ```text apps/web/src/components/settings/ └── connectionsSessionScopes.fork.ts → connectionsClientOnly.fork.ts ``` Upstream edits are one-line fork hooks; the managed path is unchanged. ## Scope and approval Closes #1773; the human chose a fork fix. - [ ] **Hidden:** all three rows in client-only - [ ] **Kept:** managed desktop still shows them **Also hidden in client-only:** the Version row, behind the same gate. **Known gap, left as is:** the `local-environment` search item still lists in client-only, then opens Connections without the row. Tagging it `localBackendManagementOnly` would also hide the way back when a managed desktop turns its local environment off. ## Verification Dev desktop on the worktree `.t3`; client-only attached a separate `vp run dev:server` on `:14289`. **Client-only, before** (pre-fix sources): all three rows shown ![client-only-before.png](https://github.com/user-attachments/assets/f98a7157-03c0-43a8-ad75-3ff40681a42d) **Client-only, after:** rows gone ![client-only-after.png](https://github.com/user-attachments/assets/60e82d4c-6618-40d1-b45d-dd6c04e28e37) **Managed, after:** rows kept ![managed-kept.png](https://github.com/user-attachments/assets/80841cb4-66d9-4536-a569-bb6047a8ffa9) **Checks:** - Gate tests: 8/8 pass - `vp run check:changed` → exit 1 - two failing tests, outside this diff - `GitManager.test.ts`: CLAUDE.md case, fails alone - `markdownPipeline.browser.test.ts`: passes alone - `vp run fork:ci` → exit 0 Claude Opus 5.5, Claude Code in T3 Code. ## Fork trailers Fork-Domain: backend-attach Fork-Tier: bugfix Fork-Upstreamable: no Co-authored-by: donjor <[email protected]>
1 parent 9585bef commit c20d6ef

6 files changed

Lines changed: 63 additions & 27 deletions

‎apps/web/src/components/settings/ConnectionsSettings.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ import {
2525
} from "@t3tools/client-runtime/state/runtime";
2626
import * as Cause from "effect/Cause";
2727

28-
import { isLocalEnvironmentDisabled } from "../../localEnvironment";
29-
import { connectionsSessionScopesFork } from "./connectionsSessionScopes.fork"; // fork-hook: backend-attach/connections-session-scopes-import
28+
import {
29+
canManageLocalBackendFork,
30+
connectionsSessionScopesFork,
31+
} from "./connectionsClientOnly.fork"; // fork-hook: backend-attach/connections-session-scopes-import
3032
import {
3133
applyWslEnableSelection,
3234
isWslSettingsRowVisible,
@@ -292,7 +294,7 @@ export function ConnectionsSettings({ view }: { readonly view: "environments" |
292294
const canReadRelay = useEnvironmentScope(primaryEnvironmentId, AuthRelayReadScope);
293295
const canMaintain = useEnvironmentScope(primaryEnvironmentId, AuthEnvironmentMaintainScope);
294296
const canManageRelay = useEnvironmentScope(primaryEnvironmentId, AuthRelayWriteScope);
295-
const canManageLocalBackend = !isLocalEnvironmentDisabled() && canMaintain;
297+
const canManageLocalBackend = canManageLocalBackendFork(canMaintain); // fork-hook: backend-attach/connections-local-backend
296298
const showsAccess = view === "access";
297299
const authAccessChanges = useEnvironmentQuery(
298300
showsAccess && canReadAccess && primaryEnvironmentId !== null

‎apps/web/src/components/settings/LocalEnvironmentSetting.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useState } from "react";
22

3+
import { isDesktopClientOnlyMode } from "~/environments/primary/target"; // fork-hook: backend-attach/local-environment-switch-import
34
import { isLocalEnvironmentDisabled } from "../../localEnvironment";
45
import {
56
AlertDialog,
@@ -23,7 +24,7 @@ export function LocalEnvironmentSetting() {
2324
const [confirmOpen, setConfirmOpen] = useState(false);
2425
const [isUpdating, setIsUpdating] = useState(false);
2526
const [error, setError] = useState<string | null>(null);
26-
if (!setEnabled) return null;
27+
if (!setEnabled || isDesktopClientOnlyMode()) return null; // fork-hook: backend-attach/local-environment-switch
2728

2829
const applyChange = async () => {
2930
setIsUpdating(true);

apps/web/src/components/settings/connectionsSessionScopes.fork.test.ts renamed to apps/web/src/components/settings/connectionsClientOnly.fork.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import {
66
} from "@t3tools/contracts";
77
import { describe, expect, it } from "vite-plus/test";
88

9-
import { connectionsSessionScopesFork } from "./connectionsSessionScopes.fork";
9+
import {
10+
canManageLocalBackendFork,
11+
connectionsSessionScopesFork,
12+
} from "./connectionsClientOnly.fork";
1013

1114
const standardSession: AuthSessionState = {
1215
authenticated: true,
@@ -53,3 +56,18 @@ describe("connectionsSessionScopesFork", () => {
5356
expect(scopes).toEqual([AuthAccessWriteScope]);
5457
});
5558
});
59+
60+
describe("canManageLocalBackendFork", () => {
61+
it("hides local backend controls from a client-only attach holding the maintain scope", () => {
62+
expect(canManageLocalBackendFork(true, true, false)).toBe(false);
63+
});
64+
65+
it("keeps them for a desktop that manages its backend", () => {
66+
expect(canManageLocalBackendFork(true, false, false)).toBe(true);
67+
});
68+
69+
it("hides them while the local environment is off or the scope is missing", () => {
70+
expect(canManageLocalBackendFork(true, false, true)).toBe(false);
71+
expect(canManageLocalBackendFork(false, false, false)).toBe(false);
72+
});
73+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import type { AuthSessionState } from "@t3tools/contracts";
2+
3+
import { isDesktopClientOnlyMode } from "~/environments/primary/target";
4+
import { isLocalEnvironmentDisabled } from "~/localEnvironment";
5+
6+
/**
7+
* The scopes Connections settings delegate from. A desktop app that owns its
8+
* backend holds `ownedScopes`; a client-only launch attaches a server it does
9+
* not manage and holds only what that session was granted
10+
* (RSI-Software/t3code-hyprws#1390).
11+
*/
12+
export function connectionsSessionScopesFork<Owned extends ReadonlyArray<string>>(
13+
desktopBridge: unknown,
14+
ownedScopes: Owned,
15+
session: AuthSessionState | null,
16+
clientOnly: boolean = isDesktopClientOnlyMode(),
17+
): Owned | NonNullable<AuthSessionState["permissions"]> | null {
18+
if (desktopBridge && !clientOnly) return ownedScopes;
19+
// Permissions are the current wire field; scopes remain for servers older than them.
20+
return session?.authenticated ? (session.permissions ?? session.scopes ?? null) : null;
21+
}
22+
23+
/**
24+
* Whether this client may manage the local backend: its version, network
25+
* access, Tailscale, and WSL rows. Upstream gates them on the maintain scope,
26+
* which a standard pairing grants, so a client-only launch must also opt out:
27+
* the server it attached belongs to someone else (RSI-Software/t3code-hyprws#1773).
28+
*/
29+
export function canManageLocalBackendFork(
30+
canMaintain: boolean,
31+
clientOnly: boolean = isDesktopClientOnlyMode(),
32+
localEnvironmentDisabled: boolean = isLocalEnvironmentDisabled(),
33+
): boolean {
34+
return canMaintain && !clientOnly && !localEnvironmentDisabled;
35+
}

‎apps/web/src/components/settings/connectionsSessionScopes.fork.ts‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎apps/web/src/components/settings/useAvailableSettingsSearchItems.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { isProviderSettingsEnvironmentAvailable } from "./ProviderSettingsPanel.
1414
import type { SettingsScopeSearch } from "./settingsScope";
1515
import { getThreadAutoSettlementSearchAvailability } from "./settingsSearch";
1616
import { filterAvailableGitHubIssueSettingsSearchItems } from "./githubIssueSettingsSearch";
17+
import { canManageLocalBackendFork } from "./connectionsClientOnly.fork"; // fork-hook: backend-attach/search-local-backend-import
1718

1819
export function useAvailableSettingsSearchItems(scopeSearch: SettingsScopeSearch = {}) {
1920
const { environments } = useEnvironments();
@@ -48,7 +49,7 @@ export function useAvailableSettingsSearchItems(scopeSearch: SettingsScopeSearch
4849
cloudLinkState?.linkRevoked !== true &&
4950
(cloudLinkState?.managedTunnelActive ?? cloudLinkState?.linked ?? false) === true;
5051
const localEnvironmentDisabled = isLocalEnvironmentDisabled() === true;
51-
const canManageLocalBackend = !localEnvironmentDisabled && canMaintain;
52+
const canManageLocalBackend = canManageLocalBackendFork(canMaintain) === true; // fork-hook: backend-attach/search-local-backend
5253
const desktopWsl = useEnvironmentQuery(
5354
isElectron && canManageLocalBackend ? desktopWslStateAtom : null,
5455
);

0 commit comments

Comments
 (0)