Files
deepseek-harness/packages/api/workspace-controller/tests/transport.client.spec.ts
T
Yichen Jiang cbae324bfa feat(workspace): stop a Session's running work before archiving it (#4765)
* feat(workspace): stop a Session's running work before archiving it

Archiving was a pure visibility write, so a Session archived mid-turn kept
running out of sight. The Workspace registry now owns archive admission
through two Host events: `workspace/session-activity` reports what still
runs and refuses the plain archive as `workspace/session-active`;
`workspace/session-stop`, requested with `stopActivity`, stops that work the
way the user's own stop actions do before the archive write. The API Session
Controller reports and stops turns, subagent descendants, and owned jobs and
rejects any model step for an archived Session; the Schedule plugin reports
and deletes active reminders. The sidebar turns the refusal into a
stop-and-archive confirmation listing the Host's answer.

* test(workspace): pin the widened archive signature and prove child liveness by heartbeat

The Client inspect catalog spec pins archiveSession's new options
parameter, and the archive e2e reads the Bash child's liveness from a
heartbeat file instead of a pid: the Linux sandbox runs the tool in its own
PID namespace, so the pid it reports is not comparable from the test.

* test(workspace): cover the archive-admission providers and dialog to the per-file gate

Drop the provider's unused disposer and the dialog's unreachable confirm
guard, read reminders without a catch that no composition can reach, and
add the cases the coverage lane found missing: a stop without a jobs
registry, a looping lineage, a descendant whose projections reject, the
dialog's Escape guard and non-Error reason, and a family merged by another
provider.

* fix(workspace): write the archive before stopping, gate subagent lineage, and delete reminders under the schedule barriers

Review round on #4765. The registry now writes the archive set before it
dispatches `workspace/session-stop`, so the durable set already gates
every wake the stops induce; the controller's `agent/pre-step` gate also
blocks subagent descendants of an archived Session and contains each
cancel or kill on its own. The Schedule plugin's stop listener runs as a
management delete in the agent's transaction queue between the same two
persistence barriers the `schedule_delete` tool uses. The confirm dialog
selects singular or plural English lines and keys list rows by index.
Docs: archive-admission section with type-equiv blocks on the workspace
subsystem page, write-first order and residual windows in the READMEs
and the Agent Note, and the missing zh reminders sentence.

* test(web): scope the question composer's New Session wait to the Sessions tree

The wide sidebar's New Session button carries the same visible label as
a fresh session row, so the unscoped `getByText` either settled on the
button before the row existed or hit a strict-mode violation once the
row rendered first, which is how the snapshots lane failed on
ece68c2ab5. Waiting inside the Sessions tree names the row alone.

* fix(schedule): answer archive admission from the owned runtime's fold, not the projection registry

The `sessionProjections.snapshot` API is the Client projection view and
is not a Host read path (review on #4765). `ScheduleRuntime.activeRecords()`
folds the live log the way every drive does, and the archive-admission
listeners ask the owned runtime for that fold: a session without a live
agent or without an owned runtime has nothing armed to fire, so it reports
nothing and has nothing to stop. Covers the runtime-less agent, a fold that
turns unreadable at the persistence barrier, and the stopping/faulted
runtime answering nothing.

* refactor(subagent): report and stop subagent descendants from the Subagent runtime

The `subagent` family of archive admission moves out of the API Session
Controller into `dsh-subagent`, which records the lineage at delegation
and owns the descriptor (review on #4765): `SubagentRuntime` answers
`workspace/session-activity` with the running descendants, labelled from
each child's descriptor through a live Session observation, and
`workspace/session-stop` by cancelling each of them with the parent
cause. The controller keeps turns, owned jobs, and the lineage step gate,
and composes its provider through `ctx.plugin(SessionActivityProvider)`
with declared injections instead of a bare installer call. `dsh-workspace`
becomes an optional type-only peer of `dsh-subagent`.

* refactor(jobs): answer archive admission for owned jobs from the job registry seam

The `job` family moves out of the API Session Controller into `dsh-jobs`
(review on #4765): the seam's constructor installs the
`workspace/session-activity` and `workspace/session-stop` listeners for
every implementation through the abstract `list` and `kill` alone, so the
controller no longer knows the jobs vocabulary and keeps only the turn
family and the archived-lineage step gate. `dsh-workspace` becomes an
optional type-only peer of `dsh-jobs`.

* refactor(workspace): leave SessionActivityKindMap empty and let each provider merge its family

The workspace package no longer names any activity family (review on
#4765): `SessionActivityKindMap` is empty, and each provider merges its own
key from a module both its faces import — `turn` in the API Session
Controller's types, `job` in the job registry seam's view, `subagent` in
the Subagent runtime's control types, `schedule` in the Schedule plugin's
types. The confirm dialog imports those modules for its cases and keeps
the generic line for any other key; the registry and controller suites
merge test-owned families instead of borrowing the providers'.

* refactor(agent): report and stop the running turn from the Agent registry

The `turn` family moves out of the API Session Controller into `dsh-agent`
(review on #4765): the registry's constructor installs the
`workspace/session-activity` and `workspace/session-stop` listeners for
every Agent it publishes, answering with its own lookup and cancelling the
turn with the user cause, and merges the `turn` key from its client-safe
types. The controller keeps only the archived-lineage step gate, renamed
`ArchivedSessionGate`. `dsh-workspace` becomes an optional type-only peer
of `dsh-agent`; the workspace package depends on none of the providers,
so the edge stays acyclic.

Since #3127 a foreground Bash command is a registered job from its start,
so the archive dialog lists it beside the turn; the e2e and its ARIA golden
expect that row, and the capture keeps the running job by design.
2026-09-21 11:46:13 +00:00

431 lines
21 KiB
TypeScript

/**
* Workspace Controller client plugin, state stream, and command facade driven
* through the assembled Gateway client: every `workspace/*` call crosses the
* roster's own Connection and is answered by endpoint name.
*/
import { describe, expect, onTestFinished, vi } from 'vitest'
import { RemoteStreamCarrierError, type ClientRemote } from '@deepseek-ai/dsh-api-gateway/client'
import { SessionId } from '@deepseek-ai/dsh-session/types'
import { RemoteError } from '@deepseek-ai/dsh-typert-protocol'
import { frames, openStream, type RemoteMock, type StreamScript } from '@deepseek-ai/dsh-remote-mock'
import { createClientTest, type TestClient, webApp } from '@deepseek-ai/dsh-client-test-runtime/src/assembly/index.ts'
import {
ClientWorkspaceModel,
createWorkspaceStateStream,
WorkspaceArchiveError,
WorkspaceController,
WorkspaceCreateError,
type WorkspaceFollowSink,
} from '../src/client/index.ts'
import type { WorkspaceFollowFrame, WorkspaceId } from '../src/types.ts'
import { FOLLOW, baseline, err, followGenerations, workspace, workspaceWorld } from './remote/workspace.client.ts'
const SELF = '@deepseek-ai/dsh-api-workspace-controller'
/** The plugin as the web bundle composes it: itself plus the Gateway client, the Connection, and the Typert registry. */
const PLUGIN_ROSTER = webApp.closure([SELF])
/** A stream or model built by hand talks through the Gateway client alone. */
const API_ROSTER = webApp.closure(['@deepseek-ai/dsh-api-gateway'])
const pluginTest = createClientTest({ roster: PLUGIN_ROSTER })
const it = createClientTest({ roster: API_ROSTER })
/** The first client boot pays the cold module transform of the plugin cone. */
const COLD_BOOT_TIMEOUT_MS = 60_000
const wid = (id: string): WorkspaceId => id as WorkspaceId
const sid = (id: string): SessionId => SessionId(id)
/** Boot the plugin with `follow` answering its state stream. */
async function pluginClient(mock: RemoteMock, start: () => Promise<TestClient>, follow: StreamScript): Promise<TestClient> {
mock.stream(FOLLOW, follow)
return start()
}
/** Boot the Gateway client with the Workspace command answers registered, so `remote.workspace` is provided. */
async function gatewayClient(mock: RemoteMock, start: () => Promise<TestClient>): Promise<{ remote: ClientRemote; client: TestClient }> {
mock.load(workspaceWorld)
const client = await start()
return { remote: client.ctx.remote, client }
}
const carrierLoss = (message: string): StreamScript => (_args, stream) => {
stream.fail(new RemoteStreamCarrierError(message))
}
function accepts(overrides: Partial<WorkspaceFollowSink> = {}): WorkspaceFollowSink {
const ignore = (): void => {}
return {
replaceBaseline: ignore,
upsertView: ignore,
removeView: ignore,
replaceOrder: ignore,
replaceArchived: ignore,
replacePinned: ignore,
...overrides,
}
}
function streamStates(mock: RemoteMock): string[] {
return mock.log.streams(FOLLOW).map(row => row.state)
}
describe('Workspace Controller Client apply', () => {
pluginTest('provides the Workspace service and stops its follow generation with the plugin fiber', async ({ mock, start }) => {
const client = await pluginClient(mock, start, openStream([baseline('mounted')]))
await vi.waitFor(() => {
expect(client.ctx.workspaces.list.getSnapshot()).toMatchObject({
phase: 'ready',
state: 'idle',
items: [{ workspaceId: 'mounted' }],
})
})
await client.unload(SELF)
expect(streamStates(client.mock)).toEqual(['cancelled'])
expect(client.ctx.get('workspaces')).toBeUndefined()
}, COLD_BOOT_TIMEOUT_MS)
pluginTest('reopens the follow and re-provides the service across a Loader rebuild', async ({ mock, start }) => {
const client = await pluginClient(mock, start, openStream([baseline('mounted')]))
await vi.waitFor(() => {
expect(client.ctx.workspaces.list.getSnapshot()).toMatchObject({ phase: 'ready', items: [{ workspaceId: 'mounted' }] })
})
const before = client.ctx.workspaces
await client.reload(SELF)
expect(streamStates(client.mock)).toEqual(['cancelled', 'open'])
expect(client.ctx.workspaces).not.toBe(before)
await vi.waitFor(() => {
expect(client.ctx.workspaces.list.getSnapshot()).toMatchObject({ phase: 'ready', items: [{ workspaceId: 'mounted' }] })
})
})
pluginTest('publishes exhausted carrier retries as a gateway/internal error state', async ({ mock, start }) => {
// Neither generation reaches an accepted baseline, so the retry budget runs
// out and the escaping carrier failure crosses the stream boundary marked.
const client = await pluginClient(mock, start, followGenerations([
carrierLoss('generation lost'),
carrierLoss('generation lost again'),
]))
await vi.waitFor(() => {
expect(client.ctx.workspaces.list.getSnapshot()).toMatchObject({
state: 'error',
error: { code: 'gateway/internal', message: 'generation lost again' },
})
})
expect(streamStates(client.mock)).toEqual(['failed', 'failed'])
})
pluginTest('marks carrier loss while retrying and publishes a later protocol failure', async ({ mock, start }) => {
const carrierFailure = vi.spyOn(ClientWorkspaceModel.prototype, 'handleCarrierFailure')
const streamFailure = vi.spyOn(ClientWorkspaceModel.prototype, 'handleStreamFailure')
onTestFinished(() => {
carrierFailure.mockRestore()
streamFailure.mockRestore()
})
const client = await pluginClient(mock, start, followGenerations([
(_args, stream) => {
stream.push(baseline('old'))
stream.fail(new RemoteStreamCarrierError('generation lost'))
},
openStream([baseline('fresh'), baseline('duplicate')]),
]))
await vi.waitFor(() => {
expect(client.ctx.workspaces.list.getSnapshot()).toMatchObject({
phase: 'ready',
state: 'error',
items: [{ workspaceId: 'fresh' }],
error: { code: 'gateway/internal', message: 'Workspace state stream emitted more than one opening snapshot' },
})
})
expect(carrierFailure).toHaveBeenCalledOnce()
expect(streamFailure).toHaveBeenCalledOnce()
})
})
describe('Workspace state stream', () => {
it('delivers one baseline followed by increments', async ({ mock, start }) => {
const { remote } = await gatewayClient(mock, start)
const opening = baseline('one')
const view = opening.value.items[0]!
const increments: WorkspaceFollowFrame[] = [
{ type: 'upsert', workspace: view },
{ type: 'remove', workspaceId: view.workspaceId },
{ type: 'order', workspaceIds: [view.workspaceId] },
{ type: 'archived', archivedSessionIds: [sid('session-one')] },
{ type: 'pinned', pinnedSessionIds: [sid('session-two')] },
]
mock.stream(FOLLOW, openStream([opening, ...increments]))
const replaceBaseline = vi.fn<WorkspaceFollowSink['replaceBaseline']>()
const upsertView = vi.fn<WorkspaceFollowSink['upsertView']>()
const removeView = vi.fn<WorkspaceFollowSink['removeView']>()
const replaceOrder = vi.fn<WorkspaceFollowSink['replaceOrder']>()
const replaceArchived = vi.fn<WorkspaceFollowSink['replaceArchived']>()
const replacePinned = vi.fn<WorkspaceFollowSink['replacePinned']>()
const stream = createWorkspaceStateStream(remote, {
accept: accepts({ replaceBaseline, upsertView, removeView, replaceOrder, replaceArchived, replacePinned }),
failed: vi.fn(),
})
stream.start()
stream.start()
await vi.waitFor(() => { expect(replacePinned).toHaveBeenCalledOnce() })
expect(replaceBaseline).toHaveBeenCalledWith(opening.value)
expect(upsertView).toHaveBeenCalledWith(view)
expect(removeView).toHaveBeenCalledWith(view.workspaceId)
expect(replaceOrder).toHaveBeenCalledWith([view.workspaceId])
expect(replaceArchived).toHaveBeenCalledWith(['session-one'])
expect(replacePinned).toHaveBeenCalledWith(['session-two'])
await stream.dispose()
expect(streamStates(mock)).toEqual(['cancelled'])
})
it('retains the old state across carrier loss and applies the replacement baseline', async ({ mock, start }) => {
const { remote } = await gatewayClient(mock, start)
const carrier = new RemoteStreamCarrierError('socket lost')
mock.stream(FOLLOW, followGenerations([
(_args, stream) => {
stream.push(baseline('old'))
stream.fail(carrier)
},
openStream([baseline('fresh')]),
]))
const replaceBaseline = vi.fn<WorkspaceFollowSink['replaceBaseline']>()
const carrierFailed = vi.fn()
const failed = vi.fn()
const stream = createWorkspaceStateStream(remote, {
accept: accepts({ replaceBaseline }),
carrierFailed,
failed,
})
stream.start()
await vi.waitFor(() => { expect(replaceBaseline).toHaveBeenCalledTimes(2) })
expect(replaceBaseline.mock.calls.map(([value]) => value.items[0]?.title)).toEqual(['old', 'fresh'])
expect(carrierFailed).toHaveBeenCalledWith(carrier)
expect(failed).not.toHaveBeenCalled()
await stream.dispose()
})
it('classifies a normal end after the opening baseline as carrier loss', async ({ mock, start }) => {
const { remote } = await gatewayClient(mock, start)
mock.stream(FOLLOW, followGenerations([
frames([baseline('old')]),
openStream([baseline('fresh')]),
]))
const replaceBaseline = vi.fn<WorkspaceFollowSink['replaceBaseline']>()
const carrierFailed = vi.fn()
const stream = createWorkspaceStateStream(remote, {
accept: accepts({ replaceBaseline }),
carrierFailed,
failed: vi.fn(),
})
stream.start()
await vi.waitFor(() => { expect(replaceBaseline).toHaveBeenCalledTimes(2) })
expect(carrierFailed.mock.calls[0]?.[0]).toMatchObject({
message: 'Workspace state stream ended without a terminal result',
})
await stream.dispose()
})
it('suppresses callback failure after disposal begins', async ({ mock, start }) => {
const { remote } = await gatewayClient(mock, start)
mock.stream(FOLLOW, frames([baseline()]))
const failed = vi.fn()
let closing: Promise<void> | undefined
const stream = createWorkspaceStateStream(remote, {
accept: accepts({
replaceBaseline: () => {
closing = stream.dispose()
throw new Error('disposed callback')
},
}),
failed,
})
stream.start()
await vi.waitFor(() => { expect(closing).toBeDefined() })
await closing
expect(failed).not.toHaveBeenCalled()
})
it.for([
{
name: 'an increment before the baseline',
items: [{ type: 'remove', workspaceId: wid('one') }] as WorkspaceFollowFrame[],
message: 'update before its opening snapshot',
},
{
name: 'a duplicate baseline',
items: [baseline(), baseline()] as WorkspaceFollowFrame[],
message: 'more than one opening snapshot',
},
{
name: 'a normal end before the baseline',
items: [] as WorkspaceFollowFrame[],
message: 'ended before its opening snapshot',
},
])('reports $name as a terminal failure', async ({ items, message }, { mock, start }) => {
const { remote } = await gatewayClient(mock, start)
mock.stream(FOLLOW, frames(items))
const failed = vi.fn()
const stream = createWorkspaceStateStream(remote, { accept: accepts(), failed })
stream.start()
await vi.waitFor(() => { expect(failed).toHaveBeenCalledOnce() })
const failure: unknown = failed.mock.calls[0]?.[0]
expect(failure).toBeInstanceOf(Error)
if (!(failure instanceof Error)) throw new Error('expected Workspace stream failure')
expect(failure.message).toContain(message)
// A protocol failure is terminal: no retry opens a second generation.
expect(mock.log.requests(FOLLOW)).toHaveLength(1)
await stream.dispose()
})
it('restarts a live generation without reporting cancellation as failure', async ({ mock, start }) => {
const { remote } = await gatewayClient(mock, start)
mock.stream(FOLLOW, followGenerations([
openStream([baseline('first')]),
openStream([baseline('second')]),
]))
const replaceBaseline = vi.fn<WorkspaceFollowSink['replaceBaseline']>()
const failed = vi.fn()
const stream = createWorkspaceStateStream(remote, {
accept: accepts({ replaceBaseline }),
failed,
})
stream.start()
await vi.waitFor(() => { expect(replaceBaseline).toHaveBeenCalledOnce() })
stream.restart()
await vi.waitFor(() => { expect(replaceBaseline).toHaveBeenCalledTimes(2) })
expect(failed).not.toHaveBeenCalled()
expect(streamStates(mock)).toEqual(['cancelled', 'open'])
await stream.dispose()
})
})
describe('WorkspaceController', () => {
it('returns no Workspace when startup is ineligible without changing the list', async ({ mock, start }) => {
const { remote, client } = await gatewayClient(mock, start)
const model = new ClientWorkspaceModel(remote.workspace)
model.replaceBaseline({ items: [], archivedSessionIds: [], pinnedSessionIds: [] })
const controller = new WorkspaceController(client.ctx, model)
const before = model.getSnapshot()
mock.remote.workspace.initializeDefault.mockResolvedValueOnce({ ok: true, value: undefined })
await expect(controller.initializeDefault({ directoryName: 'Default workspace', title: 'Default workspace' }))
.resolves.toBeUndefined()
expect(model.getSnapshot()).toBe(before)
})
it('publishes the model source and exposes successful Workspace commands', async ({ mock, start }) => {
const { remote, client } = await gatewayClient(mock, start)
const model = new ClientWorkspaceModel(remote.workspace)
model.replaceBaseline({ items: [workspace('one')], archivedSessionIds: [], pinnedSessionIds: [] })
const controller = new WorkspaceController(client.ctx, model)
expect(controller.list).toBe(model)
expect(client.ctx.workspaces.list).toBe(model)
await expect(controller.initializeDefault({ directoryName: '默认工作区', title: '默认工作区' }, new AbortController().signal)).resolves.toMatchObject({ workspaceId: 'default' })
await expect(controller.create({ path: '/work/created' })).resolves.toMatchObject({ workspaceId: 'created' })
await expect(controller.rename(wid('one'), 'renamed')).resolves.toMatchObject({ title: 'renamed' })
await expect(controller.insertBefore(wid('one'))).resolves.toBeUndefined()
await expect(controller.insertSessionBefore(wid('one'), sid('session'))).resolves.toMatchObject({
sessionIds: ['session'],
})
await expect(controller.archiveSession(sid('session'))).resolves.toBeUndefined()
await expect(controller.unarchiveSession(sid('session'))).resolves.toBeUndefined()
await expect(controller.pinSession(sid('session'))).resolves.toBeUndefined()
await expect(controller.unpinSession(sid('session'))).resolves.toBeUndefined()
await expect(controller.delete(wid('one'))).resolves.toBeUndefined()
// Each command crosses the wire as one positional request object.
expect(mock.log.requests('workspace/initializeDefault')).toEqual([{ directoryName: '默认工作区', title: '默认工作区' }])
expect(mock.log.requests('workspace/create')).toEqual([{ path: '/work/created' }])
expect(mock.log.requests('workspace/rename')).toEqual([{ workspaceId: 'one', title: 'renamed' }])
expect(mock.log.requests('workspace/insertBefore')).toEqual([{ workspaceId: 'one' }])
expect(mock.log.requests('workspace/insertSessionBefore')).toEqual([{ workspaceId: 'one', sessionId: 'session' }])
await expect(controller.archiveSession(sid('session'), { stopActivity: true })).resolves.toBeUndefined()
expect(mock.log.requests('workspace/archiveSession')).toEqual([{ sessionId: 'session' }, { sessionId: 'session', stopActivity: true }])
expect(mock.log.requests('workspace/unarchiveSession')).toEqual([{ sessionId: 'session' }])
expect(mock.log.requests('workspace/pinSession')).toEqual([{ sessionId: 'session' }])
expect(mock.log.requests('workspace/unpinSession')).toEqual([{ sessionId: 'session' }])
expect(mock.log.requests('workspace/delete')).toEqual([{ workspaceId: 'one' }])
})
it('maps generated business failures to the command facade errors', async ({ mock, start }) => {
const { remote, client } = await gatewayClient(mock, start)
const controller = new WorkspaceController(client.ctx, new ClientWorkspaceModel(remote.workspace))
const missingWorkspace = new RemoteError('workspace/not-found', 'gone', { workspaceId: wid('missing') })
const missingSession = new RemoteError('session/not-found', 'missing session', { sessionId: sid('session') })
mock.remote.workspace.initializeDefault.mockResolvedValueOnce(err(new RemoteError('gateway/internal', 'directory denied', {})))
await expect(controller.initializeDefault({ directoryName: 'Default workspace', title: 'Default workspace' })).rejects.toBeInstanceOf(WorkspaceCreateError)
mock.remote.workspace.create.mockResolvedValueOnce(err(new RemoteError('workspace/invalid-path', 'missing path', { path: '/missing' })))
const create = controller.create({ path: '/missing' })
await expect(create).rejects.toBeInstanceOf(WorkspaceCreateError)
await expect(create).rejects.toThrow('workspace create failed: workspace/invalid-path: missing path')
mock.remote.workspace.rename.mockResolvedValueOnce(err(missingWorkspace))
await expect(controller.rename(wid('missing'), 'name')).rejects.toThrow('workspace rename failed: workspace/not-found: gone')
mock.remote.workspace.delete.mockResolvedValueOnce(err(missingWorkspace))
await expect(controller.delete(wid('missing'))).rejects.toThrow('workspace delete failed: workspace/not-found: gone')
mock.remote.workspace.insertBefore.mockResolvedValueOnce(err(missingWorkspace))
await expect(controller.insertBefore(wid('missing'))).rejects.toThrow('workspace reorder failed: workspace/not-found: gone')
mock.remote.workspace.archiveSession.mockResolvedValueOnce(err(missingSession))
const archiveMissing = controller.archiveSession(sid('session'))
await expect(archiveMissing).rejects.toBeInstanceOf(WorkspaceArchiveError)
await expect(archiveMissing).rejects.toThrow('workspace session archive failed: session/not-found: missing session')
// The active-session refusal keeps its structured details so a surface
// can name what still runs.
const active = new RemoteError('workspace/session-active', 'session is active', {
sessionId: sid('session'), activity: [{ kind: 'probe' }, { kind: 'probe-items', items: [{ id: 'item-1' }] }],
})
mock.remote.workspace.archiveSession.mockResolvedValueOnce(err(active))
await expect(controller.archiveSession(sid('session'))).rejects.toMatchObject({
name: 'WorkspaceArchiveError',
rpcError: { code: 'workspace/session-active', details: { activity: [{ kind: 'probe' }, { kind: 'probe-items', items: [{ id: 'item-1' }] }] } },
})
mock.remote.workspace.unarchiveSession.mockResolvedValueOnce(err(missingSession))
await expect(controller.unarchiveSession(sid('session')))
.rejects.toThrow('workspace session unarchive failed: session/not-found: missing session')
mock.remote.workspace.pinSession.mockResolvedValueOnce(err(missingSession))
await expect(controller.pinSession(sid('session')))
.rejects.toThrow('workspace session pin failed: session/not-found: missing session')
mock.remote.workspace.unpinSession.mockResolvedValueOnce(err(missingSession))
await expect(controller.unpinSession(sid('session')))
.rejects.toThrow('workspace session unpin failed: session/not-found: missing session')
mock.remote.workspace.insertSessionBefore.mockResolvedValueOnce(err(new RemoteError(
'workspace/move-invalid', 'invalid move', { workspaceId: wid('missing'), sessionId: sid('session') },
)))
await expect(controller.insertSessionBefore(wid('missing'), sid('session')))
.rejects.toThrow('workspace move failed: workspace/move-invalid: invalid move')
})
it('receives a carrier throw as the client\'s gateway/internal fold, never as a rejection', async ({ mock, start }) => {
const { remote, client } = await gatewayClient(mock, start)
const controller = new WorkspaceController(client.ctx, new ClientWorkspaceModel(remote.workspace))
mock.remote.workspace.create.mockImplementation(() => Promise.reject(new Error('create wire down')))
const create = controller.create({ path: '/work/created' })
await expect(create).rejects.toBeInstanceOf(WorkspaceCreateError)
await expect(create).rejects.toThrow(
'workspace create failed: gateway/internal: client api: workspace/create failed: create wire down',
)
expect(mock.log.calls('workspace/create').map(call => call.state)).toEqual(['failed'])
})
})
// The wire relays whatever families the Host's providers report; this suite merges its own.
declare module '@deepseek-ai/dsh-workspace/types' {
interface SessionActivityKindMap {
probe: true
'probe-items': true
}
}