mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 22:11:23 +00:00
refactor(test): reuse shared skill writer in sandbox and bundled tests
This commit is contained in:
@@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|||||||
import type { OpenClawConfig } from "../config/config.js";
|
import type { OpenClawConfig } from "../config/config.js";
|
||||||
import { captureFullEnv } from "../test-utils/env.js";
|
import { captureFullEnv } from "../test-utils/env.js";
|
||||||
import { resolveSandboxContext } from "./sandbox.js";
|
import { resolveSandboxContext } from "./sandbox.js";
|
||||||
|
import { writeSkill } from "./skills.e2e-test-helpers.js";
|
||||||
|
|
||||||
vi.mock("./sandbox/docker.js", () => ({
|
vi.mock("./sandbox/docker.js", () => ({
|
||||||
ensureSandboxContainer: vi.fn(async () => "openclaw-sbx-test"),
|
ensureSandboxContainer: vi.fn(async () => "openclaw-sbx-test"),
|
||||||
@@ -18,16 +19,6 @@ vi.mock("./sandbox/prune.js", () => ({
|
|||||||
maybePruneSandboxes: vi.fn(async () => undefined),
|
maybePruneSandboxes: vi.fn(async () => undefined),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
async function writeSkill(params: { dir: string; name: string; description: string }) {
|
|
||||||
const { dir, name, description } = params;
|
|
||||||
await fs.mkdir(dir, { recursive: true });
|
|
||||||
await fs.writeFile(
|
|
||||||
path.join(dir, "SKILL.md"),
|
|
||||||
`---\nname: ${name}\ndescription: ${description}\n---\n\n# ${name}\n`,
|
|
||||||
"utf-8",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("sandbox skill mirroring", () => {
|
describe("sandbox skill mirroring", () => {
|
||||||
let envSnapshot: ReturnType<typeof captureFullEnv>;
|
let envSnapshot: ReturnType<typeof captureFullEnv>;
|
||||||
|
|
||||||
|
|||||||
@@ -4,17 +4,9 @@ import path from "node:path";
|
|||||||
import { pathToFileURL } from "node:url";
|
import { pathToFileURL } from "node:url";
|
||||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||||
import { captureEnv } from "../../test-utils/env.js";
|
import { captureEnv } from "../../test-utils/env.js";
|
||||||
|
import { writeSkill } from "../skills.e2e-test-helpers.js";
|
||||||
import { resolveBundledSkillsDir } from "./bundled-dir.js";
|
import { resolveBundledSkillsDir } from "./bundled-dir.js";
|
||||||
|
|
||||||
async function writeSkill(dir: string, name: string) {
|
|
||||||
await fs.mkdir(dir, { recursive: true });
|
|
||||||
await fs.writeFile(
|
|
||||||
path.join(dir, "SKILL.md"),
|
|
||||||
`---\nname: ${name}\ndescription: ${name}\n---\n\n# ${name}\n`,
|
|
||||||
"utf-8",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("resolveBundledSkillsDir", () => {
|
describe("resolveBundledSkillsDir", () => {
|
||||||
let envSnapshot: ReturnType<typeof captureEnv>;
|
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||||
|
|
||||||
@@ -38,7 +30,11 @@ describe("resolveBundledSkillsDir", () => {
|
|||||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-bundled-"));
|
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-bundled-"));
|
||||||
await fs.writeFile(path.join(root, "package.json"), JSON.stringify({ name: "openclaw" }));
|
await fs.writeFile(path.join(root, "package.json"), JSON.stringify({ name: "openclaw" }));
|
||||||
|
|
||||||
await writeSkill(path.join(root, "skills", "peekaboo"), "peekaboo");
|
await writeSkill({
|
||||||
|
dir: path.join(root, "skills", "peekaboo"),
|
||||||
|
name: "peekaboo",
|
||||||
|
description: "peekaboo",
|
||||||
|
});
|
||||||
|
|
||||||
const distDir = path.join(root, "dist");
|
const distDir = path.join(root, "dist");
|
||||||
await fs.mkdir(distDir, { recursive: true });
|
await fs.mkdir(distDir, { recursive: true });
|
||||||
|
|||||||
Reference in New Issue
Block a user