mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-02 09:01:33 +00:00
test: restore shared runtime state (#113334)
This commit is contained in:
committed by
GitHub
parent
44c3ec10ed
commit
10484486a0
@@ -1,6 +1,6 @@
|
||||
// Context engine tests cover context extraction and prompt context assembly.
|
||||
import type { AgentMessage } from "openclaw/plugin-sdk/agent-core";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { MemoryCitationsMode } from "../config/types.memory.js";
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import {
|
||||
@@ -26,7 +26,10 @@ import {
|
||||
resolveContextEngine,
|
||||
resolveContextEngineOwnerPluginId,
|
||||
} from "./registry.js";
|
||||
import { resetContextEngineRuntimeQuarantineForTests } from "./registry.test-support.js";
|
||||
import {
|
||||
captureContextEngineRegistryStateForTests,
|
||||
resetContextEngineRuntimeQuarantineForTests,
|
||||
} from "./registry.test-support.js";
|
||||
import type {
|
||||
ContextEngine,
|
||||
ContextEngineInfo,
|
||||
@@ -93,6 +96,16 @@ function makeMockMessage(role: "user" | "assistant" = "user", text = "hello"): A
|
||||
return { role, content: text, timestamp: Date.now() } as AgentMessage;
|
||||
}
|
||||
|
||||
let restoreContextEngineRegistry = () => {};
|
||||
|
||||
beforeAll(() => {
|
||||
restoreContextEngineRegistry = captureContextEngineRegistryStateForTests();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
restoreContextEngineRegistry();
|
||||
});
|
||||
|
||||
let uniqueEngineIdCounter = 0;
|
||||
function uniqueEngineId(prefix: string): string {
|
||||
uniqueEngineIdCounter += 1;
|
||||
|
||||
@@ -1,18 +1,53 @@
|
||||
import { resolveGlobalSingleton } from "../shared/global-singleton.js";
|
||||
import { clearPersistedContextEngineQuarantineForProcess } from "./quarantine-health.js";
|
||||
import {
|
||||
clearPersistedContextEngineQuarantineForProcess,
|
||||
recordPersistedContextEngineQuarantine,
|
||||
} from "./quarantine-health.js";
|
||||
|
||||
type ContextEngineRuntimeQuarantineForTests = {
|
||||
engineId: string;
|
||||
owner?: string;
|
||||
operation: string;
|
||||
reason: string;
|
||||
failedAt: Date;
|
||||
};
|
||||
|
||||
type ContextEngineRegistryStateForTests = {
|
||||
engines: Map<string, unknown>;
|
||||
quarantinedEngines: Map<string, unknown>;
|
||||
quarantinedEngines: Map<string, ContextEngineRuntimeQuarantineForTests>;
|
||||
};
|
||||
|
||||
const CONTEXT_ENGINE_REGISTRY_STATE = Symbol.for("openclaw.contextEngineRegistryState");
|
||||
|
||||
export function resetContextEngineRuntimeQuarantineForTests(): void {
|
||||
const state = resolveGlobalSingleton<ContextEngineRegistryStateForTests>(
|
||||
function getContextEngineRegistryStateForTests(): ContextEngineRegistryStateForTests {
|
||||
return resolveGlobalSingleton<ContextEngineRegistryStateForTests>(
|
||||
CONTEXT_ENGINE_REGISTRY_STATE,
|
||||
() => ({ engines: new Map(), quarantinedEngines: new Map() }),
|
||||
);
|
||||
}
|
||||
|
||||
export function captureContextEngineRegistryStateForTests(): () => void {
|
||||
const state = getContextEngineRegistryStateForTests();
|
||||
const engines = new Map(state.engines);
|
||||
const quarantinedEngines = new Map(state.quarantinedEngines);
|
||||
|
||||
return () => {
|
||||
state.engines.clear();
|
||||
for (const [engineId, registration] of engines) {
|
||||
state.engines.set(engineId, registration);
|
||||
}
|
||||
|
||||
state.quarantinedEngines.clear();
|
||||
clearPersistedContextEngineQuarantineForProcess(undefined, process.pid);
|
||||
for (const [engineId, quarantine] of quarantinedEngines) {
|
||||
state.quarantinedEngines.set(engineId, quarantine);
|
||||
recordPersistedContextEngineQuarantine(quarantine);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function resetContextEngineRuntimeQuarantineForTests(): void {
|
||||
const state = getContextEngineRegistryStateForTests();
|
||||
state.quarantinedEngines.clear();
|
||||
clearPersistedContextEngineQuarantineForProcess(undefined, process.pid);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Gmail watcher tests cover watcher events and Gmail hook message flow.
|
||||
import { EventEmitter } from "node:events";
|
||||
import { expectDefined } from "@openclaw/normalization-core";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
hasBinary: vi.fn(() => true),
|
||||
@@ -104,6 +104,11 @@ describe("startGmailWatcher", () => {
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
vi.useRealTimers();
|
||||
await stopGmailWatcher();
|
||||
});
|
||||
|
||||
it("does not let a stale cancelled startup clear newer watcher config", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
|
||||
@@ -169,6 +169,7 @@ describe("web search runtime", () => {
|
||||
let runWebSearch: typeof import("./runtime.js").runWebSearch;
|
||||
let activateSecretsRuntimeSnapshot: typeof import("../secrets/runtime.js").activateSecretsRuntimeSnapshot;
|
||||
let clearSecretsRuntimeSnapshot: typeof import("../secrets/runtime.js").clearSecretsRuntimeSnapshot;
|
||||
let clearRuntimeConfigSnapshot: typeof import("../config/config.js").clearRuntimeConfigSnapshot;
|
||||
let setRuntimeConfigSnapshot: typeof import("../config/config.js").setRuntimeConfigSnapshot;
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
@@ -176,10 +177,12 @@ describe("web search runtime", () => {
|
||||
({ hasUsableWebSearchProvider, runWebSearch } = await import("./runtime.js"));
|
||||
({ activateSecretsRuntimeSnapshot, clearSecretsRuntimeSnapshot } =
|
||||
await import("../secrets/runtime.js"));
|
||||
({ setRuntimeConfigSnapshot } = await import("../config/config.js"));
|
||||
({ clearRuntimeConfigSnapshot, setRuntimeConfigSnapshot } =
|
||||
await import("../config/config.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
clearRuntimeConfigSnapshot();
|
||||
resolveManifestContractOwnerPluginIdMock.mockReset();
|
||||
resolvePluginWebSearchProvidersMock.mockReset();
|
||||
resolveRuntimeWebSearchProvidersMock.mockReset();
|
||||
@@ -189,6 +192,7 @@ describe("web search runtime", () => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
clearRuntimeConfigSnapshot();
|
||||
clearSecretsRuntimeSnapshot();
|
||||
clearRuntimeAuthProfileStoreSnapshots();
|
||||
for (const tempDir of tempDirs.splice(0)) {
|
||||
|
||||
Reference in New Issue
Block a user