Skip to content

Commit f4c6495

Browse files
committed
chore: merge main into preview port branch
2 parents 2e74105 + 1451e7c commit f4c6495

564 files changed

Lines changed: 27616 additions & 10416 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.

‎.github/workflows/desktop-macos-preview.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ jobs:
7878
- name: Install browser secret helper build libraries
7979
run: sudo apt-get update && sudo apt-get install -y libsecret-1-dev pkg-config
8080

81+
# desktop-macos-preview-publish.yml packages this bundle as the preview channel.
8182
- name: Build JS bundle
83+
env:
84+
T3CODE_TELEMETRY_CHANNEL: ${{ github.repository == 'pingdotgg/t3code' && 'preview' || 'dev' }}
8285
run: vp run build:desktop
8386

8487
# Same layout as release.yml's js-bundle so release-desktop.yml can

‎.github/workflows/release-desktop.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,9 @@ jobs:
501501
# the runner, and only exact versions have a dist directory. Keep in
502502
# step with SEA_NODE_VERSION in apps/server/vite.config.ts.
503503
VP_NODE_VERSION: "26.8.2"
504+
# The executable bundles the server again, so it needs the same stamp
505+
# as release.yml's JS bundle.
506+
T3CODE_TELEMETRY_CHANNEL: ${{ github.repository == 'pingdotgg/t3code' && inputs.release_channel || 'dev' }}
504507
run: node apps/server/scripts/cli.ts build-exe --verbose
505508

506509
- name: Import macOS signing certificate for the CLI archive

‎.github/workflows/release.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,11 @@ jobs:
525525
# Runs t3#build (which depends on @t3tools/web#build) and
526526
# @t3tools/desktop#build, so apps/server/dist holds the server bundle
527527
# plus the web client and apps/desktop/dist-electron the Electron main.
528+
# The release channel is already stable, nightly, or preview. Builds in
529+
# other repositories report "dev" telemetry.
528530
- name: Build JS bundle
531+
env:
532+
T3CODE_TELEMETRY_CHANNEL: ${{ github.repository == 'pingdotgg/t3code' && needs.preflight.outputs.release_channel || 'dev' }}
529533
run: vp run build:desktop
530534

531535
# Two paths under apps/ so the artifact root is apps/; consumers download

‎apps/desktop/src/backend/DesktopBackendPool.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,50 @@ describe("DesktopBackendPool", () => {
156156
}),
157157
),
158158
);
159+
160+
it.effect("unregister stops the registered instance", () =>
161+
Effect.scoped(
162+
Effect.gen(function* () {
163+
const id = DesktopBackendPool.BackendInstanceId("wsl:Ubuntu");
164+
const pool = yield* DesktopBackendPool.DesktopBackendPool;
165+
const instance = yield* pool.register({
166+
id,
167+
label: Effect.succeed("WSL (Ubuntu)"),
168+
// A transient preflight failure leaves a restart fiber scheduled
169+
// without needing a real child process.
170+
configResolve: Effect.succeed({
171+
executablePath: "/electron",
172+
args: [],
173+
entryPath: "/server/bin.mjs",
174+
cwd: "/server",
175+
env: {},
176+
bootstrap: {
177+
mode: "desktop",
178+
noBrowser: true,
179+
port: 3774,
180+
t3Home: "/tmp/t3",
181+
host: "127.0.0.1",
182+
desktopBootstrapToken: "token",
183+
tailscaleServeEnabled: false,
184+
tailscaleServePort: 443,
185+
},
186+
bootstrapDelivery: "fd3",
187+
extendEnv: true,
188+
httpBaseUrl: new URL("http://127.0.0.1:3774"),
189+
captureOutput: false,
190+
preflightFailure: Option.some({ reason: "WSL starting", fatal: false }),
191+
} satisfies DesktopBackendStartConfig),
192+
});
193+
yield* instance.start;
194+
assert.equal((yield* instance.snapshot).restartScheduled, true);
195+
196+
yield* pool.unregister(id);
197+
198+
const stopped = yield* instance.snapshot;
199+
assert.equal(stopped.desiredRunning, false);
200+
assert.equal(stopped.restartScheduled, false);
201+
assert.equal(Option.isNone(yield* pool.get(id)), true);
202+
}).pipe(Effect.provide(layerPool(Ref.makeUnsafe("Windows")))),
203+
),
204+
);
159205
});

‎apps/desktop/src/backend/DesktopBackendPool.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,14 @@ export const layer = Layer.effect(
219219
] as const);
220220
}
221221
return Effect.gen(function* () {
222-
// Provide the captured factory services first, then the child scope
223-
// last so instance finalizers are owned by the unregisterable scope.
222+
// Provide the child scope after the captured factory context. That
223+
// context also holds the pool layer's Scope, so providing it last
224+
// would let it shadow the child scope and leave the instance's
225+
// stop finalizer and restart fibers running after unregister.
224226
const instanceScope = yield* Scope.fork(layerScope, "sequential");
225227
const instance = yield* DesktopBackendManager.makeBackendInstance(spec).pipe(
226-
Effect.provide(factoryContext),
227228
Scope.provide(instanceScope),
229+
Effect.provide(factoryContext),
228230
);
229231
const next = new Map(current);
230232
next.set(spec.id, {

‎apps/desktop/src/backend/DesktopServerExposure.test.ts‎

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ const tailnetNetworkInterfaces: DesktopNetworkInterfaces.NetworkInterfaces = {
4040
],
4141
};
4242

43-
function layerMockSpawner(statusJson = "{}") {
43+
function layerMockSpawner(statusJson = "{}", onSpawn?: () => void) {
4444
return Layer.succeed(
4545
ChildProcessSpawner.ChildProcessSpawner,
4646
ChildProcessSpawner.make(() =>
47-
Effect.succeed(
48-
ChildProcessSpawner.makeHandle({
47+
Effect.sync(() => {
48+
onSpawn?.();
49+
return ChildProcessSpawner.makeHandle({
4950
pid: ChildProcessSpawner.ProcessId(1),
5051
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)),
5152
isRunning: Effect.succeed(false),
@@ -57,8 +58,8 @@ function layerMockSpawner(statusJson = "{}") {
5758
all: Stream.empty,
5859
getInputFd: () => Sink.drain,
5960
getOutputFd: () => Stream.empty,
60-
}),
61-
),
61+
});
62+
}),
6263
),
6364
);
6465
}
@@ -146,6 +147,34 @@ const withHarness = <A, E, R>(
146147
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped);
147148

148149
describe("DesktopServerExposure", () => {
150+
it.effect("uses cached Tailscale identity to exclude another VPN's pairing address", () => {
151+
let statusReads = 0;
152+
return withHarness(
153+
{
154+
...lanNetworkInterfaces,
155+
pvpnksintrf1: [{ address: "100.85.0.1", family: "IPv4", internal: false }],
156+
vpn0: [{ address: "100.74.126.34", family: "IPv4", internal: false }],
157+
},
158+
Effect.gen(function* () {
159+
const serverExposure = yield* DesktopServerExposure.DesktopServerExposure;
160+
yield* serverExposure.configureFromSettings({ port: 4173 });
161+
yield* serverExposure.setMode("network-accessible");
162+
163+
const endpoints = yield* serverExposure.getAdvertisedEndpoints;
164+
assert.deepEqual(
165+
endpoints.map((endpoint) => endpoint.httpBaseUrl),
166+
["http://127.0.0.1:4173/", "http://192.168.1.20:4173/", "http://100.74.126.34:4173/"],
167+
);
168+
assert.deepEqual(yield* serverExposure.getAdvertisedEndpoints, endpoints);
169+
assert.equal(statusReads, 1);
170+
}),
171+
{},
172+
layerMockSpawner(`{"Self":{"TailscaleIPs":["100.74.126.34"]}}`, () => {
173+
statusReads += 1;
174+
}),
175+
);
176+
});
177+
149178
it.effect("falls back to local-only without losing the requested network preference", () =>
150179
withHarness(
151180
emptyNetworkInterfaces,

‎apps/desktop/src/backend/DesktopServerExposure.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,8 @@ export const make = Effect.gen(function* () {
437437
// Cache the `tailscale status` spawn for the TTL. On macOS, the Mac App
438438
// Store Tailscale CLI lives inside Tailscale's sandbox container, so each
439439
// spawn re-triggers the "Other apps" TCC prompt.
440-
const cachedReadMagicDnsName = yield* Effect.cachedWithTTL(
440+
const cachedReadTailscaleStatus = yield* Effect.cachedWithTTL(
441441
readTailscaleStatus.pipe(
442-
Effect.map((status) => status.magicDnsName),
443442
Effect.orElseSucceed(() => null),
444443
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, childProcessSpawner),
445444
),
@@ -565,7 +564,7 @@ export const make = Effect.gen(function* () {
565564
serveEnabled: state.tailscaleServeEnabled,
566565
servePort: state.tailscaleServePort,
567566
networkInterfaces: currentNetworkInterfaces,
568-
readMagicDnsName: cachedReadMagicDnsName,
567+
readStatus: cachedReadTailscaleStatus,
569568
}).pipe(
570569
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, childProcessSpawner),
571570
Effect.provideService(HttpClient.HttpClient, httpClient),

‎apps/desktop/src/backend/tailscaleEndpointProvider.test.ts‎

Lines changed: 111 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,109 @@ const layerUnusedTailscaleExternalServices = Layer.mergeAll(
2020
),
2121
);
2222

23+
const protonAndTailscaleInterfaces = {
24+
pvpnksintrf1: [{ address: "100.85.0.1", family: "IPv4", internal: false }],
25+
tailscale0: [{ address: "100.74.126.34", family: "IPv4", internal: false }],
26+
};
27+
2328
describe("tailscale endpoint provider", () => {
29+
it.effect("does not advertise Proton's CGNAT address as a Tailscale pairing endpoint", () =>
30+
Effect.gen(function* () {
31+
const endpoints = yield* resolveTailscaleAdvertisedEndpoints({
32+
port: 3773,
33+
networkInterfaces: protonAndTailscaleInterfaces,
34+
statusJson: `{"Self":{"TailscaleIPs":["100.74.126.34"]}}`,
35+
});
36+
assert.deepEqual(
37+
endpoints.map((endpoint) => endpoint.httpBaseUrl),
38+
["http://100.74.126.34:3773/"],
39+
);
40+
}).pipe(Effect.provide(layerUnusedTailscaleExternalServices)),
41+
);
42+
43+
it.effect(
44+
"does not advertise CGNAT interfaces when Tailscale reports no assigned addresses",
45+
() =>
46+
Effect.gen(function* () {
47+
const endpoints = yield* resolveTailscaleAdvertisedEndpoints({
48+
port: 3773,
49+
networkInterfaces: { pvpnksintrf1: protonAndTailscaleInterfaces.pvpnksintrf1 },
50+
statusJson: `{"BackendState":"NoState","Self":{"TailscaleIPs":null}}`,
51+
});
52+
assert.deepEqual(endpoints, []);
53+
}).pipe(Effect.provide(layerUnusedTailscaleExternalServices)),
54+
);
55+
56+
it.effect("keeps native Tailscale interfaces with missing, malformed, or stale status", () =>
57+
Effect.gen(function* () {
58+
for (const interfaceName of ["tailscale0", "Tailscale"]) {
59+
for (const statusJson of [null, "not-json", `{"Self":{"TailscaleIPs":[]}}`]) {
60+
const endpoints = yield* resolveTailscaleAdvertisedEndpoints({
61+
port: 3773,
62+
networkInterfaces: {
63+
pvpnksintrf1: protonAndTailscaleInterfaces.pvpnksintrf1,
64+
[interfaceName]: protonAndTailscaleInterfaces.tailscale0,
65+
},
66+
statusJson,
67+
});
68+
assert.deepEqual(
69+
endpoints.map((endpoint) => endpoint.httpBaseUrl),
70+
["http://100.74.126.34:3773/"],
71+
);
72+
}
73+
}
74+
}).pipe(Effect.provide(layerUnusedTailscaleExternalServices)),
75+
);
76+
77+
it.effect(
78+
"recognizes a macOS Tailscale tunnel by its IPv6 address when status is unavailable",
79+
() =>
80+
Effect.gen(function* () {
81+
const endpoints = yield* resolveTailscaleAdvertisedEndpoints({
82+
port: 3773,
83+
networkInterfaces: {
84+
utun3: [{ address: "100.85.0.1", family: "IPv4", internal: false }],
85+
utun4: [
86+
{ address: "100.74.126.34", family: "IPv4", internal: false },
87+
{ address: "fd7a:115c:a1e0::1234", family: "IPv6", internal: false },
88+
],
89+
},
90+
statusJson: null,
91+
});
92+
assert.deepEqual(
93+
endpoints.map((endpoint) => endpoint.httpBaseUrl),
94+
["http://100.74.126.34:3773/"],
95+
);
96+
}).pipe(Effect.provide(layerUnusedTailscaleExternalServices)),
97+
);
98+
99+
it.effect("uses assigned addresses for renamed adapters without IPv6", () =>
100+
Effect.gen(function* () {
101+
const endpoints = yield* resolveTailscaleAdvertisedEndpoints({
102+
port: 3773,
103+
networkInterfaces: {
104+
vpn0: [{ address: "100.74.126.34", family: "IPv4", internal: false }],
105+
},
106+
statusJson: `{"Self":{"TailscaleIPs":["100.74.126.34"]}}`,
107+
});
108+
assert.deepEqual(
109+
endpoints.map((endpoint) => endpoint.httpBaseUrl),
110+
["http://100.74.126.34:3773/"],
111+
);
112+
}).pipe(Effect.provide(layerUnusedTailscaleExternalServices)),
113+
);
114+
115+
it.effect("does not advertise cached Tailscale addresses absent from local interfaces", () =>
116+
Effect.gen(function* () {
117+
const endpoints = yield* resolveTailscaleAdvertisedEndpoints({
118+
port: 3773,
119+
networkInterfaces: { pvpnksintrf1: protonAndTailscaleInterfaces.pvpnksintrf1 },
120+
statusJson: `{"Self":{"TailscaleIPs":["100.74.126.35"]}}`,
121+
});
122+
assert.deepEqual(endpoints, []);
123+
}).pipe(Effect.provide(layerUnusedTailscaleExternalServices)),
124+
);
125+
24126
it.effect("parses MagicDNS names from tailscale status", () =>
25127
Effect.gen(function* () {
26128
const dnsName = yield* parseTailscaleMagicDnsName(
@@ -49,7 +151,7 @@ describe("tailscale endpoint provider", () => {
49151
},
50152
],
51153
},
52-
statusJson: `{"Self":{"DNSName":"desktop.tail.ts.net."}}`,
154+
statusJson: `{"Self":{"DNSName":"desktop.tail.ts.net.","TailscaleIPs":["100.100.100.100"]}}`,
53155
});
54156
assert.deepEqual(endpoints, [
55157
{
@@ -96,21 +198,24 @@ describe("tailscale endpoint provider", () => {
96198
}).pipe(Effect.provide(layerUnusedTailscaleExternalServices)),
97199
);
98200

99-
it.effect("uses an injected magic DNS name reader instead of spawning tailscale", () =>
201+
it.effect("uses one injected status reader for both IP and MagicDNS endpoints", () =>
100202
Effect.gen(function* () {
101203
let readerCalls = 0;
102204
const endpoints = yield* resolveTailscaleAdvertisedEndpoints({
103205
port: 3773,
104-
networkInterfaces: {},
105-
readMagicDnsName: Effect.sync(() => {
206+
networkInterfaces: protonAndTailscaleInterfaces,
207+
readStatus: Effect.sync(() => {
106208
readerCalls += 1;
107-
return "desktop.tail.ts.net";
209+
return {
210+
magicDnsName: "desktop.tail.ts.net",
211+
tailnetIpv4Addresses: ["100.74.126.34"],
212+
};
108213
}),
109214
});
110215
assert.equal(readerCalls, 1);
111216
assert.deepEqual(
112217
endpoints.map((endpoint) => endpoint.httpBaseUrl),
113-
["https://desktop.tail.ts.net/"],
218+
["http://100.74.126.34:3773/", "https://desktop.tail.ts.net/"],
114219
);
115220
}).pipe(Effect.provide(layerUnusedTailscaleExternalServices)),
116221
);

0 commit comments

Comments
 (0)