From 0ad2da060ece04b4b6ccdd30493feb04c9e64218 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 3 Apr 2026 19:34:46 +0100 Subject: [PATCH] test: route openclaw root through boundary config --- src/infra/openclaw-root.test.ts | 29 +++++++++++++++++++---------- test/vitest-unit-paths.test.ts | 1 + vitest.unit-paths.mjs | 2 ++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/infra/openclaw-root.test.ts b/src/infra/openclaw-root.test.ts index 35597136a87..74cfa2c0979 100644 --- a/src/infra/openclaw-root.test.ts +++ b/src/infra/openclaw-root.test.ts @@ -39,8 +39,8 @@ function expectResolvedPackageRoot( return expect(asyncResolver(opts)).resolves.toBe(expected); } -vi.mock("node:fs", async (importOriginal) => { - const actual = await importOriginal(); +const mockFsModule = async (importOriginal: () => Promise) => { + const actual = await importOriginal(); const wrapped = { ...actual, existsSync: (p: string) => @@ -80,10 +80,12 @@ vi.mock("node:fs", async (importOriginal) => { : actual.realpathSync(p), }; return { ...wrapped, default: wrapped }; -}); +}; -vi.mock("node:fs/promises", async (importOriginal) => { - const actual = await importOriginal(); +const mockFsPromisesModule = async ( + importOriginal: () => Promise, +) => { + const actual = await importOriginal(); const wrapped = { ...actual, readFile: async (p: string, encoding?: BufferEncoding) => { @@ -98,21 +100,28 @@ vi.mock("node:fs/promises", async (importOriginal) => { }, }; return { ...wrapped, default: wrapped }; -}); +}; describe("resolveOpenClawPackageRoot", () => { let resolveOpenClawPackageRoot: typeof import("./openclaw-root.js").resolveOpenClawPackageRoot; let resolveOpenClawPackageRootSync: typeof import("./openclaw-root.js").resolveOpenClawPackageRootSync; - beforeEach(async () => { - vi.resetModules(); - ({ resolveOpenClawPackageRoot, resolveOpenClawPackageRootSync } = - await import("./openclaw-root.js")); + beforeEach(() => { state.entries.clear(); state.realpaths.clear(); state.realpathErrors.clear(); }); + beforeEach(async () => { + vi.resetModules(); + vi.doUnmock("node:fs"); + vi.doUnmock("node:fs/promises"); + vi.doMock("node:fs", mockFsModule); + vi.doMock("node:fs/promises", mockFsPromisesModule); + ({ resolveOpenClawPackageRoot, resolveOpenClawPackageRootSync } = + await import("./openclaw-root.js")); + }); + it.each([ { name: "resolves package root from .bin argv1", diff --git a/test/vitest-unit-paths.test.ts b/test/vitest-unit-paths.test.ts index 6501a469a9b..bb63785d306 100644 --- a/test/vitest-unit-paths.test.ts +++ b/test/vitest-unit-paths.test.ts @@ -17,6 +17,7 @@ describe("isUnitConfigTestFile", () => { ), ).toBe(false); expect(isUnitConfigTestFile("src/infra/matrix-plugin-helper.test.ts")).toBe(false); + expect(isUnitConfigTestFile("src/infra/openclaw-root.test.ts")).toBe(false); expect(isUnitConfigTestFile("src/plugin-sdk/facade-runtime.test.ts")).toBe(false); expect(isUnitConfigTestFile("src/plugins/loader.test.ts")).toBe(false); expect(isUnitConfigTestFile("test/extension-test-boundary.test.ts")).toBe(false); diff --git a/vitest.unit-paths.mjs b/vitest.unit-paths.mjs index e058fcf2fef..b50f530fca3 100644 --- a/vitest.unit-paths.mjs +++ b/vitest.unit-paths.mjs @@ -16,6 +16,7 @@ export const unitTestIncludePatterns = [ ]; export const boundaryTestFiles = [ + "src/infra/openclaw-root.test.ts", "test/extension-plugin-sdk-boundary.test.ts", "test/extension-test-boundary.test.ts", "test/plugin-extension-import-boundary.test.ts", @@ -39,6 +40,7 @@ export const unitTestAdditionalExcludePatterns = [ "src/commands/**", "src/channels/plugins/contracts/**", "src/plugins/contracts/**", + "src/infra/openclaw-root.test.ts", ...bundledPluginDependentUnitTestFiles, "src/config/doc-baseline.integration.test.ts", "src/config/schema.base.generated.test.ts",