mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 04:29:36 +00:00
(fix): .env vars not available during runtime config reloads (healthchecks fail with MissingEnvVarError) (#12748)
* Config: reload dotenv before env substitution on runtime loads * Test: isolate config env var regression from host state env * fix: keep dotenv vars resolvable on runtime config reloads (#12748) (thanks @rodrigouroz) --------- Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveStateDir } from "./paths.js";
|
||||
import { withEnvOverride, withTempHome } from "./test-helpers.js";
|
||||
|
||||
describe("config env vars", () => {
|
||||
@@ -75,4 +76,50 @@ describe("config env vars", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("loads ${VAR} substitutions from ~/.openclaw/.env on repeated runtime loads", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
await withEnvOverride(
|
||||
{
|
||||
OPENCLAW_STATE_DIR: path.join(home, ".openclaw"),
|
||||
CLAWDBOT_STATE_DIR: undefined,
|
||||
OPENCLAW_HOME: undefined,
|
||||
CLAWDBOT_HOME: undefined,
|
||||
BRAVE_API_KEY: undefined,
|
||||
OPENCLAW_DISABLE_CONFIG_CACHE: "1",
|
||||
},
|
||||
async () => {
|
||||
const configDir = resolveStateDir(process.env, () => home);
|
||||
await fs.mkdir(configDir, { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join(configDir, "openclaw.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
tools: {
|
||||
web: {
|
||||
search: {
|
||||
apiKey: "${BRAVE_API_KEY}",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf-8",
|
||||
);
|
||||
await fs.writeFile(path.join(configDir, ".env"), "BRAVE_API_KEY=from-dotenv\n", "utf-8");
|
||||
|
||||
const { loadConfig } = await import("./config.js");
|
||||
|
||||
const first = loadConfig();
|
||||
expect(first.tools?.web?.search?.apiKey).toBe("from-dotenv");
|
||||
|
||||
delete process.env.BRAVE_API_KEY;
|
||||
const second = loadConfig();
|
||||
expect(second.tools?.web?.search?.apiKey).toBe("from-dotenv");
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user