mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-14 02:31:24 +00:00
test: make talk and compaction config checks pure
This commit is contained in:
@@ -1,25 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { TALK_TEST_PROVIDER_ID } from "../test-utils/talk-test-provider.js";
|
||||
import { createConfigIO } from "./io.js";
|
||||
import { buildTalkConfigResponse, normalizeTalkSection } from "./talk.js";
|
||||
|
||||
async function withTempConfig(
|
||||
config: unknown,
|
||||
run: (configPath: string) => Promise<void>,
|
||||
): Promise<void> {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-talk-"));
|
||||
const configPath = path.join(dir, "openclaw.json");
|
||||
await fs.writeFile(configPath, JSON.stringify(config, null, 2));
|
||||
try {
|
||||
await run(configPath);
|
||||
} finally {
|
||||
await fs.rm(dir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
describe("talk normalization", () => {
|
||||
it("keeps core Talk normalization generic and ignores legacy provider-flat fields", () => {
|
||||
const normalized = normalizeTalkSection({
|
||||
@@ -137,20 +119,13 @@ describe("talk normalization", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("does not inject provider apiKey defaults during snapshot materialization", async () => {
|
||||
await withTempConfig(
|
||||
{
|
||||
talk: {
|
||||
voiceId: "voice-123",
|
||||
},
|
||||
},
|
||||
async (configPath) => {
|
||||
const io = createConfigIO({ configPath });
|
||||
const snapshot = await io.readConfigFileSnapshot();
|
||||
expect(snapshot.config.talk?.provider).toBeUndefined();
|
||||
expect(snapshot.config.talk?.providers?.elevenlabs?.voiceId).toBe("voice-123");
|
||||
expect(snapshot.config.talk?.providers?.elevenlabs?.apiKey).toBeUndefined();
|
||||
},
|
||||
);
|
||||
it("does not inject provider apiKey defaults during snapshot materialization", () => {
|
||||
const payload = buildTalkConfigResponse({
|
||||
voiceId: "voice-123",
|
||||
});
|
||||
|
||||
expect(payload?.provider).toBe("elevenlabs");
|
||||
expect(payload?.resolved?.config.voiceId).toBe("voice-123");
|
||||
expect(payload?.resolved?.config.apiKey).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user