perf(test): replace module resets with direct spies and runtime seams

This commit is contained in:
Peter Steinberger
2026-02-13 16:04:43 +00:00
parent 59733a02c8
commit c2f7b66d22
11 changed files with 80 additions and 195 deletions

View File

@@ -1,20 +1,18 @@
import path from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
import { resolveDefaultAgentWorkspaceDir } from "./workspace.js";
afterEach(() => {
vi.unstubAllEnvs();
vi.resetModules();
});
describe("DEFAULT_AGENT_WORKSPACE_DIR", () => {
it("uses OPENCLAW_HOME at module import time", async () => {
it("uses OPENCLAW_HOME when resolving the default workspace dir", () => {
const home = path.join(path.sep, "srv", "openclaw-home");
vi.stubEnv("OPENCLAW_HOME", home);
vi.stubEnv("HOME", path.join(path.sep, "home", "other"));
vi.resetModules();
const mod = await import("./workspace.js");
expect(mod.DEFAULT_AGENT_WORKSPACE_DIR).toBe(
expect(resolveDefaultAgentWorkspaceDir()).toBe(
path.join(path.resolve(home), ".openclaw", "workspace"),
);
});