|
|
@@ -8,6 +8,7 @@ import {
|
|
|
bootstrapDirectory,
|
|
|
loadAgentsQuery,
|
|
|
loadCommands,
|
|
|
+ loadGlobalConfigQuery,
|
|
|
loadPathQuery,
|
|
|
loadProjectsQuery,
|
|
|
loadProvidersQuery,
|
|
|
@@ -76,6 +77,7 @@ function directoryState() {
|
|
|
|
|
|
describe("bootstrapDirectory", () => {
|
|
|
test("uses legacy MCP endpoints while refreshing a v1 directory", async () => {
|
|
|
+ const legacyConfigReads: string[] = []
|
|
|
const mcpReads: string[] = []
|
|
|
const [store, setStore] = directoryState()
|
|
|
|
|
|
@@ -91,7 +93,12 @@ describe("bootstrapDirectory", () => {
|
|
|
},
|
|
|
sdk: {
|
|
|
app: { agents: async () => ({ data: [{ name: "build", mode: "primary" }] }) },
|
|
|
- config: { get: async () => ({ data: {} }) },
|
|
|
+ config: {
|
|
|
+ get: async () => {
|
|
|
+ legacyConfigReads.push("directory")
|
|
|
+ return { data: {} }
|
|
|
+ },
|
|
|
+ },
|
|
|
session: { status: async () => ({ data: {} }) },
|
|
|
vcs: { get: async () => ({ data: undefined }) },
|
|
|
command: {
|
|
|
@@ -134,8 +141,88 @@ describe("bootstrapDirectory", () => {
|
|
|
await new Promise((resolve) => setTimeout(resolve, 80))
|
|
|
|
|
|
expect(store.status).toBe("complete")
|
|
|
+ expect(legacyConfigReads).toEqual(["directory"])
|
|
|
expect(mcpReads.sort()).toEqual(["command", "resource", "status"])
|
|
|
})
|
|
|
+
|
|
|
+ test("skips legacy config while refreshing a v2 directory", async () => {
|
|
|
+ const [store, setStore] = directoryState()
|
|
|
+
|
|
|
+ await bootstrapDirectory({
|
|
|
+ directory: "/project",
|
|
|
+ scope: ServerScope.local,
|
|
|
+ mcp: false,
|
|
|
+ global: {
|
|
|
+ config: {} satisfies Config,
|
|
|
+ path: { state: "", config: "", worktree: "/project", directory: "/project", home: "/home" },
|
|
|
+ project: [{ id: "project", worktree: "/project" } as Project],
|
|
|
+ provider,
|
|
|
+ },
|
|
|
+ sdk: {
|
|
|
+ config: {
|
|
|
+ get: async () => {
|
|
|
+ throw new Error("legacy directory config should not be called")
|
|
|
+ },
|
|
|
+ },
|
|
|
+ } as unknown as OpencodeClient,
|
|
|
+ api,
|
|
|
+ store,
|
|
|
+ setStore,
|
|
|
+ vcsCache: { setStore() {} } as unknown as VcsCache,
|
|
|
+ loadSessions() {},
|
|
|
+ translate: (key) => key,
|
|
|
+ queryClient: new QueryClient(),
|
|
|
+ protocol: Promise.resolve("v2"),
|
|
|
+ })
|
|
|
+
|
|
|
+ expect(store.status).toBe("partial")
|
|
|
+
|
|
|
+ await new Promise((resolve) => setTimeout(resolve, 80))
|
|
|
+
|
|
|
+ expect(store.status).toBe("complete")
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+describe("config queries", () => {
|
|
|
+ test("skips legacy global config for v2 servers", async () => {
|
|
|
+ const sdk = {
|
|
|
+ global: {
|
|
|
+ config: {
|
|
|
+ get: async () => {
|
|
|
+ throw new Error("legacy global config should not be called")
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ } as unknown as OpencodeClient
|
|
|
+
|
|
|
+ const result = await new QueryClient().fetchQuery(
|
|
|
+ loadGlobalConfigQuery(ServerScope.local, sdk, Promise.resolve("v2")),
|
|
|
+ )
|
|
|
+
|
|
|
+ expect(result).toEqual({})
|
|
|
+ })
|
|
|
+
|
|
|
+ test("loads legacy global config for v1 servers", async () => {
|
|
|
+ const calls: string[] = []
|
|
|
+ const config = { shell: "zsh" } satisfies Config
|
|
|
+ const sdk = {
|
|
|
+ global: {
|
|
|
+ config: {
|
|
|
+ get: async () => {
|
|
|
+ calls.push("global")
|
|
|
+ return { data: config }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ } as unknown as OpencodeClient
|
|
|
+
|
|
|
+ const result = await new QueryClient().fetchQuery(
|
|
|
+ loadGlobalConfigQuery(ServerScope.local, sdk, Promise.resolve("v1")),
|
|
|
+ )
|
|
|
+
|
|
|
+ expect(result).toEqual(config)
|
|
|
+ expect(calls).toEqual(["global"])
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
describe("query keys", () => {
|