@hydranium/protocol 1.0.0-next.25 → 1.0.0-next.250

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 (250) hide show
  1. package/README.md +44 -49
  2. package/lib/abstract-logger.d.ts +5 -0
  3. package/lib/abstract-logger.d.ts.map +1 -1
  4. package/lib/abstract-logger.js +7 -0
  5. package/lib/abstract-logger.js.map +1 -1
  6. package/lib/client/data-connection.d.ts +245 -0
  7. package/lib/client/data-connection.d.ts.map +1 -0
  8. package/lib/client/data-connection.js +425 -0
  9. package/lib/client/data-connection.js.map +1 -0
  10. package/lib/client/data-events.d.ts +13 -1
  11. package/lib/client/data-events.d.ts.map +1 -1
  12. package/lib/client/data-events.js +21 -0
  13. package/lib/client/data-events.js.map +1 -1
  14. package/lib/client/data-port.d.ts +44 -27
  15. package/lib/client/data-port.d.ts.map +1 -1
  16. package/lib/client/data-session.d.ts +473 -81
  17. package/lib/client/data-session.d.ts.map +1 -1
  18. package/lib/client/data-session.js +743 -108
  19. package/lib/client/data-session.js.map +1 -1
  20. package/lib/client/index.d.ts +14 -9
  21. package/lib/client/index.d.ts.map +1 -1
  22. package/lib/client/index.js +14 -9
  23. package/lib/client/index.js.map +1 -1
  24. package/lib/client/message-relay.d.ts +10 -4
  25. package/lib/client/message-relay.d.ts.map +1 -1
  26. package/lib/client/message-relay.js +12 -6
  27. package/lib/client/message-relay.js.map +1 -1
  28. package/lib/client/post-message-transport.d.ts +64 -3
  29. package/lib/client/post-message-transport.d.ts.map +1 -1
  30. package/lib/client/post-message-transport.js +175 -1
  31. package/lib/client/post-message-transport.js.map +1 -1
  32. package/lib/client/rpc-connection.d.ts +157 -0
  33. package/lib/client/rpc-connection.d.ts.map +1 -0
  34. package/lib/client/rpc-connection.js +214 -0
  35. package/lib/client/rpc-connection.js.map +1 -0
  36. package/lib/client-ids.d.ts +45 -0
  37. package/lib/client-ids.d.ts.map +1 -0
  38. package/lib/client-ids.js +48 -0
  39. package/lib/client-ids.js.map +1 -0
  40. package/lib/clock.d.ts +38 -0
  41. package/lib/clock.d.ts.map +1 -1
  42. package/lib/clock.js +36 -1
  43. package/lib/clock.js.map +1 -1
  44. package/lib/console-logger.d.ts +23 -0
  45. package/lib/console-logger.d.ts.map +1 -0
  46. package/lib/console-logger.js +39 -0
  47. package/lib/console-logger.js.map +1 -0
  48. package/lib/data/data-protocol-methods.d.ts +4 -4
  49. package/lib/data/data-protocol-methods.d.ts.map +1 -1
  50. package/lib/data/data-protocol-methods.js +12 -1
  51. package/lib/data/data-protocol-methods.js.map +1 -1
  52. package/lib/data/data-server-protocol.d.ts +132 -41
  53. package/lib/data/data-server-protocol.d.ts.map +1 -1
  54. package/lib/data/events.d.ts +117 -21
  55. package/lib/data/events.d.ts.map +1 -1
  56. package/lib/data/requests.d.ts +69 -11
  57. package/lib/data/requests.d.ts.map +1 -1
  58. package/lib/debouncer.d.ts.map +1 -1
  59. package/lib/debouncer.js.map +1 -1
  60. package/lib/errors.d.ts +187 -29
  61. package/lib/errors.d.ts.map +1 -1
  62. package/lib/errors.js +270 -29
  63. package/lib/errors.js.map +1 -1
  64. package/lib/glsp-request-model-args.d.ts +16 -0
  65. package/lib/glsp-request-model-args.d.ts.map +1 -0
  66. package/lib/glsp-request-model-args.js +19 -0
  67. package/lib/glsp-request-model-args.js.map +1 -0
  68. package/lib/glsp-save-model-actions.d.ts +50 -0
  69. package/lib/glsp-save-model-actions.d.ts.map +1 -0
  70. package/lib/glsp-save-model-actions.js +28 -0
  71. package/lib/glsp-save-model-actions.js.map +1 -0
  72. package/lib/index.d.ts +7 -0
  73. package/lib/index.d.ts.map +1 -1
  74. package/lib/index.js +10 -0
  75. package/lib/index.js.map +1 -1
  76. package/lib/latency-collector.d.ts +8 -4
  77. package/lib/latency-collector.d.ts.map +1 -1
  78. package/lib/latency-collector.js.map +1 -1
  79. package/lib/logger.d.ts +22 -1
  80. package/lib/logger.d.ts.map +1 -1
  81. package/lib/logger.js +31 -3
  82. package/lib/logger.js.map +1 -1
  83. package/lib/messages/index.d.ts +30 -0
  84. package/lib/messages/index.d.ts.map +1 -0
  85. package/lib/messages/index.js +62 -0
  86. package/lib/messages/index.js.map +1 -0
  87. package/lib/messages/primitives.d.ts +188 -0
  88. package/lib/messages/primitives.d.ts.map +1 -0
  89. package/lib/messages/primitives.js +161 -0
  90. package/lib/messages/primitives.js.map +1 -0
  91. package/lib/model-server.d.ts +60 -13
  92. package/lib/model-server.d.ts.map +1 -1
  93. package/lib/model-server.js +4 -2
  94. package/lib/model-server.js.map +1 -1
  95. package/lib/model-service/base-version.d.ts +64 -0
  96. package/lib/model-service/base-version.d.ts.map +1 -0
  97. package/lib/model-service/base-version.js +43 -0
  98. package/lib/model-service/base-version.js.map +1 -0
  99. package/lib/model-service/index.d.ts +1 -1
  100. package/lib/model-service/index.d.ts.map +1 -1
  101. package/lib/model-service/index.js +4 -5
  102. package/lib/model-service/index.js.map +1 -1
  103. package/lib/model-service/reference-candidate.d.ts +5 -3
  104. package/lib/model-service/reference-candidate.d.ts.map +1 -1
  105. package/lib/{model-service/args.js → node/index.d.ts} +2 -3
  106. package/lib/node/index.d.ts.map +1 -0
  107. package/lib/node/index.js +29 -0
  108. package/lib/node/index.js.map +1 -0
  109. package/lib/node/process-memory.d.ts +66 -0
  110. package/lib/node/process-memory.d.ts.map +1 -0
  111. package/lib/node/process-memory.js +291 -0
  112. package/lib/node/process-memory.js.map +1 -0
  113. package/lib/noop-logger.d.ts.map +1 -1
  114. package/lib/noop-logger.js.map +1 -1
  115. package/lib/observable-value.js.map +1 -1
  116. package/lib/patch-merge.d.ts +35 -32
  117. package/lib/patch-merge.d.ts.map +1 -1
  118. package/lib/patch-merge.js +67 -23
  119. package/lib/patch-merge.js.map +1 -1
  120. package/lib/profile-session.d.ts +8 -4
  121. package/lib/profile-session.d.ts.map +1 -1
  122. package/lib/profile-session.js.map +1 -1
  123. package/lib/random-uuid.d.ts +14 -0
  124. package/lib/random-uuid.d.ts.map +1 -0
  125. package/lib/random-uuid.js +24 -0
  126. package/lib/random-uuid.js.map +1 -0
  127. package/lib/reconcile-write.d.ts +65 -0
  128. package/lib/reconcile-write.d.ts.map +1 -0
  129. package/lib/reconcile-write.js +67 -0
  130. package/lib/reconcile-write.js.map +1 -0
  131. package/lib/rpc/bind-rpc-methods.d.ts +33 -3
  132. package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
  133. package/lib/rpc/bind-rpc-methods.js +32 -3
  134. package/lib/rpc/bind-rpc-methods.js.map +1 -1
  135. package/lib/rpc/create-rpc-proxy.d.ts +10 -0
  136. package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
  137. package/lib/rpc/create-rpc-proxy.js +12 -2
  138. package/lib/rpc/create-rpc-proxy.js.map +1 -1
  139. package/lib/rpc/index.d.ts +1 -0
  140. package/lib/rpc/index.d.ts.map +1 -1
  141. package/lib/rpc/index.js +1 -0
  142. package/lib/rpc/index.js.map +1 -1
  143. package/lib/rpc/send-by-method-name.d.ts +76 -0
  144. package/lib/rpc/send-by-method-name.d.ts.map +1 -0
  145. package/lib/rpc/send-by-method-name.js +120 -0
  146. package/lib/rpc/send-by-method-name.js.map +1 -0
  147. package/lib/rpc/wire-prefix.js.map +1 -1
  148. package/lib/testing/catalogue-audit.d.ts +80 -0
  149. package/lib/testing/catalogue-audit.d.ts.map +1 -0
  150. package/lib/testing/catalogue-audit.js +94 -0
  151. package/lib/testing/catalogue-audit.js.map +1 -0
  152. package/lib/testing/data-doubles.d.ts +46 -15
  153. package/lib/testing/data-doubles.d.ts.map +1 -1
  154. package/lib/testing/data-doubles.js +58 -10
  155. package/lib/testing/data-doubles.js.map +1 -1
  156. package/lib/testing/fake-clock.d.ts +9 -1
  157. package/lib/testing/fake-clock.d.ts.map +1 -1
  158. package/lib/testing/fake-clock.js +54 -45
  159. package/lib/testing/fake-clock.js.map +1 -1
  160. package/lib/testing/index.d.ts +1 -0
  161. package/lib/testing/index.d.ts.map +1 -1
  162. package/lib/testing/index.js +5 -2
  163. package/lib/testing/index.js.map +1 -1
  164. package/lib/testing/node/duplex-connection.d.ts.map +1 -1
  165. package/lib/testing/node/duplex-connection.js +3 -2
  166. package/lib/testing/node/duplex-connection.js.map +1 -1
  167. package/lib/testing/node/duplex-stream.js.map +1 -1
  168. package/lib/testing/node/index.d.ts +1 -0
  169. package/lib/testing/node/index.d.ts.map +1 -1
  170. package/lib/testing/node/index.js +2 -2
  171. package/lib/testing/node/index.js.map +1 -1
  172. package/lib/testing/node/message-port-pair.d.ts +25 -0
  173. package/lib/testing/node/message-port-pair.d.ts.map +1 -0
  174. package/lib/testing/node/message-port-pair.js +26 -0
  175. package/lib/testing/node/message-port-pair.js.map +1 -0
  176. package/lib/testing/wait-for.d.ts +3 -2
  177. package/lib/testing/wait-for.d.ts.map +1 -1
  178. package/lib/testing/wait-for.js +40 -10
  179. package/lib/testing/wait-for.js.map +1 -1
  180. package/lib/tracer.d.ts.map +1 -1
  181. package/lib/tracer.js.map +1 -1
  182. package/lib/transfer-diagnostic.d.ts +33 -0
  183. package/lib/transfer-diagnostic.d.ts.map +1 -1
  184. package/lib/transfer-diagnostic.js +23 -0
  185. package/lib/transfer-diagnostic.js.map +1 -1
  186. package/lib/transfer-document.d.ts +70 -32
  187. package/lib/transfer-document.d.ts.map +1 -1
  188. package/lib/transfer-document.js +17 -9
  189. package/lib/transfer-document.js.map +1 -1
  190. package/lib/uri.d.ts.map +1 -1
  191. package/lib/uri.js.map +1 -1
  192. package/lib/util.d.ts +8 -0
  193. package/lib/util.d.ts.map +1 -1
  194. package/lib/util.js +32 -0
  195. package/lib/util.js.map +1 -1
  196. package/package.json +29 -37
  197. package/src/abstract-logger.ts +8 -0
  198. package/src/client/data-connection.ts +520 -0
  199. package/src/client/data-events.ts +33 -1
  200. package/src/client/data-port.ts +46 -28
  201. package/src/client/data-session.ts +951 -126
  202. package/src/client/index.ts +14 -9
  203. package/src/client/message-relay.ts +30 -8
  204. package/src/client/post-message-transport.ts +219 -4
  205. package/src/client/rpc-connection.ts +281 -0
  206. package/src/client-ids.ts +49 -0
  207. package/src/clock.ts +56 -0
  208. package/src/console-logger.ts +39 -0
  209. package/src/data/data-protocol-methods.ts +13 -4
  210. package/src/data/data-server-protocol.ts +157 -41
  211. package/src/data/events.ts +123 -21
  212. package/src/data/requests.ts +74 -11
  213. package/src/errors.ts +322 -36
  214. package/src/glsp-request-model-args.ts +16 -0
  215. package/src/glsp-save-model-actions.ts +59 -0
  216. package/src/index.ts +10 -0
  217. package/src/latency-collector.ts +8 -3
  218. package/src/logger.ts +28 -2
  219. package/src/messages/index.ts +37 -0
  220. package/src/messages/primitives.ts +271 -0
  221. package/src/model-server.ts +64 -19
  222. package/src/model-service/base-version.ts +72 -0
  223. package/src/model-service/index.ts +4 -5
  224. package/src/model-service/reference-candidate.ts +5 -3
  225. package/src/node/index.ts +14 -0
  226. package/src/node/process-memory.ts +299 -0
  227. package/src/patch-merge.ts +97 -42
  228. package/src/profile-session.ts +9 -4
  229. package/src/random-uuid.ts +21 -0
  230. package/src/reconcile-write.ts +124 -0
  231. package/src/rpc/README.md +4 -5
  232. package/src/rpc/bind-rpc-methods.ts +59 -4
  233. package/src/rpc/create-rpc-proxy.ts +20 -2
  234. package/src/rpc/index.ts +1 -0
  235. package/src/rpc/send-by-method-name.ts +140 -0
  236. package/src/testing/catalogue-audit.ts +111 -0
  237. package/src/testing/data-doubles.ts +149 -25
  238. package/src/testing/fake-clock.ts +62 -47
  239. package/src/testing/index.ts +5 -2
  240. package/src/testing/node/duplex-connection.ts +3 -2
  241. package/src/testing/node/index.ts +2 -2
  242. package/src/testing/node/message-port-pair.ts +40 -0
  243. package/src/testing/wait-for.ts +38 -11
  244. package/src/transfer-diagnostic.ts +40 -0
  245. package/src/transfer-document.ts +87 -34
  246. package/src/util.ts +33 -0
  247. package/lib/model-service/args.d.ts +0 -64
  248. package/lib/model-service/args.d.ts.map +0 -1
  249. package/lib/model-service/args.js.map +0 -1
  250. package/src/model-service/args.ts +0 -67
@@ -33,8 +33,19 @@
33
33
 
34
34
  import { Emitter, type MessageConnection } from 'vscode-jsonrpc';
35
35
  import type { DataPort } from '../client/data-port';
36
+ import { DATA_CLIENT_PROTOCOL_METHODS } from '../data/data-protocol-methods';
36
37
  import type { DataClientProtocol } from '../data/data-server-protocol';
37
- import type { ProjectsChangedEvent, TransferDocumentSavedEvent, TransferDocumentUpdatedEvent } from '../data/events';
38
+ import type {
39
+ ProjectsChangedEvent,
40
+ TransferDocumentDeletedEvent,
41
+ TransferDocumentDirtyChangedEvent,
42
+ TransferDocumentSavedEvent,
43
+ TransferDocumentsBuiltEvent,
44
+ TransferDocumentUpdatedEvent
45
+ } from '../data/events';
46
+ import type { Logger } from '../logger';
47
+ import type { ResolvedMessage } from '../messages/primitives';
48
+ import type { RpcProxyLifecycle } from '../rpc/create-rpc-proxy';
38
49
  import type { Project } from '../project';
39
50
  import type { TransferDiagnostic } from '../transfer-diagnostic';
40
51
  import type { TransferElement } from '../transfer-element';
@@ -49,15 +60,14 @@ export interface FakeDataPortOptions {
49
60
  *
50
61
  * Throwing (or rejecting) here is the transport-construction failure path,
51
62
  * which the consumer surfaces through {@link FakeDataPort.reported}.
63
+ *
64
+ * The double disposes none of these connections and goes on connecting
65
+ * after its dispose, where a real port releases its connection and refuses:
66
+ * the test owns them.
52
67
  */
53
68
  connect(): MessageConnection | Promise<MessageConnection>;
54
- /**
55
- * Stable client identity. Defaults to `'fake-data-port'`, which avoids the
56
- * three sentinels the framework reserves (`'language-client'`, `'unknown'`,
57
- * `'revert-on-close'`); override it when a test needs two distinguishable
58
- * clients on one server.
59
- */
60
- clientId?: string;
69
+ /** The port's {@link DataPort.logger}. */
70
+ logger?: Logger;
61
71
  }
62
72
 
63
73
  /** A {@link DataPort} that records what passed through it. */
@@ -73,10 +83,11 @@ export interface FakeDataPort extends DataPort {
73
83
  /**
74
84
  * Every {@link DataPort.reportError} call, in order. Read from outside: this
75
85
  * is the only place a transport failure surfaces, so a test for the failure
76
- * path asserts on the `context` string here rather than on a rejection that
77
- * the consumer may legitimately swallow.
86
+ * path asserts here rather than on a rejection the consumer may legitimately
87
+ * swallow. Prefer asserting on `message.code`, which is stable, over
88
+ * `message.text`, which is the English default and may be reworded.
78
89
  */
79
- readonly reported: readonly { readonly error: unknown; readonly context: string }[];
90
+ readonly reported: readonly { readonly error: unknown; readonly message: ResolvedMessage }[];
80
91
  /**
81
92
  * Fire {@link DataPort.onDispose} — the host tearing the transport down, a
82
93
  * language-server restart being the case that forces the event to exist.
@@ -96,20 +107,20 @@ export interface FakeDataPort extends DataPort {
96
107
  */
97
108
  export function makeFakeDataPort(options: FakeDataPortOptions): FakeDataPort {
98
109
  const connections: MessageConnection[] = [];
99
- const reported: { error: unknown; context: string }[] = [];
110
+ const reported: { error: unknown; message: ResolvedMessage }[] = [];
100
111
  const disposeEmitter = new Emitter<void>();
101
112
  return {
102
- clientId: options.clientId ?? 'fake-data-port',
103
113
  connections,
104
114
  reported,
115
+ logger: options.logger,
105
116
  onDispose: disposeEmitter.event,
106
117
  async connect(): Promise<MessageConnection> {
107
118
  const connection = await options.connect();
108
119
  connections.push(connection);
109
120
  return connection;
110
121
  },
111
- reportError(error: unknown, context: string): void {
112
- reported.push({ error, context });
122
+ reportError(error: unknown, message: ResolvedMessage): void {
123
+ reported.push({ error, message });
113
124
  },
114
125
  fireDispose(): void {
115
126
  disposeEmitter.fire(undefined);
@@ -120,26 +131,78 @@ export function makeFakeDataPort(options: FakeDataPortOptions): FakeDataPort {
120
131
  };
121
132
  }
122
133
 
134
+ type UpperLetter =
135
+ | 'A'
136
+ | 'B'
137
+ | 'C'
138
+ | 'D'
139
+ | 'E'
140
+ | 'F'
141
+ | 'G'
142
+ | 'H'
143
+ | 'I'
144
+ | 'J'
145
+ | 'K'
146
+ | 'L'
147
+ | 'M'
148
+ | 'N'
149
+ | 'O'
150
+ | 'P'
151
+ | 'Q'
152
+ | 'R'
153
+ | 'S'
154
+ | 'T'
155
+ | 'U'
156
+ | 'V'
157
+ | 'W'
158
+ | 'X'
159
+ | 'Y'
160
+ | 'Z';
161
+
162
+ /**
163
+ * A notification name `TClient` adds to {@link DataClientProtocol}. Limited to
164
+ * `on` plus a letter A–Z, the names the proxy sends as notifications; any other
165
+ * name would be bound as a request. The {@link RpcProxyLifecycle} names are
166
+ * excluded too: the proxy returns its own events for them and sends nothing.
167
+ */
168
+ export type AdditionalClientMethod<TClient> = Exclude<keyof TClient, keyof DataClientProtocol<TransferElement> | keyof RpcProxyLifecycle> &
169
+ `on${UpperLetter}${string}`;
170
+
123
171
  /** A {@link DataClientProtocol} plus the arrays it records into. */
124
172
  export interface CapturingDataClient<
125
173
  TTransfer extends TransferElement,
126
174
  TDiagnostic extends TransferDiagnostic = TransferDiagnostic,
127
- TProject extends Project = Project
175
+ TProject extends Project = Project,
176
+ TClient extends DataClientProtocol<TTransfer, TDiagnostic, TProject> = DataClientProtocol<TTransfer, TDiagnostic, TProject>
128
177
  > {
129
178
  /** The client to hand to a `DataSession` or bind as an RPC `localTarget`. */
130
- readonly client: DataClientProtocol<TTransfer, TDiagnostic, TProject>;
179
+ readonly client: TClient;
131
180
  /** Every `onDocumentUpdated` event, in arrival order. */
132
181
  readonly updates: TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>[];
133
182
  /** Every `onDocumentSaved` event, in arrival order. */
134
183
  readonly saves: TransferDocumentSavedEvent<TTransfer, TDiagnostic>[];
184
+ /** Every `onDocumentDirtyChanged` event, in arrival order. */
185
+ readonly dirtyChanges: TransferDocumentDirtyChangedEvent[];
186
+ /** Every `onDocumentDeleted` event, in arrival order. */
187
+ readonly deletions: TransferDocumentDeletedEvent[];
188
+ /** Every `onDocumentsBuilt` event, in arrival order. */
189
+ readonly builds: TransferDocumentsBuiltEvent[];
135
190
  /** Every `onProjectsChanged` event, in arrival order. */
136
191
  readonly projectsChanges: ProjectsChangedEvent<TProject>[];
192
+ /**
193
+ * Every event of each additional client method, keyed by method, in arrival
194
+ * order. A method of `TClient` left out of `additionalClientMethods` has no
195
+ * entry.
196
+ */
197
+ readonly additionalNotifications: {
198
+ readonly [K in AdditionalClientMethod<TClient>]: TClient[K] extends (event: infer TEvent) => void ? TEvent[] : never;
199
+ };
137
200
  }
138
201
 
139
202
  /**
140
203
  * A {@link DataClientProtocol} that records every notification it receives.
141
204
  *
142
- * Recording ALL THREE channels even when a suite reads one is deliberate: an
205
+ * Recording EVERY channel even when a suite reads one is deliberate: an
143
206
  * event delivered on the wrong channel is a real defect of the data head, and a
144
207
  * double that drops the other two turns it into silence on the one being
145
208
  * watched.
@@ -148,31 +211,92 @@ export interface CapturingDataClient<
148
211
  * the corresponding array stays empty — that is what makes an override usable
149
212
  * as a barrier (rejecting, counting differently, throwing) rather than only as
150
213
  * a spy.
214
+ *
215
+ * `additionalClientMethods` names the notifications `TClient` adds to
216
+ * {@link DataClientProtocol}. Each is recorded and overridable the same way;
217
+ * one left out is not on the client at all, and overriding it throws, since
218
+ * nothing would call the override.
151
219
  */
152
220
  export function makeCapturingDataClient<
153
221
  TTransfer extends TransferElement,
154
222
  TDiagnostic extends TransferDiagnostic = TransferDiagnostic,
155
- TProject extends Project = Project
156
- >(overrides: Partial<DataClientProtocol<TTransfer, TDiagnostic, TProject>> = {}): CapturingDataClient<TTransfer, TDiagnostic, TProject> {
223
+ TProject extends Project = Project,
224
+ TClient extends DataClientProtocol<TTransfer, TDiagnostic, TProject> = DataClientProtocol<TTransfer, TDiagnostic, TProject>
225
+ >(
226
+ overrides: Partial<TClient> = {},
227
+ additionalClientMethods: readonly AdditionalClientMethod<TClient>[] = []
228
+ ): CapturingDataClient<TTransfer, TDiagnostic, TProject, TClient> {
229
+ const bound = new Set<string>([...DATA_CLIENT_PROTOCOL_METHODS, ...additionalClientMethods]);
230
+ for (const name of Object.keys(overrides)) {
231
+ if (!bound.has(name)) {
232
+ throw new Error(
233
+ `Override '${name}' is neither a DataClientProtocol method nor listed in additionalClientMethods, so nothing would call it.`
234
+ );
235
+ }
236
+ }
237
+ const frameworkOverrides: Partial<DataClientProtocol<TTransfer, TDiagnostic, TProject>> = overrides;
157
238
  const updates: TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>[] = [];
158
239
  const saves: TransferDocumentSavedEvent<TTransfer, TDiagnostic>[] = [];
240
+ const dirtyChanges: TransferDocumentDirtyChangedEvent[] = [];
241
+ const deletions: TransferDocumentDeletedEvent[] = [];
242
+ const builds: TransferDocumentsBuiltEvent[] = [];
159
243
  const projectsChanges: ProjectsChangedEvent<TProject>[] = [];
160
- const client: DataClientProtocol<TTransfer, TDiagnostic, TProject> = {
244
+ const frameworkClient: DataClientProtocol<TTransfer, TDiagnostic, TProject> = {
161
245
  onDocumentUpdated:
162
- overrides.onDocumentUpdated ??
246
+ frameworkOverrides.onDocumentUpdated ??
163
247
  (event => {
164
248
  updates.push(event);
165
249
  }),
166
250
  onDocumentSaved:
167
- overrides.onDocumentSaved ??
251
+ frameworkOverrides.onDocumentSaved ??
168
252
  (event => {
169
253
  saves.push(event);
170
254
  }),
255
+ onDocumentDirtyChanged:
256
+ frameworkOverrides.onDocumentDirtyChanged ??
257
+ (event => {
258
+ dirtyChanges.push(event);
259
+ }),
260
+ onDocumentDeleted:
261
+ frameworkOverrides.onDocumentDeleted ??
262
+ (event => {
263
+ deletions.push(event);
264
+ }),
265
+ onDocumentsBuilt:
266
+ frameworkOverrides.onDocumentsBuilt ??
267
+ (event => {
268
+ builds.push(event);
269
+ }),
171
270
  onProjectsChanged:
172
- overrides.onProjectsChanged ??
271
+ frameworkOverrides.onProjectsChanged ??
173
272
  (event => {
174
273
  projectsChanges.push(event);
175
274
  })
176
275
  };
177
- return { client, updates, saves, projectsChanges };
276
+ const additionalNotifications: Record<string, unknown[]> = {};
277
+ const additionalHandlers: Record<string, unknown> = {};
278
+ for (const method of additionalClientMethods) {
279
+ const events: unknown[] = [];
280
+ additionalNotifications[method] = events;
281
+ additionalHandlers[method] =
282
+ overrides[method] ??
283
+ ((event: unknown) => {
284
+ events.push(event);
285
+ });
286
+ }
287
+ return {
288
+ client: { ...frameworkClient, ...additionalHandlers } as unknown as TClient,
289
+ updates,
290
+ saves,
291
+ dirtyChanges,
292
+ deletions,
293
+ builds,
294
+ projectsChanges,
295
+ additionalNotifications: additionalNotifications as CapturingDataClient<
296
+ TTransfer,
297
+ TDiagnostic,
298
+ TProject,
299
+ TClient
300
+ >['additionalNotifications']
301
+ };
178
302
  }
@@ -7,7 +7,7 @@
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
9
 
10
- import { type Clock, type Stopwatch, type Timed } from '../clock';
10
+ import { type Clock, type Stopwatch, SystemClock } from '../clock';
11
11
  import { Disposable } from '../util';
12
12
 
13
13
  /** A {@link Clock} whose time only moves when the test calls {@link FakeClock.advance}. */
@@ -17,9 +17,13 @@ export interface FakeClock extends Clock {
17
17
  * whose deadline falls within the window — in chronological order, each at
18
18
  * its own deadline (so `now()` inside a callback reads the fire instant, not
19
19
  * the advance target). Timers scheduled by a callback fire too if they fall
20
- * within the same window.
20
+ * within the same window. A {@link Clock.raceTimer} over a promise that
21
+ * settles through a chain still pending loses to the timer, so let that
22
+ * chain settle before advancing.
21
23
  */
22
24
  advance(ms: number): void;
25
+ /** How many {@link Clock.setTimer} timers have neither fired nor been disposed. */
26
+ pendingTimers(): number;
23
27
  }
24
28
 
25
29
  interface FakeTimer {
@@ -39,68 +43,79 @@ interface FakeTimer {
39
43
  *
40
44
  * Server-free and DI-free — lives in `@hydranium/protocol/testing` so every
41
45
  * head can bind it without pulling in a server package.
46
+ *
47
+ * The clock is a `SystemClock` with its time replaced, so its methods live on
48
+ * its prototype and a spread of it carries none of them. Replace one by
49
+ * assigning it onto the clock, or layer over the clock with `Object.create`.
42
50
  */
43
51
  export function makeFakeClock(options: { now?: number } = {}): FakeClock {
44
- let current = options.now ?? 0;
45
- const timers: FakeTimer[] = [];
52
+ return new VirtualClock(options.now ?? 0);
53
+ }
54
+
55
+ /**
56
+ * A `SystemClock` whose time, stopwatches and timers read one virtual axis, so
57
+ * the `measure` and `raceTimer` it inherits run on that axis too.
58
+ */
59
+ class VirtualClock extends SystemClock implements FakeClock {
60
+ protected readonly timers: FakeTimer[] = [];
46
61
 
47
- const makeStopwatch = (): Stopwatch => {
48
- const start = current;
49
- let lastLap = current;
62
+ constructor(protected current: number) {
63
+ super();
64
+ }
65
+
66
+ override now(): number {
67
+ return this.current;
68
+ }
69
+
70
+ override setTimer(callback: () => void, ms: number): Disposable {
71
+ const timer: FakeTimer = { at: this.current + ms, callback, disposed: false, fired: false };
72
+ this.timers.push(timer);
73
+ return Disposable.create(() => {
74
+ timer.disposed = true;
75
+ });
76
+ }
77
+
78
+ override stopwatch(): Stopwatch {
79
+ const read = (): number => this.current;
80
+ const start = read();
81
+ let lastLap = start;
50
82
  let stopped: number | undefined;
51
83
  return {
52
84
  get elapsedMs(): number {
53
- return (stopped ?? current) - start;
85
+ return (stopped ?? read()) - start;
54
86
  },
55
87
  lap(): number {
56
- const at = stopped ?? current;
88
+ const at = stopped ?? read();
57
89
  const split = at - lastLap;
58
90
  lastLap = at;
59
91
  return split;
60
92
  },
61
93
  stop(): number {
62
- if (stopped === undefined) {
63
- stopped = current;
64
- }
94
+ stopped ??= read();
65
95
  return stopped - start;
66
96
  }
67
97
  };
68
- };
98
+ }
69
99
 
70
- return {
71
- now: () => current,
72
- setTimer(callback: () => void, ms: number): Disposable {
73
- const timer: FakeTimer = { at: current + ms, callback, disposed: false, fired: false };
74
- timers.push(timer);
75
- return Disposable.create(() => {
76
- timer.disposed = true;
77
- });
78
- },
79
- stopwatch: makeStopwatch,
80
- measure: (<T>(callback: () => T | Promise<T>): Timed<T> | Promise<Timed<T>> => {
81
- const stopwatch = makeStopwatch();
82
- const result = callback();
83
- if (result instanceof Promise) {
84
- return (result as Promise<T>).then(value => ({ result: value, elapsedMs: stopwatch.elapsedMs }));
85
- }
86
- return { result: result as T, elapsedMs: stopwatch.elapsedMs };
87
- }) as Clock['measure'],
88
- advance(ms: number): void {
89
- const target = current + ms;
90
- // Fire due timers one at a time, re-scanning after each so a callback
91
- // that schedules a nearer timer still fires within this window.
92
- for (;;) {
93
- const next = timers
94
- .filter(timer => !timer.disposed && !timer.fired && timer.at <= target)
95
- .sort((left, right) => left.at - right.at)[0];
96
- if (!next) {
97
- break;
98
- }
99
- current = next.at;
100
- next.fired = true;
101
- next.callback();
100
+ pendingTimers(): number {
101
+ return this.timers.filter(timer => !timer.disposed && !timer.fired).length;
102
+ }
103
+
104
+ advance(ms: number): void {
105
+ const target = this.current + ms;
106
+ // Fire due timers one at a time, re-scanning after each so a callback
107
+ // that schedules a nearer timer still fires within this window.
108
+ for (;;) {
109
+ const next = this.timers
110
+ .filter(timer => !timer.disposed && !timer.fired && timer.at <= target)
111
+ .sort((left, right) => left.at - right.at)[0];
112
+ if (!next) {
113
+ break;
102
114
  }
103
- current = target;
115
+ this.current = next.at;
116
+ next.fired = true;
117
+ next.callback();
104
118
  }
105
- };
119
+ this.current = target;
120
+ }
106
121
  }
@@ -10,16 +10,19 @@
10
10
  // Subpath barrel for `@hydranium/protocol/testing` — the BROWSER-NEUTRAL shared
11
11
  // primitives: `makeFakeClock` (deterministic `Clock` double on one virtual time
12
12
  // axis), `waitFor` / `tick`, the client-side data-head doubles
13
- // (`makeFakeDataPort` / `makeCapturingDataClient`), and the `Harness` marker
13
+ // (`makeFakeDataPort` / `makeCapturingDataClient`), the translation-catalogue
14
+ // audit (`flattenCatalogue` / `findUndeclaredCodes` / `findSharedCodes`), and
15
+ // the `Harness` marker
14
16
  // interface every framework harness extends. Kept out of the main barrel so production bundles don't pull
15
17
  // the test scaffolding in by default; adopters opt in by importing from
16
18
  // `@hydranium/protocol/testing`.
17
19
  //
18
- // Neutrality is gated (`scripts/check-neutral-bundles.mjs`), which is why the
20
+ // Neutrality is gated (`scripts/check-neutral-bundles.mts`), which is why the
19
21
  // duplex transports are NOT here: a `PassThrough` pair is in their exported
20
22
  // type, so they cannot be made portable and live at `./testing/node` instead.
21
23
  // The same rule the package surface uses — the portable name is the short one.
22
24
 
25
+ export * from './catalogue-audit';
23
26
  export * from './data-doubles';
24
27
  export * from './fake-clock';
25
28
  export * from './harness';
@@ -32,8 +32,9 @@ export function makeDuplexConnectionPair(): DuplexConnectionPair {
32
32
  const pair = makeDuplexStreamPair();
33
33
  const { clientToServer, serverToClient } = pair;
34
34
 
35
- const left = createMessageConnection(new StreamMessageReader(serverToClient), new StreamMessageWriter(clientToServer));
36
- const right = createMessageConnection(new StreamMessageReader(clientToServer), new StreamMessageWriter(serverToClient));
35
+ // `console`, so a protocol fault on either end shows in the test's output.
36
+ const left = createMessageConnection(new StreamMessageReader(serverToClient), new StreamMessageWriter(clientToServer), console);
37
+ const right = createMessageConnection(new StreamMessageReader(clientToServer), new StreamMessageWriter(serverToClient), console);
37
38
 
38
39
  left.listen();
39
40
  right.listen();
@@ -8,8 +8,7 @@
8
8
  ********************************************************************************/
9
9
 
10
10
  // Subpath barrel for `@hydranium/protocol/testing/node` — the test transports
11
- // that need a Node runtime: a crossed `PassThrough` pair and the in-process
12
- // `MessageConnection` bridge over it.
11
+ // that need a Node runtime.
13
12
  //
14
13
  // Separate from `./testing` because a `PassThrough` is in `DuplexStreamPair`'s
15
14
  // exported type and `StreamMessageReader` comes from `vscode-jsonrpc/node`, so
@@ -20,3 +19,4 @@
20
19
 
21
20
  export * from './duplex-connection';
22
21
  export * from './duplex-stream';
22
+ export * from './message-port-pair';
@@ -0,0 +1,40 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+
10
+ import { MessageChannel } from 'node:worker_threads';
11
+ import type { TransferredMessagePort } from '../../client/post-message-transport';
12
+
13
+ /**
14
+ * The two ends of a `worker_threads` `MessageChannel`, typed as the transferred
15
+ * browser ports `createMessagePortTransport` takes. Node's port clones and keeps
16
+ * order as a browser's does, which is what lets a headless test stand in for a
17
+ * worker.
18
+ *
19
+ * `dispose` closes both ports. Node reports that as a close and a browser port
20
+ * reports nothing, so a test that asserts on a close does so before teardown.
21
+ */
22
+ export interface MessagePortPair {
23
+ readonly port1: TransferredMessagePort;
24
+ readonly port2: TransferredMessagePort;
25
+ dispose(): void;
26
+ }
27
+
28
+ export function makeMessagePortPair(): MessagePortPair {
29
+ const channel = new MessageChannel();
30
+ return {
31
+ // Node's port satisfies the structural type at runtime; the cast records
32
+ // one platform's port standing in for the other's.
33
+ port1: channel.port1 as unknown as TransferredMessagePort,
34
+ port2: channel.port2 as unknown as TransferredMessagePort,
35
+ dispose(): void {
36
+ channel.port1.close();
37
+ channel.port2.close();
38
+ }
39
+ };
40
+ }
@@ -33,13 +33,14 @@ export interface WaitForOptions {
33
33
  readonly timeoutMs?: number;
34
34
  /** Poll the predicate every this-many milliseconds. Default 5. */
35
35
  readonly intervalMs?: number;
36
- /** Error message on timeout. Default a generic phrasing. */
36
+ /** Error message on timeout, and when the predicate throws. Default a generic phrasing. */
37
37
  readonly message?: string;
38
38
  }
39
39
 
40
40
  /**
41
41
  * Resolve once `predicate()` returns true, polling at `intervalMs`; reject with
42
- * `message` once `timeoutMs` elapses. The **non-racy** alternative to a fixed
42
+ * `message` once `timeoutMs` elapses, or at once when the predicate throws, with
43
+ * the throw as the error's `cause`. The **non-racy** alternative to a fixed
43
44
  * sleep for awaiting an asynchronous side effect that lands on an observable
44
45
  * value.
45
46
  *
@@ -57,19 +58,45 @@ export function waitFor(predicate: () => boolean, options: WaitForOptions = {}):
57
58
  const timeoutMs = options.timeoutMs ?? 2000;
58
59
  const intervalMs = options.intervalMs ?? 5;
59
60
  const message = options.message ?? `Timed out after ${timeoutMs}ms waiting for a condition`;
60
- if (predicate()) {
61
- return Promise.resolve();
62
- }
63
61
  return new Promise<void>((resolve, reject) => {
64
- const deadline = setTimeout(() => {
62
+ // A throw would leave the promise unsettled from a timer, or escape
63
+ // `waitFor` itself on the first check; it rejects as the timeout instead,
64
+ // with the throw as cause. True once the promise is settled.
65
+ const settle = (timedOut: boolean): boolean => {
66
+ let met = false;
67
+ let threw = false;
68
+ let cause: unknown;
69
+ try {
70
+ met = predicate();
71
+ } catch (error: unknown) {
72
+ threw = true;
73
+ cause = error;
74
+ }
75
+ if (met) {
76
+ resolve();
77
+ } else if (timedOut || threw) {
78
+ reject(new Error(message, threw ? { cause } : undefined));
79
+ } else {
80
+ return false;
81
+ }
82
+ return true;
83
+ };
84
+ if (settle(false)) {
85
+ return;
86
+ }
87
+ const stop = (): void => {
65
88
  clearInterval(poll);
66
- reject(new Error(message));
89
+ clearTimeout(deadline);
90
+ };
91
+ // A stalled loop can run the deadline after the condition came true but
92
+ // before the next poll saw it, so the deadline checks once more.
93
+ const deadline = setTimeout(() => {
94
+ settle(true);
95
+ stop();
67
96
  }, timeoutMs);
68
97
  const poll = setInterval(() => {
69
- if (predicate()) {
70
- clearInterval(poll);
71
- clearTimeout(deadline);
72
- resolve();
98
+ if (settle(false)) {
99
+ stop();
73
100
  }
74
101
  }, intervalMs);
75
102
  });
@@ -7,6 +7,8 @@
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
9
 
10
+ import { type MessageParams, type ResolvedMessage } from './messages/primitives';
11
+
10
12
  /**
11
13
  * Generic, transport-friendly diagnostic shape used by the model-server protocol.
12
14
  *
@@ -56,6 +58,21 @@ export interface TransferDiagnostic {
56
58
  * is not usable as a rule identity on its own.
57
59
  */
58
60
  code?: number | string;
61
+ /**
62
+ * Substitutions for the placeholders in the message this {@link code} names,
63
+ * present only for a diagnostic raised from a framework message declaration.
64
+ *
65
+ * Without them a translated template renders with its `{name}` tokens left
66
+ * standing, because substitution leaves an unmatched token in place rather
67
+ * than raising — so a surface that translates from {@link code} alone is
68
+ * correct for a parameterless sentence and visibly wrong for a parameterised
69
+ * one. This is the field that makes the second case work; the LSP carrier has
70
+ * always moved the params, and no carrier below it did.
71
+ *
72
+ * Prefer {@link TransferDiagnostic.resolved} over reading this: it decides
73
+ * whether an identity is present at all, which a lone `params` cannot.
74
+ */
75
+ params?: MessageParams;
59
76
  }
60
77
 
61
78
  export namespace TransferDiagnostic {
@@ -74,6 +91,29 @@ export namespace TransferDiagnostic {
74
91
  return diagnostic.type === 'parsing-error';
75
92
  }
76
93
 
94
+ /**
95
+ * The diagnostic as a renderable message, for a surface that translates.
96
+ * `undefined` when it carries no framework identity — a syntactic error, an
97
+ * adopter's own check, a linker failure — which is the case a caller must
98
+ * distinguish rather than render.
99
+ *
100
+ * Hand the result to `renderFrameworkMessage` with whatever catalogue the
101
+ * host has loaded. The `text` is the server's English, so a code the
102
+ * catalogue does not carry still yields a complete sentence.
103
+ *
104
+ * `code` alone does not establish an identity: it also holds Langium's
105
+ * internal code and an adopter's own, and either would be looked up against a
106
+ * catalogue that cannot have it. Requiring `params` is what discriminates,
107
+ * and it is why a parameterless framework message still populates the field
108
+ * with an empty object rather than omitting it.
109
+ */
110
+ export function resolved(diagnostic: TransferDiagnostic): ResolvedMessage | undefined {
111
+ if (typeof diagnostic.code !== 'string' || diagnostic.params === undefined) {
112
+ return undefined;
113
+ }
114
+ return { code: diagnostic.code, params: diagnostic.params, text: diagnostic.message };
115
+ }
116
+
77
117
  export function getPath(diagnostic: TransferDiagnostic): string {
78
118
  return diagnostic.property ? `${diagnostic.element}${ELEMENT_PROPERTY_SEPARATOR}${diagnostic.property}` : diagnostic.element;
79
119
  }