mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 16:20:23 +00:00
test: speed up heavy suites with shared fixtures
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user