fix: validate voice-call legacy streaming numbers · openclaw/openclaw@b5d90ae
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
File tree
extensions/voice-call/src
| Original file line number | Diff line number | Diff line change |
|---|
@@ -62,6 +62,38 @@ describe("voice-call config compatibility", () => {
|
62 | 62 | expect(streaming?.sttModel).toBeUndefined(); |
63 | 63 | }); |
64 | 64 | |
| 65 | +it("does not migrate non-finite legacy streaming numbers", () => { |
| 66 | +const migration = migrateVoiceCallLegacyConfigInput({ |
| 67 | +value: { |
| 68 | +streaming: { |
| 69 | +silenceDurationMs: Number.NaN, |
| 70 | +vadThreshold: Number.POSITIVE_INFINITY, |
| 71 | +}, |
| 72 | +}, |
| 73 | +configPathPrefix: "plugins.entries.voice-call.config", |
| 74 | +}); |
| 75 | +const streaming = migration.config.streaming as |
| 76 | +| { |
| 77 | +providers?: { |
| 78 | +openai?: { |
| 79 | +silenceDurationMs?: number; |
| 80 | +vadThreshold?: number; |
| 81 | +}; |
| 82 | +}; |
| 83 | +} |
| 84 | +| undefined; |
| 85 | + |
| 86 | +expect(streaming?.providers?.openai).toBeUndefined(); |
| 87 | +expect(migration.changes).toEqual([ |
| 88 | +"Removed invalid plugins.entries.voice-call.config.streaming.silenceDurationMs.", |
| 89 | +"Removed invalid plugins.entries.voice-call.config.streaming.vadThreshold.", |
| 90 | +]); |
| 91 | +expect(migration.issues.map((issue) => issue.path)).toEqual([ |
| 92 | +"streaming.silenceDurationMs", |
| 93 | +"streaming.vadThreshold", |
| 94 | +]); |
| 95 | +}); |
| 96 | + |
65 | 97 | it("reports doctor-oriented legacy issues and warnings", () => { |
66 | 98 | const raw = { |
67 | 99 | provider: "log", |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -15,7 +15,7 @@ const getString = readStringField;
|
15 | 15 | |
16 | 16 | function getNumber(obj: Record<string, unknown> | undefined, key: string): number | undefined { |
17 | 17 | const value = obj?.[key]; |
18 | | -return typeof value === "number" ? value : undefined; |
| 18 | +return typeof value === "number" && Number.isFinite(value) ? value : undefined; |
19 | 19 | } |
20 | 20 | |
21 | 21 | function mergeProviderConfig( |
@@ -204,15 +204,19 @@ export function migrateVoiceCallLegacyConfigInput(params: {
|
204 | 204 | `Moved ${configPathPrefix}.streaming.sttModel → ${configPathPrefix}.streaming.providers.openai.model.`, |
205 | 205 | ); |
206 | 206 | } |
207 | | -if (typeof streaming?.silenceDurationMs === "number") { |
| 207 | +if (getNumber(streaming, "silenceDurationMs") !== undefined) { |
208 | 208 | changes.push( |
209 | 209 | `Moved ${configPathPrefix}.streaming.silenceDurationMs → ${configPathPrefix}.streaming.providers.openai.silenceDurationMs.`, |
210 | 210 | ); |
| 211 | +} else if (typeof streaming?.silenceDurationMs === "number") { |
| 212 | +changes.push(`Removed invalid ${configPathPrefix}.streaming.silenceDurationMs.`); |
211 | 213 | } |
212 | | -if (typeof streaming?.vadThreshold === "number") { |
| 214 | +if (getNumber(streaming, "vadThreshold") !== undefined) { |
213 | 215 | changes.push( |
214 | 216 | `Moved ${configPathPrefix}.streaming.vadThreshold → ${configPathPrefix}.streaming.providers.openai.vadThreshold.`, |
215 | 217 | ); |
| 218 | +} else if (typeof streaming?.vadThreshold === "number") { |
| 219 | +changes.push(`Removed invalid ${configPathPrefix}.streaming.vadThreshold.`); |
216 | 220 | } |
217 | 221 | |
218 | 222 | return { config, changes, issues }; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。