Menu
popagent
publicLatest change 2fb6f198c4c71ef37dffc8ac5dca8482068a7bfc - Add governed AkurAI Build maintenance by AkurAI Build
import { describe, expect, test } from "bun:test";
import { AutonomyActivityGate } from "./autonomy-runtime";
describe("AutonomyActivityGate", () => {
test("interactive work prevents an autonomous lease", () => {
const gate = new AutonomyActivityGate();
const release = gate.enterInteractive("turn-1");
expect(gate.isIdle).toBe(false);
expect(gate.tryEnterAutonomous("task-1")).toBeUndefined();
release();
expect(gate.isIdle).toBe(true);
});
test("holds one autonomous lease until released", () => {
const gate = new AutonomyActivityGate();
const release = gate.tryEnterAutonomous("task-1");
expect(release).toBeTypeOf("function");
expect(gate.tryEnterAutonomous("task-2")).toBeUndefined();
expect(gate.enterBackground("task-3")).toBeTypeOf("function");
expect(gate.isIdle).toBe(false);
release?.();
expect(gate.isIdle).toBe(false);
});
test("leases are idempotent and background work blocks autonomous work", () => {
const gate = new AutonomyActivityGate();
const release = gate.enterBackground("task-1");
expect(gate.tryEnterAutonomous("task-2")).toBeUndefined();
release();
release();
expect(gate.tryEnterAutonomous("task-2")).toBeTypeOf("function");
});
test("keeps duplicate operation ids isolated until every lease releases", () => {
const gate = new AutonomyActivityGate();
const first = gate.enterInteractive("same-turn");
const second = gate.enterInteractive("same-turn");
first();
expect(gate.isIdle).toBe(false);
second();
expect(gate.isIdle).toBe(true);
});
});