Merge remote-tracking branch 'origin/master' into refactor/subagent
This commit is contained in:
commit
b3b0cd95cc
238 files changed
+6750
-2131
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { resolve } from 'node:path'
|
||||
import * as nativeCommand from '@deepseek-ai/dsh-native-command'
|
||||
import { Context } from '@deepseek-ai/cordis'
|
||||
import AgentRegistry from '@deepseek-ai/dsh-agent'
|
||||
@@ -65,11 +66,11 @@ describe('session/openWorkspacePath', () => {
|
||||
|
||||
await expect(remote.openWorkspacePath({ path: '/workspace/project/src/a.ts' }, signal))
|
||||
.resolves.toEqual({ ok: true, value: { opened: true } })
|
||||
expect(openPath).toHaveBeenCalledWith('/workspace/project/src/a.ts', signal)
|
||||
expect(openPath).toHaveBeenCalledWith(resolve('/workspace/project/src/a.ts'), signal)
|
||||
expect(ctx.agents.list()).toEqual([])
|
||||
})
|
||||
|
||||
it('preserves relative and absolute Host-resolvable paths', async () => {
|
||||
it('normalizes relative and absolute Host-resolvable paths', async () => {
|
||||
const ctx = await context()
|
||||
const openPath = vi.fn((_path: string, _signal: AbortSignal) => Promise.resolve())
|
||||
const remote = createSessionTestRemote(ctx, {
|
||||
@@ -80,7 +81,7 @@ describe('session/openWorkspacePath', () => {
|
||||
|
||||
await remote.openWorkspacePath({ path: '/workspace/result.html' })
|
||||
await remote.openWorkspacePath({ path: 'result.html' })
|
||||
expect(openPath.mock.calls.map(call => call[0])).toEqual(['/workspace/result.html', 'result.html'])
|
||||
expect(openPath.mock.calls.map(call => call[0])).toEqual([resolve('/workspace/result.html'), resolve('result.html')])
|
||||
})
|
||||
|
||||
it('rejects empty paths before opening anything', async () => {
|
||||
@@ -100,7 +101,7 @@ describe('session/openWorkspacePath', () => {
|
||||
it('preserves native opener failure and cancellation results', async () => {
|
||||
const ctx = await context()
|
||||
const openPath = vi.fn((_path: string, _signal: AbortSignal) =>
|
||||
Promise.reject(new Error('desktop unavailable')))
|
||||
Promise.reject(new Error('Command failed: powershell.exe -EncodedCommand private-script-text')))
|
||||
const remote = createSessionTestRemote(ctx, {
|
||||
defaultModelSelection: () => ({ provider: 'p', model: 'm' }),
|
||||
cwd: '/default',
|
||||
@@ -110,7 +111,7 @@ describe('session/openWorkspacePath', () => {
|
||||
await expect(remote.openWorkspacePath({ path: 'result.html' }))
|
||||
.resolves.toMatchObject({
|
||||
ok: false,
|
||||
error: { code: 'gateway/internal', message: 'path open failed: desktop unavailable' },
|
||||
error: { code: 'gateway/internal', message: 'path open failed' },
|
||||
})
|
||||
|
||||
const aborted = new AbortController()
|
||||
@@ -139,7 +140,7 @@ describe('session/openWorkspacePath', () => {
|
||||
await expect(controller.openWorkspacePath({
|
||||
path: 'second.html',
|
||||
}, new AbortController().signal)).rejects.toMatchObject({
|
||||
code: 'gateway/internal', message: 'path open failed: desktop unavailable',
|
||||
code: 'gateway/internal', message: 'path open failed',
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -156,7 +157,7 @@ it('reports Host file-manager metadata and dispatches reveal separately from def
|
||||
expect(controller.workspaceDesktop()).toMatchObject({ available: true, name: expect.any(String) as string })
|
||||
const signal = new AbortController().signal
|
||||
await controller.openWorkspacePath({ path: '/workspace/report.txt', action: 'reveal' }, signal)
|
||||
expect(revealPath).toHaveBeenCalledWith('/workspace/report.txt', signal)
|
||||
expect(revealPath).toHaveBeenCalledWith(resolve('/workspace/report.txt'), signal)
|
||||
expect(openPath).not.toHaveBeenCalled()
|
||||
} finally { await ctx.fiber.dispose() }
|
||||
})
|
||||
@@ -186,7 +187,7 @@ it.each(['open', 'reveal'] as const)('rejects an unmapped remote path before nat
|
||||
defaultModelSelection: () => ({ provider: 'p', model: 'm' }), cwd: '/default', openPath, revealPath,
|
||||
})
|
||||
await expect(controller.openWorkspacePath({ path: '/remote/report.html', ...(action === 'reveal' ? { action } : {}) }, new AbortController().signal))
|
||||
.rejects.toMatchObject({ code: 'gateway/internal', message: 'path open failed: Path has no verified Host path' })
|
||||
.rejects.toMatchObject({ code: 'gateway/bad-request', message: 'Path has no verified Host path' })
|
||||
expect(openPath).not.toHaveBeenCalled()
|
||||
expect(revealPath).not.toHaveBeenCalled()
|
||||
})
|
||||
@@ -200,7 +201,7 @@ it('rejects a filesystem mapping that resolves to another process path', async (
|
||||
defaultModelSelection: () => ({ provider: 'p', model: 'm' }), cwd: '/default', openPath,
|
||||
})
|
||||
await expect(controller.openWorkspacePath({ path: '/report.html' }, new AbortController().signal))
|
||||
.rejects.toMatchObject({ code: 'gateway/internal', message: 'path open failed: Path has no verified Host path' })
|
||||
.rejects.toMatchObject({ code: 'gateway/bad-request', message: 'Path has no verified Host path' })
|
||||
expect(openPath).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@@ -213,5 +214,61 @@ it('dispatches default-app opening to the association adapter', async () => {
|
||||
})
|
||||
const signal = new AbortController().signal
|
||||
await controller.openWorkspacePath({ path: '/report.html' }, signal)
|
||||
expect(open).toHaveBeenCalledWith('/report.html', signal)
|
||||
expect(open).toHaveBeenCalledWith(resolve('/report.html'), signal)
|
||||
})
|
||||
|
||||
|
||||
it('uses the same path verification for handler queries and explicit application opening', async () => {
|
||||
const ctx = await context()
|
||||
const applications = [{ id: '/Applications/Music.app', name: 'Music', default: true, icon: null }]
|
||||
const fileApplications = vi.fn(async () => applications)
|
||||
const openFileApplication = vi.fn(async () => {})
|
||||
const controller = createSessionTestController(ctx, {
|
||||
defaultModelSelection: () => ({ provider: 'p', model: 'm' }), cwd: '/default', nativeOpen: true,
|
||||
fileApplications, openFileApplication,
|
||||
})
|
||||
const signal = new AbortController().signal
|
||||
expect(await controller.workspacePathApplications({ path: '/file.mp3' }, signal)).toEqual(applications)
|
||||
await controller.openWorkspacePath({ path: '/file.mp3', application: applications[0]!.id }, signal)
|
||||
expect(openFileApplication).toHaveBeenCalledWith(expect.stringContaining('file.mp3'), applications[0]!.id, signal)
|
||||
const mapping = vi.spyOn(ctx.fs, 'processPathFromHostPath').mockReturnValue(undefined)
|
||||
onTestFinished(() => { mapping.mockRestore() })
|
||||
await expect(controller.workspacePathApplications({ path: '/remote.mp3' }, signal)).rejects.toThrow('verified Host path')
|
||||
await expect(controller.openWorkspacePath({ path: '/remote.mp3', application: applications[0]!.id }, signal)).rejects.toThrow('verified Host path')
|
||||
expect(fileApplications).toHaveBeenCalledOnce()
|
||||
expect(openFileApplication).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
|
||||
it('avoids desktop queries when unavailable and rejects an empty query path', async () => {
|
||||
const fileApplications = vi.fn(async () => [])
|
||||
const unavailable = createSessionTestController(await context(), {
|
||||
defaultModelSelection: () => ({ provider: 'p', model: 'm' }), cwd: '/default', nativeOpen: false, fileApplications,
|
||||
})
|
||||
expect(await unavailable.workspacePathApplications({ path: '/file.mp3' }, new AbortController().signal)).toEqual([])
|
||||
const available = createSessionTestController(await context(), {
|
||||
defaultModelSelection: () => ({ provider: 'p', model: 'm' }), cwd: '/default', nativeOpen: true, fileApplications,
|
||||
})
|
||||
await expect(available.workspacePathApplications({ path: '' }, new AbortController().signal)).rejects.toMatchObject({ code: 'gateway/bad-request' })
|
||||
expect(fileApplications).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
|
||||
it('returns bounded query failures and classifies cancellation through the Remote', async () => {
|
||||
const lifetime = new AbortController()
|
||||
const fileApplications = vi.fn()
|
||||
.mockRejectedValueOnce(new Error('Command failed: osascript -e private-script-text'))
|
||||
.mockImplementationOnce(async () => {
|
||||
lifetime.abort()
|
||||
throw new Error('native query stopped')
|
||||
})
|
||||
const remote = createSessionTestRemote(await context(), {
|
||||
defaultModelSelection: () => ({ provider: 'p', model: 'm' }), cwd: '/default', nativeOpen: true, fileApplications,
|
||||
})
|
||||
await expect(remote.workspacePathApplications({ path: '/file.mp3' })).resolves.toMatchObject({
|
||||
ok: false, error: { code: 'gateway/internal', message: 'file application query failed' },
|
||||
})
|
||||
await expect(remote.workspacePathApplications({ path: '/file.mp3' }, lifetime.signal)).resolves.toMatchObject({
|
||||
ok: false, error: { code: 'gateway/cancelled' },
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,5 @@
|
||||
/** Test-only direct Remote face over the Session Controller's internal controllers. */
|
||||
import type { SessionControllerInternals } from '../src/index.ts'
|
||||
|
||||
import { SessionLogOffset } from '@deepseek-ai/dsh-session'
|
||||
import type { Context } from '@deepseek-ai/cordis'
|
||||
@@ -48,6 +49,7 @@ import type {
|
||||
SessionListValue,
|
||||
SessionOpenWorkspacePathRequest,
|
||||
SessionOpenWorkspacePathValue,
|
||||
SessionWorkspacePathApplication,
|
||||
SessionPage,
|
||||
SessionPageRequest,
|
||||
SessionPromptRequest,
|
||||
@@ -65,6 +67,9 @@ import type {
|
||||
|
||||
/** Direct test face matching the generated `ctx.remote.session` unary methods. */
|
||||
export interface TestSessionRemote {
|
||||
workspacePathApplications(
|
||||
request: { readonly path: string }, signal?: AbortSignal,
|
||||
): Promise<RemoteResult<readonly SessionWorkspacePathApplication[]>>
|
||||
canOpenWorkspacePath(): Promise<RemoteResult<boolean>>
|
||||
list(request: SessionListRequest, signal?: AbortSignal): Promise<RemoteResult<SessionListValue>>
|
||||
search(request: SessionSearchRequest, signal?: AbortSignal): Promise<RemoteResult<SessionSearchValue>>
|
||||
@@ -94,6 +99,8 @@ export interface TestSessionRemoteDefaults {
|
||||
readonly nativeOpen?: boolean
|
||||
readonly saveDefaultModelSelection?: (selection: AgentModelSelection) => void | Promise<void>
|
||||
readonly openPath?: (path: string, signal: AbortSignal) => Promise<void>
|
||||
readonly fileApplications?: SessionControllerInternals['fileApplications']
|
||||
readonly openFileApplication?: SessionControllerInternals['openFileApplication']
|
||||
readonly revealPath?: (path: string, signal: AbortSignal) => Promise<void>
|
||||
readonly canOpenPath?: () => boolean
|
||||
}
|
||||
@@ -288,6 +295,8 @@ function installControllers(
|
||||
},
|
||||
{
|
||||
...defaults.openPath === undefined ? {} : { openPath: defaults.openPath },
|
||||
...defaults.fileApplications === undefined ? {} : { fileApplications: defaults.fileApplications },
|
||||
...defaults.openFileApplication === undefined ? {} : { openFileApplication: defaults.openFileApplication },
|
||||
...defaults.revealPath === undefined ? {} : { revealPath: defaults.revealPath },
|
||||
...defaults.canOpenPath === undefined ? {} : { canOpenPath: defaults.canOpenPath },
|
||||
},
|
||||
@@ -334,6 +343,9 @@ export function createSessionTestRemote(
|
||||
): TestSessionRemote {
|
||||
const direct = createSessionTestController(ctx, defaults)
|
||||
return {
|
||||
workspacePathApplications: (request, signal = new AbortController().signal) => remoteResult(
|
||||
() => direct.workspacePathApplications(request, signal), signal,
|
||||
),
|
||||
canOpenWorkspacePath: () => remoteResult(() => direct.canOpenWorkspacePath()),
|
||||
list: (request, signal = new AbortController().signal) => remoteResult(
|
||||
() => direct.list(request, signal),
|
||||
|
||||
Reference in new issue
Block a user