YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
// screenpipe — AI that knows everything you've seen, said, or heard
// https://screenpipe.com
import { afterEach, describe, expect, it, vi } from "vitest";
import {
act,
cleanup,
fireEvent,
render,
screen,
waitFor,
within,
} from "@testing-library/react";
const mocks = vi.hoisted(() => ({
state: { user: {id: "synthetic-user", email: "[email protected]", token: "synthetic-token", cloud_subscribed: true, subscription_plan: "pro"} as any, enabled: true },
fetch: vi.fn(), toast: vi.fn(),
updateSettings: vi.fn().mockResolvedValue(undefined),
loadUser: vi.fn().mockResolvedValue(undefined),
openLoginWindow: vi.fn().mockResolvedValue(undefined),
piUpdateConfig: vi.fn().mockResolvedValue(undefined),
capture: vi.fn(),
openUrl: vi.fn().mockResolvedValue(undefined),
eventHandlers: new Map<string, (event: any) => unknown>(),
listen: vi.fn(async (event: string, handler: (event: any) => unknown) => {
mocks.eventHandlers.set(event, handler);
return () => mocks.eventHandlers.delete(event);
}),
}));
// AccountSection reads everything through useSettings + the tauri `commands`
// object; swap `mocks.state.user` per case. Keep `@/lib/app-entitlement` REAL —
// `isSignedInCloudSubscriber` is the gate under test.
vi.mock("@/lib/hooks/use-settings", () => ({
useSettings: () => ({
settings: {
user: mocks.state.user,
pipeSyncEnabled: mocks.state.enabled,
memoriesSyncEnabled: mocks.state.enabled,
connectionsSyncEnabled: mocks.state.enabled,
},
updateSettings: mocks.updateSettings,
loadUser: mocks.loadUser,
}),
}));
vi.mock("@/lib/hooks/use-health-check", () => ({
useHealthCheck: () => ({ isServerDown: false }),
}));
vi.mock("@/lib/hooks/use-managed-policy", () => ({
useManagedPolicy: () => ({ isManagedDeployment: false }),
}));
vi.mock("@/lib/utils/tauri", () => ({
commands: {
openLoginWindow: mocks.openLoginWindow,
piUpdateConfig: mocks.piUpdateConfig,
},
}));
vi.mock("@/components/ui/use-toast", () => ({ toast: mocks.toast }));
vi.mock("@/lib/api", () => ({ localFetch: mocks.fetch }));
vi.mock("posthog-js", () => ({ default: { capture: mocks.capture } }));
// Tauri plugins the effect wires up on mount — keep them inert.
vi.mock("@tauri-apps/plugin-shell", () => ({ open: mocks.openUrl }));
vi.mock("@tauri-apps/plugin-deep-link", () => ({
onOpenUrl: vi.fn().mockResolvedValue(() => {}),
}));
vi.mock("@tauri-apps/api/event", () => ({
listen: mocks.listen,
}));
// ReferralCard pulls its own data deps; it is irrelevant to the gate.
vi.mock("@/components/settings/referral-card", () => ({
ReferralCard: () => null,
}));
vi.mock("@/components/settings/business-upgrade-card", () => ({
BusinessUpgradeCard: ({
onContinue,
}: {
onContinue: (selection: any) => void;
}) => (
<button
type="button"
onClick={() =>
onContinue({
interval: "month",
offerVersion: "business-desktop-v1",
experimentKey: "desktop-business-upgrade-offer",
experimentVariant: "control",
source: "app-account-section",
})
}
>
upgrade to business
</button>
),
}));
import { AccountSection } from "@/components/settings/account-section";
vi.mock("gt-react", () => ({useGT: () => (t: string) => t, msg: (t: string) => t}));
vi.mock("@/lib/i18n/provider", () => ({useUiLocale: () => "en"}));
vi.mock("@/lib/http/tauri-fetch", () => ({tauriFetchWithDeadline: async () => new Response("{}")}));
vi.mock("@tauri-apps/plugin-os", () => ({hostname: async () => "synthetic-device"}));
vi.mock("@/components/settings/account-data-sync-card", () => ({AccountDataSyncCard: () => null}));
vi.mock("@/components/settings/sync-key-recovery", () => ({isLegacySyncKeyMismatch: () => false, SyncKeyRecovery: () => null}));
afterEach(() => {cleanup(); vi.clearAllMocks(); vi.unstubAllGlobals(); mocks.state.enabled=true; mocks.fetch.mockReset();});
function mount() {vi.stubGlobal("fetch",vi.fn(async () => {throw Error("unexpected external request")})); return render(<AccountSection/>);}
function button(index: number) {
const labels=[/^(pipe sync|sync scheduled tasks) across devices$/i,/^memories sync across devices$/i,/^connection sync across devices$/i];
const label=screen.getByText(labels[index]);let group=label.parentElement;
while(group && !within(group).queryByRole("button",{name:/^sync now$/i}))group=group.parentElement;
expect(group).not.toBeNull();return within(group!).getByRole("button",{name:/^sync now$/i});
}
const targets=["pipes","memories","connections"];
function reply(status:number, body:any) {return new Response(JSON.stringify(body),{status,headers:{"Content-Type":"application/json"}});}
for (const [index,target] of targets.entries()) {
it(target+" pull rejection prevents push and success",async()=>{
mocks.fetch.mockResolvedValue(reply(400,{error:"synthetic sync refused"}));mount();fireEvent.click(button(index));
await waitFor(()=>expect(mocks.toast).toHaveBeenCalledTimes(1));
expect(mocks.toast.mock.calls[0][0]).toMatchObject({variant:"destructive",description:expect.stringContaining("synthetic sync refused")});
expect(mocks.fetch.mock.calls.map(x=>x[0])).toEqual(["/sync/"+target+"/pull"]);expect(button(index)).not.toBeDisabled();
});
it(target+" push rejection is failure after successful pull",async()=>{
mocks.fetch.mockResolvedValueOnce(reply(200,{})).mockResolvedValueOnce(reply(401,{error:"synthetic unauthorized"}));mount();fireEvent.click(button(index));
await waitFor(()=>expect(mocks.toast).toHaveBeenCalledTimes(1));expect(mocks.toast.mock.calls[0][0]).toMatchObject({variant:"destructive",description:expect.stringContaining("synthetic unauthorized")});
expect(mocks.fetch.mock.calls.map(x=>x[0])).toEqual(["/sync/"+target+"/pull","/sync/"+target+"/push"]);expect(button(index)).not.toBeDisabled();
});
it(target+" preserves successful pull then push",async()=>{
mocks.fetch.mockResolvedValue(reply(200,{}));mount();fireEvent.click(button(index));
await waitFor(()=>expect(mocks.toast).toHaveBeenCalledTimes(1));expect(mocks.toast.mock.calls[0][0].variant).not.toBe("destructive");expect(mocks.toast.mock.calls[0][0].title).toMatch(/synced/i);
expect(mocks.fetch.mock.calls.map(x=>[x[0],x[1].method])).toEqual([["/sync/"+target+"/pull","POST"],["/sync/"+target+"/push","POST"]]);expect(button(index)).not.toBeDisabled();
});
it(target+" handles non JSON response and retries",async()=>{
mocks.fetch.mockResolvedValueOnce(new Response("synthetic unavailable",{status:503}));mount();fireEvent.click(button(index));
await waitFor(()=>expect(mocks.toast).toHaveBeenCalledTimes(1));expect(mocks.toast.mock.calls[0][0]).toMatchObject({variant:"destructive",description:expect.stringContaining("503")});
mocks.fetch.mockResolvedValue(reply(200,{}));fireEvent.click(button(index));await waitFor(()=>expect(mocks.toast).toHaveBeenCalledTimes(2));expect(mocks.toast.mock.calls[1][0].title).toMatch(/synced/i);expect(mocks.fetch).toHaveBeenCalledTimes(3);
});
it(target+" preserves network failure feedback",async()=>{
mocks.fetch.mockRejectedValue(new TypeError("Load failed"));mount();fireEvent.click(button(index));await waitFor(()=>expect(mocks.toast).toHaveBeenCalledTimes(1));expect(mocks.toast.mock.calls[0][0]).toMatchObject({variant:"destructive"});expect(String(mocks.toast.mock.calls[0][0].description)).toMatch(/server.*reachable/i);expect(mocks.fetch).toHaveBeenCalledTimes(1);expect(button(index)).not.toBeDisabled();
});
}
it("disabled sync choices do not expose manual actions or send requests",()=>{mocks.state.enabled=false;mount();expect(screen.queryAllByRole("button",{name:/^sync now$/i})).toHaveLength(0);expect(mocks.fetch).not.toHaveBeenCalled();});