fix(web): restore pending Inbox after restart
This commit is contained in:
1 parent
6bfda7a0e5
commit
8c8c5b2680
89 files changed
+523
-979
No files matched your search
@@ -153,7 +153,7 @@ describe('Session Controller Client apply', () => {
|
||||
|
||||
expect(accept).toHaveBeenCalledWith({
|
||||
type: 'baseline',
|
||||
value: { queues: {}, jobs: {}, projections: {} },
|
||||
value: { jobs: {}, projections: {} },
|
||||
})
|
||||
|
||||
bench.api.failStreams(new RemoteStreamCarrierError('generation lost'))
|
||||
|
||||
@@ -1,168 +0,0 @@
|
||||
import { Context } from '@deepseek-ai/cordis'
|
||||
import AgentRegistry, { agentEvents, Inbox } from '@deepseek-ai/dsh-agent'
|
||||
import type { Agent } from '@deepseek-ai/dsh-agent'
|
||||
import { createUserMessage } from '@deepseek-ai/dsh-llm'
|
||||
import SessionStore, { SessionId } from '@deepseek-ai/dsh-session'
|
||||
import SessionProjectionRegistry from '@deepseek-ai/dsh-session-projection'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { SessionControlController } from '../src/control.ts'
|
||||
import type { SessionControlFrame } from '../src/types.ts'
|
||||
|
||||
async function harness(): Promise<{
|
||||
ctx: Context
|
||||
control: SessionControlController
|
||||
agent: Agent
|
||||
inbox: Inbox
|
||||
}> {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(SessionStore)
|
||||
await ctx.plugin(SessionProjectionRegistry)
|
||||
await ctx.plugin(AgentRegistry)
|
||||
const session = ctx.sessions.create(SessionId('queue-session'))
|
||||
const agent = { id: session.id, session, inbox: undefined as never, status: 'running', ctx } as unknown as Agent
|
||||
Object.assign(agent, { inbox: new Inbox(ctx, agent.session, agentEvents(ctx, agent)) })
|
||||
ctx.agents.register(agent)
|
||||
return { ctx, control: new SessionControlController(ctx), agent, inbox: agent.inbox }
|
||||
}
|
||||
|
||||
function message(text: string, source: 'user' | 'plugin' = 'user') {
|
||||
return createUserMessage({
|
||||
content: [{ type: 'text', text }],
|
||||
source: source === 'user' ? { kind: 'user' } : { kind: 'plugin', plugin: 'fixture' },
|
||||
})
|
||||
}
|
||||
|
||||
describe('Session control queue projection', () => {
|
||||
/** Consume frames until the next queue replacement (inbox projection frames interleave). */
|
||||
async function nextQueueFrame(
|
||||
iterator: AsyncIterator<SessionControlFrame>,
|
||||
): Promise<Extract<SessionControlFrame, { type: 'queue' }>> {
|
||||
for (;;) {
|
||||
const next = await iterator.next()
|
||||
if (next.done) throw new Error('stream ended before a queue frame')
|
||||
if (next.value.type === 'queue') return next.value
|
||||
}
|
||||
}
|
||||
|
||||
it('projects both pending lists in baselines and live replacement frames', async () => {
|
||||
const { control, inbox } = await harness()
|
||||
const queued = message('queued')
|
||||
const steering = message('steering')
|
||||
const context = message('context', 'plugin')
|
||||
inbox.append('next-turn', queued)
|
||||
inbox.append('next-step', steering)
|
||||
inbox.append('next-step', context)
|
||||
|
||||
const abort = new AbortController()
|
||||
const iterator = control.control(abort.signal)[Symbol.asyncIterator]()
|
||||
const opened = await iterator.next()
|
||||
expect(opened.value).toMatchObject({
|
||||
type: 'baseline',
|
||||
value: {
|
||||
queues: {
|
||||
'queue-session': [
|
||||
{ id: queued.id, placement: 'queued' },
|
||||
{ id: steering.id, placement: 'steering' },
|
||||
{ id: context.id, placement: 'context' },
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const replacement = message('replacement')
|
||||
inbox.append('next-turn', replacement)
|
||||
const replaced = await nextQueueFrame(iterator)
|
||||
expect(replaced.items.map(item => item.id)).toContain(replacement.id)
|
||||
inbox.remove(steering.id)
|
||||
const removed = await nextQueueFrame(iterator)
|
||||
expect(removed.items.map(item => item.id)).not.toContain(steering.id)
|
||||
|
||||
abort.abort()
|
||||
await iterator.next()
|
||||
})
|
||||
|
||||
it('derives queue replacements from the completed projection regardless of registration order', async () => {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(SessionStore)
|
||||
await ctx.plugin(AgentRegistry)
|
||||
const control = new SessionControlController(ctx)
|
||||
await ctx.plugin(SessionProjectionRegistry)
|
||||
const session = ctx.sessions.create(SessionId('late-projection-queue'))
|
||||
const agent = { id: session.id, session, inbox: undefined as never, status: 'running', ctx } as unknown as Agent
|
||||
Object.assign(agent, { inbox: new Inbox(ctx, agent.session, agentEvents(ctx, agent)) })
|
||||
ctx.agents.register(agent)
|
||||
const abort = new AbortController()
|
||||
const iterator = control.control(abort.signal)[Symbol.asyncIterator]()
|
||||
await iterator.next()
|
||||
const pending = message('late projection')
|
||||
|
||||
agent.inbox.append('next-turn', pending)
|
||||
|
||||
await expect(iterator.next()).resolves.toMatchObject({
|
||||
value: {
|
||||
type: 'projection',
|
||||
key: 'inbox',
|
||||
value: { 'next-turn': [{ id: pending.id }], 'next-step': [] },
|
||||
},
|
||||
})
|
||||
await expect(nextQueueFrame(iterator)).resolves.toMatchObject({
|
||||
items: [{ id: pending.id, placement: 'queued' }],
|
||||
})
|
||||
|
||||
abort.abort()
|
||||
await iterator.next()
|
||||
})
|
||||
|
||||
it('ignores inbox events without the exact live Agent session', async () => {
|
||||
const { ctx, control, agent, inbox } = await harness()
|
||||
const abort = new AbortController()
|
||||
const iterator = control.control(abort.signal)[Symbol.asyncIterator]()
|
||||
await iterator.next()
|
||||
|
||||
const unrelated = ctx.sessions.create(SessionId('unrelated-queue'))
|
||||
unrelated.append('agent/inbox/spliced', {
|
||||
target: 'next-turn',
|
||||
start: 0,
|
||||
inserted: [message('unrelated')],
|
||||
})
|
||||
const replacement = ctx.sessions.create(SessionId('replacement-session'))
|
||||
Object.defineProperty(agent, 'session', { configurable: true, value: replacement })
|
||||
inbox.append('next-turn', message('wrong-session'))
|
||||
|
||||
abort.abort()
|
||||
await iterator.next()
|
||||
})
|
||||
|
||||
it('drops broadcasts after cancellation has ended its queue', async () => {
|
||||
const { control, inbox } = await harness()
|
||||
const abort = new AbortController()
|
||||
const iterator = control.control(abort.signal)[Symbol.asyncIterator]()
|
||||
await iterator.next()
|
||||
const waiting = iterator.next()
|
||||
await Promise.resolve()
|
||||
|
||||
abort.abort()
|
||||
inbox.append('next-turn', message('late'))
|
||||
|
||||
await expect(waiting).resolves.toMatchObject({ done: true })
|
||||
})
|
||||
|
||||
it('ends active streams on context disposal after flushing buffered frames', async () => {
|
||||
const { ctx, control, inbox } = await harness()
|
||||
const iterator = control.control(new AbortController().signal)[Symbol.asyncIterator]()
|
||||
await iterator.next()
|
||||
const first = message('first')
|
||||
const second = message('second')
|
||||
inbox.append('next-turn', first)
|
||||
inbox.append('next-turn', second)
|
||||
|
||||
const queues: Extract<SessionControlFrame, { type: 'queue' }>[] = []
|
||||
await ctx.fiber.dispose()
|
||||
for (;;) {
|
||||
const next = await iterator.next()
|
||||
if (next.done) break
|
||||
if (next.value.type === 'queue') queues.push(next.value)
|
||||
}
|
||||
expect(queues.map(queue => queue.items.map(item => item.id))).toEqual([[first.id], [first.id, second.id]])
|
||||
})
|
||||
})
|
||||
@@ -176,7 +176,6 @@ export class FakeApiClient implements IApiClient {
|
||||
/** Optional Host opening cursor override for stale-page and reconnect tests. */
|
||||
followCursor: number | undefined
|
||||
controlBaseline: SessionControlBaseline = {
|
||||
queues: {},
|
||||
jobs: {},
|
||||
projections: {},
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ describe('list lifecycle', () => {
|
||||
frame({
|
||||
type: 'baseline',
|
||||
value: {
|
||||
queues: {}, jobs: {},
|
||||
jobs: {},
|
||||
projections: { [S1]: { asOfSeq: 2, values: {} } },
|
||||
},
|
||||
})
|
||||
@@ -198,7 +198,7 @@ describe('list lifecycle', () => {
|
||||
frame({
|
||||
type: 'baseline',
|
||||
value: {
|
||||
queues: {}, jobs: {},
|
||||
jobs: {},
|
||||
projections: { [S1]: { asOfSeq: 2, values: { title: 'Durable' } } },
|
||||
},
|
||||
})
|
||||
@@ -967,7 +967,7 @@ describe('background-job mirror', () => {
|
||||
manager.handleControlFrame(tasksFrame(S1, [view()]))
|
||||
manager.handleControlFrame({
|
||||
type: 'baseline',
|
||||
value: { queues: {}, jobs: {}, projections: {} },
|
||||
value: { jobs: {}, projections: {} },
|
||||
})
|
||||
expect(S1 in manager.getListSnapshot().jobsBySession).toBe(false)
|
||||
})
|
||||
|
||||
@@ -171,7 +171,7 @@ describe('manager frame routing', () => {
|
||||
manager.handleControlFrame({
|
||||
type: 'baseline',
|
||||
value: {
|
||||
queues: {}, jobs: {},
|
||||
jobs: {},
|
||||
projections: { [sid('s1')]: { asOfSeq: 2, values: {} } },
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,287 +1,100 @@
|
||||
/**
|
||||
* Queue snapshot semantics: authoritative replacement after every host-side
|
||||
* change, reconnect re-baselining, pre-instantiation buffering, editable-text
|
||||
* projection, and snapshot reference stability.
|
||||
*/
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
/** Inbox projection delivery and queue-operation transport. */
|
||||
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { createUserMessage } from '@deepseek-ai/dsh-llm'
|
||||
import type { ContentBlock, UserMessage } from '@deepseek-ai/dsh-llm/types'
|
||||
import type { SessionEvent } from '@deepseek-ai/dsh-session/types'
|
||||
import type { MessageId, RpcId, SessionId } from '@deepseek-ai/dsh-api-remotes/client'
|
||||
import type { InboxState } from '@deepseek-ai/dsh-agent/types'
|
||||
import type { ContentBlock } from '@deepseek-ai/dsh-llm/types'
|
||||
import type { SessionControlFrame } from '@deepseek-ai/dsh-api-session-controller/types'
|
||||
import { Session } from '../src/client/sessions/session.ts'
|
||||
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
||||
import { SessionManager } from '../src/client/sessions/manager.ts'
|
||||
import { FakeApiClient, fakeRemote } from './fake-api.client.ts'
|
||||
|
||||
const SID = 'fk-q1' as SessionId
|
||||
const text = (value: string): ContentBlock[] => [{ type: 'text', text: value }]
|
||||
const rid = (id: string): RpcId => id as RpcId
|
||||
const iid = (id: string): MessageId => id as MessageId
|
||||
|
||||
interface QueueFixture {
|
||||
id: string
|
||||
body: string
|
||||
content?: ContentBlock[]
|
||||
placement?: 'queued' | 'steering'
|
||||
message?: UserMessage
|
||||
let nextSeq = 1
|
||||
|
||||
function message(label: string, body: string) {
|
||||
return createUserMessage({
|
||||
content: text(body),
|
||||
source: { kind: 'user', rpcId: `rpc-${label}` } as never,
|
||||
})
|
||||
}
|
||||
|
||||
/** Build one authoritative queue snapshot. */
|
||||
function queueFrame(items: QueueFixture[]): Extract<SessionControlFrame, { type: 'queue' }> {
|
||||
function inboxFrame(value: InboxState): Extract<SessionControlFrame, { type: 'projection' }> {
|
||||
return {
|
||||
type: 'queue',
|
||||
type: 'projection',
|
||||
sessionId: SID,
|
||||
items: items.map(item => ({
|
||||
id: iid(item.id),
|
||||
placement: item.placement ?? 'queued',
|
||||
message: (item.message ?? createUserMessage({
|
||||
content: item.content ?? text(item.body),
|
||||
source: { kind: 'user', rpcId: rid(`rpc-${item.id}`) } as never,
|
||||
})) as never,
|
||||
})),
|
||||
key: 'inbox',
|
||||
seq: nextSeq++,
|
||||
value: value as never,
|
||||
}
|
||||
}
|
||||
|
||||
function makeSession(): Session {
|
||||
return makeBench().session
|
||||
}
|
||||
describe('Inbox projection intake', () => {
|
||||
it('stores the complete Agent-owned value without adding queue state to the Session snapshot', () => {
|
||||
const manager = new SessionManager(fakeRemote(new FakeApiClient()))
|
||||
const queued = message('queued', 'later')
|
||||
const steering = message('steering', 'now')
|
||||
const value = { 'next-turn': [queued], 'next-step': [steering] }
|
||||
|
||||
function makeBench(): { api: FakeApiClient; session: Session } {
|
||||
const api = new FakeApiClient()
|
||||
return { api, session: new Session(SID, fakeRemote(api)) }
|
||||
}
|
||||
manager.handleControlFrame(inboxFrame(value))
|
||||
const session = manager.get(SID)
|
||||
|
||||
function makeManager(): SessionManager {
|
||||
const api = new FakeApiClient()
|
||||
return new SessionManager(fakeRemote(api))
|
||||
}
|
||||
expect(session.projections.faceOf('inbox').getSnapshot()).toEqual(value)
|
||||
expect(session.getSnapshot()).not.toHaveProperty('queue')
|
||||
})
|
||||
|
||||
describe('Session queue snapshot intake', () => {
|
||||
it('projects stable ids, flat previews, and complete text', () => {
|
||||
const session = makeSession()
|
||||
session.handleControlFrame(queueFrame([
|
||||
{ id: 'q-1', body: '第一条 排队\n消息' },
|
||||
]))
|
||||
const queue = session.getSnapshot().queue
|
||||
expect(typeof queue[0]?.messageId).toBe('string')
|
||||
expect(queue).toMatchObject([
|
||||
{
|
||||
id: 'q-1', placement: 'queued',
|
||||
content: [{ type: 'text', text: '第一条 排队\n消息' }],
|
||||
preview: '第一条 排队 消息', text: '第一条 排队\n消息',
|
||||
it('drops a projection that claims events beyond a reconnect baseline', () => {
|
||||
const manager = new SessionManager(fakeRemote(new FakeApiClient()))
|
||||
manager.handleControlFrame(inboxFrame({
|
||||
'next-turn': [message('stale', 'stale')],
|
||||
'next-step': [],
|
||||
}))
|
||||
|
||||
manager.handleControlFrame({
|
||||
type: 'baseline',
|
||||
value: {
|
||||
jobs: {},
|
||||
projections: { [SID]: { asOfSeq: 0, values: {} } },
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it('marks mixed-content messages non-editable while retaining their preview', () => {
|
||||
const session = makeSession()
|
||||
session.handleControlFrame(queueFrame([{
|
||||
id: 'q-image',
|
||||
body: '',
|
||||
content: [{ type: 'text', text: 'hi' }, { type: 'image', data: 'x' } as never],
|
||||
}]))
|
||||
const queue = session.getSnapshot().queue
|
||||
expect(typeof queue[0]?.messageId).toBe('string')
|
||||
expect(queue).toMatchObject([
|
||||
{
|
||||
id: 'q-image', placement: 'queued',
|
||||
content: [{ type: 'text', text: 'hi' }, { type: 'image', data: 'x' }],
|
||||
preview: 'hi [image]', text: null,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it('caps previews at 200 code points and preserves the full editable text', () => {
|
||||
const session = makeSession()
|
||||
const body = '长'.repeat(201)
|
||||
session.handleControlFrame(queueFrame([{ id: 'q-cap', body }]))
|
||||
const row = session.getSnapshot().queue[0]
|
||||
expect(Array.from(row?.preview ?? '')).toHaveLength(201)
|
||||
expect(row?.preview.endsWith('…')).toBe(true)
|
||||
expect(row?.text).toBe(body)
|
||||
})
|
||||
|
||||
it('replaces content, order, and membership from each authoritative frame', () => {
|
||||
const session = makeSession()
|
||||
session.handleControlFrame(queueFrame([
|
||||
{ id: 'q-1', body: 'one' },
|
||||
{ id: 'q-2', body: 'two' },
|
||||
]))
|
||||
session.handleControlFrame(queueFrame([
|
||||
{ id: 'q-2', body: 'two edited' },
|
||||
]))
|
||||
const queue = session.getSnapshot().queue
|
||||
expect(typeof queue[0]?.messageId).toBe('string')
|
||||
expect(queue).toMatchObject([
|
||||
{
|
||||
id: 'q-2', placement: 'queued',
|
||||
content: [{ type: 'text', text: 'two edited' }],
|
||||
preview: 'two edited', text: 'two edited',
|
||||
},
|
||||
])
|
||||
session.handleControlFrame(queueFrame([]))
|
||||
expect(session.getSnapshot().queue).toEqual([])
|
||||
})
|
||||
|
||||
it('keeps the queue array reference stable across unrelated snapshot swaps', () => {
|
||||
const session = makeSession()
|
||||
session.handleControlFrame(queueFrame([{ id: 'q-stable', body: '稳定' }]))
|
||||
const before = session.getSnapshot().queue
|
||||
session.handleAgentError('unrelated')
|
||||
expect(session.getSnapshot().queue).toBe(before)
|
||||
})
|
||||
|
||||
it('retains steering placement and complete content in the same authoritative snapshot', () => {
|
||||
const session = makeSession()
|
||||
session.handleControlFrame(queueFrame([
|
||||
{ id: 'q-next', body: 'later' },
|
||||
{ id: 's-now', body: 'interrupt now', placement: 'steering' },
|
||||
]))
|
||||
|
||||
expect(session.getSnapshot().queue.map(item => ({
|
||||
id: item.id, placement: item.placement, content: item.content,
|
||||
}))).toEqual([
|
||||
{ id: 'q-next', placement: 'queued', content: text('later') },
|
||||
{ id: 's-now', placement: 'steering', content: text('interrupt now') },
|
||||
])
|
||||
})
|
||||
|
||||
it('hands off exactly one current occurrence when live steering becomes durable', async () => {
|
||||
const { api, session } = makeBench()
|
||||
await session.open()
|
||||
const message = createUserMessage({
|
||||
content: text('same message'),
|
||||
source: { kind: 'user' },
|
||||
})
|
||||
session.handleControlFrame(queueFrame([
|
||||
{ id: 's-first', body: '', placement: 'steering', message },
|
||||
{ id: 's-second', body: '', placement: 'steering', message },
|
||||
]))
|
||||
const durable = {
|
||||
seq: 0,
|
||||
time: 1_700_000_000_000,
|
||||
type: 'user/message',
|
||||
surfaceOp: 'append',
|
||||
data: message,
|
||||
} as SessionEvent
|
||||
|
||||
await api.pushFollow(SID, { type: 'event', event: durable as never })
|
||||
await vi.waitFor(() => {
|
||||
expect(session.getSnapshot().queue.map(item => item.id)).toEqual(['s-second'])
|
||||
})
|
||||
|
||||
session.handleControlFrame(queueFrame([
|
||||
{ id: 's-later', body: '', placement: 'steering', message },
|
||||
]))
|
||||
await api.pushFollow(SID, { type: 'event', event: durable as never })
|
||||
await vi.waitFor(() => {
|
||||
expect(session.getSnapshot().queue.map(item => item.id)).toEqual(['s-later'])
|
||||
})
|
||||
expect(manager.get(SID).projections.faceOf('inbox').getSnapshot()).toBeUndefined()
|
||||
})
|
||||
|
||||
it('hands off live steering when the agent claims it as a user message', async () => {
|
||||
const { api, session } = makeBench()
|
||||
await session.open()
|
||||
const message = createUserMessage({
|
||||
content: text('claimed steering'),
|
||||
source: { kind: 'user' },
|
||||
})
|
||||
session.handleControlFrame(queueFrame([
|
||||
{ id: 's-claimed', body: '', placement: 'steering', message },
|
||||
]))
|
||||
it('retains only the highest-seq value received before Session materialization', () => {
|
||||
const manager = new SessionManager(fakeRemote(new FakeApiClient()))
|
||||
manager.handleControlFrame(inboxFrame({
|
||||
'next-turn': [message('old', 'old')],
|
||||
'next-step': [],
|
||||
}))
|
||||
const latest = {
|
||||
'next-turn': [message('latest', 'latest')],
|
||||
'next-step': [],
|
||||
}
|
||||
manager.handleControlFrame(inboxFrame(latest))
|
||||
|
||||
await api.pushFollow(SID, {
|
||||
type: 'event',
|
||||
event: {
|
||||
seq: 0,
|
||||
time: 1_700_000_000_000,
|
||||
type: 'user/message',
|
||||
surfaceOp: 'append',
|
||||
data: message,
|
||||
} as never,
|
||||
})
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(session.getSnapshot().queue).toEqual([])
|
||||
})
|
||||
expect(manager.get(SID).projections.faceOf('inbox').getSnapshot()).toEqual(latest)
|
||||
})
|
||||
})
|
||||
|
||||
describe('queue operation transport', () => {
|
||||
it('addresses the session.updateQueue RPC without optimistic local mutation', async () => {
|
||||
it('does not mutate the Inbox projection before the Host publishes its committed value', async () => {
|
||||
const api = new FakeApiClient()
|
||||
const session = new Session(SID, fakeRemote(api))
|
||||
session.handleControlFrame(queueFrame([{ id: 'q-op', body: 'pending' }]))
|
||||
const before = session.getSnapshot().queue
|
||||
const manager = new SessionManager(fakeRemote(api))
|
||||
const pending = message('pending', 'before')
|
||||
const initial = { 'next-turn': [pending], 'next-step': [] }
|
||||
manager.handleControlFrame(inboxFrame(initial))
|
||||
const session = manager.get(SID)
|
||||
|
||||
await expect(session.updateQueue(iid('q-op'), { kind: 'edit', content: text('next') }))
|
||||
await expect(session.updateQueue(pending.id, { kind: 'edit', content: text('after') }))
|
||||
.resolves.toEqual({ ok: true, value: { accepted: true } })
|
||||
await expect(session.updateQueue(iid('q-op'), { kind: 'steer' }))
|
||||
.resolves.toEqual({ ok: true, value: { accepted: true } })
|
||||
expect(api.callsOf('session.updateQueue')).toEqual([
|
||||
{
|
||||
sessionId: SID,
|
||||
itemId: 'q-op',
|
||||
action: { kind: 'edit', content: text('next') },
|
||||
},
|
||||
{
|
||||
sessionId: SID,
|
||||
itemId: 'q-op',
|
||||
action: { kind: 'steer' },
|
||||
},
|
||||
])
|
||||
expect(session.getSnapshot().queue).toBe(before)
|
||||
})
|
||||
})
|
||||
|
||||
describe('queue reconnect semantics', () => {
|
||||
it('a control baseline clears stale state before a fresh update lands', () => {
|
||||
const session = makeSession()
|
||||
session.handleControlFrame(queueFrame([{ id: 'q-old', body: '旧连接' }]))
|
||||
session.replaceControl([])
|
||||
expect(session.getSnapshot().queue).toEqual([])
|
||||
session.handleControlFrame(queueFrame([{ id: 'q-new', body: '新基线' }]))
|
||||
expect(session.getSnapshot().queue.map(row => row.id)).toEqual(['q-new'])
|
||||
})
|
||||
|
||||
it('resync does not clear a baseline that raced ahead of the host connection signal', async () => {
|
||||
const session = makeSession()
|
||||
await session.open()
|
||||
session.handleControlFrame(queueFrame([{ id: 'q-fresh', body: '新基线' }]))
|
||||
await session.resync()
|
||||
expect(session.getSnapshot().queue.map(row => row.id)).toEqual(['q-fresh'])
|
||||
})
|
||||
|
||||
it('running-status changes never guess at queue retirement', () => {
|
||||
const session = makeSession()
|
||||
session.handleControlFrame(queueFrame([{ id: 'q-live', body: '保留' }]))
|
||||
session.handleRunning(true)
|
||||
session.handleRunning(false)
|
||||
expect(session.getSnapshot().queue.map(row => row.id)).toEqual(['q-live'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('manager buffering of queue snapshots', () => {
|
||||
it('replays only the latest snapshot for an uninstantiated session', () => {
|
||||
const manager = makeManager()
|
||||
manager.handleControlFrame(queueFrame([{ id: 'q-old', body: '旧' }]))
|
||||
manager.handleControlFrame(queueFrame([{ id: 'q-new', body: '新' }]))
|
||||
expect(manager.get(SID).getSnapshot().queue.map(row => row.id)).toEqual(['q-new'])
|
||||
})
|
||||
|
||||
it('a control baseline replaces the prior queue', () => {
|
||||
const manager = makeManager()
|
||||
manager.handleControlFrame(queueFrame([{ id: 'q-g1', body: '第一代' }]))
|
||||
const nextQueue = queueFrame([{ id: 'q-g2', body: '第二代' }]).items
|
||||
manager.handleControlFrame({
|
||||
type: 'baseline',
|
||||
value: {
|
||||
queues: { [SID]: nextQueue },
|
||||
jobs: {},
|
||||
projections: {},
|
||||
},
|
||||
})
|
||||
const snapshot = manager.get(SID).getSnapshot()
|
||||
expect(snapshot.queue.map(row => row.id)).toEqual(['q-g2'])
|
||||
expect(api.callsOf('session.updateQueue')).toEqual([{
|
||||
sessionId: SID,
|
||||
itemId: pending.id,
|
||||
action: { kind: 'edit', content: text('after') },
|
||||
}])
|
||||
expect(session.projections.faceOf('inbox').getSnapshot()).toBe(initial)
|
||||
})
|
||||
})
|
||||
@@ -139,7 +139,7 @@ describe('scope tree', () => {
|
||||
|
||||
b.svc.handleControlFrame({
|
||||
type: 'baseline',
|
||||
value: { queues: {}, jobs: {}, projections: {} },
|
||||
value: { jobs: {}, projections: {} },
|
||||
})
|
||||
await Promise.resolve()
|
||||
expect(b.svc.resolveAgentScope(sid('s-early'))).toBe(scoped)
|
||||
|
||||
@@ -322,10 +322,10 @@ describe('Session Client stream adapters', () => {
|
||||
it('maps the Host-wide control baseline and deltas into one snapshot stream', async () => {
|
||||
const baseline: SessionControlFrame = {
|
||||
type: 'baseline',
|
||||
value: { queues: {}, jobs: {}, projections: {} },
|
||||
value: { jobs: {}, projections: {} },
|
||||
}
|
||||
const update: SessionControlFrame = {
|
||||
type: 'queue', sessionId: 'session-1' as never, items: [],
|
||||
type: 'jobs', sessionId: 'session-1' as never, jobs: [],
|
||||
}
|
||||
const remote = new ScriptedSessionRemote([], [], [baseline, update])
|
||||
const accept = vi.fn<(frame: SessionControlFrame) => void>()
|
||||
@@ -357,7 +357,7 @@ describe('Session Client stream adapters', () => {
|
||||
|
||||
const baseline: SessionControlFrame = {
|
||||
type: 'baseline',
|
||||
value: { queues: {}, jobs: {}, projections: {} },
|
||||
value: { jobs: {}, projections: {} },
|
||||
}
|
||||
const carrierFailed = vi.fn()
|
||||
const failed = vi.fn()
|
||||
|
||||
Reference in new issue
Block a user