40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import { resolvePluginLifecycleRuntimeEnv } from "./index.js";
|
|
|
|
describe("resolvePluginLifecycleRuntimeEnv", () => {
|
|
test("defaults to development with capability consent required when env is empty", () => {
|
|
expect(resolvePluginLifecycleRuntimeEnv()).toEqual({
|
|
nodeEnv: "development",
|
|
requireCapabilityConsent: true,
|
|
});
|
|
});
|
|
|
|
test("passes NODE_ENV through without altering consent default", () => {
|
|
expect(resolvePluginLifecycleRuntimeEnv({ NODE_ENV: "production" })).toEqual({
|
|
nodeEnv: "production",
|
|
requireCapabilityConsent: true,
|
|
});
|
|
});
|
|
|
|
test("only the literal string 'false' opts out of capability consent (fail-closed)", () => {
|
|
expect(resolvePluginLifecycleRuntimeEnv({ PLUGIN_REQUIRE_CAPABILITY_CONSENT: "false" }).requireCapabilityConsent).toBe(false);
|
|
|
|
// Any non-"false" value keeps consent enabled — the gate fails closed.
|
|
for (const value of ["true", "1", "0", "no", "off", "FALSE", " false ", ""]) {
|
|
expect(resolvePluginLifecycleRuntimeEnv({ PLUGIN_REQUIRE_CAPABILITY_CONSENT: value }).requireCapabilityConsent).toBe(true);
|
|
}
|
|
});
|
|
|
|
test("resolves both fields together for a fully configured env", () => {
|
|
expect(
|
|
resolvePluginLifecycleRuntimeEnv({
|
|
NODE_ENV: "test",
|
|
PLUGIN_REQUIRE_CAPABILITY_CONSENT: "false",
|
|
})
|
|
).toEqual({
|
|
nodeEnv: "test",
|
|
requireCapabilityConsent: false,
|
|
});
|
|
});
|
|
});
|