fix(tui): strip inbound metadata blocks from user messages (clean rewrite) (#22345)

* fix(tui): strip inbound metadata blocks from user text

* chore: clean up metadata-strip format and changelog credit

* chore: format tui metadata-strip tests

* test: align metadata-strip regression expectations

* refactor: reuse canonical inbound metadata stripper

* test: allow tmp media fixture paths in media-understanding tests

* refactor: reuse canonical inbound metadata stripper

* format: fix changelog blank line after headings

* test: fix unrelated check typing regressions

* test: align memory async mock embedding signatures

* test: avoid tsgo mock typing pitfall

* test: restore async search mock typings in merge tree

* test: trigger ci rerun without behavior change

* chore: dedupe todays changelog entries

* fix: dedupe sqlite mock keys in qmd manager test

* Update qmd-manager.test.ts

* test: align chat metadata sanitization expectation
This commit is contained in:
Vincent Koc
2026-02-20 23:52:43 -05:00
committed by GitHub
parent 338ae269d6
commit 35be87b09b
10 changed files with 101 additions and 119 deletions

View File

@@ -4,7 +4,6 @@ import path from "node:path";
import { describe, expect, it } from "vitest";
import type { MsgContext } from "../auto-reply/templating.js";
import type { OpenClawConfig } from "../config/config.js";
import { resolvePreferredOpenClawTmpDir } from "../infra/tmp-openclaw-dir.js";
import {
buildProviderRegistry,
createMediaAttachmentCache,
@@ -12,78 +11,96 @@ import {
runCapability,
} from "./runner.js";
async function withAudioFixture(
run: (params: {
ctx: MsgContext;
media: ReturnType<typeof normalizeMediaAttachments>;
cache: ReturnType<typeof createMediaAttachmentCache>;
}) => Promise<void>,
) {
const originalPath = process.env.PATH;
process.env.PATH = "";
const tmpPath = path.join(os.tmpdir(), `openclaw-deepgram-${Date.now()}.wav`);
await fs.writeFile(tmpPath, Buffer.from("RIFF"));
const ctx: MsgContext = { MediaPath: tmpPath, MediaType: "audio/wav" };
const media = normalizeMediaAttachments(ctx);
const cache = createMediaAttachmentCache(media, {
localPathRoots: [path.dirname(tmpPath)],
});
try {
await run({ ctx, media, cache });
} finally {
process.env.PATH = originalPath;
await cache.cleanup();
await fs.unlink(tmpPath).catch(() => {});
}
}
describe("runCapability deepgram provider options", () => {
it("merges provider options, headers, and baseUrl overrides", async () => {
const tmpPath = path.join(os.tmpdir(), `openclaw-deepgram-${Date.now()}.wav`);
await fs.writeFile(tmpPath, Buffer.from("RIFF"));
const ctx: MsgContext = { MediaPath: tmpPath, MediaType: "audio/wav" };
const media = normalizeMediaAttachments(ctx);
const cache = createMediaAttachmentCache(media, {
localPathRoots: [resolvePreferredOpenClawTmpDir(), os.tmpdir()],
});
await withAudioFixture(async ({ ctx, media, cache }) => {
let seenQuery: Record<string, string | number | boolean> | undefined;
let seenBaseUrl: string | undefined;
let seenHeaders: Record<string, string> | undefined;
let seenQuery: Record<string, string | number | boolean> | undefined;
let seenBaseUrl: string | undefined;
let seenHeaders: Record<string, string> | undefined;
const providerRegistry = buildProviderRegistry({
deepgram: {
id: "deepgram",
capabilities: ["audio"],
transcribeAudio: async (req) => {
seenQuery = req.query;
seenBaseUrl = req.baseUrl;
seenHeaders = req.headers;
return { text: "ok", model: req.model };
},
},
});
const cfg = {
models: {
providers: {
deepgram: {
baseUrl: "https://provider.example",
apiKey: "test-key",
headers: { "X-Provider": "1" },
models: [],
const providerRegistry = buildProviderRegistry({
deepgram: {
id: "deepgram",
capabilities: ["audio"],
transcribeAudio: async (req) => {
seenQuery = req.query;
seenBaseUrl = req.baseUrl;
seenHeaders = req.headers;
return { text: "ok", model: req.model };
},
},
},
tools: {
media: {
audio: {
enabled: true,
baseUrl: "https://config.example",
headers: { "X-Config": "2" },
providerOptions: {
deepgram: {
detect_language: true,
punctuate: true,
},
});
const cfg = {
models: {
providers: {
deepgram: {
baseUrl: "https://provider.example",
apiKey: "test-key",
headers: { "X-Provider": "1" },
models: [],
},
deepgram: { smartFormat: true },
models: [
{
provider: "deepgram",
model: "nova-3",
baseUrl: "https://entry.example",
headers: { "X-Entry": "3" },
providerOptions: {
deepgram: {
detectLanguage: false,
punctuate: false,
smart_format: true,
},
},
},
tools: {
media: {
audio: {
enabled: true,
baseUrl: "https://config.example",
headers: { "X-Config": "2" },
providerOptions: {
deepgram: {
detect_language: true,
punctuate: true,
},
},
],
deepgram: { smartFormat: true },
models: [
{
provider: "deepgram",
model: "nova-3",
baseUrl: "https://entry.example",
headers: { "X-Entry": "3" },
providerOptions: {
deepgram: {
detectLanguage: false,
punctuate: false,
smart_format: true,
},
},
},
],
},
},
},
},
} as unknown as OpenClawConfig;
} as unknown as OpenClawConfig;
try {
const result = await runCapability({
capability: "audio",
cfg,
@@ -105,9 +122,6 @@ describe("runCapability deepgram provider options", () => {
smart_format: true,
});
expect((seenQuery as Record<string, unknown>)["detectLanguage"]).toBeUndefined();
} finally {
await cache.cleanup();
await fs.unlink(tmpPath).catch(() => {});
}
});
});
});