@deepseek-ai/dsh-client-test-runtime 0.2.2-rc.1 → 0.2.2-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +2 -2
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/lib/index.js +9 -0
- package/lib/types/access.d.ts.map +1 -0
- package/lib/types/access.js.map +1 -0
- package/lib/types/assembly/bundle-roster.d.ts.map +1 -0
- package/lib/types/assembly/bundle-roster.js.map +1 -0
- package/lib/types/assembly/index.d.ts.map +1 -0
- package/lib/types/assembly/index.js.map +1 -0
- package/lib/types/assembly/modules.d.ts.map +1 -0
- package/lib/types/assembly/modules.js.map +1 -0
- package/lib/types/assembly/remote-default-responses.d.ts.map +1 -0
- package/lib/types/assembly/remote-default-responses.js.map +1 -0
- package/lib/types/assembly/remote-proxies.d.ts.map +1 -0
- package/lib/types/assembly/remote-proxies.js.map +1 -0
- package/lib/types/assembly/roster.d.ts.map +1 -0
- package/lib/types/assembly/roster.js.map +1 -0
- package/lib/types/assembly/test-client.d.ts +10 -2
- package/lib/types/assembly/test-client.d.ts.map +1 -0
- package/lib/types/assembly/test-client.js.map +1 -0
- package/lib/types/assembly/vitest.d.ts +1 -1
- package/lib/types/assembly/vitest.d.ts.map +1 -0
- package/lib/types/assembly/vitest.js.map +1 -0
- package/lib/types/config-form.d.ts.map +1 -0
- package/lib/types/config-form.js.map +1 -0
- package/lib/types/context-menu.d.ts.map +1 -0
- package/lib/types/context-menu.js.map +1 -0
- package/lib/types/fixtures.d.ts.map +1 -0
- package/lib/types/fixtures.js.map +1 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/locale-env.d.ts.map +1 -0
- package/lib/types/locale-env.js.map +1 -0
- package/lib/types/remote.d.ts.map +1 -0
- package/lib/types/remote.js.map +1 -0
- package/lib/types/sessions.d.ts +5 -0
- package/lib/types/sessions.d.ts.map +1 -0
- package/lib/types/sessions.js.map +1 -0
- package/lib/types/snapshot.d.ts.map +1 -0
- package/lib/types/snapshot.js.map +1 -0
- package/lib/types/translate.d.ts.map +1 -0
- package/lib/types/translate.js.map +1 -0
- package/lib/types/workspaces.d.ts.map +1 -0
- package/lib/types/workspaces.js.map +1 -0
- package/package.json +53 -50
- package/src/access.ts +95 -0
- package/src/assembly/bundle-roster.ts +167 -0
- package/src/assembly/index.ts +14 -0
- package/src/assembly/modules.ts +80 -0
- package/src/assembly/remote-default-responses.ts +64 -0
- package/src/assembly/remote-proxies.ts +87 -0
- package/src/assembly/roster.ts +163 -0
- package/src/assembly/test-client.ts +388 -0
- package/src/assembly/vitest.ts +60 -0
- package/src/config-form.ts +61 -0
- package/src/context-menu.ts +17 -0
- package/src/fixtures.ts +119 -0
- package/src/index.ts +490 -0
- package/src/locale-env.ts +29 -0
- package/src/remote.ts +103 -0
- package/src/sessions.ts +844 -0
- package/src/snapshot.ts +89 -0
- package/src/translate.ts +32 -0
- package/src/workspaces.ts +210 -0
package/src/snapshot.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM snapshot hygiene: a vitest snapshot serializer that keeps `.snap`
|
|
3
|
+
* files structural. Two normalizations, both on a clone (the live DOM is
|
|
4
|
+
* untouched, so class/tag queries keep working):
|
|
5
|
+
*
|
|
6
|
+
* - CSS-module scoped class names (`_frame_334d2d`, this repo's
|
|
7
|
+
* `_[local]_[hash]` shape) fold back to their semantic local (`frame`), so
|
|
8
|
+
* CSS edits do not churn snapshots.
|
|
9
|
+
* - `<svg>` internals collapse to a `data-content` fingerprint on the svg
|
|
10
|
+
* element: path geometry is print noise, but the fingerprint still flips
|
|
11
|
+
* when an icon's artwork actually changes.
|
|
12
|
+
*/
|
|
13
|
+
import { expect } from 'vitest'
|
|
14
|
+
import type { SnapshotSerializer } from 'vitest'
|
|
15
|
+
|
|
16
|
+
/** One scoped class token: `_<local>_<hash>` (local may itself contain underscores). */
|
|
17
|
+
const SCOPED_CLASS = /^_(.+)_[a-z0-9]+$/
|
|
18
|
+
|
|
19
|
+
/** Fold scoped tokens in one class attribute value; foreign tokens pass through. */
|
|
20
|
+
function normalizeClassValue(value: string): string {
|
|
21
|
+
return value
|
|
22
|
+
.split(/\s+/)
|
|
23
|
+
.filter(token => token !== '')
|
|
24
|
+
.map(token => token.replace(SCOPED_CLASS, '$1'))
|
|
25
|
+
.join(' ')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** FNV-1a 32-bit over the svg markup: deterministic, dependency-free fingerprint. */
|
|
29
|
+
function fingerprint(markup: string): string {
|
|
30
|
+
let hash = 0x811c9dc5
|
|
31
|
+
for (let i = 0; i < markup.length; i++) {
|
|
32
|
+
hash ^= markup.charCodeAt(i)
|
|
33
|
+
hash = Math.imul(hash, 0x01000193)
|
|
34
|
+
}
|
|
35
|
+
return (hash >>> 0).toString(16).padStart(8, '0')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** svg elements of a subtree, the root included when it is one. */
|
|
39
|
+
function svgsOf(root: Element): Element[] {
|
|
40
|
+
const svgs: Element[] = [...root.querySelectorAll('svg')]
|
|
41
|
+
if (root.tagName.toLowerCase() === 'svg') svgs.unshift(root)
|
|
42
|
+
return svgs
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Whether serializing this subtree needs a normalized clone. */
|
|
46
|
+
function needsNormalization(root: Element): boolean {
|
|
47
|
+
const scoped = [root, ...root.querySelectorAll('[class]')].some((el) => {
|
|
48
|
+
const value = el.getAttribute('class')
|
|
49
|
+
return value !== null && value.split(/\s+/).some(token => SCOPED_CLASS.test(token))
|
|
50
|
+
})
|
|
51
|
+
return scoped || svgsOf(root).some(svg => svg.childNodes.length > 0)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The serializer plugin. Matches DOM elements whose subtree carries a scoped
|
|
56
|
+
* class or svg internals; serializes a normalized clone, which no longer
|
|
57
|
+
* matches, so printing falls through to the built-in DOM element serializer.
|
|
58
|
+
*/
|
|
59
|
+
export const domSnapshotSerializer: SnapshotSerializer = {
|
|
60
|
+
test(value: unknown): boolean {
|
|
61
|
+
return typeof Element !== 'undefined' && value instanceof Element && needsNormalization(value)
|
|
62
|
+
},
|
|
63
|
+
serialize(value, config, indentation, depth, refs, printer): string {
|
|
64
|
+
const clone = (value as Element).cloneNode(true) as Element
|
|
65
|
+
for (const el of [clone, ...clone.querySelectorAll('[class]')]) {
|
|
66
|
+
const raw = el.getAttribute('class')
|
|
67
|
+
if (raw !== null) el.setAttribute('class', normalizeClassValue(raw))
|
|
68
|
+
}
|
|
69
|
+
for (const svg of svgsOf(clone)) {
|
|
70
|
+
if (svg.childNodes.length === 0) continue
|
|
71
|
+
svg.setAttribute('data-content', fingerprint(svg.innerHTML))
|
|
72
|
+
svg.replaceChildren()
|
|
73
|
+
}
|
|
74
|
+
return printer(clone, config, indentation, depth, refs)
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let registered = false
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Register {@link domSnapshotSerializer} with vitest's expect (idempotent).
|
|
82
|
+
* SlotTestRuntime.create() calls this; specs that snapshot DOM outside the
|
|
83
|
+
* runtime import and call it themselves.
|
|
84
|
+
*/
|
|
85
|
+
export function registerDomSnapshotSerializer(): void {
|
|
86
|
+
if (registered) return
|
|
87
|
+
registered = true
|
|
88
|
+
expect.addSnapshotSerializer(domSnapshotSerializer)
|
|
89
|
+
}
|
package/src/translate.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test double of the locale lookup chain: a translate stub over plain
|
|
3
|
+
* dictionaries, mirroring LocaleRuntime's resolution order (first dictionary
|
|
4
|
+
* that owns the key wins, then the key itself stays visible) and its
|
|
5
|
+
* `{name}` template interpolation. Specs stub the framework-injected `t`
|
|
6
|
+
* seat with `makeTranslate(zh, commonZh)` instead of re-implementing the
|
|
7
|
+
* chain per suite.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Build a translate stub resolving through `dicts` in order (namespace
|
|
12
|
+
* first, then the shared common vocabulary), falling back to the key.
|
|
13
|
+
* @param dicts - dictionaries consulted in order.
|
|
14
|
+
* @returns the translate function (assignable to any `XxxProps['t']` seat).
|
|
15
|
+
*/
|
|
16
|
+
export function makeTranslate(
|
|
17
|
+
...dicts: readonly Record<string, string>[]
|
|
18
|
+
): (key: string, params?: Record<string, unknown>) => string {
|
|
19
|
+
return (key, params) => {
|
|
20
|
+
let template = key
|
|
21
|
+
for (const dict of dicts) {
|
|
22
|
+
const hit = dict[key]
|
|
23
|
+
if (hit !== undefined) {
|
|
24
|
+
template = hit
|
|
25
|
+
break
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!params) return template
|
|
29
|
+
return template.replace(/\{(\w+)\}/g, (match, name: string) =>
|
|
30
|
+
name in params ? String(params[name]) : match)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/** Test-owned workspaces face: the renderer standard-kit observable plus recorded actions. */
|
|
2
|
+
import { createSnapshotStore } from '@deepseek-ai/dsh-client-store'
|
|
3
|
+
import type {
|
|
4
|
+
IWorkspaces, WorkspaceId, WorkspaceSnapshot, WorkspaceView,
|
|
5
|
+
} from '@deepseek-ai/dsh-api-workspace-controller/client'
|
|
6
|
+
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
|
7
|
+
import type { SnapshotStore } from '@deepseek-ai/dsh-client-store'
|
|
8
|
+
import { workspaceSnapshot } from './fixtures.ts'
|
|
9
|
+
import type { FixtureSnapshot, Stabilizer } from './fixtures.ts'
|
|
10
|
+
|
|
11
|
+
/** Writable test representation of the immutable Workspace Controller snapshot. */
|
|
12
|
+
type WorkspaceFixtureSnapshot = FixtureSnapshot<WorkspaceSnapshot>
|
|
13
|
+
|
|
14
|
+
/** Callable command names on the production Workspace Controller face. */
|
|
15
|
+
type WorkspaceAction = {
|
|
16
|
+
[Key in keyof IWorkspaces]: IWorkspaces[Key] extends (...args: never[]) => unknown ? Key : never
|
|
17
|
+
}[keyof IWorkspaces]
|
|
18
|
+
|
|
19
|
+
/** Test replacement retaining one Controller command's parameters and result. */
|
|
20
|
+
type WorkspaceStub<Key extends WorkspaceAction> = (
|
|
21
|
+
...args: Parameters<IWorkspaces[Key]>
|
|
22
|
+
) => ReturnType<IWorkspaces[Key]>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Workspaces test double. Implements the same IWorkspaces face features
|
|
26
|
+
* receive as `ctx.workspaces`, so a production face change breaks this
|
|
27
|
+
* double at compile time. Every action records into {@link
|
|
28
|
+
* TestWorkspaces.calls}; defaults are inert echoes — feature tests needing
|
|
29
|
+
* richer behavior replace them via {@link TestWorkspaces.stub}.
|
|
30
|
+
*/
|
|
31
|
+
export class TestWorkspaces implements IWorkspaces {
|
|
32
|
+
/** The useWorkspaces standard feed. */
|
|
33
|
+
readonly list: SnapshotStore<WorkspaceFixtureSnapshot>
|
|
34
|
+
|
|
35
|
+
/** Calls observed on the action face, newest last. */
|
|
36
|
+
readonly calls: { method: string; args: unknown[] }[] = []
|
|
37
|
+
|
|
38
|
+
/** Replaceable action seat: feature tests may stub richer behavior. */
|
|
39
|
+
private readonly stubs = new Map<WorkspaceAction, (...args: unknown[]) => unknown>()
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param stabilize - the owning runtime's act wrapper.
|
|
43
|
+
*/
|
|
44
|
+
constructor(private readonly stabilize: Stabilizer) {
|
|
45
|
+
this.list = createSnapshotStore<WorkspaceFixtureSnapshot>({ ...workspaceSnapshot() })
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Update the workspace list state through an immer draft.
|
|
50
|
+
* @param mutate - draft mutator.
|
|
51
|
+
*/
|
|
52
|
+
async update(mutate: (draft: WorkspaceFixtureSnapshot) => void): Promise<void> {
|
|
53
|
+
await this.stabilize(() => { this.list.update(mutate) })
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Replace an action's behavior (the recorded call is still appended first).
|
|
58
|
+
* @param method - Controller action name (e.g. 'create').
|
|
59
|
+
* @param impl - replacement behavior.
|
|
60
|
+
*/
|
|
61
|
+
stub<Key extends WorkspaceAction>(method: Key, impl: WorkspaceStub<Key>): void {
|
|
62
|
+
this.stubs.set(method, impl as (...args: unknown[]) => unknown)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Create a Workspace (recorded). The default echoes a view derived from
|
|
67
|
+
* the input; stub for failure or list-coupled flows.
|
|
68
|
+
* @param input - the Host create payload.
|
|
69
|
+
* @returns the created Workspace view.
|
|
70
|
+
*/
|
|
71
|
+
async create(input: { path: string }): Promise<WorkspaceView> {
|
|
72
|
+
this.calls.push({ method: 'create', args: [input] })
|
|
73
|
+
const stub = this.stubs.get('create')
|
|
74
|
+
if (stub !== undefined) return await (stub(input) as Promise<WorkspaceView>)
|
|
75
|
+
return {
|
|
76
|
+
workspaceId: `ws-${input.path}` as WorkspaceId,
|
|
77
|
+
title: input.path,
|
|
78
|
+
path: input.path,
|
|
79
|
+
sessionIds: [],
|
|
80
|
+
} as unknown as WorkspaceView
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Initialize the default Workspace through a test stub; defaults to an ineligible first use.
|
|
85
|
+
* @param signal - caller lifetime.
|
|
86
|
+
* @returns the stubbed Workspace, or undefined when initialization is ineligible.
|
|
87
|
+
*/
|
|
88
|
+
async initializeDefault(signal?: AbortSignal): Promise<WorkspaceView | undefined> {
|
|
89
|
+
this.calls.push({ method: 'initializeDefault', args: [signal] })
|
|
90
|
+
const stub = this.stubs.get('initializeDefault')
|
|
91
|
+
return await (stub?.(signal) as Promise<WorkspaceView | undefined> | undefined)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Rename a Workspace (recorded). The default echoes a minimal view.
|
|
96
|
+
* @param workspaceId - target workspace.
|
|
97
|
+
* @param title - new title.
|
|
98
|
+
* @returns the updated view.
|
|
99
|
+
*/
|
|
100
|
+
async rename(workspaceId: WorkspaceId, title: string): Promise<WorkspaceView> {
|
|
101
|
+
this.calls.push({ method: 'rename', args: [workspaceId, title] })
|
|
102
|
+
const stub = this.stubs.get('rename')
|
|
103
|
+
if (stub !== undefined) return await (stub(workspaceId, title) as Promise<WorkspaceView>)
|
|
104
|
+
return { workspaceId, title, path: `/${title}`, sessionIds: [] } as unknown as WorkspaceView
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Delete a Workspace (recorded; default no-op).
|
|
109
|
+
* @param workspaceId - target workspace.
|
|
110
|
+
*/
|
|
111
|
+
async delete(workspaceId: WorkspaceId): Promise<void> {
|
|
112
|
+
this.calls.push({ method: 'delete', args: [workspaceId] })
|
|
113
|
+
await (this.stubs.get('delete')?.(workspaceId) as Promise<void> | undefined)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Move a Workspace in display order (recorded; default no-op).
|
|
118
|
+
* @param workspaceId - Workspace to move.
|
|
119
|
+
* @param beforeWorkspaceId - Anchor; omitted appends.
|
|
120
|
+
*/
|
|
121
|
+
async insertBefore(workspaceId: WorkspaceId, beforeWorkspaceId?: WorkspaceId): Promise<void> {
|
|
122
|
+
this.calls.push({ method: 'insertBefore', args: [workspaceId, beforeWorkspaceId] })
|
|
123
|
+
await (this.stubs.get('insertBefore')?.(workspaceId, beforeWorkspaceId) as Promise<void> | undefined)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Move an accounted session (recorded). The default echoes a minimal view.
|
|
128
|
+
* @param workspaceId - target workspace.
|
|
129
|
+
* @param sessionId - session to move.
|
|
130
|
+
* @param beforeSessionId - anchor; omitted appends.
|
|
131
|
+
* @returns the updated view.
|
|
132
|
+
*/
|
|
133
|
+
async insertSessionBefore(workspaceId: WorkspaceId, sessionId: SessionId, beforeSessionId?: SessionId): Promise<WorkspaceView> {
|
|
134
|
+
this.calls.push({ method: 'insertSessionBefore', args: [workspaceId, sessionId, beforeSessionId] })
|
|
135
|
+
const stub = this.stubs.get('insertSessionBefore')
|
|
136
|
+
if (stub !== undefined) return await (stub(workspaceId, sessionId, beforeSessionId) as Promise<WorkspaceView>)
|
|
137
|
+
return { workspaceId, title: '', path: '', sessionIds: [sessionId] } as unknown as WorkspaceView
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Archive a session (recorded). The default mirrors the production face's
|
|
142
|
+
* observable effect: the id joins the list state's archive set.
|
|
143
|
+
* @param sessionId - session to archive.
|
|
144
|
+
*/
|
|
145
|
+
async archiveSession(sessionId: SessionId): Promise<void> {
|
|
146
|
+
this.calls.push({ method: 'archiveSession', args: [sessionId] })
|
|
147
|
+
const stub = this.stubs.get('archiveSession')
|
|
148
|
+
if (stub !== undefined) {
|
|
149
|
+
await (stub(sessionId) as Promise<void>)
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
await this.update((draft) => {
|
|
153
|
+
draft.archivedSessionIds = [...draft.archivedSessionIds, sessionId]
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Unarchive a session (recorded). The default mirrors the production face's
|
|
159
|
+
* observable effect: the id leaves the list state's archive set.
|
|
160
|
+
* @param sessionId - session to unarchive.
|
|
161
|
+
*/
|
|
162
|
+
async unarchiveSession(sessionId: SessionId): Promise<void> {
|
|
163
|
+
this.calls.push({ method: 'unarchiveSession', args: [sessionId] })
|
|
164
|
+
const stub = this.stubs.get('unarchiveSession')
|
|
165
|
+
if (stub !== undefined) {
|
|
166
|
+
await (stub(sessionId) as Promise<void>)
|
|
167
|
+
return
|
|
168
|
+
}
|
|
169
|
+
await this.update((draft) => {
|
|
170
|
+
draft.archivedSessionIds = draft.archivedSessionIds.filter(id => id !== sessionId)
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Pin a session (recorded). The default mirrors the production face's
|
|
176
|
+
* observable effect: the id leads the list state's pin set.
|
|
177
|
+
* @param sessionId - session to pin.
|
|
178
|
+
*/
|
|
179
|
+
async pinSession(sessionId: SessionId): Promise<void> {
|
|
180
|
+
this.calls.push({ method: 'pinSession', args: [sessionId] })
|
|
181
|
+
const stub = this.stubs.get('pinSession')
|
|
182
|
+
if (stub !== undefined) {
|
|
183
|
+
await (stub(sessionId) as Promise<void>)
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
await this.update((draft) => {
|
|
187
|
+
draft.pinnedSessionIds = [
|
|
188
|
+
sessionId,
|
|
189
|
+
...draft.pinnedSessionIds.filter(id => id !== sessionId),
|
|
190
|
+
]
|
|
191
|
+
})
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Unpin a session (recorded). The default mirrors the production face's
|
|
196
|
+
* observable effect: the id leaves the list state's pin set.
|
|
197
|
+
* @param sessionId - session to unpin.
|
|
198
|
+
*/
|
|
199
|
+
async unpinSession(sessionId: SessionId): Promise<void> {
|
|
200
|
+
this.calls.push({ method: 'unpinSession', args: [sessionId] })
|
|
201
|
+
const stub = this.stubs.get('unpinSession')
|
|
202
|
+
if (stub !== undefined) {
|
|
203
|
+
await (stub(sessionId) as Promise<void>)
|
|
204
|
+
return
|
|
205
|
+
}
|
|
206
|
+
await this.update((draft) => {
|
|
207
|
+
draft.pinnedSessionIds = draft.pinnedSessionIds.filter(id => id !== sessionId)
|
|
208
|
+
})
|
|
209
|
+
}
|
|
210
|
+
}
|