Repository navigation
feat: add DEPLOYMENT_MODE=tenant support #795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0715939
feat: add DEPLOYMENT_MODE=tenant support
2witstudios e852e38
fix: address CodeRabbit review feedback
2witstudios 3d19cdf
fix: make AI rate limits tenant-aware
2witstudios 5c92a71
fix: address CodeRabbit review — fix test mismatch and update stale c…
2witstudios File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
apps/web/src/lib/subscription/__tests__/rate-limit-middleware.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { describe, it, expect, vi, afterEach } from 'vitest'; | ||
| import { requiresProSubscription } from '../rate-limit-middleware'; | ||
|
|
||
| describe('Rate Limit Middleware', () => { | ||
| describe('requiresProSubscription()', () => { | ||
| afterEach(() => { | ||
| vi.unstubAllEnvs(); | ||
| }); | ||
|
|
||
| it('should not require pro subscription in tenant mode', () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'tenant'); | ||
| expect(requiresProSubscription('pagespace', 'pro-model', 'free')).toBe(false); | ||
| }); | ||
|
|
||
| it('should not require pro subscription in onprem mode', () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'onprem'); | ||
| expect(requiresProSubscription('pagespace', 'pro-model', 'free')).toBe(false); | ||
| }); | ||
|
|
||
| it('should not require pro subscription for non-pro model in cloud mode', () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'cloud'); | ||
| expect(requiresProSubscription('pagespace', undefined, 'free')).toBe(false); | ||
| }); | ||
|
|
||
| it('should require pro subscription for pro model with free tier in cloud mode', () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'cloud'); | ||
| expect(requiresProSubscription('pagespace', 'glm-5', 'free')).toBe(true); | ||
| }); | ||
|
|
||
| it('should not require pro subscription for business tier in cloud mode', () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'cloud'); | ||
| expect(requiresProSubscription('pagespace', 'some-model', 'business')).toBe(false); | ||
| }); | ||
|
|
||
| it('should not require pro subscription for pro tier in cloud mode', () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'cloud'); | ||
| expect(requiresProSubscription('pagespace', 'some-model', 'pro')).toBe(false); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; | ||
|
|
||
| describe('deployment-mode', () => { | ||
| beforeEach(() => { | ||
| vi.unstubAllEnvs(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.unstubAllEnvs(); | ||
| }); | ||
|
|
||
| // Dynamic import to pick up env changes per test | ||
| async function loadModule() { | ||
| vi.resetModules(); | ||
| return import('../deployment-mode'); | ||
| } | ||
|
|
||
| describe('isTenantMode', () => { | ||
| it('given DEPLOYMENT_MODE=tenant, should return true', async () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'tenant'); | ||
| const { isTenantMode } = await loadModule(); | ||
| expect(isTenantMode()).toBe(true); | ||
| }); | ||
|
|
||
| it('given DEPLOYMENT_MODE=cloud, should return false', async () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'cloud'); | ||
| const { isTenantMode } = await loadModule(); | ||
| expect(isTenantMode()).toBe(false); | ||
| }); | ||
|
|
||
| it('given DEPLOYMENT_MODE=onprem, should return false', async () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'onprem'); | ||
| const { isTenantMode } = await loadModule(); | ||
| expect(isTenantMode()).toBe(false); | ||
| }); | ||
|
|
||
| it('given DEPLOYMENT_MODE is unset, should return false', async () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', ''); | ||
| const { isTenantMode } = await loadModule(); | ||
| expect(isTenantMode()).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('isCloud', () => { | ||
| it('given DEPLOYMENT_MODE=tenant, should return false', async () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'tenant'); | ||
| const { isCloud } = await loadModule(); | ||
| expect(isCloud()).toBe(false); | ||
| }); | ||
|
|
||
| it('given DEPLOYMENT_MODE=cloud, should return true', async () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'cloud'); | ||
| const { isCloud } = await loadModule(); | ||
| expect(isCloud()).toBe(true); | ||
| }); | ||
|
|
||
| it('given DEPLOYMENT_MODE unset, should return true', async () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', ''); | ||
| const { isCloud } = await loadModule(); | ||
| expect(isCloud()).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('isOnPrem', () => { | ||
| it('given DEPLOYMENT_MODE=onprem, should return true', async () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'onprem'); | ||
| const { isOnPrem } = await loadModule(); | ||
| expect(isOnPrem()).toBe(true); | ||
| }); | ||
|
|
||
| it('given DEPLOYMENT_MODE=tenant, should return false', async () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'tenant'); | ||
| const { isOnPrem } = await loadModule(); | ||
| expect(isOnPrem()).toBe(false); | ||
| }); | ||
|
|
||
| it('given DEPLOYMENT_MODE=cloud, should return false', async () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'cloud'); | ||
| const { isOnPrem } = await loadModule(); | ||
| expect(isOnPrem()).toBe(false); | ||
| }); | ||
|
|
||
| it('given DEPLOYMENT_MODE is unset, should return false', async () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', ''); | ||
| const { isOnPrem } = await loadModule(); | ||
| expect(isOnPrem()).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('isBillingEnabled', () => { | ||
| it('given DEPLOYMENT_MODE=tenant, should return false', async () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'tenant'); | ||
| const { isBillingEnabled } = await loadModule(); | ||
| expect(isBillingEnabled()).toBe(false); | ||
| }); | ||
|
|
||
| it('given DEPLOYMENT_MODE=cloud, should return true', async () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'cloud'); | ||
| const { isBillingEnabled } = await loadModule(); | ||
| expect(isBillingEnabled()).toBe(true); | ||
| }); | ||
|
|
||
| it('given DEPLOYMENT_MODE=onprem, should return false', async () => { | ||
| vi.stubEnv('DEPLOYMENT_MODE', 'onprem'); | ||
| const { isBillingEnabled } = await loadModule(); | ||
| expect(isBillingEnabled()).toBe(false); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.