Skip to content

Commit d6c7e95

Browse files
committed
fix: scope compact skill path env
1 parent 445317a commit d6c7e95

1 file changed

Lines changed: 46 additions & 37 deletions

File tree

src/skills/loading/compact-skill-paths.test.ts

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
// Compact skill path tests cover short path formatting for skill prompt payloads.
22
import os from "node:os";
33
import 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";
56
import { createCanonicalFixtureSkill } from "../test-support/test-helpers.js";
67
import { testing as workspaceSkillsTesting, buildWorkspaceSkillsPrompt } from "./workspace.js";
78

89
describe("compactSkillPaths", () => {
9-
afterEach(() => {
10-
vi.unstubAllEnvs();
11-
});
12-
1310
function buildPromptForFixtureSkill(params: {
1411
workspaceRoot: string;
1512
skillDir: string;
@@ -63,17 +60,21 @@ describe("compactSkillPaths", () => {
6360
const skillDir = path.join(stateDir, "skills", "world-cup-soccer-openclaw-skill");
6461
const skillFile = path.join(skillDir, "SKILL.md");
6562

66-
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+
);
7778

7879
expect(prompt).toContain(`<location>${skillFile}</location>`);
7980
expect(prompt).not.toContain("~/.openclaw/skills/world-cup-soccer-openclaw-skill/SKILL.md");
@@ -86,17 +87,21 @@ describe("compactSkillPaths", () => {
8687
const skillDir = path.join(stateDir, "plugin-skills", "calendar-plugin-skill");
8788
const skillFile = path.join(skillDir, "SKILL.md");
8889

89-
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+
);
100105

101106
expect(prompt).toContain(`<location>${skillFile}</location>`);
102107
expect(prompt).not.toContain("~/.openclaw/plugin-skills/calendar-plugin-skill/SKILL.md");
@@ -107,16 +112,20 @@ describe("compactSkillPaths", () => {
107112
const stateDir = path.join(home, ".openclaw");
108113
const skillDir = path.join(stateDir, "skills", "home-managed-skill");
109114

110-
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+
);
120129

121130
expect(prompt).toContain("<location>~/.openclaw/skills/home-managed-skill/SKILL.md</location>");
122131
expect(prompt).not.toContain(`<location>${path.join(skillDir, "SKILL.md")}</location>`);

0 commit comments

Comments
 (0)