perf(test): consolidate auth/pty/health mini suites
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
@@ -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");
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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"),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -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"),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user