mirror of
https://github.com/block/buzz.git
synced 2026-11-28 04:01:45 +00:00
Signed-off-by: Will Pfleger <pfleger.will@gmail.com> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
envVarsClearingManagedApiKey,
|
|
envVarsWithoutKey,
|
|
} from "./providerEnvVarUpdates.ts";
|
|
|
|
test("envVarsWithoutKey removes a present key", () => {
|
|
assert.deepEqual(envVarsWithoutKey({ A: "1", B: "2" }, "A"), { B: "2" });
|
|
});
|
|
|
|
test("envVarsWithoutKey returns the same reference when the key is absent", () => {
|
|
const current = { A: "1" };
|
|
assert.equal(envVarsWithoutKey(current, "B"), current);
|
|
});
|
|
|
|
test("envVarsClearingManagedApiKey clears the previous provider's key on switch", () => {
|
|
const next = envVarsClearingManagedApiKey(
|
|
{ ANTHROPIC_API_KEY: "sk-1", KEEP: "x" },
|
|
"anthropic",
|
|
"openai",
|
|
);
|
|
assert.deepEqual(next, { KEEP: "x" });
|
|
});
|
|
|
|
test("envVarsClearingManagedApiKey clears when leaving to a custom/empty provider", () => {
|
|
// The dialogs' CUSTOM-provider paths delete unconditionally; empty next
|
|
// provider has no managed key, so the inequality always holds — same rule.
|
|
const next = envVarsClearingManagedApiKey(
|
|
{ ANTHROPIC_API_KEY: "sk-1" },
|
|
"anthropic",
|
|
"",
|
|
);
|
|
assert.deepEqual(next, {});
|
|
});
|
|
|
|
test("envVarsClearingManagedApiKey is a no-op when the managed key is shared or absent", () => {
|
|
const current = { ANTHROPIC_API_KEY: "sk-1" };
|
|
assert.equal(
|
|
envVarsClearingManagedApiKey(current, "anthropic", "anthropic"),
|
|
current,
|
|
);
|
|
const noManaged = { X: "1" };
|
|
assert.equal(
|
|
envVarsClearingManagedApiKey(noManaged, "", "openai"),
|
|
noManaged,
|
|
);
|
|
});
|