mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:10:45 +00:00
test(infra): assert dotenv structured warning
This commit is contained in:
@@ -5,6 +5,14 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { loadCliDotEnv } from "../cli/dotenv.js";
|
||||
import { loadDotEnv, loadWorkspaceDotEnvFile } from "./dotenv.js";
|
||||
|
||||
const loggerMocks = vi.hoisted(() => ({
|
||||
warn: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../logging/subsystem.js", () => ({
|
||||
createSubsystemLogger: vi.fn(() => loggerMocks),
|
||||
}));
|
||||
|
||||
const CREDENTIAL_AND_GATEWAY_ENV_KEYS = [
|
||||
"ANTHROPIC_API_KEY",
|
||||
"ANTHROPIC_API_KEY_SECONDARY",
|
||||
@@ -152,14 +160,18 @@ describe("loadDotEnv", () => {
|
||||
vi.spyOn(process, "cwd").mockReturnValue(cwdDir);
|
||||
delete process.env.FOO;
|
||||
delete process.env.BAR;
|
||||
const warn = vi.spyOn(console, "warn").mockImplementation(() => undefined);
|
||||
loggerMocks.warn.mockClear();
|
||||
|
||||
loadDotEnv({ quiet: true });
|
||||
|
||||
expect(process.env.FOO).toBe("from-global");
|
||||
expect(process.env.BAR).toBe("from-gateway");
|
||||
expect(warn).toHaveBeenCalledWith(expect.stringContaining("Conflicting values in"));
|
||||
expect(warn).toHaveBeenCalledWith(expect.stringContaining("gateway.env"));
|
||||
expect(loggerMocks.warn).toHaveBeenCalledWith(
|
||||
expect.stringContaining("Conflicting values in"),
|
||||
expect.objectContaining({
|
||||
ignoredPath: expect.stringContaining("gateway.env"),
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user