test(core): reduce mock reset overhead in targeted suites

This commit is contained in:
Peter Steinberger
2026-02-22 08:40:24 +00:00
parent 2a66c8d676
commit ccc00d874c
8 changed files with 19 additions and 12 deletions

View File

@@ -20,7 +20,7 @@ beforeAll(async () => {
beforeEach(() => {
vi.useRealTimers();
runEmbeddedAttemptMock.mockReset();
runEmbeddedAttemptMock.mockClear();
});
const baseUsage = {

View File

@@ -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");

View File

@@ -54,8 +54,8 @@ function installBrowserMocks() {
}
afterEach(async () => {
connectOverCdpSpy.mockReset();
getChromeWebSocketUrlSpy.mockReset();
connectOverCdpSpy.mockClear();
getChromeWebSocketUrlSpy.mockClear();
await closePlaywrightBrowserConnection().catch(() => {});
});

View File

@@ -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",

View File

@@ -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);
}
}
});

View File

@@ -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([]);
});

View File

@@ -17,7 +17,7 @@ vi.mock("../process/exec.js", () => ({
}));
beforeEach(() => {
runCommandWithTimeoutMock.mockReset();
runCommandWithTimeoutMock.mockClear();
resetGmailSetupUtilsCachesForTest();
});

View File

@@ -38,7 +38,7 @@ describe("media store redirects", () => {
});
beforeEach(() => {
mockRequest.mockReset();
mockRequest.mockClear();
setMediaStoreNetworkDepsForTest({
httpRequest: (...args) => mockRequest(...args),
httpsRequest: (...args) => mockRequest(...args),