11import { beforeEach , describe , expect , it , vi } from "vitest" ;
22
3- const hasValidLicense = vi . fn ( ) ;
43const getWebServerSettings = vi . fn ( ) ;
5- const findFirstOrg = vi . fn ( ) ;
64const findFirstServer = vi . fn ( ) ;
75
86vi . mock ( "@dokploy/server/db" , ( ) => ( {
97 db : {
108 query : {
11- organization : {
12- findFirst : ( ...args : unknown [ ] ) => findFirstOrg ( ...args ) ,
13- } ,
149 server : {
1510 findFirst : ( ...args : unknown [ ] ) => findFirstServer ( ...args ) ,
1611 } ,
@@ -19,91 +14,56 @@ vi.mock("@dokploy/server/db", () => ({
1914} ) ) ;
2015
2116vi . mock ( "@dokploy/server/db/schema" , ( ) => ( {
22- organization : { } ,
2317 server : { } ,
2418} ) ) ;
2519
26- vi . mock ( "@dokploy/server/services/proprietary/license-key" , ( ) => ( {
27- hasValidLicense : ( ...args : unknown [ ] ) => hasValidLicense ( ...args ) ,
28- } ) ) ;
29-
3020vi . mock ( "@dokploy/server/services/web-server-settings" , ( ) => ( {
3121 getWebServerSettings : ( ...args : unknown [ ] ) => getWebServerSettings ( ...args ) ,
3222} ) ) ;
3323
3424vi . mock ( "drizzle-orm" , ( ) => ( { eq : vi . fn ( ) } ) ) ;
3525
36- import {
37- assertBuildsConcurrencyAllowed ,
38- resolveBuildsConcurrency ,
39- } from "../../server/queues/concurrency" ;
26+ import { resolveBuildsConcurrency } from "../../server/queues/concurrency" ;
4027import { LOCAL_PARTITION } from "../../server/queues/in-memory-queue" ;
4128
42- describe ( "resolveBuildsConcurrency (enterprise gating) " , ( ) => {
29+ describe ( "resolveBuildsConcurrency" , ( ) => {
4330 beforeEach ( ( ) => {
4431 vi . clearAllMocks ( ) ;
45- findFirstOrg . mockResolvedValue ( { id : "org-1" } ) ;
4632 } ) ;
4733
4834 describe ( "local web server partition" , ( ) => {
49- it ( "returns the configured concurrency when licensed " , async ( ) => {
35+ it ( "returns the configured concurrency" , async ( ) => {
5036 getWebServerSettings . mockResolvedValue ( { buildsConcurrency : 5 } ) ;
51- hasValidLicense . mockResolvedValue ( true ) ;
5237
5338 await expect ( resolveBuildsConcurrency ( LOCAL_PARTITION ) ) . resolves . toBe ( 5 ) ;
5439 } ) ;
5540
56- it ( "clamps to the free max (2) when there is no valid license" , async ( ) => {
57- getWebServerSettings . mockResolvedValue ( { buildsConcurrency : 10 } ) ;
58- hasValidLicense . mockResolvedValue ( false ) ;
59-
60- await expect ( resolveBuildsConcurrency ( LOCAL_PARTITION ) ) . resolves . toBe ( 2 ) ;
61- } ) ;
62-
63- it ( "allows the free max (2) without a license" , async ( ) => {
64- getWebServerSettings . mockResolvedValue ( { buildsConcurrency : 2 } ) ;
65- hasValidLicense . mockResolvedValue ( false ) ;
66-
67- await expect ( resolveBuildsConcurrency ( LOCAL_PARTITION ) ) . resolves . toBe ( 2 ) ;
68- } ) ;
69-
70- it ( "does not cap the value when licensed (N allowed)" , async ( ) => {
41+ it ( "does not cap high values" , async ( ) => {
7142 getWebServerSettings . mockResolvedValue ( { buildsConcurrency : 999 } ) ;
72- hasValidLicense . mockResolvedValue ( true ) ;
7343
7444 await expect ( resolveBuildsConcurrency ( LOCAL_PARTITION ) ) . resolves . toBe (
7545 999 ,
7646 ) ;
7747 } ) ;
7848
49+ it ( "floors values below 1 to 1" , async ( ) => {
50+ getWebServerSettings . mockResolvedValue ( { buildsConcurrency : 0 } ) ;
51+
52+ await expect ( resolveBuildsConcurrency ( LOCAL_PARTITION ) ) . resolves . toBe ( 1 ) ;
53+ } ) ;
54+
7955 it ( "defaults to 1 when settings are missing" , async ( ) => {
8056 getWebServerSettings . mockResolvedValue ( undefined ) ;
81- hasValidLicense . mockResolvedValue ( true ) ;
8257
8358 await expect ( resolveBuildsConcurrency ( LOCAL_PARTITION ) ) . resolves . toBe ( 1 ) ;
8459 } ) ;
8560 } ) ;
8661
8762 describe ( "remote server partition" , ( ) => {
88- it ( "returns the server concurrency when its org is licensed" , async ( ) => {
89- findFirstServer . mockResolvedValue ( {
90- buildsConcurrency : 4 ,
91- organizationId : "org-1" ,
92- } ) ;
93- hasValidLicense . mockResolvedValue ( true ) ;
63+ it ( "returns the server concurrency" , async ( ) => {
64+ findFirstServer . mockResolvedValue ( { buildsConcurrency : 4 } ) ;
9465
9566 await expect ( resolveBuildsConcurrency ( "server-1" ) ) . resolves . toBe ( 4 ) ;
96- expect ( hasValidLicense ) . toHaveBeenCalledWith ( "org-1" ) ;
97- } ) ;
98-
99- it ( "clamps to the free max (2) when the server org is not licensed" , async ( ) => {
100- findFirstServer . mockResolvedValue ( {
101- buildsConcurrency : 8 ,
102- organizationId : "org-1" ,
103- } ) ;
104- hasValidLicense . mockResolvedValue ( false ) ;
105-
106- await expect ( resolveBuildsConcurrency ( "server-1" ) ) . resolves . toBe ( 2 ) ;
10767 } ) ;
10868
10969 it ( "defaults to 1 for an unknown server" , async ( ) => {
@@ -119,30 +79,3 @@ describe("resolveBuildsConcurrency (enterprise gating)", () => {
11979 await expect ( resolveBuildsConcurrency ( LOCAL_PARTITION ) ) . resolves . toBe ( 1 ) ;
12080 } ) ;
12181} ) ;
122-
123- describe ( "assertBuildsConcurrencyAllowed" , ( ) => {
124- beforeEach ( ( ) => {
125- vi . clearAllMocks ( ) ;
126- } ) ;
127-
128- it ( "allows up to the free max (2) without checking the license" , async ( ) => {
129- await expect (
130- assertBuildsConcurrencyAllowed ( 2 , "org-1" ) ,
131- ) . resolves . toBeUndefined ( ) ;
132- expect ( hasValidLicense ) . not . toHaveBeenCalled ( ) ;
133- } ) ;
134-
135- it ( "allows more than 2 when licensed" , async ( ) => {
136- hasValidLicense . mockResolvedValue ( true ) ;
137- await expect (
138- assertBuildsConcurrencyAllowed ( 5 , "org-1" ) ,
139- ) . resolves . toBeUndefined ( ) ;
140- } ) ;
141-
142- it ( "rejects more than 2 without a license" , async ( ) => {
143- hasValidLicense . mockResolvedValue ( false ) ;
144- await expect ( assertBuildsConcurrencyAllowed ( 3 , "org-1" ) ) . rejects . toThrow (
145- / e n t e r p r i s e l i c e n s e / i,
146- ) ;
147- } ) ;
148- } ) ;
0 commit comments