AbsoluteJS

Tester Scenarios

How to model realistic and adversarial caller behavior for @absolutejs/voice-tester.

#Custom Scenario

TS
import type { Scenario } from "@absolutejs/voice-tester";

export const pricingScenario: Scenario = {
	id: "pricing-question",
	maxDurationMs: 60_000,
	idleMs: 1200,
	decide: async ({ lastServiceUtterance, callerTurnCount }) => {
		if (callerTurnCount >= 5) return { type: "hangup", reason: "done" };
		if (lastServiceUtterance?.toLowerCase().includes("price")) {
			return { type: "speak", text: "Is there a free trial?" };
		}
		return { type: "speak", text: "Tell me more." };
	}
};

#Scenario Context

transcript is the chronological caller/service conversation observed so far.
elapsedMs is total runtime since the transport opened.
lastServiceUtterance is the most recent service turn or null while waiting for the first greeting.
callerTurnCount lets scenarios stop after a fixed number of actions or branch as the call progresses.

#Actions

{ type: "speak", text } synthesizes caller speech and streams it through the active transport.
{ type: "speak", text, voice } overrides the default Aura voice for one caller turn.
{ type: "speak", text, interrupt: true } models barge-in behavior when the transport supports interruption.
{ type: "silence", ms } tests greeting handling, recovery from pauses, timeout behavior, and no-input flows.
{ type: "hangup", reason } ends the scenario intentionally and produces endedReason: "scenario_hangup".

#Built-In Scenarios

happyPathScenario plays a realistic cooperative caller and is the baseline for catching basic regressions.
adversarialScenario probes silence, mumbled answers, interruptions, language switching, off-topic questions, and LLM-improvised follow-ups.
maxDurationMs caps the full call, idleMs controls when the tester decides the service has stopped speaking, and responseStartTimeoutMs controls how long it waits for the service to begin responding.
Scenarios should fail the service for loops, crashes, hangs, bad turn-taking, and inability to recover from ordinary caller behavior.