





















11// Compact skill path tests cover short path formatting for skill prompt payloads.
22import os from "node:os";
33import path from "node:path";
4-import { afterEach, describe, expect, it, vi } from "vitest";
4+import { describe, expect, it } from "vitest";
5+import { withEnv } from "../../test-utils/env.js";
56import { createCanonicalFixtureSkill } from "../test-support/test-helpers.js";
67import { testing as workspaceSkillsTesting, buildWorkspaceSkillsPrompt } from "./workspace.js";
7889describe("compactSkillPaths", () => {
9-afterEach(() => {
10-vi.unstubAllEnvs();
11-});
12-1310function buildPromptForFixtureSkill(params: {
1411workspaceRoot: string;
1512skillDir: string;
@@ -63,17 +60,21 @@ describe("compactSkillPaths", () => {
6360const skillDir = path.join(stateDir, "skills", "world-cup-soccer-openclaw-skill");
6461const skillFile = path.join(skillDir, "SKILL.md");
656266-vi.stubEnv("HOME", osHome);
67-vi.stubEnv("OPENCLAW_HOME", osHome);
68-vi.stubEnv("OPENCLAW_STATE_DIR", stateDir);
69-vi.stubEnv("OPENCLAW_CONFIG_PATH", path.join(stateDir, "openclaw.json"));
70-71-const prompt = buildPromptForFixtureSkill({
72-workspaceRoot: path.join(root, "workspace"),
73- skillDir,
74-name: "world-cup-soccer-openclaw-skill",
75-description: "World Cup standings lookup",
76-});
63+const prompt = withEnv(
64+{
65+HOME: osHome,
66+OPENCLAW_HOME: osHome,
67+OPENCLAW_STATE_DIR: stateDir,
68+OPENCLAW_CONFIG_PATH: path.join(stateDir, "openclaw.json"),
69+},
70+() =>
71+buildPromptForFixtureSkill({
72+workspaceRoot: path.join(root, "workspace"),
73+ skillDir,
74+name: "world-cup-soccer-openclaw-skill",
75+description: "World Cup standings lookup",
76+}),
77+);
77787879expect(prompt).toContain(`<location>${skillFile}</location>`);
7980expect(prompt).not.toContain("~/.openclaw/skills/world-cup-soccer-openclaw-skill/SKILL.md");
@@ -86,17 +87,21 @@ describe("compactSkillPaths", () => {
8687const skillDir = path.join(stateDir, "plugin-skills", "calendar-plugin-skill");
8788const skillFile = path.join(skillDir, "SKILL.md");
888989-vi.stubEnv("HOME", osHome);
90-vi.stubEnv("OPENCLAW_HOME", osHome);
91-vi.stubEnv("OPENCLAW_STATE_DIR", stateDir);
92-vi.stubEnv("OPENCLAW_CONFIG_PATH", path.join(stateDir, "openclaw.json"));
93-94-const prompt = buildPromptForFixtureSkill({
95-workspaceRoot: path.join(root, "workspace"),
96- skillDir,
97-name: "calendar-plugin-skill",
98-description: "Calendar plugin skill",
99-});
90+const prompt = withEnv(
91+{
92+HOME: osHome,
93+OPENCLAW_HOME: osHome,
94+OPENCLAW_STATE_DIR: stateDir,
95+OPENCLAW_CONFIG_PATH: path.join(stateDir, "openclaw.json"),
96+},
97+() =>
98+buildPromptForFixtureSkill({
99+workspaceRoot: path.join(root, "workspace"),
100+ skillDir,
101+name: "calendar-plugin-skill",
102+description: "Calendar plugin skill",
103+}),
104+);
100105101106expect(prompt).toContain(`<location>${skillFile}</location>`);
102107expect(prompt).not.toContain("~/.openclaw/plugin-skills/calendar-plugin-skill/SKILL.md");
@@ -107,16 +112,20 @@ describe("compactSkillPaths", () => {
107112const stateDir = path.join(home, ".openclaw");
108113const skillDir = path.join(stateDir, "skills", "home-managed-skill");
109114110-vi.stubEnv("HOME", home);
111-vi.stubEnv("OPENCLAW_STATE_DIR", stateDir);
112-vi.stubEnv("OPENCLAW_HOME", undefined);
113-114-const prompt = buildPromptForFixtureSkill({
115-workspaceRoot: path.join(home, "workspace"),
116- skillDir,
117-name: "home-managed-skill",
118-description: "Home managed skill",
119-});
115+const prompt = withEnv(
116+{
117+HOME: home,
118+OPENCLAW_STATE_DIR: stateDir,
119+OPENCLAW_HOME: undefined,
120+},
121+() =>
122+buildPromptForFixtureSkill({
123+workspaceRoot: path.join(home, "workspace"),
124+ skillDir,
125+name: "home-managed-skill",
126+description: "Home managed skill",
127+}),
128+);
120129121130expect(prompt).toContain("<location>~/.openclaw/skills/home-managed-skill/SKILL.md</location>");
122131expect(prompt).not.toContain(`<location>${path.join(skillDir, "SKILL.md")}</location>`);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。