Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

Preserve Server licence access to API and Automate (#8032)

ConnorYohba6d6d420aa6
diff --git a/app/common/src/main/java/stirling/software/common/service/LicenseServiceInterface.java b/app/common/src/main/java/stirling/software/common/service/LicenseServiceInterface.java
index 19387a7410..0c47b98fe5 100644
--- a/app/common/src/main/java/stirling/software/common/service/LicenseServiceInterface.java
+++ b/app/common/src/main/java/stirling/software/common/service/LicenseServiceInterface.java
@@ -20,6 +20,9 @@ public interface LicenseServiceInterface {
*/
boolean isRunningProOrHigher();
+ /** True for an installed Server licence; linked Team feature entitlements do not qualify. */
+ boolean hasServerLicense();
+
/**
* Check if running Enterprise edition.
*
diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/GateDecision.java b/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/GateDecision.java
index 7a4386e997..1b1c5a99f2 100644
--- a/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/GateDecision.java
+++ b/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/GateDecision.java
@@ -16,6 +16,8 @@ public record GateDecision(boolean allowed, Reason reason) {
ENTITLED,
/** Enterprise license permits processing with local-only usage metering. */
ENTERPRISE_LICENSE,
+ /** A Server licence includes direct PDF tool API calls without consuming credits. */
+ SERVER_LICENSE,
FREE_TIER,
/** Entitlement source unreachable — fail open, allow. */
FAIL_OPEN,
diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/InstanceEntitlementGate.java b/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/InstanceEntitlementGate.java
index 71d87bf8c2..d89904dba0 100644
--- a/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/InstanceEntitlementGate.java
+++ b/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/InstanceEntitlementGate.java
@@ -9,7 +9,8 @@ import org.springframework.stereotype.Service;
import stirling.software.common.service.LicenseServiceInterface;
/**
- * Enforces cloud processing allowance and the shared offline deadline; manual tools remain free.
+ * Enforces cloud processing allowance and the shared offline deadline. Manual tools and direct PDF
+ * tool API calls covered by a Server licence do not consume processing credits.
*/
@Service
@Profile("!saas")
@@ -43,6 +44,14 @@ public class InstanceEntitlementGate {
/** Evaluates the gate for a request, resolving live state from the store + cache. */
public GateDecision evaluate(boolean billable) {
+ return evaluate(billable, false);
+ }
+
+ /**
+ * {@code directToolApi} is true only for direct PDF tool API calls, never Processor runs, AI
+ * tools or internally dispatched automation steps.
+ */
+ public GateDecision evaluate(boolean billable, boolean directToolApi) {
if (!properties.isEnabled()) {
return GateDecision.allow(GateDecision.Reason.FLAG_OFF);
}
@@ -52,6 +61,9 @@ public class InstanceEntitlementGate {
if (licenseService.isRunningEE()) {
return GateDecision.allow(GateDecision.Reason.ENTERPRISE_LICENSE);
}
+ if (directToolApi && licenseService.hasServerLicense()) {
+ return GateDecision.allow(GateDecision.Reason.SERVER_LICENSE);
+ }
boolean linked = credentialStore.isLinked();
long freeTierRemaining = linked ? 0L : freeTierUsageService.balance().remainingUnits();
Optional<InstanceEntitlement> entitlement =
diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/InstanceEntitlementInterceptor.java b/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/InstanceEntitlementInterceptor.java
index 8f7b569a4a..4cc502b2c8 100644
--- a/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/InstanceEntitlementInterceptor.java
+++ b/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/InstanceEntitlementInterceptor.java
@@ -40,8 +40,9 @@ import stirling.software.proprietary.security.model.ApiKeyAuthenticationToken;
/**
* Request-time gate + meter for combined billing. {@code preHandle} blocks billable (API / AI /
- * automation) work once the applicable allowance is spent; Enterprise licenses and manual tools
- * pass through. {@code afterCompletion} costs the op and accrues it.
+ * automation) work once the applicable allowance is spent. Manual tools, Enterprise licenses and
+ * direct PDF tool API calls covered by Server licenses pass through. {@code afterCompletion} costs
+ * the op and accrues it unless the Server license includes it.
*
* <p>The ledger follows the gate's own reason rather than re-deriving linked-ness, so the two
* cannot disagree. Only the cloud one sits behind {@code …metering.enabled}: with it off a linked
@@ -102,9 +103,9 @@ public class InstanceEntitlementInterceptor implements HandlerInterceptor {
// rather than after its first tool. It carries no automation header itself (category
// BYPASSED), so it's gated here but metered only via its dispatched sub-steps - keeping
// the BYPASSED meter category avoids double-counting.
- boolean billable =
- category != BillingCategory.BYPASSED || PolicyRunRoutes.matches(request);
- decision = gate.evaluate(billable);
+ boolean policyRun = PolicyRunRoutes.matches(request);
+ boolean billable = category != BillingCategory.BYPASSED || policyRun;
+ decision = gate.evaluate(billable, category == BillingCategory.API && !policyRun);
} catch (RuntimeException e) {
// Fail open: an inability to resolve entitlement (e.g. a DB or SaaS blip) must never
// turn into a hard block on billable work.
@@ -187,6 +188,9 @@ public class InstanceEntitlementInterceptor implements HandlerInterceptor {
}
try {
Object reason = request.getAttribute(ATTR_REASON);
+ if (reason == GateDecision.Reason.SERVER_LICENSE) {
+ return;
+ }
if (reason == GateDecision.Reason.FREE_TIER
|| reason == GateDecision.Reason.ENTERPRISE_LICENSE) {
MeteredOp op = measure(request, UnitCalcPolicy.DEFAULT);
diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/automation/AccountLinkAutomationRunBiller.java b/app/proprietary/src/main/java/stirling/software/proprietary/automation/AccountLinkAutomationRunBiller.java
index ef069f81d3..cd2252f7e4 100644
--- a/app/proprietary/src/main/java/stirling/software/proprietary/automation/AccountLinkAutomationRunBiller.java
+++ b/app/proprietary/src/main/java/stirling/software/proprietary/automation/AccountLinkAutomationRunBiller.java
@@ -19,14 +19,15 @@ import stirling.software.proprietary.billing.DocumentUnitCalculator.FileSize;
import stirling.software.proprietary.billing.UnitCalcPolicy;
/**
- * Charges a client-side Automate run on a linked self-hosted instance: computes the input set's
+ * Charges a client-side automation run on a linked self-hosted instance: computes the input set's
* doc-units with the instance's synced {@link UnitCalcPolicy} and accrues them as {@link
* BillingCategory#AUTOMATION}, exactly as the {@code InstanceEntitlementInterceptor} meters a
* policy's tool sub-steps. Metering is instance-scoped, so no per-user context is needed.
*
- * <p>Metering itself is optional (the {@link UsageMeterService} bean is absent when {@code
- * metering.enabled=false}); a null signature is passed so each run is its own charge (the
- * standalone semantic - no workflow-window dedup).
+ * <p>A Server license includes Automate runs; Processor runs still consume credits. Metering itself
+ * is optional (the {@link UsageMeterService} bean is absent when {@code metering.enabled=false}); a
+ * null signature is passed so each run is its own charge (the standalone semantic - no
+ * workflow-window dedup).
*/
@Slf4j
@Component
@@ -48,8 +49,10 @@ public class AccountLinkAutomationRunBiller implements AutomationRunBiller {
}
@Override
- public void recordAutomationRun(List<FileSize> inputs) {
- if (inputs.isEmpty() || licenseService.isRunningEE()) {
+ public void recordAutomationRun(List<FileSize> inputs, AutomationRunSource source) {
+ if (inputs.isEmpty()
+ || licenseService.isRunningEE()
+ || (source == AutomationRunSource.AUTOMATE && licenseService.hasServerLicense())) {
return;
}
UsageMeterService meter = meterProvider.getIfAvailable();
diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/automation/AutomationMeterController.java b/app/proprietary/src/main/java/stirling/software/proprietary/automation/AutomationMeterController.java
index 5bb34dd6d9..8a81d39e2f 100644
--- a/app/proprietary/src/main/java/stirling/software/proprietary/automation/AutomationMeterController.java
+++ b/app/proprietary/src/main/java/stirling/software/proprietary/automation/AutomationMeterController.java
@@ -73,7 +73,9 @@ public class AutomationMeterController {
AutomationRunBiller runBiller = biller.getIfAvailable();
if (runBiller != null) {
try {
- runBiller.recordAutomationRun(inputs);
+ runBiller.recordAutomationRun(
+ inputs,
+ body.source() == null ? AutomationRunSource.PROCESSOR : body.source());
} catch (RuntimeException e) {
log.warn(
"[automate meter] billing failed; the run already completed unbilled: {}",
@@ -119,9 +121,12 @@ public class AutomationMeterController {
return out;
}
- /** Frontend payload: the run's name, its operation ids, and per-input page/byte facts. */
+ /** Frontend run report. An absent source retains Processor billing. */
public record AutomationMeterRequest(
- String automationName, List<String> operations, List<InputDoc> inputs) {}
+ String automationName,
+ List<String> operations,
+ List<InputDoc> inputs,
+ AutomationRunSource source) {}
/** One input document's page count (0 for non-PDF / unknown) and byte size. */
public record InputDoc(Integer pages, Long bytes) {}
diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/automation/AutomationRunBiller.java b/app/proprietary/src/main/java/stirling/software/proprietary/automation/AutomationRunBiller.java
index 3641d04942..fb58b636ae 100644
--- a/app/proprietary/src/main/java/stirling/software/proprietary/automation/AutomationRunBiller.java
+++ b/app/proprietary/src/main/java/stirling/software/proprietary/automation/AutomationRunBiller.java
@@ -13,6 +13,6 @@ import stirling.software.proprietary.billing.DocumentUnitCalculator.FileSize;
*/
public interface AutomationRunBiller {
- /** Charge one run over {@code inputs} (page/byte facts of the original input files). */
- void recordAutomationRun(List<FileSize> inputs);
+ /** Charge one run over the original inputs; a missing source retains Processor billing. */
+ void recordAutomationRun(List<FileSize> inputs, AutomationRunSource source);
}
diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/automation/AutomationRunSource.java b/app/proprietary/src/main/java/stirling/software/proprietary/automation/AutomationRunSource.java
new file mode 100644
index 0000000000..c2077f0562
--- /dev/null
+++ b/app/proprietary/src/main/java/stirling/software/proprietary/automation/AutomationRunSource.java
@@ -0,0 +1,7 @@
+package stirling.software.proprietary.automation;
+
+/** Distinguishes the existing Automate tool from Processor's browser-side work for billing. */
+public enum AutomationRunSource {
+ AUTOMATE,
+ PROCESSOR
+}
diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/security/configuration/ee/DynamicLicenseService.java b/app/proprietary/src/main/java/stirling/software/proprietary/security/configuration/ee/DynamicLicenseService.java
index e227a0685b..3369323ada 100644
--- a/app/proprietary/src/main/java/stirling/software/proprietary/security/configuration/ee/DynamicLicenseService.java
+++ b/app/proprietary/src/main/java/stirling/software/proprietary/security/configuration/ee/DynamicLicenseService.java
@@ -36,6 +36,11 @@ public class DynamicLicenseService implements LicenseServiceInterface {
return license == License.SERVER || license == License.ENTERPRISE;
}
+ @Override
+ public boolean hasServerLicense() {
+ return licenseKeyChecker.getLicenseKeyResult() == License.SERVER;
+ }
+
@Override
public boolean isRunningEE() {
return getCurrentLicense() == License.ENTERPRISE;
diff --git a/app/proprietary/src/test/java/stirling/software/proprietary/accountlink/InstanceEntitlementGateWiringTest.java b/app/proprietary/src/test/java/stirling/software/proprietary/accountlink/InstanceEntitlementGateWiringTest.java
index b8c10629ab..6dee0981de 100644
--- a/app/proprietary/src/test/java/stirling/software/proprietary/accountlink/InstanceEntitlementGateWiringTest.java
+++ b/app/proprietary/src/test/java/stirling/software/proprietary/accountlink/InstanceEntitlementGateWiringTest.java
@@ -201,4 +201,64 @@ class InstanceEntitlementGateWiringTest {
assertEquals(GateDecision.Reason.FLAG_OFF, d.reason());
verify(store, never()).isLinked();
}
+
+ @Test
+ void serverApiDoesNotReadOrConsumeCreditAllowances() {
+ when(licenseChecker.getLicenseKeyResult()).thenReturn(License.SERVER);
+
+ assertEquals(
+ GateDecision.allow(GateDecision.Reason.SERVER_LICENSE), gate.evaluate(true, true));
+ verifyNoInteractions(store, cache, syncState, localUsage, freeTier);
+ }
+
+ @ParameterizedTest
+ @EnumSource(EntitlementState.class)
+ void serverApiRemainsIncludedWhenLinked(EntitlementState state) {
+ when(licenseChecker.getLicenseKeyResult()).thenReturn(License.SERVER);
+ when(store.isLinked()).thenReturn(true);
+ when(cache.current())
+ .thenReturn(Optional.of(new InstanceEntitlement(false, 0, 0, null, state)));
+
+ assertEquals(
+ GateDecision.allow(GateDecision.Reason.SERVER_LICENSE), gate.evaluate(true, true));
+ verifyNoInteractions(store, cache, localUsage, freeTier);
+ }
+
+ @Test
+ void serverProcessorWorkStillRequiresCredits() {
+ when(licenseChecker.getLicenseKeyResult()).thenReturn(License.SERVER);
+ when(freeTier.balance()).thenReturn(grant(0));
+
+ assertEquals(
+ GateDecision.block(GateDecision.Reason.FREE_TIER_EXHAUSTED),
+ gate.evaluate(true, false));
+ }
+
+ @Test
+ void teamAllowanceWithoutServerLicenceDoesNotExemptApi() {
+ when(licenseChecker.premiumTier()).thenReturn(License.SERVER);
+ when(licenseChecker.getLicenseKeyResult()).thenReturn(License.NORMAL);
+ when(store.isLinked()).thenReturn(true);
+ when(cache.current())
+ .thenReturn(
+ Optional.of(
+ new InstanceEntitlement(
+ false, 0, 0, null, EntitlementState.OVER_LIMIT)));
+ when(localUsage.currentPeriodUnsynced())
+ .thenReturn(new LocalUsageService.LocalUsage(null, 0, 0, 0, 0));
+
+ assertEquals(GateDecision.block(GateDecision.Reason.OVER_LIMIT), gate.evaluate(true, true));
+ }
+
+ @Test
+ void expiredServerLicenceRestoresApiCreditEnforcement() {
+ when(licenseChecker.getLicenseKeyResult()).thenReturn(License.SERVER);
+ assertTrue(gate.evaluate(true, true).allowed());
+
+ when(licenseChecker.getLicenseKeyResult()).thenReturn(License.NORMAL);
+ when(freeTier.balance()).thenReturn(grant(0));
+ assertEquals(
+ GateDecision.block(GateDecision.Reason.FREE_TIER_EXHAUSTED),
+ gate.evaluate(true, true));
+ }
}
diff --git a/app/proprietary/src/test/java/stirling/software/proprietary/accountlink/InstanceEntitlementInterceptorTest.java b/app/proprietary/src/test/java/stirling/software/proprietary/accountlink/InstanceEntitlementInterceptorTest.java
index 03b1d0bec5..f68fd12d26 100644
--- a/app/proprietary/src/test/java/stirling/software/proprietary/accountlink/InstanceEntitlementInterceptorTest.java
+++ b/app/proprietary/src/test/java/stirling/software/proprietary/accountlink/InstanceEntitlementInterceptorTest.java
@@ -78,9 +78,57 @@ class InstanceEntitlementInterceptorTest {
new Object());
}
+ @Test
+ void includedServerApiSkipsBothCreditLedgers() throws Exception {
+ when(gate.evaluate(true, true))
+ .thenReturn(GateDecision.allow(GateDecision.Reason.SERVER_LICENSE));
+ authenticateWithApiKey();
+ InstanceEntitlementInterceptor interceptor = interceptor();
+ MockMultipartHttpServletRequest request = fileRequest("/api/v1/general/merge");
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ assertTrue(interceptor.preHandle(request, response, toolHandler()));
+ interceptor.afterCompletion(request, response, toolHandler(), null);
+
+ verifyNoInteractions(
+ meterProvider, freeTierUsageService, entitlementCache, tempFileManager);
+ }
+
+ @ParameterizedTest
+ @ValueSource(
+ strings = {
+ "/api/v1/policies/run",
+ "/api/v1/policies/42/trigger",
+ "/api/v1/ai/tools/summarize"
+ })
+ void processorRoutesCannotUseTheApiLicenceExemption(String path) throws Exception {
+ when(gate.evaluate(true, false))
+ .thenReturn(GateDecision.block(GateDecision.Reason.FREE_TIER_EXHAUSTED));
+ authenticateWithApiKey();
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ assertFalse(
+ interceptor()
+ .preHandle(
+ new MockHttpServletRequest("POST", path), response, toolHandler()));
+ assertEquals(402, response.getStatus());
+ }
+
+ @Test
+ void internalProcessorToolStepCannotUseTheApiLicenceExemption() throws Exception {
+ when(gate.evaluate(true, false))
+ .thenReturn(GateDecision.block(GateDecision.Reason.FREE_TIER_EXHAUSTED));
+ authenticateWithApiKey();
+ MockHttpServletRequest request =
+ new MockHttpServletRequest("POST", "/api/v1/general/merge");
+ request.addHeader("X-Stirling-Automation", "true");
+
+ assertFalse(interceptor().preHandle(request, new MockHttpServletResponse(), toolHandler()));
+ }
+
@Test
void allowsWhenGateAllows() throws Exception {
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.ENTITLED));
MockHttpServletResponse response = new MockHttpServletResponse();
@@ -90,7 +138,7 @@ class InstanceEntitlementInterceptorTest {
@Test
void blocksWith402AndTheTerminalReasonWhenGateBlocks() throws Exception {
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.block(GateDecision.Reason.FREE_TIER_EXHAUSTED));
MockHttpServletResponse response = new MockHttpServletResponse();
@@ -103,7 +151,7 @@ class InstanceEntitlementInterceptorTest {
@Test
void enterpriseProcessingWithoutFilesDoesNotAccrueUsage() throws Exception {
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.ENTERPRISE_LICENSE));
InstanceEntitlementInterceptor interceptor = interceptor();
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/api/v1/ai/tools/x");
@@ -119,7 +167,7 @@ class InstanceEntitlementInterceptorTest {
value = GateDecision.Reason.class,
names = {"FREE_TIER", "ENTERPRISE_LICENSE"})
void metersLocallyWithoutConsultingCloudBilling(GateDecision.Reason reason) throws Exception {
- when(gate.evaluate(anyBoolean())).thenReturn(GateDecision.allow(reason));
+ when(gate.evaluate(anyBoolean(), anyBoolean())).thenReturn(GateDecision.allow(reason));
InstanceEntitlementInterceptor interceptor = interceptor();
MockMultipartHttpServletRequest req = fileRequest("/api/v1/ai/tools/x");
@@ -133,7 +181,7 @@ class InstanceEntitlementInterceptorTest {
@Test
void freeTierAutomationUsesTheSourceDocumentKey() throws Exception {
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.FREE_TIER));
InstanceEntitlementInterceptor interceptor = interceptor();
MockMultipartHttpServletRequest req = fileRequest("/api/v1/general/rotate-pdf");
@@ -151,7 +199,7 @@ class InstanceEntitlementInterceptorTest {
@Test
void freeTierDoesNotMeterFilelessWork() throws Exception {
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.FREE_TIER));
InstanceEntitlementInterceptor interceptor = interceptor();
MockHttpServletRequest req = new MockHttpServletRequest("POST", "/api/v1/ai/tools/x");
@@ -165,7 +213,7 @@ class InstanceEntitlementInterceptorTest {
@Test
void manualToolNeverReachesEitherLedger() throws Exception {
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.MANUAL_FREE));
InstanceEntitlementInterceptor interceptor = interceptor();
@@ -179,7 +227,7 @@ class InstanceEntitlementInterceptorTest {
@Test
void blockedFreeTierRequestAccruesNothing() throws Exception {
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.block(GateDecision.Reason.FREE_TIER_EXHAUSTED));
InstanceEntitlementInterceptor interceptor = interceptor();
@@ -194,7 +242,7 @@ class InstanceEntitlementInterceptorTest {
@Test
void failsOpenWhenGateThrows() throws Exception {
// A DB / SaaS blip while resolving entitlement must never hard-block billable work.
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenThrow(new RuntimeException("entitlement source down"));
MockHttpServletResponse response = new MockHttpServletResponse();
@@ -204,7 +252,7 @@ class InstanceEntitlementInterceptorTest {
@Test
void metersSuccessfulBillableOp() throws Exception {
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.ENTITLED));
UsageMeterService meter = mock(UsageMeterService.class);
when(meterProvider.getIfAvailable()).thenReturn(meter);
@@ -226,7 +274,7 @@ class InstanceEntitlementInterceptorTest {
void doesNotMeterFilelessBillableOp() throws Exception {
// A billable op with no document (no multipart file) is not metered - matching SaaS, which
// short-circuits a request that carries no file.
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.ENTITLED));
UsageMeterService meter = mock(UsageMeterService.class);
when(meterProvider.getIfAvailable()).thenReturn(meter);
@@ -245,7 +293,7 @@ class InstanceEntitlementInterceptorTest {
@Test
void metersPdfByPageCountNotJustBytes(@TempDir Path tmp) throws Exception {
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.ENTITLED));
UsageMeterService meter = mock(UsageMeterService.class);
when(meterProvider.getIfAvailable()).thenReturn(meter);
@@ -277,7 +325,7 @@ class InstanceEntitlementInterceptorTest {
// A standalone op (no run id) has a null key, so identical calls each accrue - matching
// SaaS, which never groups a call outside a run ("charge per API call"). The old
// input-signature window wrongly collapsed these on the instance.
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.ENTITLED));
UsageMeterService meter = mock(UsageMeterService.class);
when(meterProvider.getIfAvailable()).thenReturn(meter);
@@ -300,7 +348,7 @@ class InstanceEntitlementInterceptorTest {
@Test
void doesNotMeterWhenMeteringSwitchOff() throws Exception {
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.ENTITLED));
when(meterProvider.getIfAvailable()).thenReturn(null); // metering.enabled = false
@@ -318,7 +366,7 @@ class InstanceEntitlementInterceptorTest {
void gatesPolicyRunUpFrontEvenWithoutAutomationHeader() throws Exception {
// The policy /run call carries no automation header, but must be blocked up front (not
// after its first tool) when the allowance is spent.
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.block(GateDecision.Reason.FREE_TIER_EXHAUSTED));
InstanceEntitlementInterceptor interceptor = interceptor();
@@ -329,14 +377,14 @@ class InstanceEntitlementInterceptorTest {
assertFalse(interceptor.preHandle(req, resp, new Object()));
assertEquals(HttpStatus.PAYMENT_REQUIRED.value(), resp.getStatus());
assertTrue(resp.getContentAsString().contains("ACCOUNT_LINK_REQUIRED"));
- verify(gate).evaluate(true); // gated as billable despite no automation header
+ verify(gate).evaluate(true, false); // gated as billable despite no automation header
}
@Test
void doesNotMeterThePolicyRunEndpointItself() throws Exception {
// Gated up front, but metered only via its dispatched tool sub-steps (category BYPASSED
// here), so the /run request itself never accrues usage.
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.ENTITLED));
InstanceEntitlementInterceptor interceptor = interceptor();
@@ -351,7 +399,7 @@ class InstanceEntitlementInterceptorTest {
@Test
void billsApiKeyToolCallAsApi() throws Exception {
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.ENTITLED));
UsageMeterService meter = mock(UsageMeterService.class);
when(meterProvider.getIfAvailable()).thenReturn(meter);
@@ -373,7 +421,7 @@ class InstanceEntitlementInterceptorTest {
void doesNotBillApiKeyCallToNonToolEndpoint() throws Exception {
// Matches SaaS: an API-key call to a non-tool endpoint (no @AutoJobPostMapping) is not
// billed. Only tool operations count as API usage.
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.ENTITLED));
authenticateWithApiKey();
@@ -389,7 +437,7 @@ class InstanceEntitlementInterceptorTest {
@Test
void policyRunSubStepsAccrueUnderTheSharedRunId() throws Exception {
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.ENTITLED));
UsageMeterService meter = mock(UsageMeterService.class);
when(meterProvider.getIfAvailable()).thenReturn(meter);
@@ -456,7 +504,7 @@ class InstanceEntitlementInterceptorTest {
// be
// able to group its separate calls into one charge: the run id keys the meter only on a
// genuine internal dispatch, so here the op falls back to its standalone null key.
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.ENTITLED));
UsageMeterService meter = mock(UsageMeterService.class);
when(meterProvider.getIfAvailable()).thenReturn(meter);
@@ -481,7 +529,7 @@ class InstanceEntitlementInterceptorTest {
// own
// key: the meter collapses a document's steps but bills the documents separately (matching
// SaaS per-document lineage), rather than collapsing the whole run to a single charge.
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.ENTITLED));
UsageMeterService meter = mock(UsageMeterService.class);
when(meterProvider.getIfAvailable()).thenReturn(meter);
diff --git a/app/proprietary/src/test/java/stirling/software/proprietary/accountlink/PolicyAutomationBillingDbTest.java b/app/proprietary/src/test/java/stirling/software/proprietary/accountlink/PolicyAutomationBillingDbTest.java
index 126fc1bd70..ebe6d52fcc 100644
--- a/app/proprietary/src/test/java/stirling/software/proprietary/accountlink/PolicyAutomationBillingDbTest.java
+++ b/app/proprietary/src/test/java/stirling/software/proprietary/accountlink/PolicyAutomationBillingDbTest.java
@@ -92,7 +92,7 @@ class PolicyAutomationBillingDbTest {
interceptor =
new InstanceEntitlementInterceptor(
gate, entitlementCache, meterProvider, freeTierUsageService, tempFiles);
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.ENTITLED));
when(meterProvider.getIfAvailable())
.thenReturn(
diff --git a/app/proprietary/src/test/java/stirling/software/proprietary/automation/AccountLinkAutomationRunBillerTest.java b/app/proprietary/src/test/java/stirling/software/proprietary/automation/AccountLinkAutomationRunBillerTest.java
index 392b9bc6ff..bf3841557f 100644
--- a/app/proprietary/src/test/java/stirling/software/proprietary/automation/AccountLinkAutomationRunBillerTest.java
+++ b/app/proprietary/src/test/java/stirling/software/proprietary/automation/AccountLinkAutomationRunBillerTest.java
@@ -21,9 +21,77 @@ import stirling.software.proprietary.accountlink.UsageMeterService;
import stirling.software.proprietary.billing.BillingCategory;
import stirling.software.proprietary.billing.DocumentUnitCalculator.FileSize;
import stirling.software.proprietary.billing.UnitCalcPolicy;
+import stirling.software.proprietary.security.configuration.ee.DynamicLicenseService;
+import stirling.software.proprietary.security.configuration.ee.KeygenLicenseVerifier.License;
+import stirling.software.proprietary.security.configuration.ee.LicenseKeyChecker;
class AccountLinkAutomationRunBillerTest {
+ @Test
+ void serverAutomateDoesNotReadCloudStateOrAccrueCredits() {
+ EntitlementCache cache = mock(EntitlementCache.class);
+ UsageMeterService meter = mock(UsageMeterService.class);
+ LicenseServiceInterface license = mock(LicenseServiceInterface.class);
+ when(license.hasServerLicense()).thenReturn(true);
+ AccountLinkAutomationRunBiller biller =
+ new AccountLinkAutomationRunBiller(cache, providerOf(meter), license);
+
+ biller.recordAutomationRun(List.of(new FileSize(25, 5000L)), AutomationRunSource.AUTOMATE);
+
+ org.mockito.Mockito.verifyNoInteractions(cache, meter);
+ }
+
+ @Test
+ void serverProcessorAndUnspecifiedRunsStillAccrueCredits() {
+ EntitlementCache cache = mock(EntitlementCache.class);
+ when(cache.current()).thenReturn(Optional.of(entitlement(POLICY, PERIOD)));
+ UsageMeterService meter = mock(UsageMeterService.class);
+ LicenseServiceInterface license = mock(LicenseServiceInterface.class);
+ when(license.hasServerLicense()).thenReturn(true);
+ AccountLinkAutomationRunBiller biller =
+ new AccountLinkAutomationRunBiller(cache, providerOf(meter), license);
+
+ biller.recordAutomationRun(List.of(new FileSize(25, 5000L)), AutomationRunSource.PROCESSOR);
+ biller.recordAutomationRun(List.of(new FileSize(25, 5000L)), null);
+
+ verify(meter, org.mockito.Mockito.times(2))
+ .accrue(PERIOD, BillingCategory.AUTOMATION, 3L, null);
+ }
+
+ @Test
+ void teamWithoutServerLicenceStillPaysForAutomate() {
+ EntitlementCache cache = mock(EntitlementCache.class);
+ when(cache.current()).thenReturn(Optional.of(entitlement(POLICY, PERIOD)));
+ UsageMeterService meter = mock(UsageMeterService.class);
+ LicenseKeyChecker checker = mock(LicenseKeyChecker.class);
+ when(checker.premiumTier()).thenReturn(License.SERVER);
+ when(checker.getLicenseKeyResult()).thenReturn(License.NORMAL);
+ AccountLinkAutomationRunBiller biller =
+ new AccountLinkAutomationRunBiller(
+ cache, providerOf(meter), new DynamicLicenseService(checker));
+
+ biller.recordAutomationRun(List.of(new FileSize(25, 5000L)), AutomationRunSource.AUTOMATE);
+
+ verify(meter).accrue(PERIOD, BillingCategory.AUTOMATION, 3L, null);
+ }
+
+ @Test
+ void removingServerLicenceRestoresAutomateBilling() {
+ EntitlementCache cache = mock(EntitlementCache.class);
+ when(cache.current()).thenReturn(Optional.of(entitlement(POLICY, PERIOD)));
+ UsageMeterService meter = mock(UsageMeterService.class);
+ LicenseServiceInterface license = mock(LicenseServiceInterface.class);
+ AccountLinkAutomationRunBiller biller =
+ new AccountLinkAutomationRunBiller(cache, providerOf(meter), license);
+ when(license.hasServerLicense()).thenReturn(true);
+ biller.recordAutomationRun(List.of(new FileSize(25, 5000L)), AutomationRunSource.AUTOMATE);
+ org.mockito.Mockito.verifyNoInteractions(cache, meter);
+
+ when(license.hasServerLicense()).thenReturn(false);
+ biller.recordAutomationRun(List.of(new FileSize(25, 5000L)), AutomationRunSource.AUTOMATE);
+ verify(meter).accrue(PERIOD, BillingCategory.AUTOMATION, 3L, null);
+ }
+
private static final UnitCalcPolicy POLICY = new UnitCalcPolicy(10, 1_000_000L, 1, 1000);
private static final LocalDateTime PERIOD = LocalDateTime.of(2026, 9, 1, 0, 0);
@@ -37,10 +105,10 @@ class AccountLinkAutomationRunBillerTest {
AccountLinkAutomationRunBiller biller =
new AccountLinkAutomationRunBiller(cache, providerOf(meter), license);
List<FileSize> inputs = List.of(new FileSize(25, 5000L));
- biller.recordAutomationRun(inputs);
+ biller.recordAutomationRun(inputs, AutomationRunSource.PROCESSOR);
org.mockito.Mockito.verifyNoInteractions(cache, meter);
when(license.isRunningEE()).thenReturn(false);
- biller.recordAutomationRun(inputs);
+ biller.recordAutomationRun(inputs, AutomationRunSource.PROCESSOR);
verify(meter).accrue(PERIOD, BillingCategory.AUTOMATION, 3L, null);
}
@@ -66,7 +134,7 @@ class AccountLinkAutomationRunBillerTest {
cache, providerOf(meter), mock(LicenseServiceInterface.class));
// 25 pages -> ceil(25/10)=3 page units; 5000 bytes -> 1 byte unit; max = 3.
- biller.recordAutomationRun(List.of(new FileSize(25, 5000L)));
+ biller.recordAutomationRun(List.of(new FileSize(25, 5000L)), AutomationRunSource.PROCESSOR);
verify(meter).accrue(PERIOD, BillingCategory.AUTOMATION, 3L, null);
}
@@ -78,7 +146,7 @@ class AccountLinkAutomationRunBillerTest {
new AccountLinkAutomationRunBiller(
cache, providerOf(null), mock(LicenseServiceInterface.class));
- biller.recordAutomationRun(List.of(new FileSize(1, 10L)));
+ biller.recordAutomationRun(List.of(new FileSize(1, 10L)), AutomationRunSource.PROCESSOR);
verify(cache, never()).current();
}
@@ -92,7 +160,7 @@ class AccountLinkAutomationRunBillerTest {
new AccountLinkAutomationRunBiller(
cache, providerOf(meter), mock(LicenseServiceInterface.class));
- biller.recordAutomationRun(List.of(new FileSize(1, 10L)));
+ biller.recordAutomationRun(List.of(new FileSize(1, 10L)), AutomationRunSource.PROCESSOR);
verify(meter, never())
.accrue(
@@ -113,8 +181,8 @@ class AccountLinkAutomationRunBillerTest {
new AccountLinkAutomationRunBiller(
cache, providerOf(meter), mock(LicenseServiceInterface.class));
- biller.recordAutomationRun(List.of(new FileSize(1, 10L)));
- biller.recordAutomationRun(List.of(new FileSize(1, 10L)));
+ biller.recordAutomationRun(List.of(new FileSize(1, 10L)), AutomationRunSource.PROCESSOR);
+ biller.recordAutomationRun(List.of(new FileSize(1, 10L)), AutomationRunSource.PROCESSOR);
verify(meter, never())
.accrue(
@@ -132,7 +200,7 @@ class AccountLinkAutomationRunBillerTest {
new AccountLinkAutomationRunBiller(
cache, providerOf(meter), mock(LicenseServiceInterface.class));
- biller.recordAutomationRun(List.of());
+ biller.recordAutomationRun(List.of(), AutomationRunSource.PROCESSOR);
verify(cache, never()).current();
}
diff --git a/app/proprietary/src/test/java/stirling/software/proprietary/automation/AutomationMeterControllerTest.java b/app/proprietary/src/test/java/stirling/software/proprietary/automation/AutomationMeterControllerTest.java
index 5190a613d7..512b2f230f 100644
--- a/app/proprietary/src/test/java/stirling/software/proprietary/automation/AutomationMeterControllerTest.java
+++ b/app/proprietary/src/test/java/stirling/software/proprietary/automation/AutomationMeterControllerTest.java
@@ -2,6 +2,7 @@ package stirling.software.proprietary.automation;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -31,7 +32,39 @@ class AutomationMeterControllerTest {
}
private static AutomationMeterRequest req(List<InputDoc> inputs) {
- return new AutomationMeterRequest("My run", List.of("compress", "rotate"), inputs);
+ return new AutomationMeterRequest("My run", List.of("compress", "rotate"), inputs, null);
+ }
+
+ @Test
+ void forwardsAutomateSourceWithoutUsingItsDisplayName() {
+ AutomationRunBiller biller = mock(AutomationRunBiller.class);
+ AutomationMeterController controller = new AutomationMeterController(providerOf(biller));
+
+ controller.meterAutomationRun(
+ new AutomationMeterRequest(
+ "Classification",
+ List.of(),
+ List.of(new InputDoc(3, 1000L)),
+ AutomationRunSource.AUTOMATE),
+ new MockHttpServletRequest());
+
+ verify(biller)
+ .recordAutomationRun(List.of(new FileSize(3, 1000L)), AutomationRunSource.AUTOMATE);
+ }
+
+ @Test
+ void automateDisplayNameDoesNotExemptUnspecifiedSource() {
+ AutomationRunBiller biller = mock(AutomationRunBiller.class);
+ AutomationMeterController controller = new AutomationMeterController(providerOf(biller));
+
+ controller.meterAutomationRun(
+ new AutomationMeterRequest(
+ "Automate", List.of(), List.of(new InputDoc(3, 1000L)), null),
+ new MockHttpServletRequest());
+
+ verify(biller)
+ .recordAutomationRun(
+ List.of(new FileSize(3, 1000L)), AutomationRunSource.PROCESSOR);
}
@Test
@@ -46,7 +79,7 @@ class AutomationMeterControllerTest {
assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
ArgumentCaptor<List<FileSize>> captor = ArgumentCaptor.forClass(List.class);
- verify(biller).recordAutomationRun(captor.capture());
+ verify(biller).recordAutomationRun(captor.capture(), eq(AutomationRunSource.PROCESSOR));
assertEquals(List.of(new FileSize(3, 1000L), new FileSize(0, 2048L)), captor.getValue());
assertEquals("My run", http.getAttribute(AuditContext.REQ_ATTR_POLICY_NAME));
assertEquals(
@@ -62,7 +95,9 @@ class AutomationMeterControllerTest {
var response = controller.meterAutomationRun(req(List.of()), new MockHttpServletRequest());
assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
- verify(biller, never()).recordAutomationRun(org.mockito.ArgumentMatchers.anyList());
+ verify(biller, never())
+ .recordAutomationRun(
+ org.mockito.ArgumentMatchers.anyList(), eq(AutomationRunSource.PROCESSOR));
}
@Test
@@ -73,7 +108,9 @@ class AutomationMeterControllerTest {
var response = controller.meterAutomationRun(null, new MockHttpServletRequest());
assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
- verify(biller, never()).recordAutomationRun(org.mockito.ArgumentMatchers.anyList());
+ verify(biller, never())
+ .recordAutomationRun(
+ org.mockito.ArgumentMatchers.anyList(), eq(AutomationRunSource.PROCESSOR));
}
@Test
@@ -92,7 +129,8 @@ class AutomationMeterControllerTest {
AutomationRunBiller biller = mock(AutomationRunBiller.class);
org.mockito.Mockito.doThrow(new RuntimeException("boom"))
.when(biller)
- .recordAutomationRun(org.mockito.ArgumentMatchers.anyList());
+ .recordAutomationRun(
+ org.mockito.ArgumentMatchers.anyList(), eq(AutomationRunSource.PROCESSOR));
AutomationMeterController controller = new AutomationMeterController(providerOf(biller));
var response =
@@ -110,10 +148,10 @@ class AutomationMeterControllerTest {
List<InputDoc> many =
IntStream.range(0, 10_050).mapToObj(i -> new InputDoc(-5, -1L)).toList();
controller.meterAutomationRun(
- new AutomationMeterRequest(null, null, many), new MockHttpServletRequest());
+ new AutomationMeterRequest(null, null, many, null), new MockHttpServletRequest());
ArgumentCaptor<List<FileSize>> captor = ArgumentCaptor.forClass(List.class);
- verify(biller).recordAutomationRun(captor.capture());
+ verify(biller).recordAutomationRun(captor.capture(), eq(AutomationRunSource.PROCESSOR));
List<FileSize> billed = captor.getValue();
assertEquals(10_000, billed.size());
assertTrue(billed.stream().allMatch(f -> f.pages() == 0 && f.bytes() == 0L));
diff --git a/app/saas/src/main/java/stirling/software/saas/config/SaasLicenseOverride.java b/app/saas/src/main/java/stirling/software/saas/config/SaasLicenseOverride.java
index ff7f6b9633..a75df89919 100644
--- a/app/saas/src/main/java/stirling/software/saas/config/SaasLicenseOverride.java
+++ b/app/saas/src/main/java/stirling/software/saas/config/SaasLicenseOverride.java
@@ -20,6 +20,11 @@ public class SaasLicenseOverride implements LicenseServiceInterface {
return true;
}
+ @Override
+ public boolean hasServerLicense() {
+ return false;
+ }
+
@Override
public boolean isRunningEE() {
return true;
diff --git a/app/saas/src/main/java/stirling/software/saas/payg/charge/SaasAutomationRunBiller.java b/app/saas/src/main/java/stirling/software/saas/payg/charge/SaasAutomationRunBiller.java
index b1d85197c0..8010287206 100644
--- a/app/saas/src/main/java/stirling/software/saas/payg/charge/SaasAutomationRunBiller.java
+++ b/app/saas/src/main/java/stirling/software/saas/payg/charge/SaasAutomationRunBiller.java
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Component;
import lombok.RequiredArgsConstructor;
import stirling.software.proprietary.automation.AutomationRunBiller;
+import stirling.software.proprietary.automation.AutomationRunSource;
import stirling.software.proprietary.billing.DocumentUnitCalculator;
import stirling.software.proprietary.billing.DocumentUnitCalculator.FileSize;
import stirling.software.proprietary.billing.UnitCalcPolicy;
@@ -38,7 +39,7 @@ public class SaasAutomationRunBiller implements AutomationRunBiller {
private final JobChargeService jobChargeService;
@Override
- public void recordAutomationRun(List<FileSize> inputs) {
+ public void recordAutomationRun(List<FileSize> inputs, AutomationRunSource source) {
if (inputs.isEmpty()) {
return;
}
@@ -56,13 +57,13 @@ public class SaasAutomationRunBiller implements AutomationRunBiller {
policy.getFileUnitCap());
int units = DocumentUnitCalculator.unitsForGroup(inputs, unitCalc);
- JobSource source =
+ JobSource jobSource =
auth instanceof ApiKeyAuthenticationToken ? JobSource.API : JobSource.WEB;
ChargeContext ctx =
new ChargeContext(
user.getId(),
user.getTeam().getId(),
- source,
+ jobSource,
ProcessType.AUTOMATION,
BillingCategory.AUTOMATION);
// chargeStandalone re-resolves the effective policy and applies its minChargeUnits floor.
diff --git a/app/saas/src/test/java/stirling/software/saas/payg/charge/SaasAutomationRunBillerTest.java b/app/saas/src/test/java/stirling/software/saas/payg/charge/SaasAutomationRunBillerTest.java
index b6aea045ae..7620eb4fae 100644
--- a/app/saas/src/test/java/stirling/software/saas/payg/charge/SaasAutomationRunBillerTest.java
+++ b/app/saas/src/test/java/stirling/software/saas/payg/charge/SaasAutomationRunBillerTest.java
@@ -11,10 +11,13 @@ import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
import org.mockito.ArgumentCaptor;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
+import stirling.software.proprietary.automation.AutomationRunSource;
import stirling.software.proprietary.billing.DocumentUnitCalculator.FileSize;
import stirling.software.proprietary.model.Team;
import stirling.software.proprietary.security.database.repository.UserRepository;
@@ -62,15 +65,16 @@ class SaasAutomationRunBillerTest {
SecurityContextHolder.getContext().setAuthentication(auth);
}
- @Test
- void chargesComputedUnitsAsWebAutomation() {
+ @ParameterizedTest
+ @EnumSource(AutomationRunSource.class)
+ void chargesComputedUnitsAsWebAutomation(AutomationRunSource source) {
User user = userWithTeam(3L, 7L);
authenticateAs(mock(Authentication.class), user);
PricingPolicy policy = policy();
when(pricingPolicyService.getEffectivePolicy(7L)).thenReturn(policy);
// 25 pages -> ceil(25/10)=3 page units; 5000 bytes -> 1 byte unit; max = 3.
- biller.recordAutomationRun(List.of(new FileSize(25, 5000L)));
+ biller.recordAutomationRun(List.of(new FileSize(25, 5000L)), source);
ArgumentCaptor<ChargeContext> ctx = ArgumentCaptor.forClass(ChargeContext.class);
verify(jobChargeService).chargeStandalone(ctx.capture(), eq(3));
@@ -88,7 +92,7 @@ class SaasAutomationRunBillerTest {
PricingPolicy policy = policy();
when(pricingPolicyService.getEffectivePolicy(7L)).thenReturn(policy);
- biller.recordAutomationRun(List.of(new FileSize(1, 10L)));
+ biller.recordAutomationRun(List.of(new FileSize(1, 10L)), AutomationRunSource.PROCESSOR);
ArgumentCaptor<ChargeContext> ctx = ArgumentCaptor.forClass(ChargeContext.class);
verify(jobChargeService).chargeStandalone(ctx.capture(), eq(1));
@@ -101,7 +105,7 @@ class SaasAutomationRunBillerTest {
when(user.getTeam()).thenReturn(null);
authenticateAs(mock(Authentication.class), user);
- biller.recordAutomationRun(List.of(new FileSize(1, 10L)));
+ biller.recordAutomationRun(List.of(new FileSize(1, 10L)), AutomationRunSource.PROCESSOR);
verify(jobChargeService, never())
.chargeStandalone(
@@ -110,7 +114,7 @@ class SaasAutomationRunBillerTest {
@Test
void noChargeForEmptyInputs() {
- biller.recordAutomationRun(List.of());
+ biller.recordAutomationRun(List.of(), AutomationRunSource.PROCESSOR);
verify(jobChargeService, never())
.chargeStandalone(
diff --git a/app/saas/src/test/java/stirling/software/saas/payg/filter/PaygBillingParityTest.java b/app/saas/src/test/java/stirling/software/saas/payg/filter/PaygBillingParityTest.java
index 09f378a643..ed93b5ea3a 100644
--- a/app/saas/src/test/java/stirling/software/saas/payg/filter/PaygBillingParityTest.java
+++ b/app/saas/src/test/java/stirling/software/saas/payg/filter/PaygBillingParityTest.java
@@ -212,7 +212,7 @@ class PaygBillingParityTest {
// Self-hosted: the run id is the meter's dedup key, so the sub-steps collapse.
InstanceEntitlementGate gate = mock(InstanceEntitlementGate.class);
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.ENTITLED));
EntitlementCache cache = mock(EntitlementCache.class);
UsageMeterService meter = mock(UsageMeterService.class);
@@ -308,7 +308,7 @@ class PaygBillingParityTest {
private void assertSelfHosted(Op op) throws Exception {
InstanceEntitlementGate gate = mock(InstanceEntitlementGate.class);
- when(gate.evaluate(anyBoolean()))
+ when(gate.evaluate(anyBoolean(), anyBoolean()))
.thenReturn(GateDecision.allow(GateDecision.Reason.ENTITLED));
EntitlementCache cache = mock(EntitlementCache.class);
UsageMeterService meter = mock(UsageMeterService.class);
diff --git a/frontend/editor/src/core/hooks/tools/automate/useAutomateOperation.ts b/frontend/editor/src/core/hooks/tools/automate/useAutomateOperation.ts
index 82205c52d1..7e4ce4baae 100644
--- a/frontend/editor/src/core/hooks/tools/automate/useAutomateOperation.ts
+++ b/frontend/editor/src/core/hooks/tools/automate/useAutomateOperation.ts
@@ -68,6 +68,7 @@ export function useAutomateOperation() {
bytes: file.size ?? 0,
}));
meterAutomationRun({
+ source: "AUTOMATE",
automationName: automationConfig.name,
operations: automationConfig.operations.map(
(operation) => operation.operation,
diff --git a/frontend/editor/src/core/services/automationMeter.ts b/frontend/editor/src/core/services/automationMeter.ts
index 59f86adcb9..dd60c61fbe 100644
--- a/frontend/editor/src/core/services/automationMeter.ts
+++ b/frontend/editor/src/core/services/automationMeter.ts
@@ -7,6 +7,8 @@ export interface AutomationMeterInput {
}
export interface AutomationMeterPayload {
+ /** Only the existing Automate tool is included in a self-hosted Server licence. */
+ source?: "AUTOMATE" | "PROCESSOR";
automationName?: string;
operations?: string[];
inputs: AutomationMeterInput[];