Skip to content

Commit 87ce1cd

Browse files
committed
chore: sync latest main for pnpm global virtual store
2 parents b3e50d9 + 8f0d66d commit 87ce1cd

19 files changed

Lines changed: 667 additions & 63 deletions

‎apps/mobile/src/features/agent-awareness/notificationNavigation.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,56 @@ describe("extractAgentNotificationDeepLink", () => {
105105
});
106106

107107
describe("routeAgentNotificationResponseOnce", () => {
108+
it("retries a failed initial response and deduplicates it after navigation succeeds", async () => {
109+
vi.spyOn(console, "error").mockImplementation(() => undefined);
110+
const response = responseWithData({ deepLink: "/threads/env/thread" }) as NotificationResponse;
111+
const handledResponseIds = new Set<string>();
112+
const navigate = vi.fn().mockImplementationOnce(() => {
113+
throw new Error("navigation not ready");
114+
});
115+
const clearLastResponse = vi.fn(() => Promise.resolve());
116+
const consume = () =>
117+
consumeLastAgentNotificationResponse({
118+
getLastResponse: () => Promise.resolve(response),
119+
clearLastResponse,
120+
handleResponse: (response) =>
121+
routeAgentNotificationResponseOnce({ handledResponseIds, response, navigate }),
122+
});
123+
124+
await consume();
125+
expect(handledResponseIds.size).toBe(0);
126+
expect(clearLastResponse).not.toHaveBeenCalled();
127+
128+
await consume();
129+
expect(navigate).toHaveBeenCalledTimes(2);
130+
expect(navigate).toHaveBeenLastCalledWith("/threads/env/thread");
131+
expect(clearLastResponse).toHaveBeenCalledOnce();
132+
133+
routeAgentNotificationResponseOnce({ handledResponseIds, response, navigate });
134+
expect(navigate).toHaveBeenCalledTimes(2);
135+
});
136+
137+
it("discards malformed destination ids without leaving the response pending", async () => {
138+
const response = responseWithData({
139+
environmentId: "env",
140+
threadId: "\ud800",
141+
}) as NotificationResponse;
142+
const handledResponseIds = new Set<string>();
143+
const navigate = vi.fn();
144+
const clearLastResponse = vi.fn(() => Promise.resolve());
145+
146+
await consumeLastAgentNotificationResponse({
147+
getLastResponse: () => Promise.resolve(response),
148+
clearLastResponse,
149+
handleResponse: (response) =>
150+
routeAgentNotificationResponseOnce({ handledResponseIds, response, navigate }),
151+
});
152+
153+
expect(navigate).not.toHaveBeenCalled();
154+
expect(clearLastResponse).toHaveBeenCalledOnce();
155+
expect(handledResponseIds.has("notification-1")).toBe(true);
156+
});
157+
108158
it("does not navigate twice when the initial and listener responses refer to one notification", () => {
109159
const handledResponseIds = new Set<string>();
110160
const navigations: Array<string> = [];

‎apps/mobile/src/features/agent-awareness/notificationPayload.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ function encodeThreadDeepLink(input: {
4141
if (input.environmentId.length === 0 || input.threadId.length === 0) {
4242
return null;
4343
}
44-
return `/threads/${encodeURIComponent(input.environmentId)}/${encodeURIComponent(input.threadId)}`;
44+
try {
45+
return `/threads/${encodeURIComponent(input.environmentId)}/${encodeURIComponent(input.threadId)}`;
46+
} catch {
47+
return null;
48+
}
4549
}
4650

4751
function normalizeThreadDeepLink(value: string): string | null {
@@ -104,11 +108,11 @@ export function routeAgentNotificationResponseOnce(input: {
104108
if (responseId && input.handledResponseIds.has(responseId)) {
105109
return;
106110
}
107-
if (responseId) {
108-
input.handledResponseIds.add(responseId);
109-
}
110111
const deepLink = extractAgentNotificationDeepLink(input.response);
111112
if (deepLink) {
112113
input.navigate(deepLink);
113114
}
115+
if (responseId) {
116+
input.handledResponseIds.add(responseId);
117+
}
114118
}

‎apps/server/src/environment/DirectEndpoints.test.ts‎

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,27 @@ const vpnInterface = (address: string) => [
8686
},
8787
];
8888

89-
const virtualInterface = (address: string) => [
89+
const virtualInterface = (address: string, mac = "02:42:ac:11:00:01") => [
9090
{
9191
address,
9292
netmask: "255.255.0.0",
9393
family: "IPv4" as const,
94-
mac: "02:42:ac:11:00:01",
94+
mac,
9595
internal: false,
9696
cidr: `${address}/16`,
9797
},
9898
];
9999

100100
describe("resolveBoundEndpoints", () => {
101101
it("lists every external IPv4 address for a wildcard bind, tagging the tailnet one", () => {
102-
expect(resolveBoundEndpoints({ host: "0.0.0.0", port: 3773, interfaces: INTERFACES })).toEqual([
102+
expect(
103+
resolveBoundEndpoints({
104+
platform: "linux",
105+
host: "0.0.0.0",
106+
port: 3773,
107+
interfaces: INTERFACES,
108+
}),
109+
).toEqual([
103110
{ kind: "lan", httpBaseUrl: "http://192.168.1.10:3773/" },
104111
{ kind: "tailnet", httpBaseUrl: "http://100.101.102.103:3773/" },
105112
]);
@@ -115,21 +122,56 @@ describe("resolveBoundEndpoints", () => {
115122
bridge100: virtualInterface("192.168.64.1"),
116123
vmbr0: virtualInterface("192.168.1.20"),
117124
};
118-
expect(resolveBoundEndpoints({ host: "0.0.0.0", port: 3773, interfaces })).toEqual([
125+
expect(
126+
resolveBoundEndpoints({ platform: "linux", host: "0.0.0.0", port: 3773, interfaces }),
127+
).toEqual([
119128
{ kind: "lan", httpBaseUrl: "http://192.168.1.10:3773/" },
120129
{ kind: "tailnet", httpBaseUrl: "http://100.101.102.103:3773/" },
121130
{ kind: "lan", httpBaseUrl: "http://192.168.1.20:3773/" },
122131
]);
123132
});
124133

134+
it("omits Windows host-only adapters without excluding guest NICs or explicit binds", () => {
135+
const interfaces = {
136+
...INTERFACES,
137+
"VirtualBox-Host-Only-Netzwerk": virtualInterface("192.168.56.1", "0A:00:27:00:01:01"),
138+
"Ethernet 2": virtualInterface("192.168.150.1", "00:50:56:c0:00:01"),
139+
"Renamed network": virtualInterface("192.168.151.1", "00:50:56:c0:00:08"),
140+
guest1: virtualInterface("192.168.1.30", "08:00:27:5e:1a:22"),
141+
guest2: virtualInterface("192.168.1.31", "00:50:56:2b:8c:01"),
142+
guest3: virtualInterface("192.168.1.32", "00:0c:29:4f:8e:35"),
143+
guest4: virtualInterface("192.168.1.33", "00:50:56:80:8c:01"),
144+
};
145+
const input = { host: "0.0.0.0", port: 3773, interfaces };
146+
const retained = [
147+
{ kind: "lan", httpBaseUrl: "http://192.168.1.10:3773/" },
148+
{ kind: "tailnet", httpBaseUrl: "http://100.101.102.103:3773/" },
149+
...[30, 31, 32, 33].map((last) => ({
150+
kind: "lan",
151+
httpBaseUrl: `http://192.168.1.${last}:3773/`,
152+
})),
153+
];
154+
expect(resolveBoundEndpoints({ ...input, platform: "win32" })).toEqual(retained);
155+
for (const platform of ["linux", "darwin"] as const) {
156+
expect(resolveBoundEndpoints({ ...input, platform })).toHaveLength(retained.length + 3);
157+
}
158+
for (const host of ["192.168.56.1", "192.168.150.1", "192.168.151.1"]) {
159+
expect(resolveBoundEndpoints({ ...input, platform: "win32", host })).toEqual([
160+
{ kind: "lan", httpBaseUrl: `http://${host}:3773/` },
161+
]);
162+
}
163+
});
164+
125165
it("tags only addresses on Tailscale's interface as tailnet, not other VPNs in its range", () => {
126166
const interfaces = {
127167
en0: INTERFACES.en0,
128168
tailscale0: vpnInterface("100.70.1.2"),
129169
CloudflareWARP: vpnInterface("100.96.0.1"),
130170
utun7: vpnInterface("100.85.0.1"),
131171
};
132-
expect(resolveBoundEndpoints({ host: "0.0.0.0", port: 3773, interfaces })).toEqual([
172+
expect(
173+
resolveBoundEndpoints({ platform: "linux", host: "0.0.0.0", port: 3773, interfaces }),
174+
).toEqual([
133175
{ kind: "lan", httpBaseUrl: "http://192.168.1.10:3773/" },
134176
{ kind: "tailnet", httpBaseUrl: "http://100.70.1.2:3773/" },
135177
{ kind: "lan", httpBaseUrl: "http://100.96.0.1:3773/" },
@@ -139,19 +181,27 @@ describe("resolveBoundEndpoints", () => {
139181

140182
it("never reports a host name, which can resolve to another machine per client", () => {
141183
for (const host of ["server.local", "devbox", "devbox.home.arpa"]) {
142-
expect(resolveBoundEndpoints({ host, port: 3773, interfaces: INTERFACES })).toEqual([]);
184+
expect(
185+
resolveBoundEndpoints({ platform: "linux", host, port: 3773, interfaces: INTERFACES }),
186+
).toEqual([]);
143187
}
144188
});
145189

146190
it("never reports a public address, which would carry the credential over plain HTTP", () => {
147191
expect(
148-
resolveBoundEndpoints({ host: "203.0.113.20", port: 3773, interfaces: INTERFACES }),
192+
resolveBoundEndpoints({
193+
platform: "linux",
194+
host: "203.0.113.20",
195+
port: 3773,
196+
interfaces: INTERFACES,
197+
}),
149198
).toEqual([]);
150199
});
151200

152201
it("reports only the tailnet address on a cloud VM, whose private network no client shares", () => {
153202
expect(
154203
resolveBoundEndpoints({
204+
platform: "linux",
155205
host: "0.0.0.0",
156206
port: 3773,
157207
interfaces: INTERFACES,
@@ -162,7 +212,12 @@ describe("resolveBoundEndpoints", () => {
162212

163213
it("never reports an IPv4-mapped host, which can name the client's own loopback", () => {
164214
expect(
165-
resolveBoundEndpoints({ host: "::ffff:127.0.0.1", port: 3773, interfaces: INTERFACES }),
215+
resolveBoundEndpoints({
216+
platform: "linux",
217+
host: "::ffff:127.0.0.1",
218+
port: 3773,
219+
interfaces: INTERFACES,
220+
}),
166221
).toEqual([]);
167222
});
168223
});

‎apps/server/src/environment/DirectEndpoints.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
1414
import * as NodeNet from "node:net";
1515
import * as NodeOS from "node:os";
1616

17+
import * as HostProcess from "@t3tools/shared/HostProcess";
1718
import { isTailnetHost } from "@t3tools/shared/hostClassification";
1819

1920
import * as ServerConfig from "../config.ts";
@@ -49,7 +50,11 @@ const isTailscaleInterface = (
4950
/^tailscale/i.test(name) ||
5051
entries.some((entry) => entry.family === "IPv6" && isTailnetHost(entry.address));
5152

53+
// Windows adapter names are mutable; Linux bridges can inherit these MACs.
54+
const WINDOWS_HOST_ADAPTER_MAC = /^(0a:00:27|00:50:56:c0:00):/i;
55+
5256
export function resolveBoundEndpoints(input: {
57+
readonly platform: NodeJS.Platform;
5358
readonly host: string | undefined;
5459
readonly port: number;
5560
readonly interfaces: NetworkInterfacesMap;
@@ -67,7 +72,10 @@ export function resolveBoundEndpoints(input: {
6772
.flatMap(([name, entries]) => (VIRTUAL_INTERFACE.test(name) ? [] : (entries ?? [])))
6873
.filter(
6974
(entry) =>
70-
!entry.internal && entry.family === "IPv4" && isAdvertisableAddress(entry.address),
75+
!entry.internal &&
76+
entry.family === "IPv4" &&
77+
isAdvertisableAddress(entry.address) &&
78+
!(input.platform === "win32" && WINDOWS_HOST_ADAPTER_MAC.test(entry.mac)),
7179
)
7280
.map((entry) => entry.address)
7381
: [input.host!].filter(isAdvertisableAddress);
@@ -111,6 +119,7 @@ export const make = Effect.gen(function* () {
111119
const config = yield* ServerConfig.ServerConfig;
112120
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
113121
const httpClient = yield* HttpClient.HttpClient;
122+
const platform = yield* HostProcess.Platform;
114123
// Only the service default listens on every interface without being asked,
115124
// so only it checks once whether it runs in a cloud. The check starts now so
116125
// the first client does not wait for its timeout.
@@ -122,6 +131,7 @@ export const make = Effect.gen(function* () {
122131
const resolve = Effect.gen(function* () {
123132
const endpoints = [
124133
...resolveBoundEndpoints({
134+
platform,
125135
host: config.host,
126136
port: config.port,
127137
interfaces: NodeOS.networkInterfaces(),

0 commit comments

Comments
 (0)