test: reduce hotspot fixture overhead

This commit is contained in:
Peter Steinberger
2026-04-17 02:35:44 +01:00
parent 2cfb660a9b
commit 3a59eddd07
6 changed files with 68 additions and 48 deletions

View File

@@ -1,7 +1,7 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
import {
buildMultimodalChunkForIndexing,
buildFileEntry,
@@ -16,13 +16,24 @@ import {
type MemoryMultimodalSettings,
} from "./multimodal.js";
let sharedTempRoot = "";
let sharedTempId = 0;
beforeAll(async () => {
sharedTempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "memory-host-sdk-tests-"));
});
afterAll(async () => {
if (sharedTempRoot) {
await fs.rm(sharedTempRoot, { recursive: true, force: true });
}
});
function setupTempDirLifecycle(prefix: string): () => string {
let tmpDir = "";
beforeEach(async () => {
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
});
afterEach(async () => {
await fs.rm(tmpDir, { recursive: true, force: true });
tmpDir = path.join(sharedTempRoot, `${prefix}${sharedTempId++}`);
await fs.mkdir(tmpDir, { recursive: true });
});
return () => tmpDir;
}

View File

@@ -1011,7 +1011,7 @@ describe("Bundle chunk isolation (#40096)", () => {
const registryUrl = new URL("./registry.ts", import.meta.url).href;
const chunks = await Promise.all(
Array.from(
{ length: 5 },
{ length: 3 },
(_, i) => import(/* @vite-ignore */ `${registryUrl}?chunk=${ts}-${i}`),
),
);

View File

@@ -52,6 +52,10 @@ vi.mock("./infra/git-commit.js", () => ({
resolveCommitHash: resolveCommitHashMock,
}));
vi.mock("./infra/gaxios-fetch-compat.js", () => ({
installGaxiosFetchCompat: vi.fn(async () => {}),
}));
vi.mock("./infra/is-main.js", () => ({
isMainModule: isMainModuleMock,
}));

View File

@@ -21,19 +21,34 @@ printf '%s\n' '${escapedOutput}'
return { root, cliPath };
}
function resolveVersionsFromInstaller(cliPaths: string[]): string[] {
function resolveInstallerVersionCases(params: {
cliPaths: string[];
stdinCliPath: string;
stdinCwd: string;
}): string[] {
const installerPath = path.join(process.cwd(), "scripts", "install.sh");
const installerSource = fs.readFileSync(installerPath, "utf-8");
const output = execFileSync(
"bash",
[
"-lc",
`source "${installerPath}" >/dev/null 2>&1
for openclaw_bin in "$@"; do
for openclaw_bin in "\${@:3}"; do
OPENCLAW_BIN="$openclaw_bin"
resolve_openclaw_version
done`,
done
(
cd "$2"
FAKE_OPENCLAW_BIN="\${@:1:1}" bash -s <<'OPENCLAW_STDIN_INSTALLER'
${installerSource}
OPENCLAW_BIN="$FAKE_OPENCLAW_BIN"
resolve_openclaw_version
OPENCLAW_STDIN_INSTALLER
)`,
"openclaw-version-test",
...cliPaths,
params.stdinCliPath,
params.stdinCwd,
...params.cliPaths,
],
{
cwd: process.cwd(),
@@ -47,44 +62,17 @@ done`,
return output.trimEnd().split("\n");
}
function resolveVersionFromInstallerViaStdin(cliPath: string, cwd: string): string {
const installerPath = path.join(process.cwd(), "scripts", "install.sh");
const installerSource = fs.readFileSync(installerPath, "utf-8");
const output = execFileSync("bash", [], {
cwd,
encoding: "utf-8",
input: `${installerSource}
OPENCLAW_BIN="$FAKE_OPENCLAW_BIN"
resolve_openclaw_version
`,
env: {
...process.env,
FAKE_OPENCLAW_BIN: cliPath,
OPENCLAW_INSTALL_SH_NO_RUN: "1",
},
});
return output.trim();
}
describe("install.sh version resolution", () => {
afterEach(() => {
cleanupTempDirs(tempRoots);
});
it.runIf(process.platform !== "win32")("parses decorated and raw CLI versions", () => {
const decorated = withFakeCli("OpenClaw 2026.3.10 (abcdef0)");
const raw = withFakeCli("OpenClaw dev's build");
expect(resolveVersionsFromInstaller([decorated.cliPath, raw.cliPath])).toEqual([
"2026.3.10",
"OpenClaw dev's build",
]);
});
it.runIf(process.platform !== "win32")(
"does not source version helpers from cwd when installer runs via stdin",
"parses CLI versions and keeps stdin helpers isolated from cwd",
() => {
const fixture = withFakeCli("OpenClaw 2026.3.10 (abcdef0)");
const decorated = withFakeCli("OpenClaw 2026.3.10 (abcdef0)");
const raw = withFakeCli("OpenClaw dev's build");
const stdinFixture = withFakeCli("OpenClaw 2026.3.10 (abcdef0)");
const hostileCwd = makeTempDir(tempRoots, "openclaw-install-stdin-");
const hostileHelper = path.join(
@@ -104,7 +92,13 @@ extract_openclaw_semver() {
"utf-8",
);
expect(resolveVersionFromInstallerViaStdin(fixture.cliPath, hostileCwd)).toBe("2026.3.10");
expect(
resolveInstallerVersionCases({
cliPaths: [decorated.cliPath, raw.cliPath],
stdinCliPath: stdinFixture.cliPath,
stdinCwd: hostileCwd,
}),
).toEqual(["2026.3.10", "OpenClaw dev's build", "2026.3.10"]);
},
);
});

View File

@@ -1,7 +1,7 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
import {
buildMultimodalChunkForIndexing,
buildFileEntry,
@@ -16,13 +16,24 @@ import {
type MemoryMultimodalSettings,
} from "./multimodal.js";
let sharedTempRoot = "";
let sharedTempId = 0;
beforeAll(async () => {
sharedTempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "memory-host-sdk-tests-"));
});
afterAll(async () => {
if (sharedTempRoot) {
await fs.rm(sharedTempRoot, { recursive: true, force: true });
}
});
function setupTempDirLifecycle(prefix: string): () => string {
let tmpDir = "";
beforeEach(async () => {
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
});
afterEach(async () => {
await fs.rm(tmpDir, { recursive: true, force: true });
tmpDir = path.join(sharedTempRoot, `${prefix}${sharedTempId++}`);
await fs.mkdir(tmpDir, { recursive: true });
});
return () => tmpDir;
}

View File

@@ -1063,7 +1063,7 @@ describe("wildcard peer bindings (peer.id=*)", () => {
describe("binding evaluation cache scalability", () => {
test("does not rescan full bindings after channel/account cache rollover (#36915)", () => {
const bindingCount = 2_205;
const bindingCount = 2_001;
const cfg: OpenClawConfig = {
bindings: Array.from({ length: bindingCount }, (_, idx) => ({
agentId: `agent-${idx}`,