Skip to content

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

838 B
Raw Blame
import * as assert from "node:assert/strict";
import {describe, it} from "node:test";
import {createHostQuitGuard} from "./hostQuit";

describe("host quit guard", () => {
    it("runs the host quit action only once", () => {
        const guard = createHostQuitGuard();
        let calls = 0;

        assert.equal(guard.run(() => calls++), true);
        assert.equal(guard.run(() => calls++), false);
        assert.equal(calls, 1);
        assert.equal(guard.isStarted(), true);
    });

    it("allows retrying when the host quit action throws", () => {
        const guard = createHostQuitGuard();

        assert.throws(() => guard.run(() => {
            throw new Error("quit failed");
        }), /quit failed/);
        assert.equal(guard.isStarted(), false);
        assert.equal(guard.run(() => undefined), true);
    });
});