evOo-local/apps/web/src/lib/shared-inflight.test.ts
cynarAI 6c7eed7580 Initial clean evOo-local from f00577b
Fresh history cut from cynarAI/evoo antigravity-handoff/project-timeline
(Voice First + project timeline). Brand docs/titles as evOo; keep @rakazo/*
packages as tech debt. Excludes node_modules, caches, secrets, voice blobs.
2026-09-20 17:15:16 +02:00

30 lines
1.0 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { sharedInflight } from "./shared-inflight.js";
describe("sharedInflight", () => {
it("reuses one in-flight promise when a second caller arrives before the first resolves", async () => {
const inflight = new Map<string, Promise<string>>();
let resolveProvision!: (value: string) => void;
const start = vi.fn(
() =>
new Promise<string>((resolve) => {
resolveProvision = resolve;
}),
);
const first = sharedInflight(inflight, "bot-1", start);
const second = sharedInflight(inflight, "bot-1", start);
expect(start).toHaveBeenCalledTimes(1);
expect(second).toBe(first);
resolveProvision("secret-a");
await expect(Promise.all([first, second])).resolves.toEqual(["secret-a", "secret-a"]);
expect(inflight.has("bot-1")).toBe(false);
const third = sharedInflight(inflight, "bot-1", async () => "secret-b");
await expect(third).resolves.toBe("secret-b");
expect(start).toHaveBeenCalledTimes(1);
});
});