Skip to content

Commit 399f5f2

Browse files
andrewm-esynergyanduimagui
authored andcommitted
test(app): cover worktree normalization and rename desktop cmd module
Add normalizeWorktree tests for trailing separators and root paths, harden normalizeWorktree root handling, and rename the desktop CLI command module from open.ts to desktop.ts for command/file consistency.
1 parent 3e79bd8 commit 399f5f2

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, test } from "bun:test"
2+
import { normalizeWorktree } from "./server"
3+
4+
describe("normalizeWorktree", () => {
5+
test("trims and removes trailing separators", () => {
6+
expect(normalizeWorktree(" /tmp/repo/ ")).toBe("/tmp/repo")
7+
expect(normalizeWorktree("C:\\repo\\")).toBe("C:\\repo")
8+
})
9+
10+
test("keeps root separators stable", () => {
11+
expect(normalizeWorktree("/")).toBe("/")
12+
expect(normalizeWorktree("\\")).toBe("\\")
13+
})
14+
15+
test("keeps values without trailing separators", () => {
16+
expect(normalizeWorktree("/tmp/repo")).toBe("/tmp/repo")
17+
expect(normalizeWorktree("C:\\repo")).toBe("C:\\repo")
18+
})
19+
})

packages/app/src/context/server.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ function isLocalHost(url: string) {
3434
}
3535

3636
export function normalizeWorktree(input: string) {
37-
return input.trim().replace(/[\/\\]+$/, "")
37+
const value = input.trim()
38+
const next = value.replace(/[\/\\]+$/, "")
39+
if (next) return next
40+
if (value.startsWith("\\")) return "\\"
41+
if (value.startsWith("/")) return "/"
42+
return value
3843
}
3944

4045
export namespace ServerConnection {

packages/opencode/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { TuiThreadCommand } from "./cli/cmd/tui/thread"
2727
import { AcpCommand } from "./cli/cmd/acp"
2828
import { EOL } from "os"
2929
import { WebCommand } from "./cli/cmd/web"
30-
import { DesktopCommand } from "./cli/cmd/open"
30+
import { DesktopCommand } from "./cli/cmd/desktop"
3131
import { PrCommand } from "./cli/cmd/pr"
3232
import { SessionCommand } from "./cli/cmd/session"
3333
import { DbCommand } from "./cli/cmd/db"

0 commit comments

Comments
 (0)