Files
openclaw/test/scripts/e2e-mock-config-limits.test.ts
2026-05-29 02:38:29 +02:00

69 lines
2.3 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { describe, expect, it } from "vitest";
const mockOpenAiPath = "scripts/e2e/mock-openai-server.mjs";
const webSearchMockPath = "scripts/e2e/lib/openai-web-search-minimal/mock-server.mjs";
const configReloadAssertPath = "scripts/e2e/lib/config-reload/assert-log.mjs";
const scrubbedEnvKeys = [
"MOCK_PORT",
"MOCK_REQUEST_LOG",
"OPENCLAW_CONFIG_RELOAD_LOG_MAX_READ_BYTES",
"OPENCLAW_CONFIG_RELOAD_LOG_PATH",
"OPENCLAW_CONFIG_RELOAD_LOG_TIMEOUT_MS",
"OPENCLAW_MOCK_OPENAI_PORT",
"RAW_SCHEMA_ERROR",
"SUCCESS_MARKER",
];
function runScript(scriptPath: string, env: Record<string, string>) {
const childEnv = { ...process.env };
for (const key of scrubbedEnvKeys) {
delete childEnv[key];
}
return spawnSync(process.execPath, [scriptPath], {
encoding: "utf8",
env: { ...childEnv, ...env },
killSignal: "SIGKILL",
timeout: 3_000,
});
}
describe("e2e mock and config helper numeric limits", () => {
it("rejects loose mock OpenAI port env values", () => {
const mockPort = runScript(mockOpenAiPath, { MOCK_PORT: "44080tcp" });
expect(mockPort.status).not.toBe(0);
expect(mockPort.stderr).toContain("invalid MOCK_PORT: 44080tcp");
const fallbackPort = runScript(mockOpenAiPath, {
OPENCLAW_MOCK_OPENAI_PORT: "44080http",
});
expect(fallbackPort.status).not.toBe(0);
expect(fallbackPort.stderr).toContain("invalid OPENCLAW_MOCK_OPENAI_PORT: 44080http");
});
it("rejects loose OpenAI web-search mock port env values", () => {
const result = runScript(webSearchMockPath, { MOCK_PORT: "80http" });
expect(result.status).not.toBe(0);
expect(result.stderr).toContain("invalid MOCK_PORT: 80http");
});
it("rejects loose config-reload log timeout env values", () => {
const result = runScript(configReloadAssertPath, {
OPENCLAW_CONFIG_RELOAD_LOG_TIMEOUT_MS: "30000ms",
});
expect(result.status).not.toBe(0);
expect(result.stderr).toContain("invalid OPENCLAW_CONFIG_RELOAD_LOG_TIMEOUT_MS: 30000ms");
});
it("rejects loose config-reload log read caps", () => {
const result = runScript(configReloadAssertPath, {
OPENCLAW_CONFIG_RELOAD_LOG_MAX_READ_BYTES: "256kb",
});
expect(result.status).not.toBe(0);
expect(result.stderr).toContain("invalid OPENCLAW_CONFIG_RELOAD_LOG_MAX_READ_BYTES: 256kb");
});
});