Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Add selector helpers for commercial posture

rcourtmane327ff9726e0
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index afa62395b4..7125b2f88e 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -348,6 +348,9 @@ lifecycle-adjacent authenticated-shell surfaces such as
`frontend-modern/src/components/Settings/useAgentProfilesPanelState.ts` must
consume the shared posture owner instead of reintroducing their own mount-time
commercial reads.
+Even on that governed first-run exception, render-time trial gating should stay
+on shared selectors such as `isCommercialTrialActive()` instead of reading raw
+commercial-posture fields inside `SetupCompletionPanel.tsx`.
That same shared boundary now also owns the one-time checkout-return lookup:
lifecycle-adjacent surfaces may initiate billing or account handoff through
shared public routes, but they must never persist, derive, or replay the
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 7a719c19e1..e3b194b179 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -777,6 +777,12 @@ for the NodeModal Pro upgrade path. The NodesAPI client remains the source of
truth for setup/install requests, while hosted trial redirects and denial copy
must flow through the shared trial-start owner rather than a second client-side
status-code map inside node setup state.
+That same frontend/API split now also requires node setup state to consume
+shared commercial selectors for non-transport trial gating. `useNodeModalState.ts`
+may decide whether to show a trial CTA through
+`frontend-modern/src/stores/licenseCommercial.ts`, but it must not repurpose
+raw commercial-posture fields as if they were part of the NodesAPI transport
+contract.
Canonical timeline entries now also preserve correlation context in
`relatedResources`, so the history surface can explain which neighboring
resources moved with restart, anomaly, config, state transition, and
@@ -1162,6 +1168,17 @@ monitored-system ledger endpoint, and TrueNAS/API-backed registration must all
reflect deduped top-level monitored systems rather than agent-only
installation count, and `legacy_connections` / `has_migration_gap` may not
imply that API-backed monitoring sits outside the commercial cap.
+That same contract now also owns prospective admission and replacement
+projection. Config-backed PVE/PBS/PMG, TrueNAS, VMware, and other API-backed
+registration or update routes must project candidates or preview records
+through the canonical monitored-system resolver before persistence, including
+replacement of one existing source-owned surface, instead of rebuilding
+handler-local priority tables or platform-specific counters.
+When an active monitored-system cap is present and current usage cannot be
+resolved, those API contracts must fail closed for net-new admissions rather
+than serializing a fake zero. `/api/license/entitlements` therefore carries
+limit-level `current_available` truth so clients can distinguish unavailable
+monitored-system usage from a real `current: 0`.
That same configured-path contract now also has an explicit shared owner for
manual auth env files: `internal/api/auth_env_path.go` must remain the only
place that derives `.env` from configured runtime paths, and neighboring
diff --git a/docs/release-control/v6/internal/subsystems/cloud-paid.md b/docs/release-control/v6/internal/subsystems/cloud-paid.md
index 56824ad953..a10e30dab8 100644
--- a/docs/release-control/v6/internal/subsystems/cloud-paid.md
+++ b/docs/release-control/v6/internal/subsystems/cloud-paid.md
@@ -214,6 +214,13 @@ the governed browser proof in
`tests/integration/tests/journeys/01-smoke-bootstrap-login-dashboard.spec.ts`,
and `tests/integration/tests/journeys/03-relay-pairing.spec.ts` must continue
to assert zero browser-shell entitlement requests outside owned billing flows.
+That same browser/store boundary also owns typed non-billing commercial
+selectors. `frontend-modern/src/stores/licenseCommercial.ts` may interpret the
+commercial-posture payload once for browser consumers, but relay, Patrol,
+trial banners, monitored-system warnings, and settings paywall state must not
+branch directly on raw `subscription_state`, `trial_eligible`,
+`trial_days_remaining`, or `overflow_days_remaining` fields in each leaf
+surface.
Legacy Cloud plan aliases are now expected to canonicalize to the `cloud_*`
contract not only when Stripe metadata is parsed, but also when persisted plan
versions are consumed at hosted entitlement and workspace-limit enforcement
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index cb15f62b72..5713f117f5 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -140,7 +140,9 @@ work extends shared components instead of creating new local variants.
118. `frontend-modern/src/components/Login.tsx`
119. `frontend-modern/src/stores/demoMode.ts`
120. `frontend-modern/src/stores/sessionCapabilities.ts`
-121. `frontend-modern/src/useAppRuntimeState.ts`
+121. `frontend-modern/src/stores/sessionPresentationPolicy.ts`
+122. `frontend-modern/src/stores/licenseCommercial.ts`
+123. `frontend-modern/src/useAppRuntimeState.ts`
## Shared Boundaries
@@ -678,6 +680,16 @@ handoff itself is now centralized in
onboarding surfaces must use that owner for redirect, success-notification, and
canonical denial handling instead of open-coding local `startProTrial()`
branches or re-interpreting backend status codes.
+That same shared primitive boundary now also owns intent-level commercial
+selectors for non-billing surfaces. Leaf/shared state such as
+`useTrialBannerState.ts`, `useActiveUseTrialNudgeState.ts`,
+`useMonitoredSystemLimitWarningBannerState.ts`, settings panel state, and
+Patrol approval/header shells must consume selector helpers from
+`frontend-modern/src/stores/licenseCommercial.ts` such as
+`canOfferCommercialTrial()`, `canStartCommercialTrial()`,
+`isCommercialTrialActive()`, `commercialTrialDaysRemaining()`, and
+`commercialOverflowDaysRemaining()` instead of branching directly on raw
+`subscription_state`, `trial_eligible`, or day-count fields.
That same owner also holds generic settings-paywall CTA labels. Runtime shells
such as `AIRuntimeControlsSection.tsx` and `RelaySettingsPanel.tsx` must source
shared labels like `Upgrade to Pro` and `Start free trial` from
diff --git a/docs/release-control/v6/internal/subsystems/organization-settings.md b/docs/release-control/v6/internal/subsystems/organization-settings.md
index 50213053ac..1fa21864cb 100644
--- a/docs/release-control/v6/internal/subsystems/organization-settings.md
+++ b/docs/release-control/v6/internal/subsystems/organization-settings.md
@@ -202,3 +202,6 @@ it must not issue its own mount-time `loadCommercialPosture()` read.
Authenticated-shell bootstrap belongs to
`frontend-modern/src/useAppRuntimeState.ts`, with only the governed first-run
setup completion surface allowed to bootstrap posture outside that shell.
+RBAC paywall state should also consume intent-level selectors such as
+`canOfferCommercialTrial()` from `frontend-modern/src/stores/licenseCommercial.ts`
+instead of reading raw posture fields locally.
diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
index 270f9e21b2..33bb8f488d 100644
--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
@@ -608,3 +608,7 @@ commercial split as the rest of the app. Patrol runtime availability must stay
on the non-commercial capability store, while approval/trial CTAs use the
shared commercial-posture store and trial-start helper. Patrol surfaces must not
recombine those two contracts into one entitlement payload.
+Patrol approval and trial shells should consume selector helpers such as
+`canStartCommercialTrial()` from
+`frontend-modern/src/stores/licenseCommercial.ts` instead of branching on raw
+commercial-posture fields in leaf components.
diff --git a/frontend-modern/src/components/Settings/__tests__/AISettings.test.tsx b/frontend-modern/src/components/Settings/__tests__/AISettings.test.tsx
index 62548dbb6a..a50480f471 100644
--- a/frontend-modern/src/components/Settings/__tests__/AISettings.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/AISettings.test.tsx
@@ -75,6 +75,7 @@ vi.mock('@/stores/license', () => ({
}));
vi.mock('@/stores/licenseCommercial', () => ({
+ canOfferCommercialTrial: () => commercialPostureMock()?.trial_eligible !== false,
commercialPosture: (...args: unknown[]) => commercialPostureMock(...args),
entitlements: (...args: unknown[]) => entitlementsMock(...args),
getUpgradeActionDestination: () => ({ href: 'https://example.com/upgrade', external: true }),
diff --git a/frontend-modern/src/components/Settings/__tests__/AgentProfilesPanel.test.tsx b/frontend-modern/src/components/Settings/__tests__/AgentProfilesPanel.test.tsx
index 4a5633e3c5..ae2700b4b5 100644
--- a/frontend-modern/src/components/Settings/__tests__/AgentProfilesPanel.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/AgentProfilesPanel.test.tsx
@@ -40,6 +40,7 @@ vi.mock('@/stores/license', () => ({
}));
vi.mock('@/stores/licenseCommercial', () => ({
+ canOfferCommercialTrial: () => true,
commercialPosture: () => ({ trial_eligible: true }),
entitlements: () => ({ trial_eligible: true }),
getUpgradeActionDestination: (...args: unknown[]) => getUpgradeActionDestinationMock(...args),
@@ -265,6 +266,8 @@ afterEach(() => {
describe('AgentProfilesPanel V6 agent ID handling', () => {
it('relies on shared commercial posture bootstrap instead of local posture loads', () => {
expect(agentProfilesPanelStateSource).not.toContain('loadCommercialPosture(');
+ expect(agentProfilesPanelStateSource).toContain('canOfferCommercialTrial');
+ expect(agentProfilesPanelStateSource).not.toContain('commercialPosture()?.trial_eligible');
});
it('maps assignments using actionable V6 agent ID instead of resource hash ID', async () => {
diff --git a/frontend-modern/src/components/Settings/__tests__/NodeModal.guardrails.test.ts b/frontend-modern/src/components/Settings/__tests__/NodeModal.guardrails.test.ts
index 31f8d7e4ea..d9c32885b6 100644
--- a/frontend-modern/src/components/Settings/__tests__/NodeModal.guardrails.test.ts
+++ b/frontend-modern/src/components/Settings/__tests__/NodeModal.guardrails.test.ts
@@ -56,7 +56,9 @@ describe('NodeModal guardrails', () => {
expect(nodeModalStateSource).toContain("from '@/stores/licenseCommercial';");
expect(nodeModalStateSource).not.toContain("from '@/stores/license';\n");
expect(nodeModalStateSource).not.toContain('loadCommercialPosture(');
- expect(nodeModalStateSource).toContain('const ent = commercialPosture();');
+ expect(nodeModalStateSource).toContain('canStartCommercialTrial');
+ expect(nodeModalStateSource).toContain('const canStartTrial = createMemo(() => canStartCommercialTrial());');
+ expect(nodeModalStateSource).not.toContain('commercialPosture()');
expect(nodeModalStateSource).toContain('const copyProxmoxAgentInstallCommand = async (');
expect(nodeModalStateSource).toContain("const data = await NodesAPI.getAgentInstallCommand({");
expect(nodeModalStateSource).toContain('type,');
@@ -132,8 +134,9 @@ describe('NodeModal guardrails', () => {
'API-managed PVE/PBS/PMG connections are governed when the connection is',
);
expect(nodeModalStateSource).toContain('const hostLimitReached = createMemo(() => false);');
- expect(nodeModalStateSource).toContain("if (ent.subscription_state === 'active' || ent.subscription_state === 'trial')");
- expect(nodeModalStateSource).toContain('return ent.trial_eligible !== false;');
+ expect(nodeModalStateSource).toContain('canStartCommercialTrial');
+ expect(nodeModalStateSource).not.toContain('subscription_state');
+ expect(nodeModalStateSource).not.toContain('trial_eligible');
expect(nodeModalStateSource).toContain('monitored-system limit banner.');
expect(nodeModalSettingsOwnerSource).not.toContain('Under agents-only counting');
expect(nodeModalSettingsOwnerSource).not.toContain('the agent limit');
diff --git a/frontend-modern/src/components/Settings/__tests__/NodeModal.installCommand.test.tsx b/frontend-modern/src/components/Settings/__tests__/NodeModal.installCommand.test.tsx
index 07b527eae6..c9eae122e0 100644
--- a/frontend-modern/src/components/Settings/__tests__/NodeModal.installCommand.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/NodeModal.installCommand.test.tsx
@@ -40,8 +40,7 @@ vi.mock('@/components/shared/Dialog', () => ({
}));
vi.mock('@/stores/licenseCommercial', () => ({
- commercialPosture: () => ({ subscription_state: 'active', trial_eligible: false }),
- loadCommercialPosture: vi.fn(),
+ canStartCommercialTrial: () => false,
startProTrial: vi.fn(),
}));
diff --git a/frontend-modern/src/components/Settings/__tests__/RBACPaywallPanels.test.tsx b/frontend-modern/src/components/Settings/__tests__/RBACPaywallPanels.test.tsx
index e1c9d7ef76..ff820e807f 100644
--- a/frontend-modern/src/components/Settings/__tests__/RBACPaywallPanels.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/RBACPaywallPanels.test.tsx
@@ -27,6 +27,7 @@ vi.mock('@/stores/license', () => ({
}));
vi.mock('@/stores/licenseCommercial', () => ({
+ canOfferCommercialTrial: () => commercialPostureMock()?.trial_eligible !== false,
commercialPosture: (...args: unknown[]) => commercialPostureMock(...args),
getUpgradeActionDestination: (feature: string) => ({
href: `https://example.com/upgrade?feature=${feature}`,
diff --git a/frontend-modern/src/components/Settings/__tests__/RelaySettingsPanel.runtime.test.tsx b/frontend-modern/src/components/Settings/__tests__/RelaySettingsPanel.runtime.test.tsx
index 9bd26bfe21..ae74b46a01 100644
--- a/frontend-modern/src/components/Settings/__tests__/RelaySettingsPanel.runtime.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/RelaySettingsPanel.runtime.test.tsx
@@ -5,7 +5,6 @@ import relaySettingsPanelSource from '../RelaySettingsPanel.tsx?raw';
import relaySettingsPanelStateSource from '../useRelaySettingsPanelState.ts?raw';
const loadLicenseStatusMock = vi.fn();
-const loadCommercialPostureMock = vi.fn();
const hasFeatureMock = vi.fn();
const getRelayConfigMock = vi.fn();
const getRelayStatusMock = vi.fn();
@@ -27,11 +26,9 @@ vi.mock('@/stores/license', () => ({
}));
vi.mock('@/stores/licenseCommercial', () => ({
- commercialPosture: () => ({ trial_eligible: false }),
+ canOfferCommercialTrial: () => false,
getUpgradeActionDestination: () => ({ href: 'https://example.com/upgrade', external: true }),
entitlements: () => ({ trial_eligible: false }),
- loadCommercialPosture: (...args: unknown[]) => loadCommercialPostureMock(...args),
- loadRuntimeCapabilities: (...args: unknown[]) => loadLicenseStatusMock(...args),
startProTrial: vi.fn(),
}));
@@ -82,7 +79,6 @@ import { RelaySettingsPanel } from '../RelaySettingsPanel';
describe('RelaySettingsPanel runtime', () => {
beforeEach(() => {
loadLicenseStatusMock.mockReset();
- loadCommercialPostureMock.mockReset();
hasFeatureMock.mockReset();
getRelayConfigMock.mockReset();
getRelayStatusMock.mockReset();
@@ -99,7 +95,6 @@ describe('RelaySettingsPanel runtime', () => {
hasFeatureMock.mockReturnValue(true);
loadLicenseStatusMock.mockResolvedValue(undefined);
- loadCommercialPostureMock.mockResolvedValue(undefined);
getRelayConfigMock.mockResolvedValue({
enabled: true,
server_url: 'wss://relay.example.test/ws/instance',
@@ -157,6 +152,8 @@ describe('RelaySettingsPanel runtime', () => {
it('relies on shared commercial posture bootstrap for relay settings', () => {
expect(relaySettingsPanelStateSource).not.toContain('loadCommercialPosture(');
+ expect(relaySettingsPanelStateSource).toContain('canOfferCommercialTrial');
+ expect(relaySettingsPanelStateSource).not.toContain('commercialPosture()?.trial_eligible');
});
it('shows supported Pulse Mobile pairing copy on the relay paywall', async () => {
@@ -186,7 +183,6 @@ describe('RelaySettingsPanel runtime', () => {
expect(screen.getByDisplayValue('wss://relay.example.test/ws/instance')).toBeInTheDocument();
});
- expect(loadCommercialPostureMock).not.toHaveBeenCalled();
expect(screen.getByText('Pair Pulse Mobile through Relay')).toBeInTheDocument();
expect(
screen.getByText(
diff --git a/frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts b/frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts
index 26799b534f..039db8f33c 100644
--- a/frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts
+++ b/frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts
@@ -1508,21 +1508,37 @@ describe('Settings architecture guardrails', () => {
expect(aiSettingsStateSource).toContain("} from '@/stores/license';");
expect(aiSettingsStateSource).toContain("} from '@/stores/licenseCommercial';");
expect(aiSettingsStateSource).not.toContain('loadCommercialPosture();');
+ expect(aiSettingsStateSource).toContain('canOfferCommercialTrial');
+ expect(aiSettingsStateSource).not.toContain('commercialPosture()?.trial_eligible');
expect(reportingPanelStateSource).toContain("} from '@/stores/license';");
expect(reportingPanelStateSource).toContain("} from '@/stores/licenseCommercial';");
expect(reportingPanelStateSource).not.toContain('loadCommercialPosture();');
+ expect(reportingPanelStateSource).toContain('canOfferCommercialTrial');
+ expect(reportingPanelStateSource).not.toContain('commercialPosture()?.trial_eligible');
expect(auditLogStateSource).toContain("} from '@/stores/license';");
expect(auditLogStateSource).toContain("} from '@/stores/licenseCommercial';");
expect(auditLogStateSource).not.toContain('loadCommercialPosture();');
+ expect(auditLogStateSource).toContain('canOfferCommercialTrial');
+ expect(auditLogStateSource).not.toContain('commercialPosture()?.trial_eligible');
expect(auditWebhookStateSource).toContain("} from '@/stores/licenseCommercial';");
expect(auditWebhookStateSource).not.toContain('loadCommercialPosture();');
+ expect(auditWebhookStateSource).toContain('canOfferCommercialTrial');
+ expect(auditWebhookStateSource).not.toContain('commercialPosture()?.trial_eligible');
expect(ssoProvidersStateSource).toContain("} from '@/stores/licenseCommercial';");
expect(ssoProvidersStateSource).not.toContain('loadCommercialPosture();');
+ expect(ssoProvidersStateSource).toContain('canOfferCommercialTrial');
+ expect(ssoProvidersStateSource).not.toContain('commercialPosture()?.trial_eligible');
expect(rbacFeatureGateStateSource).toContain("} from '@/stores/licenseCommercial';");
expect(rbacFeatureGateStateSource).not.toContain('loadCommercialPosture();');
+ expect(rbacFeatureGateStateSource).toContain('canOfferCommercialTrial');
+ expect(rbacFeatureGateStateSource).not.toContain('commercialPosture()?.trial_eligible');
expect(nodeModalStateSource).toContain("from '@/stores/licenseCommercial';");
expect(nodeModalStateSource).not.toContain('loadCommercialPosture();');
+ expect(nodeModalStateSource).toContain('canStartCommercialTrial');
+ expect(nodeModalStateSource).not.toContain('commercialPosture()');
+ expect(relaySettingsPanelStateSource).toContain('canOfferCommercialTrial');
+ expect(relaySettingsPanelStateSource).not.toContain('commercialPosture()?.trial_eligible');
});
});
diff --git a/frontend-modern/src/components/Settings/__tests__/useReportingPanelState.test.ts b/frontend-modern/src/components/Settings/__tests__/useReportingPanelState.test.ts
index 4c9c0b5d49..12f0313a52 100644
--- a/frontend-modern/src/components/Settings/__tests__/useReportingPanelState.test.ts
+++ b/frontend-modern/src/components/Settings/__tests__/useReportingPanelState.test.ts
@@ -120,6 +120,7 @@ describe('useReportingPanelState', () => {
}));
vi.doMock('@/stores/licenseCommercial', () => ({
+ canOfferCommercialTrial: vi.fn(() => true),
commercialPosture: vi.fn(() => ({ trial_eligible: true })),
getUpgradeActionDestination: vi.fn((feature?: string) => ({
href: getPublicPricingUrl(feature),
@@ -219,6 +220,7 @@ describe('useReportingPanelState', () => {
}));
vi.doMock('@/stores/licenseCommercial', () => ({
+ canOfferCommercialTrial: vi.fn(() => true),
commercialPosture: vi.fn(() => ({ trial_eligible: true })),
getUpgradeActionDestination: vi.fn((feature?: string) => ({
href: getPublicPricingUrl(feature),
diff --git a/frontend-modern/src/components/Settings/useAISettingsState.ts b/frontend-modern/src/components/Settings/useAISettingsState.ts
index d7956ea88c..aaf446a952 100644
--- a/frontend-modern/src/components/Settings/useAISettingsState.ts
+++ b/frontend-modern/src/components/Settings/useAISettingsState.ts
@@ -15,7 +15,7 @@ import {
loadRuntimeCapabilities,
} from '@/stores/license';
import {
- commercialPosture,
+ canOfferCommercialTrial,
getUpgradeActionDestination,
} from '@/stores/licenseCommercial';
import { notificationStore } from '@/stores/notifications';
@@ -156,7 +156,7 @@ export const useAISettingsState = () => {
const quickstartBlockedReason = createMemo(() =>
normalizeQuickstartReason(settings()?.quickstart_blocked_reason),
);
- const canStartTrial = () => commercialPosture()?.trial_eligible !== false;
+ const canStartTrial = () => canOfferCommercialTrial();
const upgradeAutofixDestination = () => getUpgradeActionDestination('ai_autofix');
const hasProviderBackedModels = (data: AISettingsType | null | undefined) =>
diff --git a/frontend-modern/src/components/Settings/useAgentProfilesPanelState.ts b/frontend-modern/src/components/Settings/useAgentProfilesPanelState.ts
index 60caefbc90..308f8d3d9d 100644
--- a/frontend-modern/src/components/Settings/useAgentProfilesPanelState.ts
+++ b/frontend-modern/src/components/Settings/useAgentProfilesPanelState.ts
@@ -16,7 +16,7 @@ import {
runtimeCapabilitiesLoading,
} from '@/stores/license';
import {
- commercialPosture,
+ canOfferCommercialTrial,
getUpgradeActionDestination,
} from '@/stores/licenseCommercial';
import { loadRuntimeCapabilities } from '@/stores/license';
@@ -77,7 +77,7 @@ export const useAgentProfilesPanelState = () => {
const checkingLicense = () => !runtimeCapabilitiesLoaded() || runtimeCapabilitiesLoading();
const hasAgentProfiles = () => hasEntitlement('agent_profiles');
const [startingTrial, setStartingTrial] = createSignal(false);
- const canStartTrial = () => commercialPosture()?.trial_eligible !== false;
+ const canStartTrial = () => canOfferCommercialTrial();
const [aiAvailable, setAiAvailable] = createSignal(false);
const [profiles, setProfiles] = createSignal<AgentProfile[]>([]);
diff --git a/frontend-modern/src/components/Settings/useAuditLogPanelState.ts b/frontend-modern/src/components/Settings/useAuditLogPanelState.ts
index c19c81472b..9d746be980 100644
--- a/frontend-modern/src/components/Settings/useAuditLogPanelState.ts
+++ b/frontend-modern/src/components/Settings/useAuditLogPanelState.ts
@@ -12,7 +12,7 @@ import {
runtimeCapabilitiesLoaded,
} from '@/stores/license';
import {
- commercialPosture,
+ canOfferCommercialTrial,
getUpgradeActionDestination,
} from '@/stores/licenseCommercial';
import { loadRuntimeCapabilities } from '@/stores/license';
@@ -119,7 +119,7 @@ export const useAuditLogPanelState = () => {
const showUpgradePaywall = createMemo(
() => runtimeCapabilitiesLoaded() && !auditLoggingEnabled() && !loading(),
);
- const canStartTrial = () => commercialPosture()?.trial_eligible !== false;
+ const canStartTrial = () => canOfferCommercialTrial();
const upgradeDestination = createMemo(() => getUpgradeActionDestination('audit_logging'));
const fetchAuditEvents = async (options?: { limit?: number; offset?: number }) => {
diff --git a/frontend-modern/src/components/Settings/useAuditWebhookPanelState.ts b/frontend-modern/src/components/Settings/useAuditWebhookPanelState.ts
index 1b03f64db3..b99b19edf8 100644
--- a/frontend-modern/src/components/Settings/useAuditWebhookPanelState.ts
+++ b/frontend-modern/src/components/Settings/useAuditWebhookPanelState.ts
@@ -7,7 +7,7 @@ import {
runtimeCapabilitiesLoaded,
} from '@/stores/license';
import {
- commercialPosture,
+ canOfferCommercialTrial,
getUpgradeActionDestination,
} from '@/stores/licenseCommercial';
import { loadRuntimeCapabilities } from '@/stores/license';
@@ -28,7 +28,7 @@ export const useAuditWebhookPanelState = (canManageOverride?: boolean) => {
const [startingTrial, setStartingTrial] = createSignal(false);
const canManage = () => canManageOverride !== false;
- const canStartTrial = () => commercialPosture()?.trial_eligible !== false;
+ const canStartTrial = () => canOfferCommercialTrial();
const isAuditLoggingEnabled = () => hasFeature('audit_logging');
const upgradeDestination = () => getUpgradeActionDestination('audit_logging');
diff --git a/frontend-modern/src/components/Settings/useNodeModalState.ts b/frontend-modern/src/components/Settings/useNodeModalState.ts
index 0d48662b91..5274296960 100644
--- a/frontend-modern/src/components/Settings/useNodeModalState.ts
+++ b/frontend-modern/src/components/Settings/useNodeModalState.ts
@@ -4,7 +4,7 @@ import type { NodeConfig } from '@/types/nodes';
import { notificationStore } from '@/stores/notifications';
import { NodesAPI } from '@/api/nodes';
import type { ProxmoxSetupCommandResponse } from '@/api/nodes';
-import { commercialPosture } from '@/stores/licenseCommercial';
+import { canStartCommercialTrial } from '@/stores/licenseCommercial';
import { copyToClipboard } from '@/utils/clipboard';
import { logger } from '@/utils/logger';
import {
@@ -55,12 +55,7 @@ export const useNodeModalState = (props: NodeModalProps) => {
// monitored-system limit banner.
const [startingTrial, setStartingTrial] = createSignal(false);
const hostLimitReached = createMemo(() => false);
- const canStartTrial = createMemo(() => {
- const ent = commercialPosture();
- if (!ent) return false;
- if (ent.subscription_state === 'active' || ent.subscription_state === 'trial') return false;
- return ent.trial_eligible !== false;
- });
+ const canStartTrial = createMemo(() => canStartCommercialTrial());
const handleStartTrial = async () => {
if (startingTrial()) return;
diff --git a/frontend-modern/src/components/Settings/useRBACFeatureGateState.ts b/frontend-modern/src/components/Settings/useRBACFeatureGateState.ts
index 690f853d81..1ab075e2b7 100644
--- a/frontend-modern/src/components/Settings/useRBACFeatureGateState.ts
+++ b/frontend-modern/src/components/Settings/useRBACFeatureGateState.ts
@@ -4,7 +4,7 @@ import {
runtimeCapabilitiesLoaded,
} from '@/stores/license';
import {
- commercialPosture,
+ canOfferCommercialTrial,
} from '@/stores/licenseCommercial';
import { loadRuntimeCapabilities } from '@/stores/license';
import { notificationStore } from '@/stores/notifications';
@@ -30,7 +30,7 @@ export function useRBACFeatureGateState(options: UseRBACFeatureGateStateOptions)
getRBACFeatureGateCopy(options.kind),
);
const licenseReady = createMemo(() => runtimeCapabilitiesLoaded());
- const canStartTrial = createMemo(() => commercialPosture()?.trial_eligible !== false);
+ const canStartTrial = createMemo(() => canOfferCommercialTrial());
const rbacEnabled = createMemo(() => licenseReady() && hasFeature('rbac'));
const paywallVisible = createMemo(
() => licenseReady() && !hasFeature('rbac') && !options.loading(),
diff --git a/frontend-modern/src/components/Settings/useRelaySettingsPanelState.ts b/frontend-modern/src/components/Settings/useRelaySettingsPanelState.ts
index c472e70e77..dc4bccf133 100644
--- a/frontend-modern/src/components/Settings/useRelaySettingsPanelState.ts
+++ b/frontend-modern/src/components/Settings/useRelaySettingsPanelState.ts
@@ -4,7 +4,7 @@ import {
runtimeCapabilitiesLoaded,
} from '@/stores/license';
import {
- commercialPosture,
+ canOfferCommercialTrial,
getUpgradeActionDestination,
} from '@/stores/licenseCommercial';
import { loadRuntimeCapabilities } from '@/stores/license';
@@ -36,7 +36,7 @@ export function useRelaySettingsPanelState(props: RelaySettingsPanelProps) {
const [startingTrial, setStartingTrial] = createSignal(false);
const canManage = () => props.canManage !== false;
- const canStartTrial = () => commercialPosture()?.trial_eligible !== false;
+ const canStartTrial = () => canOfferCommercialTrial();
const relayEnabled = () => hasFeature('relay');
const upgradeDestination = () => getUpgradeActionDestination('relay');
const connectionPresentation = createMemo(() =>
diff --git a/frontend-modern/src/components/Settings/useReportingPanelState.ts b/frontend-modern/src/components/Settings/useReportingPanelState.ts
index 039a4421b2..3c0442c875 100644
--- a/frontend-modern/src/components/Settings/useReportingPanelState.ts
+++ b/frontend-modern/src/components/Settings/useReportingPanelState.ts
@@ -7,7 +7,7 @@ import {
runtimeCapabilitiesLoaded,
} from '@/stores/license';
import {
- commercialPosture,
+ canOfferCommercialTrial,
getUpgradeActionDestination,
} from '@/stores/licenseCommercial';
import { loadRuntimeCapabilities } from '@/stores/license';
@@ -57,7 +57,7 @@ export const useReportingPanelState = () => {
runtimeCapabilitiesLoaded() &&
reportingFeatureId() !== '' &&
!hasFeature(reportingFeatureId());
- const canStartTrial = () => commercialPosture()?.trial_eligible !== false;
+ const canStartTrial = () => canOfferCommercialTrial();
const isReportingEnabled = () =>
runtimeCapabilitiesLoaded() &&
reportingFeatureId() !== '' &&
diff --git a/frontend-modern/src/components/Settings/useSSOProvidersState.ts b/frontend-modern/src/components/Settings/useSSOProvidersState.ts
index 231e750b13..d3c5ef63c9 100644
--- a/frontend-modern/src/components/Settings/useSSOProvidersState.ts
+++ b/frontend-modern/src/components/Settings/useSSOProvidersState.ts
@@ -7,7 +7,7 @@ import {
runtimeCapabilitiesLoaded,
} from '@/stores/license';
import {
- commercialPosture,
+ canOfferCommercialTrial,
getUpgradeActionDestination,
} from '@/stores/licenseCommercial';
import { loadRuntimeCapabilities } from '@/stores/license';
@@ -71,7 +71,7 @@ export const useSSOProvidersState = (props: SSOProvidersPanelProps) => {
const hasAdvancedSSO = createMemo(() => hasFeature('advanced_sso'));
const canManage = () => props.canManage !== false;
- const canStartTrial = () => commercialPosture()?.trial_eligible !== false;
+ const canStartTrial = () => canOfferCommercialTrial();
const handleStartTrial = async () => {
if (startingTrial()) {
diff --git a/frontend-modern/src/components/SetupWizard/SetupCompletionPanel.tsx b/frontend-modern/src/components/SetupWizard/SetupCompletionPanel.tsx
index bf5e0dbda1..4a781bd99e 100644
--- a/frontend-modern/src/components/SetupWizard/SetupCompletionPanel.tsx
+++ b/frontend-modern/src/components/SetupWizard/SetupCompletionPanel.tsx
@@ -32,7 +32,7 @@ import {
getPreferredResourceHostname,
} from '@/utils/resourceIdentity';
import {
- commercialPosture,
+ isCommercialTrialActive,
loadCommercialPosture,
} from '@/stores/licenseCommercial';
import {
@@ -735,7 +735,7 @@ Keep these credentials secure!
Relay.
</p>
<Show
- when={!trialStarted() && commercialPosture()?.subscription_state !== 'trial'}
+ when={!trialStarted() && !isCommercialTrialActive()}
fallback={
<button
type="button"
diff --git a/frontend-modern/src/components/SetupWizard/__tests__/SetupCompletionPanel.guardrails.test.ts b/frontend-modern/src/components/SetupWizard/__tests__/SetupCompletionPanel.guardrails.test.ts
index 6e50ef8a84..d7389f0907 100644
--- a/frontend-modern/src/components/SetupWizard/__tests__/SetupCompletionPanel.guardrails.test.ts
+++ b/frontend-modern/src/components/SetupWizard/__tests__/SetupCompletionPanel.guardrails.test.ts
@@ -26,6 +26,8 @@ describe('SetupCompletionPanel guardrails', () => {
expect(setupCompletionPanelSource).toContain('configure TLS and custom CA options');
expect(setupCompletionPanelSource).toContain('runStartProTrialAction({');
expect(setupCompletionPanelSource).toContain('await loadCommercialPosture(true);');
+ expect(setupCompletionPanelSource).toContain('isCommercialTrialActive');
+ expect(setupCompletionPanelSource).not.toContain("commercialPosture()?.subscription_state !== 'trial'");
expect(setupCompletionPanelSource).not.toContain('getUpgradeActionUrlOrFallback');
});
diff --git a/frontend-modern/src/components/SetupWizard/__tests__/SetupCompletionPanel.test.tsx b/frontend-modern/src/components/SetupWizard/__tests__/SetupCompletionPanel.test.tsx
index 07182e5e39..8d89ecd1dd 100644
--- a/frontend-modern/src/components/SetupWizard/__tests__/SetupCompletionPanel.test.tsx
+++ b/frontend-modern/src/components/SetupWizard/__tests__/SetupCompletionPanel.test.tsx
@@ -54,6 +54,7 @@ vi.mock('@/utils/url', () => ({
}));
vi.mock('@/stores/licenseCommercial', () => ({
+ isCommercialTrialActive: () => false,
loadCommercialPosture: (...args: unknown[]) => loadLicenseStatusMock(...args),
commercialPosture: () => ({ relay: false }),
getUpgradeActionUrlOrFallback: () => 'https://pulse.example.com/upgrade',
diff --git a/frontend-modern/src/components/patrol/ApprovalSection.tsx b/frontend-modern/src/components/patrol/ApprovalSection.tsx
index 01b95cf2ba..fbd3bdd07e 100644
--- a/frontend-modern/src/components/patrol/ApprovalSection.tsx
+++ b/frontend-modern/src/components/patrol/ApprovalSection.tsx
@@ -9,7 +9,7 @@ import { Component, Show, createSignal, createResource, createMemo } from 'solid
import { aiIntelligenceStore } from '@/stores/aiIntelligence';
import { notificationStore } from '@/stores/notifications';
import { aiChatStore } from '@/stores/aiChat';
-import { commercialPosture } from '@/stores/licenseCommercial';
+import { canStartCommercialTrial } from '@/stores/licenseCommercial';
import { hasFeature } from '@/stores/license';
import { AIAPI, type ApprovalRequest, type ApprovalExecutionResult } from '@/api/ai';
import { getApprovalRiskPresentation } from '@/utils/approvalRiskPresentation';
@@ -43,12 +43,7 @@ export const ApprovalSection: Component<ApprovalSectionProps> = (props) => {
const canAutoFix = createMemo(() => hasFeature('ai_autofix'));
const [startingTrial, setStartingTrial] = createSignal(false);
- const canStartTrial = createMemo(() => {
- const ent = commercialPosture();
- if (!ent) return false;
- if (ent.subscription_state === 'active' || ent.subscription_state === 'trial') return false;
- return ent.trial_eligible !== false;
- });
+ const canStartTrial = createMemo(() => canStartCommercialTrial());
const handleStartTrial = async (e: Event) => {
e.stopPropagation();
diff --git a/frontend-modern/src/components/patrol/__tests__/ApprovalSection.test.tsx b/frontend-modern/src/components/patrol/__tests__/ApprovalSection.test.tsx
index 69ec9149ae..620ef896e0 100644
--- a/frontend-modern/src/components/patrol/__tests__/ApprovalSection.test.tsx
+++ b/frontend-modern/src/components/patrol/__tests__/ApprovalSection.test.tsx
@@ -1,6 +1,7 @@
import { cleanup, fireEvent, render, screen, waitFor } from '@solidjs/testing-library';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import type { ApprovalExecutionResult, ApprovalRequest, InvestigationSession } from '@/api/ai';
+import approvalSectionSource from '../ApprovalSection.tsx?raw';
import ApprovalSection from '../ApprovalSection';
const state = vi.hoisted(() => ({
@@ -22,7 +23,6 @@ const notificationSuccessMock = vi.hoisted(() => vi.fn());
const notificationErrorMock = vi.hoisted(() => vi.fn());
const openWithPromptMock = vi.hoisted(() => vi.fn());
const startProTrialMock = vi.hoisted(() => vi.fn());
-const loadCommercialPostureMock = vi.hoisted(() => vi.fn());
vi.mock('@/api/ai', () => ({
AIAPI: {
@@ -59,10 +59,12 @@ vi.mock('@/stores/license', () => ({
}));
vi.mock('@/stores/licenseCommercial', () => ({
- commercialPosture: () => state.entitlements,
- licenseStatus: () => state.entitlements,
- loadCommercialPosture: (...args: unknown[]) => loadCommercialPostureMock(...args),
- loadRuntimeCapabilities: (...args: unknown[]) => loadCommercialPostureMock(...args),
+ canStartCommercialTrial: () => {
+ const ent = state.entitlements;
+ if (!ent) return false;
+ if (ent.subscription_state === 'active' || ent.subscription_state === 'trial') return false;
+ return ent.trial_eligible !== false;
+ },
startProTrial: (...args: unknown[]) => startProTrialMock(...args),
}));
@@ -89,14 +91,17 @@ describe('ApprovalSection', () => {
notificationErrorMock.mockReset();
openWithPromptMock.mockReset();
startProTrialMock.mockReset();
- loadCommercialPostureMock.mockReset();
- loadCommercialPostureMock.mockResolvedValue(undefined);
});
afterEach(() => {
cleanup();
});
+ it('keeps patrol trial gating on shared commercial selector helpers', () => {
+ expect(approvalSectionSource).toContain('canStartCommercialTrial');
+ expect(approvalSectionSource).not.toContain('commercialPosture');
+ });
+
it('keeps fix_queued findings actionable when approval and investigation details are unavailable', async () => {
getInvestigationMock.mockResolvedValue(null);
diff --git a/frontend-modern/src/components/shared/__tests__/ActiveUseTrialNudge.test.tsx b/frontend-modern/src/components/shared/__tests__/ActiveUseTrialNudge.test.tsx
index 893b32be77..fd0b618310 100644
--- a/frontend-modern/src/components/shared/__tests__/ActiveUseTrialNudge.test.tsx
+++ b/frontend-modern/src/components/shared/__tests__/ActiveUseTrialNudge.test.tsx
@@ -26,8 +26,17 @@ const {
}));
vi.mock('@/stores/licenseCommercial', () => ({
+ canShowActiveUseTrialNudge: () => {
+ const posture = commercialPostureMock();
+ return Boolean(
+ posture &&
+ posture.tier === 'free' &&
+ posture.subscription_state !== 'trial' &&
+ posture.subscription_state !== 'active' &&
+ posture.trial_eligible !== false,
+ );
+ },
commercialPosture: (...args: unknown[]) => commercialPostureMock(...args),
- loadCommercialPosture: vi.fn(),
startProTrial: (...args: unknown[]) => startProTrialMock(...args),
}));
@@ -90,6 +99,8 @@ describe('ActiveUseTrialNudge', () => {
expect(activeUseTrialNudgeStateSource).toContain('createMemo');
expect(activeUseTrialNudgeStateSource).toContain('window.localStorage');
expect(activeUseTrialNudgeStateSource).toContain('setInterval');
+ expect(activeUseTrialNudgeStateSource).toContain('canShowActiveUseTrialNudge');
+ expect(activeUseTrialNudgeStateSource).not.toContain('commercialPosture()');
expect(activeUseTrialNudgeStateSource).toContain('runStartProTrialAction');
expect(activeUseTrialNudgeStateSource).not.toContain('startProTrial()');
expect(activeUseTrialNudgeStateSource).toContain('snoozeUpsell');
diff --git a/frontend-modern/src/components/shared/__tests__/HistoryChart.test.tsx b/frontend-modern/src/components/shared/__tests__/HistoryChart.test.tsx
index c938932c66..206b6f41cf 100644
--- a/frontend-modern/src/components/shared/__tests__/HistoryChart.test.tsx
+++ b/frontend-modern/src/components/shared/__tests__/HistoryChart.test.tsx
@@ -42,9 +42,8 @@ vi.mock('@/stores/license', () => ({
}));
vi.mock('@/stores/licenseCommercial', () => ({
+ canStartCommercialTrial: () => false,
getUpgradeActionDestination: () => ({ href: 'https://example.com/upgrade', external: true }),
- commercialPosture: () => ({ subscription_state: 'active' }),
- loadCommercialPosture: vi.fn(),
startProTrial: vi.fn(),
}));
@@ -77,7 +76,7 @@ describe('HistoryChart', () => {
expect(historyChartStateSource).toContain('export function useHistoryChartState');
expect(historyChartStateSource).toContain('HISTORY_CHART_RANGES');
expect(historyChartStateSource).toContain("'mock_synthetic' | null");
- expect(historyChartStateSource).toContain('return ent.trial_eligible !== false;');
+ expect(historyChartStateSource).toContain('const canStartTrial = createMemo(() => canStartCommercialTrial());');
expect(historyChartStateSource).toContain('runStartProTrialAction({');
expect(historyChartStateSource).not.toContain('startProTrial()');
expect(historyChartStateSource).not.toContain('getTrialAlreadyUsedMessage()');
diff --git a/frontend-modern/src/components/shared/__tests__/MonitoredSystemLimitWarningBanner.test.tsx b/frontend-modern/src/components/shared/__tests__/MonitoredSystemLimitWarningBanner.test.tsx
index 304f5945d5..5209f64ccf 100644
--- a/frontend-modern/src/components/shared/__tests__/MonitoredSystemLimitWarningBanner.test.tsx
+++ b/frontend-modern/src/components/shared/__tests__/MonitoredSystemLimitWarningBanner.test.tsx
@@ -31,7 +31,6 @@ const mockLegacyConnections = vi.hoisted(() =>
const mockTrackUpgradeMetricEvent = vi.hoisted(() => vi.fn());
const mockTrackUpgradeClicked = vi.hoisted(() => vi.fn());
const mockLoadRuntimeLicenseStatus = vi.hoisted(() => vi.fn());
-const mockLoadCommercialPosture = vi.hoisted(() => vi.fn());
const mockPresentationPolicyHidesCommercialSurfaces = vi.hoisted(() => vi.fn(() => false));
const mockGetUpgradeActionDestination = vi.hoisted(() => vi.fn());
const mockGetUpgradeActionUrlOrFallback = vi.hoisted(() => vi.fn());
@@ -42,12 +41,11 @@ vi.mock('@/stores/license', () => ({
}));
vi.mock('@/stores/licenseCommercial', () => ({
- commercialPosture: mockEntitlements,
+ commercialOverflowDaysRemaining: () => mockEntitlements().overflow_days_remaining ?? null,
getUpgradeActionDestination: (...args: unknown[]) => mockGetUpgradeActionDestination(...args),
getUpgradeActionUrlOrFallback: (...args: unknown[]) => mockGetUpgradeActionUrlOrFallback(...args),
hasMigrationGap: mockHasMigrationGap,
legacyConnections: mockLegacyConnections,
- loadCommercialPosture: (...args: unknown[]) => mockLoadCommercialPosture(...args),
}));
vi.mock('@/stores/sessionPresentationPolicy', () => ({
@@ -78,8 +76,6 @@ describe('MonitoredSystemLimitWarningBanner', () => {
mockPresentationPolicyHidesCommercialSurfaces.mockReturnValue(false);
mockLoadRuntimeLicenseStatus.mockReset();
mockLoadRuntimeLicenseStatus.mockResolvedValue(undefined);
- mockLoadCommercialPosture.mockReset();
- mockLoadCommercialPosture.mockResolvedValue(undefined);
mockGetUpgradeActionDestination.mockReset();
mockGetUpgradeActionUrlOrFallback.mockReset();
mockGetUpgradeActionDestination.mockReturnValue({
@@ -119,6 +115,12 @@ describe('MonitoredSystemLimitWarningBanner', () => {
expect(monitoredSystemLimitWarningBannerStateSource).toContain(
'presentationPolicyHidesCommercialSurfaces',
);
+ expect(monitoredSystemLimitWarningBannerStateSource).toContain(
+ 'commercialOverflowDaysRemaining',
+ );
+ expect(monitoredSystemLimitWarningBannerStateSource).not.toContain(
+ 'commercialPosture()?.overflow_days_remaining',
+ );
expect(monitoredSystemLimitWarningBannerStateSource).toContain('trackUpgradeMetricEvent');
expect(monitoredSystemLimitWarningBannerStateSource).toContain('legacyConnections');
expect(monitoredSystemLimitWarningBannerStateSource).toContain('scopeSelfHostedBillingDestination');
@@ -155,7 +157,6 @@ describe('MonitoredSystemLimitWarningBanner', () => {
));
expect(mockLoadRuntimeLicenseStatus).toHaveBeenCalled();
- expect(mockLoadCommercialPosture).not.toHaveBeenCalled();
expect(screen.queryByText(/Monitored systems:/i)).not.toBeInTheDocument();
});
diff --git a/frontend-modern/src/components/shared/__tests__/TrialBanner.test.tsx b/frontend-modern/src/components/shared/__tests__/TrialBanner.test.tsx
index 888d096d61..7001dfb572 100644
--- a/frontend-modern/src/components/shared/__tests__/TrialBanner.test.tsx
+++ b/frontend-modern/src/components/shared/__tests__/TrialBanner.test.tsx
@@ -13,7 +13,6 @@ const {
getUpgradeActionDestinationMock,
getUpgradeActionUrlOrFallbackMock,
commercialPostureMock,
- loadCommercialPostureMock,
isUpsellSnoozedMock,
snoozeUpsellMock,
} =
@@ -22,16 +21,16 @@ const {
getUpgradeActionDestinationMock: vi.fn(),
getUpgradeActionUrlOrFallbackMock: vi.fn(),
commercialPostureMock: vi.fn(),
- loadCommercialPostureMock: vi.fn(),
isUpsellSnoozedMock: vi.fn(),
snoozeUpsellMock: vi.fn(),
}));
vi.mock('@/stores/licenseCommercial', () => ({
+ commercialTrialDaysRemaining: () => commercialPostureMock()?.trial_days_remaining ?? null,
getUpgradeActionDestination: (...args: unknown[]) => getUpgradeActionDestinationMock(...args),
getUpgradeActionUrlOrFallback: (...args: unknown[]) => getUpgradeActionUrlOrFallbackMock(...args),
commercialPosture: (...args: unknown[]) => commercialPostureMock(...args),
- loadCommercialPosture: (...args: unknown[]) => loadCommercialPostureMock(...args),
+ isCommercialTrialActive: () => commercialPostureMock()?.subscription_state === 'trial',
}));
vi.mock('@/stores/sessionPresentationPolicy', () => ({
@@ -57,7 +56,6 @@ describe('TrialBanner', () => {
getUpgradeActionDestinationMock.mockReset();
getUpgradeActionUrlOrFallbackMock.mockReset();
commercialPostureMock.mockReset();
- loadCommercialPostureMock.mockReset();
isUpsellSnoozedMock.mockReset();
snoozeUpsellMock.mockReset();
getUpgradeActionDestinationMock.mockReturnValue({
@@ -66,7 +64,6 @@ describe('TrialBanner', () => {
});
presentationPolicyHidesCommercialSurfacesMock.mockReturnValue(false);
getUpgradeActionUrlOrFallbackMock.mockReturnValue(getPublicPricingUrl('trial_banner'));
- loadCommercialPostureMock.mockResolvedValue(undefined);
isUpsellSnoozedMock.mockReturnValue(false);
});
@@ -88,7 +85,8 @@ describe('TrialBanner', () => {
expect(trialBannerStateSource).toContain('createMemo');
expect(trialBannerStateSource).not.toContain('loadCommercialPosture');
expect(trialBannerStateSource).toContain('presentationPolicyHidesCommercialSurfaces');
- expect(trialBannerStateSource).toContain('commercialPosture');
+ expect(trialBannerStateSource).toContain('isCommercialTrialActive');
+ expect(trialBannerStateSource).toContain('commercialTrialDaysRemaining');
expect(trialBannerStateSource).toContain('getUpgradeActionDestination');
expect(trialBannerStateSource).toContain('snoozeUpsell');
diff --git a/frontend-modern/src/components/shared/useActiveUseTrialNudgeState.ts b/frontend-modern/src/components/shared/useActiveUseTrialNudgeState.ts
index 14eaa49b4a..7f2ac02fbb 100644
--- a/frontend-modern/src/components/shared/useActiveUseTrialNudgeState.ts
+++ b/frontend-modern/src/components/shared/useActiveUseTrialNudgeState.ts
@@ -1,5 +1,5 @@
import { createMemo, createSignal, onCleanup, onMount } from 'solid-js';
-import { commercialPosture } from '@/stores/licenseCommercial';
+import { canShowActiveUseTrialNudge } from '@/stores/licenseCommercial';
import { notificationStore } from '@/stores/notifications';
import { isUpsellSnoozed, snoozeUpsell } from '@/utils/snooze';
import { runStartProTrialAction } from '@/utils/trialStartAction';
@@ -7,7 +7,6 @@ import {
ACTIVE_USE_TRIAL_NUDGE_FIRST_SEEN_KEY,
ACTIVE_USE_TRIAL_NUDGE_REFRESH_MS,
ACTIVE_USE_TRIAL_NUDGE_SNOOZE_KEY,
- isActiveUseTrialNudgeEligible,
isActiveUseTrialNudgeOldEnough,
} from './activeUseTrialNudgeModel';
@@ -46,7 +45,7 @@ export function useActiveUseTrialNudgeState() {
const shouldShow = createMemo(() => {
return (
isActiveUseTrialNudgeOldEnough(now(), firstSeen()) &&
- isActiveUseTrialNudgeEligible(commercialPosture()) &&
+ canShowActiveUseTrialNudge() &&
!snoozed()
);
});
diff --git a/frontend-modern/src/components/shared/useHistoryChartState.ts b/frontend-modern/src/components/shared/useHistoryChartState.ts
index 89ffe52c95..f4bacc295d 100644
--- a/frontend-modern/src/components/shared/useHistoryChartState.ts
+++ b/frontend-modern/src/components/shared/useHistoryChartState.ts
@@ -12,7 +12,7 @@ import {
maxHistoryDays,
} from '@/stores/license';
import {
- commercialPosture,
+ canStartCommercialTrial,
getUpgradeActionDestination,
} from '@/stores/licenseCommercial';
import { calculateOptimalPoints } from '@/utils/downsample';
@@ -53,12 +53,7 @@ export function useHistoryChartState(props: HistoryChartProps, refs: HistoryChar
const [startingTrial, setStartingTrial] = createSignal(false);
const [hoveredPoint, setHoveredPoint] = createSignal<HistoryChartHoverPoint | null>(null);
- const canStartTrial = createMemo(() => {
- const ent = commercialPosture();
- if (!ent) return false;
- if (ent.subscription_state === 'active' || ent.subscription_state === 'trial') return false;
- return ent.trial_eligible !== false;
- });
+ const canStartTrial = createMemo(() => canStartCommercialTrial());
const handleStartTrial = async () => {
if (startingTrial()) return;
diff --git a/frontend-modern/src/components/shared/useMonitoredSystemLimitWarningBannerState.ts b/frontend-modern/src/components/shared/useMonitoredSystemLimitWarningBannerState.ts
index 360c462a85..1352062a21 100644
--- a/frontend-modern/src/components/shared/useMonitoredSystemLimitWarningBannerState.ts
+++ b/frontend-modern/src/components/shared/useMonitoredSystemLimitWarningBannerState.ts
@@ -5,7 +5,7 @@ import {
loadRuntimeCapabilities,
} from '@/stores/license';
import {
- commercialPosture,
+ commercialOverflowDaysRemaining,
getUpgradeActionDestination,
hasMigrationGap,
legacyConnections,
@@ -54,7 +54,7 @@ export function useMonitoredSystemLimitWarningBannerState() {
getMonitoredSystemMigrationMessage(migrationCounts()),
);
const overflowSummary = createMemo(() =>
- getMonitoredSystemOverflowSummary(commercialPosture()?.overflow_days_remaining),
+ getMonitoredSystemOverflowSummary(commercialOverflowDaysRemaining()),
);
const toneClass = createMemo(() => getMonitoredSystemBannerToneClass(isUrgent()));
const migrationTextClass = createMemo(() =>
diff --git a/frontend-modern/src/components/shared/useTrialBannerState.ts b/frontend-modern/src/components/shared/useTrialBannerState.ts
index 80a0e6d0d2..187d6b38c3 100644
--- a/frontend-modern/src/components/shared/useTrialBannerState.ts
+++ b/frontend-modern/src/components/shared/useTrialBannerState.ts
@@ -1,5 +1,9 @@
import { createMemo, createSignal } from 'solid-js';
-import { commercialPosture, getUpgradeActionDestination } from '@/stores/licenseCommercial';
+import {
+ commercialTrialDaysRemaining,
+ getUpgradeActionDestination,
+ isCommercialTrialActive,
+} from '@/stores/licenseCommercial';
import { presentationPolicyHidesCommercialSurfaces } from '@/stores/sessionPresentationPolicy';
import { isUpsellSnoozed, snoozeUpsell } from '@/utils/snooze';
import {
@@ -15,10 +19,10 @@ export function useTrialBannerState() {
const isTrial = createMemo(
() =>
!presentationPolicyHidesCommercialSurfaces() &&
- commercialPosture()?.subscription_state === 'trial',
+ isCommercialTrialActive(),
);
const daysRemaining = createMemo(() =>
- normalizeTrialBannerDaysRemaining(commercialPosture()?.trial_days_remaining),
+ normalizeTrialBannerDaysRemaining(commercialTrialDaysRemaining()),
);
const toneClass = createMemo(() => getTrialBannerToneClass(daysRemaining()));
const upgradeDestination = createMemo(() =>
diff --git a/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts b/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts
index 6c4bb94db5..ef5d5ff9cf 100644
--- a/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts
+++ b/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts
@@ -27,7 +27,7 @@ import {
loadRuntimeCapabilities,
} from '@/stores/license';
import {
- commercialPosture,
+ canStartCommercialTrial,
getUpgradeActionDestination,
} from '@/stores/licenseCommercial';
import { getCanonicalScopeResourceIds } from '@/utils/patrolFormat';
@@ -169,17 +169,7 @@ export function usePatrolIntelligenceState() {
const alertAnalysisLocked = createMemo(() => !hasFeature('ai_alerts'));
const autoFixLocked = createMemo(() => !hasFeature('ai_autofix'));
- const canStartTrial = createMemo(() => {
- const posture = commercialPosture();
- if (!posture) return false;
- if (
- posture.subscription_state === 'active' ||
- posture.subscription_state === 'trial'
- ) {
- return false;
- }
- return posture.trial_eligible !== false;
- });
+ const canStartTrial = createMemo(() => canStartCommercialTrial());
async function handleStartTrial() {
if (startingTrial()) return;
diff --git a/frontend-modern/src/stores/licenseCommercial.ts b/frontend-modern/src/stores/licenseCommercial.ts
index 158c890e6d..027fb76021 100644
--- a/frontend-modern/src/stores/licenseCommercial.ts
+++ b/frontend-modern/src/stores/licenseCommercial.ts
@@ -210,6 +210,52 @@ export const isPro = createRoot(() =>
}),
);
+/**
+ * Used by non-billing upgrade surfaces that can render a trial CTA unless the
+ * current posture explicitly denies trial eligibility.
+ */
+export function canOfferCommercialTrial(): boolean {
+ return commercialPostureState()?.trial_eligible !== false;
+}
+
+/**
+ * Used by surfaces that should only offer trial start when the current
+ * commercial posture is loaded and not already active/trial-backed.
+ */
+export function canStartCommercialTrial(): boolean {
+ const current = commercialPostureState();
+ if (!current) return false;
+ if (current.subscription_state === 'active' || current.subscription_state === 'trial') {
+ return false;
+ }
+ return current.trial_eligible !== false;
+}
+
+export function isCommercialTrialActive(): boolean {
+ return commercialPostureState()?.subscription_state === 'trial';
+}
+
+export function commercialTrialDaysRemaining(): number | null {
+ const current = commercialPostureState()?.trial_days_remaining;
+ return typeof current === 'number' && Number.isFinite(current) ? current : null;
+}
+
+export function commercialOverflowDaysRemaining(): number | null {
+ const current = commercialPostureState()?.overflow_days_remaining;
+ return typeof current === 'number' && Number.isFinite(current) ? current : null;
+}
+
+export function canShowActiveUseTrialNudge(): boolean {
+ const current = commercialPostureState();
+ if (!current) return false;
+ return (
+ current.tier === 'free' &&
+ current.subscription_state !== 'trial' &&
+ current.subscription_state !== 'active' &&
+ current.trial_eligible !== false
+ );
+}
+
export function getUpgradeReason(key: string) {
const current = commercialPostureState();
if (!current?.upgrade_reasons?.length) return undefined;
diff --git a/tests/integration/tests/18-patrol-runtime-state.spec.ts b/tests/integration/tests/18-patrol-runtime-state.spec.ts
index aaf73097f0..b1d944904c 100644
--- a/tests/integration/tests/18-patrol-runtime-state.spec.ts
+++ b/tests/integration/tests/18-patrol-runtime-state.spec.ts
@@ -1,6 +1,6 @@
import { expect, test, type Page } from "@playwright/test";
-import { ensureAuthenticated } from "./helpers";
+import { ensureAuthenticated, trackBrowserRequests } from "./helpers";
const PATROL_BLOCK_REASON =
"Quickstart credits exhausted. Connect your API key to continue using AI Patrol.";
@@ -483,10 +483,22 @@ test.describe("Patrol runtime-state browser contract", () => {
"Desktop-only Patrol runtime coverage",
);
+ const commercialPostureRequests = trackBrowserRequests(
+ page,
+ "/api/license/commercial-posture",
+ );
+ const entitlementsRequests = trackBrowserRequests(
+ page,
+ "/api/license/entitlements",
+ );
+
await ensureAuthenticated(page);
+ commercialPostureRequests.clear();
+ entitlementsRequests.clear();
await mockBlockedPatrolRuntimeState(page);
- await page.goto("/ai", { waitUntil: "domcontentloaded" });
+ await page.getByRole("tab", { name: "Patrol" }).click();
+ await expect(page).toHaveURL(/\/ai/);
await expect(page.getByText("Patrol Paused").first()).toBeVisible();
await expect(page.getByText("Patrol paused").first()).toBeVisible();
@@ -496,6 +508,10 @@ test.describe("Patrol runtime-state browser contract", () => {
).toBeDisabled();
await expect(page.getByText("Patrol quickstart exhausted")).toBeVisible();
await expect(page.getByText("Health A · 100/100")).toHaveCount(0);
+ expect(commercialPostureRequests.count()).toBe(0);
+ expect(entitlementsRequests.count()).toBe(0);
+ commercialPostureRequests.stop();
+ entitlementsRequests.stop();
});
test("surfaces scoped trigger context inside the summary and split trigger controls on the Patrol page", async ({