@aloma.io/integration-sdk 3.8.70 → 3.8.71
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 +15 -2
- package/build/internal/connector/server/on-connect/make-oauth.mjs +27 -6
- package/build/internal/fetcher/fetcher.d.mts +14 -1
- package/build/internal/fetcher/fetcher.mjs +52 -11
- package/build/internal/fetcher/oauth-fetcher.d.mts +15 -2
- package/build/internal/fetcher/oauth-fetcher.mjs +72 -27
- package/build/internal/util/index.d.mts +8 -0
- package/build/internal/util/index.mjs +13 -1
- package/build/internal/util/jwe/index.mjs +3 -1
- package/package.json +8 -3
- package/.prettierrc.cjs +0 -8
- package/FINDINGS-PLAT-47.md +0 -253
- package/MULTI_RESOURCE_GUIDE.md +0 -220
- package/OPENAPI_TO_CONNECTOR.md +0 -349
- package/examples/hello-world/package.json +0 -25
- package/examples/hello-world/src/controller/index.mts +0 -12
- package/examples/hello-world/src/index.mts +0 -6
- package/examples/hello-world/tsconfig.json +0 -27
- package/examples/sample-api.json +0 -325
- package/examples/sample-api.yaml +0 -222
- package/examples/simple-api.json +0 -39
- package/index.js +0 -4
- package/src/builder/index.mts +0 -274
- package/src/builder/runtime-context.mts +0 -129
- package/src/cli.mts +0 -533
- package/src/controller/index.mts +0 -278
- package/src/index.mts +0 -2
- package/src/internal/connector/config.mts +0 -59
- package/src/internal/connector/index.mts +0 -53
- package/src/internal/connector/metrics.mts +0 -34
- package/src/internal/connector/server/index.mts +0 -51
- package/src/internal/connector/server/on-connect/decrypt-config.mts +0 -27
- package/src/internal/connector/server/on-connect/finish-oauth.mts +0 -109
- package/src/internal/connector/server/on-connect/index.mts +0 -162
- package/src/internal/connector/server/on-connect/make-oauth.mts +0 -97
- package/src/internal/connector/server/on-connect/start-oauth.mts +0 -24
- package/src/internal/connector/server/on-message.mts +0 -13
- package/src/internal/dispatcher/index.mts +0 -231
- package/src/internal/fetcher/fetcher.mts +0 -215
- package/src/internal/fetcher/oauth-fetcher.mts +0 -153
- package/src/internal/index.mts +0 -3
- package/src/internal/util/index.mts +0 -52
- package/src/internal/util/jwe/cli.mts +0 -12
- package/src/internal/util/jwe/index.mts +0 -72
- package/src/internal/websocket/config.mjs +0 -109
- package/src/internal/websocket/connection/constants.mjs +0 -25
- package/src/internal/websocket/connection/index.mjs +0 -71
- package/src/internal/websocket/connection/registration.mjs +0 -42
- package/src/internal/websocket/index.mjs +0 -46
- package/src/internal/websocket/transport/durable.mjs +0 -71
- package/src/internal/websocket/transport/index.mjs +0 -194
- package/src/internal/websocket/transport/packet.mjs +0 -54
- package/src/internal/websocket/transport/processor.mjs +0 -66
- package/src/openapi-to-connector.mts +0 -1648
- package/src/testing/fake-aloma.mts +0 -306
- package/src/testing/harness.mts +0 -172
- package/src/testing/index.mts +0 -15
- package/src/testing/keys.mts +0 -19
- package/src/testing/network-guard.mts +0 -57
- package/src/testing/runtime-connector.mts +0 -50
- package/src/testing/vendor-mock.mts +0 -166
- package/src/transform/index.mts +0 -544
- package/test/MUTATION-entry.md +0 -21
- package/test/MUTATION.md +0 -43
- package/test/dispatcher-ctx-forwarding.test.mjs +0 -161
- package/test/fetcher-query-params.test.mjs +0 -294
- package/test/fixtures/transform/basic/expected.json +0 -9
- package/test/fixtures/transform/basic/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/basic/src/controller/index.mts +0 -30
- package/test/fixtures/transform/basic/tsconfig.json +0 -1
- package/test/fixtures/transform/interface-param/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/interface-param/src/controller/index.mts +0 -12
- package/test/fixtures/transform/interface-param/tsconfig.json +0 -1
- package/test/fixtures/transform/overloads/expected.json +0 -6
- package/test/fixtures/transform/overloads/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/overloads/src/controller/index.mts +0 -11
- package/test/fixtures/transform/overloads/tsconfig.json +0 -1
- package/test/fixtures/transform/tdd-stub/expected.json +0 -8
- package/test/fixtures/transform/tdd-stub/src/controller/abstract.mts +0 -6
- package/test/fixtures/transform/tdd-stub/src/controller/index.mts +0 -204
- package/test/fixtures/transform/tdd-stub/tsconfig.json +0 -1
- package/test/fixtures/transform/two-exports/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/two-exports/src/controller/index.mts +0 -9
- package/test/fixtures/transform/two-exports/tsconfig.json +0 -1
- package/test/fixtures/transform/type-error/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/type-error/src/controller/index.mts +0 -7
- package/test/fixtures/transform/type-error/tsconfig.json +0 -1
- package/test/fixtures/transform/typed/expected.json +0 -8
- package/test/fixtures/transform/typed/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/typed/src/controller/index.mts +0 -13
- package/test/fixtures/transform/typed/tsconfig.json +0 -1
- package/test/fixtures/transform/visibility/expected.json +0 -9
- package/test/fixtures/transform/visibility/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/visibility/src/controller/index.mts +0 -19
- package/test/fixtures/transform/visibility/tsconfig.json +0 -1
- package/test/harness-connector-smoke.test.mjs +0 -72
- package/test/harness.test.mjs +0 -375
- package/test/nested-resolver.test.mjs +0 -184
- package/test/openapi-generator-bugs.test.mjs +0 -248
- package/test/openapi-identifier-sanitise.test.mjs +0 -69
- package/test/openapi-nested-paths.test.mjs +0 -100
- package/test/openapi-to-connector.test.mts +0 -232
- package/test/openapi-ts-compilation.test.mjs +0 -178
- package/test/scenarios/README.md +0 -148
- package/test/scenarios/complex/expected/controller.mts +0 -271
- package/test/scenarios/complex/expected/orders-resource.mts +0 -262
- package/test/scenarios/complex/expected/products-resource.mts +0 -237
- package/test/scenarios/complex/specs/orders.json +0 -362
- package/test/scenarios/complex/specs/products.json +0 -308
- package/test/scenarios/simple/expected-controller.mts +0 -60
- package/test/scenarios/simple/simple-api.json +0 -39
- package/test/scenarios.test.mts +0 -294
- package/test/transform.test.mjs +0 -68
- package/test/verify-scenarios.mjs +0 -298
- package/tools/mutation-run-entry.mjs +0 -52
- package/tools/mutation-run.mjs +0 -138
- package/tools/run-tests.mjs +0 -64
- package/tsconfig.json +0 -27
package/test/harness.test.mjs
DELETED
|
@@ -1,375 +0,0 @@
|
|
|
1
|
-
// Tests for the connector test harness (src/testing) and, through it, the SDK's
|
|
2
|
-
// handshake, dispatch and result-return paths. No test reaches the network:
|
|
3
|
-
// the only sockets are on 127.0.0.1 and vendor HTTP is mocked.
|
|
4
|
-
import http from 'node:http';
|
|
5
|
-
import {describe, it, afterEach} from 'mocha';
|
|
6
|
-
import {expect} from 'chai';
|
|
7
|
-
import {Transport} from '../build/internal/websocket/transport/index.mjs';
|
|
8
|
-
import {Connector} from '../build/internal/connector/index.mjs';
|
|
9
|
-
import Fetcher from '../build/internal/fetcher/fetcher.mjs';
|
|
10
|
-
import {ConnectorHarness, FakeAloma, VendorMock} from '../build/testing/index.mjs';
|
|
11
|
-
|
|
12
|
-
const VENDOR = 'https://api.vendor.example.test';
|
|
13
|
-
|
|
14
|
-
// A tiny connector, wired the way the SDK wires a connector repo's controller.
|
|
15
|
-
function exampleConnector(seen = {}) {
|
|
16
|
-
const connector = new Connector({id: 'example-connector', version: '1.2.3', name: 'Example Connector'});
|
|
17
|
-
|
|
18
|
-
connector
|
|
19
|
-
.configure()
|
|
20
|
-
.config({
|
|
21
|
-
fields: {
|
|
22
|
-
apiKey: {name: 'API Key', type: 'line'},
|
|
23
|
-
region: {name: 'Region', type: 'line', plain: true},
|
|
24
|
-
},
|
|
25
|
-
})
|
|
26
|
-
.types('type Query { echo: String }')
|
|
27
|
-
.resolvers({
|
|
28
|
-
echo: async (args) => args,
|
|
29
|
-
shout: async ({text}) => String(text).toUpperCase(),
|
|
30
|
-
whoami: async (_args, ctx) => ({ctx}),
|
|
31
|
-
nested: {deep: {method: async () => ({found: true})}},
|
|
32
|
-
getItem: async ({id}) => {
|
|
33
|
-
const client = seen.getClient({
|
|
34
|
-
baseUrl: VENDOR,
|
|
35
|
-
retry: 1,
|
|
36
|
-
customize: (o) => {
|
|
37
|
-
o.headers = {...o.headers, Authorization: `Bearer ${seen.config.apiKey}`};
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
return client.fetch(`/items/${id}`, {method: 'GET'});
|
|
41
|
-
},
|
|
42
|
-
createItem: async (body) => {
|
|
43
|
-
const client = seen.getClient({baseUrl: VENDOR, retry: 1});
|
|
44
|
-
return client.fetch('/items', {method: 'POST', body});
|
|
45
|
-
},
|
|
46
|
-
forgottenMock: async () => new Fetcher({retry: 1}).fetch('https://not-mocked.example.test/x'),
|
|
47
|
-
rawSocket: async () =>
|
|
48
|
-
new Promise((resolve, reject) => {
|
|
49
|
-
http.get('http://203.0.113.9/', () => resolve({reached: true})).on('error', reject);
|
|
50
|
-
}),
|
|
51
|
-
boom: async () => {
|
|
52
|
-
throw new Error('kaput');
|
|
53
|
-
},
|
|
54
|
-
makeBlob: async () => ({id: await seen.createBlob({name: 'a.txt'})}),
|
|
55
|
-
})
|
|
56
|
-
.main((arg) => {
|
|
57
|
-
seen.config = arg.config;
|
|
58
|
-
seen.getClient = arg.getClient;
|
|
59
|
-
seen.createBlob = arg.createBlob;
|
|
60
|
-
seen.starts = (seen.starts || 0) + 1;
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
return connector;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
describe('connector test harness', function () {
|
|
67
|
-
this.timeout(15000);
|
|
68
|
-
|
|
69
|
-
let harness;
|
|
70
|
-
let seen;
|
|
71
|
-
const realFetch = globalThis.fetch;
|
|
72
|
-
|
|
73
|
-
const start = async (extra = {}) => {
|
|
74
|
-
seen = {};
|
|
75
|
-
harness = await ConnectorHarness.start({
|
|
76
|
-
connector: exampleConnector(seen),
|
|
77
|
-
config: {apiKey: 'fake-api-key-not-real', region: 'eu-test'},
|
|
78
|
-
...extra,
|
|
79
|
-
});
|
|
80
|
-
return harness;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
afterEach(async () => {
|
|
84
|
-
if (harness) await harness.stop({verify: false});
|
|
85
|
-
harness = undefined;
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe('handshake', () => {
|
|
89
|
-
it('registers, connects and opens the websocket', async () => {
|
|
90
|
-
await start();
|
|
91
|
-
const {aloma} = harness;
|
|
92
|
-
|
|
93
|
-
expect(aloma.connected).to.equal(true);
|
|
94
|
-
expect(aloma.registrations).to.have.length(1);
|
|
95
|
-
expect(aloma.protocolErrors).to.deep.equal([]);
|
|
96
|
-
// first connect has no token and is told to register (401), the second carries the issued token
|
|
97
|
-
expect(aloma.connects.map((c) => c.authorized)).to.deep.equal([false, true]);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('registers id, version, name, a public key and the schema', async () => {
|
|
101
|
-
await start();
|
|
102
|
-
const body = harness.aloma.registration;
|
|
103
|
-
|
|
104
|
-
expect(body.id).to.equal('example-connector');
|
|
105
|
-
expect(body.version).to.equal('1.2.3');
|
|
106
|
-
expect(body.name).to.equal('Example Connector');
|
|
107
|
-
expect(body.publicKey).to.be.a('string').with.length.greaterThan(100);
|
|
108
|
-
expect(body.schema.configSchema.fields).to.have.keys('apiKey', 'region');
|
|
109
|
-
expect(body.schema.introspect).to.equal('type Query { echo: String }');
|
|
110
|
-
expect(harness.aloma.connects[1].headers['user-agent']).to.equal('example-connector/1.2.3');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('delivers encrypted config decrypted and plain config as is, then runs main() once', async () => {
|
|
114
|
-
await start();
|
|
115
|
-
|
|
116
|
-
expect(seen.config).to.deep.equal({apiKey: 'fake-api-key-not-real', region: 'eu-test'});
|
|
117
|
-
expect(seen.starts).to.equal(1);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('answers connector.introspect with the schema and types', async () => {
|
|
121
|
-
await start();
|
|
122
|
-
const answer = await harness.aloma.introspect();
|
|
123
|
-
|
|
124
|
-
expect(answer.introspect).to.equal('type Query { echo: String }');
|
|
125
|
-
expect(answer.configSchema.fields.apiKey.name).to.equal('API Key');
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('can be started and stopped repeatedly without leaking state', async () => {
|
|
129
|
-
for (let i = 0; i < 3; i++) {
|
|
130
|
-
await start();
|
|
131
|
-
expect(await harness.call('shout', {text: 'x'})).to.deep.equal({shout: 'X'});
|
|
132
|
-
await harness.stop();
|
|
133
|
-
harness = undefined;
|
|
134
|
-
}
|
|
135
|
-
expect(globalThis.fetch).to.equal(realFetch);
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
describe('method calls', () => {
|
|
140
|
-
it('round-trips an object result unchanged', async () => {
|
|
141
|
-
await start();
|
|
142
|
-
expect(await harness.call('echo', {a: 1, b: ['x']})).to.deep.equal({a: 1, b: ['x']});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('wraps a non-object result under the method name', async () => {
|
|
146
|
-
await start();
|
|
147
|
-
expect(await harness.call('shout', {text: 'hello'})).to.deep.equal({shout: 'HELLO'});
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('resolves nested methods addressed by a path array', async () => {
|
|
151
|
-
await start();
|
|
152
|
-
expect(await harness.call(['nested', 'deep', 'method'])).to.deep.equal({found: true});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('forwards taskId, namespace and sticky as ctx', async () => {
|
|
156
|
-
await start();
|
|
157
|
-
const answer = await harness.call('whoami', {}, {taskId: 't-1', namespace: 'ns', sticky: true});
|
|
158
|
-
|
|
159
|
-
expect(answer.ctx).to.deep.equal({taskId: 't-1', namespace: 'ns', sticky: true});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('answers concurrent calls independently', async () => {
|
|
163
|
-
await start();
|
|
164
|
-
const results = await Promise.all([1, 2, 3, 4, 5].map((n) => harness.call('echo', {n})));
|
|
165
|
-
|
|
166
|
-
expect(results.map((r) => r.n)).to.deep.equal([1, 2, 3, 4, 5]);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('serves connector-initiated requests through the fake endpoint (blobs)', async () => {
|
|
170
|
-
await start();
|
|
171
|
-
harness.aloma.handle('connector.blob.create', (args) => (args.name === 'a.txt' ? {id: 'blob-1'} : {error: 'bad'}));
|
|
172
|
-
|
|
173
|
-
expect(await harness.call('makeBlob')).to.deep.equal({id: 'blob-1'});
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
describe('vendor HTTP mock', () => {
|
|
178
|
-
it('answers the connector vendor call from a recorded response', async () => {
|
|
179
|
-
await start();
|
|
180
|
-
harness.vendor.get(`${VENDOR}/items/7`, {json: {id: 7, name: 'recorded'}});
|
|
181
|
-
|
|
182
|
-
expect(await harness.call('getItem', {id: 7})).to.deep.equal({id: 7, name: 'recorded'});
|
|
183
|
-
expect(harness.vendor.requests).to.have.length(1);
|
|
184
|
-
expect(harness.vendor.requests[0].headers.authorization).to.equal('Bearer fake-api-key-not-real');
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it('lets a responder function see the request body and choose the reply', async () => {
|
|
188
|
-
await start();
|
|
189
|
-
harness.vendor.post(`${VENDOR}/items`, (req) => ({status: 201, json: {created: JSON.parse(req.body)}}));
|
|
190
|
-
|
|
191
|
-
expect(await harness.call('createItem', {name: 'new'})).to.deep.equal({created: {name: 'new'}});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('records the url the Fetcher really sends', async () => {
|
|
195
|
-
await start();
|
|
196
|
-
harness.vendor.get(`${VENDOR}/items/1`, {json: {}});
|
|
197
|
-
await harness.call('getItem', {id: 1});
|
|
198
|
-
|
|
199
|
-
// PINS SUSPECT BEHAVIOUR: Fetcher joins baseUrl + path and then collapses every run of slashes with
|
|
200
|
-
// .replace(/\/\/+/g, '/'), so "https://host" becomes "https:/host". Node's URL parser repairs
|
|
201
|
-
// this for http(s), but the same replace would also damage a "//" inside a query value.
|
|
202
|
-
expect(harness.vendor.requests[0].url).to.equal('https://api.vendor.example.test/items/1');
|
|
203
|
-
expect(harness.vendor.requests[0].rawUrl).to.equal('https:/api.vendor.example.test/items/1');
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('turns a vendor error status into a method error', async () => {
|
|
207
|
-
await start();
|
|
208
|
-
harness.vendor.get(/\/items\/9$/, {status: 404, text: 'no such item'});
|
|
209
|
-
|
|
210
|
-
const answer = await harness.call('getItem', {id: 9});
|
|
211
|
-
expect(answer.error).to.match(/404 no such item/);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it('rejects an unmocked request, reports it to the connector and fails the test on stop()', async () => {
|
|
215
|
-
await start();
|
|
216
|
-
const answer = await harness.call('forgottenMock');
|
|
217
|
-
|
|
218
|
-
expect(answer.error).to.match(/UNMOCKED vendor request: GET https:\/\/not-mocked\.example\.test\/x/);
|
|
219
|
-
expect(harness.vendor.unmocked).to.have.length(1);
|
|
220
|
-
|
|
221
|
-
let failure;
|
|
222
|
-
try {
|
|
223
|
-
await harness.stop();
|
|
224
|
-
} catch (e) {
|
|
225
|
-
failure = e;
|
|
226
|
-
}
|
|
227
|
-
harness = undefined;
|
|
228
|
-
expect(failure, 'stop() must fail when an unmocked request happened').to.be.instanceOf(Error);
|
|
229
|
-
expect(failure.message).to.match(/UNMOCKED vendor requests/);
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it('blocks raw sockets to non-loopback hosts even when fetch is bypassed', async () => {
|
|
233
|
-
await start();
|
|
234
|
-
const answer = await harness.call('rawSocket');
|
|
235
|
-
|
|
236
|
-
expect(answer.error).to.match(/NETWORK BLOCKED/);
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it('restores fetch and the network guard on stop()', async () => {
|
|
240
|
-
await start();
|
|
241
|
-
expect(globalThis.fetch).to.not.equal(realFetch);
|
|
242
|
-
await harness.stop();
|
|
243
|
-
harness = undefined;
|
|
244
|
-
|
|
245
|
-
expect(globalThis.fetch).to.equal(realFetch);
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it('limits a route with times and can assert every route was used', async () => {
|
|
249
|
-
const vendor = new VendorMock();
|
|
250
|
-
vendor.get('https://a.example.test/x', {json: {n: 1}}, {times: 1});
|
|
251
|
-
vendor.get('https://b.example.test/never', {json: {}});
|
|
252
|
-
vendor.install();
|
|
253
|
-
try {
|
|
254
|
-
const first = await globalThis.fetch('https://a.example.test/x');
|
|
255
|
-
expect(await first.json()).to.deep.equal({n: 1});
|
|
256
|
-
|
|
257
|
-
let failure;
|
|
258
|
-
try {
|
|
259
|
-
await globalThis.fetch('https://a.example.test/x');
|
|
260
|
-
} catch (e) {
|
|
261
|
-
failure = e;
|
|
262
|
-
}
|
|
263
|
-
expect(failure && failure.message).to.match(/UNMOCKED/);
|
|
264
|
-
expect(() => vendor.verifyAllRoutesUsed()).to.throw(/never called/);
|
|
265
|
-
expect(() => vendor.verify()).to.throw(/UNMOCKED/);
|
|
266
|
-
} finally {
|
|
267
|
-
vendor.uninstall();
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
describe('failing connectors', () => {
|
|
273
|
-
it('reports a throwing method as an error answer and keeps serving', async () => {
|
|
274
|
-
await start();
|
|
275
|
-
|
|
276
|
-
expect(await harness.call('boom')).to.deep.equal({error: 'Error: kaput'});
|
|
277
|
-
expect(await harness.call('shout', {text: 'still up'})).to.deep.equal({shout: 'STILL UP'});
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
it('reports an unknown method as an error answer', async () => {
|
|
281
|
-
await start();
|
|
282
|
-
const answer = await harness.call('doesNotExist');
|
|
283
|
-
|
|
284
|
-
expect(answer.error).to.match(/doesNotExist not found/);
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it('callOk() throws when the connector answered with an error', async () => {
|
|
288
|
-
await start();
|
|
289
|
-
let failure;
|
|
290
|
-
try {
|
|
291
|
-
await harness.callOk('boom');
|
|
292
|
-
} catch (e) {
|
|
293
|
-
failure = e;
|
|
294
|
-
}
|
|
295
|
-
expect(failure.message).to.match(/boom failed: Error: kaput/);
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
it('fails start() with the cause when main() throws', async () => {
|
|
299
|
-
const connector = new Connector({id: 'broken-main', version: '0.0.1', name: 'Broken'});
|
|
300
|
-
connector
|
|
301
|
-
.configure()
|
|
302
|
-
.config({fields: {k: {name: 'K', type: 'line'}}})
|
|
303
|
-
.types('type Query { x: String }')
|
|
304
|
-
.resolvers({x: async () => 1})
|
|
305
|
-
.main(() => {
|
|
306
|
-
throw new Error('cannot start');
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
let failure;
|
|
310
|
-
try {
|
|
311
|
-
await ConnectorHarness.start({connector, config: {k: 'v'}});
|
|
312
|
-
} catch (e) {
|
|
313
|
-
failure = e;
|
|
314
|
-
}
|
|
315
|
-
expect(failure && failure.message).to.equal('cannot start');
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
describe('pinned SDK behaviour', () => {
|
|
320
|
-
it('Transport.close() never terminates the websocket', () => {
|
|
321
|
-
// PINS SUSPECT BEHAVIOUR: Transport.close() calls local.ws.terminate(), but `local` is not defined in
|
|
322
|
-
// close() (it is only defined in the other methods). The ReferenceError is swallowed by the try/catch,
|
|
323
|
-
// so close() clears its timers and flags but leaves the socket open. Today a closed connector relies on
|
|
324
|
-
// the server side (or process exit) to drop the connection.
|
|
325
|
-
const transport = new Transport({config: {}, onMessage() {}, onConnect() {}});
|
|
326
|
-
let terminated = false;
|
|
327
|
-
transport.ws = {terminate: () => (terminated = true)};
|
|
328
|
-
|
|
329
|
-
transport.close();
|
|
330
|
-
|
|
331
|
-
expect(transport.running).to.equal(false);
|
|
332
|
-
expect(transport.connected).to.equal(false);
|
|
333
|
-
expect(terminated).to.equal(false);
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
describe('fake ALOMA strictness', () => {
|
|
338
|
-
let aloma;
|
|
339
|
-
afterEach(async () => aloma && (await aloma.close()));
|
|
340
|
-
|
|
341
|
-
it('refuses registration with a wrong registration token and records it', async () => {
|
|
342
|
-
aloma = await FakeAloma.start();
|
|
343
|
-
const response = await fetch(`${aloma.url}register`, {
|
|
344
|
-
method: 'POST',
|
|
345
|
-
body: '{}',
|
|
346
|
-
headers: {Authorization: 'Connector wrong-token'},
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
expect(response.status).to.equal(401);
|
|
350
|
-
expect(aloma.protocolErrors.join()).to.match(/wrong registration token/);
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
it('answers /connect with 401 until a token was issued by registering', async () => {
|
|
354
|
-
aloma = await FakeAloma.start();
|
|
355
|
-
const response = await fetch(`${aloma.url}connect`, {
|
|
356
|
-
method: 'POST',
|
|
357
|
-
body: '{}',
|
|
358
|
-
headers: {Authorization: 'Connector null'},
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
expect(response.status).to.equal(401);
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
it('times out with a diagnostic when no connector connects', async () => {
|
|
365
|
-
aloma = await FakeAloma.start();
|
|
366
|
-
let failure;
|
|
367
|
-
try {
|
|
368
|
-
await aloma.waitForConnection(50);
|
|
369
|
-
} catch (e) {
|
|
370
|
-
failure = e;
|
|
371
|
-
}
|
|
372
|
-
expect(failure.message).to.match(/did not connect within 50ms/);
|
|
373
|
-
});
|
|
374
|
-
});
|
|
375
|
-
});
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { Dispatcher } from '../build/internal/dispatcher/index.mjs';
|
|
2
|
-
|
|
3
|
-
// Simple test framework matching project convention
|
|
4
|
-
const colors = {
|
|
5
|
-
green: '\x1b[32m',
|
|
6
|
-
red: '\x1b[31m',
|
|
7
|
-
yellow: '\x1b[33m',
|
|
8
|
-
reset: '\x1b[0m',
|
|
9
|
-
cyan: '\x1b[36m'
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
let passed = 0;
|
|
13
|
-
let failed = 0;
|
|
14
|
-
|
|
15
|
-
async function test(name, fn) {
|
|
16
|
-
try {
|
|
17
|
-
console.log(`${colors.cyan}Running: ${name}${colors.reset}`);
|
|
18
|
-
await fn();
|
|
19
|
-
console.log(`${colors.green}✓ PASS: ${name}${colors.reset}\n`);
|
|
20
|
-
passed++;
|
|
21
|
-
} catch (error) {
|
|
22
|
-
console.log(`${colors.red}✗ FAIL: ${name}${colors.reset}`);
|
|
23
|
-
console.log(`${colors.red} Error: ${error.message}${colors.reset}\n`);
|
|
24
|
-
failed++;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function assert(condition, message) {
|
|
29
|
-
if (!condition) throw new Error(message || 'Assertion failed');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function assertEqual(actual, expected, message) {
|
|
33
|
-
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
|
|
34
|
-
throw new Error(message || `Expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Helper: build a dispatcher with given resolvers and execute a query
|
|
39
|
-
async function buildAndExecute(resolvers, query, variables) {
|
|
40
|
-
const dispatcher = new Dispatcher();
|
|
41
|
-
dispatcher.types({ fields: {} });
|
|
42
|
-
dispatcher.resolvers(resolvers);
|
|
43
|
-
dispatcher.main(async () => {});
|
|
44
|
-
const built = dispatcher.build();
|
|
45
|
-
return built.execute({ query, variables });
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// --- TESTS ---
|
|
49
|
-
|
|
50
|
-
// Test 1: Dispatcher correctly resolves pre-built nested structures (baseline)
|
|
51
|
-
await test('Dispatcher resolves pre-built nested structure (baseline)', async () => {
|
|
52
|
-
const handler = async (args) => ({ created: true, ...args });
|
|
53
|
-
const resolvers = { crm: { contacts: { create: handler } } };
|
|
54
|
-
const result = await buildAndExecute(resolvers, ['crm', 'contacts', 'create'], { name: 'test' });
|
|
55
|
-
assertEqual(result, { created: true, name: 'test' });
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// Test 2: Dispatcher resolves flat keys (baseline)
|
|
59
|
-
await test('Dispatcher resolves flat key (baseline)', async () => {
|
|
60
|
-
const handler = async (args) => ({ flat: true, ...args });
|
|
61
|
-
const resolvers = { contactsCreate: handler };
|
|
62
|
-
const result = await buildAndExecute(resolvers, ['contactsCreate'], { id: 1 });
|
|
63
|
-
assertEqual(result, { flat: true, id: 1 });
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// Test 3: CRITICAL — import buildResolvers from runtime-context and verify it
|
|
67
|
-
// handles dotted method names by creating nested structures.
|
|
68
|
-
// This is the RED test: buildResolvers doesn't exist yet.
|
|
69
|
-
await test('buildResolvers creates nested structure for dotted method names', async () => {
|
|
70
|
-
const { buildResolvers } = await import('../build/builder/runtime-context.mjs');
|
|
71
|
-
|
|
72
|
-
assert(typeof buildResolvers === 'function', 'buildResolvers should be exported from runtime-context');
|
|
73
|
-
|
|
74
|
-
const mockController = {
|
|
75
|
-
'crm.contacts.create': async (args) => ({ method: 'crm.contacts.create', ...args }),
|
|
76
|
-
'crm.contacts.list': async (args) => ({ method: 'crm.contacts.list', ...args }),
|
|
77
|
-
'flatMethod': async (args) => ({ method: 'flatMethod', ...args }),
|
|
78
|
-
'__autocomplete': async () => ({}),
|
|
79
|
-
'__endpoint': async () => ({}),
|
|
80
|
-
'__default': async () => ({}),
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const methods = ['crm.contacts.create', 'crm.contacts.list', 'flatMethod', '__autocomplete', '__endpoint', '__default'];
|
|
84
|
-
const resolvers = buildResolvers(methods, mockController);
|
|
85
|
-
|
|
86
|
-
// Nested structure for dotted names
|
|
87
|
-
assert(resolvers.crm, 'resolvers.crm should exist');
|
|
88
|
-
assert(resolvers.crm.contacts, 'resolvers.crm.contacts should exist');
|
|
89
|
-
assert(typeof resolvers.crm.contacts.create === 'function', 'crm.contacts.create should be a function');
|
|
90
|
-
assert(typeof resolvers.crm.contacts.list === 'function', 'crm.contacts.list should be a function');
|
|
91
|
-
|
|
92
|
-
// Flat structure for non-dotted names
|
|
93
|
-
assert(typeof resolvers.flatMethod === 'function', 'flatMethod should be a function');
|
|
94
|
-
assert(typeof resolvers.__autocomplete === 'function', '__autocomplete should be a function');
|
|
95
|
-
assert(typeof resolvers.__endpoint === 'function', '__endpoint should be a function');
|
|
96
|
-
assert(typeof resolvers.__default === 'function', '__default should be a function');
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
// Test 4: buildResolvers nested methods resolve correctly through dispatcher
|
|
100
|
-
await test('buildResolvers nested methods resolve through dispatcher end-to-end', async () => {
|
|
101
|
-
const { buildResolvers } = await import('../build/builder/runtime-context.mjs');
|
|
102
|
-
|
|
103
|
-
const mockController = {
|
|
104
|
-
'crm.contacts.create': async (args) => ({ created: true, ...(args || {}) }),
|
|
105
|
-
'crm.contacts.list': async () => ({ items: ['a', 'b'] }),
|
|
106
|
-
'flatMethod': async (args) => ({ flat: true, ...(args || {}) }),
|
|
107
|
-
'__autocomplete': async () => ({}),
|
|
108
|
-
'__endpoint': async () => ({}),
|
|
109
|
-
'__default': async () => ({}),
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const methods = ['crm.contacts.create', 'crm.contacts.list', 'flatMethod', '__autocomplete', '__endpoint', '__default'];
|
|
113
|
-
const resolvers = buildResolvers(methods, mockController);
|
|
114
|
-
|
|
115
|
-
// Execute through dispatcher
|
|
116
|
-
const nestedResult = await buildAndExecute(resolvers, ['crm', 'contacts', 'create'], { name: 'Acme' });
|
|
117
|
-
assertEqual(nestedResult, { created: true, name: 'Acme' });
|
|
118
|
-
|
|
119
|
-
const listResult = await buildAndExecute(resolvers, ['crm', 'contacts', 'list'], {});
|
|
120
|
-
assertEqual(listResult, { items: ['a', 'b'] });
|
|
121
|
-
|
|
122
|
-
const flatResult = await buildAndExecute(resolvers, ['flatMethod'], { x: 42 });
|
|
123
|
-
assertEqual(flatResult, { flat: true, x: 42 });
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
// Test 5: buildResolvers preserves existing flat registration for non-dotted names
|
|
127
|
-
await test('buildResolvers flat names are unchanged (backward compat)', async () => {
|
|
128
|
-
const { buildResolvers } = await import('../build/builder/runtime-context.mjs');
|
|
129
|
-
|
|
130
|
-
const mockController = {
|
|
131
|
-
'simpleMethodA': async () => ({ a: true }),
|
|
132
|
-
'simpleMethodB': async () => ({ b: true }),
|
|
133
|
-
'__autocomplete': async () => ({}),
|
|
134
|
-
'__endpoint': async () => ({}),
|
|
135
|
-
'__default': async () => ({}),
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const methods = ['simpleMethodA', 'simpleMethodB', '__autocomplete', '__endpoint', '__default'];
|
|
139
|
-
const resolvers = buildResolvers(methods, mockController);
|
|
140
|
-
|
|
141
|
-
// All flat — no nested structures
|
|
142
|
-
assert(typeof resolvers.simpleMethodA === 'function', 'simpleMethodA should be a function');
|
|
143
|
-
assert(typeof resolvers.simpleMethodB === 'function', 'simpleMethodB should be a function');
|
|
144
|
-
|
|
145
|
-
const resultA = await buildAndExecute(resolvers, ['simpleMethodA'], {});
|
|
146
|
-
assertEqual(resultA, { a: true });
|
|
147
|
-
|
|
148
|
-
const resultB = await buildAndExecute(resolvers, ['simpleMethodB'], {});
|
|
149
|
-
assertEqual(resultB, { b: true });
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
// Test 6: Nested and flat coexist without overwriting each other
|
|
153
|
-
await test('buildResolvers nested and flat coexist without conflicts', async () => {
|
|
154
|
-
const { buildResolvers } = await import('../build/builder/runtime-context.mjs');
|
|
155
|
-
|
|
156
|
-
const mockController = {
|
|
157
|
-
'crm.contacts.create': async () => ({ source: 'nested' }),
|
|
158
|
-
'contactsCreate': async () => ({ source: 'flat' }),
|
|
159
|
-
'__autocomplete': async () => ({}),
|
|
160
|
-
'__endpoint': async () => ({}),
|
|
161
|
-
'__default': async () => ({}),
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const methods = ['crm.contacts.create', 'contactsCreate', '__autocomplete', '__endpoint', '__default'];
|
|
165
|
-
const resolvers = buildResolvers(methods, mockController);
|
|
166
|
-
|
|
167
|
-
const nestedResult = await buildAndExecute(resolvers, ['crm', 'contacts', 'create'], {});
|
|
168
|
-
assertEqual(nestedResult, { source: 'nested' });
|
|
169
|
-
|
|
170
|
-
const flatResult = await buildAndExecute(resolvers, ['contactsCreate'], {});
|
|
171
|
-
assertEqual(flatResult, { source: 'flat' });
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
// --- SUMMARY ---
|
|
175
|
-
console.log(`\n${colors.yellow}📊 Nested Resolver Test Results:${colors.reset}`);
|
|
176
|
-
console.log(`${colors.green}✓ Passed: ${passed}${colors.reset}`);
|
|
177
|
-
console.log(`${colors.red}✗ Failed: ${failed}${colors.reset}`);
|
|
178
|
-
|
|
179
|
-
if (failed > 0) {
|
|
180
|
-
console.log(`\n${colors.red}❌ Some tests failed!${colors.reset}`);
|
|
181
|
-
process.exit(1);
|
|
182
|
-
} else {
|
|
183
|
-
console.log(`\n${colors.green}🎉 All nested resolver tests passed!${colors.reset}`);
|
|
184
|
-
}
|