Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: completed reconsile and refresh got removed
=51fd27a92e62
diff --git a/backend/src/ee/services/license/license-service.ts b/backend/src/ee/services/license/license-service.tsindex 27fc81f433..f900c29d33 100644--- a/backend/src/ee/services/license/license-service.ts+++ b/backend/src/ee/services/license/license-service.ts@@ -69,12 +69,13 @@ type TLicenseServiceFactoryDep = {orgDAL: Pick<TOrgDALFactory, "findRootOrgDetails" | "countAllOrgMembers" | "findById">;permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;licenseDAL: TLicenseDALFactory;- keyStore: Pick<TKeyStoreFactory, "setItemWithExpiry" | "setItemWithExpiryNX" | "getItem" | "deleteItem">;+ keyStore: Pick<TKeyStoreFactory, "setItemWithExpiry" | "setItemWithExpiryNX" | "getItems" | "deleteItem">;projectDAL: TProjectDALFactory;licenseClient?: Pick<TLicenseClientFactory, "getEntitlements" | "getSubscription" | "refreshEntitlements">;licenseDualRead?: Pick<TDualReadServiceFactory, "compareInBackground">;- // Fire-and-forget v2 usage meter for org user seats; no-ops when the v2 license server is disabled.- usageMeteringService?: Pick<TUsageMeteringServiceFactory, "emit">;+ // Fire-and-forget v2 usage meter for org user seats + demand-driven reconciliation; both no-op when+ // the v2 license server is disabled.+ usageMeteringService?: Pick<TUsageMeteringServiceFactory, "emit" | "reconcile">;};export type TLicenseServiceFactory = ReturnType<typeof licenseServiceFactory>;@@ -320,18 +321,33 @@ export const licenseServiceFactory = ({logger.info(`getPlan: attempting to fetch plan for [orgId=${orgId}] [projectId=${projectId}]`);try {if (instanceType === InstanceType.Cloud) {- const [cachedPlan, passThrough] = await Promise.all([- keyStore.getItem(KeyStorePrefixes.LicenseCloudPlan(orgId)),- keyStore.getItem(KeyStorePrefixes.LicenseCachePassThrough(orgId))+ // One MGET for the plan cache + the two markers instead of three separate round-trips.+ const [cachedPlan, passThrough, reconcileMarker] = await keyStore.getItems([+ KeyStorePrefixes.LicenseCloudPlan(orgId),+ KeyStorePrefixes.LicenseCachePassThrough(orgId),+ KeyStorePrefixes.LicenseUsageReconcileMarker(orgId)]);++ // Demand-driven usage reconciliation: for a billable org (a paid plan → non-null slug) that+ // hasn't been reconciled this interval, re-emit its meters in the background. reconcile()+ // self-throttles on the same marker, so this is a no-op on the vast majority of calls and never+ // blocks the request. Free orgs (null slug) never enter the reconcile path.+ const maybeReconcile = (plan: TFeatureSet) => {+ if (!reconcileMarker && plan.slug) {+ usageMeteringService?.reconcile(orgId);+ }+ };+if (cachedPlan) {// A billing mutation flagged this org: serve the cached plan now but kick a background refresh// so the cache converges as the license server reconciles, instead of waiting out the TTL.if (passThrough) {void revalidatePlanInBackground(orgId);}+ const plan = JSON.parse(cachedPlan) as TFeatureSet;+ maybeReconcile(plan);logger.info(`getPlan: plan fetched from cache [orgId=${orgId}] [projectId=${projectId}]`);- return JSON.parse(cachedPlan) as TFeatureSet;+ return plan;}const org = await orgDAL.findRootOrgDetails(orgId);@@ -395,6 +411,7 @@ export const licenseServiceFactory = ({licenseDualRead?.compareInBackground(rootOrgId, currentPlan);}+ maybeReconcile(currentPlan);return currentPlan;}} catch (error) {diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.tsindex 088f78f8a4..acb8e0e71d 100644--- a/backend/src/keystore/keystore.ts+++ b/backend/src/keystore/keystore.ts@@ -154,6 +154,8 @@ export const KeyStorePrefixes = {LicenseCachePassThrough: (orgId: string) => `license-cache-passthrough-${orgId}` as const,// Single-flight guard so only one background revalidation runs per org per lock window.LicenseCacheRevalidateLock: (orgId: string) => `license-cache-revalidate-lock-${orgId}` as const,+ // Throttles the demand-driven usage reconciliation (fired from getPlan) to once per org per interval.+ LicenseUsageReconcileMarker: (orgId: string) => `license-usage-reconcile-${orgId}` as const,LicenseUsageLastReported: (orgId: string, featureKey: string) =>`license-usage-last-reported-${orgId}-${featureKey}` as const,IdentityLockoutState: (identityId: string, authMethod: string, slug: string) =>@@ -204,6 +206,8 @@ export const KeyStoreTtls = {LicenseCachePassThroughInSeconds: 180, // 3 minutes// Throttle window for the single-flight background revalidation.LicenseCacheRevalidateLockInSeconds: 10,+ // How often a billable org's usage is re-emitted for reconciliation (demand-driven from getPlan).+ LicenseUsageReconcileIntervalInSeconds: 21600, // 6 hoursLicenseUsageLastReportedInSeconds: 604800, // 7 daysAiMcpEndpointOAuthFlowInSeconds: 300, // 5 minutesOauthAuthorizationCodeInSeconds: 600, // 10 minutesdiff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex 489efc3260..2506d9ba4b 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -807,7 +807,7 @@ export const registerRoutes = async (// Created before licenseService so the latter can emit the v2 user-seat meter from its// updateSubscriptionOrgMemberCount chokepoint.- const usageMeteringService = usageMeteringServiceFactory({ queueService, projectDAL, envConfig });+ const usageMeteringService = usageMeteringServiceFactory({ queueService, projectDAL, keyStore, envConfig });const licenseService = licenseServiceFactory({permissionService,@@ -836,9 +836,11 @@ export const registerRoutes = async (cronJob,keyStore,orgDAL,+ licenseService,usageMeteringService,meteredFeatures,usageReporter,+ isCloud: envConfig.isCloud,source: usageSource});diff --git a/backend/src/services/license-client/license-client-backends.ts b/backend/src/services/license-client/license-client-backends.tsindex 5342d40eab..b31fc294c1 100644--- a/backend/src/services/license-client/license-client-backends.ts+++ b/backend/src/services/license-client/license-client-backends.ts@@ -39,7 +39,6 @@ import {// Token-scoped paths for the self-hosted (license-key) backend: the key identifies the license, so// no org_id is carried. The global catalog is org-independent and shared by both backends.const ENTITLEMENTS_PATH = "/v1/entitlements";-const ENTITLEMENTS_REFRESH_PATH = "/v1/entitlements/refresh";const PRODUCTS_PATH = "/v1/products";const SUBSCRIPTION_PATH = "/v1/subscription";@@ -131,16 +130,6 @@ export const licenseServerBackend = (return entitlementsResponseSchema.parse(body);},- refreshEntitlements: async (org: TEntitlementOrg): Promise<void> => {- const url = new URL(orgScoped(org.id, "/entitlements/refresh"), serverUrl);- const res = await fetch(url, {- method: "POST",- headers: { Authorization: `Bearer ${mintServiceToken(signingKey)}` },- redirect: "manual"- });- await throwIfResponseError(res);- },-fetchCatalog: async (orgId: string): Promise<TCatalogResponse> => {const url = new URL(orgScoped(orgId, "/products"), serverUrl);const res = await fetch(url, {@@ -396,16 +385,6 @@ export const licenseServerSelfHostedBackend = (return entitlementsResponseSchema.parse(body);},- refreshEntitlements: async (): Promise<void> => {- const url = new URL(ENTITLEMENTS_REFRESH_PATH, serverUrl);- const res = await fetch(url, {- method: "POST",- headers: { Authorization: `Bearer ${licenseKey}` },- redirect: "manual"- });- await throwIfResponseError(res);- },-fetchCatalog: async (): Promise<TCatalogResponse> => {const url = new URL(PRODUCTS_PATH, serverUrl);const res = await fetch(url, {diff --git a/backend/src/services/license-client/license-client-types.ts b/backend/src/services/license-client/license-client-types.tsindex 03b4e983d3..d84aacd02c 100644--- a/backend/src/services/license-client/license-client-types.ts+++ b/backend/src/services/license-client/license-client-types.ts@@ -459,8 +459,6 @@ export { trialsResponseSchema };export type TLicenseClientBackend = {fetchEntitlements: (org: TEntitlementOrg) => Promise<TEntitlementsResponse>;- // Ask the license server to recompute/bust its cached entitlements after a license change.- refreshEntitlements: (org: TEntitlementOrg) => Promise<void>;// Org-scoped on cloud (the catalog is filtered per calling org). The self-hosted backend ignores the// arg and hits its single-tenant /v1/products.fetchCatalog: (orgId: string) => Promise<TCatalogResponse>;diff --git a/backend/src/services/license-client/license-client.ts b/backend/src/services/license-client/license-client.tsindex 9a4dfb203a..a1f4c128e6 100644--- a/backend/src/services/license-client/license-client.ts+++ b/backend/src/services/license-client/license-client.ts@@ -104,13 +104,13 @@ export const licenseClientFactory = ({ envConfig, keyStore }: TLicenseClientFactawait resolver.markPassThrough(orgId);};- // Ask the license server to recompute its cached entitlements (used after a license change), then- // drop the local cache so the next read reflects them. No-op when the backend is dormant.+ // Drop the local plan cache so the next read reflects a change immediately. The license server no+ // longer caches entitlements (reads are always live), so there's nothing to ask it to recompute.+ // No-op when the backend is dormant.const refreshEntitlements = async (org: TEntitlementOrg) => {if (!backend) {return;}- await backend.refreshEntitlements(org);await invalidateEntitlements(org.id);};diff --git a/backend/src/services/license-client/usage/usage-counters.ts b/backend/src/services/license-client/usage/usage-counters.tsindex 01095d6635..1efeea9d4b 100644--- a/backend/src/services/license-client/usage/usage-counters.ts+++ b/backend/src/services/license-client/usage/usage-counters.ts@@ -16,6 +16,17 @@ export type TMeteredFeature = {count: TFeatureCounterFn;};+// Static list of every metered dimension key (no DAL needed). For callers that only need the keys, not+// the count fns — e.g. background reconciliation emitting one event per dimension for an org.+export const METERED_DIMENSION_KEYS: string[] = [+ IdentitiesMeter,+ InternalCas,+ ActiveCerts,+ SecretIdentities,+ PamIdentities,+ UserIdentities+].map((feature) => feature.key);+type TBuildMeteredFeaturesDep = {licenseDAL: Pick<TLicenseDALFactory, "countOrgUsersAndIdentities" | "countOfOrgMembers">;usageCounterDAL: TUsageCounterDALFactory;diff --git a/backend/src/services/license-client/usage/usage-event-queue.ts b/backend/src/services/license-client/usage/usage-event-queue.tsindex c60d3e0d20..80b63c33e1 100644--- a/backend/src/services/license-client/usage/usage-event-queue.ts+++ b/backend/src/services/license-client/usage/usage-event-queue.ts@@ -1,22 +1,28 @@+import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";import { KeyStorePrefixes, KeyStoreTtls, TKeyStoreFactory } from "@app/keystore/keystore";-import { getConfig } from "@app/lib/config/env";import { CronJobName, TCronJobFactory } from "@app/lib/cron/cron-job";import { logger } from "@app/lib/logger";import { QueueName, TQueueServiceFactory } from "@app/queue";import { TOrgDALFactory } from "@app/services/org/org-dal";+import { ActiveCerts, InternalCas } from "../features";import { TMeteredFeature } from "./usage-counters";import { TUsageMeteringServiceFactory } from "./usage-metering-service";import { TUsageReporter, UsageReportError } from "./usage-reporter";+// Temporarily not reporting the internal-CA and certificate meters; events for these drain harmlessly.+const SKIPPED_DIMENSION_KEYS = new Set<string>([InternalCas.key, ActiveCerts.key]);+type TUsageEventQueueFactoryDep = {queueService: Pick<TQueueServiceFactory, "start">;cronJob: TCronJobFactory;keyStore: Pick<TKeyStoreFactory, "getItem" | "setItemWithExpiry">;orgDAL: Pick<TOrgDALFactory, "find">;+ licenseService: Pick<TLicenseServiceFactory, "getPlan">;usageMeteringService: Pick<TUsageMeteringServiceFactory, "emit">;meteredFeatures: TMeteredFeature[];usageReporter: TUsageReporter | null;+ isCloud: boolean;source: string;};@@ -25,9 +31,11 @@ export const usageEventQueueFactory = ({cronJob,keyStore,orgDAL,+ licenseService,usageMeteringService,meteredFeatures,usageReporter,+ isCloud,source}: TUsageEventQueueFactoryDep) => {const featureByKey = new Map(meteredFeatures.map((m) => [m.feature.key, m]));@@ -35,9 +43,21 @@ export const usageEventQueueFactory = ({// Counts the meter and reports it to the License Server only when the value changed since the last// report. No-ops when the reporter is null (v2 disabled), so queued events drain harmlessly.const handleUsageEvent = async (orgId: string, dimensionKey: string, observedAt: Date) => {+ if (SKIPPED_DIMENSION_KEYS.has(dimensionKey)) {+ return;+ }if (!usageReporter) {return;}+ // On cloud, an org with no active paid plan (null slug) has no license on the server, so a report+ // would just 404 "license not found". Skip the round-trip. Self-hosted is a single licensed+ // instance, so this gate doesn't apply there.+ if (isCloud) {+ const plan = await licenseService.getPlan(orgId);+ if (!plan.slug) {+ return;+ }+ }try {const metered = featureByKey.get(dimensionKey);if (!metered) {@@ -141,12 +161,11 @@ export const usageEventQueueFactory = ({const init = () => {startWorker();- const appCfg = getConfig();cronJob.register({name: CronJobName.LicenseUsageFlush,pattern: "*/30 * * * *",runHashTtlS: 60 * 60,- enabled: !appCfg.isCloud,+ enabled: !isCloud,handler: flushAllOrgs});};diff --git a/backend/src/services/license-client/usage/usage-metering-service.ts b/backend/src/services/license-client/usage/usage-metering-service.tsindex 6e967d37b0..38f8699ff3 100644--- a/backend/src/services/license-client/usage/usage-metering-service.ts+++ b/backend/src/services/license-client/usage/usage-metering-service.ts@@ -1,13 +1,17 @@+import { KeyStorePrefixes, KeyStoreTtls, TKeyStoreFactory } from "@app/keystore/keystore";import { TEnvConfig } from "@app/lib/config/env";import { logger } from "@app/lib/logger";import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";import { TProjectDALFactory } from "@app/services/project/project-dal";+import { METERED_DIMENSION_KEYS } from "./usage-counters";+export type TUsageMeteringServiceFactory = ReturnType<typeof usageMeteringServiceFactory>;type TUsageMeteringServiceFactoryDep = {queueService: Pick<TQueueServiceFactory, "queue">;projectDAL: Pick<TProjectDALFactory, "findById">;+ keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX">;envConfig: Pick<TEnvConfig, "LICENSE_SERVER_V2_MODE">;};@@ -16,6 +20,7 @@ const DEBOUNCE_MS = 5000;export const usageMeteringServiceFactory = ({queueService,projectDAL,+ keyStore,envConfig}: TUsageMeteringServiceFactoryDep) => {const enqueue = async (orgId: string, dimensionKey: string) => {@@ -73,5 +78,29 @@ export const usageMeteringServiceFactory = ({});};- return { emit, emitForProject };+ // Demand-driven reconciliation: re-emit every metered dimension for an org so a missed/dropped event+ // or an expired lastReported converges. Fired fire-and-forget from getPlan for billable orgs; the NX+ // marker throttles it to once per org per interval (and coalesces concurrent callers). The emits reuse+ // the normal pipeline, so the slug gate and lastReported dedup still apply downstream.+ const reconcile = (orgId: string) => {+ if (envConfig.LICENSE_SERVER_V2_MODE === "off") {+ return;+ }++ void (async () => {+ const acquired = await keyStore.setItemWithExpiryNX(+ KeyStorePrefixes.LicenseUsageReconcileMarker(orgId),+ KeyStoreTtls.LicenseUsageReconcileIntervalInSeconds,+ "1"+ );+ if (acquired !== "OK") {+ return;+ }+ METERED_DIMENSION_KEYS.forEach((dimensionKey) => emit(orgId, dimensionKey));+ })().catch((error) => {+ logger.error(error, `usage-metering: failed to reconcile org usage [orgId=${orgId}]`);+ });+ };++ return { emit, emitForProject, reconcile };};diff --git a/backend/src/services/license-client/usage/usage-metering.test.ts b/backend/src/services/license-client/usage/usage-metering.test.tsindex c1da836074..662047c499 100644--- a/backend/src/services/license-client/usage/usage-metering.test.ts+++ b/backend/src/services/license-client/usage/usage-metering.test.ts@@ -11,7 +11,7 @@ import {SecretIdentities,UserIdentities} from "../features";-import { buildMeteredFeatures } from "./usage-counters";+import { buildMeteredFeatures, METERED_DIMENSION_KEYS } from "./usage-counters";import { usageEventQueueFactory } from "./usage-event-queue";import { usageMeteringServiceFactory } from "./usage-metering-service";import { buildUsageReporter, TUsageSnapshot, UsageReportError } from "./usage-reporter";@@ -45,6 +45,13 @@ const createFakeKeyStore = () => {store.set(key, String(value));return "OK" as const;}),+ setItemWithExpiryNX: vi.fn(async (key: string, _ttl: number | string, value: string | number | Buffer) => {+ if (store.has(key)) {+ return null;+ }+ store.set(key, String(value));+ return "OK" as const;+ }),store};};@@ -54,6 +61,7 @@ describe("usageMeteringService.emit (org-scoped)", () => {const queue = makeQueueMock();const svc = usageMeteringServiceFactory({queueService: { queue },+ keyStore: createFakeKeyStore(),projectDAL: { findById: vi.fn() },envConfig: { LICENSE_SERVER_V2_MODE: "off" }});@@ -68,6 +76,7 @@ describe("usageMeteringService.emit (org-scoped)", () => {const queue = makeQueueMock();const svc = usageMeteringServiceFactory({queueService: { queue },+ keyStore: createFakeKeyStore(),projectDAL: { findById: vi.fn() },envConfig: { LICENSE_SERVER_V2_MODE: "read-compare" }});@@ -90,6 +99,7 @@ describe("usageMeteringService.emit (org-scoped)", () => {});const svc = usageMeteringServiceFactory({queueService: { queue },+ keyStore: createFakeKeyStore(),projectDAL: { findById: vi.fn() },envConfig: { LICENSE_SERVER_V2_MODE: "read-compare" }});@@ -105,6 +115,7 @@ describe("usageMeteringService.emitForProject (project-scoped)", () => {const findById = vi.fn(async () => ({ id: PROJECT_ID, orgId: ORG_ID }));const svc = usageMeteringServiceFactory({queueService: { queue },+ keyStore: createFakeKeyStore(),projectDAL: { findById } as never,envConfig: { LICENSE_SERVER_V2_MODE: "read-compare" }});@@ -123,6 +134,7 @@ describe("usageMeteringService.emitForProject (project-scoped)", () => {const queue = makeQueueMock();const svc = usageMeteringServiceFactory({queueService: { queue },+ keyStore: createFakeKeyStore(),projectDAL: { findById: vi.fn(async () => undefined) } as never,envConfig: { LICENSE_SERVER_V2_MODE: "read-compare" }});@@ -138,6 +150,7 @@ describe("usageMeteringService.emitForProject (project-scoped)", () => {const findById = vi.fn();const svc = usageMeteringServiceFactory({queueService: { queue },+ keyStore: createFakeKeyStore(),projectDAL: { findById },envConfig: { LICENSE_SERVER_V2_MODE: "off" }});@@ -150,6 +163,44 @@ describe("usageMeteringService.emitForProject (project-scoped)", () => {});});+describe("usageMeteringService.reconcile (demand-driven)", () => {+ test("does nothing when the v2 license server is disabled", async () => {+ const queue = makeQueueMock();+ const svc = usageMeteringServiceFactory({+ queueService: { queue },+ keyStore: createFakeKeyStore(),+ projectDAL: { findById: vi.fn() },+ envConfig: { LICENSE_SERVER_V2_MODE: "off" }+ });++ svc.reconcile(ORG_ID);+ await flushAsync();++ expect(queue).not.toHaveBeenCalled();+ });++ test("emits every metered dimension once, then throttles repeats via the NX marker", async () => {+ const queue = makeQueueMock();+ const keyStore = createFakeKeyStore();+ const svc = usageMeteringServiceFactory({+ queueService: { queue },+ keyStore,+ projectDAL: { findById: vi.fn() },+ envConfig: { LICENSE_SERVER_V2_MODE: "on" }+ });++ svc.reconcile(ORG_ID);+ await flushAsync();+ expect(queue).toHaveBeenCalledTimes(METERED_DIMENSION_KEYS.length);++ // A second call within the interval is throttled by the marker set on the first.+ queue.mockClear();+ svc.reconcile(ORG_ID);+ await flushAsync();+ expect(queue).not.toHaveBeenCalled();+ });+});+describe("buildUsageReporter", () => {test("is null when disabled", () => {expect(buildUsageReporter({ LICENSE_SERVER_V2_MODE: "off" })).toBeNull();@@ -245,6 +296,8 @@ describe("usageEventQueue.handleUsageEvent (worker)", () => {usageReporter?: unknown;keyStore?: ReturnType<typeof createFakeKeyStore>;orgFind?: unknown;+ isCloud?: boolean;+ getPlan?: (orgId: string) => Promise<{ slug: string | null }>;} = {}) => {const reportSnapshots = vi.fn(async () => {});@@ -252,17 +305,21 @@ describe("usageEventQueue.handleUsageEvent (worker)", () => {const usageReporter = overrides.usageReporter === undefined ? { reportSnapshots } : overrides.usageReporter;const emit = vi.fn();const find = overrides.orgFind ?? vi.fn(async () => []);+ // Default to a billable plan so the cloud slug gate is a pass-through unless a test overrides it.+ const getPlan = vi.fn(overrides.getPlan ?? (async () => ({ slug: "pro" })));const queue = usageEventQueueFactory({queueService: { start: vi.fn() },cronJob: { register: vi.fn(), start: vi.fn(), stop: vi.fn() } as never,keyStore,orgDAL: { find } as never,+ licenseService: { getPlan } as never,usageMeteringService: { emit },meteredFeatures,usageReporter: usageReporter as never,+ isCloud: overrides.isCloud ?? false,source: "test-region"});- return { queue, reportSnapshots, keyStore, emit, find };+ return { queue, reportSnapshots, keyStore, emit, find, getPlan };};beforeEach(() => {@@ -290,6 +347,46 @@ describe("usageEventQueue.handleUsageEvent (worker)", () => {expect(keyStore.store.get(`license-usage-last-reported-${ORG_ID}-${IdentitiesMeter.key}`)).toBe("42");});+ test("on cloud, skips a free org (null slug) before counting to avoid a 404", async () => {+ const { queue, reportSnapshots, getPlan } = buildQueue({+ isCloud: true,+ getPlan: async () => ({ slug: null })+ });++ await queue.handleUsageEvent(ORG_ID, IdentitiesMeter.key, new Date());++ expect(getPlan).toHaveBeenCalledWith(ORG_ID);+ expect(meteredFeatures[0].count).not.toHaveBeenCalled();+ expect(reportSnapshots).not.toHaveBeenCalled();+ });++ test("on cloud, proceeds for a billable org (non-null slug)", async () => {+ const { queue, reportSnapshots } = buildQueue({ isCloud: true, getPlan: async () => ({ slug: "pro" }) });++ await queue.handleUsageEvent(ORG_ID, IdentitiesMeter.key, new Date());++ expect(reportSnapshots).toHaveBeenCalledTimes(1);+ });++ test("self-hosted does not consult the plan slug gate", async () => {+ const { queue, reportSnapshots, getPlan } = buildQueue({ isCloud: false });++ await queue.handleUsageEvent(ORG_ID, IdentitiesMeter.key, new Date());++ expect(getPlan).not.toHaveBeenCalled();+ expect(reportSnapshots).toHaveBeenCalledTimes(1);+ });++ test("skips the internal-CA and certificate meters entirely (before any plan lookup)", async () => {+ const { queue, reportSnapshots, getPlan } = buildQueue({ isCloud: true });++ await queue.handleUsageEvent(ORG_ID, InternalCas.key, new Date());+ await queue.handleUsageEvent(ORG_ID, ActiveCerts.key, new Date());++ expect(getPlan).not.toHaveBeenCalled();+ expect(reportSnapshots).not.toHaveBeenCalled();+ });+test("skips the report when the count is unchanged", async () => {const keyStore = createFakeKeyStore();keyStore.store.set(`license-usage-last-reported-${ORG_ID}-${IdentitiesMeter.key}`, "42");