Repository navigation
Expand file tree
/
Copy pathassemble-execution-context.test.ts
More file actions
591 lines (548 loc) · 23.2 KB
/
Copy pathassemble-execution-context.test.ts
File metadata and controls
591 lines (548 loc) · 23.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
//
// Commit f586f1a89 — the ExecutionContext assembly converges onto ONE module, and the
// maintainer ruling of 2026-08-08 (Option A) is explicit that **neither surface
// changes runtime behaviour**: what changes is that the anonymous divergence
// becomes named API instead of drift.
//
// A green suite proves nothing about that on its own — the suite was green
// before the change too. So the load-bearing test here is a PARITY PIN: the
// assembly of each face before commit f586f1a89 is transcribed VERBATIM below, frozen, and
// every shape either face can serve is assembled both ways and compared.
//
// ⚠ The two `legacy*` functions are FROZEN TRANSCRIPTIONS of code that no
// longer exists (runtime `resolve-execution-context.ts` and REST
// `rest-server.ts` `computeExecCtx`, at `origin/main@0caf122f0`). They are a
// pin, NOT a second live implementation: nothing imports them, and they must
// never be "kept up to date" with the shared assembler — the day they need
// editing is the day a face's output changed and the change must be argued on
// its own merits, not absorbed here.
import { describe, it, expect } from 'vitest';
import { ExecutionContextSchema } from '@objectstack/spec/kernel';
import {
assembleExecutionContext,
assembleExecutionContextOrGuest,
ENTRY_EXECUTION_CONTEXT_FIELDS,
type EntryLocalization,
type OAuthTokenProvenance,
} from './assemble-execution-context.js';
import type { ResolvedAuthzContext } from './resolve-authz-context.js';
// ───────────────────────── frozen transcriptions from before commit f586f1a89 ─────────────────────────
/** Runtime / MCP dispatcher assembly, verbatim, before commit f586f1a89. FROZEN — see header. */
function legacyDispatcherAssembly(
authz: ResolvedAuthzContext,
oauthPrincipal: OAuthTokenProvenance | undefined,
localization: EntryLocalization | undefined,
requestLocale: string | undefined,
): any {
const ctx: any = {
positions: authz.positions,
permissions: authz.permissions,
systemPermissions: authz.systemPermissions,
isSystem: false,
};
if (authz.userId) {
if (oauthPrincipal?.clientId) {
ctx.principalKind = 'agent';
ctx.onBehalfOf = { userId: authz.userId, principalKind: 'human' };
// Before commit f586f1a89 these two read `scopesToAgentPermissionSets(oauthPrincipal.scopes)`
// and `oauthPrincipal.scopes?.includes(MCP_OAUTH_SCOPE_ACTIONS)` inline.
// Both are now interpreted at the `/mcp` door and arrive pre-derived; the
// scope→ceiling mapping itself is pinned end-to-end through the real
// resolver in `packages/runtime/src/security/resolve-execution-context.test.ts`
// ("ADR-0090 D10 agent principal"). What THIS pin freezes is unchanged:
// which envelope fields the ceiling replaces.
ctx.permissions = oauthPrincipal.scopePermissions;
ctx.positions = [];
ctx.systemPermissions = oauthPrincipal.delegatesActions
? (authz.systemPermissions ?? [])
: [];
} else {
ctx.principalKind = 'human';
}
} else {
ctx.principalKind = 'guest';
ctx.positions = ['guest'];
}
if (authz.userId) ctx.userId = authz.userId;
if (authz.tenantId) ctx.tenantId = authz.tenantId;
if (authz.email) ctx.email = authz.email;
if (authz.accessToken) ctx.accessToken = authz.accessToken;
if (authz.tabPermissions) ctx.tabPermissions = authz.tabPermissions;
if (authz.posture) ctx.posture = authz.posture;
ctx.org_user_ids = authz.org_user_ids;
ctx.accessible_org_ids = authz.accessible_org_ids;
if (oauthPrincipal && ctx.userId === oauthPrincipal.userId) {
ctx.oauthScopes = oauthPrincipal.scopes;
}
if (authz.userId) {
ctx.timezone = localization?.timezone;
ctx.locale = requestLocale ?? localization?.locale;
if (localization?.currency) ctx.currency = localization.currency;
}
return ctx;
}
/**
* REST `computeExecCtx` assembly, verbatim, before commit f586f1a89. FROZEN — see header.
* `authGate` / `__kernel` are outside: at the time this was frozen neither was
* an `ExecutionContext` field, and the REST face added both after assembly.
*
* `authGate` has since been DECLARED and joined the closed entry set (#7280),
* so the parity probes below pass `authGate: undefined` — the value that keeps
* them comparable with this frozen transcription. The gate's own carriage is
* pinned separately (see "#7280 — the ADR-0069 gate is an ENTRY-decided field").
*/
function legacyRestAssembly(
authz: ResolvedAuthzContext,
localization: EntryLocalization,
requestLocale: string | undefined,
): any {
if (!authz.userId) return undefined; // anonymous → no ctx → 401
const effectiveLocale = requestLocale ?? localization.locale;
return {
userId: authz.userId,
tenantId: authz.tenantId,
email: authz.email,
positions: authz.positions,
permissions: authz.permissions,
systemPermissions: authz.systemPermissions,
...(authz.tabPermissions ? { tabPermissions: authz.tabPermissions } : {}),
...(authz.posture ? { posture: authz.posture } : {}),
principalKind: 'human',
isSystem: false,
org_user_ids: authz.org_user_ids,
accessible_org_ids: authz.accessible_org_ids,
...(localization.timezone ? { timezone: localization.timezone } : {}),
...(effectiveLocale ? { locale: effectiveLocale } : {}),
...(localization.currency ? { currency: localization.currency } : {}),
};
}
// ───────────────────────── comparison + fixtures ─────────────────────────
/**
* What a CONSUMER of the envelope can observe: every key carrying a defined
* value, and that value. Key insertion order and keys explicitly set to
* `undefined` are invisible to `ctx.x` reads, to `JSON.stringify`, and to
* object spread of the result — the shared assembler emits in its own declared
* order and omits undefined-valued keys, which is exactly the delta this helper
* normalizes away. The undefined-key residual is asserted separately below so
* it is measured, not waved off.
*/
function observable(ctx: any): Record<string, unknown> {
return Object.fromEntries(Object.entries(ctx).filter(([, v]) => v !== undefined));
}
const baseAuthz = (over: Partial<ResolvedAuthzContext> = {}): ResolvedAuthzContext => ({
positions: [],
permissions: [],
systemPermissions: [],
org_user_ids: [],
accessible_org_ids: [],
...over,
});
const ANONYMOUS = baseAuthz();
const HUMAN_MINIMAL = baseAuthz({
userId: 'u1',
positions: ['member_default'],
permissions: ['task.read'],
systemPermissions: [],
org_user_ids: ['u1', 'u2'],
accessible_org_ids: ['org1'],
});
const HUMAN_FULL = baseAuthz({
userId: 'u1',
tenantId: 'org1',
email: 'u1@example.com',
accessToken: 'sess_token_abc',
positions: ['member_default', 'sales'],
permissions: ['task.read', 'task.write'],
systemPermissions: ['admin_full_access'],
tabPermissions: { task: 'visible' },
posture: 'PLATFORM_ADMIN',
org_user_ids: ['u1', 'u2'],
accessible_org_ids: ['org1', 'org2'],
});
const LOCALIZATIONS: Array<[string, EntryLocalization | undefined]> = [
['no localization', undefined],
['empty localization', {}],
['timezone only', { timezone: 'Asia/Shanghai' }],
['full localization', { timezone: 'Asia/Shanghai', locale: 'zh-CN', currency: 'CNY' }],
];
const REQUEST_LOCALES: Array<[string, string | undefined]> = [
['no request locale', undefined],
['request locale wins', 'en-US'],
];
// ───────────────────────── the parity pins ─────────────────────────
describe('#6216 — runtime/dispatcher face: byte-for-byte parity with the pre-#6216 assembly', () => {
const AUTHZ_SHAPES: Array<[string, ResolvedAuthzContext]> = [
['anonymous', ANONYMOUS],
['minimal human', HUMAN_MINIMAL],
['full human (tenant/email/token/tabs/posture)', HUMAN_FULL],
];
const OAUTH_SHAPES: Array<[string, OAuthTokenProvenance | undefined]> = [
['no oauth', undefined],
['agent, read-only ceiling', {
userId: 'u1', scopes: ['data:read'], clientId: 'cli1',
scopePermissions: ['agent_data_read'], delegatesActions: false,
}],
['agent, read+write ceiling', {
userId: 'u1', scopes: ['data:write'], clientId: 'cli1',
scopePermissions: ['agent_data_read', 'agent_data_write'], delegatesActions: false,
}],
['agent delegating actions', {
userId: 'u1', scopes: ['data:read', 'actions:execute'], clientId: 'cli1',
scopePermissions: ['agent_data_read'], delegatesActions: true,
}],
['agent with an EMPTY ceiling (no data scope)', {
userId: 'u1', scopes: ['actions:execute'], clientId: 'cli1',
scopePermissions: [], delegatesActions: true,
}],
['bearer WITHOUT a client (azp) — still human', {
userId: 'u1', scopes: ['data:read'],
scopePermissions: ['agent_data_read'], delegatesActions: false,
}],
['bearer for a DIFFERENT user — scopes withheld', {
userId: 'other', scopes: ['data:read'],
scopePermissions: ['agent_data_read'], delegatesActions: false,
}],
];
for (const [authzName, authz] of AUTHZ_SHAPES) {
for (const [oauthName, oauth] of OAUTH_SHAPES) {
for (const [locName, localization] of LOCALIZATIONS) {
for (const [rlName, requestLocale] of REQUEST_LOCALES) {
it(`${authzName} · ${oauthName} · ${locName} · ${rlName}`, () => {
const now = assembleExecutionContextOrGuest({
authz,
oauth,
localization,
requestLocale,
accessToken: authz.accessToken,
authGate: undefined,
});
const before = legacyDispatcherAssembly(authz, oauth, localization, requestLocale);
// [#17022] The ONE argued delta from the frozen transcription, and
// it is SUBTRACTED here rather than absorbed into the transcription
// itself — the header's rule is that a legacy function is never
// "kept up to date", because the day it needs editing is the day a
// face's output changed and the change owes its own argument.
// Here that argument is ADR-0090 D10 rule 4: the agent face now
// carries the identity of the client that performed the write, and
// no other face carries anything new.
//
// Subtraction alone would be a hole big enough to hide the next
// drift in, so the key is asserted POSITIVELY on the very next
// line: present exactly on the agent branch — an authenticated
// principal whose token names a client — absent everywhere else,
// and carrying that client's id. The parity pin below is otherwise
// unweakened: every other key still compares byte-for-byte.
const { performedBy, ...restOfNow } = observable(now);
expect(restOfNow).toEqual(observable(before));
expect(performedBy).toEqual(
authz.userId && oauth?.clientId ? { clientId: oauth.clientId } : undefined,
);
});
}
}
}
}
});
describe('#6216 — REST face: byte-for-byte parity with the pre-#6216 assembly', () => {
const AUTHZ_SHAPES: Array<[string, ResolvedAuthzContext]> = [
['anonymous', ANONYMOUS],
['minimal human', HUMAN_MINIMAL],
['full human (tenant/email/token/tabs/posture)', HUMAN_FULL],
];
for (const [authzName, authz] of AUTHZ_SHAPES) {
for (const [locName, localization] of LOCALIZATIONS) {
for (const [rlName, requestLocale] of REQUEST_LOCALES) {
it(`${authzName} · ${locName} · ${rlName}`, () => {
const now = assembleExecutionContext({
authz,
oauth: undefined,
localization,
requestLocale,
// The named per-face divergence: REST has never carried the
// session bearer, and commit f586f1a89 preserves that.
accessToken: undefined,
authGate: undefined,
});
const before = legacyRestAssembly(authz, localization ?? {}, requestLocale);
if (before === undefined) {
expect(now).toBeUndefined();
return;
}
expect(now).toBeDefined();
expect(observable(now)).toEqual(observable(before));
});
}
}
}
});
describe('#6216 — the anonymous face, in BOTH directions', () => {
it('the DEFAULT entry is fail-closed: no principal → no context (the surface answers 401)', () => {
expect(
assembleExecutionContext({
authz: ANONYMOUS,
oauth: undefined,
localization: { timezone: 'Asia/Shanghai', locale: 'zh-CN', currency: 'CNY' },
requestLocale: 'en-US',
accessToken: 'sess_token_abc',
authGate: undefined,
}),
).toBeUndefined();
});
it('the GUEST entry produces the dispatcher guest envelope, unchanged', () => {
const ctx = assembleExecutionContextOrGuest({
authz: ANONYMOUS,
oauth: undefined,
localization: undefined,
requestLocale: undefined,
accessToken: undefined,
authGate: undefined,
});
// The exact envelope, key set included — `explain-engine.ts` reads
// `principalKind === 'guest'` for its EXTERNAL posture floor, and the
// `guest` position is the declared vocabulary for what anonymous may do.
expect(ctx).toEqual({
positions: ['guest'],
permissions: [],
systemPermissions: [],
isSystem: false,
principalKind: 'guest',
org_user_ids: [],
accessible_org_ids: [],
});
expect(Object.keys(ctx)).not.toContain('userId');
expect(Object.keys(ctx)).not.toContain('posture');
});
it('an authenticated request is unaffected by WHICH entry the face chose', () => {
const input = {
authz: HUMAN_FULL,
oauth: undefined,
localization: { timezone: 'Asia/Shanghai', locale: 'zh-CN' },
requestLocale: undefined,
accessToken: HUMAN_FULL.accessToken,
authGate: undefined,
} as const;
expect(assembleExecutionContextOrGuest(input)).toEqual(assembleExecutionContext(input));
});
});
describe('#6216 — the named per-face divergences are values, not switches', () => {
it('a face that withholds the session bearer emits NO accessToken key', () => {
const ctx = assembleExecutionContext({
authz: HUMAN_FULL,
oauth: undefined,
localization: undefined,
requestLocale: undefined,
accessToken: undefined,
authGate: undefined,
})!;
expect(Object.keys(ctx)).not.toContain('accessToken');
});
it('a face that carries it emits the bearer verbatim', () => {
const ctx = assembleExecutionContext({
authz: HUMAN_FULL,
oauth: undefined,
localization: undefined,
requestLocale: undefined,
accessToken: HUMAN_FULL.accessToken,
authGate: undefined,
})!;
expect(ctx.accessToken).toBe('sess_token_abc');
});
it('a face that accepts no OAuth token cannot produce an agent principal', () => {
const ctx = assembleExecutionContext({
authz: HUMAN_FULL,
oauth: undefined,
localization: undefined,
requestLocale: undefined,
accessToken: undefined,
authGate: undefined,
})!;
expect(ctx.principalKind).toBe('human');
expect(Object.keys(ctx)).not.toContain('onBehalfOf');
expect(Object.keys(ctx)).not.toContain('oauthScopes');
});
});
describe('#7280 — the ADR-0069 gate is an ENTRY-decided field', () => {
const GATE = { code: 'PASSWORD_EXPIRED' as const, message: 'Your password has expired.' };
it('a face that resolves a gate carries it on the envelope verbatim', () => {
const ctx = assembleExecutionContext({
authz: HUMAN_FULL,
oauth: undefined,
localization: undefined,
requestLocale: undefined,
accessToken: undefined,
authGate: GATE,
})!;
expect(ctx.authGate).toEqual(GATE);
});
it('a face that resolves none emits NO authGate key — not a key spelled undefined', () => {
const ctx = assembleExecutionContext({
authz: HUMAN_FULL,
oauth: undefined,
localization: undefined,
requestLocale: undefined,
accessToken: undefined,
authGate: undefined,
})!;
// Behaviour preserved: the pre-#7280 REST face spread
// `...(authGate ? { authGate } : {})` AFTER assembly, so the key was absent
// for exactly these inputs too. Only the declaration moved.
expect(Object.keys(ctx)).not.toContain('authGate');
expect('authGate' in ctx).toBe(false);
});
it('a GUEST principal never carries a gate, even when a face passes one', () => {
const ctx = assembleExecutionContextOrGuest({
authz: ANONYMOUS,
oauth: undefined,
localization: undefined,
requestLocale: undefined,
accessToken: undefined,
authGate: GATE,
});
// An anonymous request has no authenticated session for an
// authentication-policy gate to attach to, so "gated guest" is not a state
// this entry can emit.
expect(ctx.principalKind).toBe('guest');
expect(Object.keys(ctx)).not.toContain('authGate');
});
it('the gate rides the SAME closed set as every other entry field', () => {
expect(ENTRY_EXECUTION_CONTEXT_FIELDS).toContain('authGate');
});
});
describe('#6216 — the field set is CLOSED', () => {
/**
* The non-entry partition, spelled again here on purpose: the module's
* `NonEntryExecutionContextField` is a type and cannot be read at runtime, so
* this list is the runtime mirror of it. A new `ExecutionContext` field makes
* this test red until it is added to ONE of the two lists — the same decision
* the compiler demands of `ExecutionContextEntryFields`, enforced a second
* way in case someone reaches for `as any` to get past the first.
*/
const NON_ENTRY_FIELDS = [
'actor',
'attributedUserId',
'rlsMembership',
'transaction',
'traceId',
'flowRunId',
'skipTriggers',
'skipAutomations',
'seedReplay',
'skipStateMachine',
'preserveAudit',
'keptOptionValues',
];
it('every ExecutionContext field is either assembled at the entry or declared non-entry', () => {
const schemaFields = Object.keys((ExecutionContextSchema as any).shape).sort();
const decided = [...ENTRY_EXECUTION_CONTEXT_FIELDS, ...NON_ENTRY_FIELDS].sort();
expect(decided).toEqual(schemaFields);
});
it('no field is decided twice', () => {
const decided = [...ENTRY_EXECUTION_CONTEXT_FIELDS, ...NON_ENTRY_FIELDS];
expect(new Set(decided).size).toBe(decided.length);
});
it('every assembled key belongs to the closed set — nothing leaks in', () => {
const ctx = assembleExecutionContextOrGuest({
authz: HUMAN_FULL,
oauth: {
userId: 'u1', scopes: ['data:write', 'actions:execute'], clientId: 'cli1',
scopePermissions: ['agent_data_read', 'agent_data_write'], delegatesActions: true,
},
localization: { timezone: 'Asia/Shanghai', locale: 'zh-CN', currency: 'CNY' },
requestLocale: 'en-US',
accessToken: 'sess_token_abc',
authGate: undefined,
});
for (const key of Object.keys(ctx)) {
expect(ENTRY_EXECUTION_CONTEXT_FIELDS).toContain(key);
}
});
});
describe('#6216 — the measured residual: keys that were present-with-undefined', () => {
// Reported rather than hidden. The dispatcher before commit f586f1a89 assigned
// `ctx.timezone` / `ctx.locale` unconditionally inside its authenticated
// branch, and the REST literal always spelled `tenantId` / `email` — so both
// faces could emit a key whose value was `undefined`. The shared assembler
// omits those keys instead. This is invisible to `ctx.x` reads, to
// `JSON.stringify`, and to spreading the envelope; it is visible to
// `Object.keys` / `in`, so it is pinned here rather than left to be
// rediscovered.
it('dispatcher: an authenticated request with no localization no longer spells timezone/locale as undefined', () => {
const input = {
authz: HUMAN_MINIMAL,
oauth: undefined,
localization: undefined,
requestLocale: undefined,
accessToken: undefined,
authGate: undefined,
} as const;
const before = legacyDispatcherAssembly(HUMAN_MINIMAL, undefined, undefined, undefined);
const now = assembleExecutionContextOrGuest(input);
expect(Object.keys(before)).toContain('timezone');
expect(before.timezone).toBeUndefined();
expect(Object.keys(now)).not.toContain('timezone');
expect((now as any).timezone).toBeUndefined();
// …and nothing observable moved.
expect(observable(now)).toEqual(observable(before));
expect(JSON.stringify(now)).toBe(JSON.stringify(observable(before)));
});
it('REST: a principal with no tenant no longer spells tenantId/email as undefined', () => {
const before = legacyRestAssembly(HUMAN_MINIMAL, {}, undefined);
const now = assembleExecutionContext({
authz: HUMAN_MINIMAL,
oauth: undefined,
localization: {},
requestLocale: undefined,
accessToken: undefined,
authGate: undefined,
})!;
expect(Object.keys(before)).toContain('tenantId');
expect(before.tenantId).toBeUndefined();
expect(Object.keys(now)).not.toContain('tenantId');
expect(observable(now)).toEqual(observable(before));
});
});
// [Ruling of record 6355206139, letter B] The population stamp is an ENTRY
// decision made once, by the resolver: an `external` member's envelope carries
// `audience: 'external'` on every face, its agent's envelope too (the OWD floor
// re-runs the on-behalf-of leg under that envelope), and an internal principal
// or a guest never carries it.
describe('ruling 6355206139 — the resolver’s audience stamp rides the envelope', () => {
const EXTERNAL_MEMBER = baseAuthz({
userId: 'u_ext',
tenantId: 'org1',
positions: ['org_external'],
permissions: ['external_default'],
posture: 'EXTERNAL',
audience: 'external',
accessible_org_ids: ['org1'],
});
const assemble = (authz: ResolvedAuthzContext, oauth?: OAuthTokenProvenance) =>
assembleExecutionContextOrGuest({
authz,
oauth,
localization: undefined,
requestLocale: undefined,
accessToken: undefined,
authGate: undefined,
});
it('an external member’s envelope carries audience external beside its EXTERNAL rung, and parses', () => {
const ctx = assemble(EXTERNAL_MEMBER);
expect(ctx.audience).toBe('external');
expect(ctx.posture).toBe('EXTERNAL');
expect(ExecutionContextSchema.safeParse(ctx).success).toBe(true);
});
it('an agent acting for an external member carries the human’s audience', () => {
const ctx = assemble(EXTERNAL_MEMBER, {
userId: 'u_ext', scopes: ['data:read'], clientId: 'cli1',
scopePermissions: ['agent_data_read'], delegatesActions: false,
} as OAuthTokenProvenance);
expect(ctx.principalKind).toBe('agent');
expect(ctx.audience).toBe('external');
});
it('CONTROL: an internal principal and a guest carry no audience', () => {
expect(Object.keys(assemble(HUMAN_FULL))).not.toContain('audience');
expect(Object.keys(assemble(ANONYMOUS))).not.toContain('audience');
expect(Object.keys(assemble({ ...ANONYMOUS, audience: 'external' }))).not.toContain('audience');
});
});