fix(cloud): ENTITLEMENTS-A seat bounds stay plan policy (drop the duplicate max_seats entitlement)

This commit is contained in:
Neil
2026-11-11 22:14:49 -08:00
parent ec8cfe5dac
commit 4ec3b71798
3 changed files with 7 additions and 14 deletions
+1 -2
View File
@@ -22,8 +22,7 @@
"max_concurrent_sandboxes": { "value": 3, "perSeat": true },
"max_concurrent_sandboxes_per_member": { "value": 3 },
"machine_sizes": { "value": ["standard", "large"] },
"overage_allowed": { "value": true },
"max_seats": { "value": 500 }
"overage_allowed": { "value": true }
},
"policy": {
"paymentGraceHours": 96,
+3 -7
View File
@@ -12,8 +12,7 @@ export const ENTITLEMENT_KEYS = [
'max_concurrent_sandboxes',
'max_concurrent_sandboxes_per_member',
'machine_sizes',
'overage_allowed',
'max_seats'
'overage_allowed'
] as const
export type EntitlementKey = (typeof ENTITLEMENT_KEYS)[number]
@@ -28,8 +27,7 @@ export const ENTITLEMENT_REGISTRY: Record<EntitlementKey, { schema: z.ZodType; a
max_concurrent_sandboxes: { schema: NonNegativeInt, aggregate: 'sum', perSeatAllowed: true },
max_concurrent_sandboxes_per_member: { schema: NonNegativeInt, aggregate: 'max', perSeatAllowed: false },
machine_sizes: { schema: z.array(z.enum(MACHINE_SIZES)).max(MACHINE_SIZES.length), aggregate: 'union', perSeatAllowed: false },
overage_allowed: { schema: z.boolean(), aggregate: 'or', perSeatAllowed: false },
max_seats: { schema: NonNegativeInt, aggregate: 'max', perSeatAllowed: false }
overage_allowed: { schema: z.boolean(), aggregate: 'or', perSeatAllowed: false }
}
export function isEntitlementKey(value: string): value is EntitlementKey {
@@ -64,7 +62,6 @@ export type EffectiveValues = {
maxConcurrentSandboxesPerMember: number
machineSizes: MachineSize[]
overageAllowed: boolean
maxSeats: number
}
/** Combines grant values by each key's rule. Per-seat values multiply by max(1, seats). */
@@ -101,7 +98,6 @@ export function aggregateGrants(grants: readonly GrantValue[]): EffectiveValues
maxConcurrentSandboxesPerMember: maxes.max_concurrent_sandboxes_per_member ?? 0,
// Registry order, so the list is stable whatever order grants came in.
machineSizes: MACHINE_SIZES.filter((size) => sizes.has(size)),
overageAllowed: overage,
maxSeats: maxes.max_seats ?? 0
overageAllowed: overage
}
}
+3 -5
View File
@@ -74,7 +74,7 @@ describe('catalog', () => {
}
expect(() => parseCatalogFile(withEntitlement('gpu_hours', { value: 1 }))).toThrow(/unknown entitlement key/)
expect(() => parseCatalogFile(withEntitlement('sandbox_hours_monthly', { value: 'lots' }))).toThrow(/invalid value/)
expect(() => parseCatalogFile(withEntitlement('max_seats', { value: 5, perSeat: true }))).toThrow(/cannot be per seat/)
expect(() => parseCatalogFile(withEntitlement('max_concurrent_sandboxes_per_member', { value: 5, perSeat: true }))).toThrow(/cannot be per seat/)
expect(() => parseCatalogFile(withEntitlement('machine_sizes', { value: ['huge'] }))).toThrow(/invalid value/)
const noPolicy = repoCatalog()
noPolicy.plans[0]!.versions[0]!.policy = {}
@@ -111,8 +111,7 @@ describe('aggregation', () => {
maxConcurrentSandboxes: 3,
maxConcurrentSandboxesPerMember: 5,
machineSizes: ['standard', 'large'],
overageAllowed: true,
maxSeats: 0
overageAllowed: true
})
})
})
@@ -125,7 +124,6 @@ describe('subscription grants (ENTITLEMENTS_MODE=on)', () => {
{ entitlement_key: 'machine_sizes', value_json: '["standard","large"]', per_seat: 0, seat_quantity: null, state: 'active', hold_reason: null, ends_at: null, revoked_reason: null, plan_version: 1 },
{ entitlement_key: 'max_concurrent_sandboxes', value_json: '3', per_seat: 1, seat_quantity: 2, state: 'active', hold_reason: null, ends_at: null, revoked_reason: null, plan_version: 1 },
{ entitlement_key: 'max_concurrent_sandboxes_per_member', value_json: '3', per_seat: 0, seat_quantity: null, state: 'active', hold_reason: null, ends_at: null, revoked_reason: null, plan_version: 1 },
{ entitlement_key: 'max_seats', value_json: '500', per_seat: 0, seat_quantity: null, state: 'active', hold_reason: null, ends_at: null, revoked_reason: null, plan_version: 1 },
{ entitlement_key: 'overage_allowed', value_json: 'true', per_seat: 0, seat_quantity: null, state: 'active', hold_reason: null, ends_at: null, revoked_reason: null, plan_version: 1 },
{ entitlement_key: 'sandbox_hours_monthly', value_json: '60', per_seat: 1, seat_quantity: 2, state: 'active', hold_reason: null, ends_at: null, revoked_reason: null, plan_version: 1 }
])
@@ -138,7 +136,7 @@ describe('subscription grants (ENTITLEMENTS_MODE=on)', () => {
canStartSandbox: true
})
const audit = h.raw.prepare("SELECT action, actor FROM entitlement_audit WHERE source_type = 'subscription'").all()
expect(audit).toHaveLength(6)
expect(audit).toHaveLength(5)
expect(audit[0]).toEqual({ action: 'grant', actor: 'stripe_webhook' })
})