Something went wrong. Try again.
watches turns and automatically creates and resolves tasks that get pinned into main agent context
Something went wrong. Try again.
1.3 kB · 44 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445import assert from "node:assert/strict";import test from "node:test";import type { ExtensionContext, SessionEntry } from "@earendil-works/pi-coding-agent";import { onLiveBranch } from "../src/liveness.ts";
const STALE = "This extension ctx is stale after session replacement or reload.";
const entry = (id: string): SessionEntry => ({ type: "custom", id, parentId: null, timestamp: "2026-09-12T00:00:00.000Z", customType: "unrelated", data: {}, }) as SessionEntry;
const context = (branch: SessionEntry[] | (() => never)): ExtensionContext => ({ get sessionManager() { return typeof branch === "function" ? { getBranch: branch, } : { getBranch: () => branch }; }, }) as unknown as ExtensionContext;
test("a boundary still on the branch is live", () => { assert.equal(onLiveBranch(context([entry("a"), entry("b")]), "a"), true);});
test("a boundary that left the branch is not live", () => { assert.equal(onLiveBranch(context([entry("a")]), "b"), false);});
test("a replaced session is not a live branch and does not throw", () => { const replaced = context(() => { throw new Error(STALE); });
assert.equal(onLiveBranch(replaced, "a"), false); assert.equal(onLiveBranch(replaced, null), false);});