@xema/omni-protocol 0.1.129 → 0.1.131
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/GLOSSARY.md +2 -2
- package/README.md +6 -8
- package/dist/index.d.ts +145 -94
- package/dist/index.js +27 -12
- package/dist/testing.d.ts +18 -18
- package/dist/testing.js +89 -92
- package/dist/validation.d.ts +23 -23
- package/dist/validation.js +178 -125
- package/guide/agent.md +34 -34
- package/guide/breaks.md +1 -1
- package/guide/lead.md +34 -17
- package/guide/phone.md +22 -22
- package/guide/queue.md +7 -7
- package/guide/voice.md +64 -54
- package/guide.md +168 -148
- package/package.json +1 -1
package/dist/testing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { assertNoViolations, validateAuthenticationState, validateBreakTransition, validateEventEnvelope, validateHostGuarantees, validateHostReport, validateUserDetails, observeRules, ruleTested, validateHostMute, validateHostRecording,
|
|
1
|
+
import { browserProfileKey, sameCapabilities, } from "./index.js";
|
|
2
|
+
import { assertNoViolations, validateAuthenticationState, validateBreakTransition, validateEventEnvelope, validateHostGuarantees, validateHostReport, validateUserDetails, observeRules, ruleTested, validateHostMute, validateHostRecording, validateSessionStore, validateHistoryReport, validateManifest, validateResult, validateSnapshot, validateTask, validateLanguages, validateTimeZone, validatePhone, validateTaskCommand, isTimeZone, sameTimeZone, } from "./validation.js";
|
|
3
3
|
export { ProtocolConformanceError, assertNoViolations } from "./validation.js";
|
|
4
4
|
/**
|
|
5
5
|
* A part of the contract a run may never reach: state nothing obliges an adapter to publish, so
|
|
@@ -84,11 +84,8 @@ function observeTask(value, seen) {
|
|
|
84
84
|
const capabilities = isRecord(value.capabilities) ? value.capabilities : {};
|
|
85
85
|
if (isRecord(capabilities.outcomes))
|
|
86
86
|
seen.add("task.outcomes");
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (isRecord(declared) && some(declared.destinations))
|
|
90
|
-
seen.add("task.destinations");
|
|
91
|
-
}
|
|
87
|
+
if (isRecord(capabilities.addToCall) && typeof capabilities.addToCall.destinations === "string")
|
|
88
|
+
seen.add("task.destinations");
|
|
92
89
|
if (some(capabilities.custom))
|
|
93
90
|
seen.add("task.custom");
|
|
94
91
|
if (Object.values(capabilities).some(declared => isRecord(declared) && declared.lockedBy !== undefined))
|
|
@@ -215,7 +212,7 @@ function observeEvent(envelope, seen) {
|
|
|
215
212
|
* Adapter conformance exercise: validates the manifest, opens an authenticated session,
|
|
216
213
|
* connects, checks that every method the declarations require is implemented, subscribes,
|
|
217
214
|
* validates the snapshot, every delivered event, and every authentication state the session
|
|
218
|
-
* publishes during the run -- against the latest
|
|
215
|
+
* publishes during the run -- against the latest session, since capabilities are current, not
|
|
219
216
|
* fixed -- states a capacity, then unsubscribes and disconnects.
|
|
220
217
|
*
|
|
221
218
|
* Violations are collected rather than thrown from inside the adapter's own
|
|
@@ -249,7 +246,7 @@ export async function testAdapter(adapter, context, options = {}) {
|
|
|
249
246
|
let unsubscribeAuthentication;
|
|
250
247
|
let unsubscribeHost;
|
|
251
248
|
let authenticationState;
|
|
252
|
-
let
|
|
249
|
+
let signedIn;
|
|
253
250
|
let disconnectWasClean = false;
|
|
254
251
|
try {
|
|
255
252
|
authenticationState = await authentication.state();
|
|
@@ -258,18 +255,18 @@ export async function testAdapter(adapter, context, options = {}) {
|
|
|
258
255
|
if (authenticationState.status !== "authenticated") {
|
|
259
256
|
throw new Error(`Adapter contract exercise requires authenticated test state, received ${authenticationState.status}`);
|
|
260
257
|
}
|
|
261
|
-
// The harness knows who is signed in and what their
|
|
258
|
+
// The harness knows who is signed in and what their capabilities include, so it can hold the
|
|
262
259
|
// adapter to rules the structural validators cannot check alone: a team member list never carries the
|
|
263
260
|
// agent it is published to, a lead's snapshot always carries one, nobody else's ever does.
|
|
264
|
-
// Capabilities are current, not fixed, so the
|
|
261
|
+
// Capabilities are current, not fixed, so the session is read when something is validated,
|
|
265
262
|
// never captured at sign-in: a provider that withdraws one republishes `authenticated`, and
|
|
266
263
|
// everything published after that is held to the new set. A published state that fails
|
|
267
|
-
// validation is reported and not adopted -- the harness keeps the last
|
|
268
|
-
|
|
264
|
+
// validation is reported and not adopted -- the harness keeps the last session it could trust.
|
|
265
|
+
signedIn = authenticationState;
|
|
269
266
|
const current = () => {
|
|
270
|
-
if (
|
|
271
|
-
throw new Error("unreachable: the exercise has an authenticated
|
|
272
|
-
return
|
|
267
|
+
if (signedIn === undefined)
|
|
268
|
+
throw new Error("unreachable: the exercise has an authenticated session");
|
|
269
|
+
return signedIn;
|
|
273
270
|
};
|
|
274
271
|
// Off until the application has said otherwise: the provider assumes nothing of the team feature.
|
|
275
272
|
let leadFeaturesOn = false;
|
|
@@ -278,7 +275,7 @@ export async function testAdapter(adapter, context, options = {}) {
|
|
|
278
275
|
capabilities: current().capabilities,
|
|
279
276
|
leadFeatures: leadFeaturesOn,
|
|
280
277
|
phone: context.phone,
|
|
281
|
-
|
|
278
|
+
sessionId: context.sessionId,
|
|
282
279
|
autoAcceptTasks: context.autoAcceptTasks,
|
|
283
280
|
locked: options.lockedValues,
|
|
284
281
|
});
|
|
@@ -301,19 +298,19 @@ export async function testAdapter(adapter, context, options = {}) {
|
|
|
301
298
|
// The four stand or fall together: `granted` is a promise to honour a later commit, and
|
|
302
299
|
// an adapter with requestBreak but no commitBreak leaves an agent a break that never starts.
|
|
303
300
|
for (const method of ["requestBreak", "commitBreak", "cancelBreak", "endBreak"]) {
|
|
304
|
-
requireMethod(on, method, "the
|
|
301
|
+
requireMethod(on, method, "the user's capabilities include breaks");
|
|
305
302
|
}
|
|
306
303
|
}
|
|
307
|
-
if (capabilities.lead
|
|
308
|
-
requireMethod(on, "executeTeam", "the
|
|
304
|
+
if (capabilities.lead !== undefined)
|
|
305
|
+
requireMethod(on, "executeTeam", "the user's capabilities include lead");
|
|
309
306
|
if (capabilities.nextCall === true) {
|
|
310
307
|
// The ask, its withdrawal and the release stand together: a lined-up call the agent could neither withdraw nor let go is a promise with no way out.
|
|
311
308
|
for (const method of ["requestNextCall", "cancelNextCall", "releaseLinedUp"]) {
|
|
312
|
-
requireMethod(on, method, "the
|
|
309
|
+
requireMethod(on, method, "the user's capabilities include nextCall");
|
|
313
310
|
}
|
|
314
311
|
}
|
|
315
312
|
if (some(capabilities.preferences))
|
|
316
|
-
requireMethod(on, "setPreference", "the
|
|
313
|
+
requireMethod(on, "setPreference", "the user's capabilities include preferences");
|
|
317
314
|
};
|
|
318
315
|
const onAuthenticationState = (state) => {
|
|
319
316
|
const own = validateAuthenticationState(state, "authentication", { levels });
|
|
@@ -335,7 +332,7 @@ export async function testAdapter(adapter, context, options = {}) {
|
|
|
335
332
|
violations.push(...refreshingCarriesOver(current(), state, "authentication"));
|
|
336
333
|
}
|
|
337
334
|
else if (state.status === "authenticated") {
|
|
338
|
-
|
|
335
|
+
signedIn = state;
|
|
339
336
|
// A capability granted later requires its methods just as one declared at sign-in does.
|
|
340
337
|
if (connection !== undefined)
|
|
341
338
|
requireCapabilityMethods(connection, state.capabilities);
|
|
@@ -360,16 +357,16 @@ export async function testAdapter(adapter, context, options = {}) {
|
|
|
360
357
|
violations.push(...validateHostReport(first, "context.host"));
|
|
361
358
|
const hasAudio = isRecord(first) && first.audio !== undefined;
|
|
362
359
|
if (softphone && !hasAudio) {
|
|
363
|
-
violations.push({ rule: "context.host.audio.required", path: "context.host.audio", message: "a softphone
|
|
360
|
+
violations.push({ rule: "context.host.audio.required", path: "context.host.audio", message: "a softphone session's host reports its audio" });
|
|
364
361
|
}
|
|
365
362
|
if (!softphone && hasAudio) {
|
|
366
363
|
violations.push({ rule: "context.host.audio.unexpected", path: "context.host.audio",
|
|
367
|
-
message: adapter.manifest.channel === "voice" ? "a hardphone
|
|
364
|
+
message: adapter.manifest.channel === "voice" ? "a hardphone session has no audio in the host to report" : `a ${adapter.manifest.channel} connection has no audio for the host to report` });
|
|
368
365
|
}
|
|
369
366
|
// What the host's Mute does is stated where the host holds a microphone, and nowhere else.
|
|
370
367
|
violations.push(...validateHostMute(context.host.mute, softphone, "context.host.mute"));
|
|
371
|
-
// The
|
|
372
|
-
const storeShape =
|
|
368
|
+
// The session's store is the host's to provide: an adapter that composes a record keeps in it what its platform cannot.
|
|
369
|
+
const storeShape = validateSessionStore(context.store, "context.store");
|
|
373
370
|
violations.push(...storeShape);
|
|
374
371
|
// The harness watches the store it hands over, so what an adapter leaves behind is seen rather than asked for.
|
|
375
372
|
const watched = storeShape.length === 0 ? watchStore(context.store) : { store: context.store, held: new Set(), everHeld: new Set() };
|
|
@@ -412,11 +409,11 @@ export async function testAdapter(adapter, context, options = {}) {
|
|
|
412
409
|
requireMethod(on, "dial", "the manifest declares dial");
|
|
413
410
|
// On a softphone the call's audio lands in Omni, so the adapter has to open it; on a hardphone the host opens nothing.
|
|
414
411
|
if (softphone)
|
|
415
|
-
requireMethod(on, "openAudio", "the
|
|
412
|
+
requireMethod(on, "openAudio", "the session is on a softphone");
|
|
416
413
|
// The microphone is the host's, so on a softphone every call can be muted by it, and the
|
|
417
414
|
// record of that leg is the provider's to take; on a hardphone the host holds no microphone.
|
|
418
415
|
if (softphone)
|
|
419
|
-
requireMethod(on, "recordStep", "the
|
|
416
|
+
requireMethod(on, "recordStep", "the session is on a softphone, whose microphone the host mutes");
|
|
420
417
|
};
|
|
421
418
|
connectObligations(live);
|
|
422
419
|
const tellRefused = (report) => {
|
|
@@ -486,7 +483,7 @@ export async function testAdapter(adapter, context, options = {}) {
|
|
|
486
483
|
if (earlier !== undefined) {
|
|
487
484
|
if (earlier !== payload) {
|
|
488
485
|
violations.push({ rule: "event.id.reused", path: "event.id",
|
|
489
|
-
message: `envelope ${envelope.id} was delivered again with a different event: an id names one event for the life of the
|
|
486
|
+
message: `envelope ${envelope.id} was delivered again with a different event: an id names one event for the life of the session` });
|
|
490
487
|
}
|
|
491
488
|
return;
|
|
492
489
|
}
|
|
@@ -537,8 +534,8 @@ export async function testAdapter(adapter, context, options = {}) {
|
|
|
537
534
|
authentication = session;
|
|
538
535
|
connection = second;
|
|
539
536
|
live = second;
|
|
540
|
-
// The second client is held to everything the first was on connect: its methods, its
|
|
541
|
-
// methods, the
|
|
537
|
+
// The second client is held to everything the first was on connect: its methods, its session's
|
|
538
|
+
// methods, the session it publishes from here, and a capacity stated to it, since the first's
|
|
542
539
|
// statement died with the first and nothing may be assigned against a count nobody stated to it.
|
|
543
540
|
connectObligations(second);
|
|
544
541
|
requireCapabilityMethods(second, current().capabilities);
|
|
@@ -660,7 +657,7 @@ export async function testAdapter(adapter, context, options = {}) {
|
|
|
660
657
|
// reaches the lead, which the reader held the connect snapshot to. A reloaded client is a
|
|
661
658
|
// connect too: it is told again, after its capacity, and held the same way.
|
|
662
659
|
const switchOnLeadFeatures = async (on, at) => {
|
|
663
|
-
if (current().capabilities.lead
|
|
660
|
+
if (current().capabilities.lead === undefined || typeof on.executeTeam !== "function")
|
|
664
661
|
return;
|
|
665
662
|
const from = events.length;
|
|
666
663
|
let switched;
|
|
@@ -789,7 +786,7 @@ export async function testAdapter(adapter, context, options = {}) {
|
|
|
789
786
|
return {
|
|
790
787
|
events: events,
|
|
791
788
|
authenticationState: authenticationState,
|
|
792
|
-
|
|
789
|
+
signedIn: (signedIn ?? authenticationState),
|
|
793
790
|
notTested: CONTRACT_SUBJECTS.filter(subject => !seen.has(subject)),
|
|
794
791
|
disconnectWasClean,
|
|
795
792
|
violations,
|
|
@@ -887,23 +884,23 @@ function eventNamesUsers(envelope) {
|
|
|
887
884
|
}
|
|
888
885
|
}
|
|
889
886
|
/**
|
|
890
|
-
* `refreshing` carries the identity and capabilities of the
|
|
891
|
-
* either is published as `authenticated`; a different identity is a new
|
|
887
|
+
* `refreshing` carries the identity and capabilities of the session it refreshes. A change to
|
|
888
|
+
* either is published as `authenticated`; a different identity is a new session.
|
|
892
889
|
*/
|
|
893
|
-
function refreshingCarriesOver(
|
|
890
|
+
function refreshingCarriesOver(signedIn, state, path) {
|
|
894
891
|
const found = [];
|
|
895
|
-
if (state.identity.id !==
|
|
892
|
+
if (state.identity.id !== signedIn.identity.id) {
|
|
896
893
|
found.push({
|
|
897
894
|
rule: "authentication.refreshing.identity",
|
|
898
895
|
path: `${path}.identity.id`,
|
|
899
|
-
message: "refreshing carries the identity of the
|
|
896
|
+
message: "refreshing carries the identity of the session it refreshes; a different identity is a new session",
|
|
900
897
|
});
|
|
901
898
|
}
|
|
902
|
-
if (!sameCapabilities(state.capabilities,
|
|
899
|
+
if (!sameCapabilities(state.capabilities, signedIn.capabilities)) {
|
|
903
900
|
found.push({
|
|
904
901
|
rule: "authentication.refreshing.capabilities",
|
|
905
902
|
path: `${path}.capabilities`,
|
|
906
|
-
message: "refreshing carries the capabilities of the
|
|
903
|
+
message: "refreshing carries the capabilities of the session it refreshes; a change is published as authenticated",
|
|
907
904
|
});
|
|
908
905
|
}
|
|
909
906
|
return found;
|
|
@@ -958,10 +955,10 @@ function connectingReports(context, violations) {
|
|
|
958
955
|
settled: () => { settled = true; },
|
|
959
956
|
};
|
|
960
957
|
}
|
|
961
|
-
/** Validates each state of a published sequence, and that every `refreshing` carries over the
|
|
962
|
-
function
|
|
958
|
+
/** Validates each state of a published sequence, and that every `refreshing` carries over the session before it. */
|
|
959
|
+
function assertSignedInSequence(states, levels, summary) {
|
|
963
960
|
const found = [];
|
|
964
|
-
let
|
|
961
|
+
let signedIn;
|
|
965
962
|
states.forEach((state, index) => {
|
|
966
963
|
const path = `states[${index}]`;
|
|
967
964
|
const own = validateAuthenticationState(state, path, { levels });
|
|
@@ -969,18 +966,18 @@ function assertLoginSequence(states, levels, summary) {
|
|
|
969
966
|
if (own.length > 0)
|
|
970
967
|
return;
|
|
971
968
|
if (state.status === "authenticated")
|
|
972
|
-
|
|
973
|
-
else if (state.status === "refreshing" &&
|
|
974
|
-
found.push(...refreshingCarriesOver(
|
|
969
|
+
signedIn = state;
|
|
970
|
+
else if (state.status === "refreshing" && signedIn !== undefined)
|
|
971
|
+
found.push(...refreshingCarriesOver(signedIn, state, path));
|
|
975
972
|
});
|
|
976
973
|
assertNoViolations(found, summary);
|
|
977
974
|
}
|
|
978
975
|
/**
|
|
979
976
|
* Validates restored authentication followed by a refresh failure or expiry. Every state is
|
|
980
|
-
* validated against the manifest's levels, and a `refreshing` state must carry over the
|
|
977
|
+
* validated against the manifest's levels, and a `refreshing` state must carry over the session it refreshes.
|
|
981
978
|
*/
|
|
982
979
|
export function assertAuthenticationRestoreAndExpiry(states, manifest) {
|
|
983
|
-
|
|
980
|
+
assertSignedInSequence(states, declaredLevels(manifest), "Authentication scenario");
|
|
984
981
|
if (states.length < 2 || states[0]?.status !== "authenticated") {
|
|
985
982
|
throw new Error("Authentication scenario must start with a restored authenticated state");
|
|
986
983
|
}
|
|
@@ -1039,34 +1036,34 @@ function notYetReadTasks(tasks, path) {
|
|
|
1039
1036
|
* Capabilities are current, not fixed. A provider that withdraws one republishes `authenticated`
|
|
1040
1037
|
* with the new set, and the next snapshot agrees with it. `states` is what the authentication
|
|
1041
1038
|
* session published, first to last: beginning and ending `authenticated` for the same identity,
|
|
1042
|
-
* passing only through usable states (`expired`, `terminated` or `signed-out` ends the
|
|
1039
|
+
* passing only through usable states (`expired`, `terminated` or `signed-out` ends the session instead), with at
|
|
1043
1040
|
* least one capability gone by the end. `snapshot` is the first snapshot published after the last
|
|
1044
|
-
* state, validated against that
|
|
1041
|
+
* state, validated against that sign-in -- so a team member list still published to a session that no longer
|
|
1045
1042
|
* leads, or requests to one that may no longer join, is the failure.
|
|
1046
1043
|
*/
|
|
1047
1044
|
export function assertCapabilityWithdrawal(states, snapshot, manifest) {
|
|
1048
|
-
|
|
1045
|
+
assertSignedInSequence(states, declaredLevels(manifest), "Capability withdrawal");
|
|
1049
1046
|
const stray = states.findIndex(state => state.status !== "authenticated" && state.status !== "refreshing");
|
|
1050
1047
|
if (stray >= 0) {
|
|
1051
|
-
throw new Error(`Capability withdrawal passes only through usable states; states[${stray}] is ${states[stray]?.status}, which ends the
|
|
1048
|
+
throw new Error(`Capability withdrawal passes only through usable states; states[${stray}] is ${states[stray]?.status}, which ends the session`);
|
|
1052
1049
|
}
|
|
1053
1050
|
const first = states[0];
|
|
1054
1051
|
const last = states.at(-1);
|
|
1055
1052
|
if (first?.status !== "authenticated" || last?.status !== "authenticated") {
|
|
1056
|
-
throw new Error("Capability withdrawal must begin and end with an authenticated
|
|
1053
|
+
throw new Error("Capability withdrawal must begin and end with an authenticated session");
|
|
1057
1054
|
}
|
|
1058
1055
|
if (first.identity.id !== last.identity.id) {
|
|
1059
|
-
throw new Error("Capability withdrawal must keep the identity: a different identity is a new
|
|
1056
|
+
throw new Error("Capability withdrawal must keep the identity: a different identity is a new session");
|
|
1060
1057
|
}
|
|
1061
1058
|
const before = first.capabilities;
|
|
1062
1059
|
const after = last.capabilities;
|
|
1063
1060
|
const withdrawn = (before.breaks === true && after.breaks !== true) ||
|
|
1064
|
-
(before.lead
|
|
1061
|
+
Object.keys(before.lead ?? {}).some(name => after.lead?.[name] !== true) ||
|
|
1065
1062
|
(before.preferences ?? []).some(was => !(after.preferences ?? []).some(now => now.id === was.id));
|
|
1066
1063
|
if (!withdrawn) {
|
|
1067
|
-
throw new Error("Capability withdrawal must end with at least one capability the first
|
|
1064
|
+
throw new Error("Capability withdrawal must end with at least one capability the first session declared withdrawn");
|
|
1068
1065
|
}
|
|
1069
|
-
assertNoViolations(validateSnapshot(snapshot, manifest, "snapshot", { self: last.identity.id, capabilities: after }), "Capability withdrawal: the snapshot after the last
|
|
1066
|
+
assertNoViolations(validateSnapshot(snapshot, manifest, "snapshot", { self: last.identity.id, capabilities: after }), "Capability withdrawal: the snapshot after the last session must agree with it");
|
|
1070
1067
|
}
|
|
1071
1068
|
/**
|
|
1072
1069
|
* A command that arrives after its capability was withdrawn is answered `failed` with
|
|
@@ -1692,14 +1689,14 @@ async function testOneCall(call) {
|
|
|
1692
1689
|
try {
|
|
1693
1690
|
const restoredSession = await again.createAuthenticationSession({ ...call.context, secrets: call.secrets });
|
|
1694
1691
|
// The reload is a restore before it is anything else: the second session stands authenticated
|
|
1695
|
-
// as the same person, from the secrets alone, or nothing it reads afterwards is this
|
|
1692
|
+
// as the same person, from the secrets alone, or nothing it reads afterwards is this session's.
|
|
1696
1693
|
const restored = await restoredSession.state();
|
|
1697
|
-
found.push(...validateAuthenticationState(restored, "test.reload.
|
|
1698
|
-
ruleTested("test.reload.
|
|
1694
|
+
found.push(...validateAuthenticationState(restored, "test.reload.session", { levels: declaredLevels(call.manifest) }));
|
|
1695
|
+
ruleTested("test.reload.session");
|
|
1699
1696
|
const same = isRecord(restored) && restored.status === "authenticated" && isRecord(restored.identity) && restored.identity.id === call.reader().self;
|
|
1700
1697
|
if (!same) {
|
|
1701
|
-
refuse("test.reload.
|
|
1702
|
-
// A reload that cannot restore the
|
|
1698
|
+
refuse("test.reload.session", "test.reload.session", `a second adapter built from the same session and secrets did not restore it: the authentication session says ${String(isRecord(restored) ? restored.status : restored)}${isRecord(restored) && isRecord(restored.identity) ? ` as ${String(restored.identity.id)}` : ""}, and the session is ${String(call.reader().self)}`);
|
|
1699
|
+
// A reload that cannot restore the session is a sign-in screen, not a connection: the run ends here.
|
|
1703
1700
|
try {
|
|
1704
1701
|
await restoredSession.close();
|
|
1705
1702
|
}
|
|
@@ -1730,7 +1727,7 @@ async function testOneCall(call) {
|
|
|
1730
1727
|
? snapshot.tasks.find(task => isRecord(task) && task.assignmentId === taskId) : undefined;
|
|
1731
1728
|
ruleTested("test.reload.snapshot");
|
|
1732
1729
|
if (carried === undefined) {
|
|
1733
|
-
refuse("test.reload.snapshot", "test.reload.snapshot", `a second adapter built from the same
|
|
1730
|
+
refuse("test.reload.snapshot", "test.reload.snapshot", `a second adapter built from the same session does not carry ${taskId} on its snapshot, and the task is still open`);
|
|
1734
1731
|
return;
|
|
1735
1732
|
}
|
|
1736
1733
|
ruleTested("test.reload.history");
|
|
@@ -1742,11 +1739,11 @@ async function testOneCall(call) {
|
|
|
1742
1739
|
const lost = wasRead.filter(entry => !steps.some(now => isRecord(now) && now.step === entry.step && now.at === entry.at))
|
|
1743
1740
|
.map(entry => `${String(entry.step)}@${String(entry.at)}`);
|
|
1744
1741
|
if (lost.length > 0) {
|
|
1745
|
-
refuse("test.reload.history", "test.reload.history", `a second adapter built from the same
|
|
1742
|
+
refuse("test.reload.history", "test.reload.history", `a second adapter built from the same session carries ${taskId} without ${lost.join(", ")}, which the first had published: a record once read is not unread`);
|
|
1746
1743
|
}
|
|
1747
1744
|
const leg = steps.find(entry => isRecord(entry) && entry.step === "muted" && entry.at === at);
|
|
1748
1745
|
if (leg === undefined) {
|
|
1749
|
-
refuse("test.reload.history", "test.reload.history", `a second adapter built from the same
|
|
1746
|
+
refuse("test.reload.history", "test.reload.history", `a second adapter built from the same session carries ${taskId} without the muted leg at ${at}: the record was composed in memory and died with the adapter; the session's store is where it lives`);
|
|
1750
1747
|
}
|
|
1751
1748
|
else if (leg.mutedBy !== "host") {
|
|
1752
1749
|
refuse("test.reload.history", "test.reload.history", `the reloaded record's muted leg at ${at} says mutedBy ${String(leg.mutedBy)}; the host reported host`);
|
|
@@ -1772,7 +1769,7 @@ async function testOneCall(call) {
|
|
|
1772
1769
|
if (malformed.length === 0 && isRecord(reopened) && reopened.status === "opened")
|
|
1773
1770
|
session = reopened.audio;
|
|
1774
1771
|
else if (malformed.length === 0)
|
|
1775
|
-
refuse("test.reload.openAudio", "test.reload.openAudio", `a second adapter built from the same
|
|
1772
|
+
refuse("test.reload.openAudio", "test.reload.openAudio", `a second adapter built from the same session could not open the audio of ${taskId}, which its own snapshot carries with audio started`);
|
|
1776
1773
|
}
|
|
1777
1774
|
}
|
|
1778
1775
|
catch (error) {
|
|
@@ -1794,7 +1791,7 @@ async function testOneCall(call) {
|
|
|
1794
1791
|
if (call.everHeldForTask(taskId))
|
|
1795
1792
|
ruleTested("test.store.retained");
|
|
1796
1793
|
if (retained.length > 0) {
|
|
1797
|
-
refuse("test.store.retained", "test.store", `${taskId} has ended and the
|
|
1794
|
+
refuse("test.store.retained", "test.store", `${taskId} has ended and the session's store still holds ${retained.join(", ")}: a task's keys go with the task, or the next offer of the same id inherits them`);
|
|
1798
1795
|
}
|
|
1799
1796
|
};
|
|
1800
1797
|
// A key written about the task after its end -- a persist hung off a timer, a late command -- is the
|
|
@@ -1805,7 +1802,7 @@ async function testOneCall(call) {
|
|
|
1805
1802
|
ruleTested("test.store.late");
|
|
1806
1803
|
const late = [...call.held].filter(key => namesTask(key, taskId) && !retainedAtEnd.has(key));
|
|
1807
1804
|
if (late.length > 0) {
|
|
1808
|
-
refuse("test.store.late", "test.store", `${taskId} had ended with its keys gone, and the
|
|
1805
|
+
refuse("test.store.late", "test.store", `${taskId} had ended with its keys gone, and the session's store now holds ${late.join(", ")}: something wrote about the task after its end`);
|
|
1809
1806
|
}
|
|
1810
1807
|
};
|
|
1811
1808
|
// The task, as first seen: on the snapshot, or on the first offer.
|
|
@@ -1999,7 +1996,7 @@ async function testOneCall(call) {
|
|
|
1999
1996
|
if (malformed.length === 0 && isRecord(opened) && opened.status === "opened")
|
|
2000
1997
|
session = opened.audio;
|
|
2001
1998
|
else if (malformed.length === 0 && isRecord(opened))
|
|
2002
|
-
refuse("test.openAudio.unavailable", "test.openAudio", "a softphone
|
|
1999
|
+
refuse("test.openAudio.unavailable", "test.openAudio", "a softphone session's adapter could not open the call's audio");
|
|
2003
2000
|
}
|
|
2004
2001
|
// 3b. The microphone is the host's. With the audio open, the test mutes it for a moment and
|
|
2005
2002
|
// reports the leg the provider's record would otherwise miss -- begun, then ended -- and
|
|
@@ -2064,8 +2061,8 @@ async function testOneCall(call) {
|
|
|
2064
2061
|
setMuted(false);
|
|
2065
2062
|
await report({ at, seconds: Math.round((Date.now() - began) / 1000), ended: true });
|
|
2066
2063
|
reportedLegs.push({ at: canonicalTimes.get(at), task: latestTask() });
|
|
2067
|
-
// 3c. A host reload destroys the adapter object and keeps the
|
|
2068
|
-
// the same
|
|
2064
|
+
// 3c. A host reload destroys the adapter object and keeps the session's store. Built again from
|
|
2065
|
+
// the same session, a second adapter carries the task and the leg -- from its platform, or from
|
|
2069
2066
|
// the store -- or it composed the record in memory and the record died with it.
|
|
2070
2067
|
if (call.rebuild !== undefined && canonicalTimes.has(at)) {
|
|
2071
2068
|
await recordSurvivesReload(canonicalTimes.get(at));
|
|
@@ -2074,7 +2071,7 @@ async function testOneCall(call) {
|
|
|
2074
2071
|
return found;
|
|
2075
2072
|
}
|
|
2076
2073
|
}
|
|
2077
|
-
// The host's Mute is unavailable on hold, and the host promised as much at
|
|
2074
|
+
// The host's Mute is unavailable on hold, and the host promised as much at sign-in: a host holds the
|
|
2078
2075
|
// report back (historyReport.muted.held), and an adapter that receives one anyway must refuse it --
|
|
2079
2076
|
// so the test sends a mute begun on hold past the validator and expects failed.
|
|
2080
2077
|
const muteRefusedOnHold = async () => {
|
|
@@ -2359,7 +2356,7 @@ export class BreakStream {
|
|
|
2359
2356
|
recovery = true;
|
|
2360
2357
|
/** True until a validated authoritative snapshot establishes a usable baseline. */
|
|
2361
2358
|
get needsRecovery() { return this.recovery; }
|
|
2362
|
-
/** Caller establishes snapshot freshness/
|
|
2359
|
+
/** Caller establishes snapshot freshness/session scope separately; malformed state never replaces the baseline. */
|
|
2363
2360
|
seed(snapshot) {
|
|
2364
2361
|
const state = isRecord(snapshot) ? snapshot.break : undefined;
|
|
2365
2362
|
const found = validateBreakTransition(state, state, "snapshot.break");
|
|
@@ -2434,7 +2431,7 @@ function watchStore(store) {
|
|
|
2434
2431
|
},
|
|
2435
2432
|
};
|
|
2436
2433
|
}
|
|
2437
|
-
/** A
|
|
2434
|
+
/** A session store that lives in memory for the test: what most adapter tests hand `testAdapter` as `context.store`. */
|
|
2438
2435
|
export function memoryStore() {
|
|
2439
2436
|
const kept = new Map();
|
|
2440
2437
|
return {
|
|
@@ -2469,7 +2466,7 @@ export function assertHistoryAgreesAcrossTasks(earlier, later) {
|
|
|
2469
2466
|
}
|
|
2470
2467
|
before.forEach((step, index) => {
|
|
2471
2468
|
const restated = after[index];
|
|
2472
|
-
for (const field of ["step", "at", "by", "dialId", "
|
|
2469
|
+
for (const field of ["step", "at", "by", "dialId", "contactId", "mutedBy"]) {
|
|
2473
2470
|
if (step[field] !== restated[field]) {
|
|
2474
2471
|
throw new Error(`steps[${index}].${field} is ${String(step[field])} on ${earlier.assignmentId} and ${String(restated[field])} on ${later.assignmentId}: one call has one history`);
|
|
2475
2472
|
}
|
|
@@ -2479,12 +2476,12 @@ export function assertHistoryAgreesAcrossTasks(earlier, later) {
|
|
|
2479
2476
|
}
|
|
2480
2477
|
});
|
|
2481
2478
|
}
|
|
2482
|
-
const
|
|
2479
|
+
const usableSession = (status) => status === "authenticated" || status === "refreshing";
|
|
2483
2480
|
/**
|
|
2484
2481
|
* A break one provider forces stops the agent everywhere: the host states a capacity of zero on
|
|
2485
2482
|
* every other usable provider holding capacity -- taken, never refused, and nothing the agent can
|
|
2486
2483
|
* cancel -- and on the forcing provider states nothing, since the break itself holds the agent
|
|
2487
|
-
* there. A provider whose
|
|
2484
|
+
* there. A provider whose session is not usable is left alone, as a break attempt leaves it.
|
|
2488
2485
|
*/
|
|
2489
2486
|
export function assertForcedBreakStopsTheRest(forcedOn, candidates, stopped) {
|
|
2490
2487
|
if (!candidates.some(candidate => candidate.id === forcedOn))
|
|
@@ -2499,19 +2496,19 @@ export function assertForcedBreakStopsTheRest(forcedOn, candidates, stopped) {
|
|
|
2499
2496
|
for (const candidate of candidates) {
|
|
2500
2497
|
if (candidate.id === forcedOn)
|
|
2501
2498
|
continue;
|
|
2502
|
-
const expected =
|
|
2499
|
+
const expected = usableSession(candidate.authentication) && candidate.holdsCapacity;
|
|
2503
2500
|
if (expected && !chosen.has(candidate.id)) {
|
|
2504
2501
|
throw new Error(`${candidate.id} can give the agent work and must be stopped: capacity 0 stated`);
|
|
2505
2502
|
}
|
|
2506
2503
|
if (!expected && chosen.has(candidate.id)) {
|
|
2507
|
-
const why =
|
|
2504
|
+
const why = usableSession(candidate.authentication) ? "holds no capacity" : `is ${candidate.authentication}`;
|
|
2508
2505
|
throw new Error(`${candidate.id} ${why} and is not stopped: there is nothing to stop`);
|
|
2509
2506
|
}
|
|
2510
2507
|
}
|
|
2511
2508
|
}
|
|
2512
2509
|
/**
|
|
2513
2510
|
* A break attempt asks every connected provider from which the agent can currently receive work.
|
|
2514
|
-
* A provider whose
|
|
2511
|
+
* A provider whose session is not usable -- `expired` above all -- is not asked, whatever else is
|
|
2515
2512
|
* true of it: nothing can be asked of it, and a host that waits on it stalls the break for
|
|
2516
2513
|
* everyone. A usable provider holding capacity is asked, and cannot be left out. `refreshing` is
|
|
2517
2514
|
* usable: identity and capabilities remain available and work continues.
|
|
@@ -2523,12 +2520,12 @@ export function assertBreakAttemptProviders(candidates, asked) {
|
|
|
2523
2520
|
throw new Error(`${id} is not a provider the host knows`);
|
|
2524
2521
|
}
|
|
2525
2522
|
for (const candidate of candidates) {
|
|
2526
|
-
const expected =
|
|
2523
|
+
const expected = usableSession(candidate.authentication) && candidate.holdsCapacity;
|
|
2527
2524
|
if (expected && !chosen.has(candidate.id)) {
|
|
2528
2525
|
throw new Error(`${candidate.id} can give the agent work and must be asked`);
|
|
2529
2526
|
}
|
|
2530
2527
|
if (!expected && chosen.has(candidate.id)) {
|
|
2531
|
-
const why =
|
|
2528
|
+
const why = usableSession(candidate.authentication) ? "holds no capacity" : `is ${candidate.authentication}`;
|
|
2532
2529
|
throw new Error(`${candidate.id} ${why} and is not asked: nothing can be asked of it`);
|
|
2533
2530
|
}
|
|
2534
2531
|
}
|
|
@@ -2561,16 +2558,16 @@ export function assertBreakBeginsAfterTask(steps) {
|
|
|
2561
2558
|
}
|
|
2562
2559
|
}
|
|
2563
2560
|
/** The session key one scenario derives, or `undefined` where the browser shares nothing. */
|
|
2564
|
-
const
|
|
2565
|
-
/** Validates whether two task-browser definitions should share one browser
|
|
2566
|
-
export function
|
|
2567
|
-
const leftKey =
|
|
2568
|
-
const rightKey =
|
|
2561
|
+
const profileKeyFor = (scenario) => browserProfileKey(scenario);
|
|
2562
|
+
/** Validates whether two task-browser definitions should share one browser profile. */
|
|
2563
|
+
export function assertBrowserProfileIsolation(left, right, expectedReuse) {
|
|
2564
|
+
const leftKey = profileKeyFor(left);
|
|
2565
|
+
const rightKey = profileKeyFor(right);
|
|
2569
2566
|
// A browser that does not share its session has no session key at all, so two of them never share one.
|
|
2570
2567
|
// Treating "no key" as a match would report sharing nobody asked for.
|
|
2571
2568
|
const actualReuse = leftKey !== undefined && leftKey === rightKey;
|
|
2572
2569
|
if (actualReuse !== expectedReuse) {
|
|
2573
|
-
throw new Error(`Browser
|
|
2570
|
+
throw new Error(`Browser profile sharing mismatch: expected ${expectedReuse}, received ${actualReuse} (${String(leftKey)} vs ${String(rightKey)})`);
|
|
2574
2571
|
}
|
|
2575
2572
|
}
|
|
2576
2573
|
/**
|
|
@@ -2579,15 +2576,15 @@ export function assertBrowserSessionIsolation(left, right, expectedReuse) {
|
|
|
2579
2576
|
* `B`, casing variants, separators — because a collision silently shares cookies,
|
|
2580
2577
|
* storage, and permissions between two backends.
|
|
2581
2578
|
*/
|
|
2582
|
-
export function
|
|
2579
|
+
export function assertNoBrowserProfileKeyCollisions(scenarios) {
|
|
2583
2580
|
const byKey = new Map();
|
|
2584
2581
|
for (const scenario of scenarios) {
|
|
2585
|
-
const key =
|
|
2582
|
+
const key = profileKeyFor(scenario);
|
|
2586
2583
|
if (key === undefined)
|
|
2587
2584
|
continue;
|
|
2588
2585
|
const existing = byKey.get(key);
|
|
2589
2586
|
if (existing) {
|
|
2590
|
-
throw new Error(`Browser
|
|
2587
|
+
throw new Error(`Browser profile key collision on '${key}': ` +
|
|
2591
2588
|
`${JSON.stringify({ provider: existing.providerId, taskType: existing.taskType, tab: existing.browser.name })} and ` +
|
|
2592
2589
|
`${JSON.stringify({ provider: scenario.providerId, taskType: scenario.taskType, tab: scenario.browser.name })}`);
|
|
2593
2590
|
}
|