Skip to content

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

test(e2e): isolate entitlement account state (#5157)

Louis Beaumont5a0279cc25af
diff --git a/apps/screenpipe-app-tauri/e2e/specs/zz-account-basic-upgrade-billing.spec.ts b/apps/screenpipe-app-tauri/e2e/specs/zz-account-basic-upgrade-billing.spec.ts
index 7e0d04e34..9268f1fab 100644
--- a/apps/screenpipe-app-tauri/e2e/specs/zz-account-basic-upgrade-billing.spec.ts
+++ b/apps/screenpipe-app-tauri/e2e/specs/zz-account-basic-upgrade-billing.spec.ts
@@ -14,6 +14,7 @@ import {
waitForTestId,
t,
} from "../helpers/test-utils.js";
+import { invoke } from "../helpers/tauri.js";
const FAKE_TOKEN = "e2e-fake-token-basic-upgrade";
const FAKE_EMAIL = "[email protected]";
@@ -211,6 +212,25 @@ async function restoreMocks(): Promise<void> {
}).catch(() => {});
}
+async function clearBasicAccountUser(): Promise<void> {
+ const logout = await $('[data-testid="account-logout-button"]');
+ if (await logout.isExisting()) {
+ await logout.click();
+ }
+
+ // Keep this spec isolated even if the UI logout is interrupted by a reload.
+ const result = await invoke("set_cloud_token", { token: null });
+ expect(result.ok).toBe(true);
+ await browser.waitUntil(
+ async () => (await loginStatusText()).includes("not logged in"),
+ {
+ timeout: t(8_000),
+ interval: 200,
+ timeoutMsg: "Basic billing test did not clear its fake account",
+ },
+ );
+}
+
async function forEachWindow(fn: () => Promise<void>): Promise<void> {
const start = await browser.getWindowHandle().catch(() => null);
for (const handle of await browser.getWindowHandles().catch(() => [] as string[])) {
@@ -259,7 +279,11 @@ describe("Basic subscriber upgrade uses billing, not fresh checkout", function (
});
after(async () => {
- await forEachWindow(() => restoreMocks()).catch(() => {});
+ try {
+ await clearBasicAccountUser();
+ } finally {
+ await forEachWindow(() => restoreMocks()).catch(() => {});
+ }
});
it("does not hit /api/subscription/checkout when upgrading an existing Basic plan", async () => {
diff --git a/apps/screenpipe-app-tauri/e2e/specs/zz-app-entitlement-gate.spec.ts b/apps/screenpipe-app-tauri/e2e/specs/zz-app-entitlement-gate.spec.ts
index 8ce991c5a..9d4e415d1 100644
--- a/apps/screenpipe-app-tauri/e2e/specs/zz-app-entitlement-gate.spec.ts
+++ b/apps/screenpipe-app-tauri/e2e/specs/zz-app-entitlement-gate.spec.ts
@@ -22,9 +22,26 @@ import { invoke } from '../helpers/tauri.js';
import { getLocalApiConfig, waitForLocalApi } from '../helpers/api-utils.js';
const FORCE_KEY = 'screenpipe_e2e_force_billing_gate';
+const E2E_ACCOUNT_USER_KEY = 'screenpipe_e2e_account_user';
+const E2E_ACCOUNT_USER_EVENT = 'screenpipe-e2e-seed-account-user';
const FAKE_DENIED_TOKEN = 'e2e-fake-token-cloud-sub-app-denied';
const FAKE_DENIED_EMAIL = '[email protected]';
+async function clearAccountState(): Promise<void> {
+ await browser.execute(
+ (key: string, eventName: string) => {
+ window.localStorage.setItem(key, 'null');
+ window.dispatchEvent(new Event(eventName));
+ },
+ E2E_ACCOUNT_USER_KEY,
+ E2E_ACCOUNT_USER_EVENT,
+ );
+
+ const result = await invoke('set_cloud_token', { token: null });
+ expect(result.ok).toBe(true);
+ await browser.pause(t(500));
+}
+
/** Forcing the gate on drives the entitlement gate to stop the engine
* (components/app-entitlement-gate.tsx calls stopScreenpipe for an unentitled
* session). Clearing the flag restores the dev bypass but does NOT restart the
@@ -148,6 +165,10 @@ describe('App entitlement gate', () => {
before(async () => {
await waitForAppReady();
await openHomeWindow();
+ // The preceding Basic billing spec intentionally seeds an entitled user.
+ // Start from an explicit signed-out state instead of depending on spec order
+ // or an eventual real-network 401 to clear that synthetic account.
+ await clearAccountState();
});
after(async () => {