


























@@ -3,6 +3,7 @@ import os from "node:os";
33import path from "node:path";
44import { pathToFileURL } from "node:url";
55import { describe, expect, it, vi } from "vitest";
6+import { resolvePreferredOpenClawTmpDir } from "../../../infra/tmp-openclaw-dir.js";
67import { createHostSandboxFsBridge } from "../../test-helpers/host-sandbox-fs-bridge.js";
78import { createUnsafeMountedSandbox } from "../../test-helpers/unsafe-mounted-sandbox.js";
89import {
@@ -81,6 +82,54 @@ describe("detectImageReferences", () => {
8182});
8283});
838485+it("ignores OpenClaw CLI image cache paths from prior prompt transcripts", () => {
86+const refs = detectImageReferences(
87+[
88+'<system-reminder>Called the Read tool with {"file_path":"/Users/ada/.openclaw/workspace/.openclaw-cli-images/stale.png"}</system-reminder>',
89+"Compare it with /Users/ada/Pictures/current.png",
90+].join("\n"),
91+);
92+93+expect(refs).toStrictEqual([
94+{
95+raw: "/Users/ada/Pictures/current.png",
96+type: "path",
97+resolved: "/Users/ada/Pictures/current.png",
98+},
99+]);
100+});
101+102+it("ignores temporary OpenClaw CLI image cache paths", () => {
103+expectNoImageReferences(
104+`Prior turn wrote ${path.join(resolvePreferredOpenClawTmpDir(), "openclaw-cli-images", "stale.jpg")}`,
105+);
106+expectNoImageReferences(
107+`[media attached: ${path.join(resolvePreferredOpenClawTmpDir(), "openclaw-cli-images", "stale.jpg")} (image/jpeg)]`,
108+);
109+expectNoImageReferences(
110+`Prior turn wrote ${path.join(os.tmpdir(), "openclaw", "openclaw-cli-images", "stale.jpg")}`,
111+);
112+expectNoImageReferences(
113+`Prior turn wrote ${path.join(os.tmpdir(), "openclaw-501", "openclaw-cli-images", "stale.jpg")}`,
114+);
115+});
116+117+it("ignores file URLs into the OpenClaw CLI image cache", () => {
118+const stalePath = path.join(os.tmpdir(), "openclaw", "openclaw-cli-images", "stale.png");
119+120+expectNoImageReferences(`Prior turn wrote ${pathToFileURL(stalePath).href}`);
121+});
122+123+it("detects normal user image paths in similarly named directories", () => {
124+expect(detectImageReferences("/workspace/openclaw-cli-images/current.png")).toStrictEqual([
125+{
126+raw: "/workspace/openclaw-cli-images/current.png",
127+type: "path",
128+resolved: "/workspace/openclaw-cli-images/current.png",
129+},
130+]);
131+});
132+84133it("detects multiple image references in a prompt", () => {
85134const refs = expectImageReferenceCount(
86135`
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。