mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
improve(tests): narrow shared runner resets (#118455)
* test(agents): reuse shared runner module graph * test(agents): narrow shared runner resets * test(agents): keep broad reset private --------- Co-authored-by: Peter Steinberger <steipete@mac-studio-sf2.local>
This commit is contained in:
committed by
GitHub
parent
708c0acf16
commit
578c190579
@@ -11,7 +11,7 @@ import {
|
||||
mockedRunEmbeddedAttempt,
|
||||
mockedSleepWithAbort,
|
||||
overflowBaseRunParams,
|
||||
resetRunOverflowCompactionHarnessMocks,
|
||||
resetSharedRunIntegrationHarnessMocks,
|
||||
useOpenAIPlatformAuthFixture,
|
||||
} from "./run.overflow-compaction.harness.js";
|
||||
import { loadSharedRunIntegrationHarness } from "./run.shared-integration-harness.test-support.js";
|
||||
@@ -78,7 +78,7 @@ describe("runEmbeddedAgent before_agent_finalize", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetRunOverflowCompactionHarnessMocks();
|
||||
resetSharedRunIntegrationHarnessMocks();
|
||||
useOpenAIPlatformAuthFixture();
|
||||
mockedGlobalHookRunner.hasHooks.mockImplementation(
|
||||
(hookName: string) => hookName === "before_agent_finalize",
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
mockedGlobalHookRunner,
|
||||
mockedRunEmbeddedAttempt,
|
||||
overflowBaseRunParams,
|
||||
resetRunOverflowCompactionHarnessMocks,
|
||||
resetSharedRunIntegrationHarnessMocks,
|
||||
} from "./run.overflow-compaction.harness.js";
|
||||
import { loadSharedRunIntegrationHarness } from "./run.shared-integration-harness.test-support.js";
|
||||
|
||||
@@ -54,7 +54,7 @@ describe("runEmbeddedAgent before_agent_reply seam", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetRunOverflowCompactionHarnessMocks();
|
||||
resetSharedRunIntegrationHarnessMocks();
|
||||
});
|
||||
|
||||
it("lets before_agent_reply claim cron runs before the embedded attempt starts", async () => {
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
mockedMarkAuthProfileFailure,
|
||||
mockedRunEmbeddedAttempt,
|
||||
overflowBaseRunParams,
|
||||
resetRunOverflowCompactionHarnessMocks,
|
||||
resetSharedRunIntegrationHarnessMocks,
|
||||
} from "./run.overflow-compaction.harness.js";
|
||||
import { loadSharedRunIntegrationHarness } from "./run.shared-integration-harness.test-support.js";
|
||||
import { hasCodexAppServerRecoveryRetryBudget } from "./run/codex-app-server-recovery.js";
|
||||
@@ -98,7 +98,7 @@ describe("runEmbeddedAgent Codex app-server recovery", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetRunOverflowCompactionHarnessMocks();
|
||||
resetSharedRunIntegrationHarnessMocks();
|
||||
mockedClassifyFailoverReason.mockReturnValue(null);
|
||||
});
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
mockedIsFailoverAssistantError,
|
||||
mockedRunEmbeddedAttempt,
|
||||
overflowBaseRunParams,
|
||||
resetRunOverflowCompactionHarnessMocks,
|
||||
resetSharedRunIntegrationHarnessMocks,
|
||||
useOpenAIPlatformAuthFixture,
|
||||
} from "./run.overflow-compaction.harness.js";
|
||||
import { loadSharedRunIntegrationHarness } from "./run.shared-integration-harness.test-support.js";
|
||||
@@ -24,7 +24,7 @@ describe("runEmbeddedAgent Codex server_error fallback handoff", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetRunOverflowCompactionHarnessMocks();
|
||||
resetSharedRunIntegrationHarnessMocks();
|
||||
useOpenAIPlatformAuthFixture();
|
||||
mockedGlobalHookRunner.hasHooks.mockImplementation(() => false);
|
||||
});
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
mockedIsCompactionFailureError,
|
||||
mockedIsLikelyContextOverflowError,
|
||||
mockedRunEmbeddedAttempt,
|
||||
resetRunOverflowCompactionHarnessMocks,
|
||||
resetSharedRunIntegrationHarnessMocks,
|
||||
} from "./run.overflow-compaction.harness.js";
|
||||
import { loadSharedRunIntegrationHarness } from "./run.shared-integration-harness.test-support.js";
|
||||
|
||||
@@ -111,7 +111,7 @@ describe("post-compaction loop guard wired into runEmbeddedAgent", () => {
|
||||
beforeEach(() => {
|
||||
liveToolCallSeq = 0;
|
||||
diagnosticSessionStates.clear();
|
||||
resetRunOverflowCompactionHarnessMocks();
|
||||
resetSharedRunIntegrationHarnessMocks();
|
||||
mockedIsCompactionFailureError.mockImplementation((msg?: string) => {
|
||||
if (!msg) {
|
||||
return false;
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ import {
|
||||
mockedRunEmbeddedAttempt,
|
||||
mockedResolveAuthProfileOrder,
|
||||
overflowBaseRunParams,
|
||||
resetRunOverflowCompactionHarnessMocks,
|
||||
resetSharedRunIntegrationHarnessMocks,
|
||||
warmRunOverflowCompactionHarness,
|
||||
} from "./run.overflow-compaction.harness.js";
|
||||
import { loadSharedRunIntegrationHarness } from "./run.shared-integration-harness.test-support.js";
|
||||
@@ -174,7 +174,7 @@ describe("runEmbeddedAgent cross-provider fallback error handling", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetRunOverflowCompactionHarnessMocks();
|
||||
resetSharedRunIntegrationHarnessMocks();
|
||||
useCrossProviderAuthFixture();
|
||||
mockedGlobalHookRunner.hasHooks.mockImplementation(() => false);
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
mockedGlobalHookRunner,
|
||||
mockedRunEmbeddedAttempt,
|
||||
overflowBaseRunParams,
|
||||
resetRunOverflowCompactionHarnessMocks,
|
||||
resetSharedRunIntegrationHarnessMocks,
|
||||
} from "./run.overflow-compaction.harness.js";
|
||||
import { loadSharedRunIntegrationHarness } from "./run.shared-integration-harness.test-support.js";
|
||||
import { buildEmbeddedRunPayloads as realBuildEmbeddedRunPayloads } from "./run/payloads.js";
|
||||
@@ -67,7 +67,7 @@ describe("runEmbeddedAgent silent-error retry", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetRunOverflowCompactionHarnessMocks();
|
||||
resetSharedRunIntegrationHarnessMocks();
|
||||
mockedGlobalHookRunner.hasHooks.mockImplementation(() => false);
|
||||
mockedClassifyFailoverReason.mockReturnValue(null);
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
mockedGlobalHookRunner,
|
||||
mockedRunEmbeddedAttempt,
|
||||
overflowBaseRunParams,
|
||||
resetRunOverflowCompactionHarnessMocks,
|
||||
resetSharedRunIntegrationHarnessMocks,
|
||||
} from "./run.overflow-compaction.harness.js";
|
||||
import { loadSharedRunIntegrationHarness } from "./run.shared-integration-harness.test-support.js";
|
||||
import type { EmbeddedRunAttemptResult } from "./run/types.js";
|
||||
@@ -57,7 +57,7 @@ describe("runEmbeddedAgent fast auto progress", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetRunOverflowCompactionHarnessMocks();
|
||||
resetSharedRunIntegrationHarnessMocks();
|
||||
mockedGlobalHookRunner.hasHooks.mockImplementation(() => false);
|
||||
mockedClassifyFailoverReason.mockReturnValue(null);
|
||||
});
|
||||
|
||||
@@ -447,10 +447,7 @@ export const overflowBaseRunParams = {
|
||||
runId: "run-1",
|
||||
} as const;
|
||||
|
||||
/** Reset every mocked runner dependency to the default successful no-op state. */
|
||||
export function resetRunOverflowCompactionHarnessMocks(): void {
|
||||
vi.unstubAllEnvs();
|
||||
resetCommandQueueStateForTest();
|
||||
function resetMockAgentHarness(): void {
|
||||
clearAgentHarnesses();
|
||||
registerAgentHarness({
|
||||
id: "codex",
|
||||
@@ -472,6 +469,13 @@ export function resetRunOverflowCompactionHarnessMocks(): void {
|
||||
return { assistant, ...(result.attemptUsage ? { usage: result.attemptUsage } : {}) };
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** Reset every mocked runner dependency to the default successful no-op state. */
|
||||
function resetRunOverflowCompactionHarnessMocks(): void {
|
||||
vi.unstubAllEnvs();
|
||||
resetCommandQueueStateForTest();
|
||||
resetMockAgentHarness();
|
||||
mockedGlobalHookRunner.hasHooks.mockReset();
|
||||
mockedGlobalHookRunner.hasHooks.mockReturnValue(false);
|
||||
mockedGlobalHookRunner.runBeforeAgentReply.mockReset();
|
||||
@@ -663,6 +667,80 @@ export function resetRunOverflowCompactionHarnessMocks(): void {
|
||||
mockedSleepWithAbort.mockResolvedValue(undefined);
|
||||
}
|
||||
|
||||
/** Reset only the seams mutated by the shared public-entry integration suites. */
|
||||
export function resetSharedRunIntegrationHarnessMocks(): void {
|
||||
vi.unstubAllEnvs();
|
||||
resetCommandQueueStateForTest();
|
||||
resetMockAgentHarness();
|
||||
|
||||
mockedBuildEmbeddedRunPayloads.mockReset();
|
||||
mockedBuildEmbeddedRunPayloads.mockReturnValue([]);
|
||||
mockedClassifyFailoverReason.mockReset();
|
||||
mockedClassifyFailoverReason.mockReturnValue(null);
|
||||
mockedClassifyAssistantFailoverReason.mockReset();
|
||||
mockedClassifyAssistantFailoverReason.mockImplementation(
|
||||
(assistant?: { errorMessage?: string | null }): FailoverReason | null =>
|
||||
mockedClassifyFailoverReason(assistant?.errorMessage ?? ""),
|
||||
);
|
||||
mockedCompactDirect.mockReset();
|
||||
mockedCompactDirect.mockResolvedValue({
|
||||
ok: false,
|
||||
compacted: false,
|
||||
reason: "nothing to compact",
|
||||
});
|
||||
mockedEnsureAuthProfileStore.mockReset();
|
||||
mockedEnsureAuthProfileStore.mockReturnValue({ version: 1, profiles: {} });
|
||||
mockedEnsureAuthProfileStoreWithoutExternalProfiles.mockReset();
|
||||
mockedEnsureAuthProfileStoreWithoutExternalProfiles.mockReturnValue({
|
||||
version: 1,
|
||||
profiles: {},
|
||||
});
|
||||
mockedFormatAssistantErrorText.mockReset();
|
||||
mockedFormatAssistantErrorText.mockReturnValue("");
|
||||
mockedGetApiKeyForModel.mockReset();
|
||||
mockedGetApiKeyForModel.mockImplementation(
|
||||
async ({ profileId }: MockGetApiKeyForModelParams = {}) => ({
|
||||
apiKey: "test-key",
|
||||
profileId: profileId ?? "test-profile",
|
||||
source: "test",
|
||||
mode: "api-key",
|
||||
}),
|
||||
);
|
||||
mockedGlobalHookRunner.hasHooks.mockReset();
|
||||
mockedGlobalHookRunner.hasHooks.mockReturnValue(false);
|
||||
mockedGlobalHookRunner.runBeforeAgentReply.mockReset();
|
||||
mockedGlobalHookRunner.runBeforeAgentReply.mockResolvedValue(undefined);
|
||||
mockedIsCompactionFailureError.mockReset();
|
||||
mockedIsCompactionFailureError.mockReturnValue(false);
|
||||
mockedIsFailoverAssistantError.mockReset();
|
||||
mockedIsFailoverAssistantError.mockReturnValue(false);
|
||||
mockedIsLikelyContextOverflowError.mockReset();
|
||||
mockedIsLikelyContextOverflowError.mockImplementation((msg?: string) => {
|
||||
const lower = normalizeLowercaseStringOrEmpty(msg ?? "");
|
||||
return (
|
||||
lower.includes("request_too_large") ||
|
||||
lower.includes("context window exceeded") ||
|
||||
(lower.includes("context window") && lower.includes("ran out of room")) ||
|
||||
lower.includes("prompt is too long")
|
||||
);
|
||||
});
|
||||
mockedIsRateLimitAssistantError.mockReset();
|
||||
mockedIsRateLimitAssistantError.mockReturnValue(false);
|
||||
mockedResolveAuthProfileOrder.mockReset();
|
||||
mockedResolveAuthProfileOrder.mockReturnValue([]);
|
||||
mockedResolveModelAsync.mockReset();
|
||||
mockedResolveModelAsync.mockImplementation(
|
||||
async (provider?: string, modelId?: string, _agentDir?: string, cfg?: unknown) =>
|
||||
createMockResolvedModel(provider, modelId, cfg),
|
||||
);
|
||||
mockedRunEmbeddedAttempt.mockReset();
|
||||
|
||||
mockedAcquireAgentRunPreparedModelRuntime.mockClear();
|
||||
mockedLog.warn.mockClear();
|
||||
mockedMarkAuthProfileFailure.mockClear();
|
||||
mockedSleepWithAbort.mockClear();
|
||||
}
|
||||
|
||||
/** Install module mocks, import the runner, and return the mocked entrypoint. */
|
||||
export async function loadRunOverflowCompactionHarness(): Promise<{
|
||||
runEmbeddedAgent: typeof import("./run.js").runEmbeddedAgent;
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
mockedClassifyFailoverReason,
|
||||
mockedRunEmbeddedAttempt,
|
||||
overflowBaseRunParams,
|
||||
resetRunOverflowCompactionHarnessMocks,
|
||||
resetSharedRunIntegrationHarnessMocks,
|
||||
useOpenAIPlatformAuthFixture,
|
||||
} from "./run.overflow-compaction.harness.js";
|
||||
import { loadSharedRunIntegrationHarness } from "./run.shared-integration-harness.test-support.js";
|
||||
@@ -20,7 +20,7 @@ describe("runEmbeddedAgent prompt timeout fallback handoff", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetRunOverflowCompactionHarnessMocks();
|
||||
resetSharedRunIntegrationHarnessMocks();
|
||||
useOpenAIPlatformAuthFixture();
|
||||
});
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
mockedResolveAuthProfileOrder,
|
||||
mockedRunEmbeddedAttempt,
|
||||
overflowBaseRunParams,
|
||||
resetRunOverflowCompactionHarnessMocks,
|
||||
resetSharedRunIntegrationHarnessMocks,
|
||||
} from "./run.overflow-compaction.harness.js";
|
||||
import { loadSharedRunIntegrationHarness } from "./run.shared-integration-harness.test-support.js";
|
||||
|
||||
@@ -34,7 +34,7 @@ describe("runEmbeddedAgent timeout recovery composition", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetRunOverflowCompactionHarnessMocks();
|
||||
resetSharedRunIntegrationHarnessMocks();
|
||||
});
|
||||
|
||||
it("adopts a compacted transcript and retries with the complete runtime context", async () => {
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
mockedGlobalHookRunner,
|
||||
mockedRunEmbeddedAttempt,
|
||||
overflowBaseRunParams,
|
||||
resetRunOverflowCompactionHarnessMocks,
|
||||
resetSharedRunIntegrationHarnessMocks,
|
||||
} from "./run.overflow-compaction.harness.js";
|
||||
import { loadSharedRunIntegrationHarness } from "./run.shared-integration-harness.test-support.js";
|
||||
import { isEmbeddedAgentRunActive, queueEmbeddedAgentMessageWithOutcome } from "./runs.js";
|
||||
@@ -23,7 +23,7 @@ describe("sessions_yield orchestration", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetRunOverflowCompactionHarnessMocks();
|
||||
resetSharedRunIntegrationHarnessMocks();
|
||||
mockedGlobalHookRunner.hasHooks.mockImplementation(() => false);
|
||||
});
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
mockedAcquireAgentRunPreparedModelRuntime,
|
||||
mockedResolveModelAsync,
|
||||
mockedRunEmbeddedAttempt,
|
||||
resetRunOverflowCompactionHarnessMocks,
|
||||
resetSharedRunIntegrationHarnessMocks,
|
||||
} from "./run.overflow-compaction.harness.js";
|
||||
import { loadSharedRunIntegrationHarness } from "./run.shared-integration-harness.test-support.js";
|
||||
import type { EmbeddedRunAttemptResult } from "./run/types.js";
|
||||
@@ -48,7 +48,7 @@ describe("runEmbeddedAgent usage reporting", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetRunOverflowCompactionHarnessMocks();
|
||||
resetSharedRunIntegrationHarnessMocks();
|
||||
});
|
||||
|
||||
it("bootstraps runtime plugins with the resolved workspace before running", async () => {
|
||||
|
||||
Reference in New Issue
Block a user