@egen-civitas/esm-embed-testing 0.2.0 → 0.4.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 +37 -0
- package/README.md +5 -5
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +58 -79
- package/dist/conformance.d.ts.map +1 -1
- package/dist/conformance.js +244 -82
- package/dist/server.d.ts +0 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +14 -11
- package/dist/test-host.d.ts +7 -15
- package/dist/test-host.d.ts.map +1 -1
- package/dist/test-host.js +29 -239
- package/package.json +4 -4
- package/src/check.ts +7 -12
- package/src/conformance.ts +64 -28
- package/src/server.ts +10 -13
- package/src/test-host.ts +26 -53
package/src/test-host.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { effectiveGrants, type ApprovedGrants, type CapabilityId, type GrantConfig } from '@egen-civitas/esm-embed-protocol';
|
|
2
2
|
import type { ConnectOptions } from '@egen-civitas/esm-embed-client';
|
|
3
|
-
import { createBus, HostConnection, type
|
|
3
|
+
import { createBus, HostConnection, type ExtensionInfo, type HostProviders } from '@egen-civitas/esm-embed-host';
|
|
4
4
|
|
|
5
5
|
export interface TestHostOptions {
|
|
6
6
|
moduleName?: string;
|
|
@@ -10,15 +10,12 @@ export interface TestHostOptions {
|
|
|
10
10
|
manifestCapabilities?: Partial<Record<CapabilityId, GrantConfig>>;
|
|
11
11
|
/** Plafond fixé par l'opérateur (défaut : rien d'approuvé hors capacités « par défaut »). */
|
|
12
12
|
approved?: ApprovedGrants;
|
|
13
|
-
session?: Record<string, unknown>;
|
|
14
13
|
tenant?: { id: string | null };
|
|
15
14
|
locale?: string;
|
|
16
|
-
theme?: ThemeState;
|
|
17
15
|
config?: Record<string, unknown>;
|
|
18
16
|
flags?: Record<string, boolean>;
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
api?: (req: ApiRequest) => ApiResponse | Promise<ApiResponse>;
|
|
17
|
+
/** Extensions attachées à chaque slot (`{ 'topbar-nav-slot': [...] }`). */
|
|
18
|
+
extensions?: Record<string, ExtensionInfo[]>;
|
|
22
19
|
confirm?: boolean | ((d: { title: string; message: string; danger?: boolean }) => boolean);
|
|
23
20
|
}
|
|
24
21
|
|
|
@@ -34,22 +31,18 @@ export interface TestHost {
|
|
|
34
31
|
connection: HostConnection;
|
|
35
32
|
/** Journal des services du Core sollicités par l'app. */
|
|
36
33
|
calls: CallRecord[];
|
|
37
|
-
notifications: Array<{ kind: string; title: string; subtitle?: string }>;
|
|
34
|
+
notifications: Array<{ id?: string; kind: string; title: string; subtitle?: string }>;
|
|
38
35
|
published: Array<{ topic: string; payload: unknown; from: string }>;
|
|
39
|
-
tools: Map<string, { description: string }>;
|
|
40
36
|
/** Pousse un changement vers l'app (comme le ferait le Core). */
|
|
41
37
|
emit: {
|
|
42
|
-
session(v: Record<string, unknown>): void;
|
|
43
38
|
tenant(v: { id: string | null }): void;
|
|
44
39
|
locale(v: string): void;
|
|
45
|
-
|
|
40
|
+
extensions(slot: string, list: ExtensionInfo[]): void;
|
|
46
41
|
config(v: Record<string, unknown>): void;
|
|
47
42
|
event(topic: string, payload?: unknown): void;
|
|
48
43
|
goto(path: string): void;
|
|
49
44
|
visibility(visible: boolean): void;
|
|
50
45
|
};
|
|
51
|
-
/** L'agent IA appelle un outil déclaré par l'app. */
|
|
52
|
-
invokeTool(name: string, args?: Record<string, unknown>): Promise<unknown>;
|
|
53
46
|
destroy(): void;
|
|
54
47
|
}
|
|
55
48
|
|
|
@@ -71,8 +64,8 @@ function watchable<T>(initial: T) {
|
|
|
71
64
|
* relié à votre app par de fausses fenêtres et un vrai `MessageChannel`. Aucun navigateur, aucun Core.
|
|
72
65
|
*
|
|
73
66
|
* ```ts
|
|
74
|
-
* const sim = createTestHost({
|
|
75
|
-
* const egen = await connectToEgen({ ...sim.connectOptions, capabilities: ['
|
|
67
|
+
* const sim = createTestHost({ locale: 'fr', tenant: { id: 'acme' } });
|
|
68
|
+
* const egen = await connectToEgen({ ...sim.connectOptions, capabilities: ['locale', 'tenant'] });
|
|
76
69
|
* ```
|
|
77
70
|
*/
|
|
78
71
|
export function createTestHost(o: TestHostOptions = {}): TestHost {
|
|
@@ -81,14 +74,12 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
|
|
|
81
74
|
const calls: CallRecord[] = [];
|
|
82
75
|
const notifications: TestHost['notifications'] = [];
|
|
83
76
|
const published: TestHost['published'] = [];
|
|
84
|
-
const tools = new Map<string, { description: string }>();
|
|
85
|
-
const toolInvokers = new Map<string, (name: string, args: Record<string, unknown>) => Promise<unknown>>();
|
|
86
77
|
const log = (cap: string, method: string, ...args: unknown[]) => void calls.push({ cap, method, args });
|
|
87
78
|
|
|
88
|
-
const session = watchable<Record<string, unknown> | undefined>(o.session ?? { authenticated: true });
|
|
89
79
|
const tenant = watchable(o.tenant ?? { id: null });
|
|
90
80
|
const locale = watchable(o.locale ?? 'fr');
|
|
91
|
-
const
|
|
81
|
+
const extList = new Map<string, ExtensionInfo[]>(Object.entries(o.extensions ?? {}));
|
|
82
|
+
const extSubs = new Map<string, Set<(l: ExtensionInfo[]) => void>>();
|
|
92
83
|
const config = watchable(o.config ?? {});
|
|
93
84
|
const flagSubs = new Set<() => void>();
|
|
94
85
|
const eventSubs = new Map<string, Set<(p: unknown) => void>>();
|
|
@@ -103,10 +94,8 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
|
|
|
103
94
|
});
|
|
104
95
|
|
|
105
96
|
const providers: HostProviders = {
|
|
106
|
-
session: wrapWatch('session', session),
|
|
107
97
|
tenant: wrapWatch('tenant', tenant),
|
|
108
98
|
locale: wrapWatch('locale', locale),
|
|
109
|
-
theme: wrapWatch('theme', theme),
|
|
110
99
|
config: wrapWatch('config', config),
|
|
111
100
|
flags: {
|
|
112
101
|
isEnabled: (n) => {
|
|
@@ -115,10 +104,16 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
|
|
|
115
104
|
},
|
|
116
105
|
subscribe: (cb) => (flagSubs.add(cb), () => void flagSubs.delete(cb)),
|
|
117
106
|
},
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
log('
|
|
121
|
-
return
|
|
107
|
+
extensions: {
|
|
108
|
+
list: (slot) => {
|
|
109
|
+
log('extensions', 'list', slot);
|
|
110
|
+
return extList.get(slot) ?? [];
|
|
111
|
+
},
|
|
112
|
+
subscribe: (slot, cb) => {
|
|
113
|
+
let set = extSubs.get(slot);
|
|
114
|
+
if (!set) extSubs.set(slot, (set = new Set()));
|
|
115
|
+
set.add(cb);
|
|
116
|
+
return () => void set!.delete(cb);
|
|
122
117
|
},
|
|
123
118
|
},
|
|
124
119
|
events: {
|
|
@@ -136,7 +131,10 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
|
|
|
136
131
|
notifications: {
|
|
137
132
|
show: (n) => {
|
|
138
133
|
log('notifications', 'show', n);
|
|
134
|
+
// même dédoublonnage que le Core : un `id` déjà affiché n'est pas réaffiché
|
|
135
|
+
if (n.id && notifications.some((x) => x.id === n.id)) return false;
|
|
139
136
|
notifications.push(n);
|
|
137
|
+
return true;
|
|
140
138
|
},
|
|
141
139
|
},
|
|
142
140
|
dialogs: {
|
|
@@ -145,28 +143,7 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
|
|
|
145
143
|
return typeof o.confirm === 'function' ? o.confirm(d) : (o.confirm ?? true);
|
|
146
144
|
},
|
|
147
145
|
},
|
|
148
|
-
api: {
|
|
149
|
-
fetch: async (req) => {
|
|
150
|
-
log('api', 'fetch', req);
|
|
151
|
-
return o.api ? o.api(req) : { status: 200, headers: { 'content-type': 'application/json' }, body: '{}' };
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
146
|
telemetry: { log: (l, m, c) => log('telemetry', 'log', l, m, c), metric: (n, v, t) => log('telemetry', 'metric', n, v, t) },
|
|
155
|
-
aiTools: {
|
|
156
|
-
register: (_m, list, invoke) => {
|
|
157
|
-
log('ai-tools', 'register', list.map((t) => t.name));
|
|
158
|
-
for (const t of list) {
|
|
159
|
-
tools.set(t.name, { description: t.description });
|
|
160
|
-
toolInvokers.set(t.name, invoke);
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
unregister: (_m, names) => {
|
|
164
|
-
for (const n of names) {
|
|
165
|
-
tools.delete(n);
|
|
166
|
-
toolInvokers.delete(n);
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
147
|
};
|
|
171
148
|
|
|
172
149
|
const appWindow = new EventTarget();
|
|
@@ -202,22 +179,18 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
|
|
|
202
179
|
calls,
|
|
203
180
|
notifications,
|
|
204
181
|
published,
|
|
205
|
-
tools,
|
|
206
182
|
emit: {
|
|
207
|
-
session: (v) => session.set(v),
|
|
208
183
|
tenant: (v) => tenant.set(v),
|
|
209
184
|
locale: (v) => locale.set(v),
|
|
210
|
-
|
|
185
|
+
extensions: (slot, list) => {
|
|
186
|
+
extList.set(slot, list);
|
|
187
|
+
extSubs.get(slot)?.forEach((cb) => cb(list));
|
|
188
|
+
},
|
|
211
189
|
config: (v) => config.set(v),
|
|
212
190
|
event: (topic, payload) => eventSubs.get(topic)?.forEach((cb) => cb(payload)),
|
|
213
191
|
goto: (path) => channel.emit('goto', { path, seq: Date.now() }),
|
|
214
192
|
visibility: (v) => channel.emit('visibility', v),
|
|
215
193
|
},
|
|
216
|
-
invokeTool: async (name, args = {}) => {
|
|
217
|
-
const inv = toolInvokers.get(name);
|
|
218
|
-
if (!inv) throw new Error(`Outil non enregistré : ${name}`);
|
|
219
|
-
return inv(name, args);
|
|
220
|
-
},
|
|
221
194
|
destroy: () => connection.destroy(),
|
|
222
195
|
};
|
|
223
196
|
}
|