Skip to content

Commit 3f47f52

Browse files
committed
fix(tui): only flag session location missing on LocationNotFoundError
1 parent eeec76b commit 3f47f52

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

‎packages/tui/src/context/location.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { LocationGetOutput, LocationRef } from "@opencode/client"
2+
import { isLocationNotFoundError } from "@opencode/client"
23
import { createContext, createMemo, createSignal, onCleanup, useContext, type ParentProps } from "solid-js"
34
import { useClient } from "./client"
45
import { useData } from "./data"
@@ -36,6 +37,9 @@ export function LocationProvider(props: ParentProps) {
3637
current.workspaceID !== location.workspaceID
3738
)
3839
return
40+
// Only the server's typed LocationNotFoundError proves the folder is gone.
41+
// Transient sync failures (reconnect, timeouts) must not mount recovery.
42+
if (!isLocationNotFoundError(cause)) return
3943
setError({ location, cause })
4044
})
4145
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/** @jsxImportSource @opentui/solid */
2+
import { expect, test } from "bun:test"
3+
import { testRender } from "@opentui/solid"
4+
import { ConfigProvider } from "../../../src/config"
5+
import { ClientProvider } from "../../../src/context/client"
6+
import { DataProvider, useData } from "../../../src/context/data"
7+
import { LocationProvider, useLocation } from "../../../src/context/location"
8+
import { Keymap } from "../../../src/context/keymap"
9+
import { createApi, createEventStream, createFetch, json } from "../../fixture/tui-client"
10+
import { TestTuiContexts } from "../../fixture/tui-environment"
11+
import { createTuiResolvedConfig } from "../../fixture/tui-runtime"
12+
13+
const directory = "/tmp/opencode/missing-clone"
14+
15+
test("transient location sync failure does not flag the location as missing", async () => {
16+
const fixture = await renderLocation("transient")
17+
try {
18+
fixture.location.set({ directory })
19+
await fixture.app.waitFor(() => fixture.reads.includes(directory))
20+
// Let the sync rejection settle through LocationProvider's catch.
21+
await new Promise((resolve) => setTimeout(resolve, 100))
22+
23+
expect(fixture.location.error).toBeUndefined()
24+
} finally {
25+
fixture.app.renderer.destroy()
26+
}
27+
})
28+
29+
test("typed LocationNotFoundError flags the location as missing", async () => {
30+
const fixture = await renderLocation("not-found")
31+
try {
32+
fixture.location.set({ directory })
33+
await fixture.app.waitFor(() => fixture.location.error !== undefined)
34+
35+
expect(fixture.location.error?.location.directory).toBe(directory)
36+
} finally {
37+
fixture.app.renderer.destroy()
38+
}
39+
})
40+
41+
async function renderLocation(mode: "transient" | "not-found") {
42+
const reads: string[] = []
43+
const calls = createFetch(async (url) => {
44+
if (url.pathname === "/api/location") {
45+
const requested = url.searchParams.get("location[directory]") ?? ""
46+
reads.push(requested)
47+
if (requested === directory) {
48+
if (mode === "not-found")
49+
return json(
50+
{
51+
_tag: "LocationNotFoundError",
52+
location: { directory },
53+
message: `Location not found: ${directory}`,
54+
},
55+
{ status: 404 },
56+
)
57+
return json({ message: "Location unavailable" }, { status: 503 })
58+
}
59+
}
60+
return undefined
61+
}, createEventStream())
62+
let data!: ReturnType<typeof useData>
63+
let location!: ReturnType<typeof useLocation>
64+
65+
function Probe() {
66+
data = useData()
67+
location = useLocation()
68+
return null
69+
}
70+
71+
const app = await testRender(
72+
() => (
73+
<TestTuiContexts cwd={directory}>
74+
<ConfigProvider config={createTuiResolvedConfig()}>
75+
<Keymap.Provider>
76+
<ClientProvider api={createApi(calls.fetch)}>
77+
<DataProvider directory={directory}>
78+
<LocationProvider>
79+
<Probe />
80+
</LocationProvider>
81+
</DataProvider>
82+
</ClientProvider>
83+
</Keymap.Provider>
84+
</ConfigProvider>
85+
</TestTuiContexts>
86+
),
87+
{ width: 100, height: 30, kittyKeyboard: true },
88+
)
89+
app.renderer.start()
90+
await app.waitFor(() => location !== undefined)
91+
92+
return { app, data, location, reads }
93+
}

0 commit comments

Comments
 (0)