mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 05:26:47 +03:00
fix(tui): mount each dialog once so /fork shows its pending view (#55751)
This commit is contained in:
committed by
GitHub
Unverified
parent
a58d1dd924
commit
22dea2453b
@@ -225,7 +225,7 @@ function DialogFooterItem(props: { action: DialogFooterAction }) {
|
||||
function init() {
|
||||
const [store, setStore] = createStore({
|
||||
stack: [] as {
|
||||
element: JSX.Element
|
||||
element: () => JSX.Element
|
||||
onClose?: () => void
|
||||
key?: unknown
|
||||
}[],
|
||||
@@ -316,7 +316,7 @@ function init() {
|
||||
})
|
||||
refocus()
|
||||
},
|
||||
replace(input: any, onClose?: () => void, options?: { key?: unknown; size?: DialogSize }) {
|
||||
replace(input: () => JSX.Element, onClose?: () => void, options?: { key?: unknown; size?: DialogSize }) {
|
||||
if (store.stack.length === 0) {
|
||||
focus = renderer.currentFocusedRenderable
|
||||
focus?.blur()
|
||||
@@ -390,7 +390,11 @@ export function DialogProvider(props: ParentProps) {
|
||||
>
|
||||
<Show when={value.stack.length}>
|
||||
<Dialog onClose={() => value.clear()} size={value.size} centered={value.centered}>
|
||||
{value.stack.at(-1)!.element}
|
||||
{/* Render each entry once: inserting the element function directly would re-run it, remounting
|
||||
the dialog with fresh state, whenever a signal it reads at its root (e.g. a top-level <Show>) changes. */}
|
||||
<Show when={value.stack.at(-1)} keyed>
|
||||
{(item) => item.element()}
|
||||
</Show>
|
||||
</Dialog>
|
||||
</Show>
|
||||
</box>
|
||||
|
||||
@@ -35,7 +35,7 @@ for (const width of [40, 100]) {
|
||||
route = useRoute()
|
||||
const dialog = useDialog()
|
||||
onMount(() =>
|
||||
dialog.replace(
|
||||
dialog.replace(() => (
|
||||
<DialogErrorDetails
|
||||
title="Server plugin error"
|
||||
source={source}
|
||||
@@ -43,8 +43,8 @@ for (const width of [40, 100]) {
|
||||
context={`Plugin: broken\nRuntime: server\nSource: ${source}`}
|
||||
diagnosticRef="err_a1b2c3d4"
|
||||
onBack={() => dialog.clear()}
|
||||
/>,
|
||||
),
|
||||
/>
|
||||
)),
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { expect, test } from "bun:test"
|
||||
import { createAppFixture } from "./fixture/app"
|
||||
import { directory, json } from "./fixture/tui-client"
|
||||
|
||||
const session = {
|
||||
id: "ses_fork_pending",
|
||||
title: "Fork pending",
|
||||
projectID: "proj_test",
|
||||
location: { directory },
|
||||
cost: 0,
|
||||
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
||||
time: { created: 0, updated: 0 },
|
||||
}
|
||||
const messages = [
|
||||
{
|
||||
type: "assistant",
|
||||
id: "msg_b",
|
||||
agent: "build",
|
||||
model: { providerID: "fixture", id: "fixture" },
|
||||
finish: "stop",
|
||||
time: { created: 2, completed: 3 },
|
||||
content: [{ type: "text", text: "First answer" }],
|
||||
},
|
||||
{ type: "user", id: "msg_a", text: "First prompt", time: { created: 1 } },
|
||||
]
|
||||
|
||||
test("choosing a row in /fork shows the pending view until the fork finishes", async () => {
|
||||
const fork = Promise.withResolvers<Response>()
|
||||
const requested = Promise.withResolvers<void>()
|
||||
await using setup = await createAppFixture({
|
||||
width: 112,
|
||||
height: 34,
|
||||
config: { animations: false, tabs: { enabled: false } },
|
||||
args: { sessionID: session.id },
|
||||
fetch: (url) => {
|
||||
if (url.pathname === "/api/session") return json({ data: [session], cursor: {} })
|
||||
if (url.pathname === `/api/session/${session.id}`) return json({ data: session })
|
||||
if (url.pathname === `/api/session/${session.id}/fork`) {
|
||||
requested.resolve()
|
||||
return fork.promise
|
||||
}
|
||||
if (/^\/api\/session\/ses_fork_pending\/(message|inbox|permission)$/.test(url.pathname))
|
||||
return json({ data: url.pathname.endsWith("/message") ? messages : [], cursor: {} })
|
||||
return undefined
|
||||
},
|
||||
})
|
||||
|
||||
try {
|
||||
await setup.waitForFrame((frame) => frame.includes("First answer"))
|
||||
await setup.mockInput.typeText("/fork")
|
||||
setup.mockInput.pressEnter()
|
||||
await setup.waitForFrame((frame) => frame.includes("Fork session") && frame.includes("Full session"))
|
||||
setup.mockInput.pressEnter()
|
||||
await requested.promise
|
||||
await setup.waitForFrame((frame) => frame.includes("Forking session") && !frame.includes("Full session"))
|
||||
expect(setup.captureCharFrame()).toContain("Fork session")
|
||||
} finally {
|
||||
fork.resolve(new Response(null, { status: 500 }))
|
||||
}
|
||||
}, 20000)
|
||||
Reference in New Issue
Block a user