Skip to content

Commit be82af1

Browse files
authored
fix(tui): install server-listed plugins in the client cache
Fix split-cache TUI loading for anomalyco#55084. Local sources remain resolve-only. Add real Git/Npm/TUI regression tests for empty and populated client caches. AI-assisted; 131 focused plugin/lifecycle tests pass. TUI typecheck passes with constrained Go memory settings. Full lint/typechecks remain blocked and are documented in the draft PR.
1 parent c1615b1 commit be82af1

3 files changed

Lines changed: 101 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ export function PluginProvider(props: ParentProps<{ packages: PackageSource; dir
300300
})),
301301
...serverTuiPlugins().map((plugin) => ({
302302
entry: plugin.source.type === "package" ? plugin.source.target : path.dirname(plugin.source.path),
303-
install: false,
303+
// A remote server or different environment may not share this TUI cache.
304+
install: plugin.source.type === "package",
304305
optional: true,
305306
})),
306307
...(config.data.plugins ?? []).map((entry) => ({ entry, install: true, optional: false })),

‎packages/tui/test/fixture/app.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export async function createAppFixture(
1313
height?: number
1414
state?: string
1515
config?: Config.Info
16+
packages?: TuiInput["packages"]
1617
args?: TuiInput["args"]
1718
fetch?: FetchHandler
1819
} = {},
@@ -35,7 +36,7 @@ export async function createAppFixture(
3536
app: { name: "test", version: "test", channel: "test" },
3637
server: { endpoint: { url: server.url.toString() } },
3738
config: { get: async () => input.config ?? { animations: false }, update: async () => ({}) },
38-
packages: { prepare: async () => ({ directory: "" }) },
39+
packages: input.packages ?? { prepare: async () => ({ directory: "" }) },
3940
terminalHandoff: async () => ({ renderer: setup.renderer, mode: "dark", complete: ready.resolve }),
4041
args: input.args ?? {},
4142
log: () => {},
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { expect, test } from "bun:test"
2+
import { Effect } from "effect"
3+
import { mkdir } from "node:fs/promises"
4+
import path from "node:path"
5+
import { pathToFileURL } from "node:url"
6+
import { Global } from "@opencode/util/global"
7+
import { Npm } from "@opencode/util/npm"
8+
import { LayerNode } from "@opencode/util/effect/layer-node"
9+
import { createAppFixture } from "./fixture/app"
10+
import { tmpdir } from "./fixture/fixture"
11+
import { directory, json } from "./fixture/tui-client"
12+
13+
const npmLayer = (cache: string) =>
14+
LayerNode.compile(Npm.node, {
15+
replacements: [Global.node.replace(Global.layerWith({ cache, state: path.join(cache, "state") }))],
16+
})
17+
18+
test.each([false, true])(
19+
"server Git plugins load with a separate TUI cache (cached: %s)",
20+
async (cached) => {
21+
await using tmp = await tmpdir()
22+
const repository = path.join(tmp.path, "repository")
23+
await mkdir(repository)
24+
await Bun.write(
25+
path.join(repository, "package.json"),
26+
JSON.stringify({
27+
name: "fixture-git-tui",
28+
version: "1.0.0",
29+
type: "module",
30+
exports: { ".": "./index.js", "./tui": "./tui.js" },
31+
}),
32+
)
33+
await Bun.write(path.join(repository, "index.js"), "export default {}\n")
34+
await Bun.write(
35+
path.join(repository, "tui.js"),
36+
`export default {
37+
id: "fixture.git-tui",
38+
setup(context) {
39+
context.ui.toast.show({ message: "Git TUI plugin loaded", variant: "success" })
40+
}
41+
}\n`,
42+
)
43+
await Bun.$`git init -q -b fixture ${repository}`
44+
await Bun.$`git -C ${repository} add .`
45+
await Bun.$`git -C ${repository} -c user.name=fixture -c [email protected] commit -qm fixture`
46+
const target = `git+${pathToFileURL(repository).href}#fixture`
47+
48+
await Effect.gen(function* () {
49+
const server = yield* Npm.Service.pipe(Effect.provide(npmLayer(path.join(tmp.path, "server-cache"))))
50+
const installed = yield* server.add(target)
51+
const client = yield* Npm.Service.pipe(Effect.provide(npmLayer(path.join(tmp.path, "tui-cache"))))
52+
if (cached) yield* client.add(target)
53+
const preparations: boolean[] = []
54+
const inventories: string[] = []
55+
yield* Effect.promise(async () => {
56+
await using setup = await createAppFixture({
57+
config: { animations: false },
58+
packages: {
59+
prepare: (spec, install = true) => {
60+
preparations.push(install)
61+
return Effect.runPromise(install ? client.add(spec) : client.resolve(spec))
62+
},
63+
},
64+
fetch: (url) => {
65+
if (url.pathname !== "/api/plugin") return undefined
66+
inventories.push(url.pathname)
67+
return json({
68+
location: { directory, project: { id: "proj_test", directory, canonical: directory } },
69+
data: [
70+
{
71+
id: "fixture.git-tui",
72+
source: { type: "package", target, version: installed.version },
73+
features: { server: true, tui: true },
74+
state: { status: "active" },
75+
},
76+
],
77+
})
78+
},
79+
})
80+
await setup.ready
81+
await setup.waitFor(() => preparations.length > 0)
82+
expect(preparations).toEqual([true])
83+
await setup.waitForFrame((frame) => frame.includes("Git TUI plugin loaded"))
84+
expect(preparations).toEqual([true])
85+
const prepared = await Effect.runPromise(client.resolve(target))
86+
expect(prepared.directory).not.toBe(installed.directory)
87+
expect(await Bun.file(path.join(prepared.directory, "tui.js")).exists()).toBe(true)
88+
89+
setup.events.emit({ id: "evt_plugins", created: 1, type: "plugin.updated", data: {} })
90+
await setup.waitFor(() => inventories.length > 1)
91+
await setup.renderOnce()
92+
expect(preparations).toEqual([true])
93+
})
94+
}).pipe(Effect.scoped, Effect.runPromise)
95+
},
96+
30_000,
97+
)

0 commit comments

Comments
 (0)