Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: a folder added again in other letter case opens its existing workspace

ogsamrat890ca415f5cf
diff --git a/apps/server/src/routes/workspaces.ts b/apps/server/src/routes/workspaces.ts
index ade8ebb6..b7d06181 100644
--- a/apps/server/src/routes/workspaces.ts
+++ b/apps/server/src/routes/workspaces.ts
@@ -10,6 +10,7 @@ import { ensureDir, exists, shortId } from "../utils.js";
import { defaultWorkspaceOmniRushConfig, ensureWorkspaceFiles } from "../workspace-init.js";
import { seedOmniRushWorkspaceConfigIfEmpty } from "../omnirush-workspace-config-store.js";
import { workspaceIdForPath, workspaceIdForRemote } from "../workspaces.js";
+import { directoryMatchKey } from "../session-list-fallback.js";
import { addRoute, type RequestContext, type Route } from "./registry.js";
type JsonResponse = (data: unknown, status?: number) => Response;
@@ -248,14 +249,20 @@ async function persistServerWorkspaceState(config: ServerConfig): Promise<boolea
*/
export async function addLocalWorkspace(
config: ServerConfig,
- input: { folderPath: string; name: string; preset: string; actor?: RequestContext["actor"]; task?: WorkspaceInfo["task"] },
+ input: { folderPath: string; name: string; preset: string; actor?: RequestContext["actor"]; task?: WorkspaceInfo["task"]; platform?: NodeJS.Platform },
): Promise<{ workspace: WorkspaceInfo; persisted: boolean }> {
- const { name, preset } = input;
- const workspacePath = resolve(input.folderPath);
+ const { preset } = input;
+ // Another spelling of a folder already added (letter case on Windows and macOS, as a trailing slash
+ // anywhere) is that workspace: a second one for the same folder hangs its chats.
+ const requested = resolve(input.folderPath);
+ const existing = config.workspaces.find((entry) => entry.workspaceType !== "remote" && entry.path
+ && directoryMatchKey(entry.path, input.platform) === directoryMatchKey(requested, input.platform));
+ const workspacePath = existing?.path ?? requested;
+ const name = existing?.name ?? input.name;
await ensureDir(workspacePath);
await ensureWorkspaceFiles(workspacePath, preset);
- const workspaceId = workspaceIdForPath(workspacePath);
+ const workspaceId = existing?.id ?? workspaceIdForPath(workspacePath);
// Seed the per-workspace omnirush config in the runtime DB (replaces the
// legacy `.opencode/omnirush.json` file). No-op if a row already exists.
await seedOmniRushWorkspaceConfigIfEmpty(
diff --git a/apps/server/src/workspace-add-spelling.test.ts b/apps/server/src/workspace-add-spelling.test.ts
new file mode 100644
index 00000000..90f56b56
--- /dev/null
+++ b/apps/server/src/workspace-add-spelling.test.ts
@@ -0,0 +1,53 @@
+import { describe, expect, test } from "bun:test";
+import { existsSync } from "node:fs";
+import { mkdir, mkdtemp, rm } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+
+import { addLocalWorkspace } from "./routes/workspaces.js";
+import type { ServerConfig } from "./types.js";
+
+async function withConfig(fn: (root: string, config: ServerConfig) => Promise<void>) {
+ const root = await mkdtemp(join(tmpdir(), "omnirush-ws-spelling-"));
+ const previousDb = process.env.OMNIRUSH_RUNTIME_DB;
+ process.env.OMNIRUSH_RUNTIME_DB = join(root, "runtime.sqlite");
+ const config: ServerConfig = {
+ host: "127.0.0.1", port: 0, token: "token", hostToken: "host-token", configPath: join(root, "server.json"),
+ approval: { mode: "auto", timeoutMs: 0 }, corsOrigins: [], workspaces: [], authorizedRoots: [root], readOnly: false,
+ startedAt: Date.now(), tokenSource: "generated", hostTokenSource: "generated", logFormat: "pretty", logRequests: false,
+ };
+ try {
+ await fn(root, config);
+ } finally {
+ if (previousDb === undefined) delete process.env.OMNIRUSH_RUNTIME_DB;
+ else process.env.OMNIRUSH_RUNTIME_DB = previousDb;
+ await rm(root, { recursive: true, force: true });
+ }
+}
+
+describe("adding a folder already added under another spelling", () => {
+ test("macOS and Windows: a letter-case variant is the existing workspace, never a second one", async () => {
+ await withConfig(async (root, config) => {
+ const folder = join(root, "Atwo");
+ await mkdir(folder);
+ const first = await addLocalWorkspace(config, { folderPath: folder, name: "Atwo", preset: "starter", platform: "darwin" });
+ const again = await addLocalWorkspace(config, { folderPath: join(root, "ATWO"), name: "ATWO", preset: "starter", platform: "darwin" });
+ expect(again.workspace).toMatchObject({ id: first.workspace.id, path: folder, name: "Atwo" });
+ expect(config.workspaces.map((entry) => entry.id)).toEqual([first.workspace.id]);
+ expect(existsSync(join(root, "ATWO"))).toBe(false);
+ const win = await addLocalWorkspace(config, { folderPath: `${join(root, "atwo")}/`, name: "atwo", preset: "starter", platform: "win32" });
+ expect(win.workspace.id).toBe(first.workspace.id);
+ expect(config.workspaces).toHaveLength(1);
+ });
+ });
+
+ test("Linux keeps case apart; a trailing slash is the same folder everywhere", async () => {
+ await withConfig(async (root, config) => {
+ const first = await addLocalWorkspace(config, { folderPath: join(root, "Atwo"), name: "Atwo", preset: "starter", platform: "linux" });
+ expect((await addLocalWorkspace(config, { folderPath: `${join(root, "Atwo")}/`, name: "x", preset: "starter", platform: "linux" })).workspace.id).toBe(first.workspace.id);
+ const other = await addLocalWorkspace(config, { folderPath: join(root, "ATWO"), name: "ATWO", preset: "starter", platform: "linux" });
+ expect(other.workspace.id).not.toBe(first.workspace.id);
+ expect(config.workspaces).toHaveLength(2);
+ });
+ });
+});