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.

Align dev entitlements with feature gates

rcourtmanb9dc003712b7
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 190e4d5919..282f20658f 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -316,6 +316,11 @@ must expose `/api/admin/reports/catalog`, but frontend consumers may treat a
the legacy report-generation transport only; they must not synthesize or guess
the newer catalog-owned inventory export contract when the backend does not
provide it.
+The licensing API must also stay internally coherent in local dev mode. When
+backend feature gates are widened by `PULSE_DEV=true` or demo/mock mode,
+`/api/license/entitlements` must advertise the same capability set in
+`capabilities`; it must not leave frontend shells on stale free-tier gating
+while backend `HasFeature()` already treats those features as available.
The `/api/resources` serializer now also refreshes canonical identity and
policy metadata through the shared unified-resource helper before it writes
the payload, so backend and frontend contract tests stay aligned on one
diff --git a/docs/release-control/v6/internal/subsystems/cloud-paid.md b/docs/release-control/v6/internal/subsystems/cloud-paid.md
index 4b9e7832b8..b5c8abb7ea 100644
--- a/docs/release-control/v6/internal/subsystems/cloud-paid.md
+++ b/docs/release-control/v6/internal/subsystems/cloud-paid.md
@@ -681,6 +681,12 @@ The runtime entitlement surface now follows the same rule: evaluator/token
source accessors, hosted-subscription validity rules, and frontend entitlement
payload construction should move behind explicit proof routes rather than being
implicitly trusted as part of the catch-all cloud runtime layer.
+That same runtime surface must stay internally coherent in local dev mode. If
+`pkg/licensing/service.go` widens backend `HasFeature()` checks under
+`PULSE_DEV=true` or demo/mock mode, the entitlement payload and any other
+frontend-facing capability contract derived from that service must advertise
+the same capability set instead of leaving paid surfaces artificially locked
+behind stale free-tier capabilities.
Cloud/MSP live price IDs are no longer an open fill-in task either. The audit
record `docs/release-control/v6/records/cloud-msp-price-audit-2026-03-13.md`
verified that the 13 canonical Cloud/MSP v6 `price_*` IDs are present in the
diff --git a/internal/api/entitlement_handlers_test.go b/internal/api/entitlement_handlers_test.go
index 4bb4dcb70a..0f77348f50 100644
--- a/internal/api/entitlement_handlers_test.go
+++ b/internal/api/entitlement_handlers_test.go
@@ -15,6 +15,15 @@ import (
pkglicensing "github.com/rcourtman/pulse-go-rewrite/pkg/licensing"
)
+func containsCapability(values []string, key string) bool {
+ for _, value := range values {
+ if value == key {
+ return true
+ }
+ }
+ return false
+}
+
func TestBuildEntitlementPayload_ActiveLicense(t *testing.T) {
status := &license.LicenseStatus{
Valid: true,
@@ -353,6 +362,45 @@ func TestEntitlementHandler_TrialEligibility_FreshOrgAllowed(t *testing.T) {
}
}
+func TestEntitlementHandler_DevModeMirrorsFeatureGateCapabilities(t *testing.T) {
+ t.Setenv("PULSE_DEV", "true")
+
+ baseDir := t.TempDir()
+ mtp := config.NewMultiTenantPersistence(baseDir)
+ h := NewLicenseHandlers(mtp, false)
+
+ ctx := context.WithValue(context.Background(), OrgIDContextKey, "default")
+ req := httptest.NewRequest(http.MethodGet, "/api/license/entitlements", nil).WithContext(ctx)
+ rec := httptest.NewRecorder()
+ h.HandleEntitlements(rec, req)
+
+ if rec.Code != http.StatusOK {
+ t.Fatalf("status=%d, want %d: %s", rec.Code, http.StatusOK, rec.Body.String())
+ }
+
+ var payload EntitlementPayload
+ if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil {
+ t.Fatalf("unmarshal payload failed: %v", err)
+ }
+
+ if !containsCapability(payload.Capabilities, license.FeatureAdvancedReporting) {
+ t.Fatalf("expected dev entitlements to include %q, got %v", license.FeatureAdvancedReporting, payload.Capabilities)
+ }
+ if len(payload.UpgradeReasons) != 0 {
+ t.Fatalf("expected no upgrade reasons in dev mode, got %v", payload.UpgradeReasons)
+ }
+
+ svc, _, err := h.getTenantComponents(ctx)
+ if err != nil {
+ t.Fatalf("getTenantComponents failed: %v", err)
+ }
+ for _, cap := range payload.Capabilities {
+ if !svc.HasFeature(cap) {
+ t.Fatalf("parity mismatch: HasFeature(%q)=false but capability present in payload", cap)
+ }
+ }
+}
+
func TestEntitlementHandler_TrialEligibility_AlreadyUsedDenied(t *testing.T) {
baseDir := t.TempDir()
mtp := config.NewMultiTenantPersistence(baseDir)
diff --git a/pkg/licensing/service.go b/pkg/licensing/service.go
index f9890c2e4e..28f71715a5 100644
--- a/pkg/licensing/service.go
+++ b/pkg/licensing/service.go
@@ -633,6 +633,9 @@ func (s *Service) Status() *LicenseStatus {
status.MaxMonitoredSystems = defaultSystems
}
}
+ if isDemoMode() || isDevMode() {
+ status.Features = allKnownFeatures()
+ }
return status
}
@@ -688,6 +691,10 @@ func (s *Service) Status() *LicenseStatus {
status.MaxGuests = 0
}
+ if isDemoMode() || isDevMode() {
+ status.Features = allKnownFeatures()
+ }
+
return status
}
@@ -734,6 +741,17 @@ func evaluatorFeatures(eval *Evaluator) []string {
// Derive a stable, known capability list from the evaluator by enumerating
// all feature keys currently used by tier-based gating.
+ caps := make([]string, 0, len(allKnownFeatures()))
+ for _, feature := range allKnownFeatures() {
+ if eval.HasCapability(feature) {
+ caps = append(caps, feature)
+ }
+ }
+ sort.Strings(caps)
+ return caps
+}
+
+func allKnownFeatures() []string {
known := make(map[string]struct{}, 32)
for _, features := range TierFeatures {
for _, feature := range features {
@@ -741,14 +759,12 @@ func evaluatorFeatures(eval *Evaluator) []string {
}
}
- caps := make([]string, 0, len(known))
+ out := make([]string, 0, len(known))
for feature := range known {
- if eval.HasCapability(feature) {
- caps = append(caps, feature)
- }
+ out = append(out, feature)
}
- sort.Strings(caps)
- return caps
+ sort.Strings(out)
+ return out
}
func unionFeatures(a, b []string) []string {
diff --git a/pkg/licensing/service_activate_test.go b/pkg/licensing/service_activate_test.go
index 95223df229..d1ac9c2b40 100644
--- a/pkg/licensing/service_activate_test.go
+++ b/pkg/licensing/service_activate_test.go
@@ -168,3 +168,32 @@ func TestServiceStatusMissingJWTCloudPlanFailsClosed(t *testing.T) {
t.Fatalf("status.MaxMonitoredSystems=%d, want %d", status.MaxMonitoredSystems, UnknownPlanDefaultMonitoredSystemLimit)
}
}
+
+func TestServiceStatus_DevModeAdvertisesAllKnownFeaturesWithoutLicense(t *testing.T) {
+ t.Setenv("PULSE_DEV", "true")
+
+ svc := NewService()
+ status := svc.Status()
+
+ if status.Valid {
+ t.Fatalf("status.Valid=%v, want false", status.Valid)
+ }
+ if status.Tier != TierFree {
+ t.Fatalf("status.Tier=%q, want %q", status.Tier, TierFree)
+ }
+
+ for _, feature := range allKnownFeatures() {
+ if !containsStringValue(status.Features, feature) {
+ t.Fatalf("status.Features missing %q in dev mode: %v", feature, status.Features)
+ }
+ }
+}
+
+func containsStringValue(values []string, want string) bool {
+ for _, value := range values {
+ if value == want {
+ return true
+ }
+ }
+ return false
+}