test: harden package-root mocks after setup slimming

This commit is contained in:
Shakker
2026-04-01 18:25:22 +01:00
committed by Shakker
parent a898cd464a
commit 3b727d2433
5 changed files with 35 additions and 14 deletions

View File

@@ -48,10 +48,14 @@ vi.mock("../infra/update-runner.js", () => ({
runGatewayUpdate: vi.fn(),
}));
vi.mock("../infra/openclaw-root.js", () => ({
resolveOpenClawPackageRoot: vi.fn(),
resolveOpenClawPackageRootSync: vi.fn(() => process.cwd()),
}));
vi.mock("../infra/openclaw-root.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../infra/openclaw-root.js")>();
return {
...actual,
resolveOpenClawPackageRoot: vi.fn(),
resolveOpenClawPackageRootSync: vi.fn(() => process.cwd()),
};
});
vi.mock("../config/config.js", () => ({
readConfigFileSnapshot: vi.fn(),

View File

@@ -448,10 +448,14 @@ vi.mock("../gateway/session-utils.js", async (importOriginal) => {
...actual,
};
});
vi.mock("../infra/openclaw-root.js", () => ({
resolveOpenClawPackageRoot: vi.fn().mockResolvedValue("/tmp/openclaw"),
resolveOpenClawPackageRootSync: vi.fn(() => "/tmp/openclaw"),
}));
vi.mock("../infra/openclaw-root.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../infra/openclaw-root.js")>();
return {
...actual,
resolveOpenClawPackageRoot: vi.fn().mockResolvedValue("/tmp/openclaw"),
resolveOpenClawPackageRootSync: vi.fn(() => "/tmp/openclaw"),
};
});
vi.mock("../infra/os-summary.js", () => ({
resolveOsSummary: () => ({
platform: "darwin",

View File

@@ -32,9 +32,13 @@ vi.mock("../../config/sessions.js", () => ({
},
}));
vi.mock("../../infra/openclaw-root.js", () => ({
resolveOpenClawPackageRoot: async () => "/tmp/openclaw",
}));
vi.mock("../../infra/openclaw-root.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../../infra/openclaw-root.js")>();
return {
...actual,
resolveOpenClawPackageRoot: async () => "/tmp/openclaw",
};
});
vi.mock("../../infra/restart-sentinel.js", async (importOriginal) => {
const actual = await importOriginal();

View File

@@ -5,9 +5,13 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi }
import { captureEnv } from "../test-utils/env.js";
import type { UpdateCheckResult } from "./update-check.js";
vi.mock("./openclaw-root.js", () => ({
resolveOpenClawPackageRoot: vi.fn(),
}));
vi.mock("./openclaw-root.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("./openclaw-root.js")>();
return {
...actual,
resolveOpenClawPackageRoot: vi.fn(),
};
});
vi.mock("./update-check.js", async () => {
const parse = (value: string) => value.split(".").map((part) => Number.parseInt(part, 10));

View File

@@ -270,6 +270,11 @@ function installDefaultPluginRegistry(): void {
setActivePluginRegistry(resolveDefaultPluginRegistryProxy());
}
// Some suites import channel/plugin consumers at module top level, before
// Vitest runs hooks. Seed the lazy registry during setup module evaluation so
// import-time lookups still see the default test registry.
installDefaultPluginRegistry();
beforeAll(() => {
installDefaultPluginRegistry();
});