fix: clean up OpenCode streams and allow external working directories
Completed OpenCode requests left their event streams open across repeated and parallel conversations. Each request now closes its own subscription on exit without cancelling peer sessions, and cancellation preserves its original cause. Direct-model Execute commands no longer restrict cwd to the workspace. Absolute paths, parent-relative paths, and symlinks to external directories are accepted. The workspace remains the default and relative-path base; Ask stays read-only, and local execution binding, directory validation, and process cleanup remain. Add real OpenCode lifecycle and real Shell tool-loop regressions, plus matching feature documentation. Focused checks: 182 passed, 1 skipped; typecheck and lint passed. Full shared-worktree suite: 3542 passed, 57 skipped, 1 unrelated sidebar heading failure, reproduced separately and documented. Release note: 修复 OpenCode 连续及并行对话结束后事件连接未释放的问题;直连模型 Execute 命令现在可直接指定工作区外的绝对路径、相对路径或符号链接目录,Ask 只读边界保持不变。
This commit is contained in:
@@ -1290,6 +1290,59 @@ describe('OpenCodeRuntime embedded launcher', () => {
|
||||
expect(runtime.requiresToolApproval).toBe(false)
|
||||
})
|
||||
|
||||
it.each(['completed', 'failed', 'cancelled', 'consumer-return'])(
|
||||
'closes the event subscription when a run is %s',
|
||||
async (outcome) => {
|
||||
const setup = runClient([])
|
||||
const controller = new AbortController()
|
||||
let subscriptionSignal: AbortSignal | undefined
|
||||
const subscribe = setup.event.subscribe as unknown as ReturnType<typeof vi.fn>
|
||||
subscribe.mockImplementation(async (_input, options: { signal: AbortSignal }) => {
|
||||
subscriptionSignal = options.signal
|
||||
return {
|
||||
stream: (async function* () {
|
||||
if (outcome === 'cancelled') {
|
||||
controller.abort(new DOMException('Cancelled', 'AbortError'))
|
||||
return
|
||||
}
|
||||
if (outcome === 'failed') return
|
||||
yield {
|
||||
type: 'session.idle',
|
||||
properties: { sessionID: 'session-1' }
|
||||
}
|
||||
})()
|
||||
}
|
||||
})
|
||||
const runtime = new OpenCodeRuntime(
|
||||
options({ embedded: false, baseUrl: 'http://127.0.0.1:4096' }),
|
||||
{ createClient: (() => setup.client) as typeof createOpencodeClient }
|
||||
)
|
||||
const collect = async (): Promise<void> => {
|
||||
for await (const event of runtime.run({
|
||||
requestId: crypto.randomUUID(),
|
||||
conversationId: crypto.randomUUID(),
|
||||
prompt: 'test',
|
||||
workMode: 'execute'
|
||||
}, controller.signal)) {
|
||||
if (outcome === 'consumer-return' && event.type === 'done') break
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (outcome === 'failed') {
|
||||
await expect(collect()).rejects.toThrow('事件流意外结束')
|
||||
} else if (outcome === 'cancelled') {
|
||||
await expect(collect()).rejects.toMatchObject({ name: 'AbortError' })
|
||||
} else {
|
||||
await collect()
|
||||
}
|
||||
expect(subscriptionSignal?.aborted).toBe(true)
|
||||
expect(controller.signal.aborted).toBe(outcome === 'cancelled')
|
||||
} finally {
|
||||
await runtime.dispose()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
it('serializes external runs that share one conversation session', async () => {
|
||||
const child = fakeChild()
|
||||
let releaseFirst!: () => void
|
||||
|
||||
Reference in New Issue
Block a user