Privileged helper for system proxy (#796)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Gregory SchierandClaude Opus 5.5 authored and GitHub committed 2026-10-30 00:41:00 -07:00
1 parent 4d38a482f6
commit f7aea62c07
33 files changed
+3536 -176

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
import { describe, expect, test, vi } from "vite-plus/test";
import { unsubscribeWhenReady } from "./unsubscribe";
function pending() {
let resolve: (fn: () => void) => void = () => {};
const promise = new Promise<() => void>((r) => (resolve = r));
return { promise, resolve };
}
describe("unsubscribeWhenReady", () => {
test("unsubscribes once ready when cleanup ran first", async () => {
const { promise, resolve } = pending();
const unsub = vi.fn();
const subscription = unsubscribeWhenReady(promise);
subscription.unsubscribe();
expect(subscription.active()).toBe(false);
resolve(unsub);
await promise;
await Promise.resolve();
expect(unsub).toHaveBeenCalledTimes(1);
});
test("unsubscribes at once when already ready, and only once", async () => {
const unsub = vi.fn();
const promise = Promise.resolve(unsub);
const subscription = unsubscribeWhenReady(promise);
await promise;
await Promise.resolve();
expect(subscription.active()).toBe(true);
subscription.unsubscribe();
subscription.unsubscribe();
expect(unsub).toHaveBeenCalledTimes(1);
});
});