
























@@ -4,6 +4,7 @@ import type { IncomingMessage } from "node:http";
44import os from "node:os";
55import path from "node:path";
66import { describe, expect, it, vi } from "vitest";
7+import { resolveStateDir } from "../config/paths.js";
78import { approveDevicePairing, requestDevicePairing } from "../infra/device-pairing.js";
89import { resolvePreferredOpenClawTmpDir } from "../infra/tmp-openclaw-dir.js";
910import type { ResolvedGatewayAuth } from "./auth.js";
@@ -331,6 +332,47 @@ describe("handleControlUiHttpRequest", () => {
331332});
332333});
333334335+it("serves assistant media from canonical inbound media refs", async () => {
336+const stateDir = resolveStateDir();
337+const id = `ui-media-ref-${Date.now()}-${Math.random().toString(36).slice(2)}.png`;
338+const filePath = path.join(stateDir, "media", "inbound", id);
339+await fs.mkdir(path.dirname(filePath), { recursive: true });
340+await fs.writeFile(filePath, Buffer.from("not-a-real-png"));
341+342+try {
343+const { res, handled } = await runAssistantMediaRequest({
344+url: `/__openclaw__/assistant-media?source=${encodeURIComponent(`media://inbound/${id}`)}&token=test-token`,
345+method: "GET",
346+auth: { mode: "token", token: "test-token", allowTailscale: false },
347+});
348+expect(handled).toBe(true);
349+expect(res.statusCode).toBe(200);
350+} finally {
351+await fs.rm(filePath, { force: true });
352+}
353+});
354+355+it("reports assistant media metadata for canonical inbound media refs", async () => {
356+const stateDir = resolveStateDir();
357+const id = `ui-media-ref-meta-${Date.now()}-${Math.random().toString(36).slice(2)}.png`;
358+const filePath = path.join(stateDir, "media", "inbound", id);
359+await fs.mkdir(path.dirname(filePath), { recursive: true });
360+await fs.writeFile(filePath, Buffer.from("not-a-real-png"));
361+362+try {
363+const { res, handled, end } = await runAssistantMediaRequest({
364+url: `/__openclaw__/assistant-media?meta=1&source=${encodeURIComponent(`media://inbound/${id}`)}&token=test-token`,
365+method: "GET",
366+auth: { mode: "token", token: "test-token", allowTailscale: false },
367+});
368+expect(handled).toBe(true);
369+expect(res.statusCode).toBe(200);
370+expect(JSON.parse(String(end.mock.calls[0]?.[0] ?? ""))).toEqual({ available: true });
371+} finally {
372+await fs.rm(filePath, { force: true });
373+}
374+});
375+334376it("rejects assistant local media outside allowed preview roots", async () => {
335377const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-ui-media-blocked-"));
336378try {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。