Skip to content
Closed
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ T3 Code is a minimal web GUI for coding agents. Currently Codex-first, with Clau
npx t3
```

If you have the CLI installed or linked locally, you can open a project directly:

```bash
t3 .
t3 ../my-app
```

If the desktop app is installed, `t3` prefers opening the desktop app. If the `t3` command is missing, the desktop app can prompt you to install it globally.

You can also just install the desktop app. It's cooler.

Install the [desktop app from the Releases page](https://github.com/pingdotgg/t3code/releases)
Expand Down
136 changes: 136 additions & 0 deletions apps/desktop/src/launcherManager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import * as FS from "node:fs";
import * as OS from "node:os";
import * as Path from "node:path";

import { afterEach, describe, expect, it, vi } from "vitest";

import { getDesktopLauncherState, installDesktopLauncher } from "./launcherManager";

const TEMP_DIR_PREFIX = "t3-desktop-launcher-test-";

describe("launcherManager", () => {
let tempDir: string | null = null;

afterEach(() => {
if (tempDir) {
FS.rmSync(tempDir, { recursive: true, force: true });
tempDir = null;
}
});

function createTempDir(): string {
tempDir = FS.mkdtempSync(Path.join(OS.tmpdir(), TEMP_DIR_PREFIX));
return tempDir;
}

it("reports a missing launcher when t3 is unavailable", () => {
const homeDir = createTempDir();
const env: NodeJS.ProcessEnv = {
PATH: "",
SHELL: "/bin/zsh",
};

const state = getDesktopLauncherState({
stateDir: Path.join(homeDir, "state"),
executablePath: "/tmp/T3 Code",
serverEntryPath: "/tmp/server/index.mjs",
env,
platform: "darwin",
homeDir,
shell: env.SHELL,
});

expect(state.status).toBe("missing");
expect(state.installDir).toBe(Path.join(homeDir, ".t3", "bin"));
expect(state.pathConfigured).toBe(false);
});

it("installs the managed launcher and keeps a needs-path status until PATH is updated", () => {
const homeDir = createTempDir();
const stateDir = Path.join(homeDir, "state");
const env: NodeJS.ProcessEnv = {
PATH: "",
SHELL: "/bin/zsh",
};

const result = installDesktopLauncher({
stateDir,
executablePath: "/Applications/T3 Code.app/Contents/MacOS/T3 Code",
serverEntryPath:
"/Applications/T3 Code.app/Contents/Resources/app/apps/server/dist/index.mjs",
updatePath: false,
env,
platform: "darwin",
homeDir,
shell: env.SHELL,
});

expect(result.completed).toBe(true);
expect(result.state.status).toBe("needs-path");
expect(FS.existsSync(result.state.launcherPath)).toBe(true);
expect(FS.statSync(result.state.launcherPath).mode & 0o111).not.toBe(0);
});

it("updates the shell profile and current PATH when the user allows PATH changes", () => {
const homeDir = createTempDir();
const stateDir = Path.join(homeDir, "state");
const env: NodeJS.ProcessEnv = {
PATH: "",
SHELL: "/bin/zsh",
};

const execFileSync = vi.fn() as unknown as typeof import("node:child_process").execFileSync;
const result = installDesktopLauncher({
stateDir,
executablePath: "/Applications/T3 Code.app/Contents/MacOS/T3 Code",
serverEntryPath:
"/Applications/T3 Code.app/Contents/Resources/app/apps/server/dist/index.mjs",
updatePath: true,
env,
platform: "darwin",
homeDir,
shell: env.SHELL,
execFileSync,
});

expect(result.completed).toBe(true);
expect(result.state.status).toBe("installed");
expect(env.PATH?.startsWith(Path.join(homeDir, ".t3", "bin"))).toBe(true);
expect(FS.readFileSync(Path.join(homeDir, ".zprofile"), "utf8")).toContain(
'export PATH="',
);
expect(execFileSync).not.toHaveBeenCalled();
});

it("installs into an existing writable PATH directory when one is available", () => {
const homeDir = createTempDir();
const localBinDir = Path.join(homeDir, ".local", "bin");
FS.mkdirSync(localBinDir, { recursive: true });
const stateDir = Path.join(homeDir, "state");
const env: NodeJS.ProcessEnv = {
PATH: `${localBinDir}:/usr/local/bin`,
SHELL: "/bin/zsh",
};

const result = installDesktopLauncher({
stateDir,
executablePath: "/Applications/T3 Code.app/Contents/MacOS/T3 Code",
serverEntryPath:
"/Applications/T3 Code.app/Contents/Resources/app/apps/server/dist/index.mjs",
updatePath: false,
env,
platform: "darwin",
homeDir,
shell: env.SHELL,
});

expect(result.completed).toBe(true);
expect(result.state.status).toBe("installed");
expect(result.state.launcherPath).toBe(Path.join(localBinDir, "t3"));
const legacyLauncherPath = Path.join(homeDir, ".t3", "bin", "t3");
expect(FS.existsSync(legacyLauncherPath)).toBe(true);
expect(FS.readFileSync(legacyLauncherPath, "utf8")).toContain(
`exec '${Path.join(localBinDir, "t3")}' "$@"`,
);
});
});
Loading