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,13 +1,14 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { defaultRuntime } from "../runtime.js";
import {
restoreStateDirEnv,
setStateDirEnv,
snapshotStateDirEnv,
} from "../test-helpers/state-dir-env.js";
import { createCanvasHostHandler } from "./server.js";
describe("canvas host state dir defaults", () => {
let envSnapshot: ReturnType<typeof snapshotStateDirEnv>;
@@ -17,7 +18,6 @@ describe("canvas host state dir defaults", () => {
});
afterEach(() => {
vi.resetModules();
restoreStateDirEnv(envSnapshot);
});
@@ -25,9 +25,6 @@ describe("canvas host state dir defaults", () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-canvas-state-"));
const stateDir = path.join(tempRoot, "state");
setStateDirEnv(stateDir);
vi.resetModules();
const { createCanvasHostHandler } = await import("./server.js");
const handler = await createCanvasHostHandler({
runtime: defaultRuntime,
allowInTests: true,

View File

@@ -7,7 +7,7 @@ import http, { type IncomingMessage, type Server, type ServerResponse } from "no
import path from "node:path";
import { type WebSocket, WebSocketServer } from "ws";
import type { RuntimeEnv } from "../runtime.js";
import { STATE_DIR } from "../config/paths.js";
import { resolveStateDir } from "../config/paths.js";
import { isTruthyEnvValue } from "../infra/env.js";
import { SafeOpenError, openFileWithinRoot } from "../infra/fs-safe.js";
import { detectMime } from "../media/mime.js";
@@ -235,7 +235,7 @@ async function prepareCanvasRoot(rootDir: string) {
}
function resolveDefaultCanvasRoot(): string {
const candidates = [path.join(STATE_DIR, "canvas")];
const candidates = [path.join(resolveStateDir(), "canvas")];
const existing = candidates.find((dir) => {
try {
return fsSync.statSync(dir).isDirectory();