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
6 changes: 5 additions & 1 deletion packages/server/src/handlers/persistent-pty.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PersistentPty } from "@opencode/core/persistent-pty"
import { PtyTicket } from "@opencode/core/pty/ticket"
import { ShellSelect } from "@opencode/core/shell/select"
import {
ForbiddenError,
InvalidRequestError,
Expand Down Expand Up @@ -62,10 +63,13 @@ export const PersistentPtyHandler = HttpApiBuilder.group(Api, "server.experiment
.handle(
"persistentPty.create",
Effect.fn(function* (ctx) {
const shell = yield* ShellSelect.Service
return {
data: yield* pty
.create(ctx.params.sessionID, {
command: ctx.payload.command,
// PersistentPty is process-global and cannot yield the Location-scoped shell
// service, so the configured shell is resolved here instead.
command: ctx.payload.command ?? (yield* shell.resolve({ priority: "config" })),
args: ctx.payload.args,
cwd: ctx.payload.cwd,
title: ctx.payload.title,
Expand Down
37 changes: 37 additions & 0 deletions packages/server/test/persistent-pty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,43 @@ smoke(
20_000,
)

smoke(
"uses the configured shell for terminals created without a command",
() =>
Effect.gen(function* () {
const fixture = yield* testDirectory()
const configured = path.join(fixture.root, "configured-shell")
yield* Effect.promise(async () => {
await fs.writeFile(configured, "#!/bin/sh\nprintf configured-shell; exec cat\n")
await fs.chmod(configured, 0o755)
})
const server = yield* ServerProcess.start<never, never>({
hostname: "127.0.0.1",
port: 0,
password: "secret",
app: { version: "test-version" },
database: { path: fixture.database },
fs: { filewatcher: false },
config: { content: JSON.stringify({ shell: configured }) },
})
const base = HttpServer.formatAddress(server.address)
const sessionID = Session.ID.make("ses_persistent_pty_configured_shell")
expect((yield* request(base, "GET", `/api/experimental/session/${sessionID}/terminal`)).data).toEqual([])
const terminal = Schema.decodeUnknownSync(PersistentPty.Info)(
(yield* request(base, "POST", `/api/experimental/session/${sessionID}/terminal`, {
args: [],
cwd: fixture.root,
title: "configured shell",
env: {},
})).data,
)
expect(terminal.command).toBe(configured)
expect(yield* waitForText(base, terminal.id, "configured-shell")).toContain("configured-shell")
yield* request(base, "DELETE", `/api/experimental/persistent-pty/${terminal.id}`)
}),
20_000,
)

smoke(
"isolates servers sharing a database and preserves terminals only through explicit restart handoff",
() =>
Expand Down
Loading