mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:50:42 +00:00
test: share debug proxy reset helper
This commit is contained in:
@@ -3,6 +3,7 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { installDebugProxyTestResetHooks } from "../test-support/debug-proxy-env-test-helpers.js";
|
||||
|
||||
vi.mock("node-edge-tts", () => ({
|
||||
EdgeTTS: class {
|
||||
@@ -20,28 +21,7 @@ import * as ttsModule from "./tts.js";
|
||||
const TEST_CFG = {} as OpenClawConfig;
|
||||
|
||||
describe("listMicrosoftVoices", () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
const proxyEnvKeys = [
|
||||
"OPENCLAW_DEBUG_PROXY_ENABLED",
|
||||
"OPENCLAW_DEBUG_PROXY_DB_PATH",
|
||||
"OPENCLAW_DEBUG_PROXY_BLOB_DIR",
|
||||
"OPENCLAW_DEBUG_PROXY_SESSION_ID",
|
||||
] as const;
|
||||
let priorProxyEnv: Partial<Record<(typeof proxyEnvKeys)[number], string | undefined>> = {};
|
||||
|
||||
afterEach(() => {
|
||||
globalThis.fetch = originalFetch;
|
||||
vi.restoreAllMocks();
|
||||
for (const key of proxyEnvKeys) {
|
||||
const value = priorProxyEnv[key];
|
||||
if (value === undefined) {
|
||||
delete process.env[key];
|
||||
} else {
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
priorProxyEnv = {};
|
||||
});
|
||||
const proxyReset = installDebugProxyTestResetHooks();
|
||||
|
||||
it("maps Microsoft voice metadata into speech voice options", async () => {
|
||||
globalThis.fetch = vi.fn().mockResolvedValue(
|
||||
@@ -89,9 +69,7 @@ describe("listMicrosoftVoices", () => {
|
||||
|
||||
it("records voice discovery exchanges in debug proxy capture mode", async () => {
|
||||
const tempDir = mkdtempSync(path.join(os.tmpdir(), "microsoft-voices-capture-"));
|
||||
priorProxyEnv = Object.fromEntries(
|
||||
proxyEnvKeys.map((key) => [key, process.env[key]]),
|
||||
) as typeof priorProxyEnv;
|
||||
proxyReset.captureProxyEnv();
|
||||
process.env.OPENCLAW_DEBUG_PROXY_ENABLED = "1";
|
||||
process.env.OPENCLAW_DEBUG_PROXY_DB_PATH = path.join(tempDir, "capture.sqlite");
|
||||
process.env.OPENCLAW_DEBUG_PROXY_BLOB_DIR = path.join(tempDir, "blobs");
|
||||
@@ -134,9 +112,7 @@ describe("listMicrosoftVoices", () => {
|
||||
|
||||
it("does not double-capture voice discovery when the global fetch patch is installed", async () => {
|
||||
const tempDir = mkdtempSync(path.join(os.tmpdir(), "microsoft-voices-global-"));
|
||||
priorProxyEnv = Object.fromEntries(
|
||||
proxyEnvKeys.map((key) => [key, process.env[key]]),
|
||||
) as typeof priorProxyEnv;
|
||||
proxyReset.captureProxyEnv();
|
||||
process.env.OPENCLAW_DEBUG_PROXY_ENABLED = "1";
|
||||
process.env.OPENCLAW_DEBUG_PROXY_DB_PATH = path.join(tempDir, "capture.sqlite");
|
||||
process.env.OPENCLAW_DEBUG_PROXY_BLOB_DIR = path.join(tempDir, "blobs");
|
||||
@@ -175,7 +151,7 @@ describe("listMicrosoftVoices", () => {
|
||||
const kinds = events.map((event) => String(event.kind)).toSorted();
|
||||
expect(kinds).toEqual(["request", "response"]);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
globalThis.fetch = proxyReset.originalFetch;
|
||||
finalizeDebugProxyCapture();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user