@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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-client-test-runtime",
|
|
3
3
|
"description": "Browser test runtimes: a jsdom slot bench with test-owned Session and Workspace doubles, and a whole-client tier that boots the web roster through the production bootClient over an endpoint-named Remote mock",
|
|
4
|
-
"version": "0.2.2-rc.
|
|
4
|
+
"version": "0.2.2-rc.3",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -32,67 +32,70 @@
|
|
|
32
32
|
"@deepseek-ai/cordis": "~4.1.0",
|
|
33
33
|
"@deepseek-ai/cordis-plugin-include": "~1.1.0",
|
|
34
34
|
"@deepseek-ai/cordis-plugin-loader": "~1.1.0",
|
|
35
|
-
"@deepseek-ai/dsh-api-gateway": "0.2.2-rc.
|
|
36
|
-
"@deepseek-ai/dsh-api-session-controller": "0.2.2-rc.
|
|
37
|
-
"@deepseek-ai/dsh-api-workspace-controller": "0.2.2-rc.
|
|
38
|
-
"@deepseek-ai/dsh-attachment": "0.2.2-rc.
|
|
39
|
-
"@deepseek-ai/dsh-client-connection": "0.2.2-rc.
|
|
40
|
-
"@deepseek-ai/dsh-client-hmr": "0.2.2-rc.
|
|
41
|
-
"@deepseek-ai/dsh-client-modules": "0.2.2-rc.
|
|
42
|
-
"@deepseek-ai/dsh-client-store": "0.2.2-rc.
|
|
43
|
-
"@deepseek-ai/dsh-client-ui-chat": "0.2.2-rc.
|
|
44
|
-
"@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.
|
|
45
|
-
"@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.
|
|
46
|
-
"@deepseek-ai/dsh-client-ui-session": "0.2.2-rc.
|
|
47
|
-
"@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.
|
|
48
|
-
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.
|
|
49
|
-
"@deepseek-ai/dsh-client-web": "0.2.2-rc.
|
|
50
|
-
"@deepseek-ai/dsh-remote-mock": "0.2.2-rc.
|
|
51
|
-
"@deepseek-ai/dsh-session": "0.2.2-rc.
|
|
52
|
-
"@deepseek-ai/dsh-subagent": "0.2.2-rc.
|
|
53
|
-
"@deepseek-ai/dsh-typert-protocol": "0.2.2-rc.
|
|
35
|
+
"@deepseek-ai/dsh-api-gateway": "0.2.2-rc.3",
|
|
36
|
+
"@deepseek-ai/dsh-api-session-controller": "0.2.2-rc.3",
|
|
37
|
+
"@deepseek-ai/dsh-api-workspace-controller": "0.2.2-rc.3",
|
|
38
|
+
"@deepseek-ai/dsh-attachment": "0.2.2-rc.3",
|
|
39
|
+
"@deepseek-ai/dsh-client-connection": "0.2.2-rc.3",
|
|
40
|
+
"@deepseek-ai/dsh-client-hmr": "0.2.2-rc.3",
|
|
41
|
+
"@deepseek-ai/dsh-client-modules": "0.2.2-rc.3",
|
|
42
|
+
"@deepseek-ai/dsh-client-store": "0.2.2-rc.3",
|
|
43
|
+
"@deepseek-ai/dsh-client-ui-chat": "0.2.2-rc.3",
|
|
44
|
+
"@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.3",
|
|
45
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.3",
|
|
46
|
+
"@deepseek-ai/dsh-client-ui-session": "0.2.2-rc.3",
|
|
47
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.3",
|
|
48
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.3",
|
|
49
|
+
"@deepseek-ai/dsh-client-web": "0.2.2-rc.3",
|
|
50
|
+
"@deepseek-ai/dsh-remote-mock": "0.2.2-rc.3",
|
|
51
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.3",
|
|
52
|
+
"@deepseek-ai/dsh-subagent": "0.2.2-rc.3",
|
|
53
|
+
"@deepseek-ai/dsh-typert-protocol": "0.2.2-rc.3",
|
|
54
54
|
"react": "^18.2.0",
|
|
55
55
|
"react-dom": "^18.2.0",
|
|
56
|
-
"@deepseek-ai/dsh-client-ui-context-menu": "0.2.2-rc.
|
|
56
|
+
"@deepseek-ai/dsh-client-ui-context-menu": "0.2.2-rc.3"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@deepseek-ai/cordis": "~4.1.0",
|
|
60
60
|
"@deepseek-ai/cordis-plugin-include": "~1.1.0",
|
|
61
61
|
"@deepseek-ai/cordis-plugin-loader": "~1.1.0",
|
|
62
|
-
"@deepseek-ai/dsh-api-gateway": "0.2.2-rc.
|
|
63
|
-
"@deepseek-ai/dsh-api-remote-access": "0.2.2-rc.
|
|
64
|
-
"@deepseek-ai/dsh-api-remotes": "0.2.2-rc.
|
|
65
|
-
"@deepseek-ai/dsh-api-session-controller": "0.2.2-rc.
|
|
66
|
-
"@deepseek-ai/dsh-api-workspace-controller": "0.2.2-rc.
|
|
67
|
-
"@deepseek-ai/dsh-attachment": "0.2.2-rc.
|
|
68
|
-
"@deepseek-ai/dsh-base": "0.2.2-rc.
|
|
69
|
-
"@deepseek-ai/dsh-client-connection": "0.2.2-rc.
|
|
70
|
-
"@deepseek-ai/dsh-client-hmr": "0.2.2-rc.
|
|
71
|
-
"@deepseek-ai/dsh-client-locale": "0.2.2-rc.
|
|
72
|
-
"@deepseek-ai/dsh-client-modules": "0.2.2-rc.
|
|
73
|
-
"@deepseek-ai/dsh-client-store": "0.2.2-rc.
|
|
74
|
-
"@deepseek-ai/dsh-client-ui-chat": "0.2.2-rc.
|
|
75
|
-
"@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.
|
|
76
|
-
"@deepseek-ai/dsh-client-ui-layout": "0.2.2-rc.
|
|
77
|
-
"@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.
|
|
78
|
-
"@deepseek-ai/dsh-client-ui-session": "0.2.2-rc.
|
|
79
|
-
"@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.
|
|
80
|
-
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.
|
|
81
|
-
"@deepseek-ai/dsh-client-ui-workspace": "0.2.2-rc.
|
|
82
|
-
"@deepseek-ai/dsh-client-web": "0.2.2-rc.
|
|
83
|
-
"@deepseek-ai/dsh-remote-mock": "0.2.2-rc.
|
|
84
|
-
"@deepseek-ai/dsh-session": "0.2.2-rc.
|
|
85
|
-
"@deepseek-ai/dsh-settings": "0.2.2-rc.
|
|
86
|
-
"@deepseek-ai/dsh-subagent": "0.2.2-rc.
|
|
87
|
-
"@deepseek-ai/dsh-typert-protocol": "0.2.2-rc.
|
|
88
|
-
"@deepseek-ai/dsh-web-app": "0.2.2-rc.
|
|
62
|
+
"@deepseek-ai/dsh-api-gateway": "0.2.2-rc.3",
|
|
63
|
+
"@deepseek-ai/dsh-api-remote-access": "0.2.2-rc.3",
|
|
64
|
+
"@deepseek-ai/dsh-api-remotes": "0.2.2-rc.3",
|
|
65
|
+
"@deepseek-ai/dsh-api-session-controller": "0.2.2-rc.3",
|
|
66
|
+
"@deepseek-ai/dsh-api-workspace-controller": "0.2.2-rc.3",
|
|
67
|
+
"@deepseek-ai/dsh-attachment": "0.2.2-rc.3",
|
|
68
|
+
"@deepseek-ai/dsh-base": "0.2.2-rc.3",
|
|
69
|
+
"@deepseek-ai/dsh-client-connection": "0.2.2-rc.3",
|
|
70
|
+
"@deepseek-ai/dsh-client-hmr": "0.2.2-rc.3",
|
|
71
|
+
"@deepseek-ai/dsh-client-locale": "0.2.2-rc.3",
|
|
72
|
+
"@deepseek-ai/dsh-client-modules": "0.2.2-rc.3",
|
|
73
|
+
"@deepseek-ai/dsh-client-store": "0.2.2-rc.3",
|
|
74
|
+
"@deepseek-ai/dsh-client-ui-chat": "0.2.2-rc.3",
|
|
75
|
+
"@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.3",
|
|
76
|
+
"@deepseek-ai/dsh-client-ui-layout": "0.2.2-rc.3",
|
|
77
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.3",
|
|
78
|
+
"@deepseek-ai/dsh-client-ui-session": "0.2.2-rc.3",
|
|
79
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.3",
|
|
80
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.3",
|
|
81
|
+
"@deepseek-ai/dsh-client-ui-workspace": "0.2.2-rc.3",
|
|
82
|
+
"@deepseek-ai/dsh-client-web": "0.2.2-rc.3",
|
|
83
|
+
"@deepseek-ai/dsh-remote-mock": "0.2.2-rc.3",
|
|
84
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.3",
|
|
85
|
+
"@deepseek-ai/dsh-settings": "0.2.2-rc.3",
|
|
86
|
+
"@deepseek-ai/dsh-subagent": "0.2.2-rc.3",
|
|
87
|
+
"@deepseek-ai/dsh-typert-protocol": "0.2.2-rc.3",
|
|
88
|
+
"@deepseek-ai/dsh-web-app": "0.2.2-rc.3",
|
|
89
89
|
"@types/js-yaml": "^4.0.9",
|
|
90
90
|
"react": "^18.2.0",
|
|
91
91
|
"react-dom": "^18.2.0",
|
|
92
|
-
"@deepseek-ai/dsh-client-ui-context-menu": "0.2.2-rc.
|
|
92
|
+
"@deepseek-ai/dsh-client-ui-context-menu": "0.2.2-rc.3"
|
|
93
93
|
},
|
|
94
94
|
"files": [
|
|
95
95
|
"lib/index.js",
|
|
96
|
-
"lib/types/**/*.d.ts"
|
|
96
|
+
"lib/types/**/*.d.ts",
|
|
97
|
+
"lib/types/**/*.d.ts.map",
|
|
98
|
+
"lib/**/*.js.map",
|
|
99
|
+
"src"
|
|
97
100
|
]
|
|
98
101
|
}
|
package/src/access.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static access for client specs. Production pages receive the
|
|
3
|
+
* `remoteAccess` Client service and the global-resource `useRemoteAccess` Hook
|
|
4
|
+
* from the remote-access Client plugin, and the Session and Workspace access
|
|
5
|
+
* Hooks (Session-scope `useAccess`, `useSessionAccess`, `useWorkspaceAccess`)
|
|
6
|
+
* from ui-session and ui-workspace over that service. The test runtimes
|
|
7
|
+
* install an allow-all service and `useRemoteAccess` Hook instead, and
|
|
8
|
+
* hand-built component props spread {@link allowAllAccess}; a spec of a
|
|
9
|
+
* refused path overrides one Hook or provides a {@link StaticRemoteAccess}
|
|
10
|
+
* that refuses the action.
|
|
11
|
+
* @module @deepseek-ai/dsh-client-test-runtime/src/access
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { Service, type Context } from '@deepseek-ai/cordis'
|
|
15
|
+
import type { AccessEffect, ClientRemoteAccess, RemoteEndpoint, TypertResourceKind } from '@deepseek-ai/dsh-api-remote-access/client'
|
|
16
|
+
import type { GlobalStandardProps, HostObservable, SessionStandardProps } from '@deepseek-ai/dsh-client-ui-slots'
|
|
17
|
+
import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
|
|
18
|
+
import type {} from '@deepseek-ai/dsh-client-ui-session/client'
|
|
19
|
+
import type {} from '@deepseek-ai/dsh-client-ui-workspace/client'
|
|
20
|
+
|
|
21
|
+
/** The access Hooks every Slot component receives. */
|
|
22
|
+
export type AccessStandardProps =
|
|
23
|
+
& Pick<GlobalStandardProps, 'useRemoteAccess' | 'useSessionAccess' | 'useWorkspaceAccess'>
|
|
24
|
+
& Pick<SessionStandardProps, 'useAccess'>
|
|
25
|
+
|
|
26
|
+
/** Access Hooks that allow every action on every resource, for hand-built component props. */
|
|
27
|
+
export const allowAllAccess: AccessStandardProps = {
|
|
28
|
+
useRemoteAccess: () => true,
|
|
29
|
+
useAccess: () => true,
|
|
30
|
+
useSessionAccess: () => true,
|
|
31
|
+
useWorkspaceAccess: () => true,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const ALLOWED: HostObservable<boolean> = { getSnapshot: () => true, subscribe: () => () => {} }
|
|
35
|
+
const REFUSED: HostObservable<boolean> = { getSnapshot: () => false, subscribe: () => () => {} }
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A `remoteAccess` Client service whose answers never change: `allows`
|
|
39
|
+
* decides each action on every resource once. `whenAccess` installs an
|
|
40
|
+
* allowed action's effects in the caller's fiber at once and never installs a
|
|
41
|
+
* refused action's effects.
|
|
42
|
+
*/
|
|
43
|
+
export class StaticRemoteAccess extends Service implements ClientRemoteAccess {
|
|
44
|
+
/**
|
|
45
|
+
* @param ctx - Context the service is provided on.
|
|
46
|
+
* @param allows - the fixed answer for each action; allows everything when omitted.
|
|
47
|
+
*/
|
|
48
|
+
constructor(ctx: Context, private readonly allows: (action: string) => boolean = () => true) {
|
|
49
|
+
super(ctx, 'remoteAccess')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
source(_kind: TypertResourceKind, _id: string, action: string): HostObservable<boolean> {
|
|
53
|
+
return this.allows(action) ? ALLOWED : REFUSED
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Prototype methods: the Cordis service proxy binds `this.ctx` to the caller's Context.
|
|
57
|
+
whenAccess(action: RemoteEndpoint, callback: () => AccessEffect): () => void {
|
|
58
|
+
if (!this.allows(action)) return () => {}
|
|
59
|
+
const dispose = this.ctx.effect(callback, `remoteAccess.whenAccess(${JSON.stringify(action)})`)
|
|
60
|
+
return () => { void dispose() }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
whenResourceAccess(_kind: TypertResourceKind, _id: string, action: RemoteEndpoint, callback: () => AccessEffect): () => void {
|
|
64
|
+
return this.whenAccess(action, callback)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The plugin shape {@link staticAccessPlugin} returns. */
|
|
69
|
+
export interface StaticAccessPlugin {
|
|
70
|
+
readonly name: string
|
|
71
|
+
readonly inject: readonly string[]
|
|
72
|
+
apply(ctx: Context): void
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Plugin standing in for the remote-access Client row with fixed answers: it
|
|
77
|
+
* provides a {@link StaticRemoteAccess}, so ui-session and ui-workspace
|
|
78
|
+
* publish their resource Hooks over it, and the matching `useRemoteAccess`
|
|
79
|
+
* Hook on the global resource.
|
|
80
|
+
* @param allows - the fixed answer for each action on every resource.
|
|
81
|
+
* @returns the plugin.
|
|
82
|
+
*/
|
|
83
|
+
export function staticAccessPlugin(allows: (action: string) => boolean): StaticAccessPlugin {
|
|
84
|
+
return {
|
|
85
|
+
name: 'client-test-runtime:static-access',
|
|
86
|
+
inject: ['slots'],
|
|
87
|
+
apply(ctx: Context): void {
|
|
88
|
+
new StaticRemoteAccess(ctx, allows)
|
|
89
|
+
ctx.slots.provideRoot({ keyedHooks: { remoteAccess: (action: string) => (allows(action) ? ALLOWED : REFUSED) } })
|
|
90
|
+
},
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** {@link staticAccessPlugin} allowing every action on every resource. */
|
|
95
|
+
export const allowAllAccessPlugin: StaticAccessPlugin = staticAccessPlugin(() => true)
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser roster of a `dsh --profile`, read from its bundle patch files
|
|
3
|
+
* the way the launcher composes them: each bundle's `dsh.bundle.patch` file list is
|
|
4
|
+
* parsed with the include plugin's YAML dialect (`entryListSchema`) and
|
|
5
|
+
* composed by its `applyEntryPatches`; every enabled row whose package
|
|
6
|
+
* declares `dsh.client.platform === 'web'` becomes a roster row carrying that
|
|
7
|
+
* declaration's `inject` and `immediately`; rows nested in Loader groups count
|
|
8
|
+
* like the Loader counts them, a disabled group disabling every row beneath
|
|
9
|
+
* it. A patch that matches nothing
|
|
10
|
+
* throws here where the launcher warns. Nothing is copied from the bundles: a
|
|
11
|
+
* bundle change is visible at the next import. Node only — the
|
|
12
|
+
* whole-client tier runs under vitest, and this is the one place it reads the
|
|
13
|
+
* repository.
|
|
14
|
+
* @module @deepseek-ai/dsh-client-test-runtime/src/assembly/bundle-roster
|
|
15
|
+
*/
|
|
16
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs'
|
|
17
|
+
import { createRequire } from 'node:module'
|
|
18
|
+
import { basename, dirname, join } from 'node:path'
|
|
19
|
+
import { fileURLToPath } from 'node:url'
|
|
20
|
+
import { evaluate, isJsExpr, type EntryOptions } from '@deepseek-ai/cordis-plugin-loader'
|
|
21
|
+
import { applyEntryPatches, entryListSchema, type PatchOptions } from '@deepseek-ai/cordis-plugin-include'
|
|
22
|
+
import { exactPackageSpecifier, parseDshClient } from '@deepseek-ai/dsh-client-modules/client'
|
|
23
|
+
import * as yaml from 'js-yaml'
|
|
24
|
+
import { ClientRoster, type ClientRosterRow } from './roster.ts'
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The `web` profile's bundle layers, in the order `dsh --profile web` applies them
|
|
28
|
+
* (`PROFILE_TEMPLATES.web` in `@deepseek-ai/dsh-official-bundles`).
|
|
29
|
+
*/
|
|
30
|
+
export const WEB_PROFILE_BUNDLES: readonly string[] = ['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app']
|
|
31
|
+
|
|
32
|
+
interface PackageManifest {
|
|
33
|
+
name?: unknown
|
|
34
|
+
dsh?: { bundle?: { patch?: unknown }; client?: unknown }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** One bundle: where its package.json is (plugin names resolve from there) and its parsed patch list. */
|
|
38
|
+
interface BundleLayer {
|
|
39
|
+
readonly manifestPath: string
|
|
40
|
+
readonly patches: PatchOptions[]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Compose the browser roster of `bundles`, applied in order.
|
|
45
|
+
* @param bundles - bundle package names in application order.
|
|
46
|
+
* @param anchor - file whose package resolution locates the bundles; default this package.
|
|
47
|
+
* @param disabledContext - optional Loader evaluation scope for trusted `disabled` expressions.
|
|
48
|
+
* @returns the roster in composition order, one row per package.
|
|
49
|
+
* @throws {Error} when a bundle, its patch file, or an enabled row's package does not resolve, when the patch list
|
|
50
|
+
* is not a list or does not apply as written, or when a browser row has an unevaluated `disabled` expression.
|
|
51
|
+
*/
|
|
52
|
+
export function bundleRoster(
|
|
53
|
+
bundles: readonly string[],
|
|
54
|
+
anchor: string = fileURLToPath(import.meta.url),
|
|
55
|
+
disabledContext?: object,
|
|
56
|
+
): ClientRoster {
|
|
57
|
+
const layers = bundles.map(name => readLayer(name, anchor))
|
|
58
|
+
const entries = applyEntryPatches([], layers.flatMap(layer => layer.patches), (message: string, ...args: unknown[]) => {
|
|
59
|
+
throw new Error(`client-test-runtime: bundle patch ${describe(message, args)}`)
|
|
60
|
+
})
|
|
61
|
+
const anchors = layers.map(layer => layer.manifestPath)
|
|
62
|
+
const rows: ClientRosterRow[] = []
|
|
63
|
+
const seen = new Set<string>()
|
|
64
|
+
for (const { entry, disabled } of flattenGroups(entries)) {
|
|
65
|
+
const name = exactPackageSpecifier(entry.name)
|
|
66
|
+
if (name === undefined || disabled.includes(true) || seen.has(name)) continue
|
|
67
|
+
if (disabledContext !== undefined
|
|
68
|
+
&& disabled.some(value => isJsExpr(value) && Boolean(evaluate(disabledContext, value.__jsExpr)))) continue
|
|
69
|
+
seen.add(name)
|
|
70
|
+
const manifestPath = locateManifest(anchors, name)
|
|
71
|
+
if (manifestPath === undefined) {
|
|
72
|
+
throw new Error(`client-test-runtime: cannot resolve plugin package ${name} from ${bundles.join(', ')}`)
|
|
73
|
+
}
|
|
74
|
+
const manifest = readManifest(manifestPath)
|
|
75
|
+
if (manifest.name !== name) {
|
|
76
|
+
throw new Error(`client-test-runtime: ${manifestPath} names ${JSON.stringify(manifest.name)}, expected ${name}`)
|
|
77
|
+
}
|
|
78
|
+
const declaration = parseDshClient(name, manifest.dsh?.client)
|
|
79
|
+
if (declaration === undefined || declaration.platform !== 'web') continue
|
|
80
|
+
if (disabled.some(value => value !== undefined && value !== null && typeof value !== 'boolean'
|
|
81
|
+
&& !(disabledContext !== undefined && isJsExpr(value)))) {
|
|
82
|
+
throw new Error(`client-test-runtime: browser row ${name} has a \`disabled\` value this reader cannot evaluate (a !!js expression)`)
|
|
83
|
+
}
|
|
84
|
+
rows.push({ name, inject: declaration.inject ?? [], immediately: declaration.immediately === true })
|
|
85
|
+
}
|
|
86
|
+
return ClientRoster.of(rows)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function readLayer(bundle: string, anchor: string): BundleLayer {
|
|
90
|
+
const manifestPath = locateManifest([anchor], bundle)
|
|
91
|
+
if (manifestPath === undefined) throw new Error(`client-test-runtime: cannot resolve bundle ${bundle} from ${anchor}`)
|
|
92
|
+
const declared = readManifest(manifestPath).dsh?.bundle?.patch
|
|
93
|
+
const files = typeof declared === 'string' ? [declared] : declared
|
|
94
|
+
if (!Array.isArray(files) || !files.every(file => typeof file === 'string')) {
|
|
95
|
+
throw new Error(`client-test-runtime: bundle ${bundle} declares no dsh.bundle.patch file list in ${manifestPath}`)
|
|
96
|
+
}
|
|
97
|
+
const patches = files.flatMap((patch) => {
|
|
98
|
+
const file = join(dirname(manifestPath), patch)
|
|
99
|
+
const parsed: unknown = yaml.load(readFileSync(file, 'utf8'), { schema: entryListSchema })
|
|
100
|
+
if (!Array.isArray(parsed)) throw new Error(`client-test-runtime: ${file} must be a top-level list of patches`)
|
|
101
|
+
return parsed as PatchOptions[]
|
|
102
|
+
})
|
|
103
|
+
return { manifestPath, patches }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** One Loader row with its ancestor and own disable conditions, in outer-to-inner order. */
|
|
107
|
+
interface FlatEntry {
|
|
108
|
+
readonly entry: EntryOptions
|
|
109
|
+
readonly disabled: readonly unknown[]
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Rows in Loader order with groups descended, as the Loader loads them: a group is never a plugin itself, and a group's
|
|
114
|
+
* `disabled` disables every row beneath it.
|
|
115
|
+
* @param entries - composed entries, possibly nested.
|
|
116
|
+
* @param inherited - the enclosing groups' disable conditions.
|
|
117
|
+
* @returns the plugin rows.
|
|
118
|
+
*/
|
|
119
|
+
function flattenGroups(entries: readonly EntryOptions[], inherited: readonly unknown[] = []): FlatEntry[] {
|
|
120
|
+
const rows: FlatEntry[] = []
|
|
121
|
+
for (const entry of entries) {
|
|
122
|
+
const disabled = [...inherited, (entry as { disabled?: unknown }).disabled]
|
|
123
|
+
if (entry.group === true && Array.isArray(entry.config)) {
|
|
124
|
+
rows.push(...flattenGroups(entry.config as EntryOptions[], disabled))
|
|
125
|
+
continue
|
|
126
|
+
}
|
|
127
|
+
rows.push({ entry, disabled })
|
|
128
|
+
}
|
|
129
|
+
return rows
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function readManifest(path: string): PackageManifest {
|
|
133
|
+
return JSON.parse(readFileSync(path, 'utf8')) as PackageManifest
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Prefer an anchor manifest with the requested package name, then search dependencies by depth and anchor order.
|
|
138
|
+
* Return real paths so linked bundles use their own dependency directories.
|
|
139
|
+
*/
|
|
140
|
+
function locateManifest(anchors: readonly string[], name: string): string | undefined {
|
|
141
|
+
for (const anchor of anchors) {
|
|
142
|
+
if (basename(anchor) === 'package.json' && readManifest(anchor).name === name) return realpathSync(anchor)
|
|
143
|
+
}
|
|
144
|
+
const paths = anchors.map(anchor => createRequire(anchor).resolve.paths(name) ?? [])
|
|
145
|
+
for (let depth = 0; depth < Math.max(...paths.map(search => search.length)); depth++) {
|
|
146
|
+
for (const search of paths) {
|
|
147
|
+
const directory = search[depth]
|
|
148
|
+
if (directory === undefined) continue
|
|
149
|
+
const candidate = join(directory, name, 'package.json')
|
|
150
|
+
if (existsSync(candidate)) return realpathSync(candidate)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return undefined
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** The include plugin's `%C` placeholders, filled the way the launcher prints them. */
|
|
157
|
+
function describe(message: string, args: readonly unknown[]): string {
|
|
158
|
+
let index = 0
|
|
159
|
+
return message.replace(/%C/g, () => JSON.stringify(args[index++]))
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const webProfileServices: Readonly<Record<string, object | undefined>> = { profileContext: { name: 'web' } }
|
|
163
|
+
|
|
164
|
+
/** The `web` profile's browser roster, composed with its profile name and no business Host services. */
|
|
165
|
+
export const webApp: ClientRoster = bundleRoster(WEB_PROFILE_BUNDLES, undefined, {
|
|
166
|
+
get: (name: string) => webProfileServices[name],
|
|
167
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whole-client tier entry (deep import only:
|
|
3
|
+
* `@deepseek-ai/dsh-client-test-runtime/src/assembly/index.ts`). Kept out of
|
|
4
|
+
* the package root so slot-tier specs do not load the assembly machinery.
|
|
5
|
+
* @module @deepseek-ai/dsh-client-test-runtime/src/assembly
|
|
6
|
+
*/
|
|
7
|
+
export { ClientRoster } from './roster.ts'
|
|
8
|
+
export type { AssemblyPlan, ClientPluginModule, ClientRosterRow } from './roster.ts'
|
|
9
|
+
export { TestClient } from './test-client.ts'
|
|
10
|
+
export type { TestClientOptions } from './test-client.ts'
|
|
11
|
+
export { remoteDefaultResponses } from './remote-default-responses.ts'
|
|
12
|
+
export { bundleRoster, webApp } from './bundle-roster.ts'
|
|
13
|
+
export { createClientTest } from './vitest.ts'
|
|
14
|
+
export type { ClientTestFixtures } from './vitest.ts'
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-process module arrival: import every roster row's `/client` module (or
|
|
3
|
+
* the plan's replacement) and register each as a pre-arrived factory on a
|
|
4
|
+
* production `ClientModuleSystem`, so neither the Loader's `internal.import`
|
|
5
|
+
* nor a stage-one `prefetch` ever fetches a bundle.
|
|
6
|
+
* @module @deepseek-ai/dsh-client-test-runtime/src/assembly/modules
|
|
7
|
+
*/
|
|
8
|
+
import * as modulesClient from '@deepseek-ai/dsh-client-modules/client'
|
|
9
|
+
import { createClientModuleSystem } from '@deepseek-ai/dsh-client-modules/client'
|
|
10
|
+
import type { ClientModuleLoader, ClientModuleLoaderTarget, WebBootGraph } from '@deepseek-ai/dsh-client-modules/client'
|
|
11
|
+
import type { AssemblyPlan, ClientPluginModule } from './roster.ts'
|
|
12
|
+
|
|
13
|
+
/** The bootstrap row: always this process's static namespace, never a dynamic import or a `provide` replacement. */
|
|
14
|
+
export const MODULES_PACKAGE = '@deepseek-ai/dsh-client-modules'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Resolve each roster row to its plugin module: `plan.provide[name]` when
|
|
18
|
+
* present, otherwise a `/client` import resolved by the repository's tsconfig
|
|
19
|
+
* path aliases under Vitest. The bootstrap row is the
|
|
20
|
+
* statically imported `@deepseek-ai/dsh-client-modules/client` namespace.
|
|
21
|
+
* @param plan - validated plan.
|
|
22
|
+
* @returns package name → module, in roster order.
|
|
23
|
+
* @throws {Error} when an import fails (the package name prefixes the original message) or the bootstrap row is provided.
|
|
24
|
+
*/
|
|
25
|
+
export async function loadPluginModules(plan: AssemblyPlan): Promise<ReadonlyMap<string, ClientPluginModule>> {
|
|
26
|
+
const modules = new Map<string, ClientPluginModule>()
|
|
27
|
+
for (const { name } of plan.roster.rows) {
|
|
28
|
+
const provided = plan.provide?.[name]
|
|
29
|
+
if (name === MODULES_PACKAGE) {
|
|
30
|
+
if (provided !== undefined) {
|
|
31
|
+
throw new Error(`client-test-runtime: ${MODULES_PACKAGE} is the bootstrap module and cannot be provided`)
|
|
32
|
+
}
|
|
33
|
+
modules.set(name, modulesClient)
|
|
34
|
+
continue
|
|
35
|
+
}
|
|
36
|
+
modules.set(name, provided ?? await importClient(name))
|
|
37
|
+
}
|
|
38
|
+
return modules
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function importClient(name: string): Promise<ClientPluginModule> {
|
|
42
|
+
let namespace: unknown
|
|
43
|
+
try {
|
|
44
|
+
namespace = await import(/* @vite-ignore */ `${name}/client`)
|
|
45
|
+
} catch (error) {
|
|
46
|
+
throw new Error(`client-test-runtime: cannot import ${name}/client: ${String(error)}`, { cause: error })
|
|
47
|
+
}
|
|
48
|
+
return namespace as ClientPluginModule
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Build the production module system over queued factories returning the
|
|
53
|
+
* loaded namespaces. The bootstrap row uses `bootstrapModule`; `staticModules`
|
|
54
|
+
* is empty because namespaces already hold their own imports. Missing factories
|
|
55
|
+
* reject through `loadBundle` without fetching.
|
|
56
|
+
* @param graph - raw boot graph from `graphFromRoster`; `createClientModuleSystem` parses it.
|
|
57
|
+
* @param modules - loaded plugin modules keyed by package name.
|
|
58
|
+
* @returns module system to install as `loader.internal`; its `manifest` is the parsed graph.
|
|
59
|
+
*/
|
|
60
|
+
export function createInProcessModules(
|
|
61
|
+
graph: WebBootGraph,
|
|
62
|
+
modules: ReadonlyMap<string, ClientPluginModule>,
|
|
63
|
+
): ClientModuleLoader {
|
|
64
|
+
const target: ClientModuleLoaderTarget = {
|
|
65
|
+
mode: 'queue',
|
|
66
|
+
pendingQueue: [],
|
|
67
|
+
/* v8 ignore next -- construction replaces this sink before draining the prefilled queue. */
|
|
68
|
+
load: () => { throw new Error('client-test-runtime: module facade is not initialized') },
|
|
69
|
+
create: options => createClientModuleSystem(target, { id: MODULES_PACKAGE, exports: modulesClient }, options),
|
|
70
|
+
}
|
|
71
|
+
for (const [id, namespace] of modules) {
|
|
72
|
+
if (id === MODULES_PACKAGE) continue
|
|
73
|
+
target.pendingQueue.push({ id, factory: () => namespace as unknown as Record<string, unknown> })
|
|
74
|
+
}
|
|
75
|
+
return target.create({
|
|
76
|
+
boot: graph,
|
|
77
|
+
staticModules: {},
|
|
78
|
+
loadBundle: url => Promise.reject(new Error(`client-test-runtime: in-process modules never load bundles (${url})`)),
|
|
79
|
+
})
|
|
80
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default responses for every Remote endpoint the web assembly calls while
|
|
3
|
+
* booting and rendering with no sessions, no workspaces, and default settings.
|
|
4
|
+
* The comment above each row names the plugin that calls it; endpoints boot
|
|
5
|
+
* never touches stay absent so a new call fails loud. `$events` is built into
|
|
6
|
+
* `RemoteMock`.
|
|
7
|
+
* @module @deepseek-ai/dsh-client-test-runtime/src/assembly/remote-default-responses
|
|
8
|
+
*/
|
|
9
|
+
import { ok, openStream, type RemoteTable } from '@deepseek-ai/dsh-remote-mock'
|
|
10
|
+
|
|
11
|
+
/** Default responses of the boot-time Remote endpoints; a spec loads it first and layers its own table on top. */
|
|
12
|
+
export const remoteDefaultResponses: RemoteTable = {
|
|
13
|
+
unary: {
|
|
14
|
+
// api-session-controller `sessions.handleConnected()` on `connection/reset`.
|
|
15
|
+
'session/list': ok({ items: [] }),
|
|
16
|
+
// ui-workspace startup with no entries; first-use initialization is ineligible.
|
|
17
|
+
'workspace/initializeDefault': ok(undefined),
|
|
18
|
+
// ui-settings `mirror.ensure()` at apply and again on `connection/reset`.
|
|
19
|
+
'settings/describe': ok({ writable: true, hasDocument: false, namespaces: [] }),
|
|
20
|
+
// ui-model-selection `ModelDirectoryResolver` constructor.
|
|
21
|
+
'session/modelCatalog': ok({
|
|
22
|
+
default: { provider: 'deepseek-official', model: 'deepseek-v4-flash' },
|
|
23
|
+
routableProviders: [],
|
|
24
|
+
groups: [],
|
|
25
|
+
failures: [],
|
|
26
|
+
}),
|
|
27
|
+
// ui-agent-preset hero chip and header label on first mount.
|
|
28
|
+
'agentPresets/list': ok({ presets: [] }),
|
|
29
|
+
// cordis-client-runner `ClientCordisInspectRegistry.sync` at apply and on `connection/reset`.
|
|
30
|
+
'dynamicCordisRunner/syncInspectManifest': ok(null),
|
|
31
|
+
// ui-cordis inventory at apply and on `connection/reset`.
|
|
32
|
+
'dynamicCordisRunner/inventory': ok([]),
|
|
33
|
+
// ui-settings-web-search page `readCredential()` when the settings mirror first publishes.
|
|
34
|
+
'credentials/describe': ok({}),
|
|
35
|
+
// ui-settings-web-search page provider options at apply and on `connection/reset`.
|
|
36
|
+
'web/listProviders': ok({ search: [], fetch: [] }),
|
|
37
|
+
// ui-permission-presets `PermissionCatalogDirectory` on its first read for a connection generation.
|
|
38
|
+
'permissionPresets/catalog': ok({ options: [] }),
|
|
39
|
+
// ui-settings-account refreshes details after a stored-grant snapshot.
|
|
40
|
+
'account/getProfile': ok(null),
|
|
41
|
+
'account/getBalance': ok(null),
|
|
42
|
+
// ui-settings-account bonus notice read and acknowledgement at signing in.
|
|
43
|
+
'account/getNotifications': ok(null),
|
|
44
|
+
'account/getNotificationContent': ok(null),
|
|
45
|
+
'account/reportNotificationEvent': ok(true),
|
|
46
|
+
},
|
|
47
|
+
// Stream endpoints the roster opens later than boot; declared so a spec that forgets the script gets a stream miss.
|
|
48
|
+
streams: [
|
|
49
|
+
// api-session-controller `SessionEventStream.follow` when a Session opens.
|
|
50
|
+
'session/follow',
|
|
51
|
+
],
|
|
52
|
+
stream: {
|
|
53
|
+
// api-session-controller client `apply`: the control stream's opening baseline, then open.
|
|
54
|
+
'session/control': openStream([{ type: 'baseline', value: { projections: {} } }]),
|
|
55
|
+
// ui-settings-account shares the account snapshot across settings and the sidebar menu.
|
|
56
|
+
'account/watch': openStream([{ type: 'snapshot', state: { status: 'signed-out', attempt: null, links: { usageUrl: 'https://platform.deepseek.com/usage', topUpUrl: 'https://platform.deepseek.com/top_up' } } }]),
|
|
57
|
+
// api-workspace-controller client `apply`: the follow stream's opening baseline, then open.
|
|
58
|
+
'workspace/follow': openStream([{ type: 'baseline', value: { items: [], archivedSessionIds: [], pinnedSessionIds: [] } }]),
|
|
59
|
+
// api-remote-access client `mountAccess`: the owner's access snapshot, then open.
|
|
60
|
+
'remoteAccess/follow': openStream([{ type: 'baseline', owner: true }]),
|
|
61
|
+
// ui-sidebar-terminal header entry `agent-terminals`: the displayed Session's terminal roster, then open.
|
|
62
|
+
'terminal/watch': openStream([[]]),
|
|
63
|
+
},
|
|
64
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `remote.<ns>` services for the whole-client tier, without the generated
|
|
3
|
+
* Remote clients. Cordis resolves `ctx.remote.<ns>` to whichever service is
|
|
4
|
+
* registered under `remote.<ns>` (vendor cordis `utils.ts`, traceable get), so
|
|
5
|
+
* the carrier provides one Proxy per namespace: `remote.<ns>.<method>(...args)`
|
|
6
|
+
* calls the endpoint `<ns>/<method>` over the roster's own Connection with the
|
|
7
|
+
* positional `args`, as a stream when the mock registered a stream script for
|
|
8
|
+
* it and as a unary call otherwise. A unary answer is returned unchanged and a
|
|
9
|
+
* unary rejection is folded the way the generated client folds a carrier
|
|
10
|
+
* throw (`gateway/internal`, or `gateway/cancelled` once the caller's signal
|
|
11
|
+
* aborted), so product code that never awaits a rejection sees none; stream
|
|
12
|
+
* items and failures pass through as the stream yields them.
|
|
13
|
+
* @module @deepseek-ai/dsh-client-test-runtime/src/assembly/remote-proxies
|
|
14
|
+
*/
|
|
15
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
16
|
+
import { cancelledFailure, carrierFailure } from '@deepseek-ai/dsh-api-gateway/client'
|
|
17
|
+
import type { ConnectionHandle } from '@deepseek-ai/dsh-client-connection/client'
|
|
18
|
+
import type { RemoteMock } from '@deepseek-ai/dsh-remote-mock'
|
|
19
|
+
import type { ClientPluginModule } from './roster.ts'
|
|
20
|
+
|
|
21
|
+
/** The assembly row the proxies stand in for; its generated clients exist only in built `lib/`. */
|
|
22
|
+
export const REMOTES_PACKAGE = '@deepseek-ai/dsh-api-remotes'
|
|
23
|
+
|
|
24
|
+
const PREFIX = 'remote.'
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Namespaces to provide: every `remote.<ns>` a roster module injects, plus the
|
|
28
|
+
* namespace of every endpoint the mock has a rule for.
|
|
29
|
+
* @param modules - loaded roster modules.
|
|
30
|
+
* @param mock - the spec's mock.
|
|
31
|
+
* @returns sorted namespace names.
|
|
32
|
+
*/
|
|
33
|
+
export function remoteNamespacesOf(modules: Iterable<ClientPluginModule>, mock: RemoteMock): readonly string[] {
|
|
34
|
+
const names = new Set<string>()
|
|
35
|
+
for (const module of modules) {
|
|
36
|
+
for (const service of injectNames(module.inject)) if (service.startsWith(PREFIX)) names.add(service.slice(PREFIX.length))
|
|
37
|
+
}
|
|
38
|
+
for (const endpoint of mock.endpoints()) {
|
|
39
|
+
const slash = endpoint.indexOf('/')
|
|
40
|
+
if (slash > 0 && !endpoint.startsWith('$')) names.add(endpoint.slice(0, slash))
|
|
41
|
+
}
|
|
42
|
+
return [...names].sort()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function injectNames(inject: ClientPluginModule['inject']): readonly string[] {
|
|
46
|
+
if (inject === undefined) return []
|
|
47
|
+
if (Array.isArray(inject)) return inject as readonly string[]
|
|
48
|
+
return Object.keys(inject)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Plugin providing the namespace proxies; `TestClient.start` mounts it before the Loader rows.
|
|
53
|
+
* @param namespaces - namespaces to provide.
|
|
54
|
+
* @param mock - the spec's mock, asked for each endpoint's mode.
|
|
55
|
+
* @returns the plugin.
|
|
56
|
+
*/
|
|
57
|
+
export function remoteProxiesPlugin(namespaces: readonly string[], mock: RemoteMock): ClientPluginModule {
|
|
58
|
+
return {
|
|
59
|
+
inject: ['connection'],
|
|
60
|
+
apply(ctx: Context) {
|
|
61
|
+
const connection = ctx.get('connection') as ConnectionHandle
|
|
62
|
+
for (const namespace of namespaces) ctx.provide(`${PREFIX}${namespace}`, namespaceProxy(namespace, connection, mock))
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function namespaceProxy(namespace: string, connection: ConnectionHandle, mock: RemoteMock): object {
|
|
68
|
+
return new Proxy(Object.create(null) as Record<string, unknown>, {
|
|
69
|
+
get: (_target, property) => {
|
|
70
|
+
// No `then`: awaiting the namespace object itself must not call a method.
|
|
71
|
+
if (typeof property !== 'string' || property === 'then') return undefined
|
|
72
|
+
return (...values: readonly unknown[]): unknown => {
|
|
73
|
+
const endpoint = `${namespace}/${property}`
|
|
74
|
+
const args = [...values]
|
|
75
|
+
const signal = args.at(-1) instanceof AbortSignal ? (args.pop() as AbortSignal) : undefined
|
|
76
|
+
if (mock.modeOf(endpoint) === 'stream') {
|
|
77
|
+
const open = connection.rpc.open
|
|
78
|
+
/* v8 ignore next -- the mock transport always supplies openStream, so the Connection carrier exposes open. */
|
|
79
|
+
if (open === undefined) throw new Error(`client-test-runtime: ${endpoint} is a stream but the carrier has no in-process opener`)
|
|
80
|
+
return open('/api', endpoint, { args }, signal ?? new AbortController().signal)
|
|
81
|
+
}
|
|
82
|
+
return connection.rpc.call('/api', endpoint, { args }, signal).catch((error: unknown) =>
|
|
83
|
+
(signal?.aborted === true ? cancelledFailure(endpoint, error) : carrierFailure(endpoint, error)))
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
})
|
|
87
|
+
}
|