test(gateway): speed up slow e2e test setup

This commit is contained in:
Peter Steinberger
2026-02-24 00:59:44 +00:00
parent 13478cc79a
commit 0cc327546b
7 changed files with 61 additions and 55 deletions

View File

@@ -1,4 +1,12 @@
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import {
loadOrCreateDeviceIdentity,
publicKeyRawBase64UrlFromPem,
signDevicePayload,
} from "../infra/device-identity.js";
import { buildDeviceAuthPayload } from "./device-auth.js";
import {
connectOk,
installGatewayTestHooks,
@@ -10,21 +18,16 @@ import { withServer } from "./test-with-server.js";
installGatewayTestHooks({ scope: "suite" });
type GatewaySocket = Parameters<Parameters<typeof withServer>[0]>[0];
const TALK_CONFIG_DEVICE_PATH = path.join(
os.tmpdir(),
`openclaw-talk-config-device-${process.pid}.json`,
);
const TALK_CONFIG_DEVICE = loadOrCreateDeviceIdentity(TALK_CONFIG_DEVICE_PATH);
async function createFreshOperatorDevice(scopes: string[], nonce: string) {
const { randomUUID } = await import("node:crypto");
const { tmpdir } = await import("node:os");
const { join } = await import("node:path");
const { buildDeviceAuthPayload } = await import("./device-auth.js");
const { loadOrCreateDeviceIdentity, publicKeyRawBase64UrlFromPem, signDevicePayload } =
await import("../infra/device-identity.js");
const identity = loadOrCreateDeviceIdentity(
join(tmpdir(), `openclaw-talk-config-${randomUUID()}.json`),
);
const signedAtMs = Date.now();
const payload = buildDeviceAuthPayload({
deviceId: identity.deviceId,
deviceId: TALK_CONFIG_DEVICE.deviceId,
clientId: "test",
clientMode: "test",
role: "operator",
@@ -35,9 +38,9 @@ async function createFreshOperatorDevice(scopes: string[], nonce: string) {
});
return {
id: identity.deviceId,
publicKey: publicKeyRawBase64UrlFromPem(identity.publicKeyPem),
signature: signDevicePayload(identity.privateKeyPem, payload),
id: TALK_CONFIG_DEVICE.deviceId,
publicKey: publicKeyRawBase64UrlFromPem(TALK_CONFIG_DEVICE.publicKeyPem),
signature: signDevicePayload(TALK_CONFIG_DEVICE.privateKeyPem, payload),
signedAt: signedAtMs,
nonce,
};