Skip to content

Commit 841e87f

Browse files
authored
chore: sync with upstream pingdotgg/t3code main (#200)
2 parents dc4c41f + d2b6b16 commit 841e87f

95 files changed

Lines changed: 5687 additions & 1224 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/features/threads/thread-work-log.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,13 +937,14 @@ const ThreadWorkLogRow = function ThreadWorkLogRow(
937937
const warning = failureItem.failure.class === "usage_limit";
938938
const timestamp = new Date(row.createdAt);
939939
const resetAt = failureItem.failure.resetAt;
940+
// The reset time is the viewer's local time; naming the zone keeps it unambiguous.
940941
const resetTime = resetAt
941-
? new Date(resetAt).toLocaleString(undefined, {
942+
? `${new Date(resetAt).toLocaleString(undefined, {
942943
month: "short",
943944
day: "numeric",
944945
hour: "numeric",
945946
minute: "2-digit",
946-
})
947+
})} (${new Intl.DateTimeFormat().resolvedOptions().timeZone})`
947948
: null;
948949
const label = warning
949950
? `Usage limit reached.${resetTime ? ` Retry after ${resetTime}.` : ""}`

‎apps/server/src/cloud/CloudLink.lifecycle.test.ts‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ describe("releaseManagedTunnelOnShutdown", () => {
140140
readonly address?: HttpServer.HttpServer["Service"]["address"];
141141
readonly respondEffect?: Effect.Effect<Response>;
142142
readonly getExisting?: CliTokenManager.CloudCliTokenManager["Service"]["getExisting"];
143+
readonly latestReachability?: ConnectReachability.ConnectReachability["Service"]["latest"];
143144
}
144145

145146
const writeLauncherState = (update: ServiceUpdateRecord) =>
@@ -165,7 +166,7 @@ describe("releaseManagedTunnelOnShutdown", () => {
165166
ConnectReachability.ConnectReachability,
166167
ConnectReachability.ConnectReachability.of({
167168
check: Effect.die("unused"),
168-
latest: Effect.succeedNone,
169+
latest: harness.latestReachability ?? Effect.succeedNone,
169170
}),
170171
),
171172
Effect.provideService(HttpServer.HttpServer, {
@@ -1050,4 +1051,57 @@ describe("releaseManagedTunnelOnShutdown", () => {
10501051
expect(values.has(CLOUD_ENDPOINT_RUNTIME_CONFIG)).toBe(false);
10511052
}).pipe(provideReleaseHarness({ store: failingStore, applyConfigCalls, requests }));
10521053
});
1054+
1055+
it.effect("does not report a not-linked check once the managed tunnel config is stored", () => {
1056+
const { store } = makeMemorySecretStore(managedLinkSecrets);
1057+
const notLinked = ConnectReachability.classifyReachability(
1058+
{
1059+
managedTunnelConfigured: false,
1060+
connector: null,
1061+
endpoint: null,
1062+
edgeReachable: null,
1063+
exitNode: null,
1064+
},
1065+
"2026-10-29T00:00:00.000Z",
1066+
);
1067+
1068+
return Effect.gen(function* () {
1069+
const state = yield* (yield* CloudLink.CloudLink).linkState();
1070+
1071+
expect(state.managedTunnelActive).toBe(true);
1072+
expect(state.reachability?.status === "unreachable" && state.reachability.cause).not.toBe(
1073+
"not_linked",
1074+
);
1075+
}).pipe(
1076+
provideReleaseHarness({
1077+
store,
1078+
applyConfigCalls: [],
1079+
requests: [],
1080+
latestReachability: Effect.succeedSome(notLinked),
1081+
}),
1082+
);
1083+
});
1084+
1085+
it.effect("reports a check that ran after the managed tunnel config was stored", () => {
1086+
const { store } = makeMemorySecretStore(managedLinkSecrets);
1087+
const reachable = {
1088+
status: "reachable" as const,
1089+
checkedAt: "2026-10-29T00:00:00.000Z",
1090+
readyConnections: 4,
1091+
protocol: "quic",
1092+
};
1093+
1094+
return Effect.gen(function* () {
1095+
const state = yield* (yield* CloudLink.CloudLink).linkState();
1096+
1097+
expect(state.reachability).toEqual(reachable);
1098+
}).pipe(
1099+
provideReleaseHarness({
1100+
store,
1101+
applyConfigCalls: [],
1102+
requests: [],
1103+
latestReachability: Effect.succeedSome(reachable),
1104+
}),
1105+
);
1106+
});
10531107
});

‎apps/server/src/cloud/CloudLink.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,13 @@ const make = Effect.gen(function* () {
12901290
],
12911291
{ concurrency: 8 },
12921292
);
1293+
// A not-linked check predates the stored tunnel config; the next check replaces it.
1294+
const currentReachability = Option.filter(
1295+
latestReachability,
1296+
(result) =>
1297+
Option.isNone(endpointRuntimeConfig) ||
1298+
!(result.status === "unreachable" && result.cause === "not_linked"),
1299+
);
12931300
return {
12941301
linked: Option.isSome(cloudUserId),
12951302
linkRevoked: Option.isSome(cloudUserId) && Option.isSome(revoked),
@@ -1302,7 +1309,7 @@ const make = Effect.gen(function* () {
13021309
: false,
13031310
holdWebhooksWhileOffline:
13041311
Option.isSome(holdWebhooks) && bytesToString(holdWebhooks.value) === "true",
1305-
...(Option.isSome(latestReachability) ? { reachability: latestReachability.value } : {}),
1312+
...(Option.isSome(currentReachability) ? { reachability: currentReachability.value } : {}),
13061313
} satisfies EnvironmentCloudLinkStateResult;
13071314
});
13081315

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ describe("classifyReachability", () => {
6565
classifyReachability(facts({ connector: notConnected, edgeReachable: true }), checkedAt),
6666
).toMatchObject({ cause: "connector_not_ready" });
6767
});
68+
69+
it("does not point an unlinked server at a background service it may not have", () => {
70+
// Desktop and `t3 serve` run the server without a background service.
71+
const result = classifyReachability(facts({ managedTunnelConfigured: false }), checkedAt);
72+
expect(result).toMatchObject({ cause: "not_linked" });
73+
expect(result.status === "unreachable" && result.fix).not.toContain("t3 service");
74+
});
6875
});
6976

7077
describe("T3 Connect troubleshooting links", () => {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ export function classifyReachability(
6868
const restart = "Restart T3 Code. If it stays, run `t3 connect` again.";
6969

7070
if (!facts.managedTunnelConfigured) {
71+
// A running server reads the link `t3 connect` stores only at startup.
7172
return fail(
7273
"not_linked",
7374
"The server has not set up a T3 Connect tunnel.",
74-
"Run `t3 connect`, then restart the server (`t3 service restart`) so it applies the link.",
75+
"Run `t3 connect`, then restart T3 Code so it applies the link.",
7576
);
7677
}
7778
if (connector === null) {

‎apps/server/src/mcp/PreviewAutomationBroker.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,43 @@ it.effect.each([
335335
),
336336
);
337337

338+
it.effect("names the click target that matched nothing when the server browser times out", () =>
339+
Effect.scoped(
340+
Effect.gen(function* () {
341+
const broker = yield* makeBroker;
342+
const clientId = SERVER_BROWSER_AUTOMATION_CLIENT_ID;
343+
const requests = requestsFrom(yield* broker.connect(makeHost({ clientId })));
344+
yield* Stream.runForEach(requests, (request) =>
345+
broker.respond({
346+
clientId,
347+
connectionId: request.connectionId,
348+
requestId: request.requestId,
349+
ok: false,
350+
error: {
351+
_tag: "PreviewAutomationTimeoutError",
352+
message: "No element matches the target.",
353+
detail: { reason: 'No element matches ".definitely-no-such-t3-target".' },
354+
},
355+
}),
356+
).pipe(Effect.forkScoped);
357+
yield* Effect.yieldNow;
358+
359+
const error = yield* broker
360+
.invoke<void>({
361+
scope,
362+
operation: "click",
363+
input: { selector: ".definitely-no-such-t3-target", timeoutMs: 15_000 },
364+
})
365+
.pipe(Effect.flip);
366+
367+
expect(error._tag).toBe("PreviewAutomationTimeoutError");
368+
expect(error.message).toBe(
369+
'Preview automation click timed out after 15000ms. No element matches ".definitely-no-such-t3-target".',
370+
);
371+
}),
372+
),
373+
);
374+
338375
it.effect("distinguishes malformed remote failures", () =>
339376
Effect.scoped(
340377
Effect.gen(function* () {

‎apps/server/src/mcp/PreviewAutomationBroker.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ const readRemoteTimeoutMs = (detail: unknown): number | undefined => {
205205
: undefined;
206206
};
207207

208+
const readRemoteReason = (detail: unknown): string | undefined =>
209+
typeof detail === "object" &&
210+
detail !== null &&
211+
"reason" in detail &&
212+
typeof detail.reason === "string"
213+
? detail.reason
214+
: undefined;
215+
208216
const MAX_REASON_CHARS = 500;
209217

210218
const classifyResponseError = (
@@ -255,9 +263,13 @@ const classifyResponseError = (
255263
});
256264
case "PreviewAutomationTimeoutError": {
257265
const remoteTimeoutMs = readRemoteTimeoutMs(error.detail);
266+
const remoteReason = readRemoteReason(error.detail);
258267
return new PreviewAutomationTimeoutError({
259268
...context,
260269
...remoteDiagnostics,
270+
...(context.clientId === SERVER_BROWSER_AUTOMATION_CLIENT_ID && remoteReason !== undefined
271+
? { reason: remoteReason.slice(0, MAX_REASON_CHARS) }
272+
: {}),
261273
...(remoteTimeoutMs === undefined
262274
? {}
263275
: { timeoutMs: Math.min(context.timeoutMs, remoteTimeoutMs) }),

0 commit comments

Comments
 (0)