Skip to content

Commit 0d2037c

Browse files
author
PR Batch Tester
committed
fix(web): hide the MCP URL while link settings refresh
Consolidate MCP URL and relink coverage into one regression test and replace manual service stubs with Layer.mock.
1 parent 4e7061b commit 0d2037c

3 files changed

Lines changed: 17 additions & 56 deletions

File tree

‎apps/server/src/cloud/ConnectReachability.test.ts‎

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { HttpClient, HttpClientResponse } from "effect/http";
1111
import { ChildProcessSpawner } from "effect/process";
1212

1313
import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
14-
import { CLOUD_ENDPOINT_RUNTIME_CONFIG } from "./config.ts";
1514
import * as ConnectReachability from "./ConnectReachability.ts";
1615
import * as ManagedEndpointRuntime from "./ManagedEndpointRuntime.ts";
1716

@@ -71,17 +70,6 @@ describe("classifyReachability", () => {
7170
).toMatchObject({ cause: "dns_failed" });
7271
});
7372

74-
it("gives the MCP URL on the host the running tunnel answered on", () => {
75-
const result = ConnectReachability.classifyReachability(
76-
facts({ endpoint: { kind: "status", status: 200 } }),
77-
checkedAt,
78-
);
79-
expect(result).toMatchObject({ status: "reachable", hostname: "env.example.test" });
80-
expect(result.status === "reachable" && connectReachableMcpUrl(result)).toBe(
81-
"https://env.example.test/mcp",
82-
);
83-
});
84-
8573
it("waits on a connector that has not connected while the edge answers", () => {
8674
expect(
8775
ConnectReachability.classifyReachability(
@@ -93,53 +81,35 @@ describe("classifyReachability", () => {
9381
});
9482

9583
describe("ConnectReachability", () => {
96-
it.effect("drops a result once the tunnel config it checked is replaced", () => {
97-
const secrets = new Map([[CLOUD_ENDPOINT_RUNTIME_CONFIG, new TextEncoder().encode("first")]]);
98-
const unused = Effect.die("unused");
84+
it.effect("exposes the checked tunnel's MCP URL until its config changes", () => {
85+
let config = new TextEncoder().encode("first");
9986
const dependencies = Layer.mergeAll(
100-
Layer.succeed(
101-
ServerSecretStore.ServerSecretStore,
102-
ServerSecretStore.ServerSecretStore.of({
103-
get: (name) => Effect.sync(() => Option.fromNullishOr(secrets.get(name))),
104-
set: () => unused,
105-
create: () => unused,
106-
getOrCreateRandom: () => unused,
107-
remove: () => unused,
108-
}),
109-
),
110-
Layer.succeed(
111-
ManagedEndpointRuntime.CloudManagedEndpointRuntime,
112-
ManagedEndpointRuntime.CloudManagedEndpointRuntime.of({
113-
applyConfig: () => unused,
114-
inspectConnector: Effect.succeed(connected),
115-
readinessChanged: Stream.empty,
116-
recoveryRequests: Stream.empty,
117-
requestRecovery: () => unused,
118-
tunnelConnected: Stream.empty,
119-
withLinkStateLock: (effect) => effect,
120-
}),
121-
),
87+
Layer.mock(ServerSecretStore.ServerSecretStore)({
88+
get: () => Effect.sync(() => Option.some(config)),
89+
}),
90+
Layer.mock(ManagedEndpointRuntime.CloudManagedEndpointRuntime)({
91+
inspectConnector: Effect.succeed(connected),
92+
readinessChanged: Stream.empty,
93+
}),
12294
Layer.succeed(
12395
HttpClient.HttpClient,
12496
HttpClient.make((request) =>
12597
Effect.succeed(HttpClientResponse.fromWeb(request, new Response("{}"))),
12698
),
12799
),
128-
Layer.succeed(
129-
ChildProcessSpawner.ChildProcessSpawner,
130-
ChildProcessSpawner.make(() => unused),
131-
),
100+
Layer.mock(ChildProcessSpawner.ChildProcessSpawner)({}),
132101
);
133102

134103
return Effect.gen(function* () {
135104
const reachability = yield* ConnectReachability.ConnectReachability;
136105
yield* reachability.check;
137-
expect(Option.getOrNull(yield* reachability.latest)).toMatchObject({
138-
hostname: "env.example.test",
139-
});
106+
const result = Option.getOrThrow(yield* reachability.latest);
107+
expect(result.status === "reachable" && connectReachableMcpUrl(result)).toBe(
108+
"https://env.example.test/mcp",
109+
);
140110

141111
// A relink stores a new tunnel before its connector reports in.
142-
secrets.set(CLOUD_ENDPOINT_RUNTIME_CONFIG, new TextEncoder().encode("second"));
112+
config = new TextEncoder().encode("second");
143113
expect(yield* reachability.latest).toEqual(Option.none());
144114
}).pipe(Effect.provide(ConnectReachability.layer.pipe(Layer.provide(dependencies))));
145115
});

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,11 @@ function useCopyMcpUrl() {
129129
}).copyToClipboard;
130130
}
131131

132-
/**
133-
* This machine's T3 Connect MCP URL, from the host its running tunnel answered on. Shown only
134-
* after a passing check, so it never hands out an address nothing serves.
135-
*/
136132
export function PrimaryMcpUrlMenuItem() {
137-
const { data } = usePrimaryCloudLinkState();
133+
const { data, isPending } = usePrimaryCloudLinkState();
138134
const copyMcpUrl = useCopyMcpUrl();
139135
const reachability =
140-
data && data.managedTunnelActive !== false && data.linkRevoked !== true
136+
data && !isPending && data.managedTunnelActive !== false && data.linkRevoked !== true
141137
? data.reachability
142138
: undefined;
143139
const mcpUrl = reachability?.status === "reachable" ? connectReachableMcpUrl(reachability) : null;

‎packages/contracts/src/environmentHttp.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,6 @@ export function formatConnectReachable(
455455
].join(" · ");
456456
}
457457

458-
/**
459-
* The MCP URL outside agents use to reach this environment through T3 Connect. It comes from
460-
* the host the running tunnel answered on, since a saved T3 Connect entry with the same name
461-
* can belong to an older environment whose tunnel is gone.
462-
*/
463458
export function connectReachableMcpUrl(
464459
result: Extract<EnvironmentConnectReachability, { status: "reachable" }>,
465460
): string | null {

0 commit comments

Comments
 (0)