Skip to content

Commit 4317ece

Browse files
fix(workspace): /integrations reads the link again after the engine check
The engine check can take seconds; a relink or an account switch meanwhile could put the previous link's attach on screen. Read the link again before opening the Status view. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HRUhVhg6XwxSKJs1iTufiA
1 parent b0ad5e1 commit 4317ece

2 files changed

Lines changed: 41 additions & 21 deletions

File tree

‎packages/opencode/src/plugin/tui/altimate/workspace.tsx‎

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,36 +2439,41 @@ async function readLink(directory: string) {
24392439
return { report, bound }
24402440
}
24412441

2442+
/** `/integrations` in an unlinked project: integrations come from a link, so offer one. */
2443+
function showNotLinked(api: TuiPluginApi, directory: string): void {
2444+
replaceOwnedDialog(api, () => (
2445+
<api.ui.DialogSelect
2446+
title="Integrations come from a linked workspace"
2447+
options={[
2448+
{ title: "Link to a workspace", value: "link", description: "This project isn't linked yet." },
2449+
{ title: "Done", value: "done", description: "Close this view." },
2450+
]}
2451+
current="link"
2452+
onSelect={(option) => {
2453+
if (option.value === "link") {
2454+
runOnDemandPicker(api, directory).catch((err) => reportFlowFailure(api, err))
2455+
return
2456+
}
2457+
api.ui.dialog.clear()
2458+
}}
2459+
/>
2460+
))
2461+
}
2462+
24422463
/** `/integrations`: the Status view straight away, or why it has nothing to
24432464
* show. Unlinked, it offers the link. With the engine missing or too old it
24442465
* opens the install offer, which says which, instead of the last attach: that
24452466
* attach no longer describes what a session here gets. */
24462467
export async function runIntegrations(api: TuiPluginApi, directory: string): Promise<void> {
2447-
const { report, bound } = await readLink(directory)
2448-
if (!report.binding || !bound) {
2449-
replaceOwnedDialog(api, () => (
2450-
<api.ui.DialogSelect
2451-
title="Integrations come from a linked workspace"
2452-
options={[
2453-
{ title: "Link to a workspace", value: "link", description: "This project isn't linked yet." },
2454-
{ title: "Done", value: "done", description: "Close this view." },
2455-
]}
2456-
current="link"
2457-
onSelect={(option) => {
2458-
if (option.value === "link") {
2459-
runOnDemandPicker(api, directory).catch((err) => reportFlowFailure(api, err))
2460-
return
2461-
}
2462-
api.ui.dialog.clear()
2463-
}}
2464-
/>
2465-
))
2466-
return
2467-
}
2468+
if (!(await readLink(directory)).bound) return showNotLinked(api, directory)
24682469
if (await describeOffer(directory)) {
24692470
await showEngineInstallOffer(api, { onDemand: true })
24702471
return
24712472
}
2473+
// The engine check can take seconds: read the link again, so a relink or an
2474+
// account switch meanwhile cannot put the previous link's attach on screen.
2475+
const { bound } = await readLink(directory)
2476+
if (!bound) return showNotLinked(api, directory)
24722477
const reading = replaceOwnedDialog(api, () => (
24732478
<api.ui.DialogSelect
24742479
title="Integrations"

‎packages/opencode/test/altimate/plugin/workspace.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,21 @@ describe("/integrations", () => {
11691169
expect(h.toasts.join(" ")).toContain("still installing")
11701170
})
11711171

1172+
test("a relink during the engine check shows the new link's attach, not the old one's", async () => {
1173+
// The first read sees workspace 42; by the time the engine check is done the project is linked to 43.
1174+
spies.push(
1175+
spyOn(Manage, "status")
1176+
.mockResolvedValueOnce({ binding } as any)
1177+
.mockResolvedValue({ binding: { datamateId: 43, datamateName: "marketing" } } as any),
1178+
)
1179+
engine("0.7.3")
1180+
const read = statusRead()
1181+
const { tui } = harness()
1182+
await runIntegrations(tui, os.tmpdir())
1183+
expect(read).toHaveBeenCalledTimes(1)
1184+
expect(read.mock.calls[0]![1]).toMatchObject({ datamateId: 43 })
1185+
})
1186+
11721187
test("a usable engine opens the Status view", async () => {
11731188
linked(binding)
11741189
engine("0.7.3")

0 commit comments

Comments
 (0)