fix(background-agent): pass query directory to session.get in 4 call-sites (#2937)

resolveSubagentSpawnContext and related lookups called client.session.get
without the query.directory parameter, causing project-scoped sessions
to 404 under newer OpenCode SDK versions. Threaded directory through
SpawnerContext/BackgroundManager so all four call-sites pass it.

🤖 Generated with OhMyOpenCode assistance
https://github.com/code-yeongyu/oh-my-opencode
This commit is contained in:
YeonGyu-Kim
2026-04-12 02:30:01 +09:00
parent d8b9bf1aad
commit 3bfa3bd608
9 changed files with 192 additions and 22 deletions
@@ -6,6 +6,48 @@ import type { PluginInput } from "@opencode-ai/plugin"
import { BackgroundManager } from "./manager"
describe("BackgroundManager session permission", () => {
test("passes query directory when loading the parent session", async () => {
// given
const getCalls: Array<Record<string, unknown>> = []
const client = {
session: {
get: async (input: Record<string, unknown>) => {
getCalls.push(input)
return { data: { directory: "/parent" } }
},
create: async () => ({ data: { id: "ses_child" } }),
promptAsync: async () => ({}),
abort: async () => ({}),
},
}
const directory = tmpdir()
const manager = new BackgroundManager({ client, directory } as unknown as PluginInput)
// when
await manager.launch({
description: "Test task",
prompt: "Do something",
agent: "explore",
parentSessionID: "ses_parent",
parentMessageID: "msg_parent",
})
await new Promise((resolve) => setTimeout(resolve, 50))
manager.shutdown()
// then
expect(getCalls).toHaveLength(2)
expect(getCalls).toEqual([
{
path: { id: "ses_parent" },
query: { directory },
},
{
path: { id: "ses_parent" },
query: { directory },
},
])
})
test("passes explicit session permission rules to child session creation", async () => {
// given
const createCalls: Array<Record<string, unknown>> = []