





















@@ -1,9 +1,9 @@
11import { Readable } from "node:stream";
2-import { describe, expect, it } from "vitest";
3-import { decodeOpusStream, resolveOpusDecoderPreference } from "./audio.js";
2+import { describe, expect, it, vi } from "vitest";
3+import { decodeOpusStream, decodeOpusStreamChunks, resolveOpusDecoderPreference } from "./audio.js";
4455describe("discord voice opus decoder selection", () => {
6-it("defaults to the pure-JS opusscript decoder", async () => {
6+it("defaults to the safe WASM opus decoder", async () => {
77const verbose: string[] = [];
88const warnings: string[] = [];
99const previousPreference = process.env.OPENCLAW_DISCORD_OPUS_DECODER;
@@ -16,7 +16,7 @@ describe("discord voice opus decoder selection", () => {
1616});
17171818expect(decoded.length).toBe(0);
19-expect(verbose).toContain("opus decoder: opusscript");
19+expect(verbose).toContain("opus decoder: opus-decoder");
2020expect(warnings).toEqual([]);
2121} finally {
2222if (previousPreference === undefined) {
@@ -32,7 +32,7 @@ describe("discord voice opus decoder selection", () => {
3232delete process.env.OPENCLAW_DISCORD_OPUS_DECODER;
33333434try {
35-expect(resolveOpusDecoderPreference()).toBe("opusscript");
35+expect(resolveOpusDecoderPreference()).toBe("wasm");
3636expect(resolveOpusDecoderPreference("opusscript")).toBe("opusscript");
3737expect(resolveOpusDecoderPreference("native")).toBe("native");
3838expect(resolveOpusDecoderPreference("@discordjs/opus")).toBe("native");
@@ -44,4 +44,23 @@ describe("discord voice opus decoder selection", () => {
4444}
4545}
4646});
47+48+it("surfaces chunk decode stream failures to callers", async () => {
49+const err = new Error("memory access out of bounds");
50+const onError = vi.fn();
51+const stream = new Readable({
52+read() {
53+this.destroy(err);
54+},
55+});
56+57+await decodeOpusStreamChunks(stream, {
58+onChunk: vi.fn(),
59+ onError,
60+onVerbose: vi.fn(),
61+onWarn: vi.fn(),
62+});
63+64+expect(onError).toHaveBeenCalledWith(err);
65+});
4766});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。