mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 21:44:32 +00:00
test(perf): reuse suite temp-home fixture in config io write tests
This commit is contained in:
@@ -1,16 +1,32 @@
|
|||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { describe, expect, it, vi } from "vitest";
|
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||||
import { withTempHome } from "./home-env.test-harness.js";
|
|
||||||
import { createConfigIO } from "./io.js";
|
import { createConfigIO } from "./io.js";
|
||||||
import type { OpenClawConfig } from "./types.js";
|
import type { OpenClawConfig } from "./types.js";
|
||||||
|
|
||||||
describe("config io write", () => {
|
describe("config io write", () => {
|
||||||
|
let fixtureRoot = "";
|
||||||
|
let homeCaseId = 0;
|
||||||
const silentLogger = {
|
const silentLogger = {
|
||||||
warn: () => {},
|
warn: () => {},
|
||||||
error: () => {},
|
error: () => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function withSuiteHome<T>(fn: (home: string) => Promise<T>): Promise<T> {
|
||||||
|
const home = path.join(fixtureRoot, `case-${homeCaseId++}`);
|
||||||
|
await fs.mkdir(home, { recursive: true });
|
||||||
|
return fn(home);
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-config-io-"));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await fs.rm(fixtureRoot, { recursive: true, force: true });
|
||||||
|
});
|
||||||
|
|
||||||
async function writeConfigAndCreateIo(params: {
|
async function writeConfigAndCreateIo(params: {
|
||||||
home: string;
|
home: string;
|
||||||
initialConfig: Record<string, unknown>;
|
initialConfig: Record<string, unknown>;
|
||||||
@@ -110,7 +126,7 @@ describe("config io write", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it("persists caller changes onto resolved config without leaking runtime defaults", async () => {
|
it("persists caller changes onto resolved config without leaking runtime defaults", async () => {
|
||||||
await withTempHome("openclaw-config-io-", async (home) => {
|
await withSuiteHome(async (home) => {
|
||||||
const { configPath, io, snapshot } = await writeConfigAndCreateIo({
|
const { configPath, io, snapshot } = await writeConfigAndCreateIo({
|
||||||
home,
|
home,
|
||||||
initialConfig: { gateway: { port: 18789 } },
|
initialConfig: { gateway: { port: 18789 } },
|
||||||
@@ -127,7 +143,7 @@ describe("config io write", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('shows actionable guidance for dmPolicy="open" without wildcard allowFrom', async () => {
|
it('shows actionable guidance for dmPolicy="open" without wildcard allowFrom', async () => {
|
||||||
await withTempHome("openclaw-config-io-", async (home) => {
|
await withSuiteHome(async (home) => {
|
||||||
const io = createConfigIO({
|
const io = createConfigIO({
|
||||||
env: {} as NodeJS.ProcessEnv,
|
env: {} as NodeJS.ProcessEnv,
|
||||||
homedir: () => home,
|
homedir: () => home,
|
||||||
@@ -153,7 +169,7 @@ describe("config io write", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("honors explicit unset paths when schema defaults would otherwise reappear", async () => {
|
it("honors explicit unset paths when schema defaults would otherwise reappear", async () => {
|
||||||
await withTempHome("openclaw-config-io-", async (home) => {
|
await withSuiteHome(async (home) => {
|
||||||
const { configPath, io, snapshot } = await writeConfigAndCreateIo({
|
const { configPath, io, snapshot } = await writeConfigAndCreateIo({
|
||||||
home,
|
home,
|
||||||
initialConfig: {
|
initialConfig: {
|
||||||
@@ -181,7 +197,7 @@ describe("config io write", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not mutate caller config when unsetPaths is applied on first write", async () => {
|
it("does not mutate caller config when unsetPaths is applied on first write", async () => {
|
||||||
await withTempHome("openclaw-config-io-", async (home) => {
|
await withSuiteHome(async (home) => {
|
||||||
const configPath = path.join(home, ".openclaw", "openclaw.json");
|
const configPath = path.join(home, ".openclaw", "openclaw.json");
|
||||||
const io = createConfigIO({
|
const io = createConfigIO({
|
||||||
env: {} as NodeJS.ProcessEnv,
|
env: {} as NodeJS.ProcessEnv,
|
||||||
@@ -206,7 +222,7 @@ describe("config io write", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not mutate caller config when unsetPaths is applied on existing files", async () => {
|
it("does not mutate caller config when unsetPaths is applied on existing files", async () => {
|
||||||
await withTempHome("openclaw-config-io-", async (home) => {
|
await withSuiteHome(async (home) => {
|
||||||
const { configPath, io, snapshot } = await writeConfigAndCreateIo({
|
const { configPath, io, snapshot } = await writeConfigAndCreateIo({
|
||||||
home,
|
home,
|
||||||
initialConfig: {
|
initialConfig: {
|
||||||
@@ -224,7 +240,7 @@ describe("config io write", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("keeps caller arrays immutable when unsetting array entries", async () => {
|
it("keeps caller arrays immutable when unsetting array entries", async () => {
|
||||||
await withTempHome("openclaw-config-io-", async (home) => {
|
await withSuiteHome(async (home) => {
|
||||||
const { configPath, io, snapshot } = await writeConfigAndCreateIo({
|
const { configPath, io, snapshot } = await writeConfigAndCreateIo({
|
||||||
home,
|
home,
|
||||||
initialConfig: {
|
initialConfig: {
|
||||||
@@ -245,7 +261,7 @@ describe("config io write", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("treats missing unset paths as no-op without mutating caller config", async () => {
|
it("treats missing unset paths as no-op without mutating caller config", async () => {
|
||||||
await withTempHome("openclaw-config-io-", async (home) => {
|
await withSuiteHome(async (home) => {
|
||||||
await runUnsetNoopCase({
|
await runUnsetNoopCase({
|
||||||
home,
|
home,
|
||||||
unsetPaths: [["commands", "missingKey"]],
|
unsetPaths: [["commands", "missingKey"]],
|
||||||
@@ -254,7 +270,7 @@ describe("config io write", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("ignores blocked prototype-key unset path segments", async () => {
|
it("ignores blocked prototype-key unset path segments", async () => {
|
||||||
await withTempHome("openclaw-config-io-", async (home) => {
|
await withSuiteHome(async (home) => {
|
||||||
await runUnsetNoopCase({
|
await runUnsetNoopCase({
|
||||||
home,
|
home,
|
||||||
unsetPaths: [
|
unsetPaths: [
|
||||||
@@ -267,7 +283,7 @@ describe("config io write", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("preserves env var references when writing", async () => {
|
it("preserves env var references when writing", async () => {
|
||||||
await withTempHome("openclaw-config-io-", async (home) => {
|
await withSuiteHome(async (home) => {
|
||||||
const { configPath, io, snapshot } = await writeConfigAndCreateIo({
|
const { configPath, io, snapshot } = await writeConfigAndCreateIo({
|
||||||
home,
|
home,
|
||||||
env: { OPENAI_API_KEY: "sk-secret" } as NodeJS.ProcessEnv,
|
env: { OPENAI_API_KEY: "sk-secret" } as NodeJS.ProcessEnv,
|
||||||
@@ -302,7 +318,7 @@ describe("config io write", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not reintroduce Slack/Discord legacy dm.policy defaults when writing", async () => {
|
it("does not reintroduce Slack/Discord legacy dm.policy defaults when writing", async () => {
|
||||||
await withTempHome("openclaw-config-io-", async (home) => {
|
await withSuiteHome(async (home) => {
|
||||||
const { configPath, io, snapshot } = await writeConfigAndCreateIo({
|
const { configPath, io, snapshot } = await writeConfigAndCreateIo({
|
||||||
home,
|
home,
|
||||||
initialConfig: {
|
initialConfig: {
|
||||||
@@ -348,7 +364,7 @@ describe("config io write", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("keeps env refs in arrays when appending entries", async () => {
|
it("keeps env refs in arrays when appending entries", async () => {
|
||||||
await withTempHome("openclaw-config-io-", async (home) => {
|
await withSuiteHome(async (home) => {
|
||||||
const configPath = path.join(home, ".openclaw", "openclaw.json");
|
const configPath = path.join(home, ".openclaw", "openclaw.json");
|
||||||
await fs.mkdir(path.dirname(configPath), { recursive: true });
|
await fs.mkdir(path.dirname(configPath), { recursive: true });
|
||||||
await fs.writeFile(
|
await fs.writeFile(
|
||||||
@@ -421,7 +437,7 @@ describe("config io write", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("logs an overwrite audit entry when replacing an existing config file", async () => {
|
it("logs an overwrite audit entry when replacing an existing config file", async () => {
|
||||||
await withTempHome("openclaw-config-io-", async (home) => {
|
await withSuiteHome(async (home) => {
|
||||||
const warn = vi.fn();
|
const warn = vi.fn();
|
||||||
const { configPath, io, snapshot } = await writeConfigAndCreateIo({
|
const { configPath, io, snapshot } = await writeConfigAndCreateIo({
|
||||||
home,
|
home,
|
||||||
@@ -451,7 +467,7 @@ describe("config io write", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not log an overwrite audit entry when creating config for the first time", async () => {
|
it("does not log an overwrite audit entry when creating config for the first time", async () => {
|
||||||
await withTempHome("openclaw-config-io-", async (home) => {
|
await withSuiteHome(async (home) => {
|
||||||
const warn = vi.fn();
|
const warn = vi.fn();
|
||||||
const io = createConfigIO({
|
const io = createConfigIO({
|
||||||
env: {} as NodeJS.ProcessEnv,
|
env: {} as NodeJS.ProcessEnv,
|
||||||
@@ -474,7 +490,7 @@ describe("config io write", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("appends config write audit JSONL entries with forensic metadata", async () => {
|
it("appends config write audit JSONL entries with forensic metadata", async () => {
|
||||||
await withTempHome("openclaw-config-io-", async (home) => {
|
await withSuiteHome(async (home) => {
|
||||||
const { configPath, lines, last } = await writeGatewayPatchAndReadLastAuditEntry({
|
const { configPath, lines, last } = await writeGatewayPatchAndReadLastAuditEntry({
|
||||||
home,
|
home,
|
||||||
initialConfig: { gateway: { port: 18789 } },
|
initialConfig: { gateway: { port: 18789 } },
|
||||||
@@ -494,7 +510,7 @@ describe("config io write", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("records gateway watch session markers in config audit entries", async () => {
|
it("records gateway watch session markers in config audit entries", async () => {
|
||||||
await withTempHome("openclaw-config-io-", async (home) => {
|
await withSuiteHome(async (home) => {
|
||||||
const { last } = await writeGatewayPatchAndReadLastAuditEntry({
|
const { last } = await writeGatewayPatchAndReadLastAuditEntry({
|
||||||
home,
|
home,
|
||||||
initialConfig: { gateway: { mode: "local" } },
|
initialConfig: { gateway: { mode: "local" } },
|
||||||
|
|||||||
Reference in New Issue
Block a user