modelProviderCodingPlan.test.ts 257 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345
  1. import * as enterpriseProductsHook from "@/settings/model-provider-section/useEnterpriseCodingPlanProducts.js";
  2. import { createElement, type ReactElement } from "react";
  3. import { type ProviderSettingsFormProvider } from "@/lib/providerSettingsFormTypes.js";
  4. import { renderToStaticMarkup } from "react-dom/server";
  5. import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
  6. import {
  7. BIGMODEL_PROVIDER_ID,
  8. BUILTIN_MODEL_PROVIDER_IDS,
  9. getModelProviderFamilySpec,
  10. ZAI_PROVIDER_ID,
  11. TID_MODEL_PROVIDER_ADD_MODEL_BUTTON,
  12. TID_MODEL_PROVIDER_MODEL_DELETE_BUTTON,
  13. type UsageEntitlementSnapshot,
  14. } from "@zcode/shared";
  15. import {
  16. resolveCodingPlanProviderSyncAttemptKey,
  17. shouldRetryUnchangedCodingPlanProviderSync,
  18. resolveModelProviderSideSelectionKey,
  19. } from "@/settings/ModelProviderSection.js";
  20. import {
  21. beginCodingPlanUpgradeLogin,
  22. isCodingPlanPurchaseAuthPending,
  23. closeAndRefreshCodingPlanUpgradeFromWebview,
  24. refreshCodingPlanUpgradeCompletion,
  25. resolvePendingCodingPlanUpgradeAfterLogin,
  26. } from "@/settings/CodingPlanUpgradeDialog.js";
  27. import {
  28. refreshModelProviderSection,
  29. refreshProviderPanelAfterAuthChange,
  30. } from "@/settings/model-provider-section/modelProviderActions.js";
  31. import { resolveCodingPlanStatusPanelViewState } from "@/settings/model-provider-section/codingPlanStatusPanelViewState.js";
  32. import {
  33. ModelProviderSectionDetail,
  34. resolveEnterprisePurchaseChoiceBannerPrice,
  35. resolvePurchaseChoiceBannerProductsProviderId,
  36. resolvePurchaseChoiceBannerPrice,
  37. resolveEnterpriseTeamPlanBannerClass,
  38. resolveEnterpriseTeamPlanBannerDescriptionId,
  39. resolveEnterpriseTeamPlanBannerIconClass,
  40. resolvePurchaseChoiceSelectionIntent,
  41. resolveTeamScopedPlanNavItem,
  42. resolveTeamPlanInspectionAccess,
  43. } from "@/settings/model-provider-section/Detail.js";
  44. import { resolveCodingPlanEntitlementState } from "@/settings/model-provider-section/providerFamilyConnectionVisibility.js";
  45. import { groupEnterpriseCodingPlanProductsByTier } from "@/settings/model-provider-section/codingPlanEnterpriseTiers.js";
  46. import {
  47. ModelProviderSectionNavigation,
  48. resolveModelProviderSideNavLabel,
  49. } from "@/settings/model-provider-section/Navigation.js";
  50. import {
  51. resolveProviderConnectionApiFormatDisplayLabel,
  52. resolveProviderConnectionApiFormatOptions,
  53. } from "@/settings/model-provider-section/ProviderCardSections.js";
  54. import {
  55. buildProviderFamilyConnectionOptions,
  56. ProviderFamilyPlanModeSwitch,
  57. } from "@/settings/model-provider-section/ProviderFamilyModeHeader.js";
  58. import { resolveCodingPlanUpgradeProductsProviderId } from "@/settings/model-provider-section/codingPlanPricingCards.js";
  59. import { CodingPlanUpgradeAction } from "@/settings/model-provider-section/CodingPlanStatusActions.js";
  60. import {
  61. formatStartPlanEffectiveDate,
  62. formatStartPlanExpireDate,
  63. resolvePendingStartPlanEffectiveTime,
  64. } from "@/settings/model-provider-section/CodingPlanStatusMeta.js";
  65. import { ConversationQuotaBanner } from "@/v4/ConversationQuotaBanner.js";
  66. import enUS from "@/i18n/locales/en-US.js";
  67. import { StartPlanCard } from "@/settings/model-provider-section/StartPlanCard.js";
  68. import {
  69. CodingPlanStatusPanel,
  70. hasStartPlanEntitlementQuota,
  71. resolveCodingPlanStatusCardTitle,
  72. } from "@/settings/model-provider-section/StatusCards.js";
  73. import {
  74. resolveFallbackModelProviderNodeKey,
  75. resolveSelectedFamilyModeNodeKey,
  76. connectionSelectionMatchesNavigationItem,
  77. useModelProviderNavigation,
  78. } from "@/settings/model-provider-section/useModelProviderNavigation.js";
  79. import {
  80. clearStartPlanPreviewCacheForTest,
  81. primeStartPlanPreviewCacheForTest,
  82. } from "@/settings/model-provider-section/useStartPlanPreview.js";
  83. import { type ModelProviderNavGroup } from "@/settings/model-provider-section/constants.js";
  84. import type { ModelProviderNavItem } from "@/settings/model-provider-section/constants.js";
  85. import type { ProviderSettingsView } from "@zcode/services";
  86. it("Start 独立后移除套餐数量快捷入口与切换按钮", () => {
  87. const item = (
  88. presetId:
  89. | typeof BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan
  90. | typeof BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  91. ): ModelProviderNavItem => ({
  92. key: `coding-plan:${presetId}`,
  93. type: "codingPlan",
  94. presetId,
  95. oauthProviderId: ZAI_PROVIDER_ID,
  96. label: presetId,
  97. providerName: "Z.AI",
  98. provider: null,
  99. status: "purchased",
  100. statusActive: true,
  101. });
  102. const start = item(BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan);
  103. const coding = item(BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan);
  104. const render = (selectedNavItem: ModelProviderNavItem, count: number, failed = false) =>
  105. renderWithTooltipProvider(
  106. createElement(ProviderFamilyPlanModeSwitch, {
  107. selectedNavItem,
  108. navigationItems: [start, coding],
  109. startPlanSubscriptionCount: count,
  110. connectionSettingsFailed: failed,
  111. onSelectNavItem: vi.fn(),
  112. }),
  113. );
  114. expect(render(coding, 2)).not.toContain('data-testid="model-provider-start-plan-count-shortcut"');
  115. // 数量不再驱动切换入口,也不保留旧快捷入口的文案与标签。
  116. expect(render(coding, 2)).not.toContain("Start Plan × 2");
  117. expect(render(coding, 2)).not.toContain('aria-label="Switch to Start Plan"');
  118. expect(render(coding, 2)).not.toContain("lucide-tickets");
  119. expect(render(coding, 2)).not.toContain('data-testid="model-provider-start-plan-switch-prefix"');
  120. expect(render(start, 2)).not.toContain('data-testid="model-provider-start-plan-count-shortcut"');
  121. expect(render(coding, 0)).not.toContain('data-testid="model-provider-start-plan-count-shortcut"');
  122. expect(render(coding, 2, true)).not.toContain(
  123. 'data-testid="model-provider-start-plan-count-shortcut"',
  124. );
  125. });
  126. it("付费下拉按完整保存选择显示团队,不读取复制的个人 current", () => {
  127. const provider = createProvider({ id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan });
  128. provider.accountState = { availability: "available", entitled: true, current: false };
  129. const coding = {
  130. key: "coding",
  131. type: "codingPlan",
  132. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  133. oauthProviderId: BIGMODEL_PROVIDER_ID,
  134. label: "个人",
  135. providerName: "BigModel",
  136. provider,
  137. status: "purchased",
  138. statusActive: false,
  139. } as ModelProviderNavItem;
  140. const team = {
  141. ...coding,
  142. key: "team",
  143. type: "teamPlan",
  144. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
  145. teamPlanName: "测试团队",
  146. organizationId: "org",
  147. projectId: "project",
  148. currentProductId: "product",
  149. } as ModelProviderNavItem;
  150. const selection = {
  151. kind: "team-coding-plan" as const,
  152. organizationId: "org",
  153. projectId: "project",
  154. productId: "product",
  155. };
  156. const render = (organizationId: string, navigationItems = [coding, team]) =>
  157. renderWithTooltipProvider(
  158. createElement(ProviderFamilyPlanModeSwitch, {
  159. selectedNavItem: team,
  160. navigationItems,
  161. connectionSelections: { bigmodel: { ...selection, organizationId } },
  162. onSelectNavItem: vi.fn(),
  163. }),
  164. );
  165. expect(render("org")).not.toContain('data-placeholder=""');
  166. expect(render("wrong-org")).toContain("settings.modelProvider.codingPlan.purchase.selectPlan");
  167. expect(render("wrong-org")).toContain("data-placeholder");
  168. expect(render("org", [team])).not.toContain(
  169. 'data-testid="model-provider-connection-mode-trigger"',
  170. );
  171. });
  172. it("旧 Start 连接下,唯一未选中的个人套餐仍提供显式选择入口", () => {
  173. const provider = createProvider({ id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan });
  174. provider.accountState = { availability: "available", entitled: true, current: false };
  175. const coding: ModelProviderNavItem = {
  176. key: `coding-plan:${provider.providerId}`,
  177. type: "codingPlan",
  178. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  179. oauthProviderId: BIGMODEL_PROVIDER_ID,
  180. label: "个人套餐",
  181. providerName: "BigModel",
  182. provider,
  183. status: "purchased",
  184. statusActive: false,
  185. };
  186. const html = renderWithTooltipProvider(
  187. createElement(ProviderFamilyPlanModeSwitch, {
  188. selectedNavItem: coding,
  189. navigationItems: [coding],
  190. onSelectNavItem: vi.fn(),
  191. }),
  192. );
  193. expect(html).toContain('data-testid="model-provider-connection-mode-trigger"');
  194. expect(html).toContain("data-placeholder");
  195. });
  196. import {
  197. CODING_PLAN_BILLING_DISCOUNT_DIALOG_BODY_CLASS,
  198. CODING_PLAN_BILLING_DISCOUNT_DIALOG_CONTENT_CLASS,
  199. clearCodingPlanBillingDiscountCacheForTest,
  200. CodingPlanBillingDiscountBadge,
  201. CodingPlanBillingDiscountBadgePill,
  202. CodingPlanBillingDiscountBanner,
  203. primeCodingPlanBillingDiscountCacheForTest,
  204. resolveCodingPlanBillingDiscountCopy,
  205. } from "@/CodingPlanBillingDiscount.js";
  206. import zhCN from "@/i18n/locales/zh-CN.js";
  207. import { TooltipProvider } from "@/components/ui/tooltip.js";
  208. const intlMockState = vi.hoisted(() => ({ locale: "en-US" }));
  209. function renderWithTooltipProvider(element: ReactElement) {
  210. return renderToStaticMarkup(createElement(TooltipProvider, null, element));
  211. }
  212. vi.mock("@/i18n/IntlProvider.js", () => ({
  213. useZCodeIntl: () => ({
  214. locale: intlMockState.locale,
  215. intl: {
  216. formatMessage: (descriptor: { id: string }, values?: Record<string, string>) => {
  217. const isZh = intlMockState.locale.toLowerCase().startsWith("zh");
  218. let message =
  219. (isZh
  220. ? {
  221. "settings.modelProvider.startPlan.meta.today": "Today",
  222. "settings.modelProvider.startPlan.meta.tomorrow": "Tomorrow",
  223. "settings.modelProvider.startPlan.balance.used": "已用 {value}",
  224. "settings.modelProvider.startPlan.preview.unit.tokens": "tokens",
  225. "settings.modelProvider.startPlan.preview.period.daily": "{unit}/日",
  226. "settings.modelProvider.startPlan.preview.entitlementSummary.daily":
  227. "每日额度 · {details}",
  228. "settings.modelProvider.startPlan.preview.entitlementSummary.generic":
  229. "额度 · {details}",
  230. "settings.modelProvider.startPlan.preview.entitlementGroup.single":
  231. "{model} {quota}",
  232. "settings.modelProvider.startPlan.preview.entitlementGroup.each":
  233. "{models} 各{quota}",
  234. "settings.modelProvider.codingPlan.purchase.fromPrice": "{price} 起",
  235. "settings.modelProvider.codingPlan.purchase.fromPriceSuffix": "起",
  236. "settings.modelProvider.codingPlan.purchaseBanner.startPlanTitle": "体验套餐",
  237. "settings.modelProvider.connectionMode.startPlanCount": "体验套餐 × {count}",
  238. "settings.modelProvider.connectionMode.switchToStartPlan": "切换至体验套餐",
  239. "settings.modelProvider.codingPlan.enterprise.tier.lite": "基础版",
  240. "settings.modelProvider.codingPlan.enterprise.tier.pro": "标准版",
  241. "settings.modelProvider.codingPlan.enterprise.tier.max": "高级版",
  242. }
  243. : {
  244. "settings.modelProvider.startPlan.meta.today": "Today",
  245. "settings.modelProvider.startPlan.meta.tomorrow": "Tomorrow",
  246. "settings.modelProvider.startPlan.balance.used": "Used {value}",
  247. "settings.modelProvider.startPlan.preview.unit.tokens": "tokens",
  248. "settings.modelProvider.startPlan.preview.period.daily": "{unit} per day",
  249. "settings.modelProvider.startPlan.preview.entitlementSummary.daily":
  250. "Daily quota · {details}",
  251. "settings.modelProvider.startPlan.preview.entitlementSummary.generic":
  252. "Quota · {details}",
  253. "settings.modelProvider.startPlan.preview.entitlementGroup.single":
  254. "{model} {quota}",
  255. "settings.modelProvider.startPlan.preview.entitlementGroup.each":
  256. "{models} {quota} each",
  257. "settings.modelProvider.codingPlan.purchase.fromPrice": "{price}+",
  258. "settings.modelProvider.codingPlan.purchase.fromPriceSuffix": "",
  259. "settings.modelProvider.codingPlan.purchaseBanner.startPlanTitle": "Start Plan",
  260. "settings.modelProvider.connectionMode.startPlanCount": "Start Plan × {count}",
  261. "settings.modelProvider.connectionMode.switchToStartPlan": "Switch to Start Plan",
  262. "settings.modelProvider.codingPlan.enterprise.tier.lite": "Lite",
  263. "settings.modelProvider.codingPlan.enterprise.tier.pro": "Pro",
  264. "settings.modelProvider.codingPlan.enterprise.tier.max": "Max",
  265. })[descriptor.id] ?? descriptor.id;
  266. for (const [key, value] of Object.entries(values ?? {})) {
  267. message = message.replace(`{${key}}`, value);
  268. }
  269. if (values?.date && !message.includes(values.date)) {
  270. message = `${message} ${values.date}`;
  271. }
  272. return message;
  273. },
  274. },
  275. }),
  276. }));
  277. vi.mock("@/hooks/usePlatform.js", () => ({
  278. useOptionalPlatform: () => ({
  279. openExternal: vi.fn(),
  280. }),
  281. usePlatform: () => ({
  282. openExternal: vi.fn(),
  283. }),
  284. }));
  285. vi.mock("@/hooks/useServices.js", () => ({
  286. useServices: () => ({}),
  287. useOptionalServices: () => null,
  288. }));
  289. vi.mock("@/settings/CodingPlanUpgradeDialogProvider.js", () => ({
  290. useOptionalCodingPlanUpgradeDialog: () => null,
  291. useCodingPlanUpgradeDialog: () => ({
  292. openCodingPlanUpgrade: vi.fn(),
  293. }),
  294. }));
  295. beforeEach(() => {
  296. clearStartPlanPreviewCacheForTest();
  297. clearCodingPlanBillingDiscountCacheForTest();
  298. intlMockState.locale = "en-US";
  299. });
  300. afterEach(() => {
  301. vi.useRealTimers();
  302. });
  303. type LegacyProviderOverrides = Partial<ProviderSettingsFormProvider> & {
  304. id?: string;
  305. name?: string;
  306. apiKey?: string;
  307. apiKeyUrl?: string;
  308. apiFormat?: "anthropic-messages" | "openai-chat-completions" | "openai-responses";
  309. endpoints?: { baseURL?: string; paths?: Record<string, string> };
  310. models?: unknown[];
  311. systemDisabledReason?: string;
  312. updatedAt?: number;
  313. };
  314. function createModelProviderModelConfig(input: {
  315. id: string;
  316. builtin?: boolean;
  317. contextWindow?: number;
  318. maxOutputTokens?: number;
  319. supportsTools?: boolean;
  320. supportsJsonSchemaOutput?: boolean;
  321. kinds?: string[];
  322. defaultKind?: string;
  323. }): ProviderSettingsFormProvider["models"][number] {
  324. const maxOutputTokens = input.maxOutputTokens;
  325. const config = {
  326. properties: {
  327. requiresMfjsToolSchema: false,
  328. contextWindow: input.contextWindow ?? 200_000,
  329. inputFormat: {
  330. supportsText: true,
  331. supportsImage: false,
  332. supportsVideo: false,
  333. supportsAudio: false,
  334. supportsPdf: false,
  335. },
  336. outputFormat: { supportsText: true },
  337. supportsToolCall: input.supportsTools ?? true,
  338. supportsJsonSchemaOutput: input.supportsJsonSchemaOutput ?? true,
  339. supportsNativeWebSearch: false,
  340. supportsMidConversationSystem: false,
  341. },
  342. optionSpecs:
  343. maxOutputTokens === undefined
  344. ? {}
  345. : {
  346. maxOutputTokens: {
  347. max: maxOutputTokens,
  348. },
  349. },
  350. };
  351. return {
  352. kind: "candidate",
  353. modelId: input.id,
  354. builtin: input.builtin ?? false,
  355. personalConfig: structuredClone(config),
  356. hasPersonalConfig: true,
  357. executable: true,
  358. selectable: true,
  359. config,
  360. };
  361. }
  362. function createProvider(overrides: LegacyProviderOverrides = {}): ProviderSettingsFormProvider {
  363. const providerId =
  364. overrides.providerId ?? overrides.id ?? BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan;
  365. const accountAccess = (() => {
  366. const family = providerId.includes("bigmodel") ? "bigmodel" : "zai";
  367. if (providerId.includes("start-plan")) {
  368. return {
  369. type: "zhipu-account" as const,
  370. family,
  371. mode: "start-plan" as const,
  372. entitled: true,
  373. };
  374. }
  375. if (providerId.includes("team-coding-plan")) {
  376. return {
  377. type: "zhipu-account" as const,
  378. family,
  379. mode: "team-coding-plan" as const,
  380. entitled: true,
  381. };
  382. }
  383. if (providerId.includes("individual-coding-plan")) {
  384. return {
  385. type: "zhipu-account" as const,
  386. family,
  387. mode: "individual-coding-plan" as const,
  388. entitled: true,
  389. };
  390. }
  391. return null;
  392. })();
  393. const legacyModels = overrides.models ?? ["glm-5"];
  394. const hasPersonalConfig =
  395. overrides.hasPersonalConfig ?? overrides.config?.group === "standard-personal";
  396. const models = legacyModels.map((model) => {
  397. if (typeof model === "object" && model !== null && "modelId" in model && "config" in model) {
  398. return model as ProviderSettingsFormProvider["models"][number];
  399. }
  400. if (typeof model === "string") {
  401. // Settings View 总会提供 Personal 空覆盖;不完整模型也应遵循完整 DTO 外壳。
  402. return {
  403. kind: "candidate" as const,
  404. modelId: model,
  405. builtin: !hasPersonalConfig,
  406. config: {},
  407. personalConfig: {},
  408. hasPersonalConfig: false,
  409. executable: false,
  410. selectable: false,
  411. };
  412. }
  413. throw new Error("测试 Provider models 只接受当前 candidate 或 modelId 字符串");
  414. });
  415. return {
  416. providerId,
  417. executable: overrides.selectable ?? overrides.enabled !== false,
  418. enabled: overrides.enabled ?? true,
  419. hasPersonalConfig,
  420. personalConfig: hasPersonalConfig
  421. ? {
  422. group: "standard-personal",
  423. personalModelIds: models.map((model) => model.modelId),
  424. enabled: overrides.enabled ?? true,
  425. }
  426. : {},
  427. providerName: overrides.name ?? overrides.providerName ?? "Z.ai",
  428. config: {
  429. group:
  430. overrides.config?.group ??
  431. (providerId.includes("bigmodel") ? "bigmodel-family" : "zai-family"),
  432. access: accountAccess ?? {
  433. type: "api-key",
  434. apiKey: overrides.apiKey ?? "sk-demo",
  435. ...(overrides.apiKeyUrl ? { apiKeyManagementUrl: overrides.apiKeyUrl } : {}),
  436. },
  437. api: {
  438. type: overrides.apiFormat ?? overrides.config?.api?.type ?? "openai-chat-completions",
  439. baseUrl:
  440. overrides.endpoints?.baseURL ??
  441. overrides.config?.api?.baseUrl ??
  442. "https://example.com/openai",
  443. },
  444. ...(hasPersonalConfig
  445. ? { personalModelIds: models.map((model) => model.modelId) }
  446. : { builtinModelIds: models.map((model) => model.modelId) }),
  447. enabled: overrides.enabled ?? true,
  448. ...overrides.config,
  449. },
  450. models,
  451. };
  452. }
  453. function createProviderSettingsView(provider: ProviderSettingsFormProvider): ProviderSettingsView {
  454. return {
  455. revision: 17,
  456. addableProviders: [],
  457. providerOrder: [provider.providerId],
  458. providers: [
  459. {
  460. providerId: provider.providerId,
  461. providerName: provider.providerName,
  462. enabled: provider.enabled,
  463. executable: provider.executable,
  464. effectiveBuiltinConfig: structuredClone(provider.config),
  465. personalConfig: structuredClone(provider.personalConfig),
  466. effectiveConfig: structuredClone(provider.config),
  467. issues: provider.issues ?? [],
  468. models: provider.models.map((model) => ({
  469. kind: "candidate" as const,
  470. modelId: model.modelId,
  471. builtin: model.builtin ?? true,
  472. effectiveBuiltinConfig: structuredClone(model.inheritedConfig ?? model.config),
  473. ...(model.hasPersonalConfig
  474. ? { personalExactConfig: structuredClone(model.personalConfig) }
  475. : {}),
  476. effectiveConfig: structuredClone(model.config),
  477. enabled: model.config.enabled !== false,
  478. executable: model.executable ?? true,
  479. selectable: model.selectable ?? true,
  480. issues: model.issues ?? [],
  481. })),
  482. },
  483. ],
  484. };
  485. }
  486. function renderDetail(
  487. selectedNavItem: Parameters<typeof ModelProviderSectionDetail>[0]["selectedNavItem"],
  488. overrides: Partial<Parameters<typeof ModelProviderSectionDetail>[0]> = {},
  489. ) {
  490. return renderToStaticMarkup(
  491. createElement(ModelProviderSectionDetail, {
  492. selectedNavItem,
  493. activeWorkspacePath: null,
  494. presetLoading: false,
  495. officialLoginProviderId: null,
  496. presetSubscriptionProviderId: null,
  497. codingPlanStatusSyncProviderId: null,
  498. codingPlanDisconnectProviderId: null,
  499. onSave: vi.fn(),
  500. onDelete: vi.fn(async () => {}),
  501. onTestModel: vi.fn(async () => ({ results: [] })),
  502. onOfficialLogin: vi.fn(async () => {}),
  503. onCodingPlanLogin: vi.fn(async () => {}),
  504. onCodingPlanDisconnect: vi.fn(),
  505. onOpenPresetApiKey: vi.fn(),
  506. onOpenApiKeyUrl: vi.fn(),
  507. onOpenBigModelRegistration: vi.fn(),
  508. onCodingPlanPurchaseComplete: vi.fn(),
  509. codingPlanPurchaseTokenAuthenticatedByProviderId: {},
  510. ...overrides,
  511. }),
  512. );
  513. }
  514. function expectConnectionApiFormatVisible(html: string): void {
  515. expect(html).toMatch(/<label[^>]*>settings\.modelProvider\.apiFormat<\/label>/);
  516. }
  517. function expectConnectionApiFormatHidden(html: string): void {
  518. expect(html).not.toMatch(/<label[^>]*>settings\.modelProvider\.apiFormat<\/label>/);
  519. }
  520. function createEntitlementSnapshot(
  521. overrides: Partial<UsageEntitlementSnapshot> = {},
  522. ): UsageEntitlementSnapshot {
  523. return {
  524. generatedAt: 1,
  525. authenticated: true,
  526. provider: {
  527. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  528. name: "BigModel - Coding Plan",
  529. },
  530. remaining: {
  531. count: 100,
  532. isShow: true,
  533. percentage: 0.2,
  534. nextResetTime: 1_779_000_000_000,
  535. },
  536. subscription: {
  537. identityType: "unknown",
  538. identityMasked: null,
  539. details: [
  540. {
  541. productId: "pro",
  542. productName: "Pro",
  543. purchaseTime: null,
  544. beginTime: null,
  545. billingCycle: "monthly",
  546. renewTime: null,
  547. expireTime: "2026-12-31T00:00:00.000Z",
  548. },
  549. ],
  550. },
  551. quota: {
  552. level: "pro",
  553. limits: [],
  554. },
  555. ...overrides,
  556. };
  557. }
  558. describe("model provider coding plan", () => {
  559. afterEach(() => {
  560. vi.useRealTimers();
  561. });
  562. it.each(["unknown", "loading"] as const)("购买登录态为 %s 时保持 Select 不可用", (status) => {
  563. expect(isCodingPlanPurchaseAuthPending(status)).toBe(true);
  564. });
  565. it.each(["authenticated", "unauthenticated", "error"] as const)(
  566. "购买登录态明确为 %s 时允许 Select 决策",
  567. (status) => {
  568. expect(isCodingPlanPurchaseAuthPending(status)).toBe(false);
  569. },
  570. );
  571. it("套餐选择发起的同一次登录成功后只恢复升级页面", () => {
  572. const target = {
  573. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  574. initialAudience: "personal" as const,
  575. };
  576. expect(
  577. resolvePendingCodingPlanUpgradeAfterLogin({
  578. pending: { loginAttemptId: 7, target },
  579. loginAttempt: {
  580. id: 7,
  581. providerId: ZAI_PROVIDER_ID,
  582. status: "succeeded",
  583. },
  584. }),
  585. ).toEqual({ action: "reopen", target });
  586. });
  587. it("套餐登录恢复只记录 audience 并重开 Plan 首页", () => {
  588. const requestLoginEntry = vi.fn(() => 7);
  589. const onClose = vi.fn();
  590. const pending = beginCodingPlanUpgradeLogin({
  591. target: {
  592. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  593. initialAudience: "team",
  594. },
  595. oauthProviderId: ZAI_PROVIDER_ID,
  596. audience: "personal",
  597. requestLoginEntry,
  598. onClose,
  599. });
  600. expect(pending).toEqual({
  601. loginAttemptId: 7,
  602. target: {
  603. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  604. initialAudience: "personal",
  605. },
  606. });
  607. expect(requestLoginEntry).toHaveBeenCalledWith(ZAI_PROVIDER_ID);
  608. expect(onClose).toHaveBeenCalledOnce();
  609. });
  610. it.each(["cancelled", "failed"] as const)(
  611. "套餐选择登录为 %s 时丢弃升级页面恢复意图",
  612. (status) => {
  613. expect(
  614. resolvePendingCodingPlanUpgradeAfterLogin({
  615. pending: {
  616. loginAttemptId: 7,
  617. target: {
  618. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  619. initialAudience: "team",
  620. },
  621. },
  622. loginAttempt: { id: 7, providerId: ZAI_PROVIDER_ID, status },
  623. }),
  624. ).toEqual({ action: "discard" });
  625. },
  626. );
  627. it("普通登录或另一条登录 attempt 成功时不恢复升级页面", () => {
  628. expect(
  629. resolvePendingCodingPlanUpgradeAfterLogin({
  630. pending: {
  631. loginAttemptId: 7,
  632. target: {
  633. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  634. initialAudience: "personal",
  635. },
  636. },
  637. loginAttempt: {
  638. id: 8,
  639. providerId: ZAI_PROVIDER_ID,
  640. status: "succeeded",
  641. },
  642. }),
  643. ).toEqual({ action: "discard" });
  644. });
  645. it.each([true, false])(
  646. "未购买套餐同步中=%s 时 Subscribe 的加载反馈与禁用状态一致",
  647. (loginLoading) => {
  648. const html = renderToStaticMarkup(
  649. createElement(CodingPlanStatusPanel, {
  650. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelCodingPlan,
  651. providerName: "BigModel",
  652. status: "notPurchased",
  653. viewState: {
  654. displayStatus: "notPurchased",
  655. actionStatus: "notPurchased",
  656. balanceStatus: "notPurchased",
  657. loginLoading,
  658. },
  659. }),
  660. );
  661. const button = html.match(
  662. /<button[^>]*>(?:(?!<\/button>)[\s\S])*settings\.modelProvider\.codingPlan\.subscribe<\/button>/,
  663. )?.[0];
  664. expect(button).toBeDefined();
  665. expect(button?.includes("animate-spin")).toBe(loginLoading);
  666. expect(button?.includes('disabled=""')).toBe(loginLoading);
  667. },
  668. );
  669. it.each(["purchased", "notPurchased"] as const)(
  670. "后台同步时保留已有 %s entitlement,避免详情闪烁",
  671. (status) => {
  672. expect(
  673. resolveCodingPlanStatusPanelViewState({
  674. status,
  675. loginPending: true,
  676. }),
  677. ).toEqual({
  678. displayStatus: status,
  679. actionStatus: status,
  680. balanceStatus: status,
  681. loginLoading: true,
  682. });
  683. },
  684. );
  685. it("uses a stable provider/auth identity for Z.ai and BigModel plan transitions", () => {
  686. expect(
  687. resolveCodingPlanProviderSyncAttemptKey({
  688. activeOAuthProvider: ZAI_PROVIDER_ID,
  689. oauthProviderId: ZAI_PROVIDER_ID,
  690. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  691. }),
  692. ).toBe(`${BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan}:${ZAI_PROVIDER_ID}`);
  693. expect(
  694. resolveCodingPlanProviderSyncAttemptKey({
  695. activeOAuthProvider: BIGMODEL_PROVIDER_ID,
  696. oauthProviderId: BIGMODEL_PROVIDER_ID,
  697. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  698. }),
  699. ).toBe(`${BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan}:${BIGMODEL_PROVIDER_ID}`);
  700. expect(
  701. resolveCodingPlanProviderSyncAttemptKey({
  702. activeOAuthProvider: ZAI_PROVIDER_ID,
  703. oauthProviderId: BIGMODEL_PROVIDER_ID,
  704. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  705. }),
  706. ).toBeNull();
  707. });
  708. it("连接项未变化但上次同步未完成时允许再次刷新 Plan", () => {
  709. const attemptKey = `${BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan}:${BIGMODEL_PROVIDER_ID}`;
  710. expect(
  711. shouldRetryUnchangedCodingPlanProviderSync({
  712. attemptKey,
  713. attemptStatus: "failed",
  714. modeUnchanged: true,
  715. selectedKeyUnchanged: true,
  716. }),
  717. ).toBe(true);
  718. expect(
  719. shouldRetryUnchangedCodingPlanProviderSync({
  720. attemptKey,
  721. attemptStatus: "succeeded",
  722. modeUnchanged: true,
  723. selectedKeyUnchanged: true,
  724. }),
  725. ).toBe(false);
  726. });
  727. it("失效 Start 连接回到可操作的同 Family 页面,不改保存的连接", () => {
  728. let captured: ReturnType<typeof useModelProviderNavigation> | undefined;
  729. const setSelectedNodeKey = vi.fn();
  730. const connectionSelections = { bigmodel: { kind: "start-plan" as const } };
  731. function Harness() {
  732. captured = useModelProviderNavigation({
  733. presetProviders: [
  734. {
  735. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  736. displayName: "BigModel",
  737. provider: null,
  738. },
  739. ],
  740. modelProviders: [],
  741. providerFamilyDomain: "bigmodel",
  742. connectionSelections,
  743. selectedNodeKey: `preset:${BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan}`,
  744. setSelectedNodeKey,
  745. intl: { formatMessage: ({ id }: { id: string }) => id } as never,
  746. });
  747. return createElement("div");
  748. }
  749. renderToStaticMarkup(createElement(Harness));
  750. expect(captured?.navigationUnavailable).toBe(false);
  751. expect(captured?.selectedNavItem).toMatchObject({
  752. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  753. });
  754. expect(connectionSelections.bigmodel.kind).toBe("start-plan");
  755. });
  756. it("预置导航并列显示 family 与 Start,付费连接方式另放 navigationItems", () => {
  757. let capturedGroups: ModelProviderNavGroup[] = [];
  758. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  759. [];
  760. function Harness() {
  761. const { navigationGroups, navigationItems } = useModelProviderNavigation({
  762. presetProviders: [
  763. {
  764. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  765. displayName: "Z.ai - API Key",
  766. provider: createProvider({
  767. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  768. }),
  769. },
  770. {
  771. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  772. displayName: "BigModel - API Key",
  773. provider: createProvider({
  774. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  775. name: "BigModel",
  776. }),
  777. },
  778. ],
  779. modelProviders: [],
  780. selectedNodeKey: null,
  781. setSelectedNodeKey: vi.fn(),
  782. intl: {
  783. formatMessage: ({ id }: { id: string }) =>
  784. id === "settings.modelProvider.connectionMode.codingPlan"
  785. ? "Coding Plan"
  786. : id === "settings.modelProvider.connectionMode.startPlan"
  787. ? "Start Plan"
  788. : id,
  789. } as never,
  790. });
  791. capturedGroups = navigationGroups;
  792. capturedNavigationItems = navigationItems;
  793. return createElement("div");
  794. }
  795. renderToStaticMarkup(createElement(Harness));
  796. const labels = capturedGroups[0]?.items.map((item) => item.label) ?? [];
  797. const presetIds = capturedGroups[0]?.items.map((item) => item.presetId) ?? [];
  798. expect(labels).toContain("Z.ai - API Key");
  799. expect(labels).toContain("BigModel - API Key");
  800. expect(presetIds).toContain(BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan);
  801. expect(presetIds).toContain(BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan);
  802. expect(
  803. capturedNavigationItems.some(
  804. (item) =>
  805. item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  806. ),
  807. ).toBe(true);
  808. expect(
  809. capturedNavigationItems.some(
  810. (item) =>
  811. item.type === "codingPlan" &&
  812. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  813. ),
  814. ).toBe(true);
  815. });
  816. it("unlink 后独立 Start 入口仍保留,浏览不连接", () => {
  817. let capturedGroups: ModelProviderNavGroup[] = [];
  818. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  819. [];
  820. function Harness() {
  821. const { navigationGroups, navigationItems } = useModelProviderNavigation({
  822. presetProviders: [
  823. {
  824. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  825. displayName: "BigModel - API Key",
  826. provider: createProvider({
  827. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  828. name: "BigModel",
  829. apiKey: "bigmodel-api-key",
  830. }),
  831. },
  832. ],
  833. modelProviders: [
  834. createProvider({
  835. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  836. name: "BigModel - Coding Plan",
  837. apiKey: "",
  838. enabled: false,
  839. systemDisabledReason: "coding_plan_not_connected",
  840. }),
  841. createProvider({
  842. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  843. name: "BigModel- Coding Plan",
  844. apiKey: "",
  845. enabled: false,
  846. systemDisabledReason: "coding_plan_not_connected",
  847. }),
  848. ],
  849. providerFamilyDomain: "bigmodel",
  850. modelProviderFamilyModes: { bigmodel: "oauth" },
  851. selectedNodeKey: `coding-plan:${BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan}`,
  852. setSelectedNodeKey: vi.fn(),
  853. intl: {
  854. formatMessage: ({ id }: { id: string }) =>
  855. id === "settings.modelProvider.connectionMode.codingPlan"
  856. ? "Coding Plan"
  857. : id === "settings.modelProvider.connectionMode.startPlan"
  858. ? "Start Plan"
  859. : id,
  860. } as never,
  861. });
  862. capturedGroups = navigationGroups;
  863. capturedNavigationItems = navigationItems;
  864. return createElement("div");
  865. }
  866. renderToStaticMarkup(createElement(Harness));
  867. const presetIds = capturedGroups[0]?.items.map((item) => item.presetId) ?? [];
  868. expect(capturedGroups[0]?.items.map((item) => item.key)).toEqual([
  869. "preset:account:bigmodel-start-plan",
  870. "coding-plan:account:bigmodel-start-plan",
  871. ]);
  872. expect(capturedNavigationItems.map((item) => item.presetId)).toContain(
  873. BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  874. );
  875. expect(presetIds).not.toContain(BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan);
  876. });
  877. it.each([false, true])(
  878. "失效 Start 或设置读取失败仍能重选,不猜测可执行模型(读取失败=%s)",
  879. (familyConnectionSettingsFailed) => {
  880. let capturedSelectedNavItem: ModelProviderNavGroup["items"][number] | null = null;
  881. function Harness() {
  882. const { selectedNavItem } = useModelProviderNavigation({
  883. presetProviders: [
  884. {
  885. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  886. displayName: "Z.ai - API Key",
  887. provider: createProvider({
  888. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  889. name: "Z.ai",
  890. apiKey: "",
  891. enabled: false,
  892. }),
  893. },
  894. ],
  895. modelProviders: [],
  896. providerFamilyDomain: "zai",
  897. connectionSelections: { zai: { kind: "start-plan" } },
  898. familyConnectionSettingsFailed,
  899. selectedNodeKey: `preset:${BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan}`,
  900. setSelectedNodeKey: vi.fn(),
  901. intl: {
  902. formatMessage: ({ id }: { id: string }) => id,
  903. } as never,
  904. });
  905. capturedSelectedNavItem = selectedNavItem;
  906. return createElement("div");
  907. }
  908. renderToStaticMarkup(createElement(Harness));
  909. expect(capturedSelectedNavItem).toMatchObject({
  910. status: "disconnected",
  911. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  912. });
  913. },
  914. );
  915. it("BigModel family 侧栏状态跟随当前 Team Plan 连接方式点亮", () => {
  916. let capturedGroups: ModelProviderNavGroup[] = [];
  917. let capturedSelectedNavItem: ModelProviderNavGroup["items"][number] | null = null;
  918. function Harness() {
  919. const { navigationGroups, selectedNavItem } = useModelProviderNavigation({
  920. presetProviders: [
  921. {
  922. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  923. displayName: "BigModel",
  924. provider: createProvider({
  925. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  926. name: "BigModel",
  927. apiKey: "",
  928. enabled: false,
  929. }),
  930. },
  931. ],
  932. modelProviders: [
  933. createProvider({
  934. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
  935. name: "BigModel Team",
  936. enabled: true,
  937. }),
  938. createProvider({
  939. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  940. name: "BigModel - Coding Plan",
  941. enabled: false,
  942. systemDisabledReason: "coding_plan_not_entitled",
  943. }),
  944. ],
  945. providerFamilyDomain: "bigmodel",
  946. connectionSelections: {
  947. bigmodel: {
  948. kind: "team-coding-plan",
  949. productId: "product-current",
  950. organizationId: "org-a",
  951. projectId: "project-a",
  952. },
  953. },
  954. subscribedTeamProducts: [
  955. {
  956. productId: "product-current",
  957. productName: "GLM Coding Team",
  958. subscribed: true,
  959. organizationId: "org-a",
  960. organizationName: "Org A",
  961. projectId: "project-a",
  962. projectName: "Project A",
  963. } as never,
  964. ],
  965. selectedNodeKey: `preset:${BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan}`,
  966. setSelectedNodeKey: vi.fn(),
  967. intl: {
  968. formatMessage: (descriptor: { id: string }) => descriptor.id,
  969. } as never,
  970. });
  971. capturedGroups = navigationGroups;
  972. capturedSelectedNavItem = selectedNavItem;
  973. return createElement("div");
  974. }
  975. renderToStaticMarkup(createElement(Harness));
  976. expect(capturedSelectedNavItem).toMatchObject({
  977. type: "teamPlan",
  978. statusActive: true,
  979. projectId: "project-a",
  980. });
  981. expect(capturedGroups[0]?.items[0]).toMatchObject({
  982. type: "preset",
  983. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  984. statusActive: true,
  985. statusProvider: {
  986. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
  987. enabled: true,
  988. executable: true,
  989. },
  990. });
  991. });
  992. it("已落盘的 Coding Plan 不进入自定义供应商分组", () => {
  993. let capturedGroups: ModelProviderNavGroup[] = [];
  994. function Harness() {
  995. const { navigationGroups } = useModelProviderNavigation({
  996. presetProviders: [],
  997. modelProviders: [
  998. createProvider({
  999. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  1000. name: "Z.ai - Coding Plan",
  1001. }),
  1002. createProvider({
  1003. id: "custom-provider",
  1004. name: "Custom Provider",
  1005. config: { group: "standard-personal" },
  1006. }),
  1007. ],
  1008. selectedNodeKey: null,
  1009. setSelectedNodeKey: vi.fn(),
  1010. intl: {
  1011. formatMessage: ({ id }: { id: string }) =>
  1012. id === "settings.modelProvider.connectionMode.codingPlan" ? "Individual Plan" : id,
  1013. } as never,
  1014. });
  1015. capturedGroups = navigationGroups;
  1016. return createElement("div");
  1017. }
  1018. renderToStaticMarkup(createElement(Harness));
  1019. const customGroup = capturedGroups.find((group) => group.id === "custom");
  1020. expect(customGroup?.items.map((item) => item.label)).toEqual(["Custom Provider"]);
  1021. });
  1022. it("Provider Template 和新增入口不混入已配置 Provider 导航", () => {
  1023. let capturedGroups: ModelProviderNavGroup[] = [];
  1024. function Harness() {
  1025. const { navigationGroups } = useModelProviderNavigation({
  1026. presetProviders: [],
  1027. modelProviders: [
  1028. createProvider({
  1029. id: "custom-provider",
  1030. name: "Custom Provider",
  1031. config: { group: "standard-personal" },
  1032. }),
  1033. ],
  1034. selectedNodeKey: null,
  1035. setSelectedNodeKey: vi.fn(),
  1036. intl: { formatMessage: ({ id }: { id: string }) => id } as never,
  1037. });
  1038. capturedGroups = navigationGroups;
  1039. return createElement("div");
  1040. }
  1041. renderToStaticMarkup(createElement(Harness));
  1042. const items = capturedGroups.find((group) => group.id === "custom")?.items ?? [];
  1043. expect(items.map((item) => item.type)).toEqual(["custom"]);
  1044. });
  1045. it("刷新中按缓存后的 provider 状态显示 Z.ai 入口且不显示 loading", () => {
  1046. for (const [selectedNodeKey] of [
  1047. ["coding-plan:account:zai-individual-coding-plan"],
  1048. ["coding-plan:account:zai-start-plan"],
  1049. ] as const) {
  1050. let capturedGroups: ModelProviderNavGroup[] = [];
  1051. let capturedNavigationItems: ReturnType<
  1052. typeof useModelProviderNavigation
  1053. >["navigationItems"] = [];
  1054. function Harness() {
  1055. const { navigationGroups, navigationItems } = useModelProviderNavigation({
  1056. presetProviders: [],
  1057. modelProviders: [
  1058. createProvider({
  1059. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  1060. name: "Z.ai - Coding Plan",
  1061. apiKey: "zai-coding-plan-key",
  1062. }),
  1063. ],
  1064. modelProvidersLoading: true,
  1065. selectedNodeKey,
  1066. setSelectedNodeKey: vi.fn(),
  1067. intl: {
  1068. formatMessage: ({ id }: { id: string }) => id,
  1069. } as never,
  1070. });
  1071. capturedGroups = navigationGroups;
  1072. capturedNavigationItems = navigationItems;
  1073. return createElement("div");
  1074. }
  1075. renderToStaticMarkup(createElement(Harness));
  1076. const presetItems = capturedNavigationItems;
  1077. expect(
  1078. presetItems.some(
  1079. (item) =>
  1080. item.type === "codingPlan" &&
  1081. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  1082. ),
  1083. ).toBe(true);
  1084. expect(presetItems.some((item) => item.type === "codingPlanLoading")).toBe(false);
  1085. expect(capturedGroups[0]?.items.some((item) => item.type === "codingPlan")).toBe(true);
  1086. }
  1087. });
  1088. it.each([undefined, "credential-unavailable"] as const)(
  1089. "已登录团队失败(%s)显示重试而不是连接账号",
  1090. (availabilityReason) => {
  1091. for (const hasProvider of [true, false]) {
  1092. const html = renderDetail(
  1093. {
  1094. key: "team:bigmodel:product:org:project",
  1095. type: "teamPlan",
  1096. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
  1097. oauthProviderId: BIGMODEL_PROVIDER_ID,
  1098. label: "团队",
  1099. providerName: "BigModel",
  1100. teamPlanName: "团队",
  1101. organizationId: "org",
  1102. projectId: "project",
  1103. currentProductId: "product",
  1104. provider: hasProvider
  1105. ? createProvider({ id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan })
  1106. : null,
  1107. status: "unavailable",
  1108. statusActive: false,
  1109. availabilityReason,
  1110. statusMessage: availabilityReason ? "无法创建API Key" : undefined,
  1111. },
  1112. { onRetryCodingPlan: vi.fn() },
  1113. );
  1114. expect(html).toContain("common.retry");
  1115. expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
  1116. expect(html).not.toContain("login.expired.action");
  1117. }
  1118. },
  1119. );
  1120. it("自定义供应商详情仍展示可配置的 API 格式", () => {
  1121. const html = renderDetail({
  1122. key: "custom:provider-a",
  1123. type: "custom",
  1124. label: "Provider A",
  1125. provider: createProvider({ id: "provider-a" }),
  1126. statusActive: false,
  1127. });
  1128. expectConnectionApiFormatVisible(html);
  1129. });
  1130. it.each(["zai", "bigmodel"] as const)(
  1131. "%s 个人套餐失败重新登录,Start 套餐失败保留重试",
  1132. (family) => {
  1133. for (const plan of ["individual-coding-plan", "start-plan"] as const) {
  1134. const providerId = `account:${family}-${plan}` as const;
  1135. const provider = {
  1136. ...createProvider({ id: providerId }),
  1137. accountState: {
  1138. availability: "unavailable" as const,
  1139. entitled: false,
  1140. unavailableReason: "credential-failed" as const,
  1141. },
  1142. };
  1143. const html = renderDetail(
  1144. {
  1145. key: `coding-plan:${providerId}`,
  1146. type: "codingPlan",
  1147. presetId: providerId,
  1148. oauthProviderId: family,
  1149. label: family,
  1150. providerName: family,
  1151. provider,
  1152. status: "unavailable",
  1153. statusActive: false,
  1154. },
  1155. { onRetryCodingPlan: vi.fn() },
  1156. );
  1157. if (plan === "individual-coding-plan") {
  1158. expect(html).toContain("login.expired.action");
  1159. expect(html).toContain("settings.modelProvider.codingPlan.description.credentialFailed");
  1160. expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
  1161. } else {
  1162. expect(html).toContain("common.retry");
  1163. expect(html).not.toContain("login.expired.action");
  1164. expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
  1165. }
  1166. }
  1167. },
  1168. );
  1169. it("内置 GLM-5.2 模型按 1M 上下文窗口展示", () => {
  1170. const html = renderDetail({
  1171. key: `coding-plan:${BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan}`,
  1172. type: "codingPlan",
  1173. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  1174. oauthProviderId: ZAI_PROVIDER_ID,
  1175. label: "Z.ai - Coding Plan",
  1176. providerName: "Z.ai",
  1177. provider: createProvider({
  1178. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  1179. name: "Z.ai - Coding Plan",
  1180. defaultKind: "anthropic",
  1181. endpoints: {
  1182. baseURL: "https://zcode.z.ai/api/v1/zcode-plan/anthropic",
  1183. paths: { anthropic: "/v1/messages" },
  1184. },
  1185. models: [
  1186. createModelProviderModelConfig({
  1187. id: "GLM-5.2",
  1188. kinds: ["anthropic"],
  1189. defaultKind: "anthropic",
  1190. contextWindow: 1_000_000,
  1191. }),
  1192. ],
  1193. }),
  1194. status: "purchased",
  1195. statusActive: true,
  1196. });
  1197. expect(html).toContain("GLM-5.2");
  1198. expect(html).toContain(">1M<");
  1199. expect(html).not.toContain(">200K<");
  1200. });
  1201. it("Account Provider 的 Effective 模型列表允许通过 Personal modelOrder 调序", () => {
  1202. const html = renderDetail(
  1203. {
  1204. key: `coding-plan:${BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan}`,
  1205. type: "codingPlan",
  1206. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  1207. oauthProviderId: BIGMODEL_PROVIDER_ID,
  1208. label: "BigModel - Coding Plan",
  1209. providerName: "BigModel",
  1210. provider: createProvider({
  1211. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  1212. models: [
  1213. createModelProviderModelConfig({ id: "GLM-5.2" }),
  1214. createModelProviderModelConfig({ id: "GLM-5-Turbo" }),
  1215. ],
  1216. }),
  1217. status: "purchased",
  1218. statusActive: true,
  1219. },
  1220. { onReorderProviderModels: vi.fn(async () => undefined) },
  1221. );
  1222. expect(html.match(/aria-label="settings\.modelProvider\.reorderModel"/g)).toHaveLength(2);
  1223. });
  1224. it("体验套餐详情允许标准模型配置,但 Built-in 成员不可删除", () => {
  1225. const primaryModel = "start-plan-cloud-primary";
  1226. const secondaryModel = "start-plan-cloud-secondary";
  1227. const html = renderDetail({
  1228. key: `coding-plan:${BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan}`,
  1229. type: "codingPlan",
  1230. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  1231. oauthProviderId: BIGMODEL_PROVIDER_ID,
  1232. label: "BigModel - Start Plan",
  1233. providerName: "BigModel",
  1234. provider: createProvider({
  1235. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  1236. name: "BigModel - Start Plan",
  1237. defaultKind: "anthropic",
  1238. endpoints: {
  1239. baseURL: "https://zcode.z.ai/api/v1/zcode-plan/anthropic",
  1240. paths: { anthropic: "/v1/messages" },
  1241. },
  1242. models: [
  1243. createModelProviderModelConfig({
  1244. id: primaryModel,
  1245. builtin: true,
  1246. kinds: ["anthropic"],
  1247. defaultKind: "anthropic",
  1248. }),
  1249. createModelProviderModelConfig({
  1250. id: secondaryModel,
  1251. builtin: true,
  1252. kinds: ["anthropic"],
  1253. defaultKind: "anthropic",
  1254. }),
  1255. ],
  1256. }),
  1257. status: "purchased",
  1258. statusActive: true,
  1259. });
  1260. expect(html).toContain(primaryModel);
  1261. expect(html).toContain(secondaryModel);
  1262. expect(html).toContain(TID_MODEL_PROVIDER_ADD_MODEL_BUTTON);
  1263. expect(html).not.toContain(TID_MODEL_PROVIDER_MODEL_DELETE_BUTTON);
  1264. });
  1265. it("Todo89:Account 已确认可用时,Start 额度卡临时刷新不隐藏模型编辑区", () => {
  1266. const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan;
  1267. const provider = createProvider({
  1268. id: providerId,
  1269. models: ["start-dynamic-model"],
  1270. });
  1271. const view = createProviderSettingsView(provider);
  1272. const item = {
  1273. key: `coding-plan:${providerId}`,
  1274. type: "codingPlan" as const,
  1275. presetId: providerId,
  1276. oauthProviderId: BIGMODEL_PROVIDER_ID,
  1277. label: "Start",
  1278. providerName: "BigModel",
  1279. provider,
  1280. status: "checking" as const,
  1281. statusActive: false,
  1282. };
  1283. const availableView = {
  1284. ...view,
  1285. providers: view.providers.map((p) => ({
  1286. ...p,
  1287. accountState: {
  1288. availability: "available" as const,
  1289. entitled: true,
  1290. current: true,
  1291. },
  1292. })),
  1293. };
  1294. expect(renderDetail(item, { providerSettingsView: availableView })).toContain(
  1295. "start-dynamic-model",
  1296. );
  1297. const unavailableView = {
  1298. ...view,
  1299. providers: view.providers.map((p) => ({
  1300. ...p,
  1301. accountState: {
  1302. availability: "unavailable" as const,
  1303. entitled: false,
  1304. current: true,
  1305. },
  1306. })),
  1307. };
  1308. expect(renderDetail(item, { providerSettingsView: unavailableView })).not.toContain(
  1309. "start-dynamic-model",
  1310. );
  1311. });
  1312. it("自定义供应商详情按单一 runtime config 展示可编辑 API 格式且不展示接口路径编辑", () => {
  1313. const html = renderDetail({
  1314. key: "custom:provider-a",
  1315. type: "custom",
  1316. label: "Provider A",
  1317. provider: createProvider({
  1318. id: "provider-a",
  1319. apiFormat: "openai-chat-completions",
  1320. defaultKind: "openai-compatible",
  1321. endpoints: {
  1322. baseURL: "https://api.example.com/v1",
  1323. paths: {
  1324. "openai-compatible": "/chat/completions",
  1325. },
  1326. },
  1327. models: [
  1328. createModelProviderModelConfig({
  1329. id: "glm-5",
  1330. kinds: ["openai-compatible"],
  1331. defaultKind: "openai-compatible",
  1332. }),
  1333. ],
  1334. }),
  1335. statusActive: false,
  1336. });
  1337. const intl = { formatMessage: ({ id }: { id: string }) => id };
  1338. const apiFormatOptions = resolveProviderConnectionApiFormatOptions();
  1339. expect(apiFormatOptions).toEqual([
  1340. "anthropic-messages",
  1341. "openai-chat-completions",
  1342. "openai-responses",
  1343. ]);
  1344. expect(
  1345. apiFormatOptions.map((format) =>
  1346. resolveProviderConnectionApiFormatDisplayLabel(intl, format),
  1347. ),
  1348. ).toEqual([
  1349. "settings.modelProvider.apiFormat.title.anthropicMessages (/v1/messages)",
  1350. "settings.modelProvider.apiFormat.title.chatCompletions (/chat/completions)",
  1351. "settings.modelProvider.apiFormat.title.responses (/responses)",
  1352. ]);
  1353. expect(html).toContain('value="https://api.example.com/v1"');
  1354. expectConnectionApiFormatVisible(html);
  1355. expect(html).not.toContain("settings.modelProvider.endpointPath");
  1356. });
  1357. it("自定义供应商详情隐藏 Claude 映射和自定义 Headers", () => {
  1358. const html = renderDetail({
  1359. key: "custom:provider-a",
  1360. type: "custom",
  1361. label: "Provider A",
  1362. provider: createProvider({
  1363. id: "provider-a",
  1364. }),
  1365. statusActive: false,
  1366. });
  1367. expect(html).not.toContain("settings.modelProvider.claudeMapping");
  1368. expect(html).not.toContain("settings.modelProvider.customHeaders");
  1369. });
  1370. it("Provider sidebar 将预置入口组织成 provider family", () => {
  1371. let capturedGroups: ModelProviderNavGroup[] = [];
  1372. function Harness() {
  1373. const { navigationGroups } = useModelProviderNavigation({
  1374. presetProviders: [
  1375. {
  1376. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  1377. displayName: "Z.ai - API Key",
  1378. provider: createProvider({
  1379. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  1380. }),
  1381. },
  1382. {
  1383. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  1384. displayName: "BigModel - API Key",
  1385. provider: createProvider({
  1386. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  1387. name: "BigModel",
  1388. }),
  1389. },
  1390. ],
  1391. modelProviders: [],
  1392. selectedNodeKey: null,
  1393. setSelectedNodeKey: vi.fn(),
  1394. intl: {
  1395. formatMessage: ({ id }: { id: string }) => id,
  1396. } as never,
  1397. });
  1398. capturedGroups = navigationGroups;
  1399. return createElement("div");
  1400. }
  1401. renderToStaticMarkup(createElement(Harness));
  1402. expect(
  1403. capturedGroups[0]?.items.map((item) => (item.type === "preset" ? item.presetId : item.key)),
  1404. ).toEqual([
  1405. BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  1406. BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  1407. "coding-plan:account:zai-start-plan",
  1408. "coding-plan:account:bigmodel-start-plan",
  1409. ]);
  1410. });
  1411. it("套餐连接入口点击时仍映射回 provider family side key", () => {
  1412. expect(
  1413. resolveModelProviderSideSelectionKey({
  1414. key: "coding-plan:account:zai-individual-coding-plan",
  1415. type: "codingPlan",
  1416. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  1417. oauthProviderId: ZAI_PROVIDER_ID,
  1418. label: "Z.ai - Coding Plan",
  1419. providerName: "Z.ai",
  1420. provider: createProvider({
  1421. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  1422. name: "Z.ai - Coding Plan",
  1423. }),
  1424. status: "purchased",
  1425. planLevel: "Coding Pro",
  1426. currentProductId: "product-zai-pro",
  1427. subscriptionBillingCycle: null,
  1428. subscriptionRenewTime: null,
  1429. subscriptionExpireTime: null,
  1430. quotaLimits: [],
  1431. purchaseUrl: "https://z.ai/manage-apikey/subscription",
  1432. statusActive: true,
  1433. }),
  1434. ).toBe("preset:account:zai-start-plan");
  1435. });
  1436. it.each([
  1437. ["preset", BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan, "BigModel", "BigModel"],
  1438. ["preset", BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan, "Z.ai", "Z.ai"],
  1439. ["codingPlan", BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan, "Start Plan", "Start Plan"],
  1440. ["codingPlan", BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan, "Start Plan", "Start Plan"],
  1441. ] as const)("导航 %s %s 保持品牌与 Start 名称", (type, presetId, en, zh) => {
  1442. const item: ModelProviderNavItem = {
  1443. key: presetId,
  1444. type,
  1445. presetId,
  1446. label: "Old brand",
  1447. ...(type === "preset"
  1448. ? { displayName: "Old brand" }
  1449. : {
  1450. oauthProviderId: "bigmodel" as const,
  1451. providerName: "Old brand",
  1452. status: "notPurchased" as const,
  1453. }),
  1454. provider: null,
  1455. statusActive: false,
  1456. };
  1457. expect(resolveModelProviderSideNavLabel(item)).toBe(en);
  1458. expect(resolveModelProviderSideNavLabel(item)).toBe(zh);
  1459. });
  1460. it("Provider sidebar 不按团队 Coding Plan 数量展开入口", () => {
  1461. const bigmodelApiKeyItem = {
  1462. key: "preset:account:bigmodel-start-plan",
  1463. type: "preset" as const,
  1464. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  1465. label: "BigModel - API Key",
  1466. provider: createProvider({
  1467. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  1468. }),
  1469. displayName: "BigModel - API Key",
  1470. statusActive: true,
  1471. };
  1472. const html = renderWithTooltipProvider(
  1473. createElement(ModelProviderSectionNavigation, {
  1474. navigationGroups: [
  1475. {
  1476. id: "preset",
  1477. title: "Preset",
  1478. items: [bigmodelApiKeyItem],
  1479. },
  1480. ],
  1481. selectedNodeKey: "preset:account:bigmodel-start-plan",
  1482. presetLoading: false,
  1483. customLoading: false,
  1484. onSelectNavItem: vi.fn(),
  1485. }),
  1486. );
  1487. expect(html).toContain("BigModel");
  1488. expect(html).not.toContain("Team A");
  1489. expect(html).not.toContain("Team B");
  1490. });
  1491. it("Z.ai family 导航保持品牌图标,不借用 Start 图标", () => {
  1492. const html = renderWithTooltipProvider(
  1493. createElement(ModelProviderSectionNavigation, {
  1494. navigationGroups: [
  1495. {
  1496. id: "preset",
  1497. title: "Preset",
  1498. items: [
  1499. {
  1500. key: "preset:account:zai-start-plan",
  1501. type: "preset",
  1502. logo: { type: "builtin", key: "zai" },
  1503. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  1504. label: "Z.ai - API Key",
  1505. displayName: "Z.ai - API Key",
  1506. provider: createProvider({
  1507. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  1508. name: "Z.ai - API Key",
  1509. config: { logo: { type: "builtin", key: "start-plan" } },
  1510. }),
  1511. statusActive: true,
  1512. },
  1513. ],
  1514. },
  1515. ],
  1516. selectedNodeKey: "preset:account:zai-start-plan",
  1517. presetLoading: false,
  1518. customLoading: false,
  1519. onSelectNavItem: vi.fn(),
  1520. }),
  1521. );
  1522. expect(html).toContain("Z.ai");
  1523. expect(html).toContain("<img ");
  1524. expect(html).toContain("model-provider-zai-app.png");
  1525. expect(html).not.toContain("model-provider-start-plan.png");
  1526. expect(html).toContain("object-contain size-4");
  1527. expect(html).toContain("border-border-hover bg-card-selected text-foreground");
  1528. expect(html).not.toContain("border-card-border bg-surface");
  1529. expect(html).toContain("flex h-8 w-full");
  1530. expect(html).not.toContain("settings.modelProvider.connectionMode.startPlan");
  1531. expect(html).not.toContain("settings.modelProvider.codingPlan.start.freeBadge");
  1532. });
  1533. it("仅有个人付费选项时不显示冗余套餐下拉", () => {
  1534. const startPlanItem = {
  1535. key: "coding-plan:account:zai-start-plan",
  1536. type: "codingPlan" as const,
  1537. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  1538. oauthProviderId: ZAI_PROVIDER_ID,
  1539. label: "Z.ai - Start Plan",
  1540. providerName: "Z.ai",
  1541. provider: createProvider({
  1542. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  1543. name: "Z.ai - Start Plan",
  1544. }),
  1545. status: "purchased" as const,
  1546. statusActive: true,
  1547. };
  1548. const oauthItem = {
  1549. key: "coding-plan:account:zai-individual-coding-plan",
  1550. type: "codingPlan" as const,
  1551. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  1552. oauthProviderId: ZAI_PROVIDER_ID,
  1553. label: "Z.ai - Coding Plan",
  1554. providerName: "Z.ai",
  1555. provider: createProvider({
  1556. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  1557. }),
  1558. status: "purchased" as const,
  1559. statusActive: true,
  1560. };
  1561. const html = renderDetail(oauthItem, {
  1562. navigationItems: [startPlanItem, oauthItem],
  1563. connectionSelections: { zai: { kind: "individual-coding-plan" } },
  1564. onSelectNavItem: vi.fn(),
  1565. });
  1566. expect(html).toContain(">Z.ai<");
  1567. expect(html).toContain("settings.modelProvider.planCard.codingPlan");
  1568. expect(html).not.toContain("settings.modelProvider.connectionMode");
  1569. expect(html).not.toContain('role="combobox"');
  1570. expect(html).not.toContain('role="tablist"');
  1571. expect(html).not.toContain('role="tab"');
  1572. });
  1573. it("Start 详情不展示付费连接获取失败提示", () => {
  1574. const startPlanItem = {
  1575. key: "coding-plan:account:zai-start-plan",
  1576. type: "codingPlan" as const,
  1577. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  1578. oauthProviderId: ZAI_PROVIDER_ID,
  1579. label: "Z.ai - Start Plan",
  1580. providerName: "Z.ai",
  1581. provider: createProvider({
  1582. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  1583. name: "Z.ai - Start Plan",
  1584. }),
  1585. status: "purchased" as const,
  1586. statusActive: true,
  1587. };
  1588. const oauthItem = {
  1589. key: "coding-plan:account:zai-individual-coding-plan",
  1590. type: "codingPlan" as const,
  1591. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  1592. oauthProviderId: ZAI_PROVIDER_ID,
  1593. label: "Z.ai - Coding Plan",
  1594. providerName: "Z.ai",
  1595. provider: null,
  1596. status: "disconnected" as const,
  1597. purchaseUrl: "https://z.ai/",
  1598. statusActive: false,
  1599. };
  1600. const html = renderDetail(startPlanItem, {
  1601. navigationItems: [startPlanItem, oauthItem],
  1602. connectionSettingsFailed: true,
  1603. onSelectNavItem: vi.fn(),
  1604. });
  1605. expect(html).not.toContain("settings.modelProvider.connectionMode.loadFailed");
  1606. expect(html).not.toContain("text-warning");
  1607. expect(html).toContain("settings.modelProvider.planCard.startPlan");
  1608. });
  1609. it("付费连接方式下拉平铺 Coding 和多个 Team Plan,排除 Start", () => {
  1610. const startPlanItem = {
  1611. key: "coding-plan:account:bigmodel-start-plan",
  1612. type: "codingPlan" as const,
  1613. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  1614. oauthProviderId: BIGMODEL_PROVIDER_ID,
  1615. label: "BigModel - Start Plan",
  1616. providerName: "BigModel",
  1617. provider: createProvider({
  1618. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  1619. }),
  1620. status: "purchased" as const,
  1621. statusActive: true,
  1622. };
  1623. const codingPlanItem = {
  1624. key: "coding-plan:account:bigmodel-individual-coding-plan",
  1625. type: "codingPlan" as const,
  1626. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  1627. oauthProviderId: BIGMODEL_PROVIDER_ID,
  1628. label: "BigModel - Coding Plan",
  1629. providerName: "BigModel",
  1630. provider: createProvider({
  1631. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  1632. }),
  1633. status: "purchased" as const,
  1634. statusActive: true,
  1635. };
  1636. const teamAItem = {
  1637. ...codingPlanItem,
  1638. key: "team-plan:team-a",
  1639. type: "teamPlan" as const,
  1640. teamPlanName: "TeamA",
  1641. organizationId: "org-a",
  1642. projectId: "proj-a",
  1643. };
  1644. const teamBItem = {
  1645. ...codingPlanItem,
  1646. key: "team-plan:team-b",
  1647. type: "teamPlan" as const,
  1648. teamPlanName: "TeamB Plan",
  1649. organizationId: "org-b",
  1650. projectId: "proj-b",
  1651. };
  1652. const options = buildProviderFamilyConnectionOptions({
  1653. familyId: "bigmodel",
  1654. navigationItems: [teamBItem, codingPlanItem, startPlanItem, teamAItem],
  1655. startPlanLabel: "体验套餐",
  1656. codingPlanLabel: "个人套餐",
  1657. teamPlanFallbackLabel: "Team Plan",
  1658. });
  1659. expect(options.map((option) => option.label)).toEqual(["个人套餐", "TeamB Plan", "TeamA"]);
  1660. });
  1661. it("已购企业套餐会进入连接方式导航项", () => {
  1662. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  1663. [];
  1664. function Harness() {
  1665. const { navigationItems } = useModelProviderNavigation({
  1666. presetProviders: [
  1667. {
  1668. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  1669. displayName: "BigModel - API Key",
  1670. provider: createProvider({
  1671. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  1672. }),
  1673. },
  1674. ],
  1675. modelProviders: [
  1676. createProvider({
  1677. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  1678. name: "BigModel - Coding Plan",
  1679. apiKey: "jwt-token",
  1680. }),
  1681. ],
  1682. codingPlanEntitlements: {},
  1683. subscribedTeamProducts: [
  1684. {
  1685. productId: "product-team-max",
  1686. productName: "Max",
  1687. productBigTitle: "Max",
  1688. originalAmount: 598,
  1689. payAmount: 598,
  1690. renewAmount: 598,
  1691. priceUnit: "month",
  1692. priceCurrency: "CNY",
  1693. productEquityList: [],
  1694. hasPreview: true,
  1695. organizationId: "org-team-a",
  1696. organizationName: "TeamA Org",
  1697. projectId: "proj-team-a",
  1698. projectName: "团队编程套餐项目",
  1699. enterpriseProduct: {
  1700. productId: "product-team-max",
  1701. tier: "MAX",
  1702. subscribeMode: "CONTINUOUS",
  1703. subscribePeriod: "MONTHLY",
  1704. subscribed: true,
  1705. organizationId: "org-team-a",
  1706. organizationName: "TeamA Org",
  1707. projectId: "proj-team-a",
  1708. projectName: "团队编程套餐项目",
  1709. },
  1710. tier: "MAX",
  1711. subscribeMode: "CONTINUOUS",
  1712. subscribePeriod: "MONTHLY",
  1713. purchaseMethodName: "连续订阅",
  1714. subscribed: true,
  1715. },
  1716. ],
  1717. selectedNodeKey: null,
  1718. setSelectedNodeKey: vi.fn(),
  1719. intl: {
  1720. formatMessage: ({ id }: { id: string }) => id,
  1721. } as never,
  1722. });
  1723. capturedNavigationItems = navigationItems;
  1724. return createElement("div");
  1725. }
  1726. renderToStaticMarkup(createElement(Harness));
  1727. const teamPlan = capturedNavigationItems.find((item) => item.type === "teamPlan");
  1728. const startPlan = capturedNavigationItems.find(
  1729. (item) =>
  1730. item.type === "codingPlan" &&
  1731. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  1732. );
  1733. expect(teamPlan).toMatchObject({
  1734. key: "team:bigmodel:product-team-max:org-team-a:proj-team-a",
  1735. teamPlanName: "TeamA Org",
  1736. label: "BigModel - TeamA Org",
  1737. organizationId: "org-team-a",
  1738. projectId: "proj-team-a",
  1739. status: "purchased",
  1740. currentProductId: "product-team-max",
  1741. });
  1742. expect(startPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
  1743. });
  1744. it("初始化 fallback 只选中 BigModel family 侧栏入口", () => {
  1745. const codingPlanItem = {
  1746. key: "coding-plan:account:bigmodel-individual-coding-plan",
  1747. type: "codingPlan" as const,
  1748. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  1749. oauthProviderId: BIGMODEL_PROVIDER_ID,
  1750. label: "BigModel - Coding Plan",
  1751. providerName: "BigModel",
  1752. provider: createProvider({
  1753. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  1754. }),
  1755. status: "purchased" as const,
  1756. statusActive: true,
  1757. };
  1758. const teamPlanItem = {
  1759. ...codingPlanItem,
  1760. key: "team:bigmodel:product-team-max:org-team:project-team",
  1761. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
  1762. type: "teamPlan" as const,
  1763. teamPlanName: "TeamA",
  1764. currentProductId: "product-team-max",
  1765. organizationId: "org-team",
  1766. projectId: "project-team",
  1767. };
  1768. expect(
  1769. resolveFallbackModelProviderNodeKey({
  1770. selectedNodeKey: null,
  1771. selectableNavigationItems: [codingPlanItem, teamPlanItem],
  1772. connectionSelections: {
  1773. bigmodel: {
  1774. kind: "team-coding-plan",
  1775. productId: "product-team-max",
  1776. organizationId: "org-team",
  1777. projectId: "project-team",
  1778. },
  1779. },
  1780. }),
  1781. ).toBe("preset:account:bigmodel-start-plan");
  1782. });
  1783. it("Team Plan 异步出现后从默认 Coding Plan 纠偏到已保存连接方式", () => {
  1784. const codingPlanItem = {
  1785. key: "coding-plan:account:bigmodel-individual-coding-plan",
  1786. type: "codingPlan" as const,
  1787. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  1788. oauthProviderId: BIGMODEL_PROVIDER_ID,
  1789. label: "BigModel - Coding Plan",
  1790. providerName: "BigModel",
  1791. provider: createProvider({
  1792. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  1793. }),
  1794. status: "purchased" as const,
  1795. statusActive: true,
  1796. };
  1797. const teamPlanItem = {
  1798. ...codingPlanItem,
  1799. key: "team:bigmodel:product-team-max:org-team:project-team",
  1800. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
  1801. type: "teamPlan" as const,
  1802. teamPlanName: "TeamA",
  1803. currentProductId: "product-team-max",
  1804. organizationId: "org-team",
  1805. projectId: "project-team",
  1806. };
  1807. expect(
  1808. resolveSelectedFamilyModeNodeKey({
  1809. selectedNavItem: codingPlanItem,
  1810. selectableNavigationItems: [codingPlanItem, teamPlanItem],
  1811. connectionSelections: {
  1812. bigmodel: {
  1813. kind: "team-coding-plan",
  1814. productId: "product-team-max",
  1815. organizationId: "org-team",
  1816. projectId: "project-team",
  1817. },
  1818. },
  1819. }),
  1820. ).toBe("team:bigmodel:product-team-max:org-team:project-team");
  1821. });
  1822. it("Team Plan 商品 ID 变化时仍按项目 key 恢复已保存连接方式", () => {
  1823. const codingPlanItem = {
  1824. key: "coding-plan:account:bigmodel-individual-coding-plan",
  1825. type: "codingPlan" as const,
  1826. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  1827. oauthProviderId: BIGMODEL_PROVIDER_ID,
  1828. label: "BigModel - Coding Plan",
  1829. providerName: "BigModel",
  1830. provider: createProvider({
  1831. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  1832. }),
  1833. status: "purchased" as const,
  1834. statusActive: true,
  1835. };
  1836. const teamPlanItem = {
  1837. ...codingPlanItem,
  1838. key: "team:bigmodel:product-current:org-team:proj-team",
  1839. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
  1840. type: "teamPlan" as const,
  1841. teamPlanName: "TeamA",
  1842. currentProductId: "product-current",
  1843. organizationId: "org-team",
  1844. projectId: "proj-team",
  1845. };
  1846. expect(
  1847. resolveSelectedFamilyModeNodeKey({
  1848. selectedNavItem: codingPlanItem,
  1849. selectableNavigationItems: [codingPlanItem, teamPlanItem],
  1850. connectionSelections: {
  1851. bigmodel: {
  1852. kind: "team-coding-plan",
  1853. productId: "product-current",
  1854. organizationId: "org-team",
  1855. projectId: "proj-team",
  1856. },
  1857. },
  1858. }),
  1859. ).toBe("team:bigmodel:product-current:org-team:proj-team");
  1860. });
  1861. it("手动选择 Coding Plan 的 pending selectedKey 不被已保存 Team Plan 纠偏", () => {
  1862. const codingPlanItem = {
  1863. key: "coding-plan:account:bigmodel-individual-coding-plan",
  1864. type: "codingPlan" as const,
  1865. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  1866. oauthProviderId: BIGMODEL_PROVIDER_ID,
  1867. label: "BigModel - Coding Plan",
  1868. providerName: "BigModel",
  1869. provider: createProvider({
  1870. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  1871. }),
  1872. status: "purchased" as const,
  1873. statusActive: true,
  1874. };
  1875. const teamPlanItem = {
  1876. ...codingPlanItem,
  1877. key: "team:bigmodel:product-team-max:org-team:project-team",
  1878. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
  1879. type: "teamPlan" as const,
  1880. teamPlanName: "TeamA",
  1881. currentProductId: "product-team-max",
  1882. organizationId: "org-team",
  1883. projectId: "project-team",
  1884. };
  1885. expect(
  1886. resolveSelectedFamilyModeNodeKey({
  1887. selectedNavItem: codingPlanItem,
  1888. selectableNavigationItems: [codingPlanItem, teamPlanItem],
  1889. connectionSelections: {
  1890. bigmodel: {
  1891. kind: "team-coding-plan",
  1892. productId: "product-team-max",
  1893. organizationId: "org-team",
  1894. projectId: "project-team",
  1895. },
  1896. },
  1897. pendingConnectionSelections: {
  1898. bigmodel: { kind: "individual-coding-plan" },
  1899. },
  1900. }),
  1901. ).toBeNull();
  1902. });
  1903. it("手动选择 Coding Plan 的 pending selectedKey 优先于 Start 初始化优先级", () => {
  1904. let capturedSelectedNavItem: ReturnType<typeof useModelProviderNavigation>["selectedNavItem"] =
  1905. null;
  1906. function Harness() {
  1907. const { selectedNavItem } = useModelProviderNavigation({
  1908. presetProviders: [
  1909. {
  1910. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  1911. displayName: "Z.ai - API Key",
  1912. provider: createProvider({
  1913. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  1914. }),
  1915. },
  1916. ],
  1917. modelProviders: [
  1918. createProvider({
  1919. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  1920. name: "Z.ai - Start Plan",
  1921. apiKey: "start-token",
  1922. }),
  1923. createProvider({
  1924. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  1925. name: "Z.ai - Coding Plan",
  1926. apiKey: "coding-token",
  1927. }),
  1928. ],
  1929. codingPlanEntitlements: {
  1930. [BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan]: {
  1931. loading: false,
  1932. error: null,
  1933. snapshot: createEntitlementSnapshot({
  1934. provider: { id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan },
  1935. remaining: null,
  1936. subscription: {
  1937. identityType: "unknown",
  1938. identityMasked: null,
  1939. details: [
  1940. {
  1941. productId: "zcode-v3-start-plan",
  1942. productName: "Start Plan",
  1943. purchaseTime: null,
  1944. beginTime: null,
  1945. billingCycle: null,
  1946. renewTime: null,
  1947. expireTime: null,
  1948. },
  1949. ],
  1950. },
  1951. quota: null,
  1952. }),
  1953. },
  1954. [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
  1955. loading: false,
  1956. error: null,
  1957. snapshot: createEntitlementSnapshot({
  1958. provider: {
  1959. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  1960. },
  1961. remaining: null,
  1962. subscription: {
  1963. identityType: "unknown",
  1964. identityMasked: null,
  1965. details: [
  1966. {
  1967. productId: "product-zai-pro",
  1968. productName: "GLM Coding Pro",
  1969. purchaseTime: null,
  1970. beginTime: null,
  1971. billingCycle: "monthly",
  1972. renewTime: null,
  1973. expireTime: null,
  1974. },
  1975. ],
  1976. },
  1977. quota: null,
  1978. }),
  1979. },
  1980. },
  1981. selectedNodeKey: "preset:account:zai-start-plan",
  1982. connectionSelections: { zai: { kind: "individual-coding-plan" } },
  1983. setSelectedNodeKey: vi.fn(),
  1984. intl: {
  1985. formatMessage: ({ id }: { id: string }) => id,
  1986. } as never,
  1987. });
  1988. capturedSelectedNavItem = selectedNavItem;
  1989. return createElement("div");
  1990. }
  1991. renderToStaticMarkup(createElement(Harness));
  1992. expect(capturedSelectedNavItem).toMatchObject({
  1993. type: "codingPlan",
  1994. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  1995. });
  1996. });
  1997. it("外部打开 Model Settings 时等待连接方式设置 hydrate,避免先闪成 Start Plan", () => {
  1998. let capturedSelectedNavItem: ReturnType<typeof useModelProviderNavigation>["selectedNavItem"] =
  1999. null;
  2000. function Harness() {
  2001. const { selectedNavItem } = useModelProviderNavigation({
  2002. presetProviders: [
  2003. {
  2004. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2005. displayName: "Z.ai - API Key",
  2006. provider: createProvider({
  2007. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2008. }),
  2009. },
  2010. ],
  2011. modelProviders: [
  2012. createProvider({
  2013. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2014. name: "Z.ai - Start Plan",
  2015. apiKey: "start-token",
  2016. }),
  2017. ],
  2018. codingPlanEntitlements: {
  2019. [BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan]: {
  2020. loading: false,
  2021. error: null,
  2022. snapshot: createEntitlementSnapshot({
  2023. provider: { id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan },
  2024. remaining: null,
  2025. subscription: {
  2026. identityType: "unknown",
  2027. identityMasked: null,
  2028. details: [
  2029. {
  2030. productId: "zcode-v3-start-plan",
  2031. productName: "Start Plan",
  2032. purchaseTime: null,
  2033. beginTime: null,
  2034. billingCycle: null,
  2035. renewTime: null,
  2036. expireTime: null,
  2037. },
  2038. ],
  2039. },
  2040. quota: null,
  2041. }),
  2042. },
  2043. },
  2044. selectedNodeKey: "preset:account:zai-start-plan",
  2045. modelProviderFamilyModes: {},
  2046. modelProviderFamilySelectedKeys: {},
  2047. familyConnectionSettingsLoading: true,
  2048. setSelectedNodeKey: vi.fn(),
  2049. intl: {
  2050. formatMessage: ({ id }: { id: string }) => id,
  2051. } as never,
  2052. });
  2053. capturedSelectedNavItem = selectedNavItem;
  2054. return createElement("div");
  2055. }
  2056. renderToStaticMarkup(createElement(Harness));
  2057. expect(capturedSelectedNavItem).toBeNull();
  2058. });
  2059. it("OAuth family 的 Plan 连接项未生成时右侧保持 loading,不先显示 API Key", () => {
  2060. let capturedSelectedNavItem: ReturnType<typeof useModelProviderNavigation>["selectedNavItem"] =
  2061. null;
  2062. function Harness() {
  2063. const { selectedNavItem } = useModelProviderNavigation({
  2064. presetProviders: [
  2065. {
  2066. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  2067. displayName: "BigModel - API Key",
  2068. provider: createProvider({
  2069. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  2070. name: "BigModel - API Key",
  2071. }),
  2072. },
  2073. ],
  2074. modelProviders: [
  2075. createProvider({
  2076. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  2077. name: "BigModel - API Key",
  2078. }),
  2079. ],
  2080. codingPlanEntitlements: {},
  2081. modelProvidersLoading: true,
  2082. selectedNodeKey: "preset:account:bigmodel-start-plan",
  2083. modelProviderFamilyModes: { bigmodel: "oauth" },
  2084. modelProviderFamilySelectedKeys: {},
  2085. setSelectedNodeKey: vi.fn(),
  2086. intl: {
  2087. formatMessage: ({ id }: { id: string }) => id,
  2088. } as never,
  2089. });
  2090. capturedSelectedNavItem = selectedNavItem;
  2091. return createElement("div");
  2092. }
  2093. renderToStaticMarkup(createElement(Harness));
  2094. expect(capturedSelectedNavItem).toBeNull();
  2095. });
  2096. it("连接方式设置获取失败时显示错误并提供可操作入口,不停在 loading", () => {
  2097. let capturedSelectedNavItem: ReturnType<typeof useModelProviderNavigation>["selectedNavItem"] =
  2098. null;
  2099. let unavailable = false;
  2100. function Harness() {
  2101. const { selectedNavItem, navigationUnavailable } = useModelProviderNavigation({
  2102. presetProviders: [
  2103. {
  2104. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2105. displayName: "Z.ai - API Key",
  2106. provider: createProvider({
  2107. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2108. }),
  2109. },
  2110. ],
  2111. modelProviders: [
  2112. createProvider({
  2113. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2114. name: "Z.ai - API Key",
  2115. }),
  2116. createProvider({
  2117. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2118. name: "Z.ai - Start Plan",
  2119. apiKey: "start-token",
  2120. }),
  2121. ],
  2122. codingPlanEntitlements: {
  2123. [BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan]: {
  2124. loading: false,
  2125. error: null,
  2126. snapshot: createEntitlementSnapshot({
  2127. provider: { id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan },
  2128. remaining: null,
  2129. subscription: {
  2130. identityType: "unknown",
  2131. identityMasked: null,
  2132. details: [
  2133. {
  2134. productId: "zcode-v3-start-plan",
  2135. productName: "Start Plan",
  2136. purchaseTime: null,
  2137. beginTime: null,
  2138. billingCycle: null,
  2139. renewTime: null,
  2140. expireTime: null,
  2141. },
  2142. ],
  2143. },
  2144. quota: null,
  2145. }),
  2146. },
  2147. },
  2148. selectedNodeKey: "preset:account:zai-start-plan",
  2149. modelProviderFamilyModes: {},
  2150. modelProviderFamilySelectedKeys: {},
  2151. familyConnectionSettingsFailed: true,
  2152. setSelectedNodeKey: vi.fn(),
  2153. intl: {
  2154. formatMessage: ({ id }: { id: string }) => id,
  2155. } as never,
  2156. });
  2157. capturedSelectedNavItem = selectedNavItem;
  2158. unavailable = navigationUnavailable;
  2159. return createElement("div");
  2160. }
  2161. renderToStaticMarkup(createElement(Harness));
  2162. expect(unavailable).toBe(true);
  2163. expect(capturedSelectedNavItem).toMatchObject({
  2164. type: "codingPlan",
  2165. status: "disconnected",
  2166. });
  2167. });
  2168. it("Team Plan 使用团队项目上下文生成连接入口", () => {
  2169. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  2170. [];
  2171. function Harness() {
  2172. const { navigationItems } = useModelProviderNavigation({
  2173. presetProviders: [],
  2174. modelProviders: [
  2175. createProvider({
  2176. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  2177. name: "BigModel - Coding Plan",
  2178. apiKey: "jwt-token",
  2179. }),
  2180. ],
  2181. subscribedTeamProducts: [
  2182. {
  2183. productId: "product-0e2085",
  2184. productName: "Pro",
  2185. productBigTitle: "Pro",
  2186. originalAmount: 100,
  2187. canRepurchase: true,
  2188. inCurrentPeriod: true,
  2189. productEquityList: [],
  2190. hasPreview: true,
  2191. enterpriseProduct: {
  2192. productId: "product-0e2085",
  2193. tier: "PRO",
  2194. subscribeMode: "CONTINUOUS",
  2195. subscribePeriod: "MONTHLY",
  2196. subscribed: true,
  2197. },
  2198. tier: "PRO",
  2199. subscribeMode: "CONTINUOUS",
  2200. subscribePeriod: "MONTHLY",
  2201. purchaseMethodName: "月付",
  2202. subscribed: true,
  2203. teamProjects: [
  2204. {
  2205. organizationId: "org-team",
  2206. organizationName: "默认机构",
  2207. projectId: "proj-team",
  2208. projectName: "团队编程套餐项目",
  2209. apiKeyStatus: "unavailable",
  2210. apiKeyUnavailableMessage: "您当前暂无有效的团队套餐授权记录,无法创建API Key",
  2211. },
  2212. ],
  2213. },
  2214. ],
  2215. selectedNodeKey: null,
  2216. setSelectedNodeKey: vi.fn(),
  2217. intl: {
  2218. formatMessage: ({ id }: { id: string }) => id,
  2219. } as never,
  2220. });
  2221. capturedNavigationItems = navigationItems;
  2222. return createElement("div");
  2223. }
  2224. renderToStaticMarkup(createElement(Harness));
  2225. const teamItem = capturedNavigationItems.find((item) => item.type === "teamPlan");
  2226. expect(teamItem).toMatchObject({
  2227. key: "team:bigmodel:product-0e2085:org-team:proj-team",
  2228. organizationId: "org-team",
  2229. projectId: "proj-team",
  2230. status: "unavailable",
  2231. availabilityReason: "credential-unavailable",
  2232. statusLabelId: undefined,
  2233. statusMessage: "您当前暂无有效的团队套餐授权记录,无法创建API Key",
  2234. });
  2235. const codingPlanItem = {
  2236. key: "coding-plan:account:bigmodel-individual-coding-plan",
  2237. type: "codingPlan" as const,
  2238. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  2239. oauthProviderId: BIGMODEL_PROVIDER_ID,
  2240. label: "BigModel - Coding Plan",
  2241. providerName: "BigModel",
  2242. provider: createProvider({
  2243. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  2244. }),
  2245. status: "purchased" as const,
  2246. statusActive: true,
  2247. };
  2248. expect(
  2249. resolveSelectedFamilyModeNodeKey({
  2250. selectedNavItem: codingPlanItem,
  2251. selectableNavigationItems: [codingPlanItem, teamItem!].filter(
  2252. (item) => item.type !== "codingPlanLoading",
  2253. ),
  2254. connectionSelections: {
  2255. bigmodel: {
  2256. kind: "team-coding-plan",
  2257. productId: "product-0e2085",
  2258. organizationId: "org-team",
  2259. projectId: "proj-team",
  2260. },
  2261. },
  2262. }),
  2263. ).toBe("team:bigmodel:product-0e2085:org-team:proj-team");
  2264. });
  2265. it("entitlement snapshot 带团队上下文时不依赖 enterprise pricing 展示 Team Plan", () => {
  2266. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  2267. [];
  2268. function Harness() {
  2269. const { navigationItems } = useModelProviderNavigation({
  2270. presetProviders: [
  2271. {
  2272. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  2273. displayName: "BigModel - API Key",
  2274. provider: createProvider({
  2275. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  2276. }),
  2277. },
  2278. ],
  2279. modelProviders: [
  2280. createProvider({
  2281. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  2282. name: "BigModel - Coding Plan",
  2283. apiKey: "jwt-token",
  2284. }),
  2285. ],
  2286. codingPlanEntitlements: {
  2287. [BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan]: {
  2288. loading: false,
  2289. error: null,
  2290. snapshot: createEntitlementSnapshot({
  2291. context: {
  2292. scope: "team",
  2293. organizationId: "org-current",
  2294. projectId: "project-current",
  2295. productId: "team-current",
  2296. displayName: "Coding Team",
  2297. },
  2298. subscription: {
  2299. identityType: "email",
  2300. identityMasked: "t***@z.ai",
  2301. details: [
  2302. {
  2303. productId: "team-current",
  2304. productName: "Coding Team",
  2305. purchaseTime: null,
  2306. beginTime: null,
  2307. expireTime: "2026-08-01T00:00:00Z",
  2308. },
  2309. ],
  2310. },
  2311. }),
  2312. },
  2313. },
  2314. subscribedTeamProducts: [],
  2315. showPurchasedTeamPlanFallback: false,
  2316. selectedNodeKey: null,
  2317. setSelectedNodeKey: vi.fn(),
  2318. intl: {
  2319. formatMessage: ({ id }: { id: string }) => id,
  2320. } as never,
  2321. });
  2322. capturedNavigationItems = navigationItems;
  2323. return createElement("div");
  2324. }
  2325. renderToStaticMarkup(createElement(Harness));
  2326. const teamPlan = capturedNavigationItems.find((item) => item.type === "teamPlan");
  2327. expect(teamPlan).toMatchObject({
  2328. key: "team:bigmodel:team-current:org-current:project-current",
  2329. teamPlanName: "Coding Team",
  2330. status: "purchased",
  2331. currentProductId: "team-current",
  2332. organizationId: "org-current",
  2333. projectId: "project-current",
  2334. });
  2335. });
  2336. it("Start 详情不因没有付费套餐显示连接控件", () => {
  2337. const startPlanItem = {
  2338. key: "coding-plan:account:zai-start-plan",
  2339. type: "codingPlan" as const,
  2340. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2341. oauthProviderId: ZAI_PROVIDER_ID,
  2342. label: "Z.ai - Start Plan",
  2343. providerName: "Z.ai",
  2344. provider: createProvider({
  2345. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2346. name: "Z.ai - Start Plan",
  2347. }),
  2348. status: "notPurchased" as const,
  2349. statusActive: false,
  2350. };
  2351. const oauthItem = {
  2352. key: "coding-plan:account:zai-individual-coding-plan",
  2353. type: "codingPlan" as const,
  2354. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  2355. oauthProviderId: ZAI_PROVIDER_ID,
  2356. label: "Z.ai - Coding Plan",
  2357. providerName: "Z.ai",
  2358. provider: createProvider({
  2359. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  2360. }),
  2361. status: "notPurchased" as const,
  2362. purchaseUrl: "https://z.ai/",
  2363. statusActive: false,
  2364. };
  2365. const html = renderDetail(startPlanItem, {
  2366. navigationItems: [startPlanItem, oauthItem],
  2367. connectionSelections: { zai: { kind: "individual-coding-plan" } },
  2368. onSelectNavItem: vi.fn(),
  2369. });
  2370. expect(html).not.toContain("settings.modelProvider.connectionMode");
  2371. expect(html).not.toContain('role="combobox"');
  2372. expect(html).not.toContain("settings.modelProvider.connectionMode.noAvailablePlan");
  2373. expect(html).not.toContain('disabled=""');
  2374. });
  2375. it("Coding Plan 状态同步中展示 checking,避免停留在旧的未连接状态", () => {
  2376. const oauthItem = {
  2377. key: "coding-plan:account:zai-individual-coding-plan",
  2378. type: "codingPlan" as const,
  2379. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  2380. oauthProviderId: ZAI_PROVIDER_ID,
  2381. label: "Z.ai - Coding Plan",
  2382. providerName: "Z.ai",
  2383. provider: createProvider({
  2384. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  2385. apiKey: "",
  2386. }),
  2387. status: "disconnected" as const,
  2388. purchaseUrl: "https://z.ai/",
  2389. statusActive: false,
  2390. };
  2391. const html = renderDetail(oauthItem, {
  2392. codingPlanStatusSyncProviderId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  2393. });
  2394. expect(html).toContain("settings.modelProvider.codingPlan.status.checking");
  2395. expect(html).not.toContain("settings.modelProvider.codingPlan.status.disconnected");
  2396. expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
  2397. });
  2398. it("StartPlanCard 使用远端 startPlanPreview 展示体验套餐权益", () => {
  2399. const html = renderToStaticMarkup(
  2400. createElement(StartPlanCard, {
  2401. preview: {
  2402. planId: "zcode-v3-start-plan",
  2403. name: "ZCode V3 Start Plan",
  2404. entitlements: [
  2405. {
  2406. grantUnits: 3_000_000,
  2407. meter: "model_usage",
  2408. period: "daily",
  2409. showName: "GLM-5.2",
  2410. unitType: "token",
  2411. },
  2412. {
  2413. grantUnits: 4_000_000,
  2414. meter: "model_usage",
  2415. period: "daily",
  2416. showName: "GLM-5-Turbo",
  2417. unitType: "token",
  2418. },
  2419. ],
  2420. },
  2421. }),
  2422. );
  2423. expect(html).toContain("settings.modelProvider.startPlan.quotaSectionTitle");
  2424. expect(html).toContain("ZCode V3 Start Plan");
  2425. expect(html).toContain("7 Million");
  2426. expect(html).toContain("tokens per day");
  2427. expect(html).toContain("GLM-5.2");
  2428. expect(html).toContain("GLM-5-Turbo");
  2429. expect(html).not.toContain("10M");
  2430. expect(html).not.toContain(">7M<");
  2431. expect(html.match(/3M/g)?.length).toBe(1);
  2432. expect(html.match(/4M/g)?.length).toBe(1);
  2433. expect(html.match(/tokens per day/g)?.length).toBe(1);
  2434. expect(html).toContain("Daily quota · GLM-5.2 3M · GLM-5-Turbo 4M");
  2435. expect(html).toContain("settings.modelProvider.startPlan.eligibleNewUser");
  2436. });
  2437. it("StartPlanCard 在模型额度相同时合并为 each 文案", () => {
  2438. const html = renderToStaticMarkup(
  2439. createElement(StartPlanCard, {
  2440. preview: {
  2441. planId: "zcode-v3-start-plan",
  2442. name: "ZCode V3 Start Plan",
  2443. entitlements: [
  2444. {
  2445. grantUnits: 10_000_000,
  2446. meter: "model_usage",
  2447. period: "daily",
  2448. showName: "GLM-5.2",
  2449. unitType: "token",
  2450. },
  2451. {
  2452. grantUnits: 10_000_000,
  2453. meter: "model_usage",
  2454. period: "daily",
  2455. showName: "GLM-5-Turbo",
  2456. unitType: "token",
  2457. },
  2458. ],
  2459. },
  2460. }),
  2461. );
  2462. expect(html).toContain("20 Million");
  2463. expect(html).toContain("Daily quota · GLM-5.2 / GLM-5-Turbo 10M each");
  2464. expect(html.match(/10M/g)?.length).toBe(1);
  2465. });
  2466. it("StartPlanCard 英文主额度使用完整 Million 文案", () => {
  2467. const html = renderToStaticMarkup(
  2468. createElement(StartPlanCard, {
  2469. preview: {
  2470. planId: "zcode-v3-start-plan",
  2471. name: "ZCode V3 Start Plan",
  2472. entitlements: [
  2473. {
  2474. grantUnits: 5_000_000,
  2475. meter: "model_usage",
  2476. period: "daily",
  2477. showName: "GLM-5.2",
  2478. unitType: "token",
  2479. },
  2480. ],
  2481. },
  2482. }),
  2483. );
  2484. expect(html).toContain("5 Million");
  2485. expect(html).toContain("tokens per day");
  2486. expect(html).toContain("Daily quota · GLM-5.2 5M");
  2487. expect(html).not.toContain(">5M<");
  2488. });
  2489. it("StartPlanCard 缺少远端权益时不展示本地硬编码 Trial plan", () => {
  2490. const html = renderToStaticMarkup(
  2491. createElement(StartPlanCard, {
  2492. preview: {
  2493. planId: "zcode-v3-start-plan",
  2494. name: "ZCode V3 Start Plan",
  2495. entitlements: [],
  2496. },
  2497. }),
  2498. );
  2499. expect(html).toBe("");
  2500. expect(html).not.toContain("settings.modelProvider.startPlan.summaryTitle");
  2501. expect(html).not.toContain("settings.modelProvider.startPlan.heroMetric");
  2502. expect(html).not.toContain("settings.modelProvider.startPlan.summaryDescription");
  2503. });
  2504. it("StartPlanCard 中文界面使用本地化紧凑单位展示体验套餐额度", () => {
  2505. intlMockState.locale = "zh-CN";
  2506. try {
  2507. const html = renderToStaticMarkup(
  2508. createElement(StartPlanCard, {
  2509. preview: {
  2510. planId: "zcode-v3-start-plan",
  2511. name: "ZCode V3 Start Plan",
  2512. entitlements: [
  2513. {
  2514. grantUnits: 30_000_000,
  2515. meter: "model_usage",
  2516. period: "daily",
  2517. showName: "GLM-5.2",
  2518. unitType: "token",
  2519. },
  2520. {
  2521. grantUnits: 10_000_000,
  2522. meter: "model_usage",
  2523. period: "daily",
  2524. showName: "GLM-5-Turbo",
  2525. unitType: "token",
  2526. },
  2527. ],
  2528. },
  2529. }),
  2530. );
  2531. expect(html).toContain("4000万");
  2532. expect(html).toContain("每日额度 · GLM-5.2 3000万 · GLM-5-Turbo 1000万");
  2533. expect(html).not.toContain("40M");
  2534. expect(html).not.toContain("30M");
  2535. expect(html).not.toContain("10M");
  2536. } finally {
  2537. intlMockState.locale = "en-US";
  2538. }
  2539. });
  2540. it("StartPlanCard 中文界面单模型每日额度使用本地化紧凑单位", () => {
  2541. intlMockState.locale = "zh-CN";
  2542. try {
  2543. const html = renderToStaticMarkup(
  2544. createElement(StartPlanCard, {
  2545. preview: {
  2546. planId: "zcode-v3-start-plan",
  2547. name: "ZCode V3 Start Plan",
  2548. entitlements: [
  2549. {
  2550. grantUnits: 5_000_000,
  2551. meter: "model_usage",
  2552. period: "daily",
  2553. showName: "GLM-5.2",
  2554. unitType: "token",
  2555. },
  2556. ],
  2557. },
  2558. }),
  2559. );
  2560. expect(html).toContain("500万");
  2561. expect(html).toContain("tokens/日");
  2562. expect(html).toContain("每日额度 · GLM-5.2 500万");
  2563. expect(html).not.toContain("5 Million");
  2564. expect(html).not.toContain("5M");
  2565. } finally {
  2566. intlMockState.locale = "en-US";
  2567. }
  2568. });
  2569. it("Z.ai Start Plan 编程套餐列表复用 Coding Plan 商品来源", () => {
  2570. expect(
  2571. resolveCodingPlanUpgradeProductsProviderId(BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan),
  2572. ).toBe(BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan);
  2573. });
  2574. it("Z.ai Start Plan 未登录且无远端 preview 时不显示 Trial plan 卡片", () => {
  2575. const html = renderDetail({
  2576. key: "coding-plan:account:zai-start-plan",
  2577. type: "codingPlan",
  2578. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2579. oauthProviderId: ZAI_PROVIDER_ID,
  2580. label: "Z.ai - Coding Plan",
  2581. providerName: "Z.ai",
  2582. provider: null,
  2583. status: "disconnected",
  2584. purchaseUrl: "https://z.ai/",
  2585. statusActive: false,
  2586. });
  2587. expect(html).toContain("settings.modelProvider.planCard.startPlan");
  2588. expect(html).not.toContain("settings.modelProvider.startPlan.summaryTitle");
  2589. expect(html).not.toContain("settings.modelProvider.startPlan.quotaSectionTitle");
  2590. expect(html).not.toContain("settings.modelProvider.startPlan.heroMetric");
  2591. expect(html).not.toContain("settings.modelProvider.startPlan.heroMetricUnit");
  2592. expect(html).not.toContain("settings.modelProvider.startPlan.summaryDescription");
  2593. expect(html).not.toContain("settings.modelProvider.startPlan.eligibleNewUser");
  2594. expect(html).not.toContain("settings.modelProvider.models");
  2595. expect(html).not.toContain("glm-4.7");
  2596. expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
  2597. expect(html).not.toContain("settings.modelProvider.codingPlan.login");
  2598. expect(html).toContain("settings.modelProvider.startPlan.status.loginRequired");
  2599. expect(html).not.toContain("settings.modelProvider.codingPlan.description.disconnected");
  2600. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.personalTitle");
  2601. expect(html).not.toContain(
  2602. "settings.modelProvider.codingPlan.purchaseBanner.personalDescription",
  2603. );
  2604. expect(html).not.toContain("CN¥49.00+");
  2605. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamTitle");
  2606. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamDescription");
  2607. expect(html).not.toContain("CN¥598.00+");
  2608. expect(html).not.toContain("settings.modelProvider.codingPlan.productsLoading");
  2609. expect(html).not.toContain("settings.modelProvider.baseUrl");
  2610. expectConnectionApiFormatHidden(html);
  2611. expect(html).not.toContain("settings.modelProvider.apiKeyPlaceholder");
  2612. expect(html).not.toContain("settings.modelProvider.disableAction");
  2613. expect(html).not.toContain("settings.modelProvider.addModel");
  2614. });
  2615. it("Z.ai Start 详情不显示体验套餐推广横幅", () => {
  2616. primeStartPlanPreviewCacheForTest({
  2617. planId: "zcode-v3-start-plan",
  2618. name: "ZCode V3 Start Plan",
  2619. entitlements: [
  2620. {
  2621. grantUnits: 5_000_000,
  2622. meter: "model_usage",
  2623. period: "daily",
  2624. showName: "GLM-5.2",
  2625. unitType: "token",
  2626. },
  2627. ],
  2628. });
  2629. const html = renderDetail({
  2630. key: "coding-plan:account:zai-start-plan",
  2631. type: "codingPlan",
  2632. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2633. oauthProviderId: ZAI_PROVIDER_ID,
  2634. label: "Z.ai - Coding Plan",
  2635. providerName: "Z.ai",
  2636. provider: null,
  2637. status: "disconnected",
  2638. purchaseUrl: "https://z.ai/",
  2639. statusActive: false,
  2640. });
  2641. expect(html).not.toContain("ZCode V3 Start Plan");
  2642. expect(html).not.toContain("5 Million");
  2643. expect(html).not.toContain("Daily quota · GLM-5.2 5M");
  2644. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.personalTitle");
  2645. expect(html).not.toContain("CN¥49.00+");
  2646. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamTitle");
  2647. expect(html).not.toContain("CN¥598.00+");
  2648. });
  2649. it("Z.ai Coding Plan 未连接时显示 Plan Card 且不显示 API Key 字段", () => {
  2650. const html = renderDetail({
  2651. key: "coding-plan:account:zai-individual-coding-plan",
  2652. type: "codingPlan",
  2653. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  2654. oauthProviderId: ZAI_PROVIDER_ID,
  2655. label: "Z.ai - Coding Plan",
  2656. providerName: "Z.ai",
  2657. provider: null,
  2658. status: "disconnected",
  2659. purchaseUrl: "https://z.ai/",
  2660. statusActive: false,
  2661. });
  2662. expect(html).toContain("settings.modelProvider.planCard.codingPlan");
  2663. expect(html).toContain("settings.modelProvider.codingPlan.status.disconnected");
  2664. expect(html).toContain("settings.modelProvider.codingPlan.connect");
  2665. expect(html).not.toContain("settings.modelProvider.codingPlan.dynamicUnsupportedTitle");
  2666. expect(html).not.toContain("settings.modelProvider.codingPlan.productsLoading");
  2667. expect(html).not.toContain("settings.modelProvider.codingPlan.zai.plan.lite.name");
  2668. expect(html).not.toContain("settings.modelProvider.codingPlan.zai.plan.pro.name");
  2669. expect(html).not.toContain("settings.modelProvider.codingPlan.zai.plan.max.name");
  2670. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.personalTitle");
  2671. expect(html).not.toContain(
  2672. "settings.modelProvider.codingPlan.purchaseBanner.personalDescription",
  2673. );
  2674. expect(html).not.toContain("CN¥49.00+");
  2675. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamTitle");
  2676. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamDescription");
  2677. expect(html).not.toContain("CN¥598.00+");
  2678. expect(html).not.toContain("settings.modelProvider.codingPlan.useApiKeyProvider");
  2679. expect(html).not.toContain("settings.modelProvider.apiKey");
  2680. });
  2681. it("BigModel Coding Plan 会按自己的 quota 权益解析为已购买", () => {
  2682. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  2683. [];
  2684. function Harness() {
  2685. const { navigationItems } = useModelProviderNavigation({
  2686. presetProviders: [],
  2687. modelProviders: [
  2688. createProvider({
  2689. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  2690. name: "BigModel - Coding Plan",
  2691. }),
  2692. ],
  2693. entitledAccountProviderIds: new Set([
  2694. BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  2695. ]),
  2696. codingPlanEntitlements: {
  2697. [BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan]: {
  2698. snapshot: createEntitlementSnapshot(),
  2699. loading: false,
  2700. error: null,
  2701. },
  2702. },
  2703. selectedNodeKey: null,
  2704. setSelectedNodeKey: vi.fn(),
  2705. intl: {
  2706. formatMessage: ({ id }: { id: string }) => id,
  2707. } as never,
  2708. });
  2709. capturedNavigationItems = navigationItems;
  2710. return createElement("div");
  2711. }
  2712. renderToStaticMarkup(createElement(Harness));
  2713. const bigmodelCodingPlan = capturedNavigationItems.find(
  2714. (item) =>
  2715. item.type === "codingPlan" &&
  2716. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  2717. );
  2718. expect(bigmodelCodingPlan).toMatchObject({
  2719. status: "purchased",
  2720. statusActive: true,
  2721. currentProductId: "pro",
  2722. subscriptionBillingCycle: "monthly",
  2723. subscriptionExpireTime: "2026-12-31T00:00:00.000Z",
  2724. });
  2725. });
  2726. it("Coding Plan 已购买但 provider 禁用时导航状态点不点亮", () => {
  2727. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  2728. [];
  2729. function Harness() {
  2730. const { navigationItems } = useModelProviderNavigation({
  2731. presetProviders: [],
  2732. modelProviders: [
  2733. createProvider({
  2734. enabled: false,
  2735. }),
  2736. ],
  2737. entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]),
  2738. codingPlanEntitlements: {
  2739. [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
  2740. snapshot: createEntitlementSnapshot({
  2741. provider: {
  2742. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  2743. name: "Z.ai - Coding Plan",
  2744. },
  2745. }),
  2746. loading: false,
  2747. error: null,
  2748. },
  2749. },
  2750. selectedNodeKey: null,
  2751. setSelectedNodeKey: vi.fn(),
  2752. intl: {
  2753. formatMessage: ({ id }: { id: string }) => id,
  2754. } as never,
  2755. });
  2756. capturedNavigationItems = navigationItems;
  2757. return createElement("div");
  2758. }
  2759. renderToStaticMarkup(createElement(Harness));
  2760. const zaiCodingPlan = capturedNavigationItems.find(
  2761. (item) =>
  2762. item.type === "codingPlan" &&
  2763. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  2764. );
  2765. expect(zaiCodingPlan).toMatchObject({
  2766. status: "purchased",
  2767. statusActive: false,
  2768. });
  2769. });
  2770. it("quota 重置时间不显示在 Coding Plan 状态卡片", () => {
  2771. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  2772. [];
  2773. function Harness() {
  2774. const { navigationItems } = useModelProviderNavigation({
  2775. presetProviders: [],
  2776. modelProviders: [
  2777. createProvider({
  2778. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  2779. name: "BigModel - Coding Plan",
  2780. }),
  2781. ],
  2782. entitledAccountProviderIds: new Set([
  2783. BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  2784. ]),
  2785. codingPlanEntitlements: {
  2786. [BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan]: {
  2787. snapshot: createEntitlementSnapshot({
  2788. subscription: {
  2789. identityType: "unknown",
  2790. identityMasked: null,
  2791. details: [
  2792. {
  2793. productId: "personal",
  2794. productName: "GLM Coding Pro",
  2795. purchaseTime: null,
  2796. beginTime: null,
  2797. renewTime: null,
  2798. expireTime: null,
  2799. },
  2800. ],
  2801. },
  2802. quota: {
  2803. level: "pro",
  2804. limits: [
  2805. {
  2806. type: "TOKENS_LIMIT",
  2807. unit: 3,
  2808. number: 5,
  2809. nextResetTime: Date.UTC(2026, 4, 26),
  2810. usageDetails: [],
  2811. },
  2812. {
  2813. type: "TOKENS_LIMIT",
  2814. unit: 6,
  2815. nextResetTime: Date.UTC(2026, 4, 27),
  2816. usageDetails: [],
  2817. },
  2818. {
  2819. type: "TIME_LIMIT",
  2820. unit: 5,
  2821. number: 1,
  2822. nextResetTime: Date.UTC(2026, 4, 28),
  2823. usageDetails: [],
  2824. },
  2825. ],
  2826. },
  2827. }),
  2828. loading: false,
  2829. error: null,
  2830. },
  2831. },
  2832. selectedNodeKey: null,
  2833. setSelectedNodeKey: vi.fn(),
  2834. intl: {
  2835. formatMessage: ({ id }: { id: string }) => id,
  2836. } as never,
  2837. });
  2838. capturedNavigationItems = navigationItems;
  2839. return createElement("div");
  2840. }
  2841. renderToStaticMarkup(createElement(Harness));
  2842. const bigmodelCodingPlan = capturedNavigationItems.find(
  2843. (item) =>
  2844. item.type === "codingPlan" &&
  2845. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  2846. );
  2847. expect(bigmodelCodingPlan).toMatchObject({
  2848. status: "purchased",
  2849. });
  2850. expect(bigmodelCodingPlan).not.toHaveProperty("resetTimes");
  2851. });
  2852. it("API Key provider 已配置时不会让对应 Coding Plan 变成已连接", () => {
  2853. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  2854. [];
  2855. function Harness() {
  2856. const { navigationItems } = useModelProviderNavigation({
  2857. presetProviders: [],
  2858. modelProviders: [
  2859. createProvider({
  2860. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2861. name: "Z.ai - API Key",
  2862. }),
  2863. createProvider({
  2864. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  2865. name: "BigModel - API Key",
  2866. }),
  2867. ],
  2868. selectedNodeKey: null,
  2869. setSelectedNodeKey: vi.fn(),
  2870. intl: {
  2871. formatMessage: ({ id }: { id: string }) => id,
  2872. } as never,
  2873. });
  2874. capturedNavigationItems = navigationItems;
  2875. return createElement("div");
  2876. }
  2877. renderToStaticMarkup(createElement(Harness));
  2878. const codingPlanItems = capturedNavigationItems.filter((item) => item.type === "codingPlan");
  2879. expect(codingPlanItems?.map((item) => item.presetId)).toEqual([
  2880. BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2881. BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  2882. BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  2883. BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  2884. ]);
  2885. expect(codingPlanItems?.map((item) => item.status)).toEqual([
  2886. "disconnected",
  2887. "disconnected",
  2888. "disconnected",
  2889. "disconnected",
  2890. ]);
  2891. });
  2892. it("未登录 Start/Coding 时仍允许保持 Coding Plan 选中项", () => {
  2893. const apiKeyItem = {
  2894. key: "preset:account:zai-start-plan",
  2895. type: "preset" as const,
  2896. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2897. label: "Z.ai - API Key",
  2898. provider: createProvider({
  2899. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2900. name: "Z.ai - API Key",
  2901. }),
  2902. displayName: "Z.ai - API Key",
  2903. statusActive: true,
  2904. };
  2905. const startItem = {
  2906. key: "coding-plan:account:zai-start-plan",
  2907. type: "codingPlan" as const,
  2908. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2909. oauthProviderId: ZAI_PROVIDER_ID,
  2910. label: "Z.ai - Coding Plan",
  2911. providerName: "Z.ai",
  2912. provider: null,
  2913. status: "disconnected" as const,
  2914. planLevel: null,
  2915. currentProductId: null,
  2916. subscriptionBillingCycle: null,
  2917. subscriptionRenewTime: null,
  2918. subscriptionExpireTime: null,
  2919. quotaLimits: [],
  2920. purchaseUrl: "https://z.ai/",
  2921. statusActive: false,
  2922. };
  2923. const selectedNodeKey = resolveSelectedFamilyModeNodeKey({
  2924. selectedNavItem: startItem,
  2925. selectableNavigationItems: [apiKeyItem, startItem],
  2926. modelProviderFamilyModes: {
  2927. zai: "oauth",
  2928. },
  2929. });
  2930. expect(selectedNodeKey).toBeNull();
  2931. });
  2932. it("未登录加载时保留独立 Start 与 Coding,不显示 loading 占位", () => {
  2933. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  2934. [];
  2935. function Harness() {
  2936. const { navigationItems } = useModelProviderNavigation({
  2937. presetProviders: [],
  2938. modelProviders: [],
  2939. modelProvidersLoading: true,
  2940. selectedNodeKey: null,
  2941. setSelectedNodeKey: vi.fn(),
  2942. intl: {
  2943. formatMessage: ({ id }: { id: string }) => id,
  2944. } as never,
  2945. });
  2946. capturedNavigationItems = navigationItems;
  2947. return createElement("div");
  2948. }
  2949. renderToStaticMarkup(createElement(Harness));
  2950. const zaiPlanItems = capturedNavigationItems.filter(
  2951. (item) =>
  2952. (item.type === "codingPlan" &&
  2953. (item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan ||
  2954. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan)) ||
  2955. item.type === "codingPlanLoading",
  2956. );
  2957. expect(zaiPlanItems).toEqual([
  2958. expect.objectContaining({
  2959. type: "codingPlan",
  2960. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  2961. }),
  2962. expect.objectContaining({
  2963. type: "codingPlan",
  2964. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  2965. status: "checking",
  2966. }),
  2967. ]);
  2968. });
  2969. it("Coding 权益未返回时仍保留独立 Start", () => {
  2970. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  2971. [];
  2972. const setSelectedNodeKey = vi.fn();
  2973. function Harness() {
  2974. const { navigationItems } = useModelProviderNavigation({
  2975. presetProviders: [],
  2976. modelProviders: [
  2977. createProvider({
  2978. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  2979. name: "Z.ai - Coding Plan",
  2980. apiKey: "jwt-token",
  2981. }),
  2982. ],
  2983. entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]),
  2984. selectedNodeKey: null,
  2985. setSelectedNodeKey,
  2986. intl: {
  2987. formatMessage: ({ id }: { id: string }) => id,
  2988. } as never,
  2989. });
  2990. capturedNavigationItems = navigationItems;
  2991. return createElement("div");
  2992. }
  2993. renderToStaticMarkup(createElement(Harness));
  2994. const zaiPlanItems = capturedNavigationItems.filter(
  2995. (item) =>
  2996. (item.type === "codingPlan" &&
  2997. (item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan ||
  2998. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan)) ||
  2999. item.type === "codingPlanLoading",
  3000. );
  3001. expect(zaiPlanItems).toEqual([
  3002. expect.objectContaining({
  3003. type: "codingPlan",
  3004. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3005. }),
  3006. expect.objectContaining({
  3007. type: "codingPlan",
  3008. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3009. }),
  3010. ]);
  3011. expect(setSelectedNodeKey).not.toHaveBeenCalledWith("coding-plan:zai:loading");
  3012. });
  3013. it("未登录时保留个人 Coding Plan 与独立 Start Plan", () => {
  3014. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  3015. [];
  3016. function Harness() {
  3017. const { navigationItems } = useModelProviderNavigation({
  3018. presetProviders: [],
  3019. modelProviders: [],
  3020. selectedNodeKey: null,
  3021. setSelectedNodeKey: vi.fn(),
  3022. intl: {
  3023. formatMessage: ({ id }: { id: string }) => id,
  3024. } as never,
  3025. });
  3026. capturedNavigationItems = navigationItems;
  3027. return createElement("div");
  3028. }
  3029. renderToStaticMarkup(createElement(Harness));
  3030. const zaiCodingPlan = capturedNavigationItems.find(
  3031. (item) =>
  3032. item.type === "codingPlan" &&
  3033. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3034. );
  3035. const zaiStartPlan = capturedNavigationItems.find(
  3036. (item) =>
  3037. item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3038. );
  3039. const bigmodelCodingPlan = capturedNavigationItems.find(
  3040. (item) =>
  3041. item.type === "codingPlan" &&
  3042. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  3043. );
  3044. const bigmodelStartPlan = capturedNavigationItems.find(
  3045. (item) =>
  3046. item.type === "codingPlan" &&
  3047. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  3048. );
  3049. expect(zaiCodingPlan).toMatchObject({
  3050. status: "disconnected",
  3051. statusActive: false,
  3052. });
  3053. expect(zaiStartPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
  3054. expect(bigmodelCodingPlan).toMatchObject({
  3055. status: "disconnected",
  3056. statusActive: false,
  3057. });
  3058. expect(bigmodelStartPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
  3059. expect(
  3060. capturedNavigationItems.some(
  3061. (item) =>
  3062. item.type === "codingPlan" &&
  3063. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3064. ),
  3065. ).toBe(true);
  3066. expect(
  3067. capturedNavigationItems.some(
  3068. (item) =>
  3069. item.type === "codingPlan" &&
  3070. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  3071. ),
  3072. ).toBe(true);
  3073. });
  3074. it("Start 过期快照显示过期提示且隐藏余额和模型,即使旧 Account 仍 available", () => {
  3075. const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan;
  3076. const state = resolveCodingPlanEntitlementState({
  3077. providerId,
  3078. accountEntitled: true,
  3079. modelProvidersLoading: false,
  3080. entitlement: {
  3081. loading: false,
  3082. error: null,
  3083. snapshot: createEntitlementSnapshot({
  3084. unavailableReason: "no_plan",
  3085. startPlanExpired: true,
  3086. subscription: null,
  3087. quota: null,
  3088. remaining: null,
  3089. }),
  3090. },
  3091. });
  3092. expect(state.status).toBe("notPurchased");
  3093. expect(state.statusLabelId).toBe("settings.modelProvider.startPlan.status.expired");
  3094. const provider = createProvider({ id: providerId, models: ["expired-start-model"] });
  3095. const html = renderDetail(
  3096. {
  3097. key: `coding-plan:${providerId}`,
  3098. type: "codingPlan",
  3099. presetId: providerId,
  3100. oauthProviderId: BIGMODEL_PROVIDER_ID,
  3101. providerName: "BigModel",
  3102. label: "Start Plan",
  3103. provider,
  3104. ...state,
  3105. statusActive: false,
  3106. },
  3107. { providerSettingsView: createProviderSettingsView(provider) },
  3108. );
  3109. expect(html).toContain("settings.modelProvider.startPlan.status.expired");
  3110. expect(html).not.toContain("expired-start-model");
  3111. expect(html).not.toContain("settings.modelProvider.startPlan.balance.title");
  3112. });
  3113. it("Z.ai Coding Plan 无付费权益时不复用 Start 免费态", () => {
  3114. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  3115. [];
  3116. function Harness() {
  3117. const { navigationItems } = useModelProviderNavigation({
  3118. presetProviders: [],
  3119. modelProviders: [
  3120. createProvider({
  3121. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3122. name: "Z.ai - Coding Plan",
  3123. apiKey: "jwt-token",
  3124. }),
  3125. ],
  3126. entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]),
  3127. codingPlanEntitlements: {
  3128. [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
  3129. snapshot: createEntitlementSnapshot({
  3130. provider: {
  3131. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3132. name: "Z.ai - Coding Plan",
  3133. },
  3134. remaining: null,
  3135. subscription: null,
  3136. quota: null,
  3137. unavailableReason: "no_plan",
  3138. }),
  3139. loading: false,
  3140. error: null,
  3141. },
  3142. },
  3143. selectedNodeKey: null,
  3144. setSelectedNodeKey: vi.fn(),
  3145. intl: {
  3146. formatMessage: ({ id }: { id: string }) => id,
  3147. } as never,
  3148. });
  3149. capturedNavigationItems = navigationItems;
  3150. return createElement("div");
  3151. }
  3152. renderToStaticMarkup(createElement(Harness));
  3153. const zaiCodingPlan = capturedNavigationItems.find(
  3154. (item) =>
  3155. item.type === "codingPlan" &&
  3156. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3157. );
  3158. const zaiStartPlan = capturedNavigationItems.find(
  3159. (item) =>
  3160. item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3161. );
  3162. expect(zaiCodingPlan).toMatchObject({
  3163. status: "notPurchased",
  3164. statusActive: true,
  3165. });
  3166. expect(zaiStartPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
  3167. });
  3168. it("Z.ai 已登录且只有 Start 有权益时显示 Start 和个人 Coding Plan", () => {
  3169. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  3170. [];
  3171. function Harness() {
  3172. const { navigationItems } = useModelProviderNavigation({
  3173. presetProviders: [],
  3174. modelProviders: [
  3175. createProvider({
  3176. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3177. name: "Z.ai - Coding Plan",
  3178. apiKey: "zai-coding-plan-key",
  3179. }),
  3180. createProvider({
  3181. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3182. name: "Z.ai - Coding Plan",
  3183. apiKey: "zcode-jwt",
  3184. }),
  3185. ],
  3186. entitledAccountProviderIds: new Set([
  3187. BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3188. BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3189. ]),
  3190. codingPlanEntitlements: {
  3191. [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
  3192. snapshot: createEntitlementSnapshot({
  3193. provider: {
  3194. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3195. name: "Z.ai - Coding Plan",
  3196. },
  3197. remaining: null,
  3198. subscription: null,
  3199. quota: null,
  3200. unavailableReason: "no_plan",
  3201. }),
  3202. loading: false,
  3203. error: null,
  3204. },
  3205. [BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan]: {
  3206. snapshot: createEntitlementSnapshot({
  3207. provider: {
  3208. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3209. name: "Z.ai - Coding Plan",
  3210. },
  3211. subscription: {
  3212. identityType: "unknown",
  3213. identityMasked: null,
  3214. details: [
  3215. {
  3216. productId: "zcode-v3-start-plan",
  3217. productName: "ZCode V3 Start Plan",
  3218. purchaseTime: null,
  3219. beginTime: null,
  3220. billingCycle: "daily",
  3221. renewTime: "2026-06-04T00:00:00.000Z",
  3222. expireTime: "2026-06-08T00:00:00.000Z",
  3223. },
  3224. ],
  3225. },
  3226. quota: null,
  3227. }),
  3228. loading: false,
  3229. error: null,
  3230. },
  3231. },
  3232. selectedNodeKey: null,
  3233. setSelectedNodeKey: vi.fn(),
  3234. intl: {
  3235. formatMessage: ({ id }: { id: string }) => id,
  3236. } as never,
  3237. });
  3238. capturedNavigationItems = navigationItems;
  3239. return createElement("div");
  3240. }
  3241. renderToStaticMarkup(createElement(Harness));
  3242. const zaiCodingPlan = capturedNavigationItems.find(
  3243. (item) =>
  3244. item.type === "codingPlan" &&
  3245. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3246. );
  3247. const zaiStartPlan = capturedNavigationItems.find(
  3248. (item) =>
  3249. item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3250. );
  3251. expect(zaiCodingPlan).toMatchObject({
  3252. status: "notPurchased",
  3253. statusActive: true,
  3254. });
  3255. expect(zaiStartPlan).toMatchObject({
  3256. status: "purchased",
  3257. currentProductId: "zcode-v3-start-plan",
  3258. statusActive: true,
  3259. });
  3260. });
  3261. it("Z.ai 未登录且缺少 Coding Key 时仍显示独立 Start", () => {
  3262. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  3263. [];
  3264. function Harness() {
  3265. const { navigationItems } = useModelProviderNavigation({
  3266. presetProviders: [],
  3267. modelProviders: [
  3268. createProvider({
  3269. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3270. name: "Z.ai - Coding Plan",
  3271. apiKey: "",
  3272. }),
  3273. ],
  3274. codingPlanEntitlements: {
  3275. [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
  3276. snapshot: createEntitlementSnapshot({
  3277. provider: {
  3278. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3279. name: "Z.ai - Coding Plan",
  3280. },
  3281. remaining: null,
  3282. subscription: null,
  3283. quota: null,
  3284. unavailableReason: "no_plan",
  3285. }),
  3286. loading: false,
  3287. error: null,
  3288. },
  3289. },
  3290. selectedNodeKey: null,
  3291. setSelectedNodeKey: vi.fn(),
  3292. intl: {
  3293. formatMessage: ({ id }: { id: string }) => id,
  3294. } as never,
  3295. });
  3296. capturedNavigationItems = navigationItems;
  3297. return createElement("div");
  3298. }
  3299. renderToStaticMarkup(createElement(Harness));
  3300. const zaiCodingPlan = capturedNavigationItems.find(
  3301. (item) =>
  3302. item.type === "codingPlan" &&
  3303. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3304. );
  3305. const zaiStartPlan = capturedNavigationItems.find(
  3306. (item) =>
  3307. item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3308. );
  3309. expect(zaiCodingPlan).toMatchObject({
  3310. status: "disconnected",
  3311. planLevel: null,
  3312. });
  3313. expect(zaiStartPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
  3314. });
  3315. it("Z.ai Start 登录后入口互斥时回落到可见的 Z.ai plan", () => {
  3316. const fallbackNodeKey = resolveFallbackModelProviderNodeKey({
  3317. selectedNodeKey: "coding-plan:account:zai-start-plan",
  3318. selectableNavigationItems: [
  3319. {
  3320. key: "preset:account:zai-start-plan",
  3321. type: "preset",
  3322. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3323. label: "Z.ai - API Key",
  3324. provider: createProvider({
  3325. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3326. }),
  3327. displayName: "Z.ai - API Key",
  3328. statusActive: true,
  3329. },
  3330. {
  3331. key: "coding-plan:account:zai-individual-coding-plan",
  3332. type: "codingPlan",
  3333. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3334. oauthProviderId: ZAI_PROVIDER_ID,
  3335. label: "Z.ai - Coding Plan",
  3336. providerName: "Z.ai",
  3337. provider: createProvider({
  3338. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3339. apiKey: "zai-coding-plan-key",
  3340. }),
  3341. status: "purchased",
  3342. planLevel: "pro",
  3343. currentProductId: "product-zai-pro-monthly",
  3344. subscriptionBillingCycle: null,
  3345. subscriptionRenewTime: null,
  3346. subscriptionExpireTime: null,
  3347. quotaLimits: [],
  3348. purchaseUrl: "https://z.ai/manage-apikey/subscription",
  3349. statusActive: true,
  3350. },
  3351. ],
  3352. });
  3353. expect(fallbackNodeKey).toBe("preset:account:zai-start-plan");
  3354. });
  3355. it("BigModel 登录后当前选中项不可见时回落到 BigModel Coding Plan", () => {
  3356. const fallbackNodeKey = resolveFallbackModelProviderNodeKey({
  3357. selectedNodeKey: "coding-plan:account:zai-individual-coding-plan",
  3358. selectableNavigationItems: [
  3359. {
  3360. key: "preset:account:bigmodel-start-plan",
  3361. type: "preset",
  3362. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  3363. label: "BigModel - API Key",
  3364. provider: createProvider({
  3365. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  3366. }),
  3367. displayName: "BigModel - API Key",
  3368. statusActive: true,
  3369. },
  3370. {
  3371. key: "coding-plan:account:bigmodel-individual-coding-plan",
  3372. type: "codingPlan",
  3373. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  3374. oauthProviderId: BIGMODEL_PROVIDER_ID,
  3375. label: "BigModel - Coding Plan",
  3376. providerName: "BigModel",
  3377. provider: createProvider({
  3378. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  3379. apiKey: "bigmodel-coding-plan-key",
  3380. }),
  3381. status: "purchased",
  3382. planLevel: "pro",
  3383. currentProductId: "product-bigmodel-pro-monthly",
  3384. subscriptionBillingCycle: null,
  3385. subscriptionRenewTime: null,
  3386. subscriptionExpireTime: null,
  3387. quotaLimits: [],
  3388. purchaseUrl: "https://bigmodel.cn/",
  3389. statusActive: true,
  3390. },
  3391. ],
  3392. });
  3393. expect(fallbackNodeKey).toBe("preset:account:bigmodel-start-plan");
  3394. });
  3395. it("首次进入 Model Providers 默认选中可见的 Z.ai Coding Plan", () => {
  3396. const fallbackNodeKey = resolveFallbackModelProviderNodeKey({
  3397. selectedNodeKey: null,
  3398. selectableNavigationItems: [
  3399. {
  3400. key: "preset:account:zai-start-plan",
  3401. type: "preset",
  3402. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3403. label: "Z.ai - API Key",
  3404. provider: createProvider({
  3405. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3406. }),
  3407. displayName: "Z.ai - API Key",
  3408. statusActive: true,
  3409. },
  3410. {
  3411. key: "coding-plan:account:zai-individual-coding-plan",
  3412. type: "codingPlan",
  3413. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3414. oauthProviderId: ZAI_PROVIDER_ID,
  3415. label: "Z.ai - Coding Plan",
  3416. providerName: "Z.ai",
  3417. provider: createProvider({
  3418. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3419. apiKey: "zai-coding-plan-key",
  3420. }),
  3421. status: "purchased",
  3422. planLevel: "pro",
  3423. currentProductId: "product-zai-pro-monthly",
  3424. subscriptionBillingCycle: null,
  3425. subscriptionRenewTime: null,
  3426. subscriptionExpireTime: null,
  3427. quotaLimits: [],
  3428. purchaseUrl: "https://z.ai/manage-apikey/subscription",
  3429. statusActive: true,
  3430. },
  3431. ],
  3432. });
  3433. expect(fallbackNodeKey).toBe("preset:account:zai-start-plan");
  3434. });
  3435. it("首次进入 Model Providers Start 和个人 Coding 都有权益时仍选中 family 节点", () => {
  3436. const fallbackNodeKey = resolveFallbackModelProviderNodeKey({
  3437. selectedNodeKey: null,
  3438. selectableNavigationItems: [
  3439. {
  3440. key: "preset:account:zai-start-plan",
  3441. type: "preset",
  3442. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3443. label: "Z.ai - API Key",
  3444. provider: createProvider({
  3445. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3446. }),
  3447. displayName: "Z.ai - API Key",
  3448. statusActive: true,
  3449. },
  3450. {
  3451. key: "coding-plan:account:zai-individual-coding-plan",
  3452. type: "codingPlan",
  3453. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3454. oauthProviderId: ZAI_PROVIDER_ID,
  3455. label: "Z.ai - Coding Plan",
  3456. providerName: "Z.ai",
  3457. provider: createProvider({
  3458. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3459. apiKey: "zai-coding-plan-key",
  3460. }),
  3461. status: "purchased",
  3462. planLevel: "pro",
  3463. currentProductId: "product-zai-pro-monthly",
  3464. subscriptionBillingCycle: null,
  3465. subscriptionRenewTime: null,
  3466. subscriptionExpireTime: null,
  3467. quotaLimits: [],
  3468. purchaseUrl: "https://z.ai/manage-apikey/subscription",
  3469. statusActive: true,
  3470. },
  3471. {
  3472. key: "coding-plan:account:zai-start-plan",
  3473. type: "codingPlan",
  3474. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3475. oauthProviderId: ZAI_PROVIDER_ID,
  3476. label: "Z.ai - 体验套餐",
  3477. providerName: "Z.ai",
  3478. provider: createProvider({
  3479. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3480. apiKey: "zcode-jwt",
  3481. }),
  3482. status: "purchased",
  3483. planLevel: "Free",
  3484. currentProductId: "zcode-v3-start-plan",
  3485. subscriptionBillingCycle: null,
  3486. subscriptionRenewTime: null,
  3487. subscriptionExpireTime: null,
  3488. quotaLimits: [],
  3489. purchaseUrl: "https://z.ai/manage-apikey/subscription",
  3490. statusActive: true,
  3491. },
  3492. ],
  3493. });
  3494. expect(fallbackNodeKey).toBe("preset:account:zai-start-plan");
  3495. });
  3496. it("首次进入 Model Providers 个人 Coding 不可用时默认选中第一个 Team Plan", () => {
  3497. const teamPlanItemA = {
  3498. key: "team:bigmodel:product-team-a",
  3499. type: "teamPlan" as const,
  3500. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  3501. oauthProviderId: BIGMODEL_PROVIDER_ID,
  3502. label: "BigModel - Team A",
  3503. providerName: "BigModel",
  3504. provider: createProvider({
  3505. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  3506. }),
  3507. status: "purchased" as const,
  3508. planLevel: "team",
  3509. teamPlanName: "Team A",
  3510. organizationId: "org-a",
  3511. projectId: "proj-a",
  3512. currentProductId: "product-team-a",
  3513. subscriptionBillingCycle: null,
  3514. subscriptionRenewTime: null,
  3515. subscriptionExpireTime: null,
  3516. quotaLimits: [],
  3517. statusActive: true,
  3518. };
  3519. const teamPlanItemB = {
  3520. ...teamPlanItemA,
  3521. key: "team:bigmodel:product-team-b",
  3522. label: "BigModel - Team B",
  3523. teamPlanName: "Team B",
  3524. organizationId: "org-b",
  3525. projectId: "proj-b",
  3526. currentProductId: "product-team-b",
  3527. };
  3528. const fallbackNodeKey = resolveFallbackModelProviderNodeKey({
  3529. selectedNodeKey: null,
  3530. selectableNavigationItems: [
  3531. {
  3532. key: "preset:account:bigmodel-start-plan",
  3533. type: "preset",
  3534. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  3535. label: "BigModel - API Key",
  3536. provider: createProvider({
  3537. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  3538. }),
  3539. displayName: "BigModel - API Key",
  3540. statusActive: true,
  3541. },
  3542. {
  3543. key: "coding-plan:account:bigmodel-individual-coding-plan",
  3544. type: "codingPlan",
  3545. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  3546. oauthProviderId: BIGMODEL_PROVIDER_ID,
  3547. label: "BigModel - Coding Plan",
  3548. providerName: "BigModel",
  3549. provider: createProvider({
  3550. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  3551. }),
  3552. status: "notPurchased",
  3553. planLevel: null,
  3554. currentProductId: null,
  3555. subscriptionBillingCycle: null,
  3556. subscriptionRenewTime: null,
  3557. subscriptionExpireTime: null,
  3558. quotaLimits: [],
  3559. purchaseUrl: "https://bigmodel.cn/",
  3560. statusActive: true,
  3561. },
  3562. teamPlanItemA,
  3563. teamPlanItemB,
  3564. ],
  3565. });
  3566. expect(fallbackNodeKey).toBe("preset:account:bigmodel-start-plan");
  3567. });
  3568. it("首次进入 Model Providers 没有套餐权益时默认选中 API Key", () => {
  3569. const fallbackNodeKey = resolveFallbackModelProviderNodeKey({
  3570. selectedNodeKey: null,
  3571. selectableNavigationItems: [
  3572. {
  3573. key: "preset:account:zai-start-plan",
  3574. type: "preset",
  3575. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3576. label: "Z.ai - API Key",
  3577. provider: createProvider({
  3578. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3579. }),
  3580. displayName: "Z.ai - API Key",
  3581. statusActive: true,
  3582. },
  3583. {
  3584. key: "coding-plan:account:zai-start-plan",
  3585. type: "codingPlan",
  3586. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3587. oauthProviderId: ZAI_PROVIDER_ID,
  3588. label: "Z.ai - 体验套餐",
  3589. providerName: "Z.ai",
  3590. provider: null,
  3591. status: "disconnected",
  3592. planLevel: null,
  3593. currentProductId: null,
  3594. subscriptionBillingCycle: null,
  3595. subscriptionRenewTime: null,
  3596. subscriptionExpireTime: null,
  3597. quotaLimits: [],
  3598. purchaseUrl: "https://z.ai/manage-apikey/subscription",
  3599. statusActive: false,
  3600. },
  3601. {
  3602. key: "coding-plan:account:zai-individual-coding-plan",
  3603. type: "codingPlan",
  3604. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3605. oauthProviderId: ZAI_PROVIDER_ID,
  3606. label: "Z.ai - Coding Plan",
  3607. providerName: "Z.ai",
  3608. provider: null,
  3609. status: "disconnected",
  3610. planLevel: null,
  3611. currentProductId: null,
  3612. subscriptionBillingCycle: null,
  3613. subscriptionRenewTime: null,
  3614. subscriptionExpireTime: null,
  3615. quotaLimits: [],
  3616. purchaseUrl: "https://z.ai/manage-apikey/subscription",
  3617. statusActive: false,
  3618. },
  3619. ],
  3620. });
  3621. expect(fallbackNodeKey).toBe("preset:account:zai-start-plan");
  3622. });
  3623. it("Z.ai Coding Plan 不可见时首次进入默认选中 Z.ai Start Plan", () => {
  3624. const fallbackNodeKey = resolveFallbackModelProviderNodeKey({
  3625. selectedNodeKey: null,
  3626. selectableNavigationItems: [
  3627. {
  3628. key: "preset:account:zai-start-plan",
  3629. type: "preset",
  3630. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3631. label: "Z.ai - API Key",
  3632. provider: createProvider({
  3633. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3634. }),
  3635. displayName: "Z.ai - API Key",
  3636. statusActive: true,
  3637. },
  3638. {
  3639. key: "coding-plan:account:zai-start-plan",
  3640. type: "codingPlan",
  3641. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3642. oauthProviderId: ZAI_PROVIDER_ID,
  3643. label: "Z.ai - 体验计划",
  3644. providerName: "Z.ai",
  3645. provider: createProvider({
  3646. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3647. apiKey: "zcode-jwt",
  3648. }),
  3649. status: "purchased",
  3650. planLevel: "Free",
  3651. currentProductId: "zcode-v3-start-plan",
  3652. subscriptionBillingCycle: null,
  3653. subscriptionRenewTime: null,
  3654. subscriptionExpireTime: null,
  3655. quotaLimits: [],
  3656. purchaseUrl: "https://z.ai/manage-apikey/subscription",
  3657. statusActive: true,
  3658. },
  3659. ],
  3660. });
  3661. expect(fallbackNodeKey).toBe("preset:account:zai-start-plan");
  3662. });
  3663. it("Z.ai Coding Plan 权益查询不可用时不误判为未开通或查询中", () => {
  3664. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  3665. [];
  3666. function Harness() {
  3667. const { navigationItems } = useModelProviderNavigation({
  3668. presetProviders: [],
  3669. modelProviders: [createProvider({ apiKey: "zai-coding-plan-key" })],
  3670. entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]),
  3671. codingPlanEntitlements: {
  3672. [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
  3673. snapshot: createEntitlementSnapshot({
  3674. provider: {
  3675. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3676. name: "Z.ai - Coding Plan",
  3677. },
  3678. unavailableReason: "not_configured",
  3679. remaining: null,
  3680. subscription: null,
  3681. quota: null,
  3682. }),
  3683. loading: false,
  3684. error: null,
  3685. },
  3686. },
  3687. selectedNodeKey: null,
  3688. setSelectedNodeKey: vi.fn(),
  3689. intl: {
  3690. formatMessage: ({ id }: { id: string }) => id,
  3691. } as never,
  3692. });
  3693. capturedNavigationItems = navigationItems;
  3694. return createElement("div");
  3695. }
  3696. renderToStaticMarkup(createElement(Harness));
  3697. const zaiCodingPlan = capturedNavigationItems.find(
  3698. (item) =>
  3699. item.type === "codingPlan" &&
  3700. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3701. );
  3702. const zaiStartPlan = capturedNavigationItems.find(
  3703. (item) =>
  3704. item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3705. );
  3706. expect(zaiCodingPlan).toMatchObject({
  3707. status: "unavailable",
  3708. statusActive: true,
  3709. });
  3710. expect(zaiStartPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
  3711. });
  3712. it("Z.ai Coding Plan 缺少 apiKey 时旧失败快照刷新仍显示未连接", () => {
  3713. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  3714. [];
  3715. function Harness() {
  3716. const { navigationItems } = useModelProviderNavigation({
  3717. presetProviders: [],
  3718. modelProviders: [createProvider({ apiKey: "" })],
  3719. codingPlanEntitlements: {
  3720. [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
  3721. snapshot: createEntitlementSnapshot({
  3722. provider: {
  3723. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3724. name: "Z.ai - Coding Plan",
  3725. },
  3726. unavailableReason: "not_configured",
  3727. remaining: null,
  3728. subscription: null,
  3729. quota: null,
  3730. }),
  3731. loading: true,
  3732. error: null,
  3733. },
  3734. },
  3735. selectedNodeKey: null,
  3736. setSelectedNodeKey: vi.fn(),
  3737. intl: {
  3738. formatMessage: ({ id }: { id: string }) => id,
  3739. } as never,
  3740. });
  3741. capturedNavigationItems = navigationItems;
  3742. return createElement("div");
  3743. }
  3744. renderToStaticMarkup(createElement(Harness));
  3745. const zaiCodingPlan = capturedNavigationItems.find(
  3746. (item) =>
  3747. item.type === "codingPlan" &&
  3748. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3749. );
  3750. const zaiStartPlan = capturedNavigationItems.find(
  3751. (item) =>
  3752. item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3753. );
  3754. expect(zaiCodingPlan).toMatchObject({
  3755. status: "disconnected",
  3756. });
  3757. expect(zaiStartPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
  3758. });
  3759. it("Account Overlay 已连接时不再受旧 Provider apiKey 空值影响", () => {
  3760. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  3761. [];
  3762. function Harness() {
  3763. const { navigationItems } = useModelProviderNavigation({
  3764. presetProviders: [],
  3765. modelProviders: [createProvider({ apiKey: "" })],
  3766. entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]),
  3767. codingPlanEntitlements: {
  3768. [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
  3769. snapshot: createEntitlementSnapshot({
  3770. provider: {
  3771. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3772. name: "Z.ai - Coding Plan",
  3773. },
  3774. unavailableReason: "no_plan",
  3775. remaining: null,
  3776. subscription: null,
  3777. quota: null,
  3778. }),
  3779. loading: false,
  3780. error: null,
  3781. },
  3782. },
  3783. selectedNodeKey: null,
  3784. setSelectedNodeKey: vi.fn(),
  3785. intl: {
  3786. formatMessage: ({ id }: { id: string }) => id,
  3787. } as never,
  3788. });
  3789. capturedNavigationItems = navigationItems;
  3790. return createElement("div");
  3791. }
  3792. renderToStaticMarkup(createElement(Harness));
  3793. const zaiCodingPlan = capturedNavigationItems.find(
  3794. (item) =>
  3795. item.type === "codingPlan" &&
  3796. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3797. );
  3798. expect(zaiCodingPlan).toMatchObject({
  3799. accountEntitled: true,
  3800. status: "notPurchased",
  3801. });
  3802. });
  3803. it("BigModel Account Overlay 已连接时也不要求 Renderer 持有 API Key", () => {
  3804. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  3805. [];
  3806. function Harness() {
  3807. const { navigationItems } = useModelProviderNavigation({
  3808. presetProviders: [],
  3809. modelProviders: [
  3810. createProvider({
  3811. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  3812. name: "BigModel - Coding Plan",
  3813. apiKey: "",
  3814. }),
  3815. ],
  3816. entitledAccountProviderIds: new Set([
  3817. BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  3818. ]),
  3819. codingPlanEntitlements: {
  3820. [BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan]: {
  3821. snapshot: createEntitlementSnapshot({
  3822. provider: {
  3823. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  3824. name: "BigModel - Coding Plan",
  3825. },
  3826. }),
  3827. loading: false,
  3828. error: null,
  3829. },
  3830. },
  3831. selectedNodeKey: null,
  3832. setSelectedNodeKey: vi.fn(),
  3833. intl: {
  3834. formatMessage: ({ id }: { id: string }) => id,
  3835. } as never,
  3836. });
  3837. capturedNavigationItems = navigationItems;
  3838. return createElement("div");
  3839. }
  3840. renderToStaticMarkup(createElement(Harness));
  3841. const bigmodelCodingPlan = capturedNavigationItems.find(
  3842. (item) =>
  3843. item.type === "codingPlan" &&
  3844. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  3845. );
  3846. expect(bigmodelCodingPlan).toMatchObject({
  3847. accountEntitled: true,
  3848. status: "purchased",
  3849. });
  3850. });
  3851. it("Account Overlay 未连接时不再被旧 Provider apiKey 误判为已连接", () => {
  3852. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  3853. [];
  3854. function Harness() {
  3855. const { navigationItems } = useModelProviderNavigation({
  3856. presetProviders: [],
  3857. modelProviders: [createProvider({ apiKey: "legacy-key" })],
  3858. entitledAccountProviderIds: new Set(),
  3859. codingPlanEntitlements: {
  3860. [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
  3861. snapshot: createEntitlementSnapshot(),
  3862. loading: false,
  3863. error: null,
  3864. },
  3865. },
  3866. selectedNodeKey: null,
  3867. setSelectedNodeKey: vi.fn(),
  3868. intl: {
  3869. formatMessage: ({ id }: { id: string }) => id,
  3870. } as never,
  3871. });
  3872. capturedNavigationItems = navigationItems;
  3873. return createElement("div");
  3874. }
  3875. renderToStaticMarkup(createElement(Harness));
  3876. const zaiCodingPlan = capturedNavigationItems.find(
  3877. (item) =>
  3878. item.type === "codingPlan" &&
  3879. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3880. );
  3881. expect(zaiCodingPlan).toMatchObject({
  3882. accountEntitled: false,
  3883. status: "disconnected",
  3884. });
  3885. });
  3886. it("Account Overlay 首次发布前保持查询中而不读旧 Provider apiKey", () => {
  3887. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  3888. [];
  3889. function Harness() {
  3890. const { navigationItems } = useModelProviderNavigation({
  3891. presetProviders: [],
  3892. modelProviders: [createProvider({ apiKey: "legacy-key" })],
  3893. entitledAccountProviderIds: new Set(),
  3894. modelProvidersLoading: true,
  3895. selectedNodeKey: null,
  3896. setSelectedNodeKey: vi.fn(),
  3897. intl: {
  3898. formatMessage: ({ id }: { id: string }) => id,
  3899. } as never,
  3900. });
  3901. capturedNavigationItems = navigationItems;
  3902. return createElement("div");
  3903. }
  3904. renderToStaticMarkup(createElement(Harness));
  3905. const zaiCodingPlan = capturedNavigationItems.find(
  3906. (item) =>
  3907. item.type === "codingPlan" &&
  3908. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3909. );
  3910. expect(zaiCodingPlan).toMatchObject({
  3911. accountEntitled: false,
  3912. status: "checking",
  3913. });
  3914. });
  3915. it("Z.ai Coding Plan 有 apiKey 但服务端无付费套餐时仍显示付费入口", () => {
  3916. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  3917. [];
  3918. function Harness() {
  3919. const { navigationItems } = useModelProviderNavigation({
  3920. presetProviders: [],
  3921. modelProviders: [createProvider({ apiKey: "zai-coding-plan-key" })],
  3922. entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]),
  3923. codingPlanEntitlements: {
  3924. [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
  3925. snapshot: createEntitlementSnapshot({
  3926. provider: {
  3927. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3928. name: "Z.ai - Coding Plan",
  3929. },
  3930. unavailableReason: "no_plan",
  3931. remaining: null,
  3932. subscription: null,
  3933. quota: null,
  3934. }),
  3935. loading: false,
  3936. error: null,
  3937. },
  3938. },
  3939. selectedNodeKey: null,
  3940. setSelectedNodeKey: vi.fn(),
  3941. intl: {
  3942. formatMessage: ({ id }: { id: string }) => id,
  3943. } as never,
  3944. });
  3945. capturedNavigationItems = navigationItems;
  3946. return createElement("div");
  3947. }
  3948. renderToStaticMarkup(createElement(Harness));
  3949. const zaiCodingPlan = capturedNavigationItems.find(
  3950. (item) =>
  3951. item.type === "codingPlan" &&
  3952. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3953. );
  3954. const zaiStartPlan = capturedNavigationItems.find(
  3955. (item) =>
  3956. item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  3957. );
  3958. expect(zaiCodingPlan).toMatchObject({
  3959. status: "notPurchased",
  3960. statusActive: true,
  3961. });
  3962. expect(zaiStartPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
  3963. });
  3964. it("Z.ai Coding Plan 有订阅详情时优先显示已购买", () => {
  3965. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  3966. [];
  3967. function Harness() {
  3968. const { navigationItems } = useModelProviderNavigation({
  3969. presetProviders: [],
  3970. modelProviders: [createProvider({ apiKey: "zai-coding-plan-key" })],
  3971. entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]),
  3972. codingPlanEntitlements: {
  3973. [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
  3974. snapshot: createEntitlementSnapshot({
  3975. provider: {
  3976. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  3977. name: "Z.ai - Coding Plan",
  3978. },
  3979. unavailableReason: "no_plan",
  3980. remaining: null,
  3981. subscription: {
  3982. identityType: "unknown",
  3983. identityMasked: null,
  3984. details: [
  3985. {
  3986. productId: "product-zai-pro-monthly",
  3987. productName: "GLM Coding Pro",
  3988. purchaseTime: null,
  3989. beginTime: null,
  3990. billingCycle: "monthly",
  3991. renewTime: "2026-07-10T00:00:00.000Z",
  3992. expireTime: null,
  3993. },
  3994. ],
  3995. },
  3996. quota: null,
  3997. }),
  3998. loading: false,
  3999. error: null,
  4000. },
  4001. },
  4002. selectedNodeKey: null,
  4003. setSelectedNodeKey: vi.fn(),
  4004. intl: {
  4005. formatMessage: ({ id }: { id: string }) => id,
  4006. } as never,
  4007. });
  4008. capturedNavigationItems = navigationItems;
  4009. return createElement("div");
  4010. }
  4011. renderToStaticMarkup(createElement(Harness));
  4012. const zaiCodingPlan = capturedNavigationItems.find(
  4013. (item) =>
  4014. item.type === "codingPlan" &&
  4015. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  4016. );
  4017. const zaiStartPlan = capturedNavigationItems.find(
  4018. (item) =>
  4019. item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  4020. );
  4021. expect(zaiCodingPlan).toMatchObject({
  4022. status: "purchased",
  4023. planLevel: "GLM Coding Pro",
  4024. currentProductId: "product-zai-pro-monthly",
  4025. subscriptionRenewTime: "2026-07-10T00:00:00.000Z",
  4026. statusActive: true,
  4027. });
  4028. expect(zaiStartPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
  4029. });
  4030. it("Z.ai Start Plan 加载权益接口时连接方式仍显示 Start 入口", () => {
  4031. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  4032. [];
  4033. function Harness() {
  4034. const { navigationItems } = useModelProviderNavigation({
  4035. presetProviders: [],
  4036. modelProviders: [
  4037. createProvider({
  4038. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  4039. name: "Z.ai - Coding Plan",
  4040. apiKey: "zcode-jwt",
  4041. }),
  4042. ],
  4043. entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan]),
  4044. codingPlanEntitlements: {
  4045. [BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan]: {
  4046. snapshot: createEntitlementSnapshot({
  4047. provider: {
  4048. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  4049. name: "Z.ai - Coding Plan",
  4050. },
  4051. subscription: {
  4052. identityType: "unknown",
  4053. identityMasked: null,
  4054. details: [
  4055. {
  4056. productId: "zcode-v3-start-plan",
  4057. productName: "ZCode V3 Start Plan",
  4058. purchaseTime: null,
  4059. beginTime: null,
  4060. billingCycle: "daily",
  4061. renewTime: "2026-06-04T00:00:00.000Z",
  4062. expireTime: "2026-06-08T00:00:00.000Z",
  4063. },
  4064. ],
  4065. },
  4066. quota: null,
  4067. }),
  4068. loading: true,
  4069. error: null,
  4070. },
  4071. },
  4072. selectedNodeKey: null,
  4073. setSelectedNodeKey: vi.fn(),
  4074. intl: {
  4075. formatMessage: ({ id }: { id: string }) => id,
  4076. } as never,
  4077. });
  4078. capturedNavigationItems = navigationItems;
  4079. return createElement("div");
  4080. }
  4081. renderToStaticMarkup(createElement(Harness));
  4082. const startPlan = capturedNavigationItems.find(
  4083. (item) =>
  4084. item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  4085. );
  4086. const loadingItem = capturedNavigationItems.find((item) => item.type === "codingPlanLoading");
  4087. expect(startPlan).toMatchObject({
  4088. type: "codingPlan",
  4089. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  4090. });
  4091. expect(loadingItem).toBeUndefined();
  4092. });
  4093. it("Z.ai Coding Plan token 失效时显示同步失败", () => {
  4094. let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
  4095. [];
  4096. function Harness() {
  4097. const { navigationItems } = useModelProviderNavigation({
  4098. presetProviders: [],
  4099. modelProviders: [createProvider({ apiKey: "zai-coding-plan-key" })],
  4100. entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]),
  4101. codingPlanEntitlements: {
  4102. [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
  4103. snapshot: createEntitlementSnapshot({
  4104. provider: {
  4105. id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  4106. name: "Z.ai - Coding Plan",
  4107. },
  4108. unavailableReason: "unavailable",
  4109. remaining: null,
  4110. subscription: null,
  4111. quota: null,
  4112. }),
  4113. loading: false,
  4114. error: null,
  4115. },
  4116. },
  4117. selectedNodeKey: null,
  4118. setSelectedNodeKey: vi.fn(),
  4119. intl: {
  4120. formatMessage: ({ id }: { id: string }) => id,
  4121. } as never,
  4122. });
  4123. capturedNavigationItems = navigationItems;
  4124. return createElement("div");
  4125. }
  4126. renderToStaticMarkup(createElement(Harness));
  4127. const zaiCodingPlan = capturedNavigationItems.find(
  4128. (item) =>
  4129. item.type === "codingPlan" &&
  4130. item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  4131. );
  4132. expect(zaiCodingPlan).toMatchObject({
  4133. status: "unavailable",
  4134. statusActive: true,
  4135. });
  4136. });
  4137. it("Z.ai Coding Plan 未连接时在 Plan Card 右侧显示 Connect 入口", () => {
  4138. const apiKeyItem = {
  4139. key: "preset:account:zai-start-plan",
  4140. type: "preset" as const,
  4141. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  4142. label: "Z.ai - API Key",
  4143. displayName: "Z.ai - API Key",
  4144. provider: createProvider({
  4145. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  4146. name: "Z.ai - API Key",
  4147. }),
  4148. statusActive: true,
  4149. };
  4150. const oauthItem = {
  4151. key: "coding-plan:account:zai-individual-coding-plan",
  4152. type: "codingPlan",
  4153. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  4154. oauthProviderId: ZAI_PROVIDER_ID,
  4155. label: "Z.ai - Coding Plan",
  4156. providerName: "Z.ai",
  4157. provider: createProvider({ apiKey: "", models: [] }),
  4158. status: "disconnected",
  4159. purchaseUrl: "https://z.ai/",
  4160. statusActive: false,
  4161. } as const;
  4162. const html = renderDetail(oauthItem, {
  4163. navigationItems: [oauthItem, apiKeyItem],
  4164. onSelectNavItem: vi.fn(),
  4165. });
  4166. expect(html).toContain("settings.modelProvider.planCard.codingPlan");
  4167. expect(html).toContain("settings.modelProvider.codingPlan.status.disconnected");
  4168. expect(html).toContain("settings.modelProvider.codingPlan.connect");
  4169. expect(html).not.toContain('data-testid="model-provider-enabled-switch"');
  4170. expect(html).not.toContain("settings.modelProvider.codingPlan.productsLoading");
  4171. expect(html).not.toContain("GLM Coding Lite");
  4172. expect(html).not.toContain("GLM Coding Pro");
  4173. expect(html).not.toContain("GLM Coding Max");
  4174. expect(html).not.toContain("lucide-loader-circle");
  4175. expect(html).not.toContain("settings.modelProvider.codingPlan.dynamicUnsupportedTitle");
  4176. expect(html).not.toContain("settings.modelProvider.models");
  4177. expect(html).not.toContain("settings.modelProvider.apiKeyPlaceholder");
  4178. });
  4179. it("Z.ai Coding Plan 连接等待时状态卡片显示 loading", () => {
  4180. const html = renderDetail(
  4181. {
  4182. key: "coding-plan:account:zai-individual-coding-plan",
  4183. type: "codingPlan",
  4184. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  4185. oauthProviderId: ZAI_PROVIDER_ID,
  4186. label: "Z.ai - Coding Plan",
  4187. providerName: "Z.ai",
  4188. provider: createProvider({ apiKey: "", models: [] }),
  4189. status: "disconnected",
  4190. purchaseUrl: "https://z.ai/",
  4191. statusActive: false,
  4192. },
  4193. {
  4194. presetSubscriptionProviderId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  4195. },
  4196. );
  4197. expect(html).toContain("settings.modelProvider.codingPlan.status.checking");
  4198. expect(html).toContain("lucide-loader-circle");
  4199. expect(html).toContain("settings.modelProvider.codingPlan.connect");
  4200. });
  4201. it("Z.ai Start Plan 连接等待时不提前显示今日余额", () => {
  4202. const html = renderDetail(
  4203. {
  4204. key: "coding-plan:account:zai-start-plan",
  4205. type: "codingPlan",
  4206. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  4207. oauthProviderId: ZAI_PROVIDER_ID,
  4208. label: "Z.ai - Coding Plan",
  4209. providerName: "Z.ai",
  4210. provider: createProvider({
  4211. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  4212. apiKey: "",
  4213. models: [],
  4214. }),
  4215. status: "disconnected",
  4216. purchaseUrl: "https://z.ai/",
  4217. statusActive: false,
  4218. },
  4219. {
  4220. presetSubscriptionProviderId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  4221. },
  4222. );
  4223. expect(html).toContain("settings.modelProvider.codingPlan.status.checking");
  4224. expect(html).toContain("lucide-loader-circle");
  4225. expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
  4226. expect(html).not.toContain("settings.modelProvider.startPlan.quotaSectionTitle");
  4227. expect(html).not.toContain("settings.modelProvider.startPlan.balance.title");
  4228. });
  4229. it("Z.ai Coding Plan 权益查询中时状态卡片不空白", () => {
  4230. const html = renderDetail({
  4231. key: "coding-plan:account:zai-individual-coding-plan",
  4232. type: "codingPlan",
  4233. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  4234. oauthProviderId: ZAI_PROVIDER_ID,
  4235. label: "Z.ai - Coding Plan",
  4236. providerName: "Z.ai",
  4237. provider: createProvider({ apiKey: "zai-coding-plan-key" }),
  4238. status: "checking",
  4239. planLevel: null,
  4240. purchaseUrl: "https://z.ai/",
  4241. statusActive: false,
  4242. });
  4243. expect(html).toContain("settings.modelProvider.codingPlan.status.checking");
  4244. expect(html).toContain("lucide-loader-circle");
  4245. expect(html).not.toContain("settings.modelProvider.codingPlan.manage");
  4246. expect(html).not.toContain("settings.modelProvider.codingPlan.upgrade");
  4247. });
  4248. it("Z.ai Coding Plan 有 apiKey 但无静态商品时隐藏个人套餐横幅", () => {
  4249. const html = renderDetail({
  4250. key: "coding-plan:account:zai-individual-coding-plan",
  4251. type: "codingPlan",
  4252. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  4253. oauthProviderId: ZAI_PROVIDER_ID,
  4254. label: "Z.ai - Coding Plan",
  4255. providerName: "Z.ai",
  4256. provider: createProvider({ apiKey: "zai-coding-plan-key" }),
  4257. status: "notPurchased",
  4258. purchaseUrl: "https://z.ai/",
  4259. statusActive: false,
  4260. });
  4261. expect(html).toContain("settings.modelProvider.codingPlan.status.notPurchased");
  4262. expect(html).not.toContain("settings.modelProvider.codingPlan.description.notPurchased");
  4263. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.personalTitle");
  4264. expect(html).not.toContain(
  4265. "settings.modelProvider.codingPlan.purchaseBanner.personalDescription",
  4266. );
  4267. expect(html).not.toContain("CN¥49.00+");
  4268. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamTitle");
  4269. expect(html).not.toContain("CN¥598.00+");
  4270. expect(html).not.toContain("settings.modelProvider.codingPlan.upgrade");
  4271. expect(html).not.toContain("settings.modelProvider.codingPlan.productsLoading");
  4272. expect(html).not.toContain("settings.modelProvider.models");
  4273. expect(html).not.toContain("settings.modelProvider.apiKey");
  4274. });
  4275. it("Z.ai Coding Plan 入口价格跟随 Z.ai 商品币种", () => {
  4276. expect(
  4277. resolvePurchaseChoiceBannerPrice({
  4278. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  4279. audience: "personal",
  4280. products: [
  4281. {
  4282. productId: "zai-lite-month",
  4283. productName: "GLM Coding Lite",
  4284. productEquityList: [],
  4285. priceCurrency: "USD",
  4286. payAmount: 18,
  4287. },
  4288. ],
  4289. }),
  4290. ).toEqual({ kind: "price", price: 18, currency: "USD" });
  4291. });
  4292. it("个人套餐入口价格在全部售罄时显示售罄状态", () => {
  4293. expect(
  4294. resolvePurchaseChoiceBannerPrice({
  4295. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  4296. audience: "personal",
  4297. products: [
  4298. {
  4299. productId: "zai-lite-month",
  4300. productName: "GLM Coding Lite",
  4301. productEquityList: [],
  4302. priceCurrency: "USD",
  4303. payAmount: 18,
  4304. soldOut: true,
  4305. },
  4306. {
  4307. productId: "zai-pro-month",
  4308. productName: "GLM Coding Pro",
  4309. productEquityList: [],
  4310. priceCurrency: "USD",
  4311. payAmount: 88,
  4312. soldOut: true,
  4313. },
  4314. ],
  4315. }),
  4316. ).toEqual({ kind: "soldOut" });
  4317. });
  4318. it("未登录个人套餐入口不前置显示售罄状态", () => {
  4319. expect(
  4320. resolvePurchaseChoiceBannerPrice({
  4321. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  4322. audience: "personal",
  4323. soldOutVisible: false,
  4324. products: [
  4325. {
  4326. productId: "bigmodel-lite-month",
  4327. productName: "GLM Coding Lite",
  4328. productEquityList: [],
  4329. priceCurrency: "CNY",
  4330. payAmount: 49,
  4331. soldOut: true,
  4332. },
  4333. ],
  4334. }),
  4335. ).toBeNull();
  4336. });
  4337. it("Z.ai Start Plan 入口价格读取付费 Coding Plan 商品源", () => {
  4338. expect(
  4339. resolvePurchaseChoiceBannerProductsProviderId(BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan),
  4340. ).toBe(BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan);
  4341. });
  4342. it("BigModel Coding Plan 无静态商品时不补固定价格", () => {
  4343. expect(
  4344. resolvePurchaseChoiceBannerPrice({
  4345. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  4346. audience: "personal",
  4347. products: [],
  4348. }),
  4349. ).toBeNull();
  4350. });
  4351. it("BigModel 登录后团队入口按企业套餐分组显示标准版和高级版价格", () => {
  4352. const groups = groupEnterpriseCodingPlanProductsByTier(
  4353. [
  4354. {
  4355. productId: "team-pro-year",
  4356. productName: "Pro",
  4357. productEquityList: [],
  4358. priceCurrency: "CNY",
  4359. payAmount: 598,
  4360. tier: "PRO",
  4361. subscribeMode: "CONTINUOUS",
  4362. subscribePeriod: "YEARLY",
  4363. purchaseMethodName: "Auto renew",
  4364. enterpriseProduct: {
  4365. productId: "team-pro-year",
  4366. tier: "PRO",
  4367. subscribeMode: "CONTINUOUS",
  4368. subscribePeriod: "YEARLY",
  4369. payAmount: 598,
  4370. },
  4371. },
  4372. {
  4373. productId: "team-max-year",
  4374. productName: "Max",
  4375. productEquityList: [],
  4376. priceCurrency: "CNY",
  4377. payAmount: 1298,
  4378. tier: "MAX",
  4379. subscribeMode: "CONTINUOUS",
  4380. subscribePeriod: "YEARLY",
  4381. purchaseMethodName: "Auto renew",
  4382. enterpriseProduct: {
  4383. productId: "team-max-year",
  4384. tier: "MAX",
  4385. subscribeMode: "CONTINUOUS",
  4386. subscribePeriod: "YEARLY",
  4387. payAmount: 1298,
  4388. },
  4389. },
  4390. ],
  4391. {
  4392. locale: "zh-CN",
  4393. formatMessage: (id, fallback) => (zhCN as Record<string, string>)[id] ?? fallback,
  4394. },
  4395. );
  4396. expect(groups.map((group) => group.title)).toEqual(["标准版", "高级版"]);
  4397. expect(groups.map(resolveEnterprisePurchaseChoiceBannerPrice)).toEqual([
  4398. { kind: "price", price: 598, currency: "CNY" },
  4399. { kind: "price", price: 1298, currency: "CNY" },
  4400. ]);
  4401. });
  4402. it("Z.ai Coding Plan 已购买时显示 Plan Card、用量卡和解绑入口", () => {
  4403. // Bugfix:用例运行日在 8 月 10 日时,产品会把额度重置时间识别为“今天”并省略日期。
  4404. // 只在同步渲染期间固定到同年的 1 月 15 日,稳定验证“日期 + 时间”展示,并保证断言失败时恢复时钟。
  4405. const currentYear = 2026;
  4406. vi.useFakeTimers();
  4407. let html = "";
  4408. try {
  4409. vi.setSystemTime(new Date(currentYear, 0, 15, 12, 0));
  4410. html = renderDetail({
  4411. key: "coding-plan:account:zai-individual-coding-plan",
  4412. type: "codingPlan",
  4413. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  4414. oauthProviderId: ZAI_PROVIDER_ID,
  4415. label: "Z.ai - Coding Plan",
  4416. providerName: "Z.ai",
  4417. provider: createProvider(),
  4418. status: "purchased",
  4419. planLevel: "pro",
  4420. subscriptionBillingCycle: "monthly",
  4421. subscriptionRenewTime: `${currentYear}-07-10T00:00:00.000Z`,
  4422. subscriptionExpireTime: "2026-12-31T00:00:00.000Z",
  4423. purchaseUrl: "https://z.ai/",
  4424. quotaLimits: [
  4425. {
  4426. type: "TOKENS_LIMIT",
  4427. unit: 3,
  4428. number: 5,
  4429. usage: 250_000,
  4430. remaining: 750_000,
  4431. percentage: 25,
  4432. nextResetTime: new Date(currentYear, 7, 10, 9, 30).getTime(),
  4433. usageDetails: [
  4434. {
  4435. modelCode: "glm-coding-lite",
  4436. displayName: "GLM CODING LITE",
  4437. usage: 250_000,
  4438. },
  4439. ],
  4440. },
  4441. {
  4442. type: "TOKENS_LIMIT",
  4443. unit: 6,
  4444. currentValue: 500_000,
  4445. remaining: 500_000,
  4446. percentage: 50,
  4447. nextResetTime: new Date(currentYear, 7, 11).getTime(),
  4448. usageDetails: [],
  4449. },
  4450. {
  4451. type: "TIME_LIMIT",
  4452. unit: 5,
  4453. number: 1,
  4454. usage: 1_000,
  4455. remaining: 9_000,
  4456. percentage: 10,
  4457. nextResetTime: new Date(currentYear, 7, 12).getTime(),
  4458. usageDetails: [
  4459. {
  4460. modelCode: "search-prime",
  4461. displayName: "Search Prime",
  4462. usage: 500,
  4463. },
  4464. {
  4465. modelCode: "web-reader",
  4466. displayName: "Web Reader",
  4467. usage: 300,
  4468. },
  4469. { modelCode: "zr", displayName: "Zr", usage: 200 },
  4470. ],
  4471. },
  4472. ],
  4473. statusActive: true,
  4474. });
  4475. } finally {
  4476. vi.useRealTimers();
  4477. }
  4478. expect(html).not.toContain("settings.modelProvider.codingPlan.status.purchased");
  4479. expect(html).not.toContain("settings.modelProvider.enabledStatus");
  4480. // 套餐卡不提供 Provider 启停;下方模型行仍应提供自己的启停控件。
  4481. expect(html.split("settings.modelProvider.models")[0]).not.toContain(
  4482. "settings.modelProvider.disableAction",
  4483. );
  4484. expect(html).toContain(">PRO<");
  4485. expect(html).toContain("settings.usage.entitlementFiveHourUsage");
  4486. expect(html).toContain("settings.usage.entitlementWeeklyUsage");
  4487. expect(html).toContain("settings.usage.entitlementMonthlyMcpUsage");
  4488. expect(html.match(/class="flex min-h-6 min-w-0 items-center gap-1"/g)).toHaveLength(3);
  4489. expect(html).toContain("GLM Coding Lite");
  4490. expect(html).not.toContain("GLM CODING LITE");
  4491. expect(html).not.toContain("Search Prime");
  4492. expect(html).not.toContain("Web Reader");
  4493. expect(html).not.toContain(">Zr<");
  4494. expect(html).toContain("75%");
  4495. expect(html).toContain("50%");
  4496. expect(html).toContain("90%");
  4497. expect(html).toContain("Aug 10, 09:30");
  4498. expect(html).toContain('text-ui-sm text-foreground-subtle">Aug 10, 09:30');
  4499. expect(html).toContain("Aug 11");
  4500. expect(html).toContain("Aug 12");
  4501. expect(html.indexOf("75%")).toBeLessThan(html.indexOf("Aug 10, 09:30"));
  4502. expect(html.indexOf("Aug 10, 09:30")).toBeLessThan(
  4503. html.indexOf("background-color:var(--color-usage-chart-1)"),
  4504. );
  4505. expect(html).toContain("background-color:var(--color-usage-chart-1)");
  4506. expect(html).toContain("background-color:var(--color-usage-chart-2)");
  4507. expect(html).toContain("background-color:var(--color-usage-chart-3)");
  4508. expect(html).not.toContain("settings.modelProvider.startPlan.balance.used");
  4509. expect(html).not.toContain("settings.modelProvider.codingPlan.period.monthly");
  4510. expect(html).toContain("settings.modelProvider.codingPlan.renewsAt");
  4511. expect(html).toContain("settings.modelProvider.codingPlan.manage");
  4512. expect(html).toContain("settings.modelProvider.codingPlan.upgrade");
  4513. expect(html).toContain("Jul 10");
  4514. expect(html).not.toContain(`Jul 10, ${currentYear}`);
  4515. expect(html).not.toContain("settings.modelProvider.codingPlan.expiresAt");
  4516. expect(html).toContain("settings.modelProvider.codingPlan.disconnect");
  4517. expect(html).not.toContain("settings.modelProvider.codingPlan.resetItem");
  4518. expect(html).toContain("settings.modelProvider.models");
  4519. expect(html).not.toContain("settings.modelProvider.codingPlan.zai.plan.lite.name");
  4520. expect(html).not.toContain("settings.modelProvider.connectionMode");
  4521. expect(html).not.toContain("settings.modelProvider.apiKey");
  4522. });
  4523. it("Z.ai Coding Plan 已购买时升级入口不替换下方模型配置", () => {
  4524. const html = renderDetail({
  4525. key: "coding-plan:account:zai-individual-coding-plan",
  4526. type: "codingPlan",
  4527. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  4528. oauthProviderId: ZAI_PROVIDER_ID,
  4529. label: "Z.ai - Coding Plan",
  4530. providerName: "Z.ai",
  4531. provider: createProvider(),
  4532. status: "purchased",
  4533. planLevel: "PRO",
  4534. currentProductId: "zai-coding-pro-monthly",
  4535. purchaseUrl: "https://z.ai/",
  4536. statusActive: true,
  4537. });
  4538. expect(html).toContain("settings.modelProvider.codingPlan.upgrade");
  4539. expect(html).toContain("settings.modelProvider.models");
  4540. expect(html).not.toContain("settings.modelProvider.codingPlan.description.notPurchased");
  4541. });
  4542. it("Z.ai Coding Plan 已购买时允许在官方模型列表添加模型", () => {
  4543. const html = renderDetail({
  4544. key: "coding-plan:account:zai-individual-coding-plan",
  4545. type: "codingPlan",
  4546. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  4547. oauthProviderId: ZAI_PROVIDER_ID,
  4548. label: "Z.ai - Coding Plan",
  4549. providerName: "Z.ai",
  4550. provider: createProvider(),
  4551. status: "purchased",
  4552. planLevel: "PRO",
  4553. currentProductId: "zai-coding-pro-monthly",
  4554. purchaseUrl: "https://z.ai/",
  4555. statusActive: true,
  4556. });
  4557. expect(html).toContain("settings.modelProvider.models");
  4558. expect(html).toContain("settings.modelProvider.addModel");
  4559. });
  4560. it("Z.ai Coding Plan 已购买时套餐标题保留模型名大小写", () => {
  4561. const html = renderDetail({
  4562. key: "coding-plan:account:zai-individual-coding-plan",
  4563. type: "codingPlan",
  4564. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  4565. oauthProviderId: ZAI_PROVIDER_ID,
  4566. label: "Z.ai - Coding Plan",
  4567. providerName: "Z.ai",
  4568. provider: createProvider(),
  4569. status: "purchased",
  4570. planLevel: "GLM CODING LITE",
  4571. purchaseUrl: "https://z.ai/",
  4572. quotaLimits: [],
  4573. statusActive: true,
  4574. });
  4575. expect(html).toContain(">GLM Coding Lite<");
  4576. expect(html).not.toContain("GLM CODING LITE");
  4577. });
  4578. it("Coding Plan 用量卡 percentage 按已用百分比反转成剩余百分比", () => {
  4579. const html = renderDetail({
  4580. key: "coding-plan:account:zai-individual-coding-plan",
  4581. type: "codingPlan",
  4582. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  4583. oauthProviderId: ZAI_PROVIDER_ID,
  4584. label: "Z.ai - Coding Plan",
  4585. providerName: "Z.ai",
  4586. provider: createProvider(),
  4587. status: "purchased",
  4588. planLevel: "pro",
  4589. quotaLimits: [
  4590. {
  4591. type: "TOKENS_LIMIT",
  4592. unit: 3,
  4593. number: 5,
  4594. usage: 100_000,
  4595. remaining: 900_000,
  4596. percentage: 1,
  4597. usageDetails: [],
  4598. },
  4599. ],
  4600. statusActive: true,
  4601. });
  4602. expect(html).toContain("99%");
  4603. expect(html).not.toContain(">0%</");
  4604. });
  4605. it("Team Plan 复用 Coding Plan 用量卡展示 quota/limit 数据", () => {
  4606. const html = renderDetail({
  4607. key: "team:bigmodel:product-team:proj-team",
  4608. type: "teamPlan",
  4609. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  4610. oauthProviderId: BIGMODEL_PROVIDER_ID,
  4611. label: "BigModel - Team Plan",
  4612. providerName: "BigModel",
  4613. provider: createProvider({
  4614. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  4615. }),
  4616. status: "purchased",
  4617. planLevel: "pro",
  4618. teamPlanName: "Team A",
  4619. organizationId: "org-team",
  4620. projectId: "proj-team",
  4621. currentProductId: "product-team",
  4622. quotaLimits: [
  4623. {
  4624. type: "TOKENS_LIMIT",
  4625. unit: 3,
  4626. number: 5,
  4627. usage: 100_000,
  4628. remaining: 900_000,
  4629. percentage: 10,
  4630. usageDetails: [],
  4631. },
  4632. {
  4633. type: "TIME_LIMIT",
  4634. unit: 5,
  4635. number: 1,
  4636. usage: 1_000,
  4637. remaining: 9_000,
  4638. percentage: 10,
  4639. usageDetails: [],
  4640. },
  4641. ],
  4642. statusActive: true,
  4643. });
  4644. expect(html).toContain("settings.usage.entitlementFiveHourUsage");
  4645. expect(html).toContain("settings.usage.entitlementMonthlyMcpUsage");
  4646. expect(html).not.toContain("settings.modelProvider.startPlan.balance.title");
  4647. });
  4648. it("Team Plan 未分配时不显示获取失败 access banner", () => {
  4649. const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan;
  4650. const html = renderDetail({
  4651. key: "team:bigmodel:product-team:org-team:proj-team",
  4652. type: "teamPlan",
  4653. presetId: providerId,
  4654. oauthProviderId: BIGMODEL_PROVIDER_ID,
  4655. label: "BigModel - Team A",
  4656. providerName: "BigModel",
  4657. provider: createProvider({
  4658. id: providerId,
  4659. models: ["glm-team-visible"],
  4660. }),
  4661. status: "unavailable",
  4662. statusLabelId: "settings.modelProvider.codingPlan.status.teamUnavailable",
  4663. availabilityReason: "not-allocated",
  4664. inactivePlanTitle: "Team A",
  4665. planLevel: "Team A",
  4666. teamPlanName: "Team A",
  4667. organizationId: "org-team",
  4668. projectId: "proj-team",
  4669. currentProductId: "product-team",
  4670. quotaLimits: [],
  4671. statusActive: false,
  4672. });
  4673. expect(html).toContain("settings.modelProvider.codingPlan.status.teamUnavailable");
  4674. expect(html).not.toContain("settings.modelProvider.codingPlan.status.unavailable");
  4675. expect(html).not.toContain("settings.modelProvider.codingPlan.description.unavailable");
  4676. expect(html).not.toContain("glm-team-visible");
  4677. expectConnectionApiFormatHidden(html);
  4678. expect(html).not.toContain("settings.modelProvider.baseUrl");
  4679. });
  4680. it("Team Plan 只从 Settings View 读取 Effective Provider,套餐状态不能覆盖模型列表", () => {
  4681. const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan;
  4682. const effectiveProvider = createProvider({
  4683. id: providerId,
  4684. models: ["effective-team-model"],
  4685. endpoints: { baseURL: "https://effective.example.com/v1" },
  4686. });
  4687. const html = renderDetail(
  4688. {
  4689. key: "team:bigmodel:product-team:org-team:proj-team",
  4690. type: "teamPlan",
  4691. presetId: providerId,
  4692. oauthProviderId: BIGMODEL_PROVIDER_ID,
  4693. label: "BigModel - Team A",
  4694. providerName: "BigModel",
  4695. provider: createProvider({
  4696. id: providerId,
  4697. models: ["stale-nav-model"],
  4698. }),
  4699. status: "checking",
  4700. inactivePlanTitle: "Team A",
  4701. planLevel: "Team A",
  4702. teamPlanName: "Team A",
  4703. organizationId: "org-team",
  4704. projectId: "proj-team",
  4705. currentProductId: "product-team",
  4706. quotaLimits: [],
  4707. statusActive: false,
  4708. },
  4709. { providerSettingsView: createProviderSettingsView(effectiveProvider) },
  4710. );
  4711. expect(html).toContain("effective-team-model");
  4712. expect(html).not.toContain("stale-nav-model");
  4713. expectConnectionApiFormatHidden(html);
  4714. expect(html).not.toContain("settings.modelProvider.baseUrl");
  4715. });
  4716. it("Team Plan 明确无权益且缺少 Provider 时不显示模型配置异常", () => {
  4717. const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan;
  4718. const html = renderDetail(
  4719. {
  4720. key: "team:bigmodel:product-team:org-team:proj-team",
  4721. type: "teamPlan",
  4722. presetId: providerId,
  4723. oauthProviderId: BIGMODEL_PROVIDER_ID,
  4724. label: "BigModel - Team A",
  4725. providerName: "BigModel",
  4726. provider: createProvider({
  4727. id: providerId,
  4728. models: ["stale-team-model"],
  4729. }),
  4730. status: "unavailable",
  4731. availabilityReason: "not-allocated",
  4732. teamPlanName: "Team A",
  4733. organizationId: "org-team",
  4734. projectId: "proj-team",
  4735. currentProductId: "product-team",
  4736. statusActive: false,
  4737. },
  4738. {
  4739. providerSettingsView: {
  4740. revision: 18,
  4741. addableProviders: [],
  4742. providerOrder: [],
  4743. providers: [],
  4744. },
  4745. },
  4746. );
  4747. expect(html).not.toContain("settings.modelProvider.accountProviderConfigMissing");
  4748. expect(html).not.toContain("stale-team-model");
  4749. });
  4750. it("Individual Coding Plan 在不可用状态仍显示 Effective 模型,但隐藏 Endpoint 与 API Schema", () => {
  4751. const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan;
  4752. const html = renderDetail({
  4753. key: `coding-plan:${providerId}`,
  4754. type: "codingPlan",
  4755. presetId: providerId,
  4756. oauthProviderId: BIGMODEL_PROVIDER_ID,
  4757. label: "BigModel - Coding Plan",
  4758. providerName: "BigModel",
  4759. provider: createProvider({
  4760. id: providerId,
  4761. models: ["individual-visible-model"],
  4762. }),
  4763. status: "unavailable",
  4764. statusActive: false,
  4765. });
  4766. expect(html).toContain("individual-visible-model");
  4767. expectConnectionApiFormatHidden(html);
  4768. expect(html).not.toContain("settings.modelProvider.baseUrl");
  4769. });
  4770. it.each(["disconnected", "notPurchased", "purchased", "checking", "unavailable"] as const)(
  4771. "个人套餐 %s 按明确权益决定模型设置是否展示",
  4772. (status) => {
  4773. const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan;
  4774. const html = renderDetail({
  4775. key: `coding-plan:${providerId}`,
  4776. type: "codingPlan",
  4777. presetId: providerId,
  4778. oauthProviderId: BIGMODEL_PROVIDER_ID,
  4779. label: "BigModel",
  4780. providerName: "BigModel",
  4781. provider: createProvider({ id: providerId, models: ["entitlement-model"] }),
  4782. status,
  4783. statusActive: status === "purchased",
  4784. });
  4785. expect(html.includes("entitlement-model")).toBe(
  4786. status !== "notPurchased" && status !== "disconnected",
  4787. );
  4788. },
  4789. );
  4790. it("Team Plan 同步 loading 时不显示未分配管理员提示", () => {
  4791. const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan;
  4792. const html = renderDetail(
  4793. {
  4794. key: "team:bigmodel:product-team:org-team:proj-team",
  4795. type: "teamPlan",
  4796. presetId: providerId,
  4797. oauthProviderId: BIGMODEL_PROVIDER_ID,
  4798. label: "BigModel - Team A",
  4799. providerName: "BigModel",
  4800. provider: createProvider({ id: providerId }),
  4801. status: "unavailable",
  4802. statusLabelId: "settings.modelProvider.codingPlan.status.teamUnavailable",
  4803. teamPlanAvailabilityReason: "not-allocated",
  4804. inactivePlanTitle: "Team A",
  4805. planLevel: "Team A",
  4806. teamPlanName: "Team A",
  4807. organizationId: "org-team",
  4808. projectId: "proj-team",
  4809. currentProductId: "product-team",
  4810. quotaLimits: [],
  4811. statusActive: false,
  4812. },
  4813. { codingPlanStatusSyncProviderId: providerId },
  4814. );
  4815. expect(html).toContain("settings.modelProvider.codingPlan.status.checking");
  4816. expect(html).not.toContain("settings.modelProvider.codingPlan.status.teamUnavailable");
  4817. });
  4818. it("Team Plan 有效订阅在 quota 缺失时仍保持已启用", () => {
  4819. const item = {
  4820. key: "team:bigmodel:product-team:proj-team",
  4821. type: "teamPlan",
  4822. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  4823. oauthProviderId: BIGMODEL_PROVIDER_ID,
  4824. label: "BigModel - Team A",
  4825. providerName: "BigModel",
  4826. provider: createProvider({
  4827. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  4828. }),
  4829. status: "purchased",
  4830. statusLabelId: "settings.modelProvider.codingPlan.status.teamUnavailable",
  4831. availabilityReason: "not-allocated",
  4832. planLevel: "PRO",
  4833. teamPlanName: "Team A",
  4834. organizationId: "org-team",
  4835. projectId: "proj-team",
  4836. currentProductId: "product-team",
  4837. quotaLimits: [],
  4838. statusActive: true,
  4839. } as const;
  4840. const resolved = resolveTeamScopedPlanNavItem(item, {
  4841. loading: false,
  4842. error: null,
  4843. snapshot: createEntitlementSnapshot({
  4844. subscription: {
  4845. identityType: "unknown",
  4846. identityMasked: null,
  4847. details: [
  4848. {
  4849. productId: "product-team",
  4850. productName: "团队套餐高级版",
  4851. purchaseTime: null,
  4852. beginTime: null,
  4853. billingCycle: "quarterly",
  4854. renewTime: "2026-08-01T00:00:00.000Z",
  4855. expireTime: null,
  4856. },
  4857. ],
  4858. },
  4859. quota: null,
  4860. }),
  4861. refresh: vi.fn(),
  4862. } as never);
  4863. expect(resolved.statusActive).toBe(true);
  4864. expect(resolved.planLevel).toBe("Team A");
  4865. expect(resolved.currentProductId).toBe("product-team");
  4866. expect(resolved.subscriptionBillingCycle).toBeNull();
  4867. expect(resolved.subscriptionRenewTime).toBeNull();
  4868. expect(resolved.teamPlanName).toBe("Team A");
  4869. expect(resolved.statusLabelId).toBeUndefined();
  4870. expect(resolved.availabilityReason).toBeUndefined();
  4871. });
  4872. it("Team Plan 明确无订阅时不继续显示已启用或个人续费日期", () => {
  4873. const item = {
  4874. key: "team:bigmodel:product-team:org-team:proj-team",
  4875. type: "teamPlan",
  4876. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  4877. oauthProviderId: BIGMODEL_PROVIDER_ID,
  4878. label: "BigModel - GY的组织",
  4879. providerName: "BigModel",
  4880. provider: createProvider({
  4881. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  4882. }),
  4883. status: "purchased",
  4884. planLevel: "PRO",
  4885. teamPlanName: "GY的组织",
  4886. organizationId: "org-team",
  4887. projectId: "proj-team",
  4888. currentProductId: "product-team",
  4889. subscriptionRenewTime: "2026-09-15T00:00:00.000Z",
  4890. subscriptionBillingCycle: "monthly",
  4891. quotaLimits: [],
  4892. statusActive: true,
  4893. } as const;
  4894. const resolved = resolveTeamScopedPlanNavItem(item, {
  4895. loading: false,
  4896. error: null,
  4897. snapshot: createEntitlementSnapshot({
  4898. context: {
  4899. scope: "team",
  4900. organizationId: "org-team",
  4901. projectId: "proj-team",
  4902. productId: "product-team",
  4903. displayName: "GY的组织",
  4904. },
  4905. remaining: null,
  4906. quota: null,
  4907. subscription: null,
  4908. unavailableReason: "no_plan",
  4909. }),
  4910. refresh: vi.fn(),
  4911. } as never);
  4912. expect(resolved.status).toBe("unavailable");
  4913. expect(resolved.statusActive).toBe(false);
  4914. expect(resolved.statusLabelId).toBe("settings.modelProvider.codingPlan.status.teamUnavailable");
  4915. expect(resolved.subscriptionRenewTime).toBeNull();
  4916. expect(resolved.subscriptionBillingCycle).toBeNull();
  4917. });
  4918. it.each(["expired", "unassigned"] as const)("团队明确 %s 不显示查询失败或登录重试", (reason) => {
  4919. const item = {
  4920. key: "team:bigmodel:product:org:project",
  4921. type: "teamPlan",
  4922. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
  4923. oauthProviderId: BIGMODEL_PROVIDER_ID,
  4924. label: "团队",
  4925. providerName: "BigModel",
  4926. teamPlanName: "团队",
  4927. organizationId: "org",
  4928. projectId: "project",
  4929. currentProductId: "product",
  4930. provider: createProvider({
  4931. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
  4932. models: ["expired-hidden-model"],
  4933. }),
  4934. status: "unavailable",
  4935. statusActive: false,
  4936. availabilityReason: "credential-unavailable",
  4937. statusMessage: "旧 Key 错误",
  4938. } as const;
  4939. expect(resolveTeamPlanInspectionAccess(item)).toEqual({
  4940. type: "zhipu-account",
  4941. family: "bigmodel",
  4942. planKind: "team-coding-plan",
  4943. productId: "product",
  4944. organizationId: "org",
  4945. projectId: "project",
  4946. });
  4947. expect(resolveTeamPlanInspectionAccess({ ...item, projectId: "" })).toBeUndefined();
  4948. const resolved = resolveTeamScopedPlanNavItem(item, {
  4949. loading: false,
  4950. error: null,
  4951. refresh: vi.fn(),
  4952. snapshot: {
  4953. ...createEntitlementSnapshot(),
  4954. subscription: null,
  4955. unavailableReason: "no_plan",
  4956. teamPlanUnavailableReason: reason,
  4957. },
  4958. } as never);
  4959. const label =
  4960. reason === "expired"
  4961. ? "settings.modelProvider.codingPlan.status.teamExpired"
  4962. : "settings.modelProvider.codingPlan.status.teamUnavailable";
  4963. expect(resolved.statusLabelId).toBe(label);
  4964. const html = renderDetail(resolved, { onRetryCodingPlan: vi.fn() });
  4965. expect(html).toContain(label);
  4966. expect(html).not.toContain("旧 Key 错误");
  4967. expect(html).not.toContain("expired-hidden-model");
  4968. expect(html).not.toContain("common.retry");
  4969. expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
  4970. expect(html).not.toContain("settings.modelProvider.codingPlan.description.unavailable");
  4971. });
  4972. it("Team Plan quota 正在刷新时显示 checking,而不是误报未分配", () => {
  4973. const item = {
  4974. key: "team:bigmodel:product-team:org-team:proj-team",
  4975. type: "teamPlan",
  4976. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
  4977. oauthProviderId: BIGMODEL_PROVIDER_ID,
  4978. label: "BigModel - Team A",
  4979. providerName: "BigModel",
  4980. provider: createProvider({
  4981. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
  4982. }),
  4983. status: "unavailable",
  4984. statusLabelId: "settings.modelProvider.codingPlan.status.teamUnavailable",
  4985. planLevel: "Team A",
  4986. teamPlanName: "Team A",
  4987. organizationId: "org-team",
  4988. projectId: "proj-team",
  4989. currentProductId: "product-team",
  4990. quotaLimits: [],
  4991. statusActive: false,
  4992. } as const;
  4993. const resolved = resolveTeamScopedPlanNavItem(item, {
  4994. loading: true,
  4995. error: null,
  4996. snapshot: null,
  4997. refresh: vi.fn(),
  4998. } as never);
  4999. expect(resolved.status).toBe("checking");
  5000. expect(resolved.statusLabelId).toBeUndefined();
  5001. expect(resolved.statusActive).toBe(false);
  5002. });
  5003. it("Team Plan quota 查询报错时显示通用获取失败,而不是误报未分配", () => {
  5004. const item = {
  5005. key: "team:bigmodel:product-team:org-team:proj-team",
  5006. type: "teamPlan",
  5007. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
  5008. oauthProviderId: BIGMODEL_PROVIDER_ID,
  5009. label: "BigModel - Team A",
  5010. providerName: "BigModel",
  5011. provider: createProvider({
  5012. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
  5013. }),
  5014. status: "unavailable",
  5015. statusLabelId: "settings.modelProvider.codingPlan.status.teamUnavailable",
  5016. planLevel: "Team A",
  5017. teamPlanName: "Team A",
  5018. organizationId: "org-team",
  5019. projectId: "proj-team",
  5020. currentProductId: "product-team",
  5021. quotaLimits: [],
  5022. statusActive: false,
  5023. } as const;
  5024. const resolved = resolveTeamScopedPlanNavItem(item, {
  5025. loading: false,
  5026. error: new Error("network failed"),
  5027. snapshot: null,
  5028. refresh: vi.fn(),
  5029. } as never);
  5030. expect(resolved.status).toBe("unavailable");
  5031. expect(resolved.statusLabelId).toBeUndefined();
  5032. expect(resolved.statusActive).toBe(false);
  5033. });
  5034. it("Coding Plan 用量卡只展示接口返回且可识别的额度项", () => {
  5035. const html = renderDetail({
  5036. key: "coding-plan:account:zai-individual-coding-plan",
  5037. type: "codingPlan",
  5038. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  5039. oauthProviderId: ZAI_PROVIDER_ID,
  5040. label: "Z.ai - Coding Plan",
  5041. providerName: "Z.ai",
  5042. provider: createProvider(),
  5043. status: "purchased",
  5044. planLevel: "pro",
  5045. quotaLimits: [
  5046. {
  5047. type: "TOKENS_LIMIT",
  5048. unit: 3,
  5049. number: 5,
  5050. usage: 100_000,
  5051. remaining: 900_000,
  5052. percentage: 10,
  5053. usageDetails: [],
  5054. },
  5055. {
  5056. type: "TOKENS_LIMIT",
  5057. unit: 6,
  5058. usage: 200_000,
  5059. remaining: 800_000,
  5060. percentage: 20,
  5061. usageDetails: [],
  5062. },
  5063. ],
  5064. statusActive: true,
  5065. });
  5066. expect(html).toContain("settings.usage.entitlementFiveHourUsage");
  5067. expect(html).toContain("settings.usage.entitlementWeeklyUsage");
  5068. expect(html).not.toContain("settings.usage.entitlementMonthlyMcpUsage");
  5069. expect(html).toContain("90%");
  5070. expect(html).toContain("80%");
  5071. expect(html).not.toContain("background-color:var(--color-usage-chart-3)");
  5072. });
  5073. it("Team Plan 非标准额度项也会展示用量卡", () => {
  5074. const html = renderDetail({
  5075. key: "team:bigmodel:product-team-pro",
  5076. type: "teamPlan",
  5077. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  5078. oauthProviderId: BIGMODEL_PROVIDER_ID,
  5079. label: "BigModel - Pro Plan",
  5080. providerName: "BigModel",
  5081. teamPlanName: "Pro",
  5082. organizationId: "org-team-a",
  5083. projectId: "proj-team-a",
  5084. provider: createProvider({
  5085. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  5086. }),
  5087. status: "purchased",
  5088. planLevel: "Pro",
  5089. quotaLimits: [
  5090. {
  5091. type: "team_model_usage",
  5092. number: 2_000_000,
  5093. remaining: 1_500_000,
  5094. usage: 500_000,
  5095. usageDetails: [{ modelCode: "glm-5.2", displayName: "GLM-5.2", usage: 500_000 }],
  5096. },
  5097. ],
  5098. statusActive: true,
  5099. });
  5100. expect(html).toContain("settings.modelProvider.planCard.usage.totalTokens");
  5101. expect(html).toContain("GLM-5.2");
  5102. expect(html).toContain("75%");
  5103. expect(html).toContain("background-color:var(--color-usage-chart-1)");
  5104. });
  5105. it("Z.ai Coding Plan Upgrade 等待 OAuth 时显示 loading", () => {
  5106. const html = renderDetail(
  5107. {
  5108. key: "coding-plan:account:zai-individual-coding-plan",
  5109. type: "codingPlan",
  5110. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  5111. oauthProviderId: ZAI_PROVIDER_ID,
  5112. label: "Z.ai - Coding Plan",
  5113. providerName: "Z.ai",
  5114. provider: createProvider(),
  5115. status: "purchased",
  5116. planLevel: "Start",
  5117. currentProductId: "zai-start-free-monthly",
  5118. purchaseUrl: "https://z.ai/",
  5119. statusActive: true,
  5120. },
  5121. {
  5122. presetSubscriptionProviderId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  5123. },
  5124. );
  5125. expect(html).toContain("settings.modelProvider.codingPlan.upgrade");
  5126. expect(html).toContain("lucide-loader-circle");
  5127. });
  5128. it("Coding Plan 已开通但套餐详情为空时状态卡片不空白", () => {
  5129. const html = renderDetail({
  5130. key: "coding-plan:account:zai-individual-coding-plan",
  5131. type: "codingPlan",
  5132. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  5133. oauthProviderId: ZAI_PROVIDER_ID,
  5134. label: "Z.ai - Coding Plan",
  5135. providerName: "Z.ai",
  5136. provider: createProvider(),
  5137. status: "purchased",
  5138. planLevel: null,
  5139. subscriptionRenewTime: null,
  5140. subscriptionExpireTime: null,
  5141. statusActive: true,
  5142. });
  5143. expect(html).not.toContain("settings.modelProvider.codingPlan.status.purchased");
  5144. expect(html).toContain("settings.modelProvider.codingPlan.upgrade");
  5145. expect(html).not.toContain("settings.modelProvider.codingPlan.manage");
  5146. });
  5147. it("系统关闭的 Coding Plan 状态卡片不显示启用状态或开关", () => {
  5148. const html = renderDetail({
  5149. key: "coding-plan:account:zai-individual-coding-plan",
  5150. type: "codingPlan",
  5151. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  5152. oauthProviderId: ZAI_PROVIDER_ID,
  5153. label: "Z.ai - Coding Plan",
  5154. providerName: "Z.ai",
  5155. provider: createProvider({
  5156. enabled: false,
  5157. systemDisabledReason: "coding_plan_auth_failed",
  5158. }),
  5159. status: "purchased",
  5160. planLevel: "pro",
  5161. purchaseUrl: "https://z.ai/",
  5162. statusActive: false,
  5163. });
  5164. expect(html).not.toContain("settings.modelProvider.disabledStatus");
  5165. expect(html).not.toContain("settings.modelProvider.enableAction");
  5166. expect(html.split("settings.modelProvider.models")[0]).not.toContain(
  5167. "settings.modelProvider.disableAction",
  5168. );
  5169. });
  5170. it("用户关闭的 Start Plan 未连接卡片不显示启用开关", () => {
  5171. const html = renderDetail({
  5172. key: "coding-plan:account:zai-start-plan",
  5173. type: "codingPlan",
  5174. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  5175. oauthProviderId: ZAI_PROVIDER_ID,
  5176. label: "Z.ai - Coding Plan",
  5177. providerName: "Z.ai",
  5178. provider: createProvider({
  5179. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  5180. name: "Z.ai - Coding Plan",
  5181. apiKey: "",
  5182. enabled: false,
  5183. systemDisabledReason: undefined,
  5184. }),
  5185. status: "disconnected",
  5186. purchaseUrl: "https://z.ai/",
  5187. statusActive: false,
  5188. });
  5189. expect(html).not.toContain("settings.modelProvider.enableAction");
  5190. });
  5191. it("系统关闭的 Start Plan 未连接卡片不显示启用开关", () => {
  5192. const html = renderDetail({
  5193. key: "coding-plan:account:zai-start-plan",
  5194. type: "codingPlan",
  5195. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  5196. oauthProviderId: ZAI_PROVIDER_ID,
  5197. label: "Z.ai - Coding Plan",
  5198. providerName: "Z.ai",
  5199. provider: createProvider({
  5200. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  5201. name: "Z.ai - Coding Plan",
  5202. apiKey: "",
  5203. enabled: false,
  5204. systemDisabledReason: "coding_plan_not_authenticated",
  5205. }),
  5206. status: "disconnected",
  5207. purchaseUrl: "https://z.ai/",
  5208. statusActive: false,
  5209. });
  5210. expect(html).not.toContain("settings.modelProvider.enableAction");
  5211. expect(html).not.toContain("settings.modelProvider.disableAction");
  5212. });
  5213. it("Z.ai Start Plan 状态卡片隐藏续期时间且不展示管理和解绑入口", () => {
  5214. vi.useFakeTimers();
  5215. try {
  5216. vi.setSystemTime(new Date(2026, 6, 10, 12, 0));
  5217. const html = renderDetail({
  5218. key: "coding-plan:account:zai-start-plan",
  5219. type: "codingPlan",
  5220. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  5221. oauthProviderId: ZAI_PROVIDER_ID,
  5222. label: "Z.ai - Coding Plan",
  5223. providerName: "Z.ai",
  5224. provider: createProvider({
  5225. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  5226. name: "Z.ai - Coding Plan",
  5227. }),
  5228. status: "purchased",
  5229. planLevel: "Start",
  5230. subscriptionRenewTime: new Date(2026, 6, 10, 0, 23).toISOString(),
  5231. subscriptionExpireTime: new Date(2026, 6, 10, 23, 59).toISOString(),
  5232. purchaseUrl: "https://z.ai/",
  5233. statusActive: true,
  5234. });
  5235. expect(html.match(/settings\.modelProvider\.planCard\.startPlan/g)?.length).toBe(1);
  5236. expect(html).not.toContain("settings.modelProvider.enabledStatus");
  5237. expect(html.split("settings.modelProvider.models")[0]).not.toContain(
  5238. "settings.modelProvider.disableAction",
  5239. );
  5240. expect(html).not.toContain("settings.modelProvider.codingPlan.start.freeBadge");
  5241. expect(html).toContain("settings.modelProvider.startPlan.expiresAt");
  5242. expect(html).toContain("Jul 10");
  5243. expect(html).not.toContain("settings.modelProvider.codingPlan.renewsAt");
  5244. expect(html).not.toContain("Jul 10 00:23");
  5245. expect(html).not.toContain("Today 00:23");
  5246. expect(html).not.toContain("settings.modelProvider.codingPlan.title");
  5247. // 语义变更:体验套餐卡片不再提供「管理」「解绑」操作,只保留升级 Coding Plan 入口。
  5248. expect(html).not.toContain("settings.modelProvider.codingPlan.manage");
  5249. expect(html).not.toContain("settings.modelProvider.codingPlan.disconnect");
  5250. expect(html).toContain("settings.modelProvider.codingPlan.upgrade");
  5251. expect(html).not.toContain("settings.modelProvider.baseUrl");
  5252. expectConnectionApiFormatHidden(html);
  5253. expect(html).not.toContain("settings.modelProvider.apiKey");
  5254. expect(html).not.toContain("settings.modelProvider.codingPlan.productsLoading");
  5255. expect(html).not.toContain("settings.modelProvider.startPlan.summaryTitle");
  5256. expect(html).not.toContain("settings.modelProvider.startPlan.heroMetric");
  5257. expect(html).not.toContain("settings.modelProvider.startPlan.summaryDescription");
  5258. } finally {
  5259. vi.useRealTimers();
  5260. }
  5261. });
  5262. it("Z.ai Start Plan 状态卡片只显示过期日期", () => {
  5263. vi.useFakeTimers();
  5264. try {
  5265. vi.setSystemTime(new Date(2026, 5, 3, 12, 0));
  5266. const html = renderDetail({
  5267. key: "coding-plan:account:zai-start-plan",
  5268. type: "codingPlan",
  5269. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  5270. oauthProviderId: ZAI_PROVIDER_ID,
  5271. label: "Z.ai - Coding Plan",
  5272. providerName: "Z.ai",
  5273. provider: createProvider({
  5274. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  5275. name: "Z.ai - Coding Plan",
  5276. }),
  5277. status: "purchased",
  5278. planLevel: "Start",
  5279. subscriptionRenewTime: new Date(2026, 5, 8, 0, 23).toISOString(),
  5280. subscriptionExpireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
  5281. purchaseUrl: "https://z.ai/",
  5282. statusActive: true,
  5283. });
  5284. expect(html).toContain("settings.modelProvider.startPlan.expiresAt");
  5285. expect(html).toContain("Jun 8");
  5286. expect(html).not.toContain("settings.modelProvider.codingPlan.renewsAt");
  5287. expect(html).not.toContain("Jun 8 00:23");
  5288. expect(html).not.toContain("Jun 8, 00:23");
  5289. expect(html).not.toContain("Jun 8 23:59");
  5290. } finally {
  5291. vi.useRealTimers();
  5292. }
  5293. });
  5294. it("Z.ai Start Plan 显示余额卡片", () => {
  5295. const html = renderDetail({
  5296. key: "coding-plan:account:zai-start-plan",
  5297. type: "codingPlan",
  5298. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  5299. oauthProviderId: ZAI_PROVIDER_ID,
  5300. label: "Z.ai - Coding Plan",
  5301. providerName: "Z.ai",
  5302. provider: createProvider({
  5303. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  5304. name: "Z.ai - Coding Plan",
  5305. }),
  5306. status: "purchased",
  5307. planLevel: "Start",
  5308. subscriptionRenewTime: new Date(2026, 5, 8, 23, 2).toISOString(),
  5309. subscriptionExpireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
  5310. // 生产数据形态:purchased 快照必带 active 套餐详情,额度桶带 plan_id。
  5311. subscriptionDetails: [
  5312. {
  5313. productId: "zcode-v3-start-plan",
  5314. productName: "ZCode V3 Start Plan",
  5315. purchaseTime: null,
  5316. beginTime: null,
  5317. billingCycle: "daily",
  5318. renewTime: null,
  5319. expireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
  5320. },
  5321. ],
  5322. quotaLimits: [
  5323. {
  5324. type: "ent_zcode_v3_glm_52",
  5325. planId: "zcode-v3-start-plan",
  5326. number: 3_000_000,
  5327. usage: 500_000,
  5328. remaining: 2_500_000,
  5329. nextResetTime: new Date(2026, 5, 8, 23, 2).getTime(),
  5330. usageDetails: [{ modelCode: "glm-5.2", displayName: "GLM-5.2", usage: 500_000 }],
  5331. },
  5332. {
  5333. type: "ent_zcode_v3_glm_5turbo",
  5334. planId: "zcode-v3-start-plan",
  5335. number: 1_000_000,
  5336. usage: 0,
  5337. remaining: 1_000_000,
  5338. nextResetTime: new Date(2026, 5, 8, 23, 2).getTime(),
  5339. usageDetails: [
  5340. {
  5341. modelCode: "glm-5-turbo",
  5342. displayName: "GLM-5-Turbo",
  5343. usage: 0,
  5344. },
  5345. ],
  5346. },
  5347. {
  5348. type: "ent_zcode_v3_glm_coding_lite",
  5349. planId: "zcode-v3-start-plan",
  5350. number: 2_000_000,
  5351. usage: 0,
  5352. remaining: 2_000_000,
  5353. nextResetTime: new Date(2026, 5, 8, 23, 2).getTime(),
  5354. usageDetails: [
  5355. {
  5356. modelCode: "glm-coding-lite",
  5357. displayName: "GLM CODING LITE",
  5358. usage: 0,
  5359. },
  5360. ],
  5361. },
  5362. ],
  5363. purchaseUrl: "https://z.ai/",
  5364. statusActive: true,
  5365. });
  5366. expect(html).toContain("settings.modelProvider.startPlan.balance.title");
  5367. // 体验套餐用量卡片不展示「管理」「解绑」操作,只保留升级 Coding Plan 入口。
  5368. expect(html).not.toContain("settings.modelProvider.codingPlan.manage");
  5369. expect(html).not.toContain("settings.modelProvider.codingPlan.disconnect");
  5370. expect(html).toContain("settings.modelProvider.codingPlan.upgrade");
  5371. // 多卡路径下套餐到期时间只在 StartPlanStatusMeta 渲染一次;
  5372. // 余额卡不再重复展示套餐级 expireTime。
  5373. expect(html.match(/settings\.modelProvider\.startPlan\.expiresAt/g)?.length).toBe(1);
  5374. expect(html).not.toContain("settings.modelProvider.startPlan.balance.remaining");
  5375. expect(html).toContain("GLM-5.2");
  5376. expect(html).toContain("GLM-5-Turbo");
  5377. expect(html).toContain("GLM Coding Lite");
  5378. expect(html).not.toContain("GLM CODING LITE");
  5379. expect(html.indexOf("GLM-5.2")).toBeLessThan(html.indexOf("GLM-5-Turbo"));
  5380. expect(html).not.toContain("GLM-5Turbo");
  5381. expect(html).toContain("83%");
  5382. // 桶刷新时间非当日仅展示日期(Jun 8),与 Coding Plan 重置时间格式对齐。
  5383. expect(html).not.toContain("23:02");
  5384. expect(html).toContain("2,500,000 / 3,000,000");
  5385. expect(html).toContain("1,000,000 / 1,000,000");
  5386. expect(html).not.toContain("2.5M / 3M");
  5387. expect(html).not.toContain("Used 500K");
  5388. });
  5389. it("Start Plan 按服务端顺序展示多个套餐并按 plan id 隔离额度桶", () => {
  5390. const html = renderToStaticMarkup(
  5391. createElement(CodingPlanStatusPanel, {
  5392. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  5393. providerName: "Z.ai",
  5394. status: "purchased",
  5395. planLevel: "Welcome Plan",
  5396. subscriptionDetails: [
  5397. {
  5398. productId: "plan-welcome",
  5399. productName: "Welcome Plan",
  5400. purchaseTime: null,
  5401. beginTime: null,
  5402. billingCycle: "daily",
  5403. renewTime: null,
  5404. expireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
  5405. },
  5406. {
  5407. productId: "plan-bonus",
  5408. productName: "Bonus Plan",
  5409. purchaseTime: null,
  5410. beginTime: null,
  5411. billingCycle: "daily",
  5412. renewTime: null,
  5413. expireTime: new Date(2026, 5, 15, 23, 59).toISOString(),
  5414. entitlements: [
  5415. {
  5416. entitlementId: "bonus-glm-5-turbo",
  5417. showName: "GLM-5-Turbo",
  5418. effectiveTime: "2096-08-28T07:00:00.000Z",
  5419. },
  5420. ],
  5421. },
  5422. ],
  5423. quotaLimits: [
  5424. {
  5425. type: "welcome-glm-52",
  5426. planId: "plan-welcome",
  5427. number: 3_000_000,
  5428. remaining: 2_500_000,
  5429. nextResetTime: new Date(2026, 5, 8, 10, 11).getTime(),
  5430. usageDetails: [{ modelCode: "glm-5.2", displayName: "GLM-5.2", usage: 500_000 }],
  5431. },
  5432. {
  5433. type: "bonus-glm-5-turbo",
  5434. planId: "plan-bonus",
  5435. number: 1_000_000,
  5436. remaining: 750_000,
  5437. nextResetTime: new Date(2026, 5, 15, 12, 22).getTime(),
  5438. usageDetails: [
  5439. {
  5440. modelCode: "glm-5-turbo",
  5441. displayName: "GLM-5-Turbo",
  5442. usage: 250_000,
  5443. },
  5444. ],
  5445. },
  5446. ],
  5447. }),
  5448. );
  5449. expect(html.indexOf("Welcome Plan")).toBeLessThan(html.indexOf("Bonus Plan"));
  5450. expect(html).toContain("Jun 8");
  5451. expect(html).toContain("Jun 15");
  5452. // 桶刷新时间与 Coding Plan 对齐:非当日仅展示日期,不携带小时分钟。
  5453. expect(html).not.toContain("10:11");
  5454. expect(html).not.toContain("12:22");
  5455. expect(html).toContain("GLM-5.2");
  5456. expect(html).toContain("GLM-5-Turbo");
  5457. const welcomeIndex = html.indexOf("Welcome Plan");
  5458. const bonusIndex = html.indexOf("Bonus Plan");
  5459. expect(html.slice(welcomeIndex, bonusIndex)).toContain("GLM-5.2");
  5460. expect(html.slice(welcomeIndex, bonusIndex)).not.toContain("GLM-5-Turbo");
  5461. expect(html.slice(bonusIndex)).toContain("GLM-5-Turbo");
  5462. expect(html.slice(bonusIndex)).toContain("settings.modelProvider.startPlan.pendingUntil");
  5463. expect(html.slice(bonusIndex)).toContain('class="whitespace-nowrap text-success"');
  5464. expect(html.slice(bonusIndex)).toContain("settings.modelProvider.startPlan.expiresAt");
  5465. expect(html.slice(bonusIndex)).toContain(">·</span>");
  5466. });
  5467. it("Start Plan 只为尚未生效的 entitlement 展示最早生效时间", () => {
  5468. const now = Date.parse("2026-08-27T00:00:00.000Z");
  5469. expect(
  5470. resolvePendingStartPlanEffectiveTime(
  5471. [
  5472. {
  5473. entitlementId: "immediate",
  5474. effectiveTime: "1970-01-01T00:00:00.000Z",
  5475. },
  5476. { entitlementId: "past", effectiveTime: "2026-08-26T00:00:00.000Z" },
  5477. { entitlementId: "later", effectiveTime: "2026-08-29T00:00:00.000Z" },
  5478. {
  5479. entitlementId: "earlier",
  5480. effectiveTime: "2026-08-28T00:00:00.000Z",
  5481. },
  5482. ],
  5483. now,
  5484. ),
  5485. ).toBe("2026-08-28T00:00:00.000Z");
  5486. expect(
  5487. resolvePendingStartPlanEffectiveTime(
  5488. [
  5489. {
  5490. entitlementId: "immediate",
  5491. effectiveTime: "1970-01-01T00:00:00.000Z",
  5492. },
  5493. ],
  5494. now,
  5495. ),
  5496. ).toBeNull();
  5497. });
  5498. it("Start Plan 刷新完成只认当前 entitlement 对应的额度桶", () => {
  5499. const entitlements = [
  5500. {
  5501. entitlementId: "ent-weekend-glm-53-flash",
  5502. effectiveTime: "2026-09-01T12:00:00.000Z",
  5503. },
  5504. ];
  5505. expect(
  5506. hasStartPlanEntitlementQuota(entitlements, [
  5507. {
  5508. type: "ent-old-glm-52",
  5509. planId: "weekend-build",
  5510. number: 1,
  5511. remaining: 1,
  5512. usageDetails: [],
  5513. },
  5514. ]),
  5515. ).toBe(false);
  5516. expect(
  5517. hasStartPlanEntitlementQuota(entitlements, [
  5518. {
  5519. type: "ent-weekend-glm-53-flash",
  5520. planId: "weekend-build",
  5521. number: 1,
  5522. remaining: 1,
  5523. usageDetails: [],
  5524. },
  5525. ]),
  5526. ).toBe(true);
  5527. });
  5528. it("Start Plan 待生效元信息明确表达尚未生效", () => {
  5529. const now = new Date(2026, 8, 1, 10, 0).getTime();
  5530. const todayEffectiveTime = new Date(2026, 8, 1, 22, 0).toISOString();
  5531. const tomorrowEffectiveTime = new Date(2026, 8, 2, 22, 0).toISOString();
  5532. const laterEffectiveTime = new Date(2026, 8, 4, 22, 0).toISOString();
  5533. expect(zhCN["settings.modelProvider.startPlan.pendingUntil"]).toBe("待生效 {date}");
  5534. expect(enUS["settings.modelProvider.startPlan.pendingUntil"]).toBe("Pending {date}");
  5535. expect(formatStartPlanEffectiveDate(todayEffectiveTime, "zh-CN", now)).toBe("今天 22:00");
  5536. expect(formatStartPlanEffectiveDate(todayEffectiveTime, "en-US", now)).toBe("Today 22:00");
  5537. expect(formatStartPlanEffectiveDate(tomorrowEffectiveTime, "zh-CN", now)).toBe("明天 22:00");
  5538. expect(formatStartPlanEffectiveDate(tomorrowEffectiveTime, "en-US", now)).toBe(
  5539. "Tomorrow 22:00",
  5540. );
  5541. expect(formatStartPlanEffectiveDate(laterEffectiveTime, "zh-CN", now)).toBe("9月4日 22:00");
  5542. expect(formatStartPlanEffectiveDate(laterEffectiveTime, "en-US", now)).toBe("Sep 4, 22:00");
  5543. expect(formatStartPlanExpireDate(laterEffectiveTime, "zh-CN", now)).toBe("9月4日 22:00");
  5544. expect(formatStartPlanExpireDate(laterEffectiveTime, "en-US", now)).toBe("Sep 4, 22:00");
  5545. });
  5546. it("Start Plan 余额卡片不从剩余量反推已用量", () => {
  5547. const html = renderDetail({
  5548. key: "coding-plan:account:zai-start-plan",
  5549. type: "codingPlan",
  5550. presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  5551. oauthProviderId: ZAI_PROVIDER_ID,
  5552. label: "Z.ai - Coding Plan",
  5553. providerName: "Z.ai",
  5554. provider: createProvider({
  5555. id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  5556. name: "Z.ai - Coding Plan",
  5557. }),
  5558. status: "purchased",
  5559. planLevel: "Start",
  5560. subscriptionExpireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
  5561. // 生产数据形态:purchased 快照必带 active 套餐详情,额度桶带 plan_id。
  5562. subscriptionDetails: [
  5563. {
  5564. productId: "zcode-v3-start-plan",
  5565. productName: "ZCode V3 Start Plan",
  5566. purchaseTime: null,
  5567. beginTime: null,
  5568. billingCycle: "daily",
  5569. renewTime: null,
  5570. expireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
  5571. },
  5572. ],
  5573. quotaLimits: [
  5574. {
  5575. type: "ent_zcode_v3_glm_52",
  5576. planId: "zcode-v3-start-plan",
  5577. number: 3_000_000,
  5578. remaining: 2_734_000,
  5579. usageDetails: [{ modelCode: "glm-5.2", displayName: "GLM-5.2", usage: 0 }],
  5580. },
  5581. ],
  5582. purchaseUrl: "https://z.ai/",
  5583. statusActive: true,
  5584. });
  5585. expect(html).toContain("2,734,000 / 3,000,000");
  5586. expect(html).not.toContain("2.7M");
  5587. expect(html).not.toContain("Used 266K");
  5588. });
  5589. it("BigModel Start Plan 按余额接口顺序和 show_name 显示余额卡片", () => {
  5590. const html = renderDetail({
  5591. key: "coding-plan:account:bigmodel-start-plan",
  5592. type: "codingPlan",
  5593. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  5594. oauthProviderId: BIGMODEL_PROVIDER_ID,
  5595. label: "BigModel- Coding Plan",
  5596. providerName: "BigModel",
  5597. provider: createProvider({
  5598. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  5599. name: "BigModel- Coding Plan",
  5600. }),
  5601. status: "purchased",
  5602. planLevel: "Start",
  5603. subscriptionExpireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
  5604. subscriptionDetails: [
  5605. {
  5606. productId: "bigmodel-start",
  5607. productName: "Start",
  5608. purchaseTime: null,
  5609. beginTime: null,
  5610. billingCycle: "daily",
  5611. renewTime: null,
  5612. expireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
  5613. },
  5614. ],
  5615. quotaLimits: [
  5616. {
  5617. type: "ent_bigmodel_glm_52",
  5618. planId: "bigmodel-start",
  5619. number: 3_000_000,
  5620. usage: 0,
  5621. remaining: 3_000_000,
  5622. usageDetails: [{ modelCode: "glm-5.2", displayName: "GLM-5.2", usage: 0 }],
  5623. },
  5624. {
  5625. type: "ent_bigmodel_glm_5turbo",
  5626. planId: "bigmodel-start",
  5627. number: 1_000_000,
  5628. usage: 0,
  5629. remaining: 1_000_000,
  5630. usageDetails: [
  5631. {
  5632. modelCode: "glm-5-turbo",
  5633. displayName: "GLM-5-Turbo",
  5634. usage: 0,
  5635. },
  5636. ],
  5637. },
  5638. ],
  5639. purchaseUrl: "https://bigmodel.cn/",
  5640. statusActive: true,
  5641. });
  5642. expect(html).toContain("GLM-5.2");
  5643. expect(html).toContain("GLM-5-Turbo");
  5644. expect(html.indexOf("GLM-5.2")).toBeLessThan(html.indexOf("GLM-5-Turbo"));
  5645. expect(html).not.toContain("GLM-5Turbo");
  5646. });
  5647. it("Start Plan 兜底单卡不再渲染额度桶,余额未落定时仅保留查询占位", () => {
  5648. // 服务端契约保证 balances 只属于 active plans:purchased 快照必有套餐详情,
  5649. // 多卡路径必然可用。兜底分支(nav item 无套餐详情)不得把全量桶塞进单卡,
  5650. // 否则违背 spec「无匹配 plan_id 的桶不得附着到任何卡片」。
  5651. const quotaLimits = [
  5652. {
  5653. type: "ent_zcode_v3_glm_52",
  5654. planId: "zcode-v3-start-plan",
  5655. number: 3_000_000,
  5656. remaining: 2_734_000,
  5657. usageDetails: [{ modelCode: "glm-5.2", displayName: "GLM-5.2", usage: 0 }],
  5658. },
  5659. ];
  5660. const settledHtml = renderToStaticMarkup(
  5661. createElement(CodingPlanStatusPanel, {
  5662. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  5663. providerName: "Z.ai",
  5664. status: "purchased",
  5665. subscriptionDetails: [],
  5666. quotaLimits,
  5667. }),
  5668. );
  5669. expect(settledHtml).not.toContain("settings.modelProvider.startPlan.balance.title");
  5670. expect(settledHtml).not.toContain("2,734,000 / 3,000,000");
  5671. // 兜底分支的套餐卡本体仍在(标题 + 升级按钮),只是不再渲染额度桶。
  5672. expect(settledHtml).toContain("settings.modelProvider.planCard.startPlan");
  5673. expect(settledHtml).toContain("settings.modelProvider.codingPlan.upgrade");
  5674. const checkingHtml = renderToStaticMarkup(
  5675. createElement(CodingPlanStatusPanel, {
  5676. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  5677. providerName: "Z.ai",
  5678. status: "purchased",
  5679. viewState: {
  5680. displayStatus: "purchased",
  5681. actionStatus: "purchased",
  5682. balanceStatus: "checking",
  5683. loginLoading: false,
  5684. },
  5685. subscriptionDetails: [],
  5686. quotaLimits,
  5687. }),
  5688. );
  5689. expect(checkingHtml).toContain("settings.modelProvider.startPlan.balance.title");
  5690. expect(checkingHtml).not.toContain("2,734,000 / 3,000,000");
  5691. });
  5692. it("Start 明确要求重新登录时不走网络重试,文案不作为操作判断", () => {
  5693. const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan;
  5694. const provider = createProvider({ id: providerId });
  5695. const html = renderDetail(
  5696. {
  5697. key: `coding-plan:${providerId}`,
  5698. type: "codingPlan",
  5699. presetId: providerId,
  5700. oauthProviderId: BIGMODEL_PROVIDER_ID,
  5701. label: "Start",
  5702. providerName: "BigModel",
  5703. provider,
  5704. status: "unavailable",
  5705. statusActive: false,
  5706. accountLoginRequired: true,
  5707. statusLabelId: "custom.login.message",
  5708. },
  5709. { onRetryCodingPlan: vi.fn() },
  5710. );
  5711. expect(html).not.toContain("common.retry");
  5712. expect(html).toContain("chat.error.action.relogin");
  5713. const noPlanHtml = renderDetail(
  5714. {
  5715. key: `coding-plan:${providerId}`,
  5716. type: "codingPlan",
  5717. presetId: providerId,
  5718. oauthProviderId: BIGMODEL_PROVIDER_ID,
  5719. label: "Start",
  5720. providerName: "BigModel",
  5721. provider,
  5722. status: "notPurchased",
  5723. statusActive: false,
  5724. },
  5725. { providerSettingsView: createProviderSettingsView(provider) },
  5726. );
  5727. expect(noPlanHtml).not.toContain("settings.modelProvider.accountProviderConfigMissing");
  5728. });
  5729. it("Start 无套餐卡不显示付费订阅按钮", () => {
  5730. const html = renderToStaticMarkup(
  5731. createElement(CodingPlanStatusPanel, {
  5732. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  5733. providerName: "BigModel",
  5734. status: "notPurchased",
  5735. startPlanPreviewVisible: false,
  5736. }),
  5737. );
  5738. expect(html).toContain("settings.modelProvider.startPlan.status.noPlan");
  5739. expect(html).not.toContain("settings.modelProvider.codingPlan.subscribe");
  5740. });
  5741. it("BigModel Start Plan 未登录且无远端 preview 时显示登录入口,不伪造套餐和模型", () => {
  5742. const html = renderDetail({
  5743. key: "coding-plan:account:bigmodel-start-plan",
  5744. type: "codingPlan",
  5745. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  5746. oauthProviderId: BIGMODEL_PROVIDER_ID,
  5747. label: "BigModel- Coding Plan",
  5748. providerName: "BigModel",
  5749. provider: null,
  5750. status: "disconnected",
  5751. purchaseUrl: "https://bigmodel.cn/",
  5752. statusActive: false,
  5753. });
  5754. expect(html).toContain("settings.modelProvider.planCard.startPlan");
  5755. expect(html).not.toContain("settings.modelProvider.startPlan.quotaSectionTitle");
  5756. expect(html).not.toContain("settings.modelProvider.startPlan.summaryTitle");
  5757. expect(html).not.toContain("settings.modelProvider.startPlan.heroMetric");
  5758. expect(html).not.toContain("settings.modelProvider.startPlan.summaryDescription");
  5759. expect(html).not.toContain("settings.modelProvider.startPlan.eligibleNewUser");
  5760. expect(html).toContain("settings.modelProvider.startPlan.status.loginRequired");
  5761. expect(html).toContain("settings.modelProvider.startPlan.login");
  5762. expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
  5763. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.startPlanTitle");
  5764. expect(html).not.toContain(
  5765. "settings.modelProvider.codingPlan.purchaseBanner.startPlanDescription",
  5766. );
  5767. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.personalTitle");
  5768. expect(html).not.toContain(
  5769. "settings.modelProvider.codingPlan.purchaseBanner.personalDescription",
  5770. );
  5771. expect(html).not.toContain("CN¥49.00+");
  5772. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamTitle");
  5773. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamDescription");
  5774. expect(html).not.toContain("CN¥598.00+");
  5775. expect(html).not.toContain("color-mix(in_srgb,var(--color-success)_24%");
  5776. expect(html).not.toContain("color-mix(in_srgb,#4099ff_24%");
  5777. expect(html).not.toContain("color-mix(in_srgb,#0ea5e9_24%");
  5778. expect(html).not.toContain("circle_at_14%_12%");
  5779. expect(html).toContain("w-full");
  5780. expect(html).not.toContain("bg-background/80");
  5781. expect(html).not.toContain("sm:grid-cols-3");
  5782. expect(html).not.toContain("button-gradient");
  5783. expect(html).not.toContain("settings.modelProvider.codingPlan.description.disconnected");
  5784. expect(html).not.toContain("settings.modelProvider.codingPlan.productsLoading");
  5785. expect(html).not.toContain("settings.modelProvider.models");
  5786. expect(html).not.toContain("settings.modelProvider.apiKey");
  5787. });
  5788. it.each(["disconnected", "notPurchased"] as const)(
  5789. "BigModel Start Plan %s 详情隐藏远端体验套餐推广",
  5790. (status) => {
  5791. primeStartPlanPreviewCacheForTest({
  5792. planId: "zcode-v3-start-plan",
  5793. name: "ZCode V3 Start Plan",
  5794. entitlements: [
  5795. {
  5796. grantUnits: 10_000_000,
  5797. meter: "model_usage",
  5798. period: "daily",
  5799. showName: "GLM-5.2",
  5800. unitType: "token",
  5801. },
  5802. {
  5803. grantUnits: 10_000_000,
  5804. meter: "model_usage",
  5805. period: "daily",
  5806. showName: "GLM-5.1",
  5807. unitType: "token",
  5808. },
  5809. {
  5810. grantUnits: 10_000_000,
  5811. meter: "model_usage",
  5812. period: "daily",
  5813. showName: "GLM-5-Turbo",
  5814. unitType: "token",
  5815. },
  5816. ],
  5817. });
  5818. const html = renderDetail({
  5819. key: "coding-plan:account:bigmodel-start-plan",
  5820. type: "codingPlan",
  5821. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  5822. oauthProviderId: BIGMODEL_PROVIDER_ID,
  5823. label: "BigModel- Coding Plan",
  5824. providerName: "BigModel",
  5825. provider: null,
  5826. status,
  5827. purchaseUrl: "https://bigmodel.cn/",
  5828. statusActive: false,
  5829. });
  5830. expect(html).not.toContain("ZCode V3 Start Plan");
  5831. expect(html).not.toContain("30 Million");
  5832. expect(html).not.toContain("tokens per day");
  5833. expect(html).not.toContain("Daily quota · GLM-5.2 / GLM-5.1 / GLM-5-Turbo 10M each");
  5834. expect(html).not.toContain("color-mix(in_srgb,var(--color-success)_24%");
  5835. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.personalTitle");
  5836. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamTitle");
  5837. },
  5838. );
  5839. it("个人套餐未连接时即使缓存有体验套餐也不显示推广或模型列表", () => {
  5840. primeStartPlanPreviewCacheForTest({
  5841. planId: "start-preview",
  5842. name: "cached-start-banner",
  5843. entitlements: [
  5844. {
  5845. grantUnits: 8_000_000,
  5846. meter: "model_usage",
  5847. period: "daily",
  5848. showName: "GLM",
  5849. unitType: "token",
  5850. },
  5851. ],
  5852. });
  5853. const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan;
  5854. const html = renderDetail({
  5855. key: `coding-plan:${providerId}`,
  5856. type: "codingPlan",
  5857. presetId: providerId,
  5858. oauthProviderId: BIGMODEL_PROVIDER_ID,
  5859. label: "BigModel",
  5860. providerName: "BigModel",
  5861. provider: createProvider({ id: providerId, models: ["disconnected-model"] }),
  5862. status: "disconnected",
  5863. statusActive: false,
  5864. });
  5865. expect(html).not.toContain("cached-start-banner");
  5866. expect(html).not.toContain("disconnected-model");
  5867. expect(html).not.toContain("settings.modelProvider.addModel");
  5868. expect(html).toContain("settings.modelProvider.codingPlan.connect");
  5869. });
  5870. it("BigModel Start Plan 中文详情不显示推广额度", () => {
  5871. intlMockState.locale = "zh-CN";
  5872. primeStartPlanPreviewCacheForTest({
  5873. planId: "zcode-v3-start-plan",
  5874. name: "ZCode V3 Start Plan",
  5875. entitlements: [
  5876. {
  5877. grantUnits: 5_000_000,
  5878. meter: "model_usage",
  5879. period: "daily",
  5880. showName: "GLM-5.2",
  5881. unitType: "token",
  5882. },
  5883. ],
  5884. });
  5885. const html = renderDetail({
  5886. key: "coding-plan:account:bigmodel-start-plan",
  5887. type: "codingPlan",
  5888. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  5889. oauthProviderId: BIGMODEL_PROVIDER_ID,
  5890. label: "BigModel- Coding Plan",
  5891. providerName: "BigModel",
  5892. provider: null,
  5893. status: "disconnected",
  5894. purchaseUrl: "https://bigmodel.cn/",
  5895. statusActive: false,
  5896. });
  5897. expect(html).not.toContain("ZCode V3 Start Plan");
  5898. expect(html).not.toContain("500万");
  5899. expect(html).not.toContain("tokens/日");
  5900. expect(html).not.toContain("每日额度 · GLM-5.2 500万");
  5901. expect(html).not.toContain("¥49.00");
  5902. expect(html).not.toContain("¥598.00");
  5903. expect(html).not.toContain("人民币 起");
  5904. });
  5905. it("BigModel Start Plan 中文详情保留标题且不显示体验推广", () => {
  5906. intlMockState.locale = "zh-CN";
  5907. primeStartPlanPreviewCacheForTest({
  5908. planId: "zcode-v3-start-plan",
  5909. name: "Start Plan",
  5910. entitlements: [
  5911. {
  5912. grantUnits: 5_000_000,
  5913. meter: "model_usage",
  5914. period: "daily",
  5915. showName: "GLM-5.2",
  5916. unitType: "token",
  5917. },
  5918. ],
  5919. });
  5920. const html = renderDetail({
  5921. key: "coding-plan:account:bigmodel-start-plan",
  5922. type: "codingPlan",
  5923. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  5924. oauthProviderId: BIGMODEL_PROVIDER_ID,
  5925. label: "BigModel- Coding Plan",
  5926. providerName: "BigModel",
  5927. provider: null,
  5928. status: "disconnected",
  5929. purchaseUrl: "https://bigmodel.cn/",
  5930. statusActive: false,
  5931. });
  5932. expect(html).not.toContain(">体验套餐<");
  5933. expect(html).toContain(">Start Plan<");
  5934. });
  5935. it("Coding Plan 权益误落到 Start provider 分支时显示权益名", () => {
  5936. expect(
  5937. resolveCodingPlanStatusCardTitle({
  5938. isPurchased: true,
  5939. isStartPlanProvider: true,
  5940. rawPlanLevel: "GLM Coding Pro",
  5941. displayPlanLevel: "GLM Coding Pro",
  5942. startPlanTitle: "Start Plan",
  5943. codingPlanTitle: "Coding Plan",
  5944. }),
  5945. ).toBe("GLM Coding Pro");
  5946. });
  5947. it("Start Plan 校验未知不会误判为未连接", () => {
  5948. expect(
  5949. resolveCodingPlanEntitlementState({
  5950. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  5951. accountEntitled: false,
  5952. accountAvailability: "unknown",
  5953. modelProvidersLoading: false,
  5954. }).status,
  5955. ).toBe("unavailable");
  5956. });
  5957. it("Start Plan 刷新失败保留套餐并显示失败和重试", () => {
  5958. const html = renderToStaticMarkup(
  5959. createElement(CodingPlanStatusPanel, {
  5960. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
  5961. providerName: "BigModel",
  5962. status: "purchased",
  5963. planLevel: "Start",
  5964. statusLabelId: "settings.modelProvider.codingPlan.status.unavailable",
  5965. onRetry: vi.fn(),
  5966. }),
  5967. );
  5968. expect(html).toContain("settings.modelProvider.planCard.startPlan");
  5969. expect(html).toContain("settings.modelProvider.codingPlan.status.unavailable");
  5970. expect(html).toContain("common.retry");
  5971. });
  5972. it("Start Plan 获取失败也保留自身标题", () => {
  5973. expect(
  5974. resolveCodingPlanStatusCardTitle({
  5975. isPurchased: false,
  5976. isUnavailable: true,
  5977. isStartPlanProvider: true,
  5978. rawPlanLevel: "",
  5979. displayPlanLevel: "",
  5980. startPlanTitle: "Start Plan",
  5981. codingPlanTitle: "Coding Plan",
  5982. }),
  5983. ).toBe("Start Plan");
  5984. });
  5985. it("Start Plan 权益继续显示 Start Plan", () => {
  5986. expect(
  5987. resolveCodingPlanStatusCardTitle({
  5988. isPurchased: true,
  5989. isStartPlanProvider: true,
  5990. rawPlanLevel: "ZCode V3 Start Plan",
  5991. displayPlanLevel: "ZCode V3 Start Plan",
  5992. startPlanTitle: "Start Plan",
  5993. codingPlanTitle: "Coding Plan",
  5994. }),
  5995. ).toBe("Start Plan");
  5996. });
  5997. it("Team Plan 不可用时状态卡标题保留团队名", () => {
  5998. expect(
  5999. resolveCodingPlanStatusCardTitle({
  6000. isPurchased: false,
  6001. isStartPlanProvider: false,
  6002. inactivePlanTitle: "Org A",
  6003. rawPlanLevel: "Org A",
  6004. displayPlanLevel: "ORG A",
  6005. startPlanTitle: "Start Plan",
  6006. codingPlanTitle: "Coding Plan",
  6007. }),
  6008. ).toBe("Org A");
  6009. });
  6010. it("Start Plan 活动升级按钮使用渐变背景", () => {
  6011. const html = renderToStaticMarkup(
  6012. createElement(CodingPlanUpgradeAction, {
  6013. loginLoading: false,
  6014. upgradePlansVisible: false,
  6015. codingPlanPurchaseTokenAuthenticated: true,
  6016. billingDiscountActive: true,
  6017. billingDiscountConfig: {
  6018. "en-US": {
  6019. badgeBody: "150% Quota",
  6020. infoTitle: "Entitlement Rules",
  6021. infoBody: "Remote campaign rules",
  6022. },
  6023. },
  6024. onUpgradePlansVisibleChange: vi.fn(),
  6025. }),
  6026. );
  6027. expect(html).toContain("button-gradient");
  6028. expect(html).toContain("dark:bg-[#484A58]");
  6029. expect(html).toContain("bg-white");
  6030. expect(html).toContain("text-[#191A1D]");
  6031. expect(html).toContain("rounded-full");
  6032. expect(html).not.toContain("lucide-trending-up");
  6033. expect(html).toContain("lucide-info");
  6034. expect(html).toContain('data-slot="dialog-trigger"');
  6035. expect(html).not.toContain("uppercase");
  6036. expect(html).toContain("150% Quota");
  6037. });
  6038. it("聊天额度 Banner 的活动升级按钮与 Model Settings 使用一致样式", () => {
  6039. const html = renderToStaticMarkup(
  6040. createElement(ConversationQuotaBanner, {
  6041. state: {
  6042. visible: true,
  6043. kind: "model-very-low",
  6044. concurrentLimitBusinessCode: null,
  6045. concurrentLimitReason: null,
  6046. providerLimitedBusinessCode: null,
  6047. providerLimitedMessage: null,
  6048. modelName: "GLM-4.5",
  6049. remainingTokens: 12_800,
  6050. remainingPercent: 10,
  6051. dismissible: true,
  6052. blocksSubmit: false,
  6053. priority: 40,
  6054. },
  6055. billingDiscountActive: true,
  6056. billingDiscountConfig: {
  6057. "en-US": {
  6058. badgeBody: "150% Quota",
  6059. infoTitle: "Entitlement Rules",
  6060. infoBody: "Remote campaign rules",
  6061. },
  6062. },
  6063. onUpgrade: vi.fn(),
  6064. onDismiss: vi.fn(),
  6065. }),
  6066. );
  6067. expect(html).toContain("button-gradient");
  6068. expect(html).toContain("dark:bg-[#484A58]");
  6069. expect(html).toContain("pr-px");
  6070. expect(html).toContain("h-auto");
  6071. expect(html).toContain("150% Quota");
  6072. });
  6073. it("Coding Plan 活动 banner 右侧显示说明入口", () => {
  6074. const html = renderToStaticMarkup(
  6075. createElement(CodingPlanBillingDiscountBanner, {
  6076. config: {
  6077. "en-US": {
  6078. cardTitle: "Limited-time 150% Quota Campaign",
  6079. cardBody: "Upgrade your Coding Plan to get 150% quota during the campaign period",
  6080. badgeBody: "150% Quota",
  6081. infoTitle: "Entitlement Rules",
  6082. infoBody: "Remote campaign rules",
  6083. },
  6084. },
  6085. }),
  6086. );
  6087. expect(html).toContain("Limited-time 150% Quota Campaign");
  6088. expect(html).toContain("150% Quota");
  6089. expect(html).toContain("lucide-trending-up");
  6090. expect(html).toContain("lucide-info");
  6091. expect(html).not.toContain('data-slot="button"');
  6092. expect(html).toContain("bg-white");
  6093. expect(html).toContain("text-[#191A1D]");
  6094. expect(html).toContain("settings.modelProvider.codingPlan.billingDiscountInfo.open");
  6095. });
  6096. it("默认活动徽标旁的说明入口在浅色背景可见", () => {
  6097. const html = renderToStaticMarkup(
  6098. createElement(CodingPlanBillingDiscountBadge, {
  6099. config: {
  6100. "en-US": {
  6101. badgeBody: "150% Quota",
  6102. infoTitle: "Entitlement Rules",
  6103. infoBody: "Remote campaign rules",
  6104. },
  6105. },
  6106. }),
  6107. );
  6108. expect(html).toContain("150% Quota");
  6109. expect(html).toContain("lucide-info");
  6110. expect(html).not.toContain('data-slot="button"');
  6111. expect(html).toContain("text-foreground-subtle");
  6112. expect(html).not.toContain("text-white/90");
  6113. });
  6114. it("compact 活动徽标使用 badge 级字号", () => {
  6115. const html = renderToStaticMarkup(
  6116. createElement(CodingPlanBillingDiscountBadgePill, {
  6117. config: {
  6118. "en-US": {
  6119. badgeBody: "150% Quota",
  6120. },
  6121. },
  6122. size: "compact",
  6123. }),
  6124. );
  6125. expect(html).toContain("text-ui-xs");
  6126. expect(html).not.toContain("text-ui-sm");
  6127. expect(html).toContain("whitespace-nowrap");
  6128. });
  6129. it("远端未下发完整活动说明时不显示 Info 入口且不使用本地兜底", () => {
  6130. const html = renderToStaticMarkup(
  6131. createElement(CodingPlanBillingDiscountBadge, {
  6132. config: {
  6133. "en-US": {
  6134. badgeBody: "150% Quota",
  6135. infoTitle: "Entitlement Rules",
  6136. },
  6137. },
  6138. }),
  6139. );
  6140. expect(html).toContain("150% Quota");
  6141. expect(html).not.toContain("lucide-info");
  6142. expect(html).not.toContain("settings.modelProvider.codingPlan.billingDiscountInfo.title");
  6143. });
  6144. it("Coding Plan 活动说明标题与 Markdown 正文来自远端配置", () => {
  6145. const copy = resolveCodingPlanBillingDiscountCopy(
  6146. {
  6147. "zh-CN": {
  6148. infoTitle: "远端权益规则",
  6149. infoBody: "- 远端规则一\n- 远端规则二",
  6150. },
  6151. },
  6152. "zh-CN",
  6153. );
  6154. expect(copy.infoTitle).toBe("远端权益规则");
  6155. expect(copy.infoBody).toBe("- 远端规则一\n- 远端规则二");
  6156. });
  6157. it("Coding Plan 活动说明弹窗使用紧凑宽度", () => {
  6158. expect(CODING_PLAN_BILLING_DISCOUNT_DIALOG_CONTENT_CLASS).toContain("max-w-lg");
  6159. expect(CODING_PLAN_BILLING_DISCOUNT_DIALOG_CONTENT_CLASS).not.toContain("max-w-2xl");
  6160. });
  6161. it("Coding Plan 活动说明文案区域使用弹窗内 wrapper", () => {
  6162. expect(CODING_PLAN_BILLING_DISCOUNT_DIALOG_BODY_CLASS).toBe("p-3 !space-y-3");
  6163. });
  6164. it("按当前 locale 读取服务端下发的 150% 活动文案", () => {
  6165. expect(
  6166. resolveCodingPlanBillingDiscountCopy(
  6167. {
  6168. "zh-CN": {
  6169. cardTitle: "限时 150% 配额活动",
  6170. cardBody: "升级 Coding Plan,可在活动期内获得150% 配额",
  6171. badgeBody: "150% 配额",
  6172. infoTitle: "权益规则说明",
  6173. infoBody: "远端规则正文",
  6174. },
  6175. "en-US": {
  6176. cardTitle: "Limited-time 150% Quota Campaign",
  6177. cardBody: "Upgrade your Coding Plan to get 150% quota during the campaign period",
  6178. badgeBody: "150% Quota",
  6179. },
  6180. },
  6181. "zh-CN",
  6182. ),
  6183. ).toEqual({
  6184. cardTitle: "限时 150% 配额活动",
  6185. cardBody: "升级 Coding Plan,可在活动期内获得150% 配额",
  6186. badgeBody: "150% 配额",
  6187. infoTitle: "权益规则说明",
  6188. infoBody: "远端规则正文",
  6189. });
  6190. });
  6191. it("服务端 150% 活动文案为空时不返回硬编码兜底", () => {
  6192. expect(
  6193. resolveCodingPlanBillingDiscountCopy(
  6194. {
  6195. "en-US": {
  6196. cardTitle: "",
  6197. cardBody: " ",
  6198. infoTitle: "",
  6199. infoBody: " ",
  6200. },
  6201. },
  6202. "en-US",
  6203. ),
  6204. ).toEqual({
  6205. badgeBody: undefined,
  6206. cardTitle: undefined,
  6207. cardBody: undefined,
  6208. infoTitle: undefined,
  6209. infoBody: undefined,
  6210. });
  6211. expect(resolveCodingPlanBillingDiscountCopy({}, "zh-CN")).toEqual({});
  6212. });
  6213. it("活动配置未透传到 UI 时不渲染 150% 活动入口", () => {
  6214. const badgeHtml = renderToStaticMarkup(
  6215. createElement(CodingPlanBillingDiscountBadge, {
  6216. config: undefined,
  6217. }),
  6218. );
  6219. const bannerHtml = renderToStaticMarkup(
  6220. createElement(CodingPlanBillingDiscountBanner, {
  6221. config: undefined,
  6222. }),
  6223. );
  6224. expect(badgeHtml).toBe("");
  6225. expect(bannerHtml).toBe("");
  6226. });
  6227. it("个人和团队 status card 名称后展示 150% 配额徽标", () => {
  6228. primeCodingPlanBillingDiscountCacheForTest({
  6229. "en-US": {
  6230. badgeBody: "150% Quota",
  6231. },
  6232. });
  6233. const personalHtml = renderToStaticMarkup(
  6234. createElement(CodingPlanStatusPanel, {
  6235. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  6236. providerName: "Z.ai",
  6237. status: "purchased",
  6238. planLevel: "Pro",
  6239. quotaLimits: [
  6240. {
  6241. type: "TOKENS_LIMIT",
  6242. unit: 3,
  6243. number: 5,
  6244. usage: 100_000,
  6245. remaining: 900_000,
  6246. percentage: 10,
  6247. usageDetails: [],
  6248. },
  6249. ],
  6250. }),
  6251. );
  6252. const teamHtml = renderToStaticMarkup(
  6253. createElement(CodingPlanStatusPanel, {
  6254. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6255. providerName: "BigModel",
  6256. status: "purchased",
  6257. planLevel: "Team A",
  6258. quotaLimits: [
  6259. {
  6260. type: "TOKENS_LIMIT",
  6261. unit: 3,
  6262. number: 5,
  6263. usage: 100_000,
  6264. remaining: 900_000,
  6265. percentage: 10,
  6266. usageDetails: [],
  6267. },
  6268. ],
  6269. }),
  6270. );
  6271. expect(personalHtml).toContain("Pro");
  6272. expect(personalHtml).toContain("150% Quota");
  6273. expect(teamHtml).toContain("TEAM A");
  6274. expect(teamHtml).toContain("150% Quota");
  6275. });
  6276. it.each([
  6277. BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  6278. BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6279. ])("%s 获取失败提供明确的重新登录操作", (providerId) => {
  6280. const html = renderToStaticMarkup(
  6281. createElement(CodingPlanStatusPanel, {
  6282. providerId,
  6283. providerName: "Provider",
  6284. status: "unavailable",
  6285. loginActionVisible: true,
  6286. loginActionPlacement: "trailing",
  6287. onLogin: vi.fn(),
  6288. reloginOnFailure: true,
  6289. }),
  6290. );
  6291. expect(html).toContain("login.expired.action");
  6292. expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
  6293. });
  6294. it("Team Plan 未分配时在状态行展示管理员提示", () => {
  6295. const html = renderToStaticMarkup(
  6296. createElement(CodingPlanStatusPanel, {
  6297. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6298. providerName: "BigModel",
  6299. status: "unavailable",
  6300. planLevel: "Org A",
  6301. inactivePlanTitle: "Org A",
  6302. statusLabelId: "settings.modelProvider.codingPlan.status.teamUnavailable",
  6303. teamPlanAvailabilityReason: "not-allocated",
  6304. loginActionVisible: true,
  6305. onLogin: vi.fn(),
  6306. }),
  6307. );
  6308. expect(html).toContain("Org A");
  6309. expect(html).toContain("settings.modelProvider.codingPlan.status.teamUnavailable");
  6310. expect(html).toContain("text-warning");
  6311. expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
  6312. });
  6313. it("Team Plan 检查中不叠加旧错误图标和文案", () => {
  6314. const html = renderToStaticMarkup(
  6315. createElement(CodingPlanStatusPanel, {
  6316. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6317. providerName: "BigModel",
  6318. status: "unavailable",
  6319. viewState: resolveCodingPlanStatusPanelViewState({
  6320. status: "unavailable",
  6321. loginPending: true,
  6322. }),
  6323. statusLabelId: "settings.modelProvider.codingPlan.status.teamUnavailable",
  6324. statusMessage: "旧团队授权错误",
  6325. teamPlanAvailabilityReason: "credential-unavailable",
  6326. }),
  6327. );
  6328. expect(html).toContain("lucide-loader-circle");
  6329. expect(html).toContain("settings.modelProvider.codingPlan.status.checking");
  6330. expect(html).not.toContain("旧团队授权错误");
  6331. expect(html).not.toContain("settings.modelProvider.codingPlan.status.teamUnavailable");
  6332. expect(html).not.toContain("text-warning");
  6333. expect(html).not.toMatch(/animate-spin[^]*lucide-info/);
  6334. });
  6335. it("Team Plan API Key 预热返回服务端 message 时状态行优先显示该 message", () => {
  6336. const html = renderToStaticMarkup(
  6337. createElement(CodingPlanStatusPanel, {
  6338. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6339. providerName: "BigModel",
  6340. status: "unavailable",
  6341. planLevel: "GY的组织",
  6342. inactivePlanTitle: "GY的组织",
  6343. statusLabelId: "settings.modelProvider.codingPlan.status.teamUnavailable",
  6344. statusMessage: "您当前暂无有效的团队套餐授权记录,无法创建API Key",
  6345. teamPlanAvailabilityReason: "credential-unavailable",
  6346. loginActionVisible: true,
  6347. onLogin: vi.fn(),
  6348. }),
  6349. );
  6350. expect(html).toContain("GY的组织");
  6351. expect(html).toContain("您当前暂无有效的团队套餐授权记录,无法创建API Key");
  6352. expect(html).not.toContain("settings.modelProvider.codingPlan.status.teamUnavailable");
  6353. expect(html).toContain("text-warning");
  6354. });
  6355. it("Z.ai Start Plan 展开升级套餐时保留余额卡片", () => {
  6356. const html = renderToStaticMarkup(
  6357. createElement(CodingPlanStatusPanel, {
  6358. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
  6359. providerName: "Z.ai",
  6360. status: "purchased",
  6361. planLevel: "Start",
  6362. subscriptionExpireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
  6363. // 生产数据形态:purchased 快照必带 active 套餐详情,额度桶带 plan_id。
  6364. subscriptionDetails: [
  6365. {
  6366. productId: "zcode-v3-start-plan",
  6367. productName: "ZCode V3 Start Plan",
  6368. purchaseTime: null,
  6369. beginTime: null,
  6370. billingCycle: "daily",
  6371. renewTime: null,
  6372. expireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
  6373. },
  6374. ],
  6375. quotaLimits: [
  6376. {
  6377. type: "ent_zcode_v3_glm_52",
  6378. planId: "zcode-v3-start-plan",
  6379. number: 3_000_000,
  6380. usage: 500_000,
  6381. remaining: 2_500_000,
  6382. usageDetails: [{ modelCode: "glm-5.2", usage: 500_000 }],
  6383. },
  6384. ],
  6385. upgradePlansVisible: true,
  6386. }),
  6387. );
  6388. expect(html).toContain("settings.modelProvider.startPlan.balance.title");
  6389. });
  6390. it("Z.ai Coding Plan 展开升级套餐时保留剩余额度卡片", () => {
  6391. const html = renderToStaticMarkup(
  6392. createElement(CodingPlanStatusPanel, {
  6393. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  6394. providerName: "Z.ai",
  6395. status: "purchased",
  6396. planLevel: "Pro",
  6397. quotaLimits: [
  6398. {
  6399. type: "TOKENS_LIMIT",
  6400. unit: 3,
  6401. number: 5,
  6402. usage: 100_000,
  6403. remaining: 900_000,
  6404. percentage: 10,
  6405. usageDetails: [],
  6406. },
  6407. {
  6408. type: "TOKENS_LIMIT",
  6409. unit: 6,
  6410. usage: 200_000,
  6411. remaining: 800_000,
  6412. percentage: 20,
  6413. usageDetails: [],
  6414. },
  6415. {
  6416. type: "TIME_LIMIT",
  6417. unit: 5,
  6418. number: 1,
  6419. usage: 1_000,
  6420. remaining: 9_000,
  6421. percentage: 10,
  6422. usageDetails: [],
  6423. },
  6424. ],
  6425. upgradePlansVisible: true,
  6426. }),
  6427. );
  6428. expect(html).toContain("settings.usage.quotaTitle");
  6429. expect(html.indexOf("settings.usage.quotaTitle")).toBeLessThan(
  6430. html.indexOf("settings.usage.entitlementFiveHourUsage"),
  6431. );
  6432. expect(html).toContain("settings.usage.entitlementFiveHourUsage");
  6433. expect(html).toContain("settings.usage.entitlementWeeklyUsage");
  6434. expect(html).toContain("settings.usage.entitlementMonthlyMcpUsage");
  6435. });
  6436. it("BigModel Coding Plan 已购买时在状态行显示管理和解绑操作", () => {
  6437. const currentYear = new Date().getUTCFullYear();
  6438. const html = renderDetail({
  6439. key: "coding-plan:account:bigmodel-individual-coding-plan",
  6440. type: "codingPlan",
  6441. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6442. oauthProviderId: BIGMODEL_PROVIDER_ID,
  6443. label: "BigModel - Coding Plan",
  6444. providerName: "BigModel",
  6445. provider: createProvider({
  6446. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6447. }),
  6448. status: "purchased",
  6449. planLevel: "pro",
  6450. subscriptionRenewTime: `${currentYear}-07-10T00:00:00.000Z`,
  6451. purchaseUrl: "https://bigmodel.cn/",
  6452. statusActive: true,
  6453. });
  6454. const planIndex = html.indexOf(">PRO<");
  6455. const renewIndex = html.indexOf("settings.modelProvider.codingPlan.renewsAt");
  6456. const manageIndex = html.indexOf("settings.modelProvider.codingPlan.manage");
  6457. const unlinkIndex = html.indexOf("settings.modelProvider.codingPlan.disconnect");
  6458. expect(planIndex).toBeGreaterThan(-1);
  6459. expect(renewIndex).toBeGreaterThan(planIndex);
  6460. expect(manageIndex).toBeGreaterThan(renewIndex);
  6461. expect(unlinkIndex).toBeGreaterThan(manageIndex);
  6462. });
  6463. it("BigModel Coding Plan 未登录且无远端 preview 时隐藏 Start 套餐入口", () => {
  6464. const html = renderDetail({
  6465. key: "coding-plan:account:bigmodel-individual-coding-plan",
  6466. type: "codingPlan",
  6467. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6468. oauthProviderId: BIGMODEL_PROVIDER_ID,
  6469. label: "BigModel - Coding Plan",
  6470. providerName: "BigModel",
  6471. provider: null,
  6472. status: "disconnected",
  6473. purchaseUrl: "https://bigmodel.cn/",
  6474. statusActive: false,
  6475. });
  6476. expect(html).toContain("settings.modelProvider.planCard.codingPlan");
  6477. expect(html).toContain("settings.modelProvider.codingPlan.status.disconnected");
  6478. expect(html).toContain("settings.modelProvider.codingPlan.connect");
  6479. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.startPlanTitle");
  6480. expect(html).not.toContain(
  6481. "settings.modelProvider.codingPlan.purchaseBanner.startPlanDescription",
  6482. );
  6483. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.personalTitle");
  6484. expect(html).not.toContain(
  6485. "settings.modelProvider.codingPlan.purchaseBanner.personalDescription",
  6486. );
  6487. expect(html).not.toContain("CN¥49.00+");
  6488. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamTitle");
  6489. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamDescription");
  6490. expect(html).not.toContain("CN¥598.00+");
  6491. expect(html).not.toContain("color-mix(in_srgb,var(--color-success)_24%");
  6492. expect(html).not.toContain("color-mix(in_srgb,#4099ff_24%");
  6493. expect(html).not.toContain("color-mix(in_srgb,#0ea5e9_24%");
  6494. expect(html).not.toContain("circle_at_14%_12%");
  6495. expect(html).toContain("w-full");
  6496. expect(html).not.toContain("bg-background/80");
  6497. expect(html).not.toContain("sm:grid-cols-3");
  6498. expect(html).not.toContain("button-gradient");
  6499. expect(html).not.toContain("settings.modelProvider.startPlan.quotaSectionTitle");
  6500. expect(html).not.toContain("settings.modelProvider.codingPlan.productsLoading");
  6501. expect(html).not.toContain("settings.modelProvider.codingPlan.bigmodel.plan.lite.name");
  6502. expect(html).not.toContain("settings.modelProvider.models");
  6503. expect(html).not.toContain("settings.modelProvider.apiKey");
  6504. });
  6505. it("BigModel 未登录点击个人/团队套餐时先登录,已登录未订阅才打开购买", () => {
  6506. expect(resolvePurchaseChoiceSelectionIntent("disconnected")).toBe("login");
  6507. expect(resolvePurchaseChoiceSelectionIntent("notPurchased")).toBe("purchase");
  6508. expect(resolvePurchaseChoiceSelectionIntent("purchased")).toBe("purchase");
  6509. });
  6510. it("BigModel Coding Plan 账号未注册时在查询行显示注册链接", () => {
  6511. const html = renderDetail(
  6512. {
  6513. key: "coding-plan:account:bigmodel-individual-coding-plan",
  6514. type: "codingPlan",
  6515. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6516. oauthProviderId: BIGMODEL_PROVIDER_ID,
  6517. label: "BigModel - Coding Plan",
  6518. providerName: "本地化后的智谱账号",
  6519. provider: null,
  6520. status: "disconnected",
  6521. purchaseUrl: "https://bigmodel.cn/",
  6522. statusActive: false,
  6523. },
  6524. {
  6525. presetSubscriptionProviderId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6526. codingPlanAuthError: "BigModel 账号未注册,请先完成 BigModel 注册后再登录。",
  6527. },
  6528. );
  6529. expect(html).toContain("settings.modelProvider.codingPlan.bigmodel.unregisteredHint");
  6530. expect(html).toContain("settings.modelProvider.codingPlan.bigmodel.registerAction");
  6531. expect(html).not.toContain("settings.modelProvider.codingPlan.status.checking");
  6532. });
  6533. it("BigModel Coding Plan 已连接时显示解绑入口", () => {
  6534. const html = renderDetail({
  6535. key: "coding-plan:account:bigmodel-individual-coding-plan",
  6536. type: "codingPlan",
  6537. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6538. oauthProviderId: BIGMODEL_PROVIDER_ID,
  6539. label: "BigModel - Coding Plan",
  6540. providerName: "BigModel",
  6541. provider: createProvider({
  6542. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6543. apiKey: "",
  6544. models: [],
  6545. }),
  6546. status: "notPurchased",
  6547. purchaseUrl: "https://bigmodel.cn/",
  6548. statusActive: false,
  6549. });
  6550. expect(html).toContain("settings.modelProvider.codingPlan.status.notPurchased");
  6551. expect(html).toContain("settings.modelProvider.codingPlan.disconnect");
  6552. expect(html).toMatch(
  6553. /settings\.modelProvider\.codingPlan\.status\.notPurchased[\s\S]*·[\s\S]*settings\.modelProvider\.codingPlan\.disconnect/,
  6554. );
  6555. expect(html).not.toContain("settings.modelProvider.codingPlan.upgrade");
  6556. expect(html).toContain("settings.modelProvider.codingPlan.description.notPurchased");
  6557. expect(html).not.toContain("settings.modelProvider.codingPlan.productsLoading");
  6558. expect(html).not.toContain("settings.modelProvider.models");
  6559. expect(html).not.toContain("settings.modelProvider.apiKey");
  6560. });
  6561. it("BigModel 已登录但无 Start/Coding 权益时等待团队套餐档位加载完成", () => {
  6562. const html = renderDetail(
  6563. {
  6564. key: "coding-plan:account:bigmodel-individual-coding-plan",
  6565. type: "codingPlan",
  6566. presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6567. oauthProviderId: BIGMODEL_PROVIDER_ID,
  6568. label: "BigModel - Coding Plan",
  6569. providerName: "BigModel",
  6570. provider: createProvider({
  6571. id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6572. apiKey: "",
  6573. models: [],
  6574. }),
  6575. status: "notPurchased",
  6576. purchaseUrl: "https://bigmodel.cn/",
  6577. statusActive: false,
  6578. },
  6579. {
  6580. codingPlanPurchaseTokenAuthenticatedByProviderId: {
  6581. [BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan]: true,
  6582. },
  6583. },
  6584. );
  6585. expect(html).toContain("settings.modelProvider.codingPlan.status.notPurchased");
  6586. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.personalTitle");
  6587. expect(html).not.toContain(
  6588. "settings.modelProvider.codingPlan.purchaseBanner.personalDescription",
  6589. );
  6590. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamTitle");
  6591. expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamDescription");
  6592. expect(html).not.toContain("color-mix(in_srgb,#4099ff_24%");
  6593. expect(html).not.toContain("color-mix(in_srgb,var(--color-warning)_24%");
  6594. expect(html).not.toContain("circle_at_14%_12%");
  6595. expect(html).toContain("w-full");
  6596. expect(html).not.toContain("bg-background/80");
  6597. expect(html).not.toContain("sm:grid-cols-2");
  6598. expect(html).not.toContain("button-gradient");
  6599. expect(html).not.toContain("settings.modelProvider.startPlan.quotaSectionTitle");
  6600. expect(html).not.toContain("settings.modelProvider.models");
  6601. expect(html).not.toContain("settings.modelProvider.apiKey");
  6602. });
  6603. it.each([false, true])("个人未开通时团队 subscribed=%s 仍展示团队 banner", (subscribed) => {
  6604. const spy = vi
  6605. .spyOn(enterpriseProductsHook, "useEnterpriseCodingPlanProducts")
  6606. .mockReturnValue({
  6607. loading: false,
  6608. error: null,
  6609. refresh: vi.fn(),
  6610. snapshot: {
  6611. authenticated: true,
  6612. staticProductIds: ["team-pro"],
  6613. raw: { productList: [] },
  6614. productList: [
  6615. {
  6616. productId: "team-pro",
  6617. productName: "Pro",
  6618. productEquityList: [],
  6619. priceCurrency: "CNY",
  6620. payAmount: 598,
  6621. tier: "PRO",
  6622. subscribeMode: "CONTINUOUS",
  6623. subscribePeriod: "YEARLY",
  6624. purchaseMethodName: "Auto renew",
  6625. subscribed,
  6626. enterpriseProduct: {
  6627. productId: "team-pro",
  6628. tier: "PRO",
  6629. subscribeMode: "CONTINUOUS",
  6630. subscribePeriod: "YEARLY",
  6631. payAmount: 598,
  6632. },
  6633. },
  6634. ],
  6635. },
  6636. });
  6637. try {
  6638. const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan;
  6639. const html = renderDetail(
  6640. {
  6641. key: `coding-plan:${providerId}`,
  6642. type: "codingPlan",
  6643. presetId: providerId,
  6644. oauthProviderId: BIGMODEL_PROVIDER_ID,
  6645. label: "BigModel",
  6646. providerName: "BigModel",
  6647. provider: createProvider({ id: providerId }),
  6648. status: "notPurchased",
  6649. statusActive: false,
  6650. },
  6651. { codingPlanPurchaseTokenAuthenticatedByProviderId: { [providerId]: true } },
  6652. );
  6653. expect(html).toContain("settings.modelProvider.codingPlan.purchaseBanner.teamDescription");
  6654. expect(html).toContain("598.00");
  6655. expect(html).not.toContain("settings.modelProvider.models");
  6656. const startId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan;
  6657. const startItem: ModelProviderNavItem = {
  6658. key: "start-expired",
  6659. type: "codingPlan",
  6660. presetId: startId,
  6661. oauthProviderId: BIGMODEL_PROVIDER_ID,
  6662. label: "Start Plan",
  6663. providerName: "BigModel",
  6664. provider: createProvider({ id: startId }),
  6665. status: "notPurchased",
  6666. statusActive: false,
  6667. statusLabelId: "settings.modelProvider.startPlan.status.expired",
  6668. };
  6669. for (const type of ["codingPlan", "teamPlan"] as const) {
  6670. for (const available of [false, true]) {
  6671. for (const status of ["purchased", "unavailable", "checking"] as const) {
  6672. const paidItem: ModelProviderNavItem = {
  6673. key: "paid",
  6674. type,
  6675. presetId: providerId,
  6676. oauthProviderId: BIGMODEL_PROVIDER_ID,
  6677. label: "Paid",
  6678. providerName: "BigModel",
  6679. provider: null,
  6680. status,
  6681. statusActive: false,
  6682. ...(type === "teamPlan"
  6683. ? {
  6684. teamPlanName: "Team",
  6685. organizationId: "org",
  6686. projectId: "project",
  6687. currentProductId: "product",
  6688. }
  6689. : {}),
  6690. };
  6691. const paidView = createProviderSettingsView(createProvider({ id: providerId }));
  6692. paidView.providers[0]!.accountState = {
  6693. availability: available ? "available" : "unavailable",
  6694. entitled: available,
  6695. current: true,
  6696. };
  6697. const startHtml = renderDetail(startItem, {
  6698. navigationItems: [startItem, paidItem],
  6699. providerSettingsView: paidView,
  6700. codingPlanPurchaseTokenAuthenticatedByProviderId: { [startId]: true },
  6701. });
  6702. expect(startHtml).toContain("settings.modelProvider.startPlan.status.expired");
  6703. expect(
  6704. startHtml.includes(
  6705. "settings.modelProvider.codingPlan.purchaseBanner.teamDescription",
  6706. ),
  6707. ).toBe(!available);
  6708. const activeStartHtml = renderDetail(
  6709. { ...startItem, status: "purchased", statusLabelId: undefined },
  6710. {
  6711. navigationItems: [startItem, paidItem],
  6712. providerSettingsView: paidView,
  6713. },
  6714. );
  6715. expect(activeStartHtml.includes("settings.modelProvider.codingPlan.upgrade")).toBe(
  6716. !available,
  6717. );
  6718. }
  6719. }
  6720. }
  6721. } finally {
  6722. spy.mockRestore();
  6723. }
  6724. });
  6725. it("团队标准版和高级版使用不同 banner 背景", () => {
  6726. const standardClassName = resolveEnterpriseTeamPlanBannerClass("pro");
  6727. const advancedClassName = resolveEnterpriseTeamPlanBannerClass("max");
  6728. expect(standardClassName).toContain("#0ea5e9");
  6729. expect(advancedClassName).toContain("#14b8a6");
  6730. expect(advancedClassName).not.toBe(standardClassName);
  6731. });
  6732. it("团队标准版和高级版图标颜色跟随 banner 背景", () => {
  6733. expect(resolveEnterpriseTeamPlanBannerIconClass("pro")).toBe("text-[#0ea5e9]");
  6734. expect(resolveEnterpriseTeamPlanBannerIconClass("max")).toBe("text-[#14b8a6]");
  6735. });
  6736. it("团队标准版和高级版使用各自的 banner 描述", () => {
  6737. expect(resolveEnterpriseTeamPlanBannerDescriptionId("pro")).toBe(
  6738. "settings.modelProvider.codingPlan.purchaseBanner.teamStandardDescription",
  6739. );
  6740. expect(resolveEnterpriseTeamPlanBannerDescriptionId("max")).toBe(
  6741. "settings.modelProvider.codingPlan.purchaseBanner.teamAdvancedDescription",
  6742. );
  6743. });
  6744. it("模型供应商手动刷新会同步 Team Plan 产品快照", async () => {
  6745. const calls: string[] = [];
  6746. await refreshModelProviderSection({
  6747. refresh: async () => {
  6748. calls.push("providers");
  6749. },
  6750. refreshTeamPlanProducts: async () => {
  6751. calls.push("team-products");
  6752. },
  6753. });
  6754. expect(calls.sort()).toEqual(["providers", "team-products"]);
  6755. });
  6756. it("连接方式切换只刷新 provider,不强制刷新套餐权益", async () => {
  6757. const calls: string[] = [];
  6758. await refreshProviderPanelAfterAuthChange({
  6759. refreshModelProviders: async () => {
  6760. calls.push("providers");
  6761. },
  6762. refreshCodingPlanEntitlements: async () => {
  6763. calls.push("entitlements");
  6764. },
  6765. refreshTeamPlanProducts: async () => {
  6766. calls.push("team-products");
  6767. },
  6768. refreshCodingPlanProducts: () => {
  6769. calls.push("products");
  6770. },
  6771. refreshPurchaseTokenState: async () => {
  6772. calls.push("token");
  6773. },
  6774. refreshPlanSnapshots: false,
  6775. });
  6776. expect(calls).toEqual(["token", "providers", "products"]);
  6777. });
  6778. it("全局购买弹窗完成 Team Plan 购买后刷新团队产品快照", async () => {
  6779. const calls: string[] = [];
  6780. await refreshCodingPlanUpgradeCompletion({
  6781. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6782. productsProviderId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6783. refreshCodingPlanEntitlements: async () => {
  6784. calls.push("entitlements");
  6785. },
  6786. refreshProviderState: async () => {
  6787. calls.push("registry");
  6788. },
  6789. refreshTeamPlanProducts: async () => {
  6790. calls.push("team-products");
  6791. },
  6792. });
  6793. expect(calls).toContain("team-products");
  6794. // 改造原因:购买流程迁到 webview 后,App 不再维护 purchase token 状态
  6795. // (oauth:active_provider 那套登录态由官网页内部处理),刷新列表里不再有 "token"。
  6796. expect(calls.sort()).toEqual(["entitlements", "registry", "team-products"]);
  6797. });
  6798. it("新 Provider Runtime 购买完成后只刷新 Account Source", async () => {
  6799. const calls: string[] = [];
  6800. await refreshCodingPlanUpgradeCompletion({
  6801. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6802. productsProviderId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  6803. refreshCodingPlanEntitlements: async () => {
  6804. calls.push("entitlements");
  6805. },
  6806. refreshProviderState: async () => {
  6807. calls.push("registry");
  6808. },
  6809. });
  6810. expect(calls.sort()).toEqual(["entitlements", "registry"]);
  6811. });
  6812. it("webview 请求购买完成后先关闭升级弹窗再刷新当前 provider", async () => {
  6813. const calls: string[] = [];
  6814. await closeAndRefreshCodingPlanUpgradeFromWebview({
  6815. onClose: () => {
  6816. calls.push("close");
  6817. },
  6818. refresh: async () => {
  6819. calls.push("refresh:start");
  6820. await Promise.resolve();
  6821. calls.push("refresh:end");
  6822. },
  6823. });
  6824. expect(calls).toEqual(["close", "refresh:start", "refresh:end"]);
  6825. });
  6826. });
  6827. describe("团队初始化的商品元数据变化", () => {
  6828. it.each(["bigmodel", "zai"] as const)(
  6829. "%s 同项目商品更新仍选中团队,且不报连接不可用",
  6830. (family) => {
  6831. const spec = getModelProviderFamilySpec(family);
  6832. let captured: ReturnType<typeof useModelProviderNavigation> | undefined;
  6833. function Harness() {
  6834. captured = useModelProviderNavigation({
  6835. presetProviders: [
  6836. { id: spec.startPlanProviderId, displayName: spec.label, provider: null },
  6837. ],
  6838. modelProviders: [],
  6839. selectedNodeKey: `preset:${spec.startPlanProviderId}`,
  6840. providerFamilyDomain: family,
  6841. connectionSelections: {
  6842. [family]: {
  6843. kind: "team-coding-plan",
  6844. productId: "saved-product",
  6845. organizationId: "org-a",
  6846. projectId: "project-a",
  6847. },
  6848. },
  6849. showPurchasedTeamPlanFallback: true,
  6850. codingPlanEntitlements: {
  6851. [spec.teamCodingPlanProviderId]: {
  6852. loading: false,
  6853. error: null,
  6854. snapshot: {
  6855. generatedAt: 1,
  6856. authenticated: true,
  6857. provider: { id: spec.teamCodingPlanProviderId },
  6858. context: {
  6859. scope: "team",
  6860. organizationId: "org-a",
  6861. projectId: "project-a",
  6862. productId: "current-product",
  6863. displayName: "Current Team",
  6864. },
  6865. subscription: null,
  6866. quota: null,
  6867. remaining: null,
  6868. },
  6869. },
  6870. },
  6871. setSelectedNodeKey: vi.fn(),
  6872. intl: { formatMessage: ({ id }: { id: string }) => id } as never,
  6873. });
  6874. return createElement("div");
  6875. }
  6876. renderToStaticMarkup(createElement(Harness));
  6877. expect(captured?.selectedNavItem).toMatchObject({
  6878. type: "teamPlan",
  6879. currentProductId: "current-product",
  6880. organizationId: "org-a",
  6881. projectId: "project-a",
  6882. });
  6883. expect(captured?.navigationUnavailable).toBe(false);
  6884. const team = captured!.selectedNavItem!;
  6885. for (const selection of [
  6886. { organizationId: "other-org", projectId: "project-a" },
  6887. { organizationId: "org-a", projectId: "other-project" },
  6888. ]) {
  6889. expect(
  6890. connectionSelectionMatchesNavigationItem(
  6891. family,
  6892. {
  6893. kind: "team-coding-plan",
  6894. productId: "current-product",
  6895. ...selection,
  6896. },
  6897. team,
  6898. ),
  6899. ).toBe(false);
  6900. }
  6901. expect(
  6902. connectionSelectionMatchesNavigationItem(
  6903. family === "bigmodel" ? "zai" : "bigmodel",
  6904. {
  6905. kind: "team-coding-plan",
  6906. productId: "current-product",
  6907. organizationId: "org-a",
  6908. projectId: "project-a",
  6909. },
  6910. team,
  6911. ),
  6912. ).toBe(false);
  6913. },
  6914. );
  6915. });