From ea07d3fdd814be139371eae275a459fa10d97640 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 16 Feb 2026 01:12:21 +0000 Subject: [PATCH] perf(test): consolidate auth/pty/health mini suites --- ...rofiles.auth-profile-cooldowns.e2e.test.ts | 12 ------- ...rofiles.markauthprofilefailure.e2e.test.ts | 16 ++++++++- src/agents/pty-dsr.e2e.test.ts | 14 -------- src/agents/pty-keys.e2e.test.ts | 13 +++++++ src/agents/subagent-depth.test.ts | 13 +++++++ src/agents/timeout.e2e.test.ts | 14 -------- src/commands/health-format.e2e.test.ts | 34 ------------------- src/commands/health.e2e.test.ts | 33 ++++++++++++++++++ 8 files changed, 74 insertions(+), 75 deletions(-) delete mode 100644 src/agents/auth-profiles.auth-profile-cooldowns.e2e.test.ts delete mode 100644 src/agents/pty-dsr.e2e.test.ts delete mode 100644 src/agents/timeout.e2e.test.ts delete mode 100644 src/commands/health-format.e2e.test.ts diff --git a/src/agents/auth-profiles.auth-profile-cooldowns.e2e.test.ts b/src/agents/auth-profiles.auth-profile-cooldowns.e2e.test.ts deleted file mode 100644 index e5fe3900a..000000000 --- a/src/agents/auth-profiles.auth-profile-cooldowns.e2e.test.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { calculateAuthProfileCooldownMs } from "./auth-profiles.js"; - -describe("auth profile cooldowns", () => { - it("applies exponential backoff with a 1h cap", () => { - expect(calculateAuthProfileCooldownMs(1)).toBe(60_000); - expect(calculateAuthProfileCooldownMs(2)).toBe(5 * 60_000); - expect(calculateAuthProfileCooldownMs(3)).toBe(25 * 60_000); - expect(calculateAuthProfileCooldownMs(4)).toBe(60 * 60_000); - expect(calculateAuthProfileCooldownMs(5)).toBe(60 * 60_000); - }); -}); diff --git a/src/agents/auth-profiles.markauthprofilefailure.e2e.test.ts b/src/agents/auth-profiles.markauthprofilefailure.e2e.test.ts index 0fc86907d..1a8cfb16e 100644 --- a/src/agents/auth-profiles.markauthprofilefailure.e2e.test.ts +++ b/src/agents/auth-profiles.markauthprofilefailure.e2e.test.ts @@ -2,7 +2,11 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { describe, expect, it } from "vitest"; -import { ensureAuthProfileStore, markAuthProfileFailure } from "./auth-profiles.js"; +import { + calculateAuthProfileCooldownMs, + ensureAuthProfileStore, + markAuthProfileFailure, +} from "./auth-profiles.js"; describe("markAuthProfileFailure", () => { it("disables billing failures for ~5 hours by default", async () => { @@ -129,3 +133,13 @@ describe("markAuthProfileFailure", () => { } }); }); + +describe("calculateAuthProfileCooldownMs", () => { + it("applies exponential backoff with a 1h cap", () => { + expect(calculateAuthProfileCooldownMs(1)).toBe(60_000); + expect(calculateAuthProfileCooldownMs(2)).toBe(5 * 60_000); + expect(calculateAuthProfileCooldownMs(3)).toBe(25 * 60_000); + expect(calculateAuthProfileCooldownMs(4)).toBe(60 * 60_000); + expect(calculateAuthProfileCooldownMs(5)).toBe(60 * 60_000); + }); +}); diff --git a/src/agents/pty-dsr.e2e.test.ts b/src/agents/pty-dsr.e2e.test.ts deleted file mode 100644 index a71f95c02..000000000 --- a/src/agents/pty-dsr.e2e.test.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { expect, test } from "vitest"; -import { buildCursorPositionResponse, stripDsrRequests } from "./pty-dsr.js"; - -test("stripDsrRequests removes cursor queries and counts them", () => { - const input = "hi\x1b[6nthere\x1b[?6n"; - const { cleaned, requests } = stripDsrRequests(input); - expect(cleaned).toBe("hithere"); - expect(requests).toBe(2); -}); - -test("buildCursorPositionResponse returns CPR sequence", () => { - expect(buildCursorPositionResponse()).toBe("\x1b[1;1R"); - expect(buildCursorPositionResponse(12, 34)).toBe("\x1b[12;34R"); -}); diff --git a/src/agents/pty-keys.e2e.test.ts b/src/agents/pty-keys.e2e.test.ts index a295a11b8..36fe6bcdf 100644 --- a/src/agents/pty-keys.e2e.test.ts +++ b/src/agents/pty-keys.e2e.test.ts @@ -1,4 +1,5 @@ import { expect, test } from "vitest"; +import { buildCursorPositionResponse, stripDsrRequests } from "./pty-dsr.js"; import { BRACKETED_PASTE_END, BRACKETED_PASTE_START, @@ -38,3 +39,15 @@ test("encodePaste wraps bracketed sequences by default", () => { expect(payload.startsWith(BRACKETED_PASTE_START)).toBe(true); expect(payload.endsWith(BRACKETED_PASTE_END)).toBe(true); }); + +test("stripDsrRequests removes cursor queries and counts them", () => { + const input = "hi\x1b[6nthere\x1b[?6n"; + const { cleaned, requests } = stripDsrRequests(input); + expect(cleaned).toBe("hithere"); + expect(requests).toBe(2); +}); + +test("buildCursorPositionResponse returns CPR sequence", () => { + expect(buildCursorPositionResponse()).toBe("\x1b[1;1R"); + expect(buildCursorPositionResponse(12, 34)).toBe("\x1b[12;34R"); +}); diff --git a/src/agents/subagent-depth.test.ts b/src/agents/subagent-depth.test.ts index 66980d2d0..5d9427b78 100644 --- a/src/agents/subagent-depth.test.ts +++ b/src/agents/subagent-depth.test.ts @@ -3,6 +3,7 @@ import os from "node:os"; import path from "node:path"; import { describe, expect, it } from "vitest"; import { getSubagentDepthFromSessionStore } from "./subagent-depth.js"; +import { resolveAgentTimeoutMs } from "./timeout.js"; describe("getSubagentDepthFromSessionStore", () => { it("uses spawnDepth from the session store when available", () => { @@ -85,3 +86,15 @@ describe("getSubagentDepthFromSessionStore", () => { expect(depth).toBe(1); }); }); + +describe("resolveAgentTimeoutMs", () => { + it("uses a timer-safe sentinel for no-timeout overrides", () => { + expect(resolveAgentTimeoutMs({ overrideSeconds: 0 })).toBe(2_147_000_000); + expect(resolveAgentTimeoutMs({ overrideMs: 0 })).toBe(2_147_000_000); + }); + + it("clamps very large timeout overrides to timer-safe values", () => { + expect(resolveAgentTimeoutMs({ overrideSeconds: 9_999_999 })).toBe(2_147_000_000); + expect(resolveAgentTimeoutMs({ overrideMs: 9_999_999_999 })).toBe(2_147_000_000); + }); +}); diff --git a/src/agents/timeout.e2e.test.ts b/src/agents/timeout.e2e.test.ts deleted file mode 100644 index 37a96a9ff..000000000 --- a/src/agents/timeout.e2e.test.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { resolveAgentTimeoutMs } from "./timeout.js"; - -describe("resolveAgentTimeoutMs", () => { - it("uses a timer-safe sentinel for no-timeout overrides", () => { - expect(resolveAgentTimeoutMs({ overrideSeconds: 0 })).toBe(2_147_000_000); - expect(resolveAgentTimeoutMs({ overrideMs: 0 })).toBe(2_147_000_000); - }); - - it("clamps very large timeout overrides to timer-safe values", () => { - expect(resolveAgentTimeoutMs({ overrideSeconds: 9_999_999 })).toBe(2_147_000_000); - expect(resolveAgentTimeoutMs({ overrideMs: 9_999_999_999 })).toBe(2_147_000_000); - }); -}); diff --git a/src/commands/health-format.e2e.test.ts b/src/commands/health-format.e2e.test.ts deleted file mode 100644 index 7381743f1..000000000 --- a/src/commands/health-format.e2e.test.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { stripAnsi } from "../terminal/ansi.js"; -import { formatHealthCheckFailure } from "./health-format.js"; - -describe("formatHealthCheckFailure", () => { - it("keeps non-rich output stable", () => { - const err = new Error("gateway closed (1006 abnormal closure): no close reason"); - expect(formatHealthCheckFailure(err, { rich: false })).toBe( - `Health check failed: ${String(err)}`, - ); - }); - - it("formats gateway connection details as indented key/value lines", () => { - const err = new Error( - [ - "gateway closed (1006 abnormal closure (no close frame)): no close reason", - "Gateway target: ws://127.0.0.1:19001", - "Source: local loopback", - "Config: /Users/steipete/.openclaw-dev/openclaw.json", - "Bind: loopback", - ].join("\n"), - ); - - expect(stripAnsi(formatHealthCheckFailure(err, { rich: true }))).toBe( - [ - "Health check failed: gateway closed (1006 abnormal closure (no close frame)): no close reason", - " Gateway target: ws://127.0.0.1:19001", - " Source: local loopback", - " Config: /Users/steipete/.openclaw-dev/openclaw.json", - " Bind: loopback", - ].join("\n"), - ); - }); -}); diff --git a/src/commands/health.e2e.test.ts b/src/commands/health.e2e.test.ts index 289af11bb..e452b1389 100644 --- a/src/commands/health.e2e.test.ts +++ b/src/commands/health.e2e.test.ts @@ -1,5 +1,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; import type { HealthSummary } from "./health.js"; +import { stripAnsi } from "../terminal/ansi.js"; +import { formatHealthCheckFailure } from "./health-format.js"; import { formatHealthChannelLines, healthCommand } from "./health.js"; const runtime = { @@ -173,3 +175,34 @@ describe("healthCommand", () => { ); }); }); + +describe("formatHealthCheckFailure", () => { + it("keeps non-rich output stable", () => { + const err = new Error("gateway closed (1006 abnormal closure): no close reason"); + expect(formatHealthCheckFailure(err, { rich: false })).toBe( + `Health check failed: ${String(err)}`, + ); + }); + + it("formats gateway connection details as indented key/value lines", () => { + const err = new Error( + [ + "gateway closed (1006 abnormal closure (no close frame)): no close reason", + "Gateway target: ws://127.0.0.1:19001", + "Source: local loopback", + "Config: /Users/steipete/.openclaw-dev/openclaw.json", + "Bind: loopback", + ].join("\n"), + ); + + expect(stripAnsi(formatHealthCheckFailure(err, { rich: true }))).toBe( + [ + "Health check failed: gateway closed (1006 abnormal closure (no close frame)): no close reason", + " Gateway target: ws://127.0.0.1:19001", + " Source: local loopback", + " Config: /Users/steipete/.openclaw-dev/openclaw.json", + " Bind: loopback", + ].join("\n"), + ); + }); +});