@@ -1556,3 +1556,129 @@ describe("ChatGPT sharing presentation", () => {
15561556 ) . toBe ( false ) ;
15571557 } ) ;
15581558} ) ;
1559+
1560+ describe ( "merged X subscription limits" , ( ) => {
1561+ const checkedAt = "2026-09-03T11:00:00.000Z" ;
1562+ const card = (
1563+ driver : "cursor" | "grok" ,
1564+ email : string | undefined ,
1565+ windows : LimitAccount [ "limits" ] [ "windows" ] ,
1566+ ) : LimitAccount => ( {
1567+ key : `${ driver } :${ email ?? "none" } ` ,
1568+ driver : ProviderDriverKind . make ( driver ) ,
1569+ displayName : null ,
1570+ email,
1571+ plan : undefined ,
1572+ accentColor : undefined ,
1573+ environments : [ ] ,
1574+ sourceLabel : null ,
1575+ redeem : null ,
1576+ limits : { checkedAt, windows } ,
1577+ } ) ;
1578+ const grokWeekly = ( email : string , usedPercent : number ) =>
1579+ card ( "grok" , email , [
1580+ {
1581+ id : "subscription" ,
1582+ kind : "weekly" ,
1583+ label : "Weekly" ,
1584+ usedPercent,
1585+ resetsAt : "2026-09-08T00:00:00.000Z" ,
1586+ } ,
1587+ ] ) ;
1588+ const cursorMerged = ( email : string , withOtherModels = true ) =>
1589+ card (
1590+ "cursor" ,
1591+ email ,
1592+ withOtherModels
1593+ ? [
1594+ { id : "autoPercentUsed" , kind : "weekly" , label : "Cursor Models" , usedPercent : 90 } ,
1595+ { id : "apiPercentUsed" , kind : "monthly" , label : "Other Models" , usedPercent : 12 } ,
1596+ ]
1597+ : [ { id : "autoPercentUsed" , kind : "weekly" , label : "Cursor Models" , usedPercent : 90 } ] ,
1598+ ) ;
1599+
1600+ it ( "keeps one first-party card and Other Models for the same email" , ( ) => {
1601+ const accounts = [ cursorMerged ( " [email protected] " ) , grokWeekly ( "[email protected] " , 40 ) ] ; 1602+ const cursorWindows = accounts [ 0 ] ?. limits . windows ;
1603+ const snapshot = structuredClone ( accounts ) ;
1604+ const pools = collectLimitPools ( accounts , now ) ;
1605+ expect ( accounts ) . toEqual ( snapshot ) ;
1606+ expect ( accounts [ 0 ] ?. limits . windows ) . toBe ( cursorWindows ) ;
1607+ const cursor = pools . find ( ( pool ) => pool . driver === "cursor" ) ;
1608+ const grok = pools . find ( ( pool ) => pool . driver === "grok" ) ;
1609+ expect ( cursor ?. windows . map ( ( window ) => [ window . id , window . usedPercent ] ) ) . toEqual ( [
1610+ [ "apiPercentUsed" , 12 ] ,
1611+ ] ) ;
1612+ expect (
1613+ grok ?. windows . map ( ( window ) => [ window . id , window . usedPercent , window . remainingPercent ] ) ,
1614+ ) . toEqual ( [ [ "subscription" , 40 , 60 ] ] ) ;
1615+ } ) ;
1616+
1617+ it ( "drops the Cursor section when the merged account has no other models" , ( ) => {
1618+ const pools = collectLimitPools (
1619+ [ cursorMerged ( "[email protected] " , false ) , grokWeekly ( "[email protected] " , 40 ) ] , 1620+ now ,
1621+ ) ;
1622+ expect ( pools . map ( ( pool ) => pool . driver ) ) . toEqual ( [ "grok" ] ) ;
1623+ } ) ;
1624+
1625+ it ( "keeps both first-party cards for different emails" , ( ) => {
1626+ const pools = collectLimitPools (
1627+ [ cursorMerged ( "[email protected] " ) , grokWeekly ( "[email protected] " , 40 ) ] , 1628+ now ,
1629+ ) ;
1630+ expect (
1631+ pools . find ( ( pool ) => pool . driver === "cursor" ) ?. windows . map ( ( window ) => window . id ) ,
1632+ ) . toEqual ( [ "autoPercentUsed" , "apiPercentUsed" ] ) ;
1633+ expect ( pools . find ( ( pool ) => pool . driver === "grok" ) ?. windows [ 0 ] ?. usedPercent ) . toBe ( 40 ) ;
1634+ } ) ;
1635+
1636+ it ( "keeps a monthly Cursor card beside a weekly Grok card" , ( ) => {
1637+ const pools = collectLimitPools (
1638+ [
1639+ card ( "cursor" , "[email protected] " , [ 1640+ { id : "autoPercentUsed" , kind : "monthly" , label : "Cursor Models" , usedPercent : 90 } ,
1641+ { id : "apiPercentUsed" , kind : "monthly" , label : "Other Models" , usedPercent : 12 } ,
1642+ ] ) ,
1643+ grokWeekly ( "[email protected] " , 40 ) , 1644+ ] ,
1645+ now ,
1646+ ) ;
1647+ expect (
1648+ pools . find ( ( pool ) => pool . driver === "cursor" ) ?. windows . map ( ( window ) => window . id ) ,
1649+ ) . toEqual ( [ "autoPercentUsed" , "apiPercentUsed" ] ) ;
1650+ expect ( pools . find ( ( pool ) => pool . driver === "grok" ) ?. windows [ 0 ] ?. id ) . toBe ( "subscription" ) ;
1651+ } ) ;
1652+
1653+ it ( "does not join a merged Cursor card with a monthly Grok period" , ( ) => {
1654+ const pools = collectLimitPools (
1655+ [
1656+ cursorMerged ( "[email protected] " ) , 1657+ card ( "grok" , "[email protected] " , [ 1658+ { id : "subscription" , kind : "monthly" , label : "Monthly" , usedPercent : 40 } ,
1659+ ] ) ,
1660+ ] ,
1661+ now ,
1662+ ) ;
1663+ expect (
1664+ pools . find ( ( pool ) => pool . driver === "cursor" ) ?. windows . map ( ( window ) => window . id ) ,
1665+ ) . toEqual ( [ "autoPercentUsed" , "apiPercentUsed" ] ) ;
1666+ expect ( pools . find ( ( pool ) => pool . driver === "grok" ) ?. windows [ 0 ] ?. kind ) . toBe ( "monthly" ) ;
1667+ } ) ;
1668+
1669+ it ( "shows a merged Cursor plan on its own when Grok is signed out" , ( ) => {
1670+ const [ pool ] = collectLimitPools ( [ cursorMerged ( "[email protected] " ) ] , now ) ; 1671+ expect ( pool ?. driver ) . toBe ( "cursor" ) ;
1672+ expect ( pool ?. windows . map ( ( window ) => [ window . id , window . kind ] ) ) . toEqual ( [
1673+ [ "autoPercentUsed" , "weekly" ] ,
1674+ [ "apiPercentUsed" , "monthly" ] ,
1675+ ] ) ;
1676+ } ) ;
1677+
1678+ it ( "leaves a Grok-only weekly card unchanged" , ( ) => {
1679+ const [ pool ] = collectLimitPools ( [ grokWeekly ( "[email protected] " , 40 ) ] , now ) ; 1680+ expect ( pool ?. windows . map ( ( window ) => [ window . id , window . usedPercent ] ) ) . toEqual ( [
1681+ [ "subscription" , 40 ] ,
1682+ ] ) ;
1683+ } ) ;
1684+ } ) ;
0 commit comments