Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

660 B
Raw Blame
import assert from "node:assert/strict";
import test from "node:test";
import { LatestWinsGate } from "../src/lib/latest-wins.ts";

test("latest request wins and stale tokens are rejected", () => {
  const gate = new LatestWinsGate();
  const a = gate.begin();
  assert.ok(gate.isCurrent(a));
  const b = gate.begin();
  assert.ok(gate.isCurrent(b));
  assert.ok(!gate.isCurrent(a), "stale A must not land after B started");
});

test("invalidate represents close/reopen", () => {
  const gate = new LatestWinsGate();
  const a = gate.begin();
  gate.invalidate();
  assert.ok(!gate.isCurrent(a));
  const b = gate.begin();
  assert.ok(gate.isCurrent(b));
});