Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

1.3 KB
Raw Blame
import { afterEach, expect, it, vi } from "vitest";

import {
  ROOM_DIAGNOSTICS_STORAGE_KEY,
  roomDiagnostic,
  setRoomDiagnosticsEnabledForTest,
} from "./room-diagnostics";

afterEach(() => {
  vi.restoreAllMocks();
  vi.unstubAllGlobals();
  setRoomDiagnosticsEnabledForTest(true);
});

it("stays silent unless the browser opts in", () => {
  const stored = new Map<string, string>();
  vi.stubGlobal("localStorage", {
    getItem: (key: string) => stored.get(key) ?? null,
  });
  const debug = vi.spyOn(console, "debug").mockImplementation(() => {});
  setRoomDiagnosticsEnabledForTest(undefined);
  roomDiagnostic("room.example", { roomId: "room-1" });
  expect(debug).not.toHaveBeenCalled();

  stored.set(ROOM_DIAGNOSTICS_STORAGE_KEY, "1");
  setRoomDiagnosticsEnabledForTest(undefined);
  roomDiagnostic("room.example", { roomId: "room-1" });
  expect(debug).toHaveBeenCalledWith("room.example", { roomId: "room-1" });
});

it("stays silent when storage is blocked", () => {
  vi.stubGlobal("localStorage", {
    getItem: () => {
      throw new Error("blocked");
    },
  });
  const debug = vi.spyOn(console, "debug").mockImplementation(() => {});
  setRoomDiagnosticsEnabledForTest(undefined);
  roomDiagnostic("room.example", {});
  expect(debug).not.toHaveBeenCalled();
});