Skip to content
Draft
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
36 changes: 36 additions & 0 deletions apps/server/src/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import {
BrowserTraceCollector,
type BrowserTraceCollectorShape,
} from "./observability/Services/BrowserTraceCollector.ts";
import { resolveCurrentShell } from "./terminal/terminalProfile.ts";
import { ProjectFaviconResolverLive } from "./project/Layers/ProjectFaviconResolver.ts";
import {
ProjectSetupScriptRunner,
Expand Down Expand Up @@ -1848,6 +1849,12 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
assert.equal(first.config.observability.otlpTracesEnabled, true);
assert.equal(first.config.observability.otlpMetricsUrl, "http://localhost:4318/v1/metrics");
assert.equal(first.config.observability.otlpMetricsEnabled, true);
assert.equal(first.config.terminal.platform, process.platform);
assert.equal(
first.config.terminal.currentShell,
resolveCurrentShell(process.platform, process.env),
);
assert.isTrue(Array.isArray(first.config.terminal.discoveredShells));
assert.deepEqual(first.config.settings, DEFAULT_SERVER_SETTINGS);
}
assert.deepEqual(second, {
Expand All @@ -1858,6 +1865,35 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
);

it.effect("routes websocket rpc serverGetConfig with terminal discovery", () =>
Effect.gen(function* () {
yield* buildAppUnderTest({
layers: {
keybindings: {
loadConfigState: Effect.succeed({
keybindings: [],
issues: [],
}),
streamChanges: Stream.empty,
},
},
});

const wsUrl = yield* getWsServerUrl("/ws");
const response = yield* Effect.scoped(
withWsRpcClient(wsUrl, (client) => client[WS_METHODS.serverGetConfig]({})),
);

assert.equal(response.terminal.platform, process.platform);
assert.equal(
response.terminal.currentShell,
resolveCurrentShell(process.platform, process.env),
);
assert.isTrue(Array.isArray(response.terminal.discoveredShells));
assert.deepEqual(response.settings, DEFAULT_SERVER_SETTINGS);
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
);

it.effect("routes websocket rpc subscribeServerConfig emits provider status updates", () =>
Effect.gen(function* () {
const nextProviders = [
Expand Down
60 changes: 60 additions & 0 deletions apps/server/src/serverSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ it.layer(NodeServices.layer)("server settings", (it) => {
},
},
);

assert.deepEqual(
decodePatch({
terminal: {
profile: {
shellPath: "/bin/zsh",
shellArgs: ["-f"],
},
},
}),
{
terminal: {
profile: {
shellPath: "/bin/zsh",
shellArgs: ["-f"],
},
},
},
);
}),
);

Expand Down Expand Up @@ -211,6 +230,47 @@ it.layer(NodeServices.layer)("server settings", (it) => {
}).pipe(Effect.provide(makeServerSettingsLayer())),
);

it.effect("writes terminal profile overrides without serializing default values", () =>
Effect.gen(function* () {
const serverSettings = yield* ServerSettingsService;
const serverConfig = yield* ServerConfig;
const fileSystem = yield* FileSystem.FileSystem;

const next = yield* serverSettings.updateSettings({
terminal: {
profile: {
shellPath: "/bin/zsh",
shellArgs: ["-f"],
env: {
ZDOTDIR: "/tmp/t3code-zsh",
},
},
},
});

assert.deepEqual(next.terminal.profile, {
shellPath: "/bin/zsh",
shellArgs: ["-f"],
env: {
ZDOTDIR: "/tmp/t3code-zsh",
},
});

const raw = yield* fileSystem.readFileString(serverConfig.settingsPath);
assert.deepEqual(JSON.parse(raw), {
terminal: {
profile: {
shellPath: "/bin/zsh",
shellArgs: ["-f"],
env: {
ZDOTDIR: "/tmp/t3code-zsh",
},
},
},
});
}).pipe(Effect.provide(makeServerSettingsLayer())),
);

it.effect("writes only non-default server settings to disk", () =>
Effect.gen(function* () {
const serverSettings = yield* ServerSettingsService;
Expand Down
40 changes: 40 additions & 0 deletions apps/server/src/terminal/Layers/Manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DEFAULT_TERMINAL_ID,
type TerminalEvent,
type TerminalOpenInput,
type TerminalProfileSettings,
type TerminalRestartInput,
} from "@t3tools/contracts";
import {
Expand Down Expand Up @@ -188,6 +189,7 @@ function multiTerminalHistoryLogPath(

interface CreateManagerOptions {
shellResolver?: () => string;
terminalProfileResolver?: Effect.Effect<TerminalProfileSettings>;
subprocessChecker?: (terminalPid: number) => Effect.Effect<boolean>;
subprocessPollIntervalMs?: number;
processKillGraceMs?: number;
Expand Down Expand Up @@ -222,6 +224,9 @@ const createManager = (
historyLineLimit,
ptyAdapter,
...(options.shellResolver !== undefined ? { shellResolver: options.shellResolver } : {}),
...(options.terminalProfileResolver !== undefined
? { terminalProfileResolver: options.terminalProfileResolver }
: {}),
...(options.subprocessChecker !== undefined
? { subprocessChecker: options.subprocessChecker }
: {}),
Expand Down Expand Up @@ -323,6 +328,41 @@ it.layer(NodeServices.layer, { excludeTestServices: true })("TerminalManager", (
}),
);

it.effect("spawns terminals with the configured shell profile", () =>
Effect.gen(function* () {
const { manager, ptyAdapter } = yield* createManager(5, {
shellResolver: () => "/bin/bash",
terminalProfileResolver: Effect.succeed({
shellPath: "/bin/zsh",
shellArgs: ["-f"],
env: {
ZDOTDIR: "/tmp/t3code-zdotdir",
PATH: "/opt/t3/bin",
},
}),
});

yield* manager.open(
openInput({
env: {
PATH: "/workspace/bin",
CUSTOM_FLAG: "1",
},
}),
);

const spawned = ptyAdapter.spawnInputs[0];
expect(spawned).toBeDefined();
if (!spawned) return;

expect(spawned.shell).toBe("/bin/zsh");
expect(spawned.args).toEqual(["-f"]);
expect(spawned.env.ZDOTDIR).toBe("/tmp/t3code-zdotdir");
expect(spawned.env.PATH).toBe("/workspace/bin");
expect(spawned.env.CUSTOM_FLAG).toBe("1");
}),
);

it.effect("forwards write and resize to active pty process", () =>
Effect.gen(function* () {
const { manager, ptyAdapter } = yield* createManager();
Expand Down
Loading
Loading