test(live): covered selected voice session boundary

Replaced schema self-comparisons with a controller contract test that selects vale and captures the options used to construct the live session.
This commit is contained in:
roboomp
2026-07-26 18:52:17 +00:00
parent ea60fc1df3
commit bb8c0f12d3
3 changed files with 62 additions and 15 deletions
@@ -1,6 +1,6 @@
import type { AssistantMessage } from "@oh-my-pi/pi-ai";
import { logger } from "@oh-my-pi/pi-utils";
import { LiveSessionController, type LiveTranscript } from "../../live/controller";
import { LiveSessionController, type LiveSessionControllerOptions, type LiveTranscript } from "../../live/controller";
import { LIVE_MODEL } from "../../live/protocol";
import { LiveVisualizer } from "../../live/visualizer";
import { vocalizer } from "../../tts/vocalizer";
@@ -11,6 +11,7 @@ import type { InteractiveModeContext } from "../types";
import { createAssistantMessageComponent } from "../utils/interactive-context-helpers";
const ANIMATION_INTERVAL_MS = 80;
type LiveSessionFactory = (options: LiveSessionControllerOptions) => LiveSessionController;
const LIVE_MESSAGE_USAGE: AssistantMessage["usage"] = {
input: 0,
@@ -27,6 +28,7 @@ function errorFrom(cause: unknown): Error {
/** Owns the editor-replacing visualizer and realtime session lifecycle for `/live`. */
export class LiveCommandController {
readonly #ctx: InteractiveModeContext;
readonly #createSession: LiveSessionFactory | undefined;
#session: LiveSessionController | undefined;
#settling: Promise<void> | undefined;
@@ -40,8 +42,9 @@ export class LiveCommandController {
#assistantTranscriptTurn = 0;
#assistantTranscriptStartedAt = 0;
constructor(ctx: InteractiveModeContext) {
constructor(ctx: InteractiveModeContext, createSession?: LiveSessionFactory) {
this.#ctx = ctx;
this.#createSession = createSession;
}
/** Whether a live session is connected, connecting, or closing. */
@@ -100,7 +103,7 @@ export class LiveCommandController {
this.#mountVisualizer(visualizer);
let session: LiveSessionController;
session = new LiveSessionController({
const options: LiveSessionControllerOptions = {
session: this.#ctx.session,
extractAssistantText: message => this.#ctx.extractAssistantText(message),
voice: this.#ctx.settings.get("live.voice"),
@@ -129,7 +132,8 @@ export class LiveCommandController {
},
onTerminal: error => this.#finish(session, error),
},
});
};
session = this.#createSession ? this.#createSession(options) : new LiveSessionController(options);
this.#session = session;
try {