refactor(runtime): prefer env-backed secrets at runtime

This commit is contained in:
2026-03-30 19:17:32 +02:00
parent 4f5d410b94
commit fed7aa5b61
13 changed files with 532 additions and 71 deletions
@@ -1,7 +1,11 @@
import { describe, expect, it, vi } from "vitest";
import { getAnonymizationDirectory } from "../lib/anonymization.js";
import { afterEach, describe, expect, it, vi } from "vitest";
import { getAnonymizationConfig, getAnonymizationDirectory } from "../lib/anonymization.js";
describe("anonymization directory", () => {
afterEach(() => {
vi.unstubAllEnvs();
});
it("persists aliases so existing resources keep the same identity when new resources appear", async () => {
let storedAliases: Record<string, { displayName: string; eid: string }> = {
resource_a: {
@@ -126,4 +130,21 @@ describe("anonymization directory", () => {
expect(alias?.eid).toMatch(/^[a-z]+(?:\.[a-z]+)*$/);
expect(db.systemSettings.update).toHaveBeenCalledTimes(1);
});
it("prefers the anonymization seed from the environment at runtime", async () => {
vi.stubEnv("ANONYMIZATION_SEED", "env-seed");
const config = await getAnonymizationConfig({
systemSettings: {
findUnique: vi.fn(async () => ({
anonymizationEnabled: true,
anonymizationDomain: "example.test",
anonymizationSeed: "db-seed",
anonymizationMode: "global",
})),
},
} as never);
expect(config.seed).toBe("env-seed");
});
});