mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 08:00:42 +00:00
fix: cache tmp dir resolution, add test for TTS temp path
Address review feedback: - Cache resolvePreferredOpenClawTmpDir() result to avoid sync I/O on every media path check and prevent mkdir side effects - Add test for TTS voice output from /tmp/openclaw/ path
This commit is contained in:
@@ -176,4 +176,24 @@ describe("createReplyMediaPathNormalizer", () => {
|
||||
mediaUrls: ["/Users/peter/.openclaw/media/outbound/persisted.png"],
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps TTS voice output from the OpenClaw temp directory", async () => {
|
||||
// resolvePreferredOpenClawTmpDir() returns /tmp/openclaw on POSIX when it exists.
|
||||
// We rely on the real function (no mock) since the test environment has /tmp/openclaw.
|
||||
const normalize = createReplyMediaPathNormalizer({
|
||||
cfg: {},
|
||||
sessionKey: "session-key",
|
||||
workspaceDir: "/tmp/agent-workspace",
|
||||
});
|
||||
|
||||
const result = await normalize({
|
||||
mediaUrls: ["/tmp/openclaw/tts-abc123/voice-1234567890.opus"],
|
||||
});
|
||||
|
||||
expect(result).toMatchObject({
|
||||
mediaUrl: "/tmp/openclaw/tts-abc123/voice-1234567890.opus",
|
||||
mediaUrls: ["/tmp/openclaw/tts-abc123/voice-1234567890.opus"],
|
||||
});
|
||||
expect(saveMediaSource).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -60,10 +60,12 @@ function isAllowedAbsoluteReplyMediaPath(params: {
|
||||
* These are trusted paths written by OpenClaw's own tooling
|
||||
* (TTS, media processing, etc.) and should be deliverable as reply media.
|
||||
*/
|
||||
let cachedTmpRoot: string | undefined;
|
||||
|
||||
function isOpenClawTmpPath(candidate: string): boolean {
|
||||
try {
|
||||
const tmpRoot = resolvePreferredOpenClawTmpDir();
|
||||
return isPathInside(tmpRoot, candidate);
|
||||
cachedTmpRoot ??= resolvePreferredOpenClawTmpDir();
|
||||
return isPathInside(cachedTmpRoot, candidate);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user