Spaces:
Running
Running
File size: 1,852 Bytes
fb4d8fe | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | import { describe, expect, it } from "vitest";
import { isTruthyEnvValue, normalizeZaiEnv } from "./env.js";
describe("normalizeZaiEnv", () => {
it("copies Z_AI_API_KEY to ZAI_API_KEY when missing", () => {
const prevZai = process.env.ZAI_API_KEY;
const prevZAi = process.env.Z_AI_API_KEY;
process.env.ZAI_API_KEY = "";
process.env.Z_AI_API_KEY = "zai-legacy";
normalizeZaiEnv();
expect(process.env.ZAI_API_KEY).toBe("zai-legacy");
if (prevZai === undefined) {
delete process.env.ZAI_API_KEY;
} else {
process.env.ZAI_API_KEY = prevZai;
}
if (prevZAi === undefined) {
delete process.env.Z_AI_API_KEY;
} else {
process.env.Z_AI_API_KEY = prevZAi;
}
});
it("does not override existing ZAI_API_KEY", () => {
const prevZai = process.env.ZAI_API_KEY;
const prevZAi = process.env.Z_AI_API_KEY;
process.env.ZAI_API_KEY = "zai-current";
process.env.Z_AI_API_KEY = "zai-legacy";
normalizeZaiEnv();
expect(process.env.ZAI_API_KEY).toBe("zai-current");
if (prevZai === undefined) {
delete process.env.ZAI_API_KEY;
} else {
process.env.ZAI_API_KEY = prevZai;
}
if (prevZAi === undefined) {
delete process.env.Z_AI_API_KEY;
} else {
process.env.Z_AI_API_KEY = prevZAi;
}
});
});
describe("isTruthyEnvValue", () => {
it("accepts common truthy values", () => {
expect(isTruthyEnvValue("1")).toBe(true);
expect(isTruthyEnvValue("true")).toBe(true);
expect(isTruthyEnvValue(" yes ")).toBe(true);
expect(isTruthyEnvValue("ON")).toBe(true);
});
it("rejects other values", () => {
expect(isTruthyEnvValue("0")).toBe(false);
expect(isTruthyEnvValue("false")).toBe(false);
expect(isTruthyEnvValue("")).toBe(false);
expect(isTruthyEnvValue(undefined)).toBe(false);
});
});
|