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
fix(app): hide stale trial expiration after upgrade (#5376)
Ezra Ellette29f4477d049b
diff --git a/apps/screenpipe-app-tauri/app/(main)/home/page.tsx b/apps/screenpipe-app-tauri/app/(main)/home/page.tsxindex c6222ca98..5e2908458 100644--- a/apps/screenpipe-app-tauri/app/(main)/home/page.tsx+++ b/apps/screenpipe-app-tauri/app/(main)/home/page.tsx@@ -1120,8 +1120,7 @@ function HomeContent() {</div><PlanExpirationNotice- expiresAt={(settings.user as AppUser | null)?.plan_expires_at}- plan={(settings.user as AppUser | null)?.subscription_plan}+ user={settings.user as AppUser | null}onClick={() => openSettings("account")}/>diff --git a/apps/screenpipe-app-tauri/components/plan-expiration-notice.test.tsx b/apps/screenpipe-app-tauri/components/plan-expiration-notice.test.tsxindex dcd68e260..4928dbbc6 100644--- a/apps/screenpipe-app-tauri/components/plan-expiration-notice.test.tsx+++ b/apps/screenpipe-app-tauri/components/plan-expiration-notice.test.tsx@@ -6,8 +6,10 @@ import { cleanup, fireEvent, render, screen } from "@testing-library/react";import { afterEach, describe, expect, it, vi } from "vitest";import {getPlanExpiration,+ getUserPlanExpiration,PlanExpirationNotice,} from "./plan-expiration-notice";+import type { AppUser } from "@/lib/app-entitlement";const analyticsMocks = vi.hoisted(() => ({ capture: vi.fn() }));@@ -37,6 +39,46 @@ describe("PlanExpirationNotice", () => {expect(getPlanExpiration("2026-07-21T11:59:59.000Z", now)).toBeNull();});+ it("shows the countdown for a profile-granted trial (server source: manual)", () => {+ // Mirrors the exact /api/user shape for the 14-day signup Business trial:+ // resolveAppEntitlement resolves profile grants as source "manual" —+ // there is no "signup_trial" source in the server vocabulary.+ const expiration = getUserPlanExpiration(+ {+ plan_expires_at: "2026-08-04T12:00:00.000Z",+ subscription_plan: "pro",+ entitlement: {+ active: true,+ plan: "pro",+ source: "manual",+ status: "active",+ expires_at: "2026-08-04T12:00:00.000Z",+ },+ } as AppUser,+ Date.parse("2026-07-21T12:00:00.000Z"),+ );++ expect(expiration?.daysRemaining).toBe(14);+ });++ it("hides a stale profile-grant trial expiration after billing takes over", () => {+ const expiration = getUserPlanExpiration(+ {+ plan_expires_at: "2026-08-04T12:00:00.000Z",+ subscription_plan: "pro",+ entitlement: {+ active: true,+ plan: "pro",+ source: "subscription",+ status: "active",+ },+ } as AppUser,+ Date.parse("2026-07-21T12:00:00.000Z"),+ );++ expect(expiration).toBeNull();+ });+it("renders the countdown and opens its destination", () => {vi.useFakeTimers();vi.setSystemTime(new Date("2026-07-21T12:00:00.000Z"));@@ -44,8 +86,11 @@ describe("PlanExpirationNotice", () => {render(<PlanExpirationNotice- expiresAt="2026-07-24T12:00:00.000Z"- plan="pro"+ user={{+ plan_expires_at: "2026-07-24T12:00:00.000Z",+ subscription_plan: "pro",+ entitlement: { source: "manual" },+ } as AppUser}onClick={onClick}/>,);@@ -82,8 +127,10 @@ describe("PlanExpirationNotice", () => {render(<PlanExpirationNotice- expiresAt="2026-07-22T12:00:00.000Z"- plan="standard"+ user={{+ plan_expires_at: "2026-07-22T12:00:00.000Z",+ subscription_plan: "standard",+ } as AppUser}onClick={vi.fn()}/>,);diff --git a/apps/screenpipe-app-tauri/components/plan-expiration-notice.tsx b/apps/screenpipe-app-tauri/components/plan-expiration-notice.tsxindex a5abe1cae..f0598e989 100644--- a/apps/screenpipe-app-tauri/components/plan-expiration-notice.tsx+++ b/apps/screenpipe-app-tauri/components/plan-expiration-notice.tsx@@ -6,7 +6,11 @@import { useEffect } from "react";import { ArrowRight, Clock } from "lucide-react";import posthog from "posthog-js";-import { planDisplayName } from "@/lib/app-entitlement";+import {+ hasBillingSubscriptionEntitlement,+ planDisplayName,+ type AppUser,+} from "@/lib/app-entitlement";export type PlanExpiration = {expiresAt: Date;@@ -30,20 +34,27 @@ export function getPlanExpiration(};}+export function getUserPlanExpiration(+ user: AppUser | null | undefined,+ nowMs = Date.now(),+): PlanExpiration | null {+ if (hasBillingSubscriptionEntitlement(user)) return null;+ return getPlanExpiration(user?.plan_expires_at, nowMs);+}+type PlanExpirationNoticeProps = {- expiresAt: string | null | undefined;- plan: string | null | undefined;+ user: AppUser | null | undefined;onClick: () => void;variant?: "sidebar" | "account";};export function PlanExpirationNotice({- expiresAt,- plan,+ user,onClick,variant = "sidebar",}: PlanExpirationNoticeProps) {- const expiration = getPlanExpiration(expiresAt);+ const expiration = getUserPlanExpiration(user);+ const plan = user?.subscription_plan;const planName = planDisplayName(plan);const daysRemaining = expiration?.daysRemaining ?? null;const expirationIso = expiration?.expiresAt.toISOString() ?? null;diff --git a/apps/screenpipe-app-tauri/components/settings/__tests__/account-section.subscription-gate.test.tsx b/apps/screenpipe-app-tauri/components/settings/__tests__/account-section.subscription-gate.test.tsxindex 07c7b20c4..ade83a088 100644--- a/apps/screenpipe-app-tauri/components/settings/__tests__/account-section.subscription-gate.test.tsx+++ b/apps/screenpipe-app-tauri/components/settings/__tests__/account-section.subscription-gate.test.tsx@@ -17,7 +17,14 @@// header and the active-plan card can never contradict each other.import { afterEach, describe, expect, it, vi } from "vitest";-import { cleanup, fireEvent, render, screen, within } from "@testing-library/react";+import {+ act,+ cleanup,+ fireEvent,+ render,+ screen,+ within,+} from "@testing-library/react";const mocks = vi.hoisted(() => ({state: { user: null as any },@@ -27,6 +34,13 @@ const mocks = vi.hoisted(() => ({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`@@ -70,7 +84,7 @@ vi.mock("@tauri-apps/plugin-deep-link", () => ({onOpenUrl: vi.fn().mockResolvedValue(() => {}),}));vi.mock("@tauri-apps/api/event", () => ({- listen: vi.fn().mockResolvedValue(() => {}),+ listen: mocks.listen,}));// ReferralCard pulls its own data deps; it is irrelevant to the gate.@@ -90,6 +104,7 @@ describe("AccountSection subscription/login gating", () => {vi.useRealTimers();vi.clearAllMocks();vi.unstubAllGlobals();+ mocks.eventHandlers.clear();mocks.state.user = null;});@@ -141,6 +156,12 @@ describe("AccountSection subscription/login gating", () => {cloud_subscribed: true,subscription_plan: "pro",plan_expires_at: "2026-08-04T12:00:00.000Z",+ entitlement: {+ active: true,+ plan: "pro",+ source: "manual",+ status: "active",+ },};render(<AccountSection />);@@ -150,6 +171,89 @@ describe("AccountSection subscription/login gating", () => {expect(mocks.openUrl).toHaveBeenCalledWith("https://screenpipe.com/account/billing");});+ it("hides a stale trial end date after the paid subscription starts", () => {+ vi.useFakeTimers();+ vi.setSystemTime(new Date("2026-07-21T12:00:00.000Z"));+ mocks.state.user = {+ id: "u1",+ email: "[email protected]",+ token: "tok",+ cloud_subscribed: true,+ subscription_plan: "pro",+ plan_expires_at: "2026-08-04T12:00:00.000Z",+ entitlement: {+ active: true,+ plan: "pro",+ source: "subscription",+ status: "active",+ },+ };++ render(<AccountSection />);++ expect(+ screen.queryByTestId("account-plan-expiration-notice"),+ ).not.toBeInTheDocument();+ expect(+ screen.queryByText("Business plan ends in 14 days"),+ ).not.toBeInTheDocument();+ });++ it("clears the trial date and refreshes entitlement when checkout activates", async () => {+ vi.useFakeTimers();+ mocks.state.user = {+ id: "u1",+ email: "[email protected]",+ token: "tok",+ cloud_subscribed: true,+ subscription_plan: "pro",+ plan_expires_at: "2026-08-04T12:00:00.000Z",+ entitlement: {+ active: true,+ plan: "pro",+ source: "manual",+ status: "active",+ },+ };+ vi.stubGlobal(+ "fetch",+ vi+ .fn()+ .mockResolvedValueOnce(+ new Response(+ JSON.stringify({ url: "https://checkout.stripe.test/session" }),+ { status: 200, headers: { "Content-Type": "application/json" } },+ ),+ )+ .mockResolvedValueOnce(+ new Response(+ JSON.stringify({+ hasSubscription: true,+ subscription: { status: "active" },+ }),+ { status: 200, headers: { "Content-Type": "application/json" } },+ ),+ ),+ );++ render(<AccountSection />);+ const trayUpgrade = mocks.eventHandlers.get("tray-upgrade");+ expect(trayUpgrade).toBeDefined();++ await act(async () => {+ await trayUpgrade?.({ event: "tray-upgrade", id: 1, payload: null });+ await vi.advanceTimersByTimeAsync(2000);+ });++ expect(mocks.updateSettings).toHaveBeenCalledWith({+ user: expect.objectContaining({+ cloud_subscribed: true,+ plan_expires_at: null,+ }),+ });+ expect(mocks.loadUser).toHaveBeenCalledWith("tok", true);+ });+it("does not regress the logged-in Basic plan badge (token, no cloud)", () => {// A paying Basic/standard owner is logged in but not cloud_subscribed: they// still get an "active" named-plan badge, but NOT the cloud sync card.diff --git a/apps/screenpipe-app-tauri/components/settings/account-section.tsx b/apps/screenpipe-app-tauri/components/settings/account-section.tsxindex 1947e0a16..edd236346 100644--- a/apps/screenpipe-app-tauri/components/settings/account-section.tsx+++ b/apps/screenpipe-app-tauri/components/settings/account-section.tsx@@ -50,7 +50,7 @@ import posthog from "posthog-js";import { describeDeepLinkForLog } from "@/lib/utils/deep-link-log";import { screenpipeWebUrl } from "@/lib/web-url";import {- getPlanExpiration,+ getUserPlanExpiration,PlanExpirationNotice,} from "@/components/plan-expiration-notice";@@ -117,8 +117,8 @@ export function AccountSection() {const [connectionsSyncing, setConnectionsSyncing] = useState(false);const subscriptionPlan = settings.user?.subscription_plan ?? null;const hasNamedPlan = !!subscriptionPlan && subscriptionPlan !== "none";- const planExpiresAt = (settings.user as AppUser | null)?.plan_expires_at;- const hasExpiringProfilePlan = getPlanExpiration(planExpiresAt) !== null;+ const appUser = settings.user as AppUser | null;+ const hasExpiringProfilePlan = getUserPlanExpiration(appUser) !== null;useEffect(() => {if (!settings.user?.email) {@@ -246,9 +246,17 @@ export function AccountSection() {// (This poll runs token-authenticated, so the guard is// belt-and-suspenders.)if (settings.user?.token) {- updateSettings({- user: { ...settings.user, cloud_subscribed: true },+ await updateSettings({+ user: {+ ...settings.user,+ cloud_subscribed: true,+ plan_expires_at: null,+ } as AppUser,});+ // Refresh the complete entitlement so its source changes+ // from manual (the profile trial grant) to subscription+ // in this session.+ await loadUser(settings.user.token, true);}toast({title: "subscription activated",@@ -375,8 +383,7 @@ export function AccountSection() {</div><PlanExpirationNotice- expiresAt={planExpiresAt}- plan={subscriptionPlan}+ user={appUser}onClick={() => openExternalUrl(BILLING_URL)}variant="account"/>diff --git a/apps/screenpipe-app-tauri/lib/app-entitlement.ts b/apps/screenpipe-app-tauri/lib/app-entitlement.tsindex 93bc30f60..cbe7ffc2f 100644--- a/apps/screenpipe-app-tauri/lib/app-entitlement.ts+++ b/apps/screenpipe-app-tauri/lib/app-entitlement.ts@@ -126,6 +126,22 @@ function asEntitlement(entitlement: AppUser["entitlement"] | undefined): AppEntireturn entitlement as AppEntitlement;}+/**+ * Whether billing has superseded a profile-granted plan such as the signup+ * trial (which the server resolves as source "manual"). The profile's+ * plan_expires_at metadata can linger after checkout, but the selected+ * entitlement source switches to subscription.+ */+export function hasBillingSubscriptionEntitlement(+ user: AppUser | null | undefined,+): boolean {+ const source = asEntitlement(user?.entitlement)?.source;+ return (+ typeof source === "string" &&+ source.trim().toLowerCase() === "subscription"+ );+}+export function getEnterpriseAccount(user: AppUser | null | undefined,): AppEnterpriseAccount | null {