mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-08 06:54:24 +00:00
test(core): reduce mock reset overhead in targeted suites
This commit is contained in:
@@ -20,7 +20,7 @@ beforeAll(async () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useRealTimers();
|
||||
runEmbeddedAttemptMock.mockReset();
|
||||
runEmbeddedAttemptMock.mockClear();
|
||||
});
|
||||
|
||||
const baseUsage = {
|
||||
|
||||
@@ -337,7 +337,7 @@ describe("abort detection", () => {
|
||||
});
|
||||
|
||||
it("cascade stop traverses ended depth-1 parents to stop active depth-2 children", async () => {
|
||||
subagentRegistryMocks.listSubagentRunsForRequester.mockReset();
|
||||
subagentRegistryMocks.listSubagentRunsForRequester.mockClear();
|
||||
subagentRegistryMocks.markSubagentRunTerminated.mockClear();
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-abort-"));
|
||||
const storePath = path.join(root, "sessions.json");
|
||||
|
||||
@@ -54,8 +54,8 @@ function installBrowserMocks() {
|
||||
}
|
||||
|
||||
afterEach(async () => {
|
||||
connectOverCdpSpy.mockReset();
|
||||
getChromeWebSocketUrlSpy.mockReset();
|
||||
connectOverCdpSpy.mockClear();
|
||||
getChromeWebSocketUrlSpy.mockClear();
|
||||
await closePlaywrightBrowserConnection().catch(() => {});
|
||||
});
|
||||
|
||||
|
||||
@@ -288,7 +288,7 @@ describe("devices cli local fallback", () => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
callGateway.mockReset();
|
||||
callGateway.mockClear();
|
||||
buildGatewayConnectionDetails.mockClear();
|
||||
buildGatewayConnectionDetails.mockReturnValue({
|
||||
url: "ws://127.0.0.1:18789",
|
||||
|
||||
@@ -118,6 +118,11 @@ vi.mock("../../config/config.js", async (importOriginal) => {
|
||||
|
||||
import { modelsStatusCommand } from "./list.status-command.js";
|
||||
|
||||
const defaultResolveAgentModelPrimaryImpl = mocks.resolveAgentModelPrimary.getMockImplementation();
|
||||
const defaultResolveAgentModelFallbacksOverrideImpl =
|
||||
mocks.resolveAgentModelFallbacksOverride.getMockImplementation();
|
||||
const defaultResolveEnvApiKeyImpl = mocks.resolveEnvApiKey.getMockImplementation();
|
||||
|
||||
const runtime = {
|
||||
log: vi.fn(),
|
||||
error: vi.fn(),
|
||||
@@ -156,12 +161,14 @@ async function withAgentScopeOverrides<T>(
|
||||
if (originalPrimary) {
|
||||
mocks.resolveAgentModelPrimary.mockImplementation(originalPrimary);
|
||||
} else {
|
||||
mocks.resolveAgentModelPrimary.mockReset();
|
||||
mocks.resolveAgentModelPrimary.mockImplementation(defaultResolveAgentModelPrimaryImpl);
|
||||
}
|
||||
if (originalFallbacks) {
|
||||
mocks.resolveAgentModelFallbacksOverride.mockImplementation(originalFallbacks);
|
||||
} else {
|
||||
mocks.resolveAgentModelFallbacksOverride.mockReset();
|
||||
mocks.resolveAgentModelFallbacksOverride.mockImplementation(
|
||||
defaultResolveAgentModelFallbacksOverrideImpl,
|
||||
);
|
||||
}
|
||||
if (originalAgentDir) {
|
||||
mocks.resolveAgentDir.mockImplementation(originalAgentDir);
|
||||
@@ -270,7 +277,7 @@ describe("modelsStatusCommand auth overview", () => {
|
||||
if (originalEnvImpl) {
|
||||
mocks.resolveEnvApiKey.mockImplementation(originalEnvImpl);
|
||||
} else {
|
||||
mocks.resolveEnvApiKey.mockReset();
|
||||
mocks.resolveEnvApiKey.mockImplementation(defaultResolveEnvApiKeyImpl);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -101,7 +101,7 @@ async function runCronTurn(home: string, options: RunCronTurnOptions = {}) {
|
||||
const storePath = options.storePath ?? (await writeSessionStore(home, options.storeEntries));
|
||||
const deps = options.deps ?? makeDeps();
|
||||
if (options.mockTexts === null) {
|
||||
vi.mocked(runEmbeddedPiAgent).mockReset();
|
||||
vi.mocked(runEmbeddedPiAgent).mockClear();
|
||||
} else {
|
||||
mockEmbeddedTexts(options.mockTexts ?? ["ok"]);
|
||||
}
|
||||
@@ -158,7 +158,7 @@ async function runTurnWithStoredModelOverride(
|
||||
|
||||
describe("runCronIsolatedAgentTurn", () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(runEmbeddedPiAgent).mockReset();
|
||||
vi.mocked(runEmbeddedPiAgent).mockClear();
|
||||
vi.mocked(loadModelCatalog).mockResolvedValue([]);
|
||||
});
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ vi.mock("../process/exec.js", () => ({
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
runCommandWithTimeoutMock.mockReset();
|
||||
runCommandWithTimeoutMock.mockClear();
|
||||
resetGmailSetupUtilsCachesForTest();
|
||||
});
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ describe("media store redirects", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
mockRequest.mockReset();
|
||||
mockRequest.mockClear();
|
||||
setMediaStoreNetworkDepsForTest({
|
||||
httpRequest: (...args) => mockRequest(...args),
|
||||
httpsRequest: (...args) => mockRequest(...args),
|
||||
|
||||
Reference in New Issue
Block a user