From ea487eb72cb45c917ec4936ff34d9c9d814bda84 Mon Sep 17 00:00:00 2001 From: Shakker Date: Fri, 29 May 2026 16:49:42 +0100 Subject: [PATCH] fix: unblock skills centralization checks --- src/auto-reply/reply.test-harness.ts | 42 +++++++------------------- test/vitest/vitest.unit-fast-paths.mjs | 4 +-- 2 files changed, 13 insertions(+), 33 deletions(-) diff --git a/src/auto-reply/reply.test-harness.ts b/src/auto-reply/reply.test-harness.ts index 78bad4c1b9f..b342caeb97d 100644 --- a/src/auto-reply/reply.test-harness.ts +++ b/src/auto-reply/reply.test-harness.ts @@ -2,6 +2,7 @@ import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import { afterAll, beforeAll, vi, type Mock } from "vitest"; +import { captureEnv } from "../test-utils/env.js"; import { withFastReplyConfig } from "./reply/get-reply-fast-path.js"; type ReplyRuntimeMocks = { @@ -119,35 +120,14 @@ vi.mock("./reply/agent-runner.runtime.js", () => ({ }, })); -type HomeEnvSnapshot = { - HOME: string | undefined; - USERPROFILE: string | undefined; - HOMEDRIVE: string | undefined; - HOMEPATH: string | undefined; - OPENCLAW_STATE_DIR: string | undefined; - OPENCLAW_AGENT_DIR: string | undefined; -}; - -function snapshotHomeEnv(): HomeEnvSnapshot { - return { - HOME: process.env.HOME, - USERPROFILE: process.env.USERPROFILE, - HOMEDRIVE: process.env.HOMEDRIVE, - HOMEPATH: process.env.HOMEPATH, - OPENCLAW_STATE_DIR: process.env.OPENCLAW_STATE_DIR, - OPENCLAW_AGENT_DIR: process.env.OPENCLAW_AGENT_DIR, - }; -} - -function restoreHomeEnv(snapshot: HomeEnvSnapshot) { - for (const [key, value] of Object.entries(snapshot)) { - if (value === undefined) { - delete process.env[key]; - } else { - process.env[key] = value; - } - } -} +const HOME_ENV_KEYS = [ + "HOME", + "USERPROFILE", + "HOMEDRIVE", + "HOMEPATH", + "OPENCLAW_STATE_DIR", + "OPENCLAW_AGENT_DIR", +] as const; export function createTempHomeHarness(options: { prefix: string; beforeEachCase?: () => void }) { let fixtureRoot = ""; @@ -167,7 +147,7 @@ export function createTempHomeHarness(options: { prefix: string; beforeEachCase? async function withTempHome(fn: (home: string) => Promise): Promise { const home = path.join(fixtureRoot, `case-${++caseId}`); await fs.mkdir(path.join(home, ".openclaw", "agents", "main", "sessions"), { recursive: true }); - const envSnapshot = snapshotHomeEnv(); + const envSnapshot = captureEnv([...HOME_ENV_KEYS]); process.env.HOME = home; process.env.USERPROFILE = home; process.env.OPENCLAW_STATE_DIR = path.join(home, ".openclaw"); @@ -185,7 +165,7 @@ export function createTempHomeHarness(options: { prefix: string; beforeEachCase? options.beforeEachCase?.(); return await fn(home); } finally { - restoreHomeEnv(envSnapshot); + envSnapshot.restore(); } } diff --git a/test/vitest/vitest.unit-fast-paths.mjs b/test/vitest/vitest.unit-fast-paths.mjs index 1b075956906..efa9881bd78 100644 --- a/test/vitest/vitest.unit-fast-paths.mjs +++ b/test/vitest/vitest.unit-fast-paths.mjs @@ -166,11 +166,11 @@ export const forcedUnitFastTestFiles = [ "src/security/audit-plugins-trust.test.ts", "src/security/audit-plugin-readonly-scope.test.ts", "src/security/audit-loopback-logging.test.ts", - "src/security/audit-workspace-skill-escape.test.ts", + "src/skills/security/workspace-audit.test.ts", "src/security/external-content.test.ts", "src/security/fix.test.ts", "src/security/scan-paths.test.ts", - "src/security/skill-scanner.test.ts", + "src/skills/security/scanner.test.ts", "src/security/audit-config-include-perms.test.ts", "src/security/context-visibility.test.ts", "src/realtime-transcription/websocket-session.test.ts",