@hydranium/conformance 1.0.0-next.27 → 1.0.0-next.270
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 +79 -74
- package/lib/conformance-suite.js +1 -1
- package/lib/data/index.d.ts +35 -12
- package/lib/data/index.d.ts.map +1 -1
- package/lib/data/index.js +753 -32
- package/lib/data/index.js.map +1 -1
- package/lib/glsp/index.d.ts +24 -4
- package/lib/glsp/index.d.ts.map +1 -1
- package/lib/glsp/index.js +34 -2
- package/lib/glsp/index.js.map +1 -1
- package/lib/glsp/node/index.d.ts +64 -0
- package/lib/glsp/node/index.d.ts.map +1 -0
- package/lib/glsp/node/index.js +195 -0
- package/lib/glsp/node/index.js.map +1 -0
- package/lib/jest/index.js +3 -3
- package/lib/jest/index.js.map +1 -1
- package/lib/lsp/index.d.ts +23 -3
- package/lib/lsp/index.d.ts.map +1 -1
- package/lib/lsp/index.js +69 -3
- package/lib/lsp/index.js.map +1 -1
- package/lib/model.d.ts +131 -8
- package/lib/model.d.ts.map +1 -1
- package/lib/model.js.map +1 -1
- package/lib/vitest/index.js +3 -3
- package/lib/vitest/index.js.map +1 -1
- package/package.json +32 -45
- package/src/conformance-suite.ts +1 -1
- package/src/data/index.ts +965 -44
- package/src/glsp/index.ts +64 -6
- package/src/glsp/node/index.ts +274 -0
- package/src/jest/index.ts +3 -3
- package/src/lsp/index.ts +110 -7
- package/src/model.ts +134 -8
- package/src/vitest/index.ts +3 -3
package/src/glsp/index.ts
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
* head, generic over the adopter's action type `TAction`. The kit imports NO
|
|
13
13
|
* `@eclipse-glsp/*` types: the FIXTURE supplies the native actions
|
|
14
14
|
* (`requestModel()`, `createOperation.action()`) and the kit matches responses
|
|
15
|
-
* by `kind` (a `string`) via the driver's `nextAction`.
|
|
15
|
+
* by `kind` (a `string`) via the driver's `nextAction`. The one field it reads
|
|
16
|
+
* beyond `kind` is the `reason` of the `setDirtyState` that is an operation's
|
|
17
|
+
* receipt.
|
|
16
18
|
*
|
|
17
19
|
* The driver port (`GlspConformanceDriver<TAction>`) is the minimal
|
|
18
20
|
* `start` / `dispatch` / `nextAction` surface that `@hydranium/glsp-server/
|
|
@@ -26,6 +28,7 @@
|
|
|
26
28
|
|
|
27
29
|
import assert from 'node:assert/strict';
|
|
28
30
|
import type { Harness } from '@hydranium/protocol/testing';
|
|
31
|
+
import { describeError } from '@hydranium/protocol';
|
|
29
32
|
import type { ConformanceCheck } from '../conformance-suite.js';
|
|
30
33
|
|
|
31
34
|
/**
|
|
@@ -40,7 +43,12 @@ export interface GlspConformanceDriver<TAction> extends Harness {
|
|
|
40
43
|
start(): Promise<void>;
|
|
41
44
|
/** Send an action to the server. Fire-and-forget (GLSP `process` is `void`). */
|
|
42
45
|
dispatch(action: TAction): void;
|
|
43
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Resolve with the next action whose `kind` matches and that arrived after
|
|
48
|
+
* the last {@link dispatch}, or since `start` before any; reject on timeout.
|
|
49
|
+
* Only after the dispatch, so an action an earlier step sent cannot pass for
|
|
50
|
+
* the answer to this one.
|
|
51
|
+
*/
|
|
44
52
|
nextAction<T extends TAction = TAction>(kind: string, timeoutMs?: number): Promise<T>;
|
|
45
53
|
}
|
|
46
54
|
|
|
@@ -64,7 +72,18 @@ export interface GlspCreateOperationSpec<TAction, TDriver extends GlspConformanc
|
|
|
64
72
|
* loaded.
|
|
65
73
|
*/
|
|
66
74
|
readonly action: (driver: TDriver) => TAction;
|
|
67
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* The action kind the server settles the operation with (e.g. a
|
|
77
|
+
* re-`RequestBounds` for client-laid-out diagrams).
|
|
78
|
+
*
|
|
79
|
+
* The kit also waits for the operation's receipt: GLSP's
|
|
80
|
+
* `OperationActionHandler` submits every operation that ran with reason
|
|
81
|
+
* `'operation'`, and `ModelSubmissionHandler` ends that submission with a
|
|
82
|
+
* `setDirtyState` carrying it. A declined operation sends none,
|
|
83
|
+
* so an action of this kind from something else, such as a late submission
|
|
84
|
+
* of the load, cannot pass for the operation's. The driver's session must
|
|
85
|
+
* receive `setDirtyState`.
|
|
86
|
+
*/
|
|
68
87
|
readonly expectedResponseKind: string;
|
|
69
88
|
/**
|
|
70
89
|
* Returns whether the source model gained the element — the adopter reads its
|
|
@@ -80,8 +99,12 @@ export interface GlspCreateOperationSpec<TAction, TDriver extends GlspConformanc
|
|
|
80
99
|
* fixture to its input document, so a fixture whose input was MUTATED by an
|
|
81
100
|
* earlier check silently expects the wrong number. Give each check pristine
|
|
82
101
|
* input, or take the delta route above.
|
|
102
|
+
*
|
|
103
|
+
* May answer asynchronously. It runs once the response kind has arrived, and
|
|
104
|
+
* a write observed from another process, a `workspace/applyEdit` say, can
|
|
105
|
+
* arrive after that.
|
|
83
106
|
*/
|
|
84
|
-
readonly expectMutated: (driver: TDriver) => boolean
|
|
107
|
+
readonly expectMutated: (driver: TDriver) => boolean | Promise<boolean>;
|
|
85
108
|
}
|
|
86
109
|
|
|
87
110
|
/**
|
|
@@ -132,10 +155,44 @@ export interface GlspConformanceOptions<TAction, TDriver extends GlspConformance
|
|
|
132
155
|
readonly connect: () => TDriver | Promise<TDriver>;
|
|
133
156
|
/** Per-diagram-type fixtures. */
|
|
134
157
|
readonly diagrams: ReadonlyArray<GlspFixture<TAction, TDriver>>;
|
|
135
|
-
/** Suite title override. Default `'conformance
|
|
158
|
+
/** Suite title override. Default `'glsp conformance'`. */
|
|
136
159
|
readonly suiteTitle?: string;
|
|
137
160
|
}
|
|
138
161
|
|
|
162
|
+
/** GLSP's `SetDirtyStateAction.KIND`, named here because the kit imports no GLSP type. */
|
|
163
|
+
const SET_DIRTY_STATE_KIND = 'setDirtyState';
|
|
164
|
+
|
|
165
|
+
/** The reason GLSP's `OperationActionHandler` submits an operation that ran with, which its dirty state carries. */
|
|
166
|
+
const OPERATION_REASON = 'operation';
|
|
167
|
+
|
|
168
|
+
function isOperationReceipt(action: unknown): boolean {
|
|
169
|
+
return typeof action === 'object' && action !== null && 'reason' in action && action.reason === OPERATION_REASON;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Resolve once the operation's receipt arrives, passing over a dirty state
|
|
174
|
+
* with any other reason. Rejects with the wait's own failure, which may be a
|
|
175
|
+
* closed connection rather than a missing receipt.
|
|
176
|
+
*/
|
|
177
|
+
async function nextOperationReceipt<TAction>(driver: GlspConformanceDriver<TAction>): Promise<void> {
|
|
178
|
+
for (;;) {
|
|
179
|
+
let dirtyState: TAction;
|
|
180
|
+
try {
|
|
181
|
+
dirtyState = await driver.nextAction(SET_DIRTY_STATE_KIND);
|
|
182
|
+
} catch (error: unknown) {
|
|
183
|
+
const reason = describeError(error);
|
|
184
|
+
throw new Error(
|
|
185
|
+
`Waiting for the operation's receipt, a ${SET_DIRTY_STATE_KIND} with reason '${OPERATION_REASON}', failed: ${reason}. ` +
|
|
186
|
+
`If none arrived in time, either no operation ran or the session does not declare ${SET_DIRTY_STATE_KIND}.`,
|
|
187
|
+
{ cause: error }
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
if (isOperationReceipt(dirtyState)) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
139
196
|
/**
|
|
140
197
|
* Build the GLSP check battery — per diagram type: `start()` resolves;
|
|
141
198
|
* `RequestModel` responds with the expected kind (+ optional `expectResponse`
|
|
@@ -195,9 +252,10 @@ export function buildGlspChecks<TAction, TDriver extends GlspConformanceDriver<T
|
|
|
195
252
|
driver.dispatch(diagram.requestModel());
|
|
196
253
|
await driver.nextAction(diagram.expectedResponseKind);
|
|
197
254
|
driver.dispatch(operation.action(driver));
|
|
255
|
+
await nextOperationReceipt(driver);
|
|
198
256
|
await driver.nextAction(operation.expectedResponseKind);
|
|
199
257
|
assert.ok(
|
|
200
|
-
operation.expectMutated(driver),
|
|
258
|
+
await operation.expectMutated(driver),
|
|
201
259
|
'expectMutated was false — the create operation did not mutate the source model'
|
|
202
260
|
);
|
|
203
261
|
} finally {
|
|
@@ -0,0 +1,274 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* The `@hydranium/conformance/glsp/node` subpath: a socket driver for the
|
|
12
|
+
* {@link GlspConformanceDriver} port, over a real TCP socket, for proving a
|
|
13
|
+
* deployed GLSP server rather than a container built in the test process.
|
|
14
|
+
*
|
|
15
|
+
* It speaks GLSP's JSON-RPC by method name, so like the rest of the kit it names
|
|
16
|
+
* no `@eclipse-glsp/*` type and the adopter's fixtures supply every action.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { randomUUID } from 'node:crypto';
|
|
20
|
+
import * as net from 'node:net';
|
|
21
|
+
import { createMessageConnection, SocketMessageReader, SocketMessageWriter, type MessageConnection } from 'vscode-jsonrpc/node';
|
|
22
|
+
import type { GlspConformanceDriver } from '../index.js';
|
|
23
|
+
|
|
24
|
+
const DEFAULT_PROTOCOL_VERSION = '1.0.0';
|
|
25
|
+
|
|
26
|
+
const DEFAULT_TIMEOUT_MS = 15_000;
|
|
27
|
+
|
|
28
|
+
/** Configuration for {@link connectGlspSocketDriver}. */
|
|
29
|
+
export interface GlspSocketDriverOptions<TAction extends { readonly kind: string } = { readonly kind: string }> {
|
|
30
|
+
readonly port: number;
|
|
31
|
+
/** Defaults to `127.0.0.1`. */
|
|
32
|
+
readonly host?: string;
|
|
33
|
+
/** The diagram type the client session is opened for. */
|
|
34
|
+
readonly diagramType: string;
|
|
35
|
+
/**
|
|
36
|
+
* The action kinds this client handles, which the server routes back to it.
|
|
37
|
+
* Declare every kind the server sends during the checks: one it sends that
|
|
38
|
+
* neither side handles fails the server's dispatch, and the session gets a
|
|
39
|
+
* rejected request or an error message instead.
|
|
40
|
+
*/
|
|
41
|
+
readonly clientActionKinds: readonly string[];
|
|
42
|
+
/** Defaults to a fresh id per driver, so drivers sharing one server never share a session. */
|
|
43
|
+
readonly clientSessionId?: string;
|
|
44
|
+
readonly applicationId?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The GLSP protocol version announced in `initialize`. The server refuses
|
|
47
|
+
* `initialize` unless it equals its own, so a server on a newer protocol
|
|
48
|
+
* needs this. Defaults to `1.0.0`.
|
|
49
|
+
*/
|
|
50
|
+
readonly protocolVersion?: string;
|
|
51
|
+
/**
|
|
52
|
+
* The client's reply to a received action, sent back to the server, or
|
|
53
|
+
* `undefined` for none. A server that lays out on the client finishes a
|
|
54
|
+
* `requestModel` only once its `requestBounds` is answered with
|
|
55
|
+
* `computedBounds`, so a load without this stops half way. A reply is not a
|
|
56
|
+
* dispatch, as the GLSP client's own is an automatic answer to the server,
|
|
57
|
+
* so it leaves the point `nextAction` matches from where it was. A throw
|
|
58
|
+
* fails every pending and later wait with it.
|
|
59
|
+
*/
|
|
60
|
+
readonly respond?: (action: TAction) => TAction | undefined;
|
|
61
|
+
/** Default bound for {@link GlspConformanceDriver.nextAction}, and the bound on the TCP connect and on each `start()` request. */
|
|
62
|
+
readonly timeoutMs?: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** A {@link GlspConformanceDriver} over a socket, with the actions it received. */
|
|
66
|
+
export interface GlspSocketDriver<TAction extends { readonly kind: string }> extends GlspConformanceDriver<TAction> {
|
|
67
|
+
/** Every action the server sent to this session, in arrival order; append-only. */
|
|
68
|
+
readonly actions: ReadonlyArray<TAction>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** GLSP's `process` notification payload, in either direction. */
|
|
72
|
+
interface ActionMessage<TAction> {
|
|
73
|
+
readonly clientId: string;
|
|
74
|
+
readonly action: TAction;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isActionMessage(value: unknown): value is ActionMessage<{ readonly kind: string }> {
|
|
78
|
+
if (typeof value !== 'object' || value === null || !('clientId' in value) || !('action' in value)) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
const { action } = value;
|
|
82
|
+
return typeof action === 'object' && action !== null && 'kind' in action && typeof action.kind === 'string';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Open a TCP connection to a GLSP server and wrap it as a driver. The session is
|
|
87
|
+
* not initialised until the kit calls `start()`.
|
|
88
|
+
*/
|
|
89
|
+
export async function connectGlspSocketDriver<TAction extends { readonly kind: string }>(
|
|
90
|
+
options: GlspSocketDriverOptions<TAction>
|
|
91
|
+
): Promise<GlspSocketDriver<TAction>> {
|
|
92
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
93
|
+
const clientSessionId = options.clientSessionId ?? `glsp-socket-${randomUUID()}`;
|
|
94
|
+
const socket = await openSocket(options.host ?? '127.0.0.1', options.port, timeoutMs);
|
|
95
|
+
const connection: MessageConnection = createMessageConnection(new SocketMessageReader(socket), new SocketMessageWriter(socket), console);
|
|
96
|
+
|
|
97
|
+
const actions: TAction[] = [];
|
|
98
|
+
const send = (action: TAction): void => {
|
|
99
|
+
// Fire-and-forget, so neither a closed connection, which throws here, nor
|
|
100
|
+
// a failed write reaches the caller; the wait that follows reports it.
|
|
101
|
+
try {
|
|
102
|
+
connection.sendNotification('process', { clientId: clientSessionId, action }).catch(() => undefined);
|
|
103
|
+
} catch {
|
|
104
|
+
// Already reported by the closed state every later wait reads.
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const consumed = new WeakSet<TAction>();
|
|
108
|
+
// Where the last dispatch fell in `actions`; a wait matches only from here.
|
|
109
|
+
let dispatchedAt = 0;
|
|
110
|
+
const waiters: Array<{ readonly kind: string; readonly resolve: (action: TAction) => void; readonly fail: (error: Error) => void }> = [];
|
|
111
|
+
// Why no awaited action can arrive any more, once something ended the session.
|
|
112
|
+
let ended: { readonly reason: string; readonly cause?: unknown } | undefined;
|
|
113
|
+
|
|
114
|
+
// A wait still pending when the session ends fails at once, naming why,
|
|
115
|
+
// rather than at its timeout reading like a declined operation.
|
|
116
|
+
function end(reason: string, cause?: unknown): void {
|
|
117
|
+
ended ??= { reason, cause };
|
|
118
|
+
for (const waiter of waiters.splice(0)) {
|
|
119
|
+
waiter.fail(new Error(`${ended.reason} while waiting for '${waiter.kind}'`, { cause: ended.cause }));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const closedReason = `GLSP connection to session ${clientSessionId} closed`;
|
|
123
|
+
connection.onClose(() => end(closedReason));
|
|
124
|
+
|
|
125
|
+
connection.onNotification('process', (message: unknown) => {
|
|
126
|
+
if (!isActionMessage(message) || message.clientId !== clientSessionId) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
// The fixture's own action type; the guard has checked the one field read here.
|
|
130
|
+
const action = message.action as TAction;
|
|
131
|
+
actions.push(action);
|
|
132
|
+
const index = waiters.findIndex(waiter => waiter.kind === action.kind);
|
|
133
|
+
if (index >= 0) {
|
|
134
|
+
const [waiter] = waiters.splice(index, 1);
|
|
135
|
+
consumed.add(action);
|
|
136
|
+
waiter.resolve(action);
|
|
137
|
+
}
|
|
138
|
+
// The connection only logs a handler's throw, so a fixture bug would
|
|
139
|
+
// otherwise surface as an unrelated wait timing out.
|
|
140
|
+
let reply: TAction | undefined;
|
|
141
|
+
try {
|
|
142
|
+
reply = options.respond?.(action);
|
|
143
|
+
} catch (error: unknown) {
|
|
144
|
+
end(`respond threw on '${action.kind}' (${String(error)})`, error);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (reply) {
|
|
148
|
+
send(reply);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
connection.listen();
|
|
152
|
+
|
|
153
|
+
let disposed = false;
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
actions,
|
|
157
|
+
|
|
158
|
+
async start(): Promise<void> {
|
|
159
|
+
// Bounded, so a server that accepts the socket and never answers fails
|
|
160
|
+
// naming the request, when the runner's own timeout is the longer one.
|
|
161
|
+
await within(
|
|
162
|
+
connection.sendRequest('initialize', {
|
|
163
|
+
applicationId: options.applicationId ?? 'hydranium-conformance',
|
|
164
|
+
protocolVersion: options.protocolVersion ?? DEFAULT_PROTOCOL_VERSION
|
|
165
|
+
}),
|
|
166
|
+
timeoutMs,
|
|
167
|
+
'initialize'
|
|
168
|
+
);
|
|
169
|
+
await within(
|
|
170
|
+
connection.sendRequest('initializeClientSession', {
|
|
171
|
+
clientSessionId,
|
|
172
|
+
diagramType: options.diagramType,
|
|
173
|
+
clientActionKinds: options.clientActionKinds
|
|
174
|
+
}),
|
|
175
|
+
timeoutMs,
|
|
176
|
+
'initializeClientSession'
|
|
177
|
+
);
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
dispatch(action: TAction): void {
|
|
181
|
+
dispatchedAt = actions.length;
|
|
182
|
+
send(action);
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
nextAction<T extends TAction = TAction>(kind: string, waitMs = timeoutMs): Promise<T> {
|
|
186
|
+
const existing = actions.find((action, index) => index >= dispatchedAt && action.kind === kind && !consumed.has(action));
|
|
187
|
+
if (existing) {
|
|
188
|
+
consumed.add(existing);
|
|
189
|
+
return Promise.resolve(existing as T);
|
|
190
|
+
}
|
|
191
|
+
if (ended) {
|
|
192
|
+
return Promise.reject(new Error(`${ended.reason}; no '${kind}' action can arrive`, { cause: ended.cause }));
|
|
193
|
+
}
|
|
194
|
+
return new Promise<T>((resolve, reject) => {
|
|
195
|
+
const waiter = {
|
|
196
|
+
kind,
|
|
197
|
+
resolve: (action: TAction): void => {
|
|
198
|
+
clearTimeout(timer);
|
|
199
|
+
resolve(action as T);
|
|
200
|
+
},
|
|
201
|
+
fail: (error: Error): void => {
|
|
202
|
+
clearTimeout(timer);
|
|
203
|
+
reject(error);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
const timer = setTimeout(() => {
|
|
207
|
+
const at = waiters.indexOf(waiter);
|
|
208
|
+
if (at >= 0) {
|
|
209
|
+
waiters.splice(at, 1);
|
|
210
|
+
}
|
|
211
|
+
// Naming what did arrive tells an operation the server declined
|
|
212
|
+
// (a status or nothing at all) apart from a transport that hangs,
|
|
213
|
+
// split at the last dispatch, before which no match counts.
|
|
214
|
+
const kindsIn = (from: number, to?: number): string =>
|
|
215
|
+
actions
|
|
216
|
+
.slice(from, to)
|
|
217
|
+
.map(action => action.kind)
|
|
218
|
+
.join(', ') || 'nothing';
|
|
219
|
+
const seen =
|
|
220
|
+
dispatchedAt === 0
|
|
221
|
+
? `received: ${kindsIn(0)}`
|
|
222
|
+
: `received before the last dispatch, which a wait does not match: ${kindsIn(0, dispatchedAt)}; since: ${kindsIn(dispatchedAt)}`;
|
|
223
|
+
reject(new Error(`No '${kind}' action within ${waitMs}ms on session ${clientSessionId}; ${seen}`));
|
|
224
|
+
}, waitMs);
|
|
225
|
+
waiters.push(waiter);
|
|
226
|
+
});
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
dispose(): void {
|
|
230
|
+
if (disposed) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
disposed = true;
|
|
234
|
+
// A disposed connection fires no close event, so the waits end here.
|
|
235
|
+
end(closedReason);
|
|
236
|
+
connection.dispose();
|
|
237
|
+
socket.destroy();
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function within<T>(request: Promise<T>, timeoutMs: number, method: string): Promise<T> {
|
|
243
|
+
return new Promise<T>((resolve, reject) => {
|
|
244
|
+
const timer = setTimeout(() => reject(new Error(`GLSP server did not answer '${method}' within ${timeoutMs}ms`)), timeoutMs);
|
|
245
|
+
request.then(
|
|
246
|
+
value => {
|
|
247
|
+
clearTimeout(timer);
|
|
248
|
+
resolve(value);
|
|
249
|
+
},
|
|
250
|
+
(error: unknown) => {
|
|
251
|
+
clearTimeout(timer);
|
|
252
|
+
reject(error);
|
|
253
|
+
}
|
|
254
|
+
);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function openSocket(host: string, port: number, timeoutMs: number): Promise<net.Socket> {
|
|
259
|
+
return new Promise<net.Socket>((resolve, reject) => {
|
|
260
|
+
const socket = net.createConnection({ host, port });
|
|
261
|
+
const timer = setTimeout(() => {
|
|
262
|
+
socket.destroy();
|
|
263
|
+
reject(new Error(`TCP connect to GLSP server at ${host}:${port} timed out after ${timeoutMs}ms`));
|
|
264
|
+
}, timeoutMs);
|
|
265
|
+
socket.once('connect', () => {
|
|
266
|
+
clearTimeout(timer);
|
|
267
|
+
resolve(socket);
|
|
268
|
+
});
|
|
269
|
+
socket.once('error', error => {
|
|
270
|
+
clearTimeout(timer);
|
|
271
|
+
reject(error);
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
}
|
package/src/jest/index.ts
CHANGED
|
@@ -57,7 +57,7 @@ const jestRunner: ConformanceRunner = {
|
|
|
57
57
|
export function runDataConformance<TTransfer extends TransferElement, TDiagnostic extends TransferDiagnostic = TransferDiagnostic>(
|
|
58
58
|
options: DataConformanceOptions<TTransfer, TDiagnostic>
|
|
59
59
|
): void {
|
|
60
|
-
emitConformanceSuite(jestRunner, options.suiteTitle ?? '
|
|
60
|
+
emitConformanceSuite(jestRunner, options.suiteTitle ?? 'data-server conformance', buildDataChecks(options));
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
@@ -66,7 +66,7 @@ export function runDataConformance<TTransfer extends TransferElement, TDiagnosti
|
|
|
66
66
|
* per language) and a ran-vs-skipped summary.
|
|
67
67
|
*/
|
|
68
68
|
export function runLspConformance(options: LspConformanceOptions): void {
|
|
69
|
-
emitConformanceSuite(jestRunner, options.suiteTitle ?? 'conformance
|
|
69
|
+
emitConformanceSuite(jestRunner, options.suiteTitle ?? 'lsp conformance', buildLspChecks(options));
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
@@ -77,5 +77,5 @@ export function runLspConformance(options: LspConformanceOptions): void {
|
|
|
77
77
|
export function runGlspConformance<TAction, TDriver extends GlspConformanceDriver<TAction>>(
|
|
78
78
|
options: GlspConformanceOptions<TAction, TDriver>
|
|
79
79
|
): void {
|
|
80
|
-
emitConformanceSuite(jestRunner, options.suiteTitle ?? 'conformance
|
|
80
|
+
emitConformanceSuite(jestRunner, options.suiteTitle ?? 'glsp conformance', buildGlspChecks(options));
|
|
81
81
|
}
|
package/src/lsp/index.ts
CHANGED
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
* The `@hydranium/conformance/lsp` slice — protocol conformance for the LSP
|
|
12
12
|
* head. The driver port is a STRUCTURAL minimum (`LspConformanceDriver`) that
|
|
13
13
|
* `@hydranium/core/testing/node`'s `LspHarness` satisfies with NO adapter: the kit
|
|
14
|
-
* names only
|
|
14
|
+
* names only strings, plain coordinates, and tiny structural minima
|
|
15
15
|
* (`{ message }`, `{ items }`, `{ capabilities }`), never
|
|
16
16
|
* `vscode-languageserver-protocol` wire types, so the harness's richer return
|
|
17
|
-
* types are assignable to the narrower port.
|
|
17
|
+
* types are assignable to the narrower port. An alias of `string` is still a
|
|
18
|
+
* string for that purpose and stays inside the rule; a wire type does not.
|
|
18
19
|
*
|
|
19
20
|
* **This slice does not read `LanguageFixture.edit` at all.** The didChange
|
|
20
21
|
* check drives `valid → invalid` using `invalid.text`, so there is no
|
|
@@ -23,9 +24,21 @@
|
|
|
23
24
|
*/
|
|
24
25
|
|
|
25
26
|
import assert from 'node:assert/strict';
|
|
27
|
+
import type { Locale } from '@hydranium/protocol';
|
|
26
28
|
import type { Harness } from '@hydranium/protocol/testing';
|
|
27
29
|
import type { ConformanceCheck } from '../conformance-suite.js';
|
|
28
|
-
import { type LanguageFixture, resolveDeferred, resolveModel } from '../model.js';
|
|
30
|
+
import { type ConformanceModel, type LanguageFixture, resolveDeferred, resolveModel } from '../model.js';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Structural minimum of the `initialize` params the kit sends — only `locale`,
|
|
34
|
+
* which is the one field a check needs to vary.
|
|
35
|
+
*
|
|
36
|
+
* A real `InitializeParams` is assignable to this, so a driver typed against
|
|
37
|
+
* upstream's shape satisfies the port with no adapter.
|
|
38
|
+
*/
|
|
39
|
+
export interface LspConformanceInitializeParams {
|
|
40
|
+
readonly locale?: Locale;
|
|
41
|
+
}
|
|
29
42
|
|
|
30
43
|
/** Structural minimum of an LSP `InitializeResult` — only the baseline capabilities the kit asserts. */
|
|
31
44
|
export interface LspConformanceInitializeResult {
|
|
@@ -76,8 +89,17 @@ function hasTextMessage(diagnostic: LspConformanceDiagnostic): boolean {
|
|
|
76
89
|
* gives the kit the universal `dispose()` teardown.
|
|
77
90
|
*/
|
|
78
91
|
export interface LspConformanceDriver extends Harness {
|
|
79
|
-
/**
|
|
80
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Drive the `initialize` → `initialized` handshake; resolve with the
|
|
94
|
+
* (structurally-minimal) result.
|
|
95
|
+
*
|
|
96
|
+
* `params` is optional and every field in it is too, so a driver that ignores
|
|
97
|
+
* the argument entirely still satisfies this port — which is what keeps
|
|
98
|
+
* adding a field here from being a breaking change. `locale` is the reading
|
|
99
|
+
* user's language, declared by the client because only the client knows it;
|
|
100
|
+
* the render check below is the only caller that passes anything.
|
|
101
|
+
*/
|
|
102
|
+
initialize(params?: LspConformanceInitializeParams): Promise<LspConformanceInitializeResult>;
|
|
81
103
|
/** Send `didOpen` for `uri` with full `text` under `languageId`. */
|
|
82
104
|
openDocument(uri: string, text: string, languageId: string, version?: number): void;
|
|
83
105
|
/** Send `didChange` for `uri` as a single full-text replacement at `version`. */
|
|
@@ -101,7 +123,7 @@ export interface LspConformanceOptions {
|
|
|
101
123
|
readonly connect: () => LspConformanceDriver | Promise<LspConformanceDriver>;
|
|
102
124
|
/** Per-language fixtures; the grammar-bearing checks run once per language. */
|
|
103
125
|
readonly languages: ReadonlyArray<LanguageFixture>;
|
|
104
|
-
/** Suite title override. Default `'conformance
|
|
126
|
+
/** Suite title override. Default `'lsp conformance'`. */
|
|
105
127
|
readonly suiteTitle?: string;
|
|
106
128
|
}
|
|
107
129
|
|
|
@@ -177,7 +199,7 @@ export function buildLspChecks(options: LspConformanceOptions): ConformanceCheck
|
|
|
177
199
|
});
|
|
178
200
|
|
|
179
201
|
for (const language of options.languages) {
|
|
180
|
-
const { valid, invalid, completionPosition } = language;
|
|
202
|
+
const { valid, invalid, completionPosition, renderedDiagnostic } = language;
|
|
181
203
|
const tag = `[${valid.languageId}]`;
|
|
182
204
|
|
|
183
205
|
checks.push({
|
|
@@ -273,7 +295,88 @@ export function buildLspChecks(options: LspConformanceOptions): ConformanceCheck
|
|
|
273
295
|
skipReason: 'fixture supplied no completionPosition'
|
|
274
296
|
});
|
|
275
297
|
}
|
|
298
|
+
|
|
299
|
+
// Opt-in: server-side rendering runs only when the fixture names a locale
|
|
300
|
+
// and the sentence it expects in it. The framework ships no catalogue, so
|
|
301
|
+
// a server that renders nothing is CORRECT and must not be failed.
|
|
302
|
+
const renderTitle = `a diagnostic is published rendered in the locale initialize declared ${tag}`;
|
|
303
|
+
const renderControlTitle = `the same diagnostic is NOT rendered when no locale is declared ${tag}`;
|
|
304
|
+
if (renderedDiagnostic) {
|
|
305
|
+
checks.push({
|
|
306
|
+
title: renderTitle,
|
|
307
|
+
body: async () => {
|
|
308
|
+
const published = await publishedMessagesFor(connect, invalid, { locale: renderedDiagnostic.locale });
|
|
309
|
+
assert.ok(
|
|
310
|
+
published.some(message => message.includes(renderedDiagnostic.expected)),
|
|
311
|
+
`no published diagnostic contained ${JSON.stringify(renderedDiagnostic.expected)}: ${JSON.stringify(published)}`
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// The second half of the pair. "Contains X" also passes for a server
|
|
317
|
+
// whose English contains X, and for one that renders whatever the
|
|
318
|
+
// locale — so the discriminating read is the fragment that must
|
|
319
|
+
// disappear. Reported as skipped rather than silently dropped when the
|
|
320
|
+
// fixture omits it, because a lone containment check IS weaker and a
|
|
321
|
+
// reader has to be able to see that from the report.
|
|
322
|
+
if (renderedDiagnostic.absentWithLocale) {
|
|
323
|
+
const { absentWithLocale } = renderedDiagnostic;
|
|
324
|
+
checks.push({
|
|
325
|
+
title: renderControlTitle,
|
|
326
|
+
body: async () => {
|
|
327
|
+
const withLocale = await publishedMessagesFor(connect, invalid, { locale: renderedDiagnostic.locale });
|
|
328
|
+
assert.ok(
|
|
329
|
+
!withLocale.some(message => message.includes(absentWithLocale)),
|
|
330
|
+
`a diagnostic still contained ${JSON.stringify(absentWithLocale)} with the locale declared: ${JSON.stringify(withLocale)}`
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
// And present without it, which is what rules out a fragment
|
|
334
|
+
// that never appears in either state — a typo in the fixture
|
|
335
|
+
// would otherwise make the assertion above pass for free.
|
|
336
|
+
const withoutLocale = await publishedMessagesFor(connect, invalid);
|
|
337
|
+
assert.ok(
|
|
338
|
+
withoutLocale.some(message => message.includes(absentWithLocale)),
|
|
339
|
+
`no diagnostic contained ${JSON.stringify(absentWithLocale)} with no locale declared, so it cannot witness the render: ${JSON.stringify(withoutLocale)}`
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
} else {
|
|
344
|
+
checks.push({
|
|
345
|
+
title: renderControlTitle,
|
|
346
|
+
skipReason: 'fixture supplied no absentWithLocale, so the render check is a containment test only'
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
checks.push({ title: renderTitle, skipReason: 'fixture supplied no renderedDiagnostic (server-side rendering is opt-in)' });
|
|
351
|
+
checks.push({ title: renderControlTitle, skipReason: 'fixture supplied no renderedDiagnostic (server-side rendering is opt-in)' });
|
|
352
|
+
}
|
|
276
353
|
}
|
|
277
354
|
|
|
278
355
|
return checks;
|
|
279
356
|
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Open `model` on a fresh driver and return the messages of the diagnostics
|
|
360
|
+
* published for it, as plain strings.
|
|
361
|
+
*
|
|
362
|
+
* A fresh driver per call because `initialize` is once-only per connection and
|
|
363
|
+
* the locale rides it — so the two states this compares cannot share one.
|
|
364
|
+
*/
|
|
365
|
+
async function publishedMessagesFor(
|
|
366
|
+
connect: LspConformanceOptions['connect'],
|
|
367
|
+
model: ConformanceModel,
|
|
368
|
+
params?: LspConformanceInitializeParams
|
|
369
|
+
): Promise<string[]> {
|
|
370
|
+
const driver = await connect();
|
|
371
|
+
try {
|
|
372
|
+
await driver.initialize(params);
|
|
373
|
+
const resolved = resolveModel(model);
|
|
374
|
+
const diagnostics = driver.nextDiagnostics(resolved.uri);
|
|
375
|
+
driver.openDocument(resolved.uri, resolved.text, resolved.languageId);
|
|
376
|
+
return (await diagnostics).map(diagnostic =>
|
|
377
|
+
typeof diagnostic.message === 'string' ? diagnostic.message : (diagnostic.message?.value ?? '')
|
|
378
|
+
);
|
|
379
|
+
} finally {
|
|
380
|
+
driver.dispose();
|
|
381
|
+
}
|
|
382
|
+
}
|