@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.
Files changed (65) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +1 -1
  3. package/README.zh.md +1 -1
  4. package/lib/index.js +9 -0
  5. package/lib/types/access.d.ts.map +1 -0
  6. package/lib/types/access.js.map +1 -0
  7. package/lib/types/assembly/bundle-roster.d.ts.map +1 -0
  8. package/lib/types/assembly/bundle-roster.js.map +1 -0
  9. package/lib/types/assembly/index.d.ts.map +1 -0
  10. package/lib/types/assembly/index.js.map +1 -0
  11. package/lib/types/assembly/modules.d.ts.map +1 -0
  12. package/lib/types/assembly/modules.js.map +1 -0
  13. package/lib/types/assembly/remote-default-responses.d.ts.map +1 -0
  14. package/lib/types/assembly/remote-default-responses.js.map +1 -0
  15. package/lib/types/assembly/remote-proxies.d.ts.map +1 -0
  16. package/lib/types/assembly/remote-proxies.js.map +1 -0
  17. package/lib/types/assembly/roster.d.ts.map +1 -0
  18. package/lib/types/assembly/roster.js.map +1 -0
  19. package/lib/types/assembly/test-client.d.ts +10 -2
  20. package/lib/types/assembly/test-client.d.ts.map +1 -0
  21. package/lib/types/assembly/test-client.js.map +1 -0
  22. package/lib/types/assembly/vitest.d.ts +1 -1
  23. package/lib/types/assembly/vitest.d.ts.map +1 -0
  24. package/lib/types/assembly/vitest.js.map +1 -0
  25. package/lib/types/config-form.d.ts.map +1 -0
  26. package/lib/types/config-form.js.map +1 -0
  27. package/lib/types/context-menu.d.ts.map +1 -0
  28. package/lib/types/context-menu.js.map +1 -0
  29. package/lib/types/fixtures.d.ts.map +1 -0
  30. package/lib/types/fixtures.js.map +1 -0
  31. package/lib/types/index.d.ts.map +1 -0
  32. package/lib/types/index.js.map +1 -0
  33. package/lib/types/locale-env.d.ts.map +1 -0
  34. package/lib/types/locale-env.js.map +1 -0
  35. package/lib/types/remote.d.ts.map +1 -0
  36. package/lib/types/remote.js.map +1 -0
  37. package/lib/types/sessions.d.ts +5 -0
  38. package/lib/types/sessions.d.ts.map +1 -0
  39. package/lib/types/sessions.js.map +1 -0
  40. package/lib/types/snapshot.d.ts.map +1 -0
  41. package/lib/types/snapshot.js.map +1 -0
  42. package/lib/types/translate.d.ts.map +1 -0
  43. package/lib/types/translate.js.map +1 -0
  44. package/lib/types/workspaces.d.ts.map +1 -0
  45. package/lib/types/workspaces.js.map +1 -0
  46. package/package.json +53 -50
  47. package/src/access.ts +95 -0
  48. package/src/assembly/bundle-roster.ts +167 -0
  49. package/src/assembly/index.ts +14 -0
  50. package/src/assembly/modules.ts +80 -0
  51. package/src/assembly/remote-default-responses.ts +64 -0
  52. package/src/assembly/remote-proxies.ts +87 -0
  53. package/src/assembly/roster.ts +163 -0
  54. package/src/assembly/test-client.ts +388 -0
  55. package/src/assembly/vitest.ts +60 -0
  56. package/src/config-form.ts +61 -0
  57. package/src/context-menu.ts +17 -0
  58. package/src/fixtures.ts +119 -0
  59. package/src/index.ts +490 -0
  60. package/src/locale-env.ts +29 -0
  61. package/src/remote.ts +103 -0
  62. package/src/sessions.ts +844 -0
  63. package/src/snapshot.ts +89 -0
  64. package/src/translate.ts +32 -0
  65. package/src/workspaces.ts +210 -0
package/src/remote.ts ADDED
@@ -0,0 +1,103 @@
1
+ /** Test-owned Remote face: `$on` subscriptions with an explicit test event driver. */
2
+ import type { Context } from '@deepseek-ai/cordis'
3
+
4
+ // Value re-export for spec-side failure construction: the api-remotes facade
5
+ // cannot carry it — its src top-level imports owner /remote lib artifacts, so a
6
+ // value import from a spec would load the unbuilt assembly chain.
7
+ export { RemoteError } from '@deepseek-ai/dsh-typert-protocol'
8
+
9
+ /**
10
+ * Remote service test double for the forwarded-event path. Feature specs need
11
+ * `ctx.remote.$on` to exist (their plugins inject `remote`) and need forwarded
12
+ * Host events to reach those subscribers, but not the wire — so this double
13
+ * implements subscription plus an explicit `emit` driver available only on the
14
+ * concrete test object. A spec that also calls one namespace scripts it through
15
+ * the constructor rather than reaching the real Client Remote service.
16
+ *
17
+ * `$mount` rejects: a spec that needs a real generated contribution installed —
18
+ * codecs, descriptors, and the wire — has outgrown this double and needs the
19
+ * real Client Remote service.
20
+ *
21
+ * One deliberate asymmetry with production: a throwing listener propagates out
22
+ * of the emit instead of being contained and logged, so a spec cannot lean on
23
+ * this double for the containment guarantee `$on` documents — assert that
24
+ * against the real service.
25
+ */
26
+ export class TestRemote {
27
+ private readonly subscriptions = new Map<string, Set<(...args: never[]) => void>>()
28
+
29
+ /**
30
+ * Fixed Host facts mirrored from the production `ctx.remote.$host`. Plain
31
+ * mutable field: a spec assigns it to script a non-loopback or homed Host.
32
+ */
33
+ $host: { home: string | undefined; isLoopback: boolean } = { home: undefined, isLoopback: true }
34
+
35
+ /**
36
+ * Register the double as `ctx.remote`, plus one service per scripted
37
+ * namespace so a plugin injecting `remote.<name>` also unparks.
38
+ * @param ctx - the spec's root Context.
39
+ * @param namespaces - scripted namespace faces reached as `ctx.remote.<name>`.
40
+ */
41
+ constructor(private readonly ctx: Context, namespaces: Readonly<Record<string, object>> = {}) {
42
+ this.validateNamespaces(namespaces)
43
+ ctx.provide('remote', this)
44
+ this.installNamespaces(namespaces)
45
+ }
46
+
47
+ /**
48
+ * Add scripted namespace faces to this Remote service.
49
+ * @param namespaces - scripted namespace faces reached as `ctx.remote.<name>`.
50
+ */
51
+ provideNamespaces(namespaces: Readonly<Record<string, object>>): void {
52
+ this.validateNamespaces(namespaces)
53
+ this.installNamespaces(namespaces)
54
+ }
55
+
56
+ private validateNamespaces(namespaces: Readonly<Record<string, object>>): void {
57
+ for (const name of Object.keys(namespaces)) {
58
+ // A namespace named after one of the double's own members would replace
59
+ // it, and `$mount`'s rejection is the contract a spec relies on.
60
+ if (name in this) {
61
+ throw new TypeError(`TestRemote: scripted namespace "${name}" would shadow the double's own member`)
62
+ }
63
+ }
64
+ }
65
+
66
+ private installNamespaces(namespaces: Readonly<Record<string, object>>): void {
67
+ Object.assign(this, namespaces)
68
+ for (const [name, face] of Object.entries(namespaces)) this.ctx.provide(`remote.${name}`, face)
69
+ }
70
+
71
+ /**
72
+ * Deliver one forwarded host event to its subscribers, standing in for the
73
+ * carrier that owns the frame sink.
74
+ * @param event - forwarded host event name.
75
+ * @param args - the Host argument list, verbatim.
76
+ */
77
+ emit(event: string, args: readonly unknown[]): void {
78
+ const listeners = this.subscriptions.get(event)
79
+ if (listeners === undefined) return
80
+ for (const listener of [...listeners]) listener(...args as never[])
81
+ }
82
+
83
+ /**
84
+ * Subscribe to one forwarded host event.
85
+ * @param event - forwarded host event name.
86
+ * @param listener - receives the Host argument list verbatim.
87
+ * @returns disposer removing this subscription.
88
+ */
89
+ $on(event: string, listener: (...args: never[]) => void): () => void {
90
+ const listeners = this.subscriptions.get(event) ?? new Set()
91
+ this.subscriptions.set(event, listeners)
92
+ listeners.add(listener)
93
+ return () => { listeners.delete(listener) }
94
+ }
95
+
96
+ /**
97
+ * Generated-namespace mount, unsupported by this double.
98
+ * @returns never; always rejects.
99
+ */
100
+ $mount(): Promise<() => Promise<void>> {
101
+ return Promise.reject(new Error('TestRemote: $mount needs the real Client Remote service'))
102
+ }
103
+ }