Luigit
repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by admin

extensions/voice/__tests__/index.test.ts

Raw
import { matchesKey } from "@earendil-works/pi-tui";
import { describe, expect, it } from "vitest";
import { __test, parseVoiceCommandArgs } from "../index.ts";

describe("/voice settings", () => {
	it("uses explicit external speech command with no implicit native fallback", () => {
		expect(__test.COMMAND_SETTING.default).toEqual(["speak_to_me"]);
		expect(__test.COMMAND_SETTING.env).toBe("PI_VOICE_COMMAND");
		expect(__test.COMMAND_SETTING.parse('["node","fake.mjs"]', "env")).toEqual([
			"node",
			"fake.mjs",
		]);
		for (const value of ["", "not json", "[]", '["", "[""]'])
			expect(() => __test.COMMAND_SETTING.parse(value, "env")).toThrow();
	});

	it("accepts opaque profile IDs only", () => {
		expect(__test.PROFILE_SETTING.default).toBeUndefined();
		expect(__test.PROFILE_SETTING.env).toBe("PI_VOICE_PROFILE");
		expect(__test.PROFILE_SETTING.parse("service_profile", "env")).toBe(
			"service_profile",
		);
		for (const value of ["", "space profile", "bad/slash"])
			expect(() => __test.PROFILE_SETTING.parse(value, "env")).toThrow();
	});

	it("keeps generic preview and conversation limits", () => {
		expect(__test.PREVIEW_SETTING.default).toBe(true);
		expect(__test.PREVIEW_SETTING.parse("false", "env")).toBe(false);
		expect(__test.MAX_SENTENCES_SETTING.parse("8", "env")).toBe(8);
		expect(__test.MAX_SPEECH_SECONDS_SETTING.parse(60, "project")).toBe(60);
	});

	it("keeps model and shortcut validation", () => {
		expect(__test.CLASSIFIER_MODEL_SETTING.default).toBe("auto");
		expect(
			__test.CLASSIFIER_MODEL_SETTING.parse(
				"provider/nested/model@revision",
				"env",
			),
		).toBe("provider/nested/model@revision");
		const toggle = __test.TOGGLE_SHORTCUT_SETTING.default;
		const mute = __test.MUTE_SHORTCUT_SETTING.default;
		if (!toggle || !mute) throw new Error("missing shortcut defaults");
		expect(matchesKey("\u001b\u0016", toggle)).toBe(true);
		expect(matchesKey("\u001b\u0002", mute)).toBe(true);
	});

	it("preserves command parsing", () => {
		expect(parseVoiceCommandArgs("--root /tmp/voice")).toEqual({
			command: "start",
			root: "/tmp/voice",
		});
		expect(() => parseVoiceCommandArgs("--no-open")).toThrow("usage");
	});
});