Skip to content

Commit 56db790

Browse files
LavindeepLavindeep
authored andcommitted
fix(server): identify spawned terminals as T3 Code
1 parent b0ae3f3 commit 56db790

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎apps/server/src/terminal/Manager.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import * as TestClock from "effect/testing/TestClock";
2727
import { ChildProcessSpawner } from "effect/unstable/process";
2828
import { expect } from "vite-plus/test";
2929

30+
import packageJson from "../../package.json" with { type: "json" };
3031
import * as ProcessRunner from "../processRunner.ts";
3132
import * as TerminalManager from "./Manager.ts";
3233
import * as PtyAdapter from "./PtyAdapter.ts";
@@ -1509,6 +1510,41 @@ it.layer(
15091510
}),
15101511
);
15111512

1513+
it.effect("identifies spawned terminals as T3 Code", () =>
1514+
Effect.gen(function* () {
1515+
const { manager, ptyAdapter } = yield* createManager(5, { env: {} });
1516+
1517+
yield* manager.open(openInput());
1518+
1519+
const spawnInput = ptyAdapter.spawnInputs[0];
1520+
expect(spawnInput).toBeDefined();
1521+
if (!spawnInput) return;
1522+
1523+
expect(spawnInput.env.TERM_PROGRAM).toBe("t3code");
1524+
expect(spawnInput.env.TERM_PROGRAM_VERSION).toBe(packageJson.version);
1525+
}),
1526+
);
1527+
1528+
it.effect("overrides inherited parent terminal identity", () =>
1529+
Effect.gen(function* () {
1530+
const { manager, ptyAdapter } = yield* createManager(5, {
1531+
env: {
1532+
TERM_PROGRAM: "Apple_Terminal",
1533+
TERM_PROGRAM_VERSION: "2.14",
1534+
},
1535+
});
1536+
1537+
yield* manager.open(openInput());
1538+
1539+
const spawnInput = ptyAdapter.spawnInputs[0];
1540+
expect(spawnInput).toBeDefined();
1541+
if (!spawnInput) return;
1542+
1543+
expect(spawnInput.env.TERM_PROGRAM).toBe("t3code");
1544+
expect(spawnInput.env.TERM_PROGRAM_VERSION).toBe(packageJson.version);
1545+
}),
1546+
);
1547+
15121548
it.effect("strips AppImage runtime env from terminal sessions", () =>
15131549
Effect.gen(function* () {
15141550
const appDir = "/tmp/.mount_T3Codeabc123";
@@ -1582,6 +1618,8 @@ it.layer(
15821618
T3CODE_PROJECT_ROOT: "/repo",
15831619
T3CODE_WORKTREE_PATH: "/repo/worktree-a",
15841620
CUSTOM_FLAG: "1",
1621+
TERM_PROGRAM: "custom-terminal",
1622+
TERM_PROGRAM_VERSION: "custom-version",
15851623
},
15861624
}),
15871625
);
@@ -1592,6 +1630,8 @@ it.layer(
15921630
assert.equal(spawnInput.env.T3CODE_PROJECT_ROOT, "/repo");
15931631
assert.equal(spawnInput.env.T3CODE_WORKTREE_PATH, "/repo/worktree-a");
15941632
assert.equal(spawnInput.env.CUSTOM_FLAG, "1");
1633+
assert.equal(spawnInput.env.TERM_PROGRAM, "custom-terminal");
1634+
assert.equal(spawnInput.env.TERM_PROGRAM_VERSION, "custom-version");
15951635
}),
15961636
);
15971637

‎apps/server/src/terminal/Manager.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import * as Scope from "effect/Scope";
5151
import * as Semaphore from "effect/Semaphore";
5252
import * as SynchronizedRef from "effect/SynchronizedRef";
5353

54+
import packageJson from "../../package.json" with { type: "json" };
5455
import * as ServerConfig from "../config.ts";
5556
import {
5657
increment,
@@ -1091,6 +1092,8 @@ function createTerminalSpawnEnv(
10911092
if (shouldExcludeTerminalEnvKey(key)) continue;
10921093
spawnEnv[key] = value;
10931094
}
1095+
spawnEnv.TERM_PROGRAM = "t3code";
1096+
spawnEnv.TERM_PROGRAM_VERSION = packageJson.version;
10941097
if (runtimeEnv) {
10951098
for (const [key, value] of Object.entries(runtimeEnv)) {
10961099
spawnEnv[key] = value;

0 commit comments

Comments
 (0)