mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 07:11:25 +00:00
refactor(test): extract shared fixture helpers in gateway and outbound tests
This commit is contained in:
@@ -78,6 +78,32 @@ const runDrySend = (params: {
|
||||
action: "send",
|
||||
});
|
||||
|
||||
async function expectSandboxMediaRewrite(params: {
|
||||
sandboxDir: string;
|
||||
media?: string;
|
||||
message?: string;
|
||||
expectedRelativePath: string;
|
||||
}) {
|
||||
const result = await runDrySend({
|
||||
cfg: slackConfig,
|
||||
actionParams: {
|
||||
channel: "slack",
|
||||
target: "#C12345678",
|
||||
...(params.media ? { media: params.media } : {}),
|
||||
...(params.message ? { message: params.message } : {}),
|
||||
},
|
||||
sandboxRoot: params.sandboxDir,
|
||||
});
|
||||
|
||||
expect(result.kind).toBe("send");
|
||||
if (result.kind !== "send") {
|
||||
throw new Error("expected send result");
|
||||
}
|
||||
expect(result.sendResult?.mediaUrl).toBe(
|
||||
path.join(params.sandboxDir, params.expectedRelativePath),
|
||||
);
|
||||
}
|
||||
|
||||
function createAlwaysConfiguredPluginConfig(account: Record<string, unknown> = { enabled: true }) {
|
||||
return {
|
||||
listAccountIds: () => ["default"],
|
||||
@@ -566,63 +592,33 @@ describe("runMessageAction sandboxed media validation", () => {
|
||||
|
||||
it("rewrites sandbox-relative media paths", async () => {
|
||||
await withSandbox(async (sandboxDir) => {
|
||||
const result = await runDrySend({
|
||||
cfg: slackConfig,
|
||||
actionParams: {
|
||||
channel: "slack",
|
||||
target: "#C12345678",
|
||||
media: "./data/file.txt",
|
||||
message: "",
|
||||
},
|
||||
sandboxRoot: sandboxDir,
|
||||
await expectSandboxMediaRewrite({
|
||||
sandboxDir,
|
||||
media: "./data/file.txt",
|
||||
message: "",
|
||||
expectedRelativePath: path.join("data", "file.txt"),
|
||||
});
|
||||
|
||||
expect(result.kind).toBe("send");
|
||||
if (result.kind !== "send") {
|
||||
throw new Error("expected send result");
|
||||
}
|
||||
expect(result.sendResult?.mediaUrl).toBe(path.join(sandboxDir, "data", "file.txt"));
|
||||
});
|
||||
});
|
||||
|
||||
it("rewrites /workspace media paths to host sandbox root", async () => {
|
||||
await withSandbox(async (sandboxDir) => {
|
||||
const result = await runDrySend({
|
||||
cfg: slackConfig,
|
||||
actionParams: {
|
||||
channel: "slack",
|
||||
target: "#C12345678",
|
||||
media: "/workspace/data/file.txt",
|
||||
message: "",
|
||||
},
|
||||
sandboxRoot: sandboxDir,
|
||||
await expectSandboxMediaRewrite({
|
||||
sandboxDir,
|
||||
media: "/workspace/data/file.txt",
|
||||
message: "",
|
||||
expectedRelativePath: path.join("data", "file.txt"),
|
||||
});
|
||||
|
||||
expect(result.kind).toBe("send");
|
||||
if (result.kind !== "send") {
|
||||
throw new Error("expected send result");
|
||||
}
|
||||
expect(result.sendResult?.mediaUrl).toBe(path.join(sandboxDir, "data", "file.txt"));
|
||||
});
|
||||
});
|
||||
|
||||
it("rewrites MEDIA directives under sandbox", async () => {
|
||||
await withSandbox(async (sandboxDir) => {
|
||||
const result = await runDrySend({
|
||||
cfg: slackConfig,
|
||||
actionParams: {
|
||||
channel: "slack",
|
||||
target: "#C12345678",
|
||||
message: "Hello\nMEDIA: ./data/note.ogg",
|
||||
},
|
||||
sandboxRoot: sandboxDir,
|
||||
await expectSandboxMediaRewrite({
|
||||
sandboxDir,
|
||||
message: "Hello\nMEDIA: ./data/note.ogg",
|
||||
expectedRelativePath: path.join("data", "note.ogg"),
|
||||
});
|
||||
|
||||
expect(result.kind).toBe("send");
|
||||
if (result.kind !== "send") {
|
||||
throw new Error("expected send result");
|
||||
}
|
||||
expect(result.sendResult?.mediaUrl).toBe(path.join(sandboxDir, "data", "note.ogg"));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user