Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(mobile): stop a directly-saved backend from hiding its T3 Connect environment (#7086)

Rishet11035058a23e65
diff --git a/apps/mobile/src/features/connection/environmentSections.test.ts b/apps/mobile/src/features/connection/environmentSections.test.ts
index 75f78738a..6d07f40a5 100644
--- a/apps/mobile/src/features/connection/environmentSections.test.ts
+++ b/apps/mobile/src/features/connection/environmentSections.test.ts
@@ -2,7 +2,7 @@ import { EnvironmentId } from "@t3tools/contracts";
import type { RelayClientEnvironmentRecord } from "@t3tools/contracts/relay";
import { describe, expect, it } from "vite-plus/test";
import type { ConnectedEnvironmentSummary } from "../../state/remote-runtime-types";
-import { splitEnvironmentSections } from "./environmentSections";
+import { relayManagedEnvironmentIds, splitEnvironmentSections } from "./environmentSections";
function connectedEnvironment(
input: Omit<Partial<ConnectedEnvironmentSummary>, "environmentId"> & {
@@ -34,6 +34,17 @@ function cloudEnvironment(environmentId: string): RelayClientEnvironmentRecord {
};
}
+describe("relayManagedEnvironmentIds", () => {
+ it("leaves out a backend that was saved directly", () => {
+ const ids = relayManagedEnvironmentIds([
+ connectedEnvironment({ environmentId: "environment-local", isRelayManaged: false }),
+ connectedEnvironment({ environmentId: "environment-cloud", isRelayManaged: true }),
+ ]);
+
+ expect([...ids]).toEqual([EnvironmentId.make("environment-cloud")]);
+ });
+});
+
describe("mobile environment settings sections", () => {
it("keeps saved relay-managed connections under T3 Connect", () => {
const local = connectedEnvironment({
@@ -111,6 +122,24 @@ describe("mobile environment settings sections", () => {
expect(sections.availableCloudEnvironments).toEqual([]);
});
+ it("still offers a cloud environment saved directly as a local backend", () => {
+ const local = connectedEnvironment({
+ environmentId: "environment-cloud",
+ isRelayManaged: false,
+ });
+
+ const sections = splitEnvironmentSections({
+ connectedEnvironments: [local],
+ cloudEnvironments: [cloudEnvironment("environment-cloud")],
+ });
+
+ expect(sections.localEnvironments).toEqual([local]);
+ expect(sections.connectedCloudEnvironments).toEqual([]);
+ expect(
+ sections.availableCloudEnvironments.map((environment) => environment.environmentId),
+ ).toEqual([EnvironmentId.make("environment-cloud")]);
+ });
+
it("keeps failed relay environments in the local connection row", () => {
const cloud = connectedEnvironment({
environmentId: "environment-cloud",
diff --git a/apps/mobile/src/features/connection/environmentSections.ts b/apps/mobile/src/features/connection/environmentSections.ts
index fc6db479c..10ba636dc 100644
--- a/apps/mobile/src/features/connection/environmentSections.ts
+++ b/apps/mobile/src/features/connection/environmentSections.ts
@@ -1,3 +1,4 @@
+import type { EnvironmentId } from "@t3tools/contracts";
import type { RelayClientEnvironmentRecord } from "@t3tools/contracts/relay";
import type { ConnectedEnvironmentSummary } from "../../state/remote-runtime-types";
@@ -12,10 +13,25 @@ export interface EnvironmentSections {
readonly availableCloudEnvironments: ReadonlyArray<RelayClientEnvironmentRecord>;
}
-export function splitEnvironmentSections(input: EnvironmentSectionsInput): EnvironmentSections {
- const savedEnvironmentIds = new Set(
- input.connectedEnvironments.map((environment) => environment.environmentId),
+/**
+ * Ids of the environments that already occupy a T3 Connect slot. A backend saved directly is
+ * not one of them, so it must not suppress the cloud environment that happens to share its id.
+ */
+export function relayManagedEnvironmentIds(
+ environments: ReadonlyArray<{
+ readonly environmentId: EnvironmentId;
+ readonly isRelayManaged: boolean;
+ }>,
+): ReadonlySet<EnvironmentId> {
+ return new Set(
+ environments
+ .filter((environment) => environment.isRelayManaged)
+ .map((environment) => environment.environmentId),
);
+}
+
+export function splitEnvironmentSections(input: EnvironmentSectionsInput): EnvironmentSections {
+ const savedEnvironmentIds = relayManagedEnvironmentIds(input.connectedEnvironments);
return {
localEnvironments: input.connectedEnvironments.filter(
diff --git a/apps/mobile/src/features/connection/useConnectionController.ts b/apps/mobile/src/features/connection/useConnectionController.ts
index bad6b6f17..faa344775 100644
--- a/apps/mobile/src/features/connection/useConnectionController.ts
+++ b/apps/mobile/src/features/connection/useConnectionController.ts
@@ -20,6 +20,7 @@ import { useEnvironments } from "../../state/environments";
import { relayEnvironmentDiscovery } from "../../state/relay";
import { useAtomCommand } from "../../state/use-atom-command";
import { projectWorkspaceEnvironment, type WorkspaceEnvironment } from "../../state/workspaceModel";
+import { relayManagedEnvironmentIds } from "./environmentSections";
export interface RelayEnvironmentView {
readonly environment: RelayClientEnvironmentRecord;
@@ -49,7 +50,7 @@ export function useConnectionController() {
[environments],
);
const registeredIds = useMemo(
- () => new Set(connectedEnvironments.map((environment) => environment.environmentId)),
+ () => relayManagedEnvironmentIds(connectedEnvironments),
[connectedEnvironments],
);
const relayEnvironments = useMemo<ReadonlyArray<RelayEnvironmentView>>(