@egen-civitas/esm-embed-testing 0.7.9 → 0.8.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @egen-civitas/esm-embed-testing
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6af1520: A4 : `defineRuntimeConformance` (contrat commun à tous les runtimes : embarqué, autonome, factice) et tests de types du SDK (`*.test-d.ts`). A5 (D-04) : le vocabulaire « platform feature » désigne la capacité de plateforme native — alias `hasPlatformFeature`, `setPlatformFeatureResolver`, `PlatformFeatureName`, `EgenPlatformFeatureExtensions` dans `esm-globals` (noms historiques inchangés). Le SDK réexporte davantage de types publics.
8
+
3
9
  ## 0.7.9
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './test-host.js';
2
2
  export * from './conformance.js';
3
3
  export * from './check.js';
4
+ export * from './runtime-conformance.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './test-host.js';
2
2
  export * from './conformance.js';
3
3
  export * from './check.js';
4
+ export * from './runtime-conformance.js';
@@ -0,0 +1,19 @@
1
+ import { type CapabilityId } from '@egen-civitas/esm-embed-protocol';
2
+ import type { EgenClient } from '@egen-civitas/esm-embed-client';
3
+ import type { ConformanceApi } from './conformance.js';
4
+ /**
5
+ * Un « runtime » est ce qui sert les capacités derrière un `EgenClient` : le Shell réel (embarqué), le mode autonome du SDK,
6
+ * un simulateur, un runtime factice… `defineRuntimeConformance` vérifie le CONTRAT COMMUN que tous doivent honorer, de sorte que
7
+ * le code d'une app ne change pas selon le runtime (cahier §1 : « la même app fonctionne avec ou sans EGEN »).
8
+ */
9
+ export interface ConformanceRuntime {
10
+ /** Nom affiché dans les résultats de test. */
11
+ name: string;
12
+ /** Fournit un client prêt à l'emploi pour ce runtime, avec les capacités demandées ; `dispose` libère ses ressources. */
13
+ create(capabilities: CapabilityId[]): Promise<{
14
+ client: EgenClient;
15
+ dispose(): void;
16
+ }>;
17
+ }
18
+ export declare function defineRuntimeConformance(runtime: ConformanceRuntime, t: ConformanceApi): void;
19
+ //# sourceMappingURL=runtime-conformance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-conformance.d.ts","sourceRoot":"","sources":["../src/runtime-conformance.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAC9F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,yHAAyH;IACzH,MAAM,CAAC,YAAY,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,UAAU,CAAC;QAAC,OAAO,IAAI,IAAI,CAAA;KAAE,CAAC,CAAC;CACxF;AAmBD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,kBAAkB,EAAE,CAAC,EAAE,cAAc,GAAG,IAAI,CAwH7F"}
@@ -0,0 +1,677 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
+ try {
11
+ var info = gen[key](arg);
12
+ var value = info.value;
13
+ } catch (error) {
14
+ reject(error);
15
+ return;
16
+ }
17
+ if (info.done) {
18
+ resolve(value);
19
+ } else {
20
+ Promise.resolve(value).then(_next, _throw);
21
+ }
22
+ }
23
+ function _async_to_generator(fn) {
24
+ return function() {
25
+ var self = this, args = arguments;
26
+ return new Promise(function(resolve, reject) {
27
+ var gen = fn.apply(self, args);
28
+ function _next(value) {
29
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
+ }
31
+ function _throw(err) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
+ }
34
+ _next(undefined);
35
+ });
36
+ };
37
+ }
38
+ function _instanceof(left, right) {
39
+ "@swc/helpers - instanceof";
40
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
41
+ return !!right[Symbol.hasInstance](left);
42
+ } else {
43
+ return left instanceof right;
44
+ }
45
+ }
46
+ function _iterable_to_array_limit(arr, i) {
47
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
48
+ if (_i == null) return;
49
+ var _arr = [];
50
+ var _n = true;
51
+ var _d = false;
52
+ var _s, _e;
53
+ try {
54
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
55
+ _arr.push(_s.value);
56
+ if (i && _arr.length === i) break;
57
+ }
58
+ } catch (err) {
59
+ _d = true;
60
+ _e = err;
61
+ } finally{
62
+ try {
63
+ if (!_n && _i["return"] != null) _i["return"]();
64
+ } finally{
65
+ if (_d) throw _e;
66
+ }
67
+ }
68
+ return _arr;
69
+ }
70
+ function _non_iterable_rest() {
71
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
72
+ }
73
+ function _sliced_to_array(arr, i) {
74
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
75
+ }
76
+ function _type_of(obj) {
77
+ "@swc/helpers - typeof";
78
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
79
+ }
80
+ function _unsupported_iterable_to_array(o, minLen) {
81
+ if (!o) return;
82
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
83
+ var n = Object.prototype.toString.call(o).slice(8, -1);
84
+ if (n === "Object" && o.constructor) n = o.constructor.name;
85
+ if (n === "Map" || n === "Set") return Array.from(n);
86
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
87
+ }
88
+ function _ts_generator(thisArg, body) {
89
+ var f, y, t, _ = {
90
+ label: 0,
91
+ sent: function() {
92
+ if (t[0] & 1) throw t[1];
93
+ return t[1];
94
+ },
95
+ trys: [],
96
+ ops: []
97
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
98
+ return d(g, "next", {
99
+ value: verb(0)
100
+ }), d(g, "throw", {
101
+ value: verb(1)
102
+ }), d(g, "return", {
103
+ value: verb(2)
104
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
105
+ value: function() {
106
+ return this;
107
+ }
108
+ }), g;
109
+ function verb(n) {
110
+ return function(v) {
111
+ return step([
112
+ n,
113
+ v
114
+ ]);
115
+ };
116
+ }
117
+ function step(op) {
118
+ if (f) throw new TypeError("Generator is already executing.");
119
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
120
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
121
+ if (y = 0, t) op = [
122
+ op[0] & 2,
123
+ t.value
124
+ ];
125
+ switch(op[0]){
126
+ case 0:
127
+ case 1:
128
+ t = op;
129
+ break;
130
+ case 4:
131
+ _.label++;
132
+ return {
133
+ value: op[1],
134
+ done: false
135
+ };
136
+ case 5:
137
+ _.label++;
138
+ y = op[1];
139
+ op = [
140
+ 0
141
+ ];
142
+ continue;
143
+ case 7:
144
+ op = _.ops.pop();
145
+ _.trys.pop();
146
+ continue;
147
+ default:
148
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
149
+ _ = 0;
150
+ continue;
151
+ }
152
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
153
+ _.label = op[1];
154
+ break;
155
+ }
156
+ if (op[0] === 6 && _.label < t[1]) {
157
+ _.label = t[1];
158
+ t = op;
159
+ break;
160
+ }
161
+ if (t && _.label < t[2]) {
162
+ _.label = t[2];
163
+ _.ops.push(op);
164
+ break;
165
+ }
166
+ if (t[2]) _.ops.pop();
167
+ _.trys.pop();
168
+ continue;
169
+ }
170
+ op = body.call(thisArg, _);
171
+ } catch (e) {
172
+ op = [
173
+ 6,
174
+ e
175
+ ];
176
+ y = 0;
177
+ } finally{
178
+ f = t = 0;
179
+ }
180
+ if (op[0] & 5) throw op[1];
181
+ return {
182
+ value: op[0] ? op[1] : void 0,
183
+ done: true
184
+ };
185
+ }
186
+ }
187
+ import { EmbedError, ERROR_CODES } from '@egen-civitas/esm-embed-protocol';
188
+ var ALL = [
189
+ 'tenant',
190
+ 'locale',
191
+ 'navigation',
192
+ 'events',
193
+ 'notifications',
194
+ 'dialogs',
195
+ 'flags',
196
+ 'config',
197
+ 'telemetry',
198
+ 'lifecycle',
199
+ 'extensions'
200
+ ];
201
+ var STATES = [
202
+ 'connecting',
203
+ 'ready',
204
+ 'active',
205
+ 'hidden',
206
+ 'closing',
207
+ 'closed',
208
+ 'failed',
209
+ 'standalone'
210
+ ];
211
+ var SURFACE = {
212
+ tenant: [
213
+ 'get',
214
+ 'onChange'
215
+ ],
216
+ locale: [
217
+ 'get',
218
+ 'onChange',
219
+ 'set',
220
+ 'fallbackChain'
221
+ ],
222
+ navigation: [
223
+ 'report',
224
+ 'navigate',
225
+ 'current',
226
+ 'exists',
227
+ 'back',
228
+ 'canGoBack',
229
+ 'intent',
230
+ 'link',
231
+ 'notFound',
232
+ 'setTitle',
233
+ 'resize',
234
+ 'onGoto'
235
+ ],
236
+ events: [
237
+ 'publish',
238
+ 'subscribe',
239
+ 'on',
240
+ 'once',
241
+ 'request',
242
+ 'respond',
243
+ 'define'
244
+ ],
245
+ notifications: [
246
+ 'show'
247
+ ],
248
+ dialogs: [
249
+ 'confirm',
250
+ 'alert'
251
+ ],
252
+ flags: [
253
+ 'isEnabled'
254
+ ],
255
+ config: [
256
+ 'get',
257
+ 'getValue',
258
+ 'environment',
259
+ 'onChange'
260
+ ],
261
+ telemetry: [
262
+ 'log',
263
+ 'metric',
264
+ 'error',
265
+ 'trace',
266
+ 'health'
267
+ ],
268
+ lifecycle: [
269
+ 'ready',
270
+ 'onBeforeLeave',
271
+ 'onClosing',
272
+ 'onError',
273
+ 'onStateChange',
274
+ 'onVisibilityChange',
275
+ 'onFocusChange',
276
+ 'setBeforeLeave'
277
+ ],
278
+ extensions: [
279
+ 'list'
280
+ ]
281
+ };
282
+ export function defineRuntimeConformance(runtime, t) {
283
+ var describe = t.describe, it = t.it, expect = t.expect;
284
+ var use = function use(caps, fn) {
285
+ return _async_to_generator(function() {
286
+ var _ref, client, dispose;
287
+ return _ts_generator(this, function(_state) {
288
+ switch(_state.label){
289
+ case 0:
290
+ return [
291
+ 4,
292
+ runtime.create(caps)
293
+ ];
294
+ case 1:
295
+ _ref = _state.sent(), client = _ref.client, dispose = _ref.dispose;
296
+ _state.label = 2;
297
+ case 2:
298
+ _state.trys.push([
299
+ 2,
300
+ ,
301
+ 4,
302
+ 5
303
+ ]);
304
+ return [
305
+ 4,
306
+ fn(client)
307
+ ];
308
+ case 3:
309
+ return [
310
+ 2,
311
+ _state.sent()
312
+ ];
313
+ case 4:
314
+ client.close();
315
+ dispose();
316
+ return [
317
+ 7
318
+ ];
319
+ case 5:
320
+ return [
321
+ 2
322
+ ];
323
+ }
324
+ });
325
+ })();
326
+ };
327
+ describe("conformit\xe9 du runtime \xab ".concat(runtime.name, " \xbb"), function() {
328
+ it('surface : mêmes domaines et méthodes que le SDK, quel que soit le runtime', function() {
329
+ return use(ALL, function(c) {
330
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
331
+ try {
332
+ for(var _iterator = Object.entries(SURFACE)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
333
+ var _step_value = _sliced_to_array(_step.value, 2), domain = _step_value[0], methods = _step_value[1];
334
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
335
+ try {
336
+ for(var _iterator1 = methods[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
337
+ var m = _step1.value;
338
+ expect(_type_of(c[domain][m])).toBe('function');
339
+ }
340
+ } catch (err) {
341
+ _didIteratorError1 = true;
342
+ _iteratorError1 = err;
343
+ } finally{
344
+ try {
345
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
346
+ _iterator1.return();
347
+ }
348
+ } finally{
349
+ if (_didIteratorError1) {
350
+ throw _iteratorError1;
351
+ }
352
+ }
353
+ }
354
+ }
355
+ } catch (err) {
356
+ _didIteratorError = true;
357
+ _iteratorError = err;
358
+ } finally{
359
+ try {
360
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
361
+ _iterator.return();
362
+ }
363
+ } finally{
364
+ if (_didIteratorError) {
365
+ throw _iteratorError;
366
+ }
367
+ }
368
+ }
369
+ for(var _i = 0, _iter = [
370
+ 'has',
371
+ 'close',
372
+ 'notify',
373
+ 'diagnostics'
374
+ ]; _i < _iter.length; _i++){
375
+ var m1 = _iter[_i];
376
+ expect(_type_of(c[m1])).toBe('function');
377
+ }
378
+ expect(_type_of(c.locale.format.number)).toBe('function');
379
+ expect(_type_of(c.telemetry.trace)).toBe('function');
380
+ });
381
+ });
382
+ it('identité : moduleName, connected et listes accordées/refusées cohérents', function() {
383
+ return use([
384
+ 'tenant'
385
+ ], function(c) {
386
+ expect(_type_of(c.moduleName)).toBe('string');
387
+ expect(_type_of(c.connected)).toBe('boolean');
388
+ expect(c.has('tenant')).toBe(true);
389
+ expect(Array.isArray(c.capabilities)).toBe(true);
390
+ expect(Array.isArray(c.denied)).toBe(true);
391
+ expect(c.capabilities.every(function(g) {
392
+ return typeof g.id === 'string' && typeof g.version === 'number';
393
+ })).toBe(true);
394
+ });
395
+ });
396
+ it('arguments invalides : INVALID_ARGS identique partout (jamais de comportement permissif)', function() {
397
+ return use([
398
+ 'navigation',
399
+ 'events'
400
+ ], function(c) {
401
+ return _async_to_generator(function() {
402
+ return _ts_generator(this, function(_state) {
403
+ switch(_state.label){
404
+ case 0:
405
+ return [
406
+ 4,
407
+ expect(c.navigation.navigate('http://evil.example')).rejects.toMatchObject({
408
+ code: 'INVALID_ARGS'
409
+ })
410
+ ];
411
+ case 1:
412
+ _state.sent();
413
+ return [
414
+ 4,
415
+ expect(c.events.publish('Pas Valide', 1)).rejects.toMatchObject({
416
+ code: 'INVALID_ARGS'
417
+ })
418
+ ];
419
+ case 2:
420
+ _state.sent();
421
+ return [
422
+ 2
423
+ ];
424
+ }
425
+ });
426
+ })();
427
+ });
428
+ });
429
+ // Méthodes FACULTATIVES (le Shell ne les sert que s'il sait les honorer) : un refus propre est permis, jamais un succès.
430
+ it('méthodes facultatives (locale.set, config.environment, dialogs.alert) : jamais de succès sur un appel invalide', function() {
431
+ return use([
432
+ 'locale'
433
+ ], function(c) {
434
+ return _async_to_generator(function() {
435
+ var code;
436
+ return _ts_generator(this, function(_state) {
437
+ switch(_state.label){
438
+ case 0:
439
+ return [
440
+ 4,
441
+ c.locale.set('fr_GA').then(function() {
442
+ return 'resolved';
443
+ }, function(e) {
444
+ return e.code;
445
+ })
446
+ ];
447
+ case 1:
448
+ code = _state.sent();
449
+ expect([
450
+ 'INVALID_ARGS',
451
+ 'UNKNOWN_METHOD',
452
+ 'DENIED'
453
+ ]).toContain(code);
454
+ return [
455
+ 2
456
+ ];
457
+ }
458
+ });
459
+ })();
460
+ });
461
+ });
462
+ it('erreurs : toujours des EmbedError dont le code appartient au catalogue fermé', function() {
463
+ return use([
464
+ 'navigation'
465
+ ], function(c) {
466
+ return _async_to_generator(function() {
467
+ var e;
468
+ return _ts_generator(this, function(_state) {
469
+ switch(_state.label){
470
+ case 0:
471
+ return [
472
+ 4,
473
+ c.navigation.navigate('http://evil.example').then(function() {
474
+ return undefined;
475
+ }, function(err) {
476
+ return err;
477
+ })
478
+ ];
479
+ case 1:
480
+ e = _state.sent();
481
+ expect(_instanceof(e, EmbedError)).toBe(true);
482
+ expect(ERROR_CODES.includes(e.code)).toBe(true);
483
+ return [
484
+ 2
485
+ ];
486
+ }
487
+ });
488
+ })();
489
+ });
490
+ });
491
+ it('capacité non demandée : DENIED, jamais d’exception synchrone', function() {
492
+ return use([
493
+ 'tenant'
494
+ ], function(c) {
495
+ return _async_to_generator(function() {
496
+ var thrown, p;
497
+ return _ts_generator(this, function(_state) {
498
+ switch(_state.label){
499
+ case 0:
500
+ thrown = false;
501
+ try {
502
+ p = c.flags.isEnabled('x');
503
+ } catch (unused) {
504
+ thrown = true;
505
+ }
506
+ expect(thrown).toBe(false);
507
+ return [
508
+ 4,
509
+ expect(p).rejects.toMatchObject({
510
+ code: 'DENIED'
511
+ })
512
+ ];
513
+ case 1:
514
+ _state.sent();
515
+ return [
516
+ 2
517
+ ];
518
+ }
519
+ });
520
+ })();
521
+ });
522
+ });
523
+ it('link() est pur et identique partout', function() {
524
+ return use([
525
+ 'navigation'
526
+ ], function(c) {
527
+ expect(c.navigation.link('/a?x=1', {
528
+ query: {
529
+ y: 2,
530
+ x: null
531
+ },
532
+ hash: 'h'
533
+ })).toBe('/a?y=2#h');
534
+ expect(function() {
535
+ return c.navigation.link('https://x.example');
536
+ }).toThrowError(/chemin interne/);
537
+ });
538
+ });
539
+ it('format.* : texte, sans échange, jamais d’exception sur une langue inconnue', function() {
540
+ return use([
541
+ 'locale'
542
+ ], function(c) {
543
+ expect(_type_of(c.locale.format.number(1234.5))).toBe('string');
544
+ expect(_type_of(c.locale.format.date(0, {
545
+ timeZone: 'UTC'
546
+ }))).toBe('string');
547
+ expect(_type_of(c.locale.format.relativeTime(-1, 'day'))).toBe('string');
548
+ });
549
+ });
550
+ it('trace : rend la valeur (ou l’exception) de la fonction mesurée, quoi qu’il arrive à l’envoi', function() {
551
+ return use([
552
+ 'telemetry'
553
+ ], function(c) {
554
+ return _async_to_generator(function() {
555
+ return _ts_generator(this, function(_state) {
556
+ switch(_state.label){
557
+ case 0:
558
+ return [
559
+ 4,
560
+ expect(c.telemetry.trace('op', function() {
561
+ return 7;
562
+ })).resolves.toBe(7)
563
+ ];
564
+ case 1:
565
+ _state.sent();
566
+ return [
567
+ 4,
568
+ expect(c.telemetry.trace('op', function() {
569
+ return _async_to_generator(function() {
570
+ return _ts_generator(this, function(_state) {
571
+ return [
572
+ 2,
573
+ 'ok'
574
+ ];
575
+ });
576
+ })();
577
+ })).resolves.toBe('ok')
578
+ ];
579
+ case 2:
580
+ _state.sent();
581
+ return [
582
+ 4,
583
+ expect(c.telemetry.trace('op', function() {
584
+ return Promise.reject(new Error('boum'));
585
+ })).rejects.toThrow('boum')
586
+ ];
587
+ case 3:
588
+ _state.sent();
589
+ return [
590
+ 2
591
+ ];
592
+ }
593
+ });
594
+ })();
595
+ });
596
+ });
597
+ it('cycle de vie : état valide, observateurs désabonnables', function() {
598
+ return use([
599
+ 'lifecycle'
600
+ ], function(c) {
601
+ expect(STATES.includes(c.lifecycle.state)).toBe(true);
602
+ var off = c.lifecycle.onBeforeLeave(function() {
603
+ return true;
604
+ });
605
+ var off2 = c.lifecycle.onClosing(function() {
606
+ return undefined;
607
+ });
608
+ var off3 = c.lifecycle.onError(function() {
609
+ return undefined;
610
+ });
611
+ var off4 = c.lifecycle.onStateChange(function() {
612
+ return undefined;
613
+ });
614
+ for(var _i = 0, _iter = [
615
+ off,
616
+ off2,
617
+ off3,
618
+ off4
619
+ ]; _i < _iter.length; _i++){
620
+ var o = _iter[_i];
621
+ expect(typeof o === "undefined" ? "undefined" : _type_of(o)).toBe('function');
622
+ }
623
+ for(var _i1 = 0, _iter1 = [
624
+ off,
625
+ off2,
626
+ off3,
627
+ off4
628
+ ]; _i1 < _iter1.length; _i1++){
629
+ var o1 = _iter1[_i1];
630
+ o1();
631
+ }
632
+ });
633
+ });
634
+ it('fermeture : close() idempotent ; ensuite les appels sont rejetés CLOSED ou DENIED, sans exception synchrone', function() {
635
+ return _async_to_generator(function() {
636
+ var _ref, client, dispose, p, code;
637
+ return _ts_generator(this, function(_state) {
638
+ switch(_state.label){
639
+ case 0:
640
+ return [
641
+ 4,
642
+ runtime.create([
643
+ 'tenant'
644
+ ])
645
+ ];
646
+ case 1:
647
+ _ref = _state.sent(), client = _ref.client, dispose = _ref.dispose;
648
+ client.close();
649
+ client.close();
650
+ expect(function() {
651
+ p = client.tenant.get();
652
+ }).not.toThrow();
653
+ return [
654
+ 4,
655
+ p.then(function() {
656
+ return 'resolved';
657
+ }, function(e) {
658
+ return e.code;
659
+ })
660
+ ];
661
+ case 2:
662
+ code = _state.sent();
663
+ expect([
664
+ 'CLOSED',
665
+ 'DENIED'
666
+ ]).toContain(code);
667
+ expect(client.lifecycle.state === 'closed' || client.lifecycle.state === 'standalone').toBe(true);
668
+ dispose();
669
+ return [
670
+ 2
671
+ ];
672
+ }
673
+ });
674
+ })();
675
+ });
676
+ });
677
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egen-civitas/esm-embed-testing",
3
- "version": "0.7.9",
3
+ "version": "0.8.0",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Développer et tester une app embarquée sans le Core : hôte de test en mémoire, suite de conformité du protocole v2, simulateur de Shell (egen-embed-sim).",
6
6
  "type": "module",
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './test-host.js';
2
2
  export * from './conformance.js';
3
3
  export * from './check.js';
4
+ export * from './runtime-conformance.js';
@@ -0,0 +1,154 @@
1
+ import { EmbedError, ERROR_CODES, type CapabilityId } from '@egen-civitas/esm-embed-protocol';
2
+ import type { EgenClient } from '@egen-civitas/esm-embed-client';
3
+ import type { ConformanceApi } from './conformance.js';
4
+
5
+ /**
6
+ * Un « runtime » est ce qui sert les capacités derrière un `EgenClient` : le Shell réel (embarqué), le mode autonome du SDK,
7
+ * un simulateur, un runtime factice… `defineRuntimeConformance` vérifie le CONTRAT COMMUN que tous doivent honorer, de sorte que
8
+ * le code d'une app ne change pas selon le runtime (cahier §1 : « la même app fonctionne avec ou sans EGEN »).
9
+ */
10
+ export interface ConformanceRuntime {
11
+ /** Nom affiché dans les résultats de test. */
12
+ name: string;
13
+ /** Fournit un client prêt à l'emploi pour ce runtime, avec les capacités demandées ; `dispose` libère ses ressources. */
14
+ create(capabilities: CapabilityId[]): Promise<{ client: EgenClient; dispose(): void }>;
15
+ }
16
+
17
+ const ALL: CapabilityId[] = ['tenant', 'locale', 'navigation', 'events', 'notifications', 'dialogs', 'flags', 'config', 'telemetry', 'lifecycle', 'extensions'];
18
+ const STATES = ['connecting', 'ready', 'active', 'hidden', 'closing', 'closed', 'failed', 'standalone'];
19
+
20
+ const SURFACE: Record<string, string[]> = {
21
+ tenant: ['get', 'onChange'],
22
+ locale: ['get', 'onChange', 'set', 'fallbackChain'],
23
+ navigation: ['report', 'navigate', 'current', 'exists', 'back', 'canGoBack', 'intent', 'link', 'notFound', 'setTitle', 'resize', 'onGoto'],
24
+ events: ['publish', 'subscribe', 'on', 'once', 'request', 'respond', 'define'],
25
+ notifications: ['show'],
26
+ dialogs: ['confirm', 'alert'],
27
+ flags: ['isEnabled'],
28
+ config: ['get', 'getValue', 'environment', 'onChange'],
29
+ telemetry: ['log', 'metric', 'error', 'trace', 'health'],
30
+ lifecycle: ['ready', 'onBeforeLeave', 'onClosing', 'onError', 'onStateChange', 'onVisibilityChange', 'onFocusChange', 'setBeforeLeave'],
31
+ extensions: ['list'],
32
+ };
33
+
34
+ export function defineRuntimeConformance(runtime: ConformanceRuntime, t: ConformanceApi): void {
35
+ const { describe, it, expect } = t;
36
+ const use = async <T>(caps: CapabilityId[], fn: (c: EgenClient) => Promise<T> | T): Promise<T> => {
37
+ const { client, dispose } = await runtime.create(caps);
38
+ try {
39
+ return await fn(client);
40
+ } finally {
41
+ client.close();
42
+ dispose();
43
+ }
44
+ };
45
+
46
+ describe(`conformité du runtime « ${runtime.name} »`, () => {
47
+ it('surface : mêmes domaines et méthodes que le SDK, quel que soit le runtime', () =>
48
+ use(ALL, (c) => {
49
+ for (const [domain, methods] of Object.entries(SURFACE)) {
50
+ for (const m of methods) expect(typeof (c as any)[domain][m]).toBe('function');
51
+ }
52
+ for (const m of ['has', 'close', 'notify', 'diagnostics']) expect(typeof (c as any)[m]).toBe('function');
53
+ expect(typeof c.locale.format.number).toBe('function');
54
+ expect(typeof c.telemetry.trace).toBe('function');
55
+ }));
56
+
57
+ it('identité : moduleName, connected et listes accordées/refusées cohérents', () =>
58
+ use(['tenant'], (c) => {
59
+ expect(typeof c.moduleName).toBe('string');
60
+ expect(typeof c.connected).toBe('boolean');
61
+ expect(c.has('tenant')).toBe(true);
62
+ expect(Array.isArray(c.capabilities)).toBe(true);
63
+ expect(Array.isArray(c.denied)).toBe(true);
64
+ expect(c.capabilities.every((g) => typeof g.id === 'string' && typeof g.version === 'number')).toBe(true);
65
+ }));
66
+
67
+ it('arguments invalides : INVALID_ARGS identique partout (jamais de comportement permissif)', () =>
68
+ use(['navigation', 'events'], async (c) => {
69
+ await expect(c.navigation.navigate('http://evil.example')).rejects.toMatchObject({ code: 'INVALID_ARGS' });
70
+ await expect(c.events.publish('Pas Valide', 1)).rejects.toMatchObject({ code: 'INVALID_ARGS' });
71
+ }));
72
+
73
+ // Méthodes FACULTATIVES (le Shell ne les sert que s'il sait les honorer) : un refus propre est permis, jamais un succès.
74
+ it('méthodes facultatives (locale.set, config.environment, dialogs.alert) : jamais de succès sur un appel invalide', () =>
75
+ use(['locale'], async (c) => {
76
+ const code = await c.locale.set('fr_GA' as string).then(
77
+ () => 'resolved',
78
+ (e: EmbedError) => e.code,
79
+ );
80
+ expect(['INVALID_ARGS', 'UNKNOWN_METHOD', 'DENIED']).toContain(code);
81
+ }));
82
+
83
+ it('erreurs : toujours des EmbedError dont le code appartient au catalogue fermé', () =>
84
+ use(['navigation'], async (c) => {
85
+ const e: unknown = await c.navigation.navigate('http://evil.example').then(
86
+ () => undefined,
87
+ (err) => err,
88
+ );
89
+ expect(e instanceof EmbedError).toBe(true);
90
+ expect((ERROR_CODES as readonly string[]).includes((e as EmbedError).code)).toBe(true);
91
+ }));
92
+
93
+ it('capacité non demandée : DENIED, jamais d’exception synchrone', () =>
94
+ use(['tenant'], async (c) => {
95
+ let thrown = false;
96
+ let p: Promise<unknown> | undefined;
97
+ try {
98
+ p = c.flags.isEnabled('x');
99
+ } catch {
100
+ thrown = true;
101
+ }
102
+ expect(thrown).toBe(false);
103
+ await expect(p).rejects.toMatchObject({ code: 'DENIED' });
104
+ }));
105
+
106
+ it('link() est pur et identique partout', () =>
107
+ use(['navigation'], (c) => {
108
+ expect(c.navigation.link('/a?x=1', { query: { y: 2, x: null }, hash: 'h' })).toBe('/a?y=2#h');
109
+ expect(() => c.navigation.link('https://x.example')).toThrowError(/chemin interne/);
110
+ }));
111
+
112
+ it('format.* : texte, sans échange, jamais d’exception sur une langue inconnue', () =>
113
+ use(['locale'], (c) => {
114
+ expect(typeof c.locale.format.number(1234.5)).toBe('string');
115
+ expect(typeof c.locale.format.date(0, { timeZone: 'UTC' })).toBe('string');
116
+ expect(typeof c.locale.format.relativeTime(-1, 'day')).toBe('string');
117
+ }));
118
+
119
+ it('trace : rend la valeur (ou l’exception) de la fonction mesurée, quoi qu’il arrive à l’envoi', () =>
120
+ use(['telemetry'], async (c) => {
121
+ await expect(c.telemetry.trace('op', () => 7)).resolves.toBe(7);
122
+ await expect(c.telemetry.trace('op', async () => 'ok')).resolves.toBe('ok');
123
+ await expect(c.telemetry.trace('op', () => Promise.reject(new Error('boum')))).rejects.toThrow('boum');
124
+ }));
125
+
126
+ it('cycle de vie : état valide, observateurs désabonnables', () =>
127
+ use(['lifecycle'], (c) => {
128
+ expect(STATES.includes(c.lifecycle.state)).toBe(true);
129
+ const off = c.lifecycle.onBeforeLeave(() => true);
130
+ const off2 = c.lifecycle.onClosing(() => undefined);
131
+ const off3 = c.lifecycle.onError(() => undefined);
132
+ const off4 = c.lifecycle.onStateChange(() => undefined);
133
+ for (const o of [off, off2, off3, off4]) expect(typeof o).toBe('function');
134
+ for (const o of [off, off2, off3, off4]) o();
135
+ }));
136
+
137
+ it('fermeture : close() idempotent ; ensuite les appels sont rejetés CLOSED ou DENIED, sans exception synchrone', async () => {
138
+ const { client, dispose } = await runtime.create(['tenant']);
139
+ client.close();
140
+ client.close();
141
+ let p: Promise<unknown> | undefined;
142
+ expect(() => {
143
+ p = client.tenant.get();
144
+ }).not.toThrow();
145
+ const code = await (p as Promise<unknown>).then(
146
+ () => 'resolved',
147
+ (e: EmbedError) => e.code,
148
+ );
149
+ expect(['CLOSED', 'DENIED']).toContain(code);
150
+ expect(client.lifecycle.state === 'closed' || client.lifecycle.state === 'standalone').toBe(true);
151
+ dispose();
152
+ });
153
+ });
154
+ }