Something went wrong. Try again.
fork of prime agent with changes i want but are not upstreamable probqbly (and some fixes)
Something went wrong. Try again.
1.7 kB · 54 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import { mkdtempSync, rmSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";import { afterEach, describe, expect, test } from "vitest";import { SessionPinsStore } from "../src/modes/agents-view/pins-store.js";
describe("SessionPinsStore", () => { const tempDirs: string[] = [];
afterEach(() => { for (const dir of tempDirs.splice(0)) { rmSync(dir, { recursive: true, force: true }); } });
function makeStore(): { store: SessionPinsStore; dir: string } { const dir = mkdtempSync(join(tmpdir(), "session-pins-")); tempDirs.push(dir); return { store: new SessionPinsStore(dir), dir }; }
test("toggles pins and persists them across instances", () => { const { store, dir } = makeStore(); expect(store.has("s1")).toBe(false);
expect(store.toggle("s1")).toBe(true); expect(store.has("s1")).toBe(true); expect(store.toggle("s1")).toBe(false); expect(store.has("s1")).toBe(false);
store.toggle("s2"); const reloaded = new SessionPinsStore(dir); expect(reloaded.has("s2")).toBe(true); expect(reloaded.has("s1")).toBe(false); });
test("a corrupt pins file starts empty instead of throwing", () => { const { store, dir } = makeStore(); store.toggle("s1"); const filePath = join(dir, "session-pins.json"); writeFileSync(filePath, "{ not json"); const reloaded = new SessionPinsStore(dir); expect(reloaded.has("s1")).toBe(false); // The in-memory set still works and re-persists cleanly. expect(reloaded.toggle("s3")).toBe(true); });
test("ids() reflects loaded pins", () => { const { store, dir } = makeStore(); store.toggle("s1"); const reloaded = new SessionPinsStore(dir); expect([...reloaded.ids()]).toEqual(["s1"]); });});