Visitar URL original
fix(app): use project server for prompt drafts (#33850) · BenGu3/opencode@1b97d99 · GitHub
Skip to content

Commit 1b97d99

Browse files
BrendonovichBenGu3
authored andcommitted
fix(app): use project server for prompt drafts (anomalyco#33850)
1 parent 3ae828b commit 1b97d99

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

‎packages/app/src/components/prompt-input/submit.test.ts‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ const storedSessions: Record<string, Array<{ id: string; title?: string }>> = {}
2020
const promoted: Array<{ directory: string; sessionID: string }> = []
2121
const sentShell: string[] = []
2222
const syncedDirectories: string[] = []
23+
const promotedDrafts: Array<{ draftID: string; server: string; sessionId: string }> = []
2324

2425
let params: { id?: string } = {}
26+
let search: { draftId?: string } = {}
2527
let selected = "/repo/worktree-a"
2628
let variant: string | undefined
2729

@@ -79,7 +81,7 @@ beforeAll(async () => {
7981
useNavigate: () => () => undefined,
8082
useParams: () => params,
8183
useLocation: () => ({}),
82-
useSearchParams: () => [{}, () => undefined],
84+
useSearchParams: () => [search, () => undefined],
8385
}))
8486

8587
mock.module("@opencode-ai/sdk/v2/client", () => ({
@@ -129,7 +131,10 @@ beforeAll(async () => {
129131

130132
mock.module("@/context/tabs", () => ({
131133
useTabs: () => ({
132-
promoteDraft: () => undefined,
134+
draft: () => ({ server: "project-server" }),
135+
promoteDraft: (draftID: string, session: { server: string; sessionId: string }) => {
136+
promotedDrafts.push({ draftID, ...session })
137+
},
133138
}),
134139
}))
135140

@@ -234,7 +239,9 @@ beforeEach(() => {
234239
optimistic.length = 0
235240
optimisticSeeded.length = 0
236241
promoted.length = 0
242+
promotedDrafts.length = 0
237243
params = {}
244+
search = {}
238245
sentShell.length = 0
239246
syncedDirectories.length = 0
240247
selected = "/repo/worktree-a"
@@ -309,6 +316,33 @@ describe("prompt submit worktree selection", () => {
309316
expect(enabledAutoAccept).toEqual([{ sessionID: "session-1", directory: "/repo/worktree-a" }])
310317
})
311318

319+
test("promotes drafts using the selected project's server", async () => {
320+
search = { draftId: "draft-1" }
321+
const submit = createPromptSubmit({
322+
prompt,
323+
info: () => undefined,
324+
imageAttachments: () => [],
325+
commentCount: () => 0,
326+
autoAccept: () => false,
327+
mode: () => "normal",
328+
working: () => false,
329+
editor: () => undefined,
330+
queueScroll: () => undefined,
331+
promptLength: (value) => value.reduce((sum, part) => sum + ("content" in part ? part.content.length : 0), 0),
332+
addToHistory: () => undefined,
333+
resetHistoryNavigation: () => undefined,
334+
setMode: () => undefined,
335+
setPopover: () => undefined,
336+
newSessionWorktree: () => selected,
337+
onNewSessionWorktreeReset: () => undefined,
338+
onSubmit: () => undefined,
339+
})
340+
341+
await submit.handleSubmit({ preventDefault: () => undefined } as unknown as Event)
342+
343+
expect(promotedDrafts).toEqual([{ draftID: "draft-1", server: "project-server", sessionId: "session-1" }])
344+
})
345+
312346
test("includes the selected variant on optimistic prompts", async () => {
313347
params = { id: "session-1" }
314348
variant = "high"

‎packages/app/src/components/prompt-input/submit.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { base64Encode } from "@opencode-ai/core/util/encode"
44
import { Binary } from "@opencode-ai/core/util/binary"
55
import { useNavigate, useParams, useSearchParams } from "@solidjs/router"
66
import { batch, type Accessor } from "solid-js"
7-
import { useServer } from "@/context/server"
87
import { useTabs } from "@/context/tabs"
98
import { useServerSync, type ServerSync } from "@/context/server-sync"
109
import { useLanguage } from "@/context/language"
@@ -206,7 +205,6 @@ export function createPromptSubmit(input: PromptSubmitInput) {
206205
const language = useLanguage()
207206
const params = useParams()
208207
const [search] = useSearchParams<{ draftId?: string }>()
209-
const server = useServer()
210208
const tabs = useTabs()
211209
const pendingKey = (sessionID: string) => ScopedKey.from(sdk().scope, sessionID)
212210

@@ -380,7 +378,7 @@ export function createPromptSubmit(input: PromptSubmitInput) {
380378
local.session.promote(sessionDirectory, session.id)
381379
layout.handoff.setTabs(base64Encode(sessionDirectory), session.id)
382380
const draftID = search.draftId
383-
if (draftID) tabs.promoteDraft(draftID, { server: server.key, sessionId: session.id })
381+
if (draftID) tabs.promoteDraft(draftID, { server: tabs.draft(draftID).server, sessionId: session.id })
384382
else navigate(`/${base64Encode(sessionDirectory)}/session/${session.id}`)
385383
submission.retarget(prompt.capture({ dir: base64Encode(sessionDirectory), id: session.id }))
386384
}

0 commit comments

Comments
 (0)