Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

1.6 KB
Raw Blame
import {describe, it} from "node:test";
import * as assert from "node:assert/strict";
import {destroyWindowPluginKernels} from "./closeWinCore";

describe("independent window plugin cleanup", () => {
    it("destroys every kernel without invoking lifecycle hooks", () => {
        let destroyed = 0;
        let lifecycleCalls = 0;
        const plugins = [1, 2].map(() => ({
            kernel: {
                destroy() {
                    destroyed++;
                },
            },
            onunload() {
                lifecycleCalls++;
            },
            uninstall() {
                lifecycleCalls++;
            },
        }));

        destroyWindowPluginKernels(plugins, () => undefined);

        assert.equal(destroyed, 2);
        assert.equal(lifecycleCalls, 0);
    });

    it("does not wait for pending destruction", async () => {
        let finished = false;
        const pending = new Promise<void>(() => undefined);

        destroyWindowPluginKernels([{kernel: {destroy: () => pending}}], () => undefined);
        finished = true;

        assert.equal(finished, true);
    });

    it("observes synchronous and asynchronous destruction errors", async () => {
        const errors: string[] = [];
        destroyWindowPluginKernels([
            {kernel: {destroy: () => {
                throw new Error("sync");
            }}},
            {kernel: {destroy: () => Promise.reject(new Error("async"))}},
        ], error => errors.push((error as Error).message));

        await Promise.resolve();

        assert.deepEqual(errors.sort(), ["async", "sync"]);
    });
});