mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 01:31:08 +00:00
test: stabilize ci test isolation
This commit is contained in:
@@ -5,11 +5,14 @@ import { logAuthProfileFailureStateChange } from "./state-observation.js";
|
||||
afterEach(() => {
|
||||
setLoggerOverride(null);
|
||||
resetLogger();
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
describe("logAuthProfileFailureStateChange", () => {
|
||||
it("sanitizes consoleMessage fields before logging", () => {
|
||||
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||
vi.stubEnv("FORCE_COLOR", "0");
|
||||
vi.stubEnv("NO_COLOR", "1");
|
||||
setLoggerOverride({ level: "silent", consoleLevel: "warn" });
|
||||
|
||||
logAuthProfileFailureStateChange({
|
||||
|
||||
@@ -12,6 +12,7 @@ import { loadOpenClawPlugins } from "../plugins/loader.js";
|
||||
import { guardSessionManager } from "./session-tool-result-guard-wrapper.js";
|
||||
|
||||
const EMPTY_PLUGIN_SCHEMA = { type: "object", additionalProperties: false, properties: {} };
|
||||
const originalBundledPluginsDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
|
||||
|
||||
function writeTempPlugin(params: { dir: string; id: string; body: string }): string {
|
||||
const pluginDir = path.join(params.dir, params.id);
|
||||
@@ -60,6 +61,11 @@ function getPersistedToolResult(sm: ReturnType<typeof SessionManager.inMemory>)
|
||||
|
||||
afterEach(() => {
|
||||
resetGlobalHookRunner();
|
||||
if (originalBundledPluginsDir === undefined) {
|
||||
delete process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
|
||||
} else {
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = originalBundledPluginsDir;
|
||||
}
|
||||
});
|
||||
|
||||
describe("tool_result_persist hook", () => {
|
||||
|
||||
@@ -20,6 +20,7 @@ const mocks = vi.hoisted(() => ({
|
||||
updateConfig: vi.fn(),
|
||||
logConfigUpdated: vi.fn(),
|
||||
openUrl: vi.fn(),
|
||||
isRemoteEnvironment: vi.fn(() => false),
|
||||
loadAuthProfileStoreForRuntime: vi.fn(),
|
||||
listProfilesForProvider: vi.fn(),
|
||||
clearAuthProfileCooldown: vi.fn(),
|
||||
@@ -75,6 +76,10 @@ vi.mock("../onboard-helpers.js", () => ({
|
||||
openUrl: mocks.openUrl,
|
||||
}));
|
||||
|
||||
vi.mock("../oauth-env.js", () => ({
|
||||
isRemoteEnvironment: mocks.isRemoteEnvironment,
|
||||
}));
|
||||
|
||||
const { modelsAuthLoginCommand, modelsAuthPasteTokenCommand, modelsAuthSetupTokenCommand } =
|
||||
await import("./auth.js");
|
||||
|
||||
@@ -147,6 +152,7 @@ describe("modelsAuthLoginCommand", () => {
|
||||
mocks.resolveAgentDir.mockReturnValue("/tmp/openclaw/agents/main");
|
||||
mocks.resolveAgentWorkspaceDir.mockReturnValue("/tmp/openclaw/workspace");
|
||||
mocks.resolveDefaultAgentWorkspaceDir.mockReturnValue("/tmp/openclaw/workspace");
|
||||
mocks.isRemoteEnvironment.mockReturnValue(false);
|
||||
mocks.loadValidConfigOrThrow.mockImplementation(async () => currentConfig);
|
||||
mocks.updateConfig.mockImplementation(
|
||||
async (mutator: (cfg: OpenClawConfig) => OpenClawConfig) => {
|
||||
|
||||
@@ -72,6 +72,10 @@ const disqualifyingPatterns = [
|
||||
code: "module-mocking",
|
||||
pattern: /\bvi\.(?:mock|doMock|unmock|doUnmock|importActual|resetModules)\s*\(/u,
|
||||
},
|
||||
{
|
||||
code: "module-mocking-helper",
|
||||
pattern: /runtime-module-mocks/u,
|
||||
},
|
||||
{
|
||||
code: "vitest-mock-api",
|
||||
pattern: /\bvi\b/u,
|
||||
|
||||
Reference in New Issue
Block a user