Skip to content

Commit 5347b5e

Browse files
authored
fix(app): register new home projects (#41018)
1 parent b467518 commit 5347b5e

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

packages/app/src/pages/home/home-controller.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,20 @@ export function createHomeController() {
9090
const directory = directories[0]
9191
if (!directory) return
9292
const ctx = global.ensureServerCtx(conn)
93-
directories.forEach((item) => ctx.projects.open(item))
93+
directories.forEach((item) => {
94+
if (ctx.projects.list().some((project) => project.worktree === item)) return
95+
const location = { directory: item }
96+
void ctx.sdk.api.file
97+
.list({ path: ".", location })
98+
.then(async (files) => {
99+
if (files.data.length > 0) return ctx.sdk.api.project.current({ location })
100+
const result = await ctx.sdk.client.project.initGit({ directory: item })
101+
return result.data ?? ctx.sdk.api.project.current({ location })
102+
})
103+
.then((project) => ctx.sync.child(item, { bootstrap: false })[1]("project", project.id))
104+
.catch(() => undefined)
105+
ctx.projects.open(item)
106+
})
94107
ctx.projects.touch(directory)
95108
setSelection({ server: ServerConnection.key(conn), directory })
96109
},

packages/opencode/test/server/httpapi-instance-context.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,21 @@ describe("HttpApi instance context middleware", () => {
161161
}),
162162
)
163163

164+
it.live("persists the routed project while loading instance context", () =>
165+
Effect.gen(function* () {
166+
const dir = yield* tmpdirScoped({ git: true })
167+
const project = yield* Project.Service
168+
yield* serveProbe()
169+
170+
const response = yield* HttpClient.get(`/probe?directory=${encodeURIComponent(dir)}`)
171+
172+
expect(response.status).toBe(200)
173+
const saved = (yield* project.list()).find((item) => item.worktree === dir)
174+
expect(saved).toBeDefined()
175+
expect(saved?.id).not.toBe("global")
176+
}),
177+
)
178+
164179
it.live("falls back to the raw directory when URI decoding fails", () =>
165180
Effect.gen(function* () {
166181
yield* serveProbe()

0 commit comments

Comments
 (0)