test: speed up heavy suites with shared fixtures

This commit is contained in:
Peter Steinberger
2026-03-02 21:58:19 +00:00
parent 6358aae024
commit 3beb1b9da9
12 changed files with 227 additions and 151 deletions

View File

@@ -1,4 +1,3 @@
import { randomUUID } from "node:crypto";
import os from "node:os";
import path from "node:path";
import { expect } from "vitest";
@@ -22,6 +21,22 @@ import {
withGatewayServer,
} from "./test-helpers.js";
let authIdentityPathSeq = 0;
function nextAuthIdentityPath(prefix: string): string {
const poolId = process.env.VITEST_POOL_ID ?? "0";
const fileName =
prefix +
"-" +
String(process.pid) +
"-" +
poolId +
"-" +
String(authIdentityPathSeq++) +
".json";
return path.join(os.tmpdir(), fileName);
}
async function waitForWsClose(ws: WebSocket, timeoutMs: number): Promise<boolean> {
if (ws.readyState === WebSocket.CLOSED) {
return true;
@@ -287,10 +302,7 @@ async function startRateLimitedTokenServerWithPairedDeviceToken() {
} as any;
const { server, ws, port, prevToken } = await startServerWithClient();
const deviceIdentityPath = path.join(
os.tmpdir(),
"openclaw-auth-rate-limit-" + randomUUID() + ".json",
);
const deviceIdentityPath = nextAuthIdentityPath("openclaw-auth-rate-limit");
try {
const initial = await connectReq(ws, { token: "secret", deviceIdentityPath });
if (!initial.ok) {
@@ -321,10 +333,7 @@ async function ensurePairedDeviceTokenForCurrentIdentity(ws: WebSocket): Promise
const { loadOrCreateDeviceIdentity } = await import("../infra/device-identity.js");
const { getPairedDevice } = await import("../infra/device-pairing.js");
const deviceIdentityPath = path.join(
os.tmpdir(),
"openclaw-auth-device-" + randomUUID() + ".json",
);
const deviceIdentityPath = nextAuthIdentityPath("openclaw-auth-device");
const res = await connectReq(ws, { token: "secret", deviceIdentityPath });
if (!res.ok) {