Skip to content

Commit ab2824a

Browse files
committed
fix(desktop): carry the kill switch into a WSL backend
A switch that silences this process while the server it launched keeps exporting is worse than no switch, and nothing crosses wsl.exe that WSLENV does not declare. Signed-off-by: Yordis Prieto <[email protected]>
1 parent 0c1331a commit ab2824a

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,52 @@ describe("DesktopBackendConfiguration", () => {
946946
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
947947
);
948948

949+
it.effect("resolveWsl carries the kill switch into the distro", () =>
950+
Effect.gen(function* () {
951+
const fileSystem = yield* FileSystem.FileSystem;
952+
const baseDir = yield* fileSystem.makeTempDirectoryScoped({
953+
prefix: "t3-desktop-backend-config-test-",
954+
});
955+
956+
const previousWslEnv = process.env.WSLENV;
957+
const previousDisabled = process.env.OTEL_SDK_DISABLED;
958+
try {
959+
delete process.env.WSLENV;
960+
process.env.OTEL_SDK_DISABLED = "true";
961+
962+
yield* Effect.gen(function* () {
963+
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
964+
const config = yield* configuration.resolveWsl({ port: 5050, distro: null });
965+
966+
// Nothing crosses wsl.exe that WSLENV does not declare, and the
967+
// endpoints reach the backend through the bootstrap regardless, so
968+
// the switch has to travel or the server keeps exporting.
969+
assert.equal(config.env.OTEL_SDK_DISABLED, "true");
970+
assert.include((config.env.WSLENV ?? "").split(":"), "OTEL_SDK_DISABLED");
971+
}).pipe(
972+
Effect.provide(
973+
DesktopBackendConfiguration.layer.pipe(
974+
Layer.provideMerge(serverExposureLayer),
975+
Layer.provideMerge(DesktopAppSettings.layerTest()),
976+
Layer.provideMerge(DesktopWslServerTree.layerTest()),
977+
Layer.provideMerge(
978+
DesktopWslEnvironment.layerTest({
979+
isAvailable: true,
980+
windowsToWslPath: () => Option.some("/mnt/c/repo/apps/server/src/index.ts"),
981+
getDistroIp: () => Option.some("172.27.0.99"),
982+
}),
983+
),
984+
Layer.provideMerge(makeEnvironmentLayer(baseDir, { platform: "win32" })),
985+
),
986+
),
987+
);
988+
} finally {
989+
restoreEnv("WSLENV", previousWslEnv);
990+
restoreEnv("OTEL_SDK_DISABLED", previousDisabled);
991+
}
992+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
993+
);
994+
949995
it.effect("resolveWsl preserves existing WSLENV entries when forwarding backend secrets", () =>
950996
Effect.gen(function* () {
951997
const fileSystem = yield* FileSystem.FileSystem;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ const DESKTOP_BACKEND_ENV_NAMES = [
9696
const WSL_FORWARDED_ENV_NAMES = [
9797
"OPENAI_API_KEY",
9898
"ANTHROPIC_API_KEY",
99+
// The kill switch has to reach the distro under its own name. A WSL backend
100+
// reads its endpoints from the bootstrap envelope, so without these two the
101+
// switch would silence this process while the server it launched kept
102+
// exporting to a persisted endpoint, which is the one outcome nobody would
103+
// look for.
104+
"T3CODE_OTEL_SDK_DISABLED",
105+
"OTEL_SDK_DISABLED",
99106
"T3CODE_OTLP_HEADERS",
100107
"T3CODE_OTLP_PROTOCOL",
101108
] as const;

0 commit comments

Comments
 (0)