- app/ (Electron 45 + TypeScript): the core joins one voice channel, decodes each speaker's Opus to 48 kHz stereo and streams it to the voice worker, sends speaking_end and speaker_leave, and emits speech_start/partial/final with the speaker's display name. - Sentence playback from the worker's TTS, first come first served, with stop that silences the clip at once and cancels unfinished requests; slash command join/leave/stop (create-or-update by name). - Transcription notice posted on every join; other bots ignored by default; at most maxSpeakers people transcribed at once. - Registered chat channels: live message events, history reads, sends split at 2,000 characters with mentions disabled; Message Content intent checked before login. - The app starts the Python voice worker with a fresh token in the environment, restarts it with backoff, and the worker client reconnects and fails in-flight TTS on a lost connection. - Spec in app/src/core/discord_core.spec.md; Vitest unit tests, a protocol test against the real Python worker server with fake engines, and an opt-in live test with two bots on real Discord. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.9 KiB
TypeScript
62 lines
2.9 KiB
TypeScript
import { mkdtempSync, writeFileSync } from "node:fs";
|
||
import { tmpdir } from "node:os";
|
||
import { join } from "node:path";
|
||
import { describe, expect, it } from "vitest";
|
||
import { defaultSettings, loadSettings, parseSettings, SettingsError } from "../src/core/settings.js";
|
||
|
||
const ID = "123456789012345678";
|
||
|
||
describe("settings", () => {
|
||
it("an empty file gives the defaults", () => {
|
||
expect(parseSettings({})).toEqual(defaultSettings());
|
||
});
|
||
|
||
it("a missing file gives the defaults", () => {
|
||
const dir = mkdtempSync(join(process.env.TMPDIR ?? tmpdir(), "jarvis-settings-"));
|
||
expect(loadSettings(join(dir, "nope.json"))).toEqual(defaultSettings());
|
||
});
|
||
|
||
it("reads a full file, BOM included", () => {
|
||
const dir = mkdtempSync(join(process.env.TMPDIR ?? tmpdir(), "jarvis-settings-"));
|
||
const path = join(dir, "settings.json");
|
||
writeFileSync(path, "" + JSON.stringify({
|
||
discord: { guildId: ID, voiceChannelId: ID, commandName: "jarvis", ephemeralReplies: false },
|
||
voice: { maxSpeakers: 3, listenToBots: true, joinNotice: "알림", wakeWords: [" 자비스 ", "", "javis"],
|
||
stt: { end_silence_ms: 250 } },
|
||
chatChannels: [{ id: ID, name: "일정", description: "일정 올리는 곳", send: false }],
|
||
voiceWorker: { python: "/venv/bin/python", cwd: "/repo/src", args: ["--melo-python", "/m/python"] },
|
||
somethingNew: 1,
|
||
}));
|
||
const s = loadSettings(path);
|
||
expect(s.discord).toEqual({ guildId: ID, voiceChannelId: ID, commandName: "jarvis", ephemeralReplies: false });
|
||
expect(s.voice).toEqual({ maxSpeakers: 3, listenToBots: true, joinNotice: "알림", wakeWords: ["자비스", "javis"],
|
||
stt: { end_silence_ms: 250 } });
|
||
expect(s.chatChannels).toEqual([{ id: ID, name: "일정", description: "일정 올리는 곳", read: true, send: false }]);
|
||
expect(s.voiceWorker.args).toEqual(["--melo-python", "/m/python"]);
|
||
});
|
||
|
||
it.each([
|
||
[{ discord: { guildId: "abc" } }, /discord.guildId/],
|
||
[{ discord: { commandName: "Jarvis" } }, /commandName/],
|
||
[{ discord: { commandName: "두 단어" } }, /commandName/],
|
||
[{ voice: { maxSpeakers: 11 } }, /maxSpeakers/],
|
||
[{ voice: { maxSpeakers: 0 } }, /maxSpeakers/],
|
||
[{ voice: { joinNotice: " " } }, /joinNotice/],
|
||
[{ chatChannels: [{ id: ID }, { id: ID }] }, /twice/],
|
||
[{ chatChannels: [{ id: "1" }] }, /chatChannels\[0\].id/],
|
||
[{ chatChannels: {} }, /chatChannels/],
|
||
[{ voice: [] }, /voice/],
|
||
[[], /object/],
|
||
])("refuses %j", (raw, message) => {
|
||
expect(() => parseSettings(raw)).toThrow(SettingsError);
|
||
expect(() => parseSettings(raw)).toThrow(message);
|
||
});
|
||
|
||
it("reports invalid JSON with the path", () => {
|
||
const dir = mkdtempSync(join(process.env.TMPDIR ?? tmpdir(), "jarvis-settings-"));
|
||
const path = join(dir, "settings.json");
|
||
writeFileSync(path, "{ nope");
|
||
expect(() => loadSettings(path)).toThrow(/not valid JSON/);
|
||
});
|
||
});
|