* ✨ feat(session): persist and synchronize read state * 🌐 fix(client): complete Japanese labels after base update * 📝 docs: refresh session read-state dependency graph * 🧪 test(web): align session menu and read-state snapshots * 🌐 fix(session): complete Japanese plugin metadata * 🧪 test(web): distinguish unread from pending user input * 🐛 修复会话阅读状态的故障隔离与生命周期 * 🐛 修复阅读状态依赖检查并补齐自动已读覆盖 * 🐛 恢复会话绿点并移除未读标题加粗 * ♻️ Keep shared session reading state in Host memory * 🌐 Complete reading-state metadata for supported locales * 📝 Refresh module graph after removing storage dependency * 🧹 Move storage dependency policy out of memory-only reading * 🐛 Wait for sidebar catalog before replay navigation * 🔧 Give Host TypeScript checks 8 GiB of heap * ✅ Align Host heap checks and Windows diagnostics * ♻️ Keep CI repairs outside the session reading PR * 🐛 Show failed unread turns with an error indicator * 🔧 Adjust npm layout budget for the reading package * 🧪 Scope projection stream assertions to observed units * 🧪 Scope permission and title assertions to their projections * ♻️ Simplify session reading updates to explicit positions * 🐛 Align session reading package with release version * 🧪 Load reading state in LiveShare viewer fixtures * 🧹 Remove persistence-only type link from memory PR * 🧪 Align context menu expectations with reading actions * 🐛 Sync reading package with the release version * 🧪 Include turn boundaries in session summary expectations * ♻️ Derive reading failure facts from Host events instead of a projection The reading service took each completion from the Agent turn-boundary projection, which forced a stateVersion bump and put that projection's whole internal state on the wire for every Session list row. The service now records `turn/end` itself, so `core/agent` and the persisted projection schema are untouched. History that ended before the service started raises no reminder, which keeps "existing history reads as read" without a startup scan. The failure flag therefore describes only turns this Host observed: marking a Session whose last turn failed before a restart shows the ordinary unread reminder. * 🐛 Preserve manual unread until explicit Session interaction * 🧪 Align cold Session reading snapshot with unloaded title * 🔖 chore(session): align session-read-state with 0.2.2-rc.2 Master moved the root and every released manifest to 0.2.2-rc.2, but the new dsh-session-read-state package still declared 0.2.2-rc.1, failing constraints, verify-version-sync, verify-npm-install-layout, and release:verify after the master merge. * ♻️ refactor(gateway): recognize Remote stream carrier loss by error code RemoteStream now decides whether a generation end or failure is a retryable carrier loss by the stable code 'gateway/carrier-lost' instead of `instanceof RemoteStreamCarrierError`. RemoteStreamCarrierError keeps working and carries that code, so existing callers are unchanged, while a Client feature package can return a coded Error from `ended` without importing the class. The new RemoteStreamCarrierFailure type describes such errors; terminal-controller classifies disconnects the same way. * ♻️ refactor(session): move Session reading into ui-session-status Fold the reading feature into the single package packages/client/ui-session-status and delete session-read-state. - Host face: SessionStatusService keeps in-memory reading records and serves the sessionStatus Remote namespace (mark, follow) with session-status/* error codes; its service key is registered only for Gateway discovery and is not declared on Context. - Client face: a package-internal reading model follows the Host stream through RemoteSnapshotStream; ctx.uiSession.sessionStatus folds the records into completionUnread and completionFailed and exposes mark and readingReady; main-view acknowledgement and the session-status/read-intent event live here. No reading service or type is exported. - verify-client-packages lets a packages/client feature package request packages/api rows through dsh.client.external; feature-to-feature requests stay rejected. - ui-workspace, ui-conversation, bundles, remotes, LiveShare, the client test runtime, docs, Agent Notes, and the upgrade guide follow. * ♻️ refactor(session): clear manual unread only when the main view switches to the Session Remove the session-status/read-intent event. ui-session-status now clears an existing manual unread mark when the main view switches to a different Session, including the first selection after a page load, once the reading baseline is ready and the body arrives. Window focus, visibility changes, a replaced binding for the same Session, and activity in the open Session preserve manual unread. ui-conversation returns to master (only the ui-session-status client tsconfig reference remains), and ui-workspace navigation no longer emits the event. Tests, the session-reading Web e2e case, READMEs, and the reading Agent Note follow the new rule. * 🐛 fix(session): address the Session status review findings - Open the reading stream only while ctx.remoteAccess allows sessionStatus/follow, so a LiveShare viewer opens no owner-only stream, keeps readingReady false, and logs no synchronization failure; access changes start or stop the stream. - Hide the unacknowledged completion of the Session the visible, focused main view retains; manual marks stay visible, completionFailed follows completionUnread, and the reminder returns on blur, hiding, or a switch. - Declare ctx.sessionStatus on Context and restore its SERVICE_PAGE and SERVICE_ROLES entries; the service and SessionRead* types document on docs/subsystems/web-client.md, which now owns the reading section with the failed field. - Document that a Host plugin reload can leave the Client with a terminal error until a page reload; drop the redundant types import and the unused publish() result. - Archived Sessions read as read and offer no reading mark in the row menu or the toggle-read shortcut. - session.toggleRead names the open dialog, open panel, or archived Session that blocks it instead of asking to select a Session. - isRemoteStreamCarrierFailure rejects a RemoteError from the Host even when it carries gateway/carrier-lost; the code is Client-local. - ./types is types-only like ui-trajectory, and files no longer ship lib/types JavaScript. * 🐛 fix(session): close the remaining Session status review gaps - The Gateway Client exports isRemoteStreamCarrierFailure, and the terminal view uses it, so a Host RemoteError carrying the carrier code shows as failed rather than disconnected. - Each access grant's reading stream carries a token: frames a revoked or superseded stream still delivers are discarded, and cleanup waits for disposal before leaving reading unavailable unless a newer grant is active. - The status table hides the viewed Session's natural reminder only while that Session is open; the panel case is a documented limitation. - The README limitation and the upgrade guide state that only the main-view switch rule, including a reload restore, clears manual unread automatically. - Add the missing blank line before the next heading in the web-client reading section. * ♻️ refactor(session): install reading under the Session status table - apply returns to master's form plus one line: UiSessionStatus is the root, published as the useSessionStatus source, and installReading() from the new src/client/read.ts follows Host reading records into it. UiSessionStatus takes master's three constructor parameters and creates its own SessionReadModel as the package-internal `reading` member; installSessionStatus is removed and acknowledge.ts stays a separate file. - The viewed Session's snapshot subscription republishes the table only when its openState changes, so streamed events do not rebuild it. - Remove the obsolete Dev Note sentence about failure outcomes. - session.toggleRead passes when the Peer may not mark reading, matching the row menu, and reports readingUnavailable only while unsynchronized. --------- Co-authored-by: imccyu <[email protected]> Co-authored-by: imccyu <[email protected]>
228 lines
9.2 KiB
TypeScript
228 lines
9.2 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { act, cleanup, renderHook } from '@testing-library/react'
|
|
import type { SessionLiveEventEntry } from '@deepseek-ai/dsh-api-session-controller/client'
|
|
import { createSnapshotStore } from '@deepseek-ai/dsh-client-store'
|
|
import { EMPTY_CHAT_SNAPSHOT } from '@deepseek-ai/dsh-client-ui-chat/client'
|
|
import { EMPTY_CONVERSATION_SNAPSHOT } from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
|
import type { WorkspaceId } from '@deepseek-ai/dsh-api-workspace-controller/client'
|
|
import type { MainPanelId, PanelInfo } from '@deepseek-ai/dsh-client-ui-layout/client'
|
|
import type { PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
|
|
import { afterAll, afterEach, describe, expect, it, vi } from 'vitest'
|
|
import {
|
|
allowAllAccess,
|
|
bindSnapshotSelector,
|
|
chatSnapshot,
|
|
conversationSnapshot,
|
|
SlotTestRuntime,
|
|
usePinnedBrowserLanguages,
|
|
} from '../src/index.ts'
|
|
|
|
const originalLanguages = [...navigator.languages]
|
|
const originalLanguage = navigator.language
|
|
|
|
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
interface SlotMap {
|
|
'trt.panel-info': { kind: 'keyed'; scope: 'root'; owner: { label: string } }
|
|
}
|
|
}
|
|
|
|
usePinnedBrowserLanguages('zh-CN', 'en-US')
|
|
afterEach(cleanup)
|
|
afterAll(() => {
|
|
expect(navigator.languages).toEqual(originalLanguages)
|
|
expect(navigator.language).toBe(originalLanguage)
|
|
})
|
|
|
|
function entry(seq: number): SessionLiveEventEntry {
|
|
return {
|
|
type: 'event',
|
|
event: {
|
|
type: 'fixture/event',
|
|
seq,
|
|
time: seq,
|
|
data: { seq },
|
|
ignorable: true,
|
|
} as unknown as SessionLiveEventEntry['event'],
|
|
}
|
|
}
|
|
|
|
describe('fixture helpers', () => {
|
|
it('allows every action on every resource through the hand-built access Hooks', () => {
|
|
expect(allowAllAccess.useRemoteAccess('session/list')).toBe(true)
|
|
expect(allowAllAccess.useAccess('session/fork')).toBe(true)
|
|
expect(allowAllAccess.useSessionAccess('s1' as SessionId, 'session/fork')).toBe(true)
|
|
expect(allowAllAccess.useWorkspaceAccess('w1' as WorkspaceId, 'workspace/follow')).toBe(true)
|
|
})
|
|
|
|
it('installs an allow-all remoteAccess service whose sources never change', async () => {
|
|
const runtime = await SlotTestRuntime.create()
|
|
try {
|
|
const source = runtime.ctx.remoteAccess.source('session', 's1', 'session/fork')
|
|
expect(source.getSnapshot()).toBe(true)
|
|
const unsubscribe = source.subscribe(() => {})
|
|
unsubscribe()
|
|
expect(source.getSnapshot()).toBe(true)
|
|
} finally {
|
|
await runtime.dispose()
|
|
}
|
|
})
|
|
|
|
it('retracts default root sources without removing their live replacements', async () => {
|
|
const runtime = await SlotTestRuntime.create()
|
|
const hooks = { workspaces: runtime.workspaces.list, panelInfo: runtime.panelInfo }
|
|
let releaseReplacement: (() => void) | undefined
|
|
try {
|
|
runtime.releaseWorkspaceSource()
|
|
runtime.releasePanelInfoSource()
|
|
releaseReplacement = runtime.slots.provideRoot({ hooks })
|
|
runtime.releaseWorkspaceSource()
|
|
runtime.releasePanelInfoSource()
|
|
for (const key of ['workspaces', 'panelInfo'] as const) {
|
|
expect(() => runtime.slots.provideRoot({ hooks: { [key]: hooks[key] } }))
|
|
.toThrow(`duplicate root standard hook '${key}'`)
|
|
}
|
|
} finally {
|
|
try {
|
|
releaseReplacement?.()
|
|
runtime.releaseWorkspaceSource()
|
|
runtime.releasePanelInfoSource()
|
|
} finally {
|
|
await runtime.dispose()
|
|
}
|
|
}
|
|
})
|
|
|
|
it('drives panel hooks, retains keyed selection on owner updates, and releases the default source', async () => {
|
|
const runtime = await SlotTestRuntime.create()
|
|
try {
|
|
await runtime.declare({ 'trt.panel-info': { kind: 'keyed', scope: 'root' } })
|
|
runtime.slots.register({ name: 'trt.panel-info', key: 'probe' },
|
|
({ usePanelInfo, label }: PropsRuntime<'trt.panel-info'>) => (
|
|
<span>{label}:{usePanelInfo(info => info.activePanelId) ?? 'conversation'}</span>
|
|
))
|
|
const view = runtime.renderSlot('trt.panel-info', { label: 'first' }, { entryKey: 'probe' })
|
|
expect(view.container.textContent).toBe('first:conversation')
|
|
act(() => { runtime.panelInfo.set({ activePanelId: 'custom' as MainPanelId }) })
|
|
expect(view.container.textContent).toBe('first:custom')
|
|
view.update({ label: 'next' })
|
|
expect(view.container.textContent).toBe('next:custom')
|
|
const replacement = createSnapshotStore<PanelInfo>({ activePanelId: null })
|
|
await act(async () => {
|
|
runtime.releasePanelInfoSource()
|
|
await runtime.mount({
|
|
inject: ['slots'],
|
|
apply(ctx) { ctx.slots.provideRoot({ hooks: { panelInfo: replacement } }) },
|
|
})
|
|
})
|
|
expect(view.container.textContent).toBe('next:conversation')
|
|
} finally {
|
|
await runtime.dispose()
|
|
}
|
|
})
|
|
|
|
it('rejects uploads and reading marks until a suite replaces their default stubs', async () => {
|
|
const runtime = await SlotTestRuntime.create()
|
|
expect(runtime.ctx.uiSession.sessionStatus.readingReady.getSnapshot()).toBe(true)
|
|
await expect(runtime.fileUpload.upload('fixture-session' as SessionId)).rejects.toThrow('file upload is not stubbed')
|
|
await expect(runtime.ctx.uiSession.sessionStatus.mark('fixture-session' as SessionId, true)).rejects.toThrow('reading mark is not stubbed')
|
|
await expect(runtime.fileUpload.uploadImage('fixture-session' as SessionId)).rejects.toThrow('image upload is not stubbed')
|
|
await runtime.dispose()
|
|
})
|
|
|
|
it('builds independent Conversation and Chat snapshots with optional overrides', () => {
|
|
const conversation = conversationSnapshot()
|
|
expect(conversation).toEqual(EMPTY_CONVERSATION_SNAPSHOT)
|
|
expect(conversation).not.toBe(EMPTY_CONVERSATION_SNAPSHOT)
|
|
const activeTargets = new Set(['chat'])
|
|
expect(conversationSnapshot({ activeTargets }).activeTargets).toBe(activeTargets)
|
|
|
|
const chat = chatSnapshot()
|
|
expect(chat).toEqual(EMPTY_CHAT_SNAPSHOT)
|
|
expect(chat).not.toBe(EMPTY_CHAT_SNAPSHOT)
|
|
const order = ['node-1']
|
|
expect(chatSnapshot({ order }).order).toBe(order)
|
|
})
|
|
|
|
it('binds an observable snapshot through the production selector hook', () => {
|
|
const source = createSnapshotStore({ value: 1 })
|
|
const useValue = bindSnapshotSelector(source)
|
|
const view = renderHook(() => useValue(snapshot => snapshot.value))
|
|
expect(view.result.current).toBe(1)
|
|
|
|
act(() => { source.update((draft) => { draft.value = 2 }) })
|
|
expect(view.result.current).toBe(2)
|
|
})
|
|
|
|
it('pins both browser language fields for the calling suite', () => {
|
|
expect(navigator.languages).toEqual(['zh-CN', 'en-US'])
|
|
expect(navigator.language).toBe('zh-CN')
|
|
})
|
|
})
|
|
|
|
describe('Session fixture lifecycle', () => {
|
|
it('initializes and drives complete event windows through replace, prepend, and append', async () => {
|
|
const runtime = await SlotTestRuntime.create()
|
|
const first = entry(1)
|
|
const older = entry(0)
|
|
const live = entry(2)
|
|
|
|
await runtime.sessions.add({ id: 'events', events: [first] })
|
|
expect(runtime.sessions.behavior('events').eventSource.getSnapshot()).toMatchObject({
|
|
entries: [first],
|
|
hasMore: false,
|
|
change: { kind: 'replace', entries: [first] },
|
|
})
|
|
|
|
await runtime.sessions.add({ id: 'has-more', hasMore: true })
|
|
expect(runtime.sessions.behavior('has-more').eventSource.getSnapshot()).toMatchObject({
|
|
entries: [],
|
|
hasMore: true,
|
|
})
|
|
|
|
await runtime.sessions.replaceEvents('events', [first])
|
|
await runtime.sessions.prependEvents('events', [older])
|
|
await runtime.sessions.appendEvent('events', live)
|
|
expect(runtime.sessions.behavior('events').eventSource.getSnapshot()).toMatchObject({
|
|
entries: [older, first, live],
|
|
hasMore: false,
|
|
change: { kind: 'append', entries: [live] },
|
|
})
|
|
await runtime.dispose()
|
|
})
|
|
|
|
it('requires an explicit create stub and records successful create and refresh calls', async () => {
|
|
const runtime = await SlotTestRuntime.create()
|
|
await expect(runtime.sessions.create()).rejects.toThrow(/create is not stubbed/)
|
|
await runtime.sessions.add({ id: 'created' })
|
|
const create = vi.fn(() => Promise.resolve('created' as SessionId))
|
|
runtime.sessions.stubCreate(create)
|
|
|
|
await expect(runtime.sessions.create({ cwd: '/workspace' })).resolves.toBe('created')
|
|
await expect(runtime.sessions.refresh()).resolves.toBeUndefined()
|
|
expect(create).toHaveBeenCalledWith({ cwd: '/workspace' })
|
|
expect(runtime.sessions.calls.slice(-2)).toEqual([
|
|
{ method: 'create', args: [{ cwd: '/workspace' }] },
|
|
{ method: 'refresh', args: [] },
|
|
])
|
|
await runtime.dispose()
|
|
})
|
|
|
|
it('borrows only retained scopes and disposes their generation with the runtime', async () => {
|
|
const runtime = await SlotTestRuntime.create()
|
|
await runtime.sessions.add({ id: 'scope-only' })
|
|
expect(runtime.sessions.scope('scope-only')).toBeUndefined()
|
|
const reference = runtime.sessions.retain('scope-only' as SessionId)
|
|
await reference.ready
|
|
const scope = runtime.sessions.scope('scope-only')
|
|
expect(scope).toBeDefined()
|
|
const release = vi.fn()
|
|
scope?.effect(() => release, 'fixture scope release')
|
|
|
|
runtime.releaseWorkspaceSource()
|
|
await runtime.dispose()
|
|
expect(release).toHaveBeenCalledOnce()
|
|
expect(() => reference.binding).toThrow('released')
|
|
})
|
|
})
|