Luigit
repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by admin

extensions/voice/__tests__/native-command.test.ts

Raw
import { describe, expect, it } from "vitest";
import { __test, parseVoiceCommandArgs } from "../index.ts";

describe("native-only /voice commands", () => {
	it("starts native by default, including an explicit approved root", () => {
		expect(parseVoiceCommandArgs("")).toEqual({ command: "start" });
		expect(parseVoiceCommandArgs("--root /tmp/voice")).toEqual({
			command: "start",
			root: "/tmp/voice",
		});
		expect(parseVoiceCommandArgs("native --root /tmp/voice")).toEqual({
			command: "start",
			root: "/tmp/voice",
		});
	});
	it("supports native controls and quoted history roots", () => {
		for (const command of [
			"start",
			"setup",
			"history",
			"mute",
			"unmute",
			"stop",
			"resume",
			"help",
		])
			expect(parseVoiceCommandArgs(command)).toEqual({ command });
		expect(parseVoiceCommandArgs('history --root "/tmp/voice data"')).toEqual({
			command: "history",
			root: "/tmp/voice data",
		});
	});
	it("rejects browser entry and browser-only flags", () => {
		for (const input of ["browser", "browser --no-open", "--no-open"])
			expect(() => parseVoiceCommandArgs(input)).toThrow("usage");
	});
	it("uses explicit service command/profile settings", () => {
		expect(__test.COMMAND_SETTING.default).toEqual(["speak_to_me"]);
		expect(__test.COMMAND_SETTING.parse('["node","fake.mjs"]', "env")).toEqual([
			"node",
			"fake.mjs",
		]);
		expect(() => __test.COMMAND_SETTING.parse("speak_to_me", "env")).toThrow(
			"JSON array",
		);
		expect(__test.PROFILE_SETTING.parse("local_en", "env")).toBe("local_en");
		expect(() => __test.PROFILE_SETTING.parse("bad profile", "env")).toThrow(
			"opaque",
		);
	});
	it("rejects relative, NUL and misplaced roots", () => {
		expect(() => parseVoiceCommandArgs("setup --root relative")).toThrow(
			"absolute path",
		);
		expect(() => parseVoiceCommandArgs("start --root /tmp/\0voice")).toThrow(
			"without NUL",
		);
		expect(() => parseVoiceCommandArgs("mute --root /tmp/voice")).toThrow(
			"only valid",
		);
	});
});