Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/opencode/src/cli/cmd/tui/context/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export function useEvent() {
return
}

if (event.directory === "global" || event.project === project.project()) {
const currentProject = project.project()
if (event.directory === "global" || currentProject === undefined || event.project === currentProject) {
handler(event.payload, { workspace: event.workspace })
}
})
Expand Down
19 changes: 17 additions & 2 deletions packages/opencode/test/cli/tui/use-event.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function createSource() {
}
}

async function mount() {
async function mount(input: { syncProject?: boolean } = {}) {
const source = createSource()
const seen: Event[] = []
const workspaces: Array<string | undefined> = []
Expand All @@ -87,7 +87,7 @@ async function mount() {
<Probe
onReady={async (ctx) => {
project = ctx.project
await project.sync()
if (input.syncProject !== false) await project.sync()
done()
}}
seen={seen}
Expand Down Expand Up @@ -178,4 +178,19 @@ describe("useEvent", () => {
app.renderer.destroy()
}
})

test("delivers project events before the current project finishes loading", async () => {
const { app, emit, seen, workspaces } = await mount({ syncProject: false })

try {
emit(event(vcs("startup"), { directory: "/tmp/root", project: projectID, workspace: "ws_start" }))

await wait(() => seen.length === 1)

expect(seen).toEqual([vcs("startup")])
expect(workspaces).toEqual(["ws_start"])
} finally {
app.renderer.destroy()
}
})
})
Loading