@xema/omni-protocol 0.1.128 → 0.1.130

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/dist/testing.js CHANGED
@@ -1,5 +1,5 @@
1
- import { browserSessionKey, effectiveLevels, sameCapabilities, } from "./index.js";
2
- import { assertNoViolations, validateAuthenticationState, validateBreakTransition, validateEventEnvelope, validateHostGuarantees, validateHostReport, validateUserDetails, observeRules, ruleTested, validateHostMute, validateHostRecording, validateLoginStore, validateHistoryReport, validateManifest, validateResult, validateSnapshot, validateTask, validateLanguages, validateTimeZone, validatePhone, validateTaskCommand, isTimeZone, sameTimeZone, } from "./validation.js";
1
+ import { browserSessionKey, 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
@@ -57,6 +57,10 @@ const CONTRACT_SUBJECTS = [
57
57
  // here assumes its shape; a subject is reached only by something the element rules would see.
58
58
  const isRecord = (value) => typeof value === "object" && value !== null;
59
59
  const some = (value) => Array.isArray(value) && value.length > 0;
60
+ // A manifest without a ladder has been reported on, and declares no level: every level is refused.
61
+ const declaredLevels = (manifest) => isRecord(manifest) && Array.isArray(manifest.orgLevels)
62
+ ? manifest.orgLevels.filter(isRecord).map(level => level.id).filter((id) => typeof id === "string")
63
+ : [];
60
64
  function observeTask(value, seen) {
61
65
  if (!isRecord(value))
62
66
  return;
@@ -80,11 +84,8 @@ function observeTask(value, seen) {
80
84
  const capabilities = isRecord(value.capabilities) ? value.capabilities : {};
81
85
  if (isRecord(capabilities.outcomes))
82
86
  seen.add("task.outcomes");
83
- for (const directory of ["coldTransfer", "warmTransfer", "conference"]) {
84
- const declared = capabilities[directory];
85
- if (isRecord(declared) && some(declared.destinations))
86
- seen.add("task.destinations");
87
- }
87
+ if (isRecord(capabilities.addToCall) && typeof capabilities.addToCall.destinations === "string")
88
+ seen.add("task.destinations");
88
89
  if (some(capabilities.custom))
89
90
  seen.add("task.custom");
90
91
  if (Object.values(capabilities).some(declared => isRecord(declared) && declared.lockedBy !== undefined))
@@ -211,7 +212,7 @@ function observeEvent(envelope, seen) {
211
212
  * Adapter conformance exercise: validates the manifest, opens an authenticated session,
212
213
  * connects, checks that every method the declarations require is implemented, subscribes,
213
214
  * validates the snapshot, every delivered event, and every authentication state the session
214
- * publishes during the run -- against the latest login, since capabilities are current, not
215
+ * publishes during the run -- against the latest session, since capabilities are current, not
215
216
  * fixed -- states a capacity, then unsubscribes and disconnects.
216
217
  *
217
218
  * Violations are collected rather than thrown from inside the adapter's own
@@ -245,27 +246,27 @@ export async function testAdapter(adapter, context, options = {}) {
245
246
  let unsubscribeAuthentication;
246
247
  let unsubscribeHost;
247
248
  let authenticationState;
248
- let login;
249
+ let signedIn;
249
250
  let disconnectWasClean = false;
250
251
  try {
251
252
  authenticationState = await authentication.state();
252
- const levels = effectiveLevels(adapter.manifest.orgLevels).map(level => level.id);
253
+ const levels = declaredLevels(adapter.manifest);
253
254
  violations.push(...validateAuthenticationState(authenticationState, "authentication", { levels }));
254
255
  if (authenticationState.status !== "authenticated") {
255
256
  throw new Error(`Adapter contract exercise requires authenticated test state, received ${authenticationState.status}`);
256
257
  }
257
- // The harness knows who is signed in and what their login declares, so it can hold the
258
+ // The harness knows who is signed in and what their capabilities include, so it can hold the
258
259
  // adapter to rules the structural validators cannot check alone: a team member list never carries the
259
260
  // agent it is published to, a lead's snapshot always carries one, nobody else's ever does.
260
- // Capabilities are current, not fixed, so the login is read when something is validated,
261
+ // Capabilities are current, not fixed, so the session is read when something is validated,
261
262
  // never captured at sign-in: a provider that withdraws one republishes `authenticated`, and
262
263
  // everything published after that is held to the new set. A published state that fails
263
- // validation is reported and not adopted -- the harness keeps the last login it could trust.
264
- login = authenticationState;
264
+ // validation is reported and not adopted -- the harness keeps the last session it could trust.
265
+ signedIn = authenticationState;
265
266
  const current = () => {
266
- if (login === undefined)
267
- throw new Error("unreachable: the exercise has an authenticated login");
268
- return login;
267
+ if (signedIn === undefined)
268
+ throw new Error("unreachable: the exercise has an authenticated session");
269
+ return signedIn;
269
270
  };
270
271
  // Off until the application has said otherwise: the provider assumes nothing of the team feature.
271
272
  let leadFeaturesOn = false;
@@ -274,7 +275,7 @@ export async function testAdapter(adapter, context, options = {}) {
274
275
  capabilities: current().capabilities,
275
276
  leadFeatures: leadFeaturesOn,
276
277
  phone: context.phone,
277
- loginId: context.loginId,
278
+ sessionId: context.sessionId,
278
279
  autoAcceptTasks: context.autoAcceptTasks,
279
280
  locked: options.lockedValues,
280
281
  });
@@ -297,19 +298,19 @@ export async function testAdapter(adapter, context, options = {}) {
297
298
  // The four stand or fall together: `granted` is a promise to honour a later commit, and
298
299
  // an adapter with requestBreak but no commitBreak leaves an agent a break that never starts.
299
300
  for (const method of ["requestBreak", "commitBreak", "cancelBreak", "endBreak"]) {
300
- requireMethod(on, method, "the login declares capabilities.breaks");
301
+ requireMethod(on, method, "the user's capabilities include breaks");
301
302
  }
302
303
  }
303
- if (capabilities.lead === true)
304
- requireMethod(on, "executeTeam", "the login declares capabilities.lead");
304
+ if (capabilities.lead !== undefined)
305
+ requireMethod(on, "executeTeam", "the user's capabilities include lead");
305
306
  if (capabilities.nextCall === true) {
306
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.
307
308
  for (const method of ["requestNextCall", "cancelNextCall", "releaseLinedUp"]) {
308
- requireMethod(on, method, "the login declares capabilities.nextCall");
309
+ requireMethod(on, method, "the user's capabilities include nextCall");
309
310
  }
310
311
  }
311
312
  if (some(capabilities.preferences))
312
- requireMethod(on, "setPreference", "the login declares capabilities.preferences");
313
+ requireMethod(on, "setPreference", "the user's capabilities include preferences");
313
314
  };
314
315
  const onAuthenticationState = (state) => {
315
316
  const own = validateAuthenticationState(state, "authentication", { levels });
@@ -331,7 +332,7 @@ export async function testAdapter(adapter, context, options = {}) {
331
332
  violations.push(...refreshingCarriesOver(current(), state, "authentication"));
332
333
  }
333
334
  else if (state.status === "authenticated") {
334
- login = state;
335
+ signedIn = state;
335
336
  // A capability granted later requires its methods just as one declared at sign-in does.
336
337
  if (connection !== undefined)
337
338
  requireCapabilityMethods(connection, state.capabilities);
@@ -356,16 +357,16 @@ export async function testAdapter(adapter, context, options = {}) {
356
357
  violations.push(...validateHostReport(first, "context.host"));
357
358
  const hasAudio = isRecord(first) && first.audio !== undefined;
358
359
  if (softphone && !hasAudio) {
359
- violations.push({ rule: "context.host.audio.required", path: "context.host.audio", message: "a softphone login's host reports its audio" });
360
+ violations.push({ rule: "context.host.audio.required", path: "context.host.audio", message: "a softphone session's host reports its audio" });
360
361
  }
361
362
  if (!softphone && hasAudio) {
362
363
  violations.push({ rule: "context.host.audio.unexpected", path: "context.host.audio",
363
- message: adapter.manifest.channel === "voice" ? "a hardphone login has no audio in the host to report" : `a ${adapter.manifest.channel} connection has no audio for the host to report` });
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` });
364
365
  }
365
366
  // What the host's Mute does is stated where the host holds a microphone, and nowhere else.
366
367
  violations.push(...validateHostMute(context.host.mute, softphone, "context.host.mute"));
367
- // The login's store is the host's to provide: an adapter that composes a record keeps in it what its platform cannot.
368
- const storeShape = validateLoginStore(context.store, "context.store");
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");
369
370
  violations.push(...storeShape);
370
371
  // The harness watches the store it hands over, so what an adapter leaves behind is seen rather than asked for.
371
372
  const watched = storeShape.length === 0 ? watchStore(context.store) : { store: context.store, held: new Set(), everHeld: new Set() };
@@ -408,11 +409,11 @@ export async function testAdapter(adapter, context, options = {}) {
408
409
  requireMethod(on, "dial", "the manifest declares dial");
409
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.
410
411
  if (softphone)
411
- requireMethod(on, "openAudio", "the login is on a softphone");
412
+ requireMethod(on, "openAudio", "the session is on a softphone");
412
413
  // The microphone is the host's, so on a softphone every call can be muted by it, and the
413
414
  // record of that leg is the provider's to take; on a hardphone the host holds no microphone.
414
415
  if (softphone)
415
- requireMethod(on, "recordStep", "the login is on a softphone, whose microphone the host mutes");
416
+ requireMethod(on, "recordStep", "the session is on a softphone, whose microphone the host mutes");
416
417
  };
417
418
  connectObligations(live);
418
419
  const tellRefused = (report) => {
@@ -482,7 +483,7 @@ export async function testAdapter(adapter, context, options = {}) {
482
483
  if (earlier !== undefined) {
483
484
  if (earlier !== payload) {
484
485
  violations.push({ rule: "event.id.reused", path: "event.id",
485
- message: `envelope ${envelope.id} was delivered again with a different event: an id names one event for the life of the login` });
486
+ message: `envelope ${envelope.id} was delivered again with a different event: an id names one event for the life of the session` });
486
487
  }
487
488
  return;
488
489
  }
@@ -533,8 +534,8 @@ export async function testAdapter(adapter, context, options = {}) {
533
534
  authentication = session;
534
535
  connection = second;
535
536
  live = second;
536
- // The second client is held to everything the first was on connect: its methods, its login's
537
- // methods, the login it publishes from here, and a capacity stated to it, since the first's
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
538
539
  // statement died with the first and nothing may be assigned against a count nobody stated to it.
539
540
  connectObligations(second);
540
541
  requireCapabilityMethods(second, current().capabilities);
@@ -656,7 +657,7 @@ export async function testAdapter(adapter, context, options = {}) {
656
657
  // reaches the lead, which the reader held the connect snapshot to. A reloaded client is a
657
658
  // connect too: it is told again, after its capacity, and held the same way.
658
659
  const switchOnLeadFeatures = async (on, at) => {
659
- if (current().capabilities.lead !== true || typeof on.executeTeam !== "function")
660
+ if (current().capabilities.lead === undefined || typeof on.executeTeam !== "function")
660
661
  return;
661
662
  const from = events.length;
662
663
  let switched;
@@ -785,7 +786,7 @@ export async function testAdapter(adapter, context, options = {}) {
785
786
  return {
786
787
  events: events,
787
788
  authenticationState: authenticationState,
788
- login: (login ?? authenticationState),
789
+ signedIn: (signedIn ?? authenticationState),
789
790
  notTested: CONTRACT_SUBJECTS.filter(subject => !seen.has(subject)),
790
791
  disconnectWasClean,
791
792
  violations,
@@ -883,23 +884,23 @@ function eventNamesUsers(envelope) {
883
884
  }
884
885
  }
885
886
  /**
886
- * `refreshing` carries the identity and capabilities of the login it refreshes. A change to
887
- * either is published as `authenticated`; a different identity is a new login.
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.
888
889
  */
889
- function refreshingCarriesOver(login, state, path) {
890
+ function refreshingCarriesOver(signedIn, state, path) {
890
891
  const found = [];
891
- if (state.identity.id !== login.identity.id) {
892
+ if (state.identity.id !== signedIn.identity.id) {
892
893
  found.push({
893
894
  rule: "authentication.refreshing.identity",
894
895
  path: `${path}.identity.id`,
895
- message: "refreshing carries the identity of the login it refreshes; a different identity is a new login",
896
+ message: "refreshing carries the identity of the session it refreshes; a different identity is a new session",
896
897
  });
897
898
  }
898
- if (!sameCapabilities(state.capabilities, login.capabilities)) {
899
+ if (!sameCapabilities(state.capabilities, signedIn.capabilities)) {
899
900
  found.push({
900
901
  rule: "authentication.refreshing.capabilities",
901
902
  path: `${path}.capabilities`,
902
- message: "refreshing carries the capabilities of the login it refreshes; a change is published as authenticated",
903
+ message: "refreshing carries the capabilities of the session it refreshes; a change is published as authenticated",
903
904
  });
904
905
  }
905
906
  return found;
@@ -954,29 +955,29 @@ function connectingReports(context, violations) {
954
955
  settled: () => { settled = true; },
955
956
  };
956
957
  }
957
- /** Validates each state of a published sequence, and that every `refreshing` carries over the login before it. */
958
- function assertLoginSequence(states, summary) {
958
+ /** Validates each state of a published sequence, and that every `refreshing` carries over the session before it. */
959
+ function assertSignedInSequence(states, levels, summary) {
959
960
  const found = [];
960
- let login;
961
+ let signedIn;
961
962
  states.forEach((state, index) => {
962
963
  const path = `states[${index}]`;
963
- const own = validateAuthenticationState(state, path);
964
+ const own = validateAuthenticationState(state, path, { levels });
964
965
  found.push(...own);
965
966
  if (own.length > 0)
966
967
  return;
967
968
  if (state.status === "authenticated")
968
- login = state;
969
- else if (state.status === "refreshing" && login !== undefined)
970
- found.push(...refreshingCarriesOver(login, state, path));
969
+ signedIn = state;
970
+ else if (state.status === "refreshing" && signedIn !== undefined)
971
+ found.push(...refreshingCarriesOver(signedIn, state, path));
971
972
  });
972
973
  assertNoViolations(found, summary);
973
974
  }
974
975
  /**
975
976
  * Validates restored authentication followed by a refresh failure or expiry. Every state is
976
- * validated, and a `refreshing` state must carry over the login it refreshes.
977
+ * validated against the manifest's levels, and a `refreshing` state must carry over the session it refreshes.
977
978
  */
978
- export function assertAuthenticationRestoreAndExpiry(states) {
979
- assertLoginSequence(states, "Authentication scenario");
979
+ export function assertAuthenticationRestoreAndExpiry(states, manifest) {
980
+ assertSignedInSequence(states, declaredLevels(manifest), "Authentication scenario");
980
981
  if (states.length < 2 || states[0]?.status !== "authenticated") {
981
982
  throw new Error("Authentication scenario must start with a restored authenticated state");
982
983
  }
@@ -1035,34 +1036,34 @@ function notYetReadTasks(tasks, path) {
1035
1036
  * Capabilities are current, not fixed. A provider that withdraws one republishes `authenticated`
1036
1037
  * with the new set, and the next snapshot agrees with it. `states` is what the authentication
1037
1038
  * session published, first to last: beginning and ending `authenticated` for the same identity,
1038
- * passing only through usable states (`expired`, `terminated` or `signed-out` ends the login instead), with at
1039
+ * passing only through usable states (`expired`, `terminated` or `signed-out` ends the session instead), with at
1039
1040
  * least one capability gone by the end. `snapshot` is the first snapshot published after the last
1040
- * state, validated against that login -- so a team member list still published to a login that no longer
1041
+ * state, validated against that sign-in -- so a team member list still published to a session that no longer
1041
1042
  * leads, or requests to one that may no longer join, is the failure.
1042
1043
  */
1043
1044
  export function assertCapabilityWithdrawal(states, snapshot, manifest) {
1044
- assertLoginSequence(states, "Capability withdrawal");
1045
+ assertSignedInSequence(states, declaredLevels(manifest), "Capability withdrawal");
1045
1046
  const stray = states.findIndex(state => state.status !== "authenticated" && state.status !== "refreshing");
1046
1047
  if (stray >= 0) {
1047
- throw new Error(`Capability withdrawal passes only through usable states; states[${stray}] is ${states[stray]?.status}, which ends the login`);
1048
+ throw new Error(`Capability withdrawal passes only through usable states; states[${stray}] is ${states[stray]?.status}, which ends the session`);
1048
1049
  }
1049
1050
  const first = states[0];
1050
1051
  const last = states.at(-1);
1051
1052
  if (first?.status !== "authenticated" || last?.status !== "authenticated") {
1052
- throw new Error("Capability withdrawal must begin and end with an authenticated login");
1053
+ throw new Error("Capability withdrawal must begin and end with an authenticated session");
1053
1054
  }
1054
1055
  if (first.identity.id !== last.identity.id) {
1055
- throw new Error("Capability withdrawal must keep the identity: a different identity is a new login");
1056
+ throw new Error("Capability withdrawal must keep the identity: a different identity is a new session");
1056
1057
  }
1057
1058
  const before = first.capabilities;
1058
1059
  const after = last.capabilities;
1059
1060
  const withdrawn = (before.breaks === true && after.breaks !== true) ||
1060
- (before.lead === true && after.lead !== true) ||
1061
+ Object.keys(before.lead ?? {}).some(name => after.lead?.[name] !== true) ||
1061
1062
  (before.preferences ?? []).some(was => !(after.preferences ?? []).some(now => now.id === was.id));
1062
1063
  if (!withdrawn) {
1063
- throw new Error("Capability withdrawal must end with at least one capability the first login declared withdrawn");
1064
+ throw new Error("Capability withdrawal must end with at least one capability the first session declared withdrawn");
1064
1065
  }
1065
- assertNoViolations(validateSnapshot(snapshot, manifest, "snapshot", { self: last.identity.id, capabilities: after }), "Capability withdrawal: the snapshot after the last login must agree with it");
1066
+ assertNoViolations(validateSnapshot(snapshot, manifest, "snapshot", { self: last.identity.id, capabilities: after }), "Capability withdrawal: the snapshot after the last session must agree with it");
1066
1067
  }
1067
1068
  /**
1068
1069
  * A command that arrives after its capability was withdrawn is answered `failed` with
@@ -1099,7 +1100,7 @@ export function assertTaskCapabilityWithdrawal(tasks, manifest, command) {
1099
1100
  }
1100
1101
  const context = {
1101
1102
  channel: manifest.channel,
1102
- levels: effectiveLevels(manifest.orgLevels).map(level => level.id),
1103
+ levels: declaredLevels(manifest),
1103
1104
  dialOutcomesDeclared: manifest.dialOutcomes !== undefined,
1104
1105
  };
1105
1106
  tasks.forEach((task, index) => {
@@ -1688,14 +1689,14 @@ async function testOneCall(call) {
1688
1689
  try {
1689
1690
  const restoredSession = await again.createAuthenticationSession({ ...call.context, secrets: call.secrets });
1690
1691
  // The reload is a restore before it is anything else: the second session stands authenticated
1691
- // as the same person, from the secrets alone, or nothing it reads afterwards is this login's.
1692
+ // as the same person, from the secrets alone, or nothing it reads afterwards is this session's.
1692
1693
  const restored = await restoredSession.state();
1693
- found.push(...validateAuthenticationState(restored, "test.reload.login"));
1694
- ruleTested("test.reload.login");
1694
+ found.push(...validateAuthenticationState(restored, "test.reload.session", { levels: declaredLevels(call.manifest) }));
1695
+ ruleTested("test.reload.session");
1695
1696
  const same = isRecord(restored) && restored.status === "authenticated" && isRecord(restored.identity) && restored.identity.id === call.reader().self;
1696
1697
  if (!same) {
1697
- refuse("test.reload.login", "test.reload.login", `a second adapter built from the same login and secrets did not restore it: the session says ${String(isRecord(restored) ? restored.status : restored)}${isRecord(restored) && isRecord(restored.identity) ? ` as ${String(restored.identity.id)}` : ""}, and the login is ${String(call.reader().self)}`);
1698
- // A reload that cannot restore the login is a sign-in screen, not a connection: the run ends here.
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.
1699
1700
  try {
1700
1701
  await restoredSession.close();
1701
1702
  }
@@ -1726,7 +1727,7 @@ async function testOneCall(call) {
1726
1727
  ? snapshot.tasks.find(task => isRecord(task) && task.assignmentId === taskId) : undefined;
1727
1728
  ruleTested("test.reload.snapshot");
1728
1729
  if (carried === undefined) {
1729
- refuse("test.reload.snapshot", "test.reload.snapshot", `a second adapter built from the same login does not carry ${taskId} on its snapshot, and the task is still open`);
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`);
1730
1731
  return;
1731
1732
  }
1732
1733
  ruleTested("test.reload.history");
@@ -1738,11 +1739,11 @@ async function testOneCall(call) {
1738
1739
  const lost = wasRead.filter(entry => !steps.some(now => isRecord(now) && now.step === entry.step && now.at === entry.at))
1739
1740
  .map(entry => `${String(entry.step)}@${String(entry.at)}`);
1740
1741
  if (lost.length > 0) {
1741
- refuse("test.reload.history", "test.reload.history", `a second adapter built from the same login carries ${taskId} without ${lost.join(", ")}, which the first had published: a record once read is not unread`);
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`);
1742
1743
  }
1743
1744
  const leg = steps.find(entry => isRecord(entry) && entry.step === "muted" && entry.at === at);
1744
1745
  if (leg === undefined) {
1745
- refuse("test.reload.history", "test.reload.history", `a second adapter built from the same login carries ${taskId} without the muted leg at ${at}: the record was composed in memory and died with the adapter; the login's store is where it lives`);
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`);
1746
1747
  }
1747
1748
  else if (leg.mutedBy !== "host") {
1748
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`);
@@ -1768,7 +1769,7 @@ async function testOneCall(call) {
1768
1769
  if (malformed.length === 0 && isRecord(reopened) && reopened.status === "opened")
1769
1770
  session = reopened.audio;
1770
1771
  else if (malformed.length === 0)
1771
- refuse("test.reload.openAudio", "test.reload.openAudio", `a second adapter built from the same login could not open the audio of ${taskId}, which its own snapshot carries with audio started`);
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`);
1772
1773
  }
1773
1774
  }
1774
1775
  catch (error) {
@@ -1790,7 +1791,7 @@ async function testOneCall(call) {
1790
1791
  if (call.everHeldForTask(taskId))
1791
1792
  ruleTested("test.store.retained");
1792
1793
  if (retained.length > 0) {
1793
- refuse("test.store.retained", "test.store", `${taskId} has ended and the login's store still holds ${retained.join(", ")}: a task's keys go with the task, or the next offer of the same id inherits them`);
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`);
1794
1795
  }
1795
1796
  };
1796
1797
  // A key written about the task after its end -- a persist hung off a timer, a late command -- is the
@@ -1801,7 +1802,7 @@ async function testOneCall(call) {
1801
1802
  ruleTested("test.store.late");
1802
1803
  const late = [...call.held].filter(key => namesTask(key, taskId) && !retainedAtEnd.has(key));
1803
1804
  if (late.length > 0) {
1804
- refuse("test.store.late", "test.store", `${taskId} had ended with its keys gone, and the login's store now holds ${late.join(", ")}: something wrote about the task after its end`);
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`);
1805
1806
  }
1806
1807
  };
1807
1808
  // The task, as first seen: on the snapshot, or on the first offer.
@@ -1836,7 +1837,7 @@ async function testOneCall(call) {
1836
1837
  ruleTested("test.timeout");
1837
1838
  const send = async (command, dialId) => {
1838
1839
  const own = validateTaskCommand(command, latestTask(), `test.command.${String(command.type)}`, {
1839
- levels: effectiveLevels(call.manifest.orgLevels).map(level => level.id),
1840
+ levels: declaredLevels(call.manifest),
1840
1841
  dialOutcomesDeclared: call.manifest.dialOutcomes !== undefined,
1841
1842
  calendarDeclared: call.manifest.idleCapabilities?.calendar === true,
1842
1843
  autoAcceptTasks: call.context.autoAcceptTasks,
@@ -1995,7 +1996,7 @@ async function testOneCall(call) {
1995
1996
  if (malformed.length === 0 && isRecord(opened) && opened.status === "opened")
1996
1997
  session = opened.audio;
1997
1998
  else if (malformed.length === 0 && isRecord(opened))
1998
- refuse("test.openAudio.unavailable", "test.openAudio", "a softphone login's adapter could not open the call's audio");
1999
+ refuse("test.openAudio.unavailable", "test.openAudio", "a softphone session's adapter could not open the call's audio");
1999
2000
  }
2000
2001
  // 3b. The microphone is the host's. With the audio open, the test mutes it for a moment and
2001
2002
  // reports the leg the provider's record would otherwise miss -- begun, then ended -- and
@@ -2060,8 +2061,8 @@ async function testOneCall(call) {
2060
2061
  setMuted(false);
2061
2062
  await report({ at, seconds: Math.round((Date.now() - began) / 1000), ended: true });
2062
2063
  reportedLegs.push({ at: canonicalTimes.get(at), task: latestTask() });
2063
- // 3c. A host reload destroys the adapter object and keeps the login's store. Built again from
2064
- // the same login, a second adapter carries the task and the leg -- from its platform, or from
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
2065
2066
  // the store -- or it composed the record in memory and the record died with it.
2066
2067
  if (call.rebuild !== undefined && canonicalTimes.has(at)) {
2067
2068
  await recordSurvivesReload(canonicalTimes.get(at));
@@ -2070,7 +2071,7 @@ async function testOneCall(call) {
2070
2071
  return found;
2071
2072
  }
2072
2073
  }
2073
- // The host's Mute is unavailable on hold, and the host promised as much at login: a host holds the
2074
+ // The host's Mute is unavailable on hold, and the host promised as much at sign-in: a host holds the
2074
2075
  // report back (historyReport.muted.held), and an adapter that receives one anyway must refuse it --
2075
2076
  // so the test sends a mute begun on hold past the validator and expects failed.
2076
2077
  const muteRefusedOnHold = async () => {
@@ -2355,7 +2356,7 @@ export class BreakStream {
2355
2356
  recovery = true;
2356
2357
  /** True until a validated authoritative snapshot establishes a usable baseline. */
2357
2358
  get needsRecovery() { return this.recovery; }
2358
- /** Caller establishes snapshot freshness/login scope separately; malformed state never replaces the baseline. */
2359
+ /** Caller establishes snapshot freshness/session scope separately; malformed state never replaces the baseline. */
2359
2360
  seed(snapshot) {
2360
2361
  const state = isRecord(snapshot) ? snapshot.break : undefined;
2361
2362
  const found = validateBreakTransition(state, state, "snapshot.break");
@@ -2430,7 +2431,7 @@ function watchStore(store) {
2430
2431
  },
2431
2432
  };
2432
2433
  }
2433
- /** A login store that lives in memory for the test: what most adapter tests hand `testAdapter` as `context.store`. */
2434
+ /** A session store that lives in memory for the test: what most adapter tests hand `testAdapter` as `context.store`. */
2434
2435
  export function memoryStore() {
2435
2436
  const kept = new Map();
2436
2437
  return {
@@ -2465,7 +2466,7 @@ export function assertHistoryAgreesAcrossTasks(earlier, later) {
2465
2466
  }
2466
2467
  before.forEach((step, index) => {
2467
2468
  const restated = after[index];
2468
- for (const field of ["step", "at", "by", "dialId", "destinationId", "mutedBy"]) {
2469
+ for (const field of ["step", "at", "by", "dialId", "contactId", "mutedBy"]) {
2469
2470
  if (step[field] !== restated[field]) {
2470
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`);
2471
2472
  }
@@ -2475,12 +2476,12 @@ export function assertHistoryAgreesAcrossTasks(earlier, later) {
2475
2476
  }
2476
2477
  });
2477
2478
  }
2478
- const usableLogin = (status) => status === "authenticated" || status === "refreshing";
2479
+ const usableSession = (status) => status === "authenticated" || status === "refreshing";
2479
2480
  /**
2480
2481
  * A break one provider forces stops the agent everywhere: the host states a capacity of zero on
2481
2482
  * every other usable provider holding capacity -- taken, never refused, and nothing the agent can
2482
2483
  * cancel -- and on the forcing provider states nothing, since the break itself holds the agent
2483
- * there. A provider whose login is not usable is left alone, as a break attempt leaves it.
2484
+ * there. A provider whose session is not usable is left alone, as a break attempt leaves it.
2484
2485
  */
2485
2486
  export function assertForcedBreakStopsTheRest(forcedOn, candidates, stopped) {
2486
2487
  if (!candidates.some(candidate => candidate.id === forcedOn))
@@ -2495,19 +2496,19 @@ export function assertForcedBreakStopsTheRest(forcedOn, candidates, stopped) {
2495
2496
  for (const candidate of candidates) {
2496
2497
  if (candidate.id === forcedOn)
2497
2498
  continue;
2498
- const expected = usableLogin(candidate.authentication) && candidate.holdsCapacity;
2499
+ const expected = usableSession(candidate.authentication) && candidate.holdsCapacity;
2499
2500
  if (expected && !chosen.has(candidate.id)) {
2500
2501
  throw new Error(`${candidate.id} can give the agent work and must be stopped: capacity 0 stated`);
2501
2502
  }
2502
2503
  if (!expected && chosen.has(candidate.id)) {
2503
- const why = usableLogin(candidate.authentication) ? "holds no capacity" : `is ${candidate.authentication}`;
2504
+ const why = usableSession(candidate.authentication) ? "holds no capacity" : `is ${candidate.authentication}`;
2504
2505
  throw new Error(`${candidate.id} ${why} and is not stopped: there is nothing to stop`);
2505
2506
  }
2506
2507
  }
2507
2508
  }
2508
2509
  /**
2509
2510
  * A break attempt asks every connected provider from which the agent can currently receive work.
2510
- * A provider whose login is not usable -- `expired` above all -- is not asked, whatever else is
2511
+ * A provider whose session is not usable -- `expired` above all -- is not asked, whatever else is
2511
2512
  * true of it: nothing can be asked of it, and a host that waits on it stalls the break for
2512
2513
  * everyone. A usable provider holding capacity is asked, and cannot be left out. `refreshing` is
2513
2514
  * usable: identity and capabilities remain available and work continues.
@@ -2519,12 +2520,12 @@ export function assertBreakAttemptProviders(candidates, asked) {
2519
2520
  throw new Error(`${id} is not a provider the host knows`);
2520
2521
  }
2521
2522
  for (const candidate of candidates) {
2522
- const expected = usableLogin(candidate.authentication) && candidate.holdsCapacity;
2523
+ const expected = usableSession(candidate.authentication) && candidate.holdsCapacity;
2523
2524
  if (expected && !chosen.has(candidate.id)) {
2524
2525
  throw new Error(`${candidate.id} can give the agent work and must be asked`);
2525
2526
  }
2526
2527
  if (!expected && chosen.has(candidate.id)) {
2527
- const why = usableLogin(candidate.authentication) ? "holds no capacity" : `is ${candidate.authentication}`;
2528
+ const why = usableSession(candidate.authentication) ? "holds no capacity" : `is ${candidate.authentication}`;
2528
2529
  throw new Error(`${candidate.id} ${why} and is not asked: nothing can be asked of it`);
2529
2530
  }
2530
2531
  }