perf(test): reduce module reload overhead in key suites

This commit is contained in:
Peter Steinberger
2026-02-13 15:45:08 +00:00
parent 4337fa2096
commit 41f2f359a5
12 changed files with 114 additions and 116 deletions

View File

@@ -1,7 +1,7 @@
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
import { STATE_DIR } from "../config/paths.js";
import { resolveStateDir } from "../config/paths.js";
export type DeviceIdentity = {
deviceId: string;
@@ -17,8 +17,9 @@ type StoredIdentity = {
createdAtMs: number;
};
const DEFAULT_DIR = path.join(STATE_DIR, "identity");
const DEFAULT_FILE = path.join(DEFAULT_DIR, "device.json");
function resolveDefaultIdentityPath(): string {
return path.join(resolveStateDir(), "identity", "device.json");
}
function ensureDir(filePath: string) {
fs.mkdirSync(path.dirname(filePath), { recursive: true });
@@ -61,7 +62,9 @@ function generateIdentity(): DeviceIdentity {
return { deviceId, publicKeyPem, privateKeyPem };
}
export function loadOrCreateDeviceIdentity(filePath: string = DEFAULT_FILE): DeviceIdentity {
export function loadOrCreateDeviceIdentity(
filePath: string = resolveDefaultIdentityPath(),
): DeviceIdentity {
try {
if (fs.existsSync(filePath)) {
const raw = fs.readFileSync(filePath, "utf8");