mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-26 16:25:14 +00:00
Summary: - The PR updates memory-core `memory_search` result shaping to surface `corpus` from each hit's `source`, adds ... session corpus-label coverage, adds a changelog entry, and includes a small tempdir test assertion cleanup. - Reproducibility: yes. Current main has a high-confidence source-level reproduction: session hits keep `sourc ... the final mapper hard-codes `corpus: "memory"`; the PR body also supplies live Gateway before/after output. Automerge notes: - PR branch already contained follow-up commit before automerge: test(memory): clarify corpus label regression - PR branch already contained follow-up commit before automerge: fix(memory): type session corpus results - PR branch already contained follow-up commit before automerge: fix(memory): preserve session corpus labels - PR branch already contained follow-up commit before automerge: fix(clawsweeper): address review for automerge-openclaw-openclaw-7189… Validation: - ClawSweeper review passed for head02d0db0861. - Required merge gates passed before the squash merge. Prepared head SHA:02d0db0861Review: https://github.com/openclaw/openclaw/pull/71898#issuecomment-4340800992 Co-authored-by: Ruben Cuevas <hi@rubencu.com> Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
import fs from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { resolvePreferredOpenClawTmpDir } from "../infra/tmp-openclaw-dir.js";
|
|
import { getImageMetadata } from "./image-ops.js";
|
|
|
|
describe("image-ops temp dir", () => {
|
|
let createdTempDir = "";
|
|
|
|
beforeEach(() => {
|
|
process.env.OPENCLAW_IMAGE_BACKEND = "sips";
|
|
const originalMkdtemp = fs.mkdtemp.bind(fs);
|
|
vi.spyOn(fs, "mkdtemp").mockImplementation(async (prefix) => {
|
|
createdTempDir = await originalMkdtemp(prefix);
|
|
return createdTempDir;
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
delete process.env.OPENCLAW_IMAGE_BACKEND;
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("creates sips temp dirs under the secured OpenClaw tmp root", async () => {
|
|
const secureRoot = await fs.realpath(resolvePreferredOpenClawTmpDir());
|
|
|
|
await getImageMetadata(Buffer.from("image"));
|
|
|
|
expect(fs.mkdtemp).toHaveBeenCalledTimes(1);
|
|
const [prefix] = vi.mocked(fs.mkdtemp).mock.calls[0] ?? [];
|
|
expect(typeof prefix).toBe("string");
|
|
const uuidPrefix = path.join(secureRoot, "openclaw-img-");
|
|
expect(prefix?.startsWith(uuidPrefix)).toBe(true);
|
|
expect(prefix?.endsWith("-")).toBe(true);
|
|
const uuid = prefix?.slice(uuidPrefix.length, -1) ?? "";
|
|
expect(uuid).toHaveLength(36);
|
|
expect(/^[0-9a-f-]+$/u.test(uuid)).toBe(true);
|
|
expect([8, 13, 18, 23].map((index) => uuid[index])).toEqual(["-", "-", "-", "-"]);
|
|
expect(path.dirname(prefix ?? "")).toBe(secureRoot);
|
|
expect(createdTempDir.startsWith(prefix ?? "")).toBe(true);
|
|
let accessError: unknown;
|
|
try {
|
|
await fs.access(createdTempDir);
|
|
} catch (error) {
|
|
accessError = error;
|
|
}
|
|
expect(accessError).toBeInstanceOf(Error);
|
|
expect((accessError as NodeJS.ErrnoException).code).toBe("ENOENT");
|
|
});
|
|
});
|