Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions apps/desktop/src/app/DesktopEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ export class DesktopEnvironment extends Context.Service<
readonly otlpProtocol: OtlpProtocol;
readonly branding: DesktopAppBranding;
readonly displayName: string;
/** Set only by a renamed build; the backend names its environment after it. */
readonly displayNameOverride: Option.Option<string>;
readonly appUserModelId: string;
readonly linuxDesktopEntryName: string;
readonly linuxApplicationsDir: string;
Expand Down Expand Up @@ -233,7 +231,6 @@ const make = Effect.fn("desktop.environment.make")(function* (
otlpProtocol: config.otlpProtocol,
branding,
displayName,
displayNameOverride: config.displayNameOverride,
appUserModelId: Option.getOrElse(config.appUserModelIdOverride, () =>
isDevelopment ? "com.t3tools.t3code.dev" : "com.t3tools.t3code",
),
Expand Down
32 changes: 0 additions & 32 deletions apps/desktop/src/backend/DesktopBackendConfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ function layerEnvironment(
readonly otlpTracesUrl?: string;
readonly otlpMetricsUrl?: string;
readonly otlpLogsUrl?: string;
readonly displayNameOverride?: string;
},
) {
return DesktopEnvironment.layer({
Expand All @@ -95,7 +94,6 @@ function layerEnvironment(
T3CODE_OTLP_TRACES_URL: options?.otlpTracesUrl,
T3CODE_OTLP_METRICS_URL: options?.otlpMetricsUrl,
T3CODE_OTLP_LOGS_URL: options?.otlpLogsUrl,
T3CODE_DESKTOP_DISPLAY_NAME: options?.displayNameOverride,
}),
),
),
Expand Down Expand Up @@ -256,8 +254,6 @@ describe("DesktopBackendConfiguration", () => {
assert.equal(first.bootstrap.t3Home, environment.baseDir);
assert.equal(first.bootstrap.tailscaleServeEnabled, true);
assert.equal(first.bootstrap.tailscaleServePort, 8443);
// A build without a display-name override lets the server name itself as before.
assert.isFalse("environmentLabel" in first.bootstrap);
assert.match(first.bootstrap.desktopBootstrapSecret ?? "", /^[0-9a-f]{64}$/i);
assert.equal(
second.bootstrap.desktopBootstrapSecret,
Expand Down Expand Up @@ -324,34 +320,6 @@ describe("DesktopBackendConfiguration", () => {
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
);

it.effect("resolvePrimary names the environment after a renamed build's display name", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const baseDir = yield* fileSystem.makeTempDirectoryScoped({
prefix: "t3-desktop-backend-config-test-",
});

const config = yield* Effect.gen(function* () {
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
return yield* configuration.resolvePrimary;
}).pipe(
Effect.provide(
layerBackendConfiguration().pipe(
Layer.provideMerge(layerServerExposure),
Layer.provideMerge(DesktopAppSettings.layerTest()),
Layer.provideMerge(DesktopWslEnvironment.layerTest()),
Layer.provideMerge(DesktopWslServerTree.layerTest()),
Layer.provideMerge(
layerEnvironment(baseDir, { displayNameOverride: "T3 Code Custom" }),
),
),
),
);

assert.equal(config.bootstrap.environmentLabel, "T3 Code Custom");
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
);

it.effect("resolveWsl pins a default-tracking run to the concrete default distro", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
Expand Down
4 changes: 0 additions & 4 deletions apps/desktop/src/backend/DesktopBackendConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,6 @@ const resolvePrimaryStartConfig = Effect.fn("desktop.backendConfiguration.resolv
onSome: (resourceMonitorPath) => ({ resourceMonitorPath }),
}),
...buildObservabilityFragment(input.observabilitySettings),
...Option.match(environment.displayNameOverride, {
onNone: () => ({}),
onSome: (environmentLabel) => ({ environmentLabel }),
}),
};

return {
Expand Down
31 changes: 0 additions & 31 deletions apps/server/src/cli/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,37 +543,6 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
}),
);

it.effect("names the environment after the desktop's display name only when it sends one", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-cli-config-label-" });
const resolveWith = (bootstrap: DesktopBackendBootstrapValue) =>
openBootstrapFd(bootstrap).pipe(
Effect.flatMap((fd) =>
resolveServerConfig(
{ ...minimalDesktopFlags(baseDir), bootstrapFd: Option.some(fd) },
Option.none(),
),
),
Effect.provide(
Layer.mergeAll(
ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })),
NetService.layer,
),
),
);

const renamed = yield* resolveWith(
makeDesktopBootstrap({ environmentLabel: "T3 Code Custom" }),
);
const plain = yield* resolveWith(makeDesktopBootstrap());

assert.strictEqual(renamed.environmentLabel, "T3 Code Custom");
assert.isUndefined(plain.environmentLabel);
assert.isFalse("environmentLabel" in plain);
}),
);

it.effect("reports saved settings as the source of endpoints read from settings.json", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
Expand Down
2 changes: 0 additions & 2 deletions apps/server/src/cli/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ export const resolveServerConfig = Effect.fn("config.resolveServerConfig")(funct
const desktopBrowserFd = bootstrap?.desktopBrowserFd;
const desktopBrowserControlFd = bootstrap?.desktopBrowserControlFd;
const resourceMonitorPath = bootstrap?.resourceMonitorPath;
const environmentLabel = bootstrap?.environmentLabel;
const autoBootstrapProjectFromCwd = Option.getOrElse(
resolveOptionPrecedence(
Option.fromUndefinedOr(options?.forceAutoBootstrapProjectFromCwd),
Expand Down Expand Up @@ -524,7 +523,6 @@ export const resolveServerConfig = Effect.fn("config.resolveServerConfig")(funct
desktopBootstrapToken,
...(desktopBootstrapSecret === undefined ? {} : { desktopBootstrapSecret }),
...(shellEnvironmentPrepared === undefined ? {} : { shellEnvironmentPrepared }),
...(environmentLabel === undefined ? {} : { environmentLabel }),
desktopTelemetryFd,
desktopTelemetryControlFd,
...(desktopAppUpdate === undefined ? {} : { desktopAppUpdate }),
Expand Down
2 changes: 0 additions & 2 deletions apps/server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ export class ServerConfig extends Context.Service<
readonly desktopBrowserFd?: number | undefined;
readonly desktopBrowserControlFd?: number | undefined;
readonly resourceMonitorPath?: string | undefined;
/** The desktop's display name, sent only by renamed builds; names this environment. */
readonly environmentLabel?: string | undefined;
readonly autoBootstrapProjectFromCwd: boolean;
readonly logWebSocketEvents: boolean;
readonly tailscaleServeEnabled: boolean;
Expand Down
1 change: 0 additions & 1 deletion apps/server/src/environment/ServerEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ export const make = Effect.gen(function* () {
const label = yield* resolveServerEnvironmentLabel({
cwdBaseName,
baseDir: serverConfig.baseDir,
displayName: serverConfig.environmentLabel,
});
const machine = yield* detectServerEnvironmentMachineKind();
const launcher = yield* resolveServiceLauncherMode();
Expand Down
28 changes: 28 additions & 0 deletions apps/server/src/environment/ServerEnvironmentLabel.sandbox.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as NodeServices from "@effect/platform-node/NodeServices";
import { expect, it } from "@effect/vitest";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as Path from "effect/Path";

import * as ProcessRunner from "../processRunner.ts";
import { resolveServerEnvironmentLabel } from "./ServerEnvironmentLabel.ts";

const TestLayer = Layer.mergeAll(
NodeServices.layer,
ProcessRunner.layer.pipe(Layer.provide(NodeServices.layer)),
);

it.effect("prefers the label provisioning writes into the base directory", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const baseDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-label-" });
yield* fileSystem.writeFileString(path.join(baseDir, "environment-label"), " Boat sandbox\n");

// No sudo, systemd, or writable /etc is needed for this path, which is why provisioning uses it.
const label = yield* resolveServerEnvironmentLabel({ cwdBaseName: "workspace", baseDir });

expect(label).toBe("Boat sandbox");
}).pipe(Effect.provide(TestLayer)),
);
90 changes: 5 additions & 85 deletions apps/server/src/environment/ServerEnvironmentLabel.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import * as NodeServices from "@effect/platform-node/NodeServices";
import { assert, expect, it } from "@effect/vitest";
import { assert, it } from "@effect/vitest";
import * as HostProcess from "@t3tools/shared/HostProcess";
import * as Effect from "effect/Effect";
import * as Fiber from "effect/Fiber";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as Path from "effect/Path";
import * as Sink from "effect/Sink";
import * as Stream from "effect/Stream";
import * as TestClock from "effect/testing/TestClock";
Expand Down Expand Up @@ -41,7 +39,6 @@ it.effect("falls back to the hostname when hostnamectl never answers", () =>
Effect.provide(
Layer.mergeAll(
FileSystem.layerNoop({ exists: () => Effect.succeed(false) }),
Path.layer,
ProcessRunner.layer.pipe(
Layer.provide(Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, neverExits)),
),
Expand Down Expand Up @@ -94,90 +91,13 @@ it.effect("qualifies the inherited Windows hostname only inside WSL", () =>
Effect.provideService(HostProcess.Environment, { WSL_DISTRO_NAME: "Ubuntu" }),
Effect.provideService(ProcessRunner.ProcessRunner, exitsWithFailure),
Effect.provide(
Layer.mergeAll(
FileSystem.layerNoop({
exists: (path) => Effect.succeed(files[path] != null),
readFileString: (path) => Effect.succeed(files[path] ?? ""),
}),
Path.layer,
),
FileSystem.layerNoop({
exists: (path) => Effect.succeed(files[path] != null),
readFileString: (path) => Effect.succeed(files[path] ?? ""),
}),
),
);
assert.equal(label, expected, kernel);
}
}),
);

const TestLayer = Layer.mergeAll(
NodeServices.layer,
ProcessRunner.layer.pipe(Layer.provide(NodeServices.layer)),
);

it.effect("prefers the label provisioning writes into the base directory", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const baseDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-label-" });
yield* fileSystem.writeFileString(path.join(baseDir, "environment-label"), " Boat sandbox\n");

// No sudo, systemd, or writable /etc is needed for this path, which is why provisioning uses it.
const label = yield* resolveServerEnvironmentLabel({ cwdBaseName: "workspace", baseDir });

expect(label).toBe("Boat sandbox");
}).pipe(Effect.provide(TestLayer)),
);

it.effect("uses the desktop's display name ahead of the computer name", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const baseDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-label-" });

// A renamed side-by-side build would otherwise share the computer name with the official app.
const label = yield* resolveServerEnvironmentLabel({
cwdBaseName: "workspace",
baseDir,
displayName: " T3 Code Custom ",
});

expect(label).toBe("T3 Code Custom");
}).pipe(Effect.provide(TestLayer)),
);

it.effect("keeps the provisioned label file ahead of the desktop's display name", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const baseDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-label-" });
yield* fileSystem.writeFileString(path.join(baseDir, "environment-label"), "Boat sandbox\n");

const label = yield* resolveServerEnvironmentLabel({
cwdBaseName: "workspace",
baseDir,
displayName: "T3 Code Custom",
});

expect(label).toBe("Boat sandbox");
}).pipe(Effect.provide(TestLayer)),
);

it.effect("falls back to the host name when no display name is set or it is blank", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const baseDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-label-" });

const withoutName = yield* resolveServerEnvironmentLabel({ cwdBaseName: "workspace", baseDir });
const blankName = yield* resolveServerEnvironmentLabel({
cwdBaseName: "workspace",
baseDir,
displayName: " ",
});

expect(withoutName).toBe("omars-macbook-pro");
expect(blankName).toBe("omars-macbook-pro");
}).pipe(
// No friendly-name probe runs off macOS and Linux, so the host name decides.
Effect.provideService(HostProcess.Platform, "freebsd"),
Effect.provideService(HostProcess.Hostname, "omars-macbook-pro"),
Effect.provide(TestLayer),
),
);
13 changes: 2 additions & 11 deletions apps/server/src/environment/ServerEnvironmentLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ import * as HostProcess from "@t3tools/shared/HostProcess";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Option from "effect/Option";
import * as Path from "effect/Path";
import * as Schema from "effect/Schema";

import * as ProcessRunner from "../processRunner.ts";

interface ResolveServerEnvironmentLabelInput {
readonly cwdBaseName: string;
/** Explicit label file directory. Provisioned sandboxes write `environment-label` here. */
/** T3 home. Provisioned sandboxes and renamed desktop builds write `environment-label` here. */
readonly baseDir?: string;
/** The name a renamed desktop build (such as t3code-diy's side-by-side app) gives itself. */
readonly displayName?: string | undefined;
}

const ServerEnvironmentLabelCommandProbe = Schema.Literals([
Expand Down Expand Up @@ -204,8 +201,7 @@ const isWsl = Effect.fn("isWsl")(function* () {
*/
const readConfiguredLabel = Effect.fn("readConfiguredLabel")(function* (baseDir: string) {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const labelPath = path.join(baseDir, "environment-label");
const labelPath = `${baseDir}/environment-label`;
const exists = yield* fileSystem.exists(labelPath).pipe(Effect.orElseSucceed(() => false));
if (!exists) return null;
return yield* fileSystem.readFileString(labelPath).pipe(
Expand All @@ -228,11 +224,6 @@ export const resolveServerEnvironmentLabel = Effect.fn("resolveServerEnvironment
}
}

const displayName = normalizeLabel(input.displayName);
if (displayName) {
return displayName;
}

const friendlyHostLabel = yield* resolveFriendlyHostLabel();
if (friendlyHostLabel) {
return friendlyHostLabel;
Expand Down
45 changes: 45 additions & 0 deletions apps/server/src/http.sandbox.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as NodeServices from "@effect/platform-node/NodeServices";
import { expect, it } from "@effect/vitest";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import { HttpRouter, HttpServerResponse } from "effect/http";
import { describe } from "vite-plus/test";

import * as ServerConfig from "./config.ts";
import * as ServerHttp from "./http.ts";

describe("browser API CORS behind a sandbox proxy", () => {
it("adds no CORS headers when the proxy in front answers CORS", async () => {
const layerRoute = Layer.effectDiscard(
Effect.gen(function* () {
const router = yield* HttpRouter.HttpRouter;
yield* router.add("GET", "/api/environment", HttpServerResponse.empty());
}),
);
const layerProxyConfig = Layer.effect(
ServerConfig.ServerConfig,
Effect.gen(function* () {
const config = yield* ServerConfig.ServerConfig;
return { ...config, proxyHandlesCors: true };
}),
).pipe(Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "http-cors-proxy-" })));
const layerApp = Layer.merge(layerRoute, ServerHttp.layerBrowserApiCors).pipe(
Layer.provide(layerProxyConfig),
Layer.provide(NodeServices.layer),
);
const { handler, dispose } = HttpRouter.toWebHandler(layerApp, { disableLogger: true });

try {
const response = await handler(
new Request("https://backend.example/api/environment", {
headers: { origin: "https://app.t3.codes" },
}),
);

// Daytona's proxy adds the origin it echoes; a second value here would fail the request.
expect(response.headers.get("access-control-allow-origin")).toBeNull();
} finally {
await dispose();
}
});
});
Loading