/** * Global safety net for the `store.*` / `vault.secret` / `signal.*` / * `clock()` / `gate.policy`·scope·rate / `channel.().template()` / * `ai.model`·prompt·embed·agent auto-registries * (`src/kernel/element-registries.ts`). * * Unlike `on()` bindings — created almost exclusively to wire a real app — * these factories are called throughout the suite as bare value constructors, * completely unrelated to booting an app (hundreds of call sites across * `src/elements/*.test.ts`). Since the registries are plain module-level * arrays shared by every test file in one `bun test` process, leaving cleanup * to per-file discipline (the convention `on.ts` relies on — see * `resetBindings()` / `registry: "ignore"`) would let stray decls from one * file silently reach a default-registry `oke()` call in a completely * unrelated file. Reset after every test, globally, via `bunfig.toml` * `[test].preload`. */ import { afterEach } from "bun:test"; const startupEnv = globalThis as { __okeTestRedisUrl?: string }; if (!("__okeTestRedisUrl" in startupEnv)) { startupEnv.__okeTestRedisUrl = process.env.REDIS_URL ?? process.env.OKE_TEST_REDIS_URL; } /** * Redis URL from process start. * Later suites must not treat a temporary delete as "redis was never configured". */ export function startupRedisUrl(): string | undefined { const url = startupEnv.__okeTestRedisUrl; return url === undefined || url.trim() === "" ? undefined : url; } import { aiAgentRegistry, aiEmbedRegistry, aiMcpServerRegistry, aiModelRegistry, aiPromptRegistry, channelTemplateRegistry, clockRegistry, gateRegistry, requiredEnvRegistry, secretRegistry, signalRegistry, storeRegistry, } from "../kernel/element-registries.ts"; afterEach(() => { storeRegistry.length = 0; secretRegistry.length = 0; requiredEnvRegistry.length = 0; signalRegistry.length = 0; clockRegistry.length = 0; gateRegistry.length = 0; channelTemplateRegistry.length = 0; aiModelRegistry.length = 0; aiPromptRegistry.length = 0; aiEmbedRegistry.length = 0; aiAgentRegistry.length = 0; aiMcpServerRegistry.length = 0; });