@hydranium/protocol 1.0.0-next.29 → 1.0.0-next.299
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.md +44 -49
- package/lib/abstract-logger.d.ts +5 -0
- package/lib/abstract-logger.d.ts.map +1 -1
- package/lib/abstract-logger.js +7 -0
- package/lib/abstract-logger.js.map +1 -1
- package/lib/client/data-connection.d.ts +302 -0
- package/lib/client/data-connection.d.ts.map +1 -0
- package/lib/client/data-connection.js +533 -0
- package/lib/client/data-connection.js.map +1 -0
- package/lib/client/data-events.d.ts +17 -1
- package/lib/client/data-events.d.ts.map +1 -1
- package/lib/client/data-events.js +25 -0
- package/lib/client/data-events.js.map +1 -1
- package/lib/client/data-port.d.ts +34 -24
- package/lib/client/data-port.d.ts.map +1 -1
- package/lib/client/data-session.d.ts +657 -89
- package/lib/client/data-session.d.ts.map +1 -1
- package/lib/client/data-session.js +1113 -115
- package/lib/client/data-session.js.map +1 -1
- package/lib/client/index.d.ts +15 -9
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +15 -9
- package/lib/client/index.js.map +1 -1
- package/lib/client/message-relay.d.ts +4 -4
- package/lib/client/message-relay.js +4 -4
- package/lib/client/message-relay.js.map +1 -1
- package/lib/client/post-message-transport.d.ts +64 -3
- package/lib/client/post-message-transport.d.ts.map +1 -1
- package/lib/client/post-message-transport.js +175 -1
- package/lib/client/post-message-transport.js.map +1 -1
- package/lib/client/rpc-connection.d.ts +157 -0
- package/lib/client/rpc-connection.d.ts.map +1 -0
- package/lib/client/rpc-connection.js +214 -0
- package/lib/client/rpc-connection.js.map +1 -0
- package/lib/client/worker-handshake.d.ts +72 -0
- package/lib/client/worker-handshake.d.ts.map +1 -0
- package/lib/client/worker-handshake.js +51 -0
- package/lib/client/worker-handshake.js.map +1 -0
- package/lib/client-ids.d.ts +45 -0
- package/lib/client-ids.d.ts.map +1 -0
- package/lib/client-ids.js +48 -0
- package/lib/client-ids.js.map +1 -0
- package/lib/clock.d.ts +50 -10
- package/lib/clock.d.ts.map +1 -1
- package/lib/clock.js +36 -1
- package/lib/clock.js.map +1 -1
- package/lib/console-logger.d.ts +23 -0
- package/lib/console-logger.d.ts.map +1 -0
- package/lib/console-logger.js +39 -0
- package/lib/console-logger.js.map +1 -0
- package/lib/data/data-protocol-methods.d.ts +4 -4
- package/lib/data/data-protocol-methods.d.ts.map +1 -1
- package/lib/data/data-protocol-methods.js +13 -1
- package/lib/data/data-protocol-methods.js.map +1 -1
- package/lib/data/data-server-protocol.d.ts +165 -48
- package/lib/data/data-server-protocol.d.ts.map +1 -1
- package/lib/data/events.d.ts +137 -21
- package/lib/data/events.d.ts.map +1 -1
- package/lib/data/requests.d.ts +71 -11
- package/lib/data/requests.d.ts.map +1 -1
- package/lib/debouncer.d.ts +3 -3
- package/lib/debouncer.d.ts.map +1 -1
- package/lib/debouncer.js +6 -9
- package/lib/debouncer.js.map +1 -1
- package/lib/errors.d.ts +175 -30
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +260 -32
- package/lib/errors.js.map +1 -1
- package/lib/glsp-request-model-args.d.ts +16 -0
- package/lib/glsp-request-model-args.d.ts.map +1 -0
- package/lib/glsp-request-model-args.js +19 -0
- package/lib/glsp-request-model-args.js.map +1 -0
- package/lib/glsp-save-model-actions.d.ts +50 -0
- package/lib/glsp-save-model-actions.d.ts.map +1 -0
- package/lib/glsp-save-model-actions.js +28 -0
- package/lib/glsp-save-model-actions.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -1
- package/lib/latency-collector.d.ts +8 -4
- package/lib/latency-collector.d.ts.map +1 -1
- package/lib/latency-collector.js.map +1 -1
- package/lib/logger.d.ts +38 -7
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +42 -4
- package/lib/logger.js.map +1 -1
- package/lib/messages/index.d.ts +4 -2
- package/lib/messages/index.d.ts.map +1 -1
- package/lib/messages/index.js +14 -4
- package/lib/messages/index.js.map +1 -1
- package/lib/messages/primitives.d.ts +71 -10
- package/lib/messages/primitives.d.ts.map +1 -1
- package/lib/messages/primitives.js +55 -3
- package/lib/messages/primitives.js.map +1 -1
- package/lib/model-server.d.ts +60 -13
- package/lib/model-server.d.ts.map +1 -1
- package/lib/model-server.js +4 -2
- package/lib/model-server.js.map +1 -1
- package/lib/model-service/base-version.d.ts +67 -0
- package/lib/model-service/base-version.d.ts.map +1 -0
- package/lib/model-service/base-version.js +44 -0
- package/lib/model-service/base-version.js.map +1 -0
- package/lib/model-service/index.d.ts +1 -1
- package/lib/model-service/index.d.ts.map +1 -1
- package/lib/model-service/index.js +4 -5
- package/lib/model-service/index.js.map +1 -1
- package/lib/model-service/reference-candidate.d.ts +5 -3
- package/lib/model-service/reference-candidate.d.ts.map +1 -1
- package/lib/{model-service/args.js → node/index.d.ts} +2 -3
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +29 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/process-memory.d.ts +66 -0
- package/lib/node/process-memory.d.ts.map +1 -0
- package/lib/node/process-memory.js +291 -0
- package/lib/node/process-memory.js.map +1 -0
- package/lib/noop-logger.d.ts.map +1 -1
- package/lib/noop-logger.js.map +1 -1
- package/lib/observable-value.js.map +1 -1
- package/lib/patch-merge.d.ts +63 -35
- package/lib/patch-merge.d.ts.map +1 -1
- package/lib/patch-merge.js +171 -25
- package/lib/patch-merge.js.map +1 -1
- package/lib/profile-session.d.ts +8 -4
- package/lib/profile-session.d.ts.map +1 -1
- package/lib/profile-session.js.map +1 -1
- package/lib/project.d.ts +4 -1
- package/lib/project.d.ts.map +1 -1
- package/lib/project.js.map +1 -1
- package/lib/random-uuid.d.ts +14 -0
- package/lib/random-uuid.d.ts.map +1 -0
- package/lib/random-uuid.js +24 -0
- package/lib/random-uuid.js.map +1 -0
- package/lib/reconcile-write.d.ts +67 -0
- package/lib/reconcile-write.d.ts.map +1 -0
- package/lib/reconcile-write.js +69 -0
- package/lib/reconcile-write.js.map +1 -0
- package/lib/rpc/bind-rpc-methods.d.ts +33 -3
- package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
- package/lib/rpc/bind-rpc-methods.js +32 -3
- package/lib/rpc/bind-rpc-methods.js.map +1 -1
- package/lib/rpc/create-rpc-proxy.d.ts +10 -0
- package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
- package/lib/rpc/create-rpc-proxy.js +12 -2
- package/lib/rpc/create-rpc-proxy.js.map +1 -1
- package/lib/rpc/index.d.ts +1 -0
- package/lib/rpc/index.d.ts.map +1 -1
- package/lib/rpc/index.js +1 -0
- package/lib/rpc/index.js.map +1 -1
- package/lib/rpc/send-by-method-name.d.ts +76 -0
- package/lib/rpc/send-by-method-name.d.ts.map +1 -0
- package/lib/rpc/send-by-method-name.js +120 -0
- package/lib/rpc/send-by-method-name.js.map +1 -0
- package/lib/rpc/wire-prefix.js.map +1 -1
- package/lib/testing/catalogue-audit.d.ts +80 -0
- package/lib/testing/catalogue-audit.d.ts.map +1 -0
- package/lib/testing/catalogue-audit.js +94 -0
- package/lib/testing/catalogue-audit.js.map +1 -0
- package/lib/testing/data-doubles.d.ts +41 -12
- package/lib/testing/data-doubles.d.ts.map +1 -1
- package/lib/testing/data-doubles.js +56 -8
- package/lib/testing/data-doubles.js.map +1 -1
- package/lib/testing/fake-clock.d.ts +17 -2
- package/lib/testing/fake-clock.d.ts.map +1 -1
- package/lib/testing/fake-clock.js +61 -46
- package/lib/testing/fake-clock.js.map +1 -1
- package/lib/testing/index.d.ts +1 -0
- package/lib/testing/index.d.ts.map +1 -1
- package/lib/testing/index.js +5 -2
- package/lib/testing/index.js.map +1 -1
- package/lib/testing/node/duplex-connection.d.ts.map +1 -1
- package/lib/testing/node/duplex-connection.js +3 -2
- package/lib/testing/node/duplex-connection.js.map +1 -1
- package/lib/testing/node/duplex-stream.js.map +1 -1
- package/lib/testing/node/index.d.ts +1 -0
- package/lib/testing/node/index.d.ts.map +1 -1
- package/lib/testing/node/index.js +2 -2
- package/lib/testing/node/index.js.map +1 -1
- package/lib/testing/node/message-port-pair.d.ts +25 -0
- package/lib/testing/node/message-port-pair.d.ts.map +1 -0
- package/lib/testing/node/message-port-pair.js +26 -0
- package/lib/testing/node/message-port-pair.js.map +1 -0
- package/lib/testing/wait-for.d.ts +9 -3
- package/lib/testing/wait-for.d.ts.map +1 -1
- package/lib/testing/wait-for.js +57 -11
- package/lib/testing/wait-for.js.map +1 -1
- package/lib/tracer.d.ts.map +1 -1
- package/lib/tracer.js +5 -9
- package/lib/tracer.js.map +1 -1
- package/lib/transfer-diagnostic.js.map +1 -1
- package/lib/transfer-document.d.ts +95 -32
- package/lib/transfer-document.d.ts.map +1 -1
- package/lib/transfer-document.js +17 -9
- package/lib/transfer-document.js.map +1 -1
- package/lib/uri.d.ts.map +1 -1
- package/lib/uri.js.map +1 -1
- package/lib/util.d.ts +8 -2
- package/lib/util.d.ts.map +1 -1
- package/lib/util.js +32 -4
- package/lib/util.js.map +1 -1
- package/package.json +24 -40
- package/src/abstract-logger.ts +8 -0
- package/src/client/data-connection.ts +653 -0
- package/src/client/data-events.ts +37 -1
- package/src/client/data-port.ts +36 -25
- package/src/client/data-session.ts +1427 -137
- package/src/client/index.ts +15 -9
- package/src/client/message-relay.ts +4 -4
- package/src/client/post-message-transport.ts +219 -4
- package/src/client/rpc-connection.ts +281 -0
- package/src/client/worker-handshake.ts +98 -0
- package/src/client-ids.ts +49 -0
- package/src/clock.ts +68 -10
- package/src/console-logger.ts +39 -0
- package/src/data/data-protocol-methods.ts +14 -4
- package/src/data/data-server-protocol.ts +192 -48
- package/src/data/events.ts +143 -21
- package/src/data/requests.ts +77 -11
- package/src/debouncer.ts +7 -10
- package/src/errors.ts +309 -40
- package/src/glsp-request-model-args.ts +16 -0
- package/src/glsp-save-model-actions.ts +59 -0
- package/src/index.ts +6 -0
- package/src/latency-collector.ts +8 -3
- package/src/logger.ts +44 -8
- package/src/messages/index.ts +4 -2
- package/src/messages/primitives.ts +102 -10
- package/src/model-server.ts +64 -19
- package/src/model-service/base-version.ts +75 -0
- package/src/model-service/index.ts +4 -5
- package/src/model-service/reference-candidate.ts +5 -3
- package/src/node/index.ts +14 -0
- package/src/node/process-memory.ts +299 -0
- package/src/patch-merge.ts +230 -45
- package/src/profile-session.ts +9 -4
- package/src/project.ts +4 -1
- package/src/random-uuid.ts +21 -0
- package/src/reconcile-write.ts +128 -0
- package/src/rpc/README.md +6 -6
- package/src/rpc/bind-rpc-methods.ts +59 -4
- package/src/rpc/create-rpc-proxy.ts +20 -2
- package/src/rpc/index.ts +1 -0
- package/src/rpc/send-by-method-name.ts +140 -0
- package/src/testing/catalogue-audit.ts +111 -0
- package/src/testing/data-doubles.ts +141 -19
- package/src/testing/fake-clock.ts +76 -48
- package/src/testing/index.ts +5 -2
- package/src/testing/node/duplex-connection.ts +3 -2
- package/src/testing/node/index.ts +2 -2
- package/src/testing/node/message-port-pair.ts +40 -0
- package/src/testing/wait-for.ts +61 -13
- package/src/tracer.ts +5 -9
- package/src/transfer-document.ts +115 -34
- package/src/util.ts +33 -6
- package/lib/model-service/args.d.ts +0 -64
- package/lib/model-service/args.d.ts.map +0 -1
- package/lib/model-service/args.js.map +0 -1
- package/src/model-service/args.ts +0 -67
|
@@ -33,9 +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 {
|
|
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';
|
|
38
47
|
import type { ResolvedMessage } from '../messages/primitives';
|
|
48
|
+
import type { RpcProxyLifecycle } from '../rpc/create-rpc-proxy';
|
|
39
49
|
import type { Project } from '../project';
|
|
40
50
|
import type { TransferDiagnostic } from '../transfer-diagnostic';
|
|
41
51
|
import type { TransferElement } from '../transfer-element';
|
|
@@ -50,15 +60,14 @@ export interface FakeDataPortOptions {
|
|
|
50
60
|
*
|
|
51
61
|
* Throwing (or rejecting) here is the transport-construction failure path,
|
|
52
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.
|
|
53
67
|
*/
|
|
54
68
|
connect(): MessageConnection | Promise<MessageConnection>;
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
* three sentinels the framework reserves (`'language-client'`, `'unknown'`,
|
|
58
|
-
* `'revert-on-close'`); override it when a test needs two distinguishable
|
|
59
|
-
* clients on one server.
|
|
60
|
-
*/
|
|
61
|
-
clientId?: string;
|
|
69
|
+
/** The port's {@link DataPort.logger}. */
|
|
70
|
+
logger?: Logger;
|
|
62
71
|
}
|
|
63
72
|
|
|
64
73
|
/** A {@link DataPort} that records what passed through it. */
|
|
@@ -101,9 +110,9 @@ export function makeFakeDataPort(options: FakeDataPortOptions): FakeDataPort {
|
|
|
101
110
|
const reported: { error: unknown; message: ResolvedMessage }[] = [];
|
|
102
111
|
const disposeEmitter = new Emitter<void>();
|
|
103
112
|
return {
|
|
104
|
-
clientId: options.clientId ?? 'fake-data-port',
|
|
105
113
|
connections,
|
|
106
114
|
reported,
|
|
115
|
+
logger: options.logger,
|
|
107
116
|
onDispose: disposeEmitter.event,
|
|
108
117
|
async connect(): Promise<MessageConnection> {
|
|
109
118
|
const connection = await options.connect();
|
|
@@ -122,26 +131,78 @@ export function makeFakeDataPort(options: FakeDataPortOptions): FakeDataPort {
|
|
|
122
131
|
};
|
|
123
132
|
}
|
|
124
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
|
+
|
|
125
171
|
/** A {@link DataClientProtocol} plus the arrays it records into. */
|
|
126
172
|
export interface CapturingDataClient<
|
|
127
173
|
TTransfer extends TransferElement,
|
|
128
174
|
TDiagnostic extends TransferDiagnostic = TransferDiagnostic,
|
|
129
|
-
TProject extends Project = Project
|
|
175
|
+
TProject extends Project = Project,
|
|
176
|
+
TClient extends DataClientProtocol<TTransfer, TDiagnostic, TProject> = DataClientProtocol<TTransfer, TDiagnostic, TProject>
|
|
130
177
|
> {
|
|
131
178
|
/** The client to hand to a `DataSession` or bind as an RPC `localTarget`. */
|
|
132
|
-
readonly client:
|
|
179
|
+
readonly client: TClient;
|
|
133
180
|
/** Every `onDocumentUpdated` event, in arrival order. */
|
|
134
181
|
readonly updates: TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>[];
|
|
135
182
|
/** Every `onDocumentSaved` event, in arrival order. */
|
|
136
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[];
|
|
137
190
|
/** Every `onProjectsChanged` event, in arrival order. */
|
|
138
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
|
+
};
|
|
139
200
|
}
|
|
140
201
|
|
|
141
202
|
/**
|
|
142
203
|
* A {@link DataClientProtocol} that records every notification it receives.
|
|
143
204
|
*
|
|
144
|
-
* Recording
|
|
205
|
+
* Recording EVERY channel even when a suite reads one is deliberate: an
|
|
145
206
|
* event delivered on the wrong channel is a real defect of the data head, and a
|
|
146
207
|
* double that drops the other two turns it into silence on the one being
|
|
147
208
|
* watched.
|
|
@@ -150,31 +211,92 @@ export interface CapturingDataClient<
|
|
|
150
211
|
* the corresponding array stays empty — that is what makes an override usable
|
|
151
212
|
* as a barrier (rejecting, counting differently, throwing) rather than only as
|
|
152
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.
|
|
153
219
|
*/
|
|
154
220
|
export function makeCapturingDataClient<
|
|
155
221
|
TTransfer extends TransferElement,
|
|
156
222
|
TDiagnostic extends TransferDiagnostic = TransferDiagnostic,
|
|
157
|
-
TProject extends Project = Project
|
|
158
|
-
|
|
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;
|
|
159
238
|
const updates: TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>[] = [];
|
|
160
239
|
const saves: TransferDocumentSavedEvent<TTransfer, TDiagnostic>[] = [];
|
|
240
|
+
const dirtyChanges: TransferDocumentDirtyChangedEvent[] = [];
|
|
241
|
+
const deletions: TransferDocumentDeletedEvent[] = [];
|
|
242
|
+
const builds: TransferDocumentsBuiltEvent[] = [];
|
|
161
243
|
const projectsChanges: ProjectsChangedEvent<TProject>[] = [];
|
|
162
|
-
const
|
|
244
|
+
const frameworkClient: DataClientProtocol<TTransfer, TDiagnostic, TProject> = {
|
|
163
245
|
onDocumentUpdated:
|
|
164
|
-
|
|
246
|
+
frameworkOverrides.onDocumentUpdated ??
|
|
165
247
|
(event => {
|
|
166
248
|
updates.push(event);
|
|
167
249
|
}),
|
|
168
250
|
onDocumentSaved:
|
|
169
|
-
|
|
251
|
+
frameworkOverrides.onDocumentSaved ??
|
|
170
252
|
(event => {
|
|
171
253
|
saves.push(event);
|
|
172
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
|
+
}),
|
|
173
270
|
onProjectsChanged:
|
|
174
|
-
|
|
271
|
+
frameworkOverrides.onProjectsChanged ??
|
|
175
272
|
(event => {
|
|
176
273
|
projectsChanges.push(event);
|
|
177
274
|
})
|
|
178
275
|
};
|
|
179
|
-
|
|
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
|
+
};
|
|
180
302
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
-
import { type Clock, type Stopwatch,
|
|
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,19 @@ 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
|
+
/**
|
|
26
|
+
* Move `now()` by `ms`, backwards when negative, leaving stopwatches and
|
|
27
|
+
* timers where they are: the wall-clock step a time sync or a manual change makes,
|
|
28
|
+
* which a duration taken from two `now()` readings gets wrong.
|
|
29
|
+
*/
|
|
30
|
+
jumpWallClock(ms: number): void;
|
|
31
|
+
/** How many {@link Clock.setTimer} timers have neither fired nor been disposed. */
|
|
32
|
+
pendingTimers(): number;
|
|
23
33
|
}
|
|
24
34
|
|
|
25
35
|
interface FakeTimer {
|
|
@@ -35,72 +45,90 @@ interface FakeTimer {
|
|
|
35
45
|
* (`Date.now` for `now()`, `performance.now()` for the stopwatch); the fake
|
|
36
46
|
* collapses them onto ONE virtual time axis, so a single
|
|
37
47
|
* {@link FakeClock.advance} drives `now()`, every live stopwatch's elapsed, and
|
|
38
|
-
* any due timer together.
|
|
48
|
+
* any due timer together; only {@link FakeClock.jumpWallClock} pulls `now()`
|
|
49
|
+
* off that axis.
|
|
39
50
|
*
|
|
40
51
|
* Server-free and DI-free — lives in `@hydranium/protocol/testing` so every
|
|
41
52
|
* head can bind it without pulling in a server package.
|
|
53
|
+
*
|
|
54
|
+
* The clock is a `SystemClock` with its time replaced, so its methods live on
|
|
55
|
+
* its prototype and a spread of it carries none of them. Replace one by
|
|
56
|
+
* assigning it onto the clock, or layer over the clock with `Object.create`.
|
|
42
57
|
*/
|
|
43
58
|
export function makeFakeClock(options: { now?: number } = {}): FakeClock {
|
|
44
|
-
|
|
45
|
-
|
|
59
|
+
return new VirtualClock(options.now ?? 0);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A `SystemClock` whose time, stopwatches and timers read one virtual axis, so
|
|
64
|
+
* the `measure` and `raceTimer` it inherits run on that axis too.
|
|
65
|
+
*/
|
|
66
|
+
class VirtualClock extends SystemClock implements FakeClock {
|
|
67
|
+
protected readonly timers: FakeTimer[] = [];
|
|
68
|
+
/** What {@link jumpWallClock} has added to `now()`. */
|
|
69
|
+
protected wallClockOffset = 0;
|
|
46
70
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
71
|
+
constructor(protected current: number) {
|
|
72
|
+
super();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
override now(): number {
|
|
76
|
+
return this.current + this.wallClockOffset;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
jumpWallClock(ms: number): void {
|
|
80
|
+
this.wallClockOffset += ms;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
override setTimer(callback: () => void, ms: number): Disposable {
|
|
84
|
+
const timer: FakeTimer = { at: this.current + ms, callback, disposed: false, fired: false };
|
|
85
|
+
this.timers.push(timer);
|
|
86
|
+
return Disposable.create(() => {
|
|
87
|
+
timer.disposed = true;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
override stopwatch(): Stopwatch {
|
|
92
|
+
const read = (): number => this.current;
|
|
93
|
+
const start = read();
|
|
94
|
+
let lastLap = start;
|
|
50
95
|
let stopped: number | undefined;
|
|
51
96
|
return {
|
|
52
97
|
get elapsedMs(): number {
|
|
53
|
-
return (stopped ??
|
|
98
|
+
return (stopped ?? read()) - start;
|
|
54
99
|
},
|
|
55
100
|
lap(): number {
|
|
56
|
-
const at = stopped ??
|
|
101
|
+
const at = stopped ?? read();
|
|
57
102
|
const split = at - lastLap;
|
|
58
103
|
lastLap = at;
|
|
59
104
|
return split;
|
|
60
105
|
},
|
|
61
106
|
stop(): number {
|
|
62
|
-
|
|
63
|
-
stopped = current;
|
|
64
|
-
}
|
|
107
|
+
stopped ??= read();
|
|
65
108
|
return stopped - start;
|
|
66
109
|
}
|
|
67
110
|
};
|
|
68
|
-
}
|
|
111
|
+
}
|
|
69
112
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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();
|
|
113
|
+
pendingTimers(): number {
|
|
114
|
+
return this.timers.filter(timer => !timer.disposed && !timer.fired).length;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
advance(ms: number): void {
|
|
118
|
+
const target = this.current + ms;
|
|
119
|
+
// Fire due timers one at a time, re-scanning after each so a callback
|
|
120
|
+
// that schedules a nearer timer still fires within this window.
|
|
121
|
+
for (;;) {
|
|
122
|
+
const next = this.timers
|
|
123
|
+
.filter(timer => !timer.disposed && !timer.fired && timer.at <= target)
|
|
124
|
+
.sort((left, right) => left.at - right.at)[0];
|
|
125
|
+
if (!next) {
|
|
126
|
+
break;
|
|
102
127
|
}
|
|
103
|
-
current =
|
|
128
|
+
this.current = next.at;
|
|
129
|
+
next.fired = true;
|
|
130
|
+
next.callback();
|
|
104
131
|
}
|
|
105
|
-
|
|
132
|
+
this.current = target;
|
|
133
|
+
}
|
|
106
134
|
}
|
package/src/testing/index.ts
CHANGED
|
@@ -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`),
|
|
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.
|
|
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
|
-
|
|
36
|
-
const
|
|
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
|
|
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
|
+
}
|
package/src/testing/wait-for.ts
CHANGED
|
@@ -33,13 +33,19 @@ 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
|
-
/**
|
|
37
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Error message on timeout, and when the predicate throws. A function is
|
|
38
|
+
* called only then, so it can report the state the wait ended on; when it
|
|
39
|
+
* throws, the default text is used, with its throw as the error's `cause`
|
|
40
|
+
* unless the predicate threw. Default a generic phrasing.
|
|
41
|
+
*/
|
|
42
|
+
readonly message?: string | (() => string);
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
/**
|
|
41
46
|
* Resolve once `predicate()` returns true, polling at `intervalMs`; reject with
|
|
42
|
-
* `message` once `timeoutMs` elapses
|
|
47
|
+
* `message` once `timeoutMs` elapses, or at once when the predicate throws, with
|
|
48
|
+
* the throw as the error's `cause`. The **non-racy** alternative to a fixed
|
|
43
49
|
* sleep for awaiting an asynchronous side effect that lands on an observable
|
|
44
50
|
* value.
|
|
45
51
|
*
|
|
@@ -56,20 +62,62 @@ export interface WaitForOptions {
|
|
|
56
62
|
export function waitFor(predicate: () => boolean, options: WaitForOptions = {}): Promise<void> {
|
|
57
63
|
const timeoutMs = options.timeoutMs ?? 2000;
|
|
58
64
|
const intervalMs = options.intervalMs ?? 5;
|
|
59
|
-
const
|
|
60
|
-
if (predicate()) {
|
|
61
|
-
return Promise.resolve();
|
|
62
|
-
}
|
|
65
|
+
const defaultMessage = `Timed out after ${timeoutMs}ms waiting for a condition`;
|
|
63
66
|
return new Promise<void>((resolve, reject) => {
|
|
64
|
-
|
|
67
|
+
// A throw from the predicate or the message function would leave the
|
|
68
|
+
// promise unsettled from the poll's or the deadline's timer, or escape
|
|
69
|
+
// `waitFor` itself on the first check; it rejects instead, with the
|
|
70
|
+
// predicate's throw, else the message function's, as cause. True once
|
|
71
|
+
// the promise is settled.
|
|
72
|
+
const settle = (timedOut: boolean): boolean => {
|
|
73
|
+
let met = false;
|
|
74
|
+
let threw = false;
|
|
75
|
+
let cause: unknown;
|
|
76
|
+
try {
|
|
77
|
+
met = predicate();
|
|
78
|
+
} catch (error: unknown) {
|
|
79
|
+
threw = true;
|
|
80
|
+
cause = error;
|
|
81
|
+
}
|
|
82
|
+
if (met) {
|
|
83
|
+
resolve();
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (!timedOut && !threw) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
let message = defaultMessage;
|
|
90
|
+
try {
|
|
91
|
+
if (typeof options.message === 'function') {
|
|
92
|
+
message = options.message();
|
|
93
|
+
} else if (options.message !== undefined) {
|
|
94
|
+
message = options.message;
|
|
95
|
+
}
|
|
96
|
+
} catch (error: unknown) {
|
|
97
|
+
if (!threw) {
|
|
98
|
+
threw = true;
|
|
99
|
+
cause = error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
reject(new Error(message, threw ? { cause } : undefined));
|
|
103
|
+
return true;
|
|
104
|
+
};
|
|
105
|
+
if (settle(false)) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const stop = (): void => {
|
|
65
109
|
clearInterval(poll);
|
|
66
|
-
|
|
110
|
+
clearTimeout(deadline);
|
|
111
|
+
};
|
|
112
|
+
// A stalled loop can run the deadline after the condition came true but
|
|
113
|
+
// before the next poll saw it, so the deadline checks once more.
|
|
114
|
+
const deadline = setTimeout(() => {
|
|
115
|
+
settle(true);
|
|
116
|
+
stop();
|
|
67
117
|
}, timeoutMs);
|
|
68
118
|
const poll = setInterval(() => {
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
clearTimeout(deadline);
|
|
72
|
-
resolve();
|
|
119
|
+
if (settle(false)) {
|
|
120
|
+
stop();
|
|
73
121
|
}
|
|
74
122
|
}, intervalMs);
|
|
75
123
|
});
|
package/src/tracer.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { Format, Logger, type LogThreshold } from './logger';
|
|
|
12
12
|
import { NoopLogger } from './noop-logger';
|
|
13
13
|
import { DefaultProfileSession, type ProfileSession } from './profile-session';
|
|
14
14
|
import { Disposable } from './util';
|
|
15
|
+
import { describeErrorWithStack } from './messages/primitives';
|
|
15
16
|
|
|
16
17
|
/** Module-global so nested timers don't reuse ids. */
|
|
17
18
|
let nextTimerId = 0;
|
|
@@ -181,15 +182,10 @@ export class DefaultTracer implements Tracer {
|
|
|
181
182
|
const suffix = this.timingSuffix(status, elapsed, options);
|
|
182
183
|
this.logger[logLevel](`${label} [#${id} ${status}, ${Format.elapsed(elapsed)}${currentExtras()}${suffix}]`);
|
|
183
184
|
if (status === 'failed') {
|
|
184
|
-
//
|
|
185
|
-
//
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
189
|
-
this.logger.warn(`${label} [#${id}] failed: ${detail}`);
|
|
190
|
-
if (error instanceof Error && error.stack) {
|
|
191
|
-
this.logger.debug(error.stack);
|
|
192
|
-
}
|
|
185
|
+
// Reporting the failure is the caller's, who receives it: a line at
|
|
186
|
+
// warn here would exist only while `logLevel` is enabled.
|
|
187
|
+
const detail = describeErrorWithStack(error);
|
|
188
|
+
this.logger.debug(`${label} [#${id}] failed: ${detail}`);
|
|
193
189
|
}
|
|
194
190
|
};
|
|
195
191
|
let result: T;
|