From d6c7e95c7b3e843f486befa57515512577ec4f2d Mon Sep 17 00:00:00 2001 From: Shakker Date: Sat, 20 Jun 2026 03:03:50 +0100 Subject: [PATCH] fix: scope compact skill path env --- .../loading/compact-skill-paths.test.ts | 83 ++++++++++--------- 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/src/skills/loading/compact-skill-paths.test.ts b/src/skills/loading/compact-skill-paths.test.ts index 6ac872d64aec..817121eb4f17 100644 --- a/src/skills/loading/compact-skill-paths.test.ts +++ b/src/skills/loading/compact-skill-paths.test.ts @@ -1,15 +1,12 @@ // Compact skill path tests cover short path formatting for skill prompt payloads. import os from "node:os"; import path from "node:path"; -import { afterEach, describe, expect, it, vi } from "vitest"; +import { describe, expect, it } from "vitest"; +import { withEnv } from "../../test-utils/env.js"; import { createCanonicalFixtureSkill } from "../test-support/test-helpers.js"; import { testing as workspaceSkillsTesting, buildWorkspaceSkillsPrompt } from "./workspace.js"; describe("compactSkillPaths", () => { - afterEach(() => { - vi.unstubAllEnvs(); - }); - function buildPromptForFixtureSkill(params: { workspaceRoot: string; skillDir: string; @@ -63,17 +60,21 @@ describe("compactSkillPaths", () => { const skillDir = path.join(stateDir, "skills", "world-cup-soccer-openclaw-skill"); const skillFile = path.join(skillDir, "SKILL.md"); - vi.stubEnv("HOME", osHome); - vi.stubEnv("OPENCLAW_HOME", osHome); - vi.stubEnv("OPENCLAW_STATE_DIR", stateDir); - vi.stubEnv("OPENCLAW_CONFIG_PATH", path.join(stateDir, "openclaw.json")); - - const prompt = buildPromptForFixtureSkill({ - workspaceRoot: path.join(root, "workspace"), - skillDir, - name: "world-cup-soccer-openclaw-skill", - description: "World Cup standings lookup", - }); + const prompt = withEnv( + { + HOME: osHome, + OPENCLAW_HOME: osHome, + OPENCLAW_STATE_DIR: stateDir, + OPENCLAW_CONFIG_PATH: path.join(stateDir, "openclaw.json"), + }, + () => + buildPromptForFixtureSkill({ + workspaceRoot: path.join(root, "workspace"), + skillDir, + name: "world-cup-soccer-openclaw-skill", + description: "World Cup standings lookup", + }), + ); expect(prompt).toContain(`${skillFile}`); expect(prompt).not.toContain("~/.openclaw/skills/world-cup-soccer-openclaw-skill/SKILL.md"); @@ -86,17 +87,21 @@ describe("compactSkillPaths", () => { const skillDir = path.join(stateDir, "plugin-skills", "calendar-plugin-skill"); const skillFile = path.join(skillDir, "SKILL.md"); - vi.stubEnv("HOME", osHome); - vi.stubEnv("OPENCLAW_HOME", osHome); - vi.stubEnv("OPENCLAW_STATE_DIR", stateDir); - vi.stubEnv("OPENCLAW_CONFIG_PATH", path.join(stateDir, "openclaw.json")); - - const prompt = buildPromptForFixtureSkill({ - workspaceRoot: path.join(root, "workspace"), - skillDir, - name: "calendar-plugin-skill", - description: "Calendar plugin skill", - }); + const prompt = withEnv( + { + HOME: osHome, + OPENCLAW_HOME: osHome, + OPENCLAW_STATE_DIR: stateDir, + OPENCLAW_CONFIG_PATH: path.join(stateDir, "openclaw.json"), + }, + () => + buildPromptForFixtureSkill({ + workspaceRoot: path.join(root, "workspace"), + skillDir, + name: "calendar-plugin-skill", + description: "Calendar plugin skill", + }), + ); expect(prompt).toContain(`${skillFile}`); expect(prompt).not.toContain("~/.openclaw/plugin-skills/calendar-plugin-skill/SKILL.md"); @@ -107,16 +112,20 @@ describe("compactSkillPaths", () => { const stateDir = path.join(home, ".openclaw"); const skillDir = path.join(stateDir, "skills", "home-managed-skill"); - vi.stubEnv("HOME", home); - vi.stubEnv("OPENCLAW_STATE_DIR", stateDir); - vi.stubEnv("OPENCLAW_HOME", undefined); - - const prompt = buildPromptForFixtureSkill({ - workspaceRoot: path.join(home, "workspace"), - skillDir, - name: "home-managed-skill", - description: "Home managed skill", - }); + const prompt = withEnv( + { + HOME: home, + OPENCLAW_STATE_DIR: stateDir, + OPENCLAW_HOME: undefined, + }, + () => + buildPromptForFixtureSkill({ + workspaceRoot: path.join(home, "workspace"), + skillDir, + name: "home-managed-skill", + description: "Home managed skill", + }), + ); expect(prompt).toContain("~/.openclaw/skills/home-managed-skill/SKILL.md"); expect(prompt).not.toContain(`${path.join(skillDir, "SKILL.md")}`);