mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 18:00:22 +00:00
Tests: fix flaky shard expectations
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
createManagedRun,
|
||||
enqueueSystemEventMock,
|
||||
requestHeartbeatNowMock,
|
||||
EXISTING_CODEX_CONFIG,
|
||||
setupCliRunnerTestModule,
|
||||
supervisorSpawnMock,
|
||||
} from "./cli-runner.test-support.js";
|
||||
@@ -174,6 +175,7 @@ describe("runCliAgent reliability", () => {
|
||||
prompt: "hi",
|
||||
provider: "codex-cli",
|
||||
model: "gpt-5.4",
|
||||
config: EXISTING_CODEX_CONFIG,
|
||||
timeoutMs: 1_000,
|
||||
runId: "run-retry-failure",
|
||||
cliSessionId: "thread-123",
|
||||
|
||||
@@ -5,7 +5,7 @@ import { formatErrorMessage } from "../infra/errors.js";
|
||||
import { executePreparedCliRun } from "./cli-runner/execute.js";
|
||||
import { prepareCliRunContext } from "./cli-runner/prepare.js";
|
||||
import type { RunCliAgentParams } from "./cli-runner/types.js";
|
||||
import { FailoverError, resolveFailoverStatus } from "./failover-error.js";
|
||||
import { FailoverError, isFailoverError, resolveFailoverStatus } from "./failover-error.js";
|
||||
import { classifyFailoverReason, isFailoverErrorMessage } from "./pi-embedded-helpers.js";
|
||||
import type { EmbeddedPiRunResult } from "./pi-embedded-runner.js";
|
||||
|
||||
@@ -56,13 +56,10 @@ export async function runCliAgent(params: RunCliAgentParams): Promise<EmbeddedPi
|
||||
const effectiveCliSessionId = output.sessionId ?? context.reusableCliSession.sessionId;
|
||||
return buildCliRunResult({ output, effectiveCliSessionId });
|
||||
} catch (err) {
|
||||
if (err instanceof FailoverError) {
|
||||
if (isFailoverError(err)) {
|
||||
const retryableSessionId = context.reusableCliSession.sessionId ?? params.cliSessionId;
|
||||
// Check if this is a session expired error and we have a session to clear
|
||||
if (
|
||||
err.reason === "session_expired" &&
|
||||
context.reusableCliSession.sessionId &&
|
||||
params.sessionKey
|
||||
) {
|
||||
if (err.reason === "session_expired" && retryableSessionId && params.sessionKey) {
|
||||
// Clear the expired session ID from the session entry
|
||||
// This requires access to the session store, which we don't have here
|
||||
// We'll need to modify the caller to handle this case
|
||||
|
||||
@@ -40,7 +40,15 @@ export class FailoverError extends Error {
|
||||
}
|
||||
|
||||
export function isFailoverError(err: unknown): err is FailoverError {
|
||||
return err instanceof FailoverError;
|
||||
if (err instanceof FailoverError) {
|
||||
return true;
|
||||
}
|
||||
return Boolean(
|
||||
err &&
|
||||
typeof err === "object" &&
|
||||
(err as { name?: unknown }).name === "FailoverError" &&
|
||||
typeof (err as { reason?: unknown }).reason === "string",
|
||||
);
|
||||
}
|
||||
|
||||
export function resolveFailoverStatus(reason: FailoverReason): number | undefined {
|
||||
|
||||
@@ -178,6 +178,7 @@ describe("callGateway url resolution", () => {
|
||||
const envSnapshot = captureEnv([
|
||||
"OPENCLAW_ALLOW_INSECURE_PRIVATE_WS",
|
||||
"OPENCLAW_CONFIG_PATH",
|
||||
"OPENCLAW_GATEWAY_PORT",
|
||||
"OPENCLAW_GATEWAY_URL",
|
||||
"OPENCLAW_GATEWAY_TOKEN",
|
||||
"OPENCLAW_STATE_DIR",
|
||||
@@ -187,6 +188,7 @@ describe("callGateway url resolution", () => {
|
||||
envSnapshot.restore();
|
||||
delete process.env.OPENCLAW_ALLOW_INSECURE_PRIVATE_WS;
|
||||
delete process.env.OPENCLAW_CONFIG_PATH;
|
||||
delete process.env.OPENCLAW_GATEWAY_PORT;
|
||||
delete process.env.OPENCLAW_GATEWAY_URL;
|
||||
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||
delete process.env.OPENCLAW_STATE_DIR;
|
||||
@@ -612,6 +614,7 @@ describe("buildGatewayConnectionDetails", () => {
|
||||
resolveGatewayPort.mockReturnValue(18800);
|
||||
__testing.setDepsForTests({
|
||||
loadConfig: {} as never,
|
||||
resolveGatewayPort: () => 18789,
|
||||
});
|
||||
|
||||
const details = buildGatewayConnectionDetails();
|
||||
|
||||
@@ -96,7 +96,7 @@ describe("gateway cli backend live helpers", () => {
|
||||
clientDisplayName: "vitest-live",
|
||||
clientVersion: "dev",
|
||||
mode: GATEWAY_CLIENT_MODES.TEST,
|
||||
connectChallengeTimeoutMs: 30_000,
|
||||
connectChallengeTimeoutMs: 45_000,
|
||||
});
|
||||
expect(gatewayClientState.lastOptions).not.toHaveProperty("requestTimeoutMs");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user