mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-01 12:16:13 +00:00
refactor(core): dedupe shared config and runtime helpers
This commit is contained in:
@@ -4,6 +4,16 @@ import { describe, expect, it } from "vitest";
|
||||
import { loadConfig } from "./config.js";
|
||||
import { withTempHome } from "./test-helpers.js";
|
||||
|
||||
async function writeConfigForTest(home: string, config: unknown): Promise<void> {
|
||||
const configDir = path.join(home, ".openclaw");
|
||||
await fs.mkdir(configDir, { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join(configDir, "openclaw.json"),
|
||||
JSON.stringify(config, null, 2),
|
||||
"utf-8",
|
||||
);
|
||||
}
|
||||
|
||||
describe("config pruning defaults", () => {
|
||||
it("does not enable contextPruning by default", async () => {
|
||||
const prevApiKey = process.env.ANTHROPIC_API_KEY;
|
||||
@@ -11,13 +21,7 @@ describe("config pruning defaults", () => {
|
||||
process.env.ANTHROPIC_API_KEY = "";
|
||||
process.env.ANTHROPIC_OAUTH_TOKEN = "";
|
||||
await withTempHome(async (home) => {
|
||||
const configDir = path.join(home, ".openclaw");
|
||||
await fs.mkdir(configDir, { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join(configDir, "openclaw.json"),
|
||||
JSON.stringify({ agents: { defaults: {} } }, null, 2),
|
||||
"utf-8",
|
||||
);
|
||||
await writeConfigForTest(home, { agents: { defaults: {} } });
|
||||
|
||||
const cfg = loadConfig();
|
||||
|
||||
@@ -37,24 +41,14 @@ describe("config pruning defaults", () => {
|
||||
|
||||
it("enables cache-ttl pruning + 1h heartbeat for Anthropic OAuth", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
const configDir = path.join(home, ".openclaw");
|
||||
await fs.mkdir(configDir, { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join(configDir, "openclaw.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
auth: {
|
||||
profiles: {
|
||||
"anthropic:me": { provider: "anthropic", mode: "oauth", email: "me@example.com" },
|
||||
},
|
||||
},
|
||||
agents: { defaults: {} },
|
||||
await writeConfigForTest(home, {
|
||||
auth: {
|
||||
profiles: {
|
||||
"anthropic:me": { provider: "anthropic", mode: "oauth", email: "me@example.com" },
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf-8",
|
||||
);
|
||||
},
|
||||
agents: { defaults: {} },
|
||||
});
|
||||
|
||||
const cfg = loadConfig();
|
||||
|
||||
@@ -66,28 +60,18 @@ describe("config pruning defaults", () => {
|
||||
|
||||
it("enables cache-ttl pruning + 1h cache TTL for Anthropic API keys", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
const configDir = path.join(home, ".openclaw");
|
||||
await fs.mkdir(configDir, { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join(configDir, "openclaw.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
auth: {
|
||||
profiles: {
|
||||
"anthropic:api": { provider: "anthropic", mode: "api_key" },
|
||||
},
|
||||
},
|
||||
agents: {
|
||||
defaults: {
|
||||
model: { primary: "anthropic/claude-opus-4-5" },
|
||||
},
|
||||
},
|
||||
await writeConfigForTest(home, {
|
||||
auth: {
|
||||
profiles: {
|
||||
"anthropic:api": { provider: "anthropic", mode: "api_key" },
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf-8",
|
||||
);
|
||||
},
|
||||
agents: {
|
||||
defaults: {
|
||||
model: { primary: "anthropic/claude-opus-4-5" },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const cfg = loadConfig();
|
||||
|
||||
@@ -102,13 +86,7 @@ describe("config pruning defaults", () => {
|
||||
|
||||
it("does not override explicit contextPruning mode", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
const configDir = path.join(home, ".openclaw");
|
||||
await fs.mkdir(configDir, { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join(configDir, "openclaw.json"),
|
||||
JSON.stringify({ agents: { defaults: { contextPruning: { mode: "off" } } } }, null, 2),
|
||||
"utf-8",
|
||||
);
|
||||
await writeConfigForTest(home, { agents: { defaults: { contextPruning: { mode: "off" } } } });
|
||||
|
||||
const cfg = loadConfig();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user