| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345 |
- import * as enterpriseProductsHook from "@/settings/model-provider-section/useEnterpriseCodingPlanProducts.js";
- import { createElement, type ReactElement } from "react";
- import { type ProviderSettingsFormProvider } from "@/lib/providerSettingsFormTypes.js";
- import { renderToStaticMarkup } from "react-dom/server";
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
- import {
- BIGMODEL_PROVIDER_ID,
- BUILTIN_MODEL_PROVIDER_IDS,
- getModelProviderFamilySpec,
- ZAI_PROVIDER_ID,
- TID_MODEL_PROVIDER_ADD_MODEL_BUTTON,
- TID_MODEL_PROVIDER_MODEL_DELETE_BUTTON,
- type UsageEntitlementSnapshot,
- } from "@zcode/shared";
- import {
- resolveCodingPlanProviderSyncAttemptKey,
- shouldRetryUnchangedCodingPlanProviderSync,
- resolveModelProviderSideSelectionKey,
- } from "@/settings/ModelProviderSection.js";
- import {
- beginCodingPlanUpgradeLogin,
- isCodingPlanPurchaseAuthPending,
- closeAndRefreshCodingPlanUpgradeFromWebview,
- refreshCodingPlanUpgradeCompletion,
- resolvePendingCodingPlanUpgradeAfterLogin,
- } from "@/settings/CodingPlanUpgradeDialog.js";
- import {
- refreshModelProviderSection,
- refreshProviderPanelAfterAuthChange,
- } from "@/settings/model-provider-section/modelProviderActions.js";
- import { resolveCodingPlanStatusPanelViewState } from "@/settings/model-provider-section/codingPlanStatusPanelViewState.js";
- import {
- ModelProviderSectionDetail,
- resolveEnterprisePurchaseChoiceBannerPrice,
- resolvePurchaseChoiceBannerProductsProviderId,
- resolvePurchaseChoiceBannerPrice,
- resolveEnterpriseTeamPlanBannerClass,
- resolveEnterpriseTeamPlanBannerDescriptionId,
- resolveEnterpriseTeamPlanBannerIconClass,
- resolvePurchaseChoiceSelectionIntent,
- resolveTeamScopedPlanNavItem,
- resolveTeamPlanInspectionAccess,
- } from "@/settings/model-provider-section/Detail.js";
- import { resolveCodingPlanEntitlementState } from "@/settings/model-provider-section/providerFamilyConnectionVisibility.js";
- import { groupEnterpriseCodingPlanProductsByTier } from "@/settings/model-provider-section/codingPlanEnterpriseTiers.js";
- import {
- ModelProviderSectionNavigation,
- resolveModelProviderSideNavLabel,
- } from "@/settings/model-provider-section/Navigation.js";
- import {
- resolveProviderConnectionApiFormatDisplayLabel,
- resolveProviderConnectionApiFormatOptions,
- } from "@/settings/model-provider-section/ProviderCardSections.js";
- import {
- buildProviderFamilyConnectionOptions,
- ProviderFamilyPlanModeSwitch,
- } from "@/settings/model-provider-section/ProviderFamilyModeHeader.js";
- import { resolveCodingPlanUpgradeProductsProviderId } from "@/settings/model-provider-section/codingPlanPricingCards.js";
- import { CodingPlanUpgradeAction } from "@/settings/model-provider-section/CodingPlanStatusActions.js";
- import {
- formatStartPlanEffectiveDate,
- formatStartPlanExpireDate,
- resolvePendingStartPlanEffectiveTime,
- } from "@/settings/model-provider-section/CodingPlanStatusMeta.js";
- import { ConversationQuotaBanner } from "@/v4/ConversationQuotaBanner.js";
- import enUS from "@/i18n/locales/en-US.js";
- import { StartPlanCard } from "@/settings/model-provider-section/StartPlanCard.js";
- import {
- CodingPlanStatusPanel,
- hasStartPlanEntitlementQuota,
- resolveCodingPlanStatusCardTitle,
- } from "@/settings/model-provider-section/StatusCards.js";
- import {
- resolveFallbackModelProviderNodeKey,
- resolveSelectedFamilyModeNodeKey,
- connectionSelectionMatchesNavigationItem,
- useModelProviderNavigation,
- } from "@/settings/model-provider-section/useModelProviderNavigation.js";
- import {
- clearStartPlanPreviewCacheForTest,
- primeStartPlanPreviewCacheForTest,
- } from "@/settings/model-provider-section/useStartPlanPreview.js";
- import { type ModelProviderNavGroup } from "@/settings/model-provider-section/constants.js";
- import type { ModelProviderNavItem } from "@/settings/model-provider-section/constants.js";
- import type { ProviderSettingsView } from "@zcode/services";
- it("Start 独立后移除套餐数量快捷入口与切换按钮", () => {
- const item = (
- presetId:
- | typeof BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan
- | typeof BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- ): ModelProviderNavItem => ({
- key: `coding-plan:${presetId}`,
- type: "codingPlan",
- presetId,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: presetId,
- providerName: "Z.AI",
- provider: null,
- status: "purchased",
- statusActive: true,
- });
- const start = item(BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan);
- const coding = item(BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan);
- const render = (selectedNavItem: ModelProviderNavItem, count: number, failed = false) =>
- renderWithTooltipProvider(
- createElement(ProviderFamilyPlanModeSwitch, {
- selectedNavItem,
- navigationItems: [start, coding],
- startPlanSubscriptionCount: count,
- connectionSettingsFailed: failed,
- onSelectNavItem: vi.fn(),
- }),
- );
- expect(render(coding, 2)).not.toContain('data-testid="model-provider-start-plan-count-shortcut"');
- // 数量不再驱动切换入口,也不保留旧快捷入口的文案与标签。
- expect(render(coding, 2)).not.toContain("Start Plan × 2");
- expect(render(coding, 2)).not.toContain('aria-label="Switch to Start Plan"');
- expect(render(coding, 2)).not.toContain("lucide-tickets");
- expect(render(coding, 2)).not.toContain('data-testid="model-provider-start-plan-switch-prefix"');
- expect(render(start, 2)).not.toContain('data-testid="model-provider-start-plan-count-shortcut"');
- expect(render(coding, 0)).not.toContain('data-testid="model-provider-start-plan-count-shortcut"');
- expect(render(coding, 2, true)).not.toContain(
- 'data-testid="model-provider-start-plan-count-shortcut"',
- );
- });
- it("付费下拉按完整保存选择显示团队,不读取复制的个人 current", () => {
- const provider = createProvider({ id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan });
- provider.accountState = { availability: "available", entitled: true, current: false };
- const coding = {
- key: "coding",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "个人",
- providerName: "BigModel",
- provider,
- status: "purchased",
- statusActive: false,
- } as ModelProviderNavItem;
- const team = {
- ...coding,
- key: "team",
- type: "teamPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
- teamPlanName: "测试团队",
- organizationId: "org",
- projectId: "project",
- currentProductId: "product",
- } as ModelProviderNavItem;
- const selection = {
- kind: "team-coding-plan" as const,
- organizationId: "org",
- projectId: "project",
- productId: "product",
- };
- const render = (organizationId: string, navigationItems = [coding, team]) =>
- renderWithTooltipProvider(
- createElement(ProviderFamilyPlanModeSwitch, {
- selectedNavItem: team,
- navigationItems,
- connectionSelections: { bigmodel: { ...selection, organizationId } },
- onSelectNavItem: vi.fn(),
- }),
- );
- expect(render("org")).not.toContain('data-placeholder=""');
- expect(render("wrong-org")).toContain("settings.modelProvider.codingPlan.purchase.selectPlan");
- expect(render("wrong-org")).toContain("data-placeholder");
- expect(render("org", [team])).not.toContain(
- 'data-testid="model-provider-connection-mode-trigger"',
- );
- });
- it("旧 Start 连接下,唯一未选中的个人套餐仍提供显式选择入口", () => {
- const provider = createProvider({ id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan });
- provider.accountState = { availability: "available", entitled: true, current: false };
- const coding: ModelProviderNavItem = {
- key: `coding-plan:${provider.providerId}`,
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "个人套餐",
- providerName: "BigModel",
- provider,
- status: "purchased",
- statusActive: false,
- };
- const html = renderWithTooltipProvider(
- createElement(ProviderFamilyPlanModeSwitch, {
- selectedNavItem: coding,
- navigationItems: [coding],
- onSelectNavItem: vi.fn(),
- }),
- );
- expect(html).toContain('data-testid="model-provider-connection-mode-trigger"');
- expect(html).toContain("data-placeholder");
- });
- import {
- CODING_PLAN_BILLING_DISCOUNT_DIALOG_BODY_CLASS,
- CODING_PLAN_BILLING_DISCOUNT_DIALOG_CONTENT_CLASS,
- clearCodingPlanBillingDiscountCacheForTest,
- CodingPlanBillingDiscountBadge,
- CodingPlanBillingDiscountBadgePill,
- CodingPlanBillingDiscountBanner,
- primeCodingPlanBillingDiscountCacheForTest,
- resolveCodingPlanBillingDiscountCopy,
- } from "@/CodingPlanBillingDiscount.js";
- import zhCN from "@/i18n/locales/zh-CN.js";
- import { TooltipProvider } from "@/components/ui/tooltip.js";
- const intlMockState = vi.hoisted(() => ({ locale: "en-US" }));
- function renderWithTooltipProvider(element: ReactElement) {
- return renderToStaticMarkup(createElement(TooltipProvider, null, element));
- }
- vi.mock("@/i18n/IntlProvider.js", () => ({
- useZCodeIntl: () => ({
- locale: intlMockState.locale,
- intl: {
- formatMessage: (descriptor: { id: string }, values?: Record<string, string>) => {
- const isZh = intlMockState.locale.toLowerCase().startsWith("zh");
- let message =
- (isZh
- ? {
- "settings.modelProvider.startPlan.meta.today": "Today",
- "settings.modelProvider.startPlan.meta.tomorrow": "Tomorrow",
- "settings.modelProvider.startPlan.balance.used": "已用 {value}",
- "settings.modelProvider.startPlan.preview.unit.tokens": "tokens",
- "settings.modelProvider.startPlan.preview.period.daily": "{unit}/日",
- "settings.modelProvider.startPlan.preview.entitlementSummary.daily":
- "每日额度 · {details}",
- "settings.modelProvider.startPlan.preview.entitlementSummary.generic":
- "额度 · {details}",
- "settings.modelProvider.startPlan.preview.entitlementGroup.single":
- "{model} {quota}",
- "settings.modelProvider.startPlan.preview.entitlementGroup.each":
- "{models} 各{quota}",
- "settings.modelProvider.codingPlan.purchase.fromPrice": "{price} 起",
- "settings.modelProvider.codingPlan.purchase.fromPriceSuffix": "起",
- "settings.modelProvider.codingPlan.purchaseBanner.startPlanTitle": "体验套餐",
- "settings.modelProvider.connectionMode.startPlanCount": "体验套餐 × {count}",
- "settings.modelProvider.connectionMode.switchToStartPlan": "切换至体验套餐",
- "settings.modelProvider.codingPlan.enterprise.tier.lite": "基础版",
- "settings.modelProvider.codingPlan.enterprise.tier.pro": "标准版",
- "settings.modelProvider.codingPlan.enterprise.tier.max": "高级版",
- }
- : {
- "settings.modelProvider.startPlan.meta.today": "Today",
- "settings.modelProvider.startPlan.meta.tomorrow": "Tomorrow",
- "settings.modelProvider.startPlan.balance.used": "Used {value}",
- "settings.modelProvider.startPlan.preview.unit.tokens": "tokens",
- "settings.modelProvider.startPlan.preview.period.daily": "{unit} per day",
- "settings.modelProvider.startPlan.preview.entitlementSummary.daily":
- "Daily quota · {details}",
- "settings.modelProvider.startPlan.preview.entitlementSummary.generic":
- "Quota · {details}",
- "settings.modelProvider.startPlan.preview.entitlementGroup.single":
- "{model} {quota}",
- "settings.modelProvider.startPlan.preview.entitlementGroup.each":
- "{models} {quota} each",
- "settings.modelProvider.codingPlan.purchase.fromPrice": "{price}+",
- "settings.modelProvider.codingPlan.purchase.fromPriceSuffix": "",
- "settings.modelProvider.codingPlan.purchaseBanner.startPlanTitle": "Start Plan",
- "settings.modelProvider.connectionMode.startPlanCount": "Start Plan × {count}",
- "settings.modelProvider.connectionMode.switchToStartPlan": "Switch to Start Plan",
- "settings.modelProvider.codingPlan.enterprise.tier.lite": "Lite",
- "settings.modelProvider.codingPlan.enterprise.tier.pro": "Pro",
- "settings.modelProvider.codingPlan.enterprise.tier.max": "Max",
- })[descriptor.id] ?? descriptor.id;
- for (const [key, value] of Object.entries(values ?? {})) {
- message = message.replace(`{${key}}`, value);
- }
- if (values?.date && !message.includes(values.date)) {
- message = `${message} ${values.date}`;
- }
- return message;
- },
- },
- }),
- }));
- vi.mock("@/hooks/usePlatform.js", () => ({
- useOptionalPlatform: () => ({
- openExternal: vi.fn(),
- }),
- usePlatform: () => ({
- openExternal: vi.fn(),
- }),
- }));
- vi.mock("@/hooks/useServices.js", () => ({
- useServices: () => ({}),
- useOptionalServices: () => null,
- }));
- vi.mock("@/settings/CodingPlanUpgradeDialogProvider.js", () => ({
- useOptionalCodingPlanUpgradeDialog: () => null,
- useCodingPlanUpgradeDialog: () => ({
- openCodingPlanUpgrade: vi.fn(),
- }),
- }));
- beforeEach(() => {
- clearStartPlanPreviewCacheForTest();
- clearCodingPlanBillingDiscountCacheForTest();
- intlMockState.locale = "en-US";
- });
- afterEach(() => {
- vi.useRealTimers();
- });
- type LegacyProviderOverrides = Partial<ProviderSettingsFormProvider> & {
- id?: string;
- name?: string;
- apiKey?: string;
- apiKeyUrl?: string;
- apiFormat?: "anthropic-messages" | "openai-chat-completions" | "openai-responses";
- endpoints?: { baseURL?: string; paths?: Record<string, string> };
- models?: unknown[];
- systemDisabledReason?: string;
- updatedAt?: number;
- };
- function createModelProviderModelConfig(input: {
- id: string;
- builtin?: boolean;
- contextWindow?: number;
- maxOutputTokens?: number;
- supportsTools?: boolean;
- supportsJsonSchemaOutput?: boolean;
- kinds?: string[];
- defaultKind?: string;
- }): ProviderSettingsFormProvider["models"][number] {
- const maxOutputTokens = input.maxOutputTokens;
- const config = {
- properties: {
- requiresMfjsToolSchema: false,
- contextWindow: input.contextWindow ?? 200_000,
- inputFormat: {
- supportsText: true,
- supportsImage: false,
- supportsVideo: false,
- supportsAudio: false,
- supportsPdf: false,
- },
- outputFormat: { supportsText: true },
- supportsToolCall: input.supportsTools ?? true,
- supportsJsonSchemaOutput: input.supportsJsonSchemaOutput ?? true,
- supportsNativeWebSearch: false,
- supportsMidConversationSystem: false,
- },
- optionSpecs:
- maxOutputTokens === undefined
- ? {}
- : {
- maxOutputTokens: {
- max: maxOutputTokens,
- },
- },
- };
- return {
- kind: "candidate",
- modelId: input.id,
- builtin: input.builtin ?? false,
- personalConfig: structuredClone(config),
- hasPersonalConfig: true,
- executable: true,
- selectable: true,
- config,
- };
- }
- function createProvider(overrides: LegacyProviderOverrides = {}): ProviderSettingsFormProvider {
- const providerId =
- overrides.providerId ?? overrides.id ?? BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan;
- const accountAccess = (() => {
- const family = providerId.includes("bigmodel") ? "bigmodel" : "zai";
- if (providerId.includes("start-plan")) {
- return {
- type: "zhipu-account" as const,
- family,
- mode: "start-plan" as const,
- entitled: true,
- };
- }
- if (providerId.includes("team-coding-plan")) {
- return {
- type: "zhipu-account" as const,
- family,
- mode: "team-coding-plan" as const,
- entitled: true,
- };
- }
- if (providerId.includes("individual-coding-plan")) {
- return {
- type: "zhipu-account" as const,
- family,
- mode: "individual-coding-plan" as const,
- entitled: true,
- };
- }
- return null;
- })();
- const legacyModels = overrides.models ?? ["glm-5"];
- const hasPersonalConfig =
- overrides.hasPersonalConfig ?? overrides.config?.group === "standard-personal";
- const models = legacyModels.map((model) => {
- if (typeof model === "object" && model !== null && "modelId" in model && "config" in model) {
- return model as ProviderSettingsFormProvider["models"][number];
- }
- if (typeof model === "string") {
- // Settings View 总会提供 Personal 空覆盖;不完整模型也应遵循完整 DTO 外壳。
- return {
- kind: "candidate" as const,
- modelId: model,
- builtin: !hasPersonalConfig,
- config: {},
- personalConfig: {},
- hasPersonalConfig: false,
- executable: false,
- selectable: false,
- };
- }
- throw new Error("测试 Provider models 只接受当前 candidate 或 modelId 字符串");
- });
- return {
- providerId,
- executable: overrides.selectable ?? overrides.enabled !== false,
- enabled: overrides.enabled ?? true,
- hasPersonalConfig,
- personalConfig: hasPersonalConfig
- ? {
- group: "standard-personal",
- personalModelIds: models.map((model) => model.modelId),
- enabled: overrides.enabled ?? true,
- }
- : {},
- providerName: overrides.name ?? overrides.providerName ?? "Z.ai",
- config: {
- group:
- overrides.config?.group ??
- (providerId.includes("bigmodel") ? "bigmodel-family" : "zai-family"),
- access: accountAccess ?? {
- type: "api-key",
- apiKey: overrides.apiKey ?? "sk-demo",
- ...(overrides.apiKeyUrl ? { apiKeyManagementUrl: overrides.apiKeyUrl } : {}),
- },
- api: {
- type: overrides.apiFormat ?? overrides.config?.api?.type ?? "openai-chat-completions",
- baseUrl:
- overrides.endpoints?.baseURL ??
- overrides.config?.api?.baseUrl ??
- "https://example.com/openai",
- },
- ...(hasPersonalConfig
- ? { personalModelIds: models.map((model) => model.modelId) }
- : { builtinModelIds: models.map((model) => model.modelId) }),
- enabled: overrides.enabled ?? true,
- ...overrides.config,
- },
- models,
- };
- }
- function createProviderSettingsView(provider: ProviderSettingsFormProvider): ProviderSettingsView {
- return {
- revision: 17,
- addableProviders: [],
- providerOrder: [provider.providerId],
- providers: [
- {
- providerId: provider.providerId,
- providerName: provider.providerName,
- enabled: provider.enabled,
- executable: provider.executable,
- effectiveBuiltinConfig: structuredClone(provider.config),
- personalConfig: structuredClone(provider.personalConfig),
- effectiveConfig: structuredClone(provider.config),
- issues: provider.issues ?? [],
- models: provider.models.map((model) => ({
- kind: "candidate" as const,
- modelId: model.modelId,
- builtin: model.builtin ?? true,
- effectiveBuiltinConfig: structuredClone(model.inheritedConfig ?? model.config),
- ...(model.hasPersonalConfig
- ? { personalExactConfig: structuredClone(model.personalConfig) }
- : {}),
- effectiveConfig: structuredClone(model.config),
- enabled: model.config.enabled !== false,
- executable: model.executable ?? true,
- selectable: model.selectable ?? true,
- issues: model.issues ?? [],
- })),
- },
- ],
- };
- }
- function renderDetail(
- selectedNavItem: Parameters<typeof ModelProviderSectionDetail>[0]["selectedNavItem"],
- overrides: Partial<Parameters<typeof ModelProviderSectionDetail>[0]> = {},
- ) {
- return renderToStaticMarkup(
- createElement(ModelProviderSectionDetail, {
- selectedNavItem,
- activeWorkspacePath: null,
- presetLoading: false,
- officialLoginProviderId: null,
- presetSubscriptionProviderId: null,
- codingPlanStatusSyncProviderId: null,
- codingPlanDisconnectProviderId: null,
- onSave: vi.fn(),
- onDelete: vi.fn(async () => {}),
- onTestModel: vi.fn(async () => ({ results: [] })),
- onOfficialLogin: vi.fn(async () => {}),
- onCodingPlanLogin: vi.fn(async () => {}),
- onCodingPlanDisconnect: vi.fn(),
- onOpenPresetApiKey: vi.fn(),
- onOpenApiKeyUrl: vi.fn(),
- onOpenBigModelRegistration: vi.fn(),
- onCodingPlanPurchaseComplete: vi.fn(),
- codingPlanPurchaseTokenAuthenticatedByProviderId: {},
- ...overrides,
- }),
- );
- }
- function expectConnectionApiFormatVisible(html: string): void {
- expect(html).toMatch(/<label[^>]*>settings\.modelProvider\.apiFormat<\/label>/);
- }
- function expectConnectionApiFormatHidden(html: string): void {
- expect(html).not.toMatch(/<label[^>]*>settings\.modelProvider\.apiFormat<\/label>/);
- }
- function createEntitlementSnapshot(
- overrides: Partial<UsageEntitlementSnapshot> = {},
- ): UsageEntitlementSnapshot {
- return {
- generatedAt: 1,
- authenticated: true,
- provider: {
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- name: "BigModel - Coding Plan",
- },
- remaining: {
- count: 100,
- isShow: true,
- percentage: 0.2,
- nextResetTime: 1_779_000_000_000,
- },
- subscription: {
- identityType: "unknown",
- identityMasked: null,
- details: [
- {
- productId: "pro",
- productName: "Pro",
- purchaseTime: null,
- beginTime: null,
- billingCycle: "monthly",
- renewTime: null,
- expireTime: "2026-12-31T00:00:00.000Z",
- },
- ],
- },
- quota: {
- level: "pro",
- limits: [],
- },
- ...overrides,
- };
- }
- describe("model provider coding plan", () => {
- afterEach(() => {
- vi.useRealTimers();
- });
- it.each(["unknown", "loading"] as const)("购买登录态为 %s 时保持 Select 不可用", (status) => {
- expect(isCodingPlanPurchaseAuthPending(status)).toBe(true);
- });
- it.each(["authenticated", "unauthenticated", "error"] as const)(
- "购买登录态明确为 %s 时允许 Select 决策",
- (status) => {
- expect(isCodingPlanPurchaseAuthPending(status)).toBe(false);
- },
- );
- it("套餐选择发起的同一次登录成功后只恢复升级页面", () => {
- const target = {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- initialAudience: "personal" as const,
- };
- expect(
- resolvePendingCodingPlanUpgradeAfterLogin({
- pending: { loginAttemptId: 7, target },
- loginAttempt: {
- id: 7,
- providerId: ZAI_PROVIDER_ID,
- status: "succeeded",
- },
- }),
- ).toEqual({ action: "reopen", target });
- });
- it("套餐登录恢复只记录 audience 并重开 Plan 首页", () => {
- const requestLoginEntry = vi.fn(() => 7);
- const onClose = vi.fn();
- const pending = beginCodingPlanUpgradeLogin({
- target: {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- initialAudience: "team",
- },
- oauthProviderId: ZAI_PROVIDER_ID,
- audience: "personal",
- requestLoginEntry,
- onClose,
- });
- expect(pending).toEqual({
- loginAttemptId: 7,
- target: {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- initialAudience: "personal",
- },
- });
- expect(requestLoginEntry).toHaveBeenCalledWith(ZAI_PROVIDER_ID);
- expect(onClose).toHaveBeenCalledOnce();
- });
- it.each(["cancelled", "failed"] as const)(
- "套餐选择登录为 %s 时丢弃升级页面恢复意图",
- (status) => {
- expect(
- resolvePendingCodingPlanUpgradeAfterLogin({
- pending: {
- loginAttemptId: 7,
- target: {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- initialAudience: "team",
- },
- },
- loginAttempt: { id: 7, providerId: ZAI_PROVIDER_ID, status },
- }),
- ).toEqual({ action: "discard" });
- },
- );
- it("普通登录或另一条登录 attempt 成功时不恢复升级页面", () => {
- expect(
- resolvePendingCodingPlanUpgradeAfterLogin({
- pending: {
- loginAttemptId: 7,
- target: {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- initialAudience: "personal",
- },
- },
- loginAttempt: {
- id: 8,
- providerId: ZAI_PROVIDER_ID,
- status: "succeeded",
- },
- }),
- ).toEqual({ action: "discard" });
- });
- it.each([true, false])(
- "未购买套餐同步中=%s 时 Subscribe 的加载反馈与禁用状态一致",
- (loginLoading) => {
- const html = renderToStaticMarkup(
- createElement(CodingPlanStatusPanel, {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelCodingPlan,
- providerName: "BigModel",
- status: "notPurchased",
- viewState: {
- displayStatus: "notPurchased",
- actionStatus: "notPurchased",
- balanceStatus: "notPurchased",
- loginLoading,
- },
- }),
- );
- const button = html.match(
- /<button[^>]*>(?:(?!<\/button>)[\s\S])*settings\.modelProvider\.codingPlan\.subscribe<\/button>/,
- )?.[0];
- expect(button).toBeDefined();
- expect(button?.includes("animate-spin")).toBe(loginLoading);
- expect(button?.includes('disabled=""')).toBe(loginLoading);
- },
- );
- it.each(["purchased", "notPurchased"] as const)(
- "后台同步时保留已有 %s entitlement,避免详情闪烁",
- (status) => {
- expect(
- resolveCodingPlanStatusPanelViewState({
- status,
- loginPending: true,
- }),
- ).toEqual({
- displayStatus: status,
- actionStatus: status,
- balanceStatus: status,
- loginLoading: true,
- });
- },
- );
- it("uses a stable provider/auth identity for Z.ai and BigModel plan transitions", () => {
- expect(
- resolveCodingPlanProviderSyncAttemptKey({
- activeOAuthProvider: ZAI_PROVIDER_ID,
- oauthProviderId: ZAI_PROVIDER_ID,
- providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- }),
- ).toBe(`${BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan}:${ZAI_PROVIDER_ID}`);
- expect(
- resolveCodingPlanProviderSyncAttemptKey({
- activeOAuthProvider: BIGMODEL_PROVIDER_ID,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- }),
- ).toBe(`${BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan}:${BIGMODEL_PROVIDER_ID}`);
- expect(
- resolveCodingPlanProviderSyncAttemptKey({
- activeOAuthProvider: ZAI_PROVIDER_ID,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- }),
- ).toBeNull();
- });
- it("连接项未变化但上次同步未完成时允许再次刷新 Plan", () => {
- const attemptKey = `${BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan}:${BIGMODEL_PROVIDER_ID}`;
- expect(
- shouldRetryUnchangedCodingPlanProviderSync({
- attemptKey,
- attemptStatus: "failed",
- modeUnchanged: true,
- selectedKeyUnchanged: true,
- }),
- ).toBe(true);
- expect(
- shouldRetryUnchangedCodingPlanProviderSync({
- attemptKey,
- attemptStatus: "succeeded",
- modeUnchanged: true,
- selectedKeyUnchanged: true,
- }),
- ).toBe(false);
- });
- it("失效 Start 连接回到可操作的同 Family 页面,不改保存的连接", () => {
- let captured: ReturnType<typeof useModelProviderNavigation> | undefined;
- const setSelectedNodeKey = vi.fn();
- const connectionSelections = { bigmodel: { kind: "start-plan" as const } };
- function Harness() {
- captured = useModelProviderNavigation({
- presetProviders: [
- {
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- displayName: "BigModel",
- provider: null,
- },
- ],
- modelProviders: [],
- providerFamilyDomain: "bigmodel",
- connectionSelections,
- selectedNodeKey: `preset:${BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan}`,
- setSelectedNodeKey,
- intl: { formatMessage: ({ id }: { id: string }) => id } as never,
- });
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- expect(captured?.navigationUnavailable).toBe(false);
- expect(captured?.selectedNavItem).toMatchObject({
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- });
- expect(connectionSelections.bigmodel.kind).toBe("start-plan");
- });
- it("预置导航并列显示 family 与 Start,付费连接方式另放 navigationItems", () => {
- let capturedGroups: ModelProviderNavGroup[] = [];
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationGroups, navigationItems } = useModelProviderNavigation({
- presetProviders: [
- {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- displayName: "Z.ai - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- }),
- },
- {
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- displayName: "BigModel - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- name: "BigModel",
- }),
- },
- ],
- modelProviders: [],
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) =>
- id === "settings.modelProvider.connectionMode.codingPlan"
- ? "Coding Plan"
- : id === "settings.modelProvider.connectionMode.startPlan"
- ? "Start Plan"
- : id,
- } as never,
- });
- capturedGroups = navigationGroups;
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const labels = capturedGroups[0]?.items.map((item) => item.label) ?? [];
- const presetIds = capturedGroups[0]?.items.map((item) => item.presetId) ?? [];
- expect(labels).toContain("Z.ai - API Key");
- expect(labels).toContain("BigModel - API Key");
- expect(presetIds).toContain(BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan);
- expect(presetIds).toContain(BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan);
- expect(
- capturedNavigationItems.some(
- (item) =>
- item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- ),
- ).toBe(true);
- expect(
- capturedNavigationItems.some(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- ),
- ).toBe(true);
- });
- it("unlink 后独立 Start 入口仍保留,浏览不连接", () => {
- let capturedGroups: ModelProviderNavGroup[] = [];
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationGroups, navigationItems } = useModelProviderNavigation({
- presetProviders: [
- {
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- displayName: "BigModel - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- name: "BigModel",
- apiKey: "bigmodel-api-key",
- }),
- },
- ],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- name: "BigModel - Coding Plan",
- apiKey: "",
- enabled: false,
- systemDisabledReason: "coding_plan_not_connected",
- }),
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- name: "BigModel- Coding Plan",
- apiKey: "",
- enabled: false,
- systemDisabledReason: "coding_plan_not_connected",
- }),
- ],
- providerFamilyDomain: "bigmodel",
- modelProviderFamilyModes: { bigmodel: "oauth" },
- selectedNodeKey: `coding-plan:${BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan}`,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) =>
- id === "settings.modelProvider.connectionMode.codingPlan"
- ? "Coding Plan"
- : id === "settings.modelProvider.connectionMode.startPlan"
- ? "Start Plan"
- : id,
- } as never,
- });
- capturedGroups = navigationGroups;
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const presetIds = capturedGroups[0]?.items.map((item) => item.presetId) ?? [];
- expect(capturedGroups[0]?.items.map((item) => item.key)).toEqual([
- "preset:account:bigmodel-start-plan",
- "coding-plan:account:bigmodel-start-plan",
- ]);
- expect(capturedNavigationItems.map((item) => item.presetId)).toContain(
- BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- );
- expect(presetIds).not.toContain(BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan);
- });
- it.each([false, true])(
- "失效 Start 或设置读取失败仍能重选,不猜测可执行模型(读取失败=%s)",
- (familyConnectionSettingsFailed) => {
- let capturedSelectedNavItem: ModelProviderNavGroup["items"][number] | null = null;
- function Harness() {
- const { selectedNavItem } = useModelProviderNavigation({
- presetProviders: [
- {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- displayName: "Z.ai - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai",
- apiKey: "",
- enabled: false,
- }),
- },
- ],
- modelProviders: [],
- providerFamilyDomain: "zai",
- connectionSelections: { zai: { kind: "start-plan" } },
- familyConnectionSettingsFailed,
- selectedNodeKey: `preset:${BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan}`,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedSelectedNavItem = selectedNavItem;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- expect(capturedSelectedNavItem).toMatchObject({
- status: "disconnected",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- });
- },
- );
- it("BigModel family 侧栏状态跟随当前 Team Plan 连接方式点亮", () => {
- let capturedGroups: ModelProviderNavGroup[] = [];
- let capturedSelectedNavItem: ModelProviderNavGroup["items"][number] | null = null;
- function Harness() {
- const { navigationGroups, selectedNavItem } = useModelProviderNavigation({
- presetProviders: [
- {
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- displayName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- name: "BigModel",
- apiKey: "",
- enabled: false,
- }),
- },
- ],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
- name: "BigModel Team",
- enabled: true,
- }),
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- name: "BigModel - Coding Plan",
- enabled: false,
- systemDisabledReason: "coding_plan_not_entitled",
- }),
- ],
- providerFamilyDomain: "bigmodel",
- connectionSelections: {
- bigmodel: {
- kind: "team-coding-plan",
- productId: "product-current",
- organizationId: "org-a",
- projectId: "project-a",
- },
- },
- subscribedTeamProducts: [
- {
- productId: "product-current",
- productName: "GLM Coding Team",
- subscribed: true,
- organizationId: "org-a",
- organizationName: "Org A",
- projectId: "project-a",
- projectName: "Project A",
- } as never,
- ],
- selectedNodeKey: `preset:${BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan}`,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: (descriptor: { id: string }) => descriptor.id,
- } as never,
- });
- capturedGroups = navigationGroups;
- capturedSelectedNavItem = selectedNavItem;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- expect(capturedSelectedNavItem).toMatchObject({
- type: "teamPlan",
- statusActive: true,
- projectId: "project-a",
- });
- expect(capturedGroups[0]?.items[0]).toMatchObject({
- type: "preset",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- statusActive: true,
- statusProvider: {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
- enabled: true,
- executable: true,
- },
- });
- });
- it("已落盘的 Coding Plan 不进入自定义供应商分组", () => {
- let capturedGroups: ModelProviderNavGroup[] = [];
- function Harness() {
- const { navigationGroups } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- }),
- createProvider({
- id: "custom-provider",
- name: "Custom Provider",
- config: { group: "standard-personal" },
- }),
- ],
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) =>
- id === "settings.modelProvider.connectionMode.codingPlan" ? "Individual Plan" : id,
- } as never,
- });
- capturedGroups = navigationGroups;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const customGroup = capturedGroups.find((group) => group.id === "custom");
- expect(customGroup?.items.map((item) => item.label)).toEqual(["Custom Provider"]);
- });
- it("Provider Template 和新增入口不混入已配置 Provider 导航", () => {
- let capturedGroups: ModelProviderNavGroup[] = [];
- function Harness() {
- const { navigationGroups } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [
- createProvider({
- id: "custom-provider",
- name: "Custom Provider",
- config: { group: "standard-personal" },
- }),
- ],
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: { formatMessage: ({ id }: { id: string }) => id } as never,
- });
- capturedGroups = navigationGroups;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const items = capturedGroups.find((group) => group.id === "custom")?.items ?? [];
- expect(items.map((item) => item.type)).toEqual(["custom"]);
- });
- it("刷新中按缓存后的 provider 状态显示 Z.ai 入口且不显示 loading", () => {
- for (const [selectedNodeKey] of [
- ["coding-plan:account:zai-individual-coding-plan"],
- ["coding-plan:account:zai-start-plan"],
- ] as const) {
- let capturedGroups: ModelProviderNavGroup[] = [];
- let capturedNavigationItems: ReturnType<
- typeof useModelProviderNavigation
- >["navigationItems"] = [];
- function Harness() {
- const { navigationGroups, navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- apiKey: "zai-coding-plan-key",
- }),
- ],
- modelProvidersLoading: true,
- selectedNodeKey,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedGroups = navigationGroups;
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const presetItems = capturedNavigationItems;
- expect(
- presetItems.some(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- ),
- ).toBe(true);
- expect(presetItems.some((item) => item.type === "codingPlanLoading")).toBe(false);
- expect(capturedGroups[0]?.items.some((item) => item.type === "codingPlan")).toBe(true);
- }
- });
- it.each([undefined, "credential-unavailable"] as const)(
- "已登录团队失败(%s)显示重试而不是连接账号",
- (availabilityReason) => {
- for (const hasProvider of [true, false]) {
- const html = renderDetail(
- {
- key: "team:bigmodel:product:org:project",
- type: "teamPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "团队",
- providerName: "BigModel",
- teamPlanName: "团队",
- organizationId: "org",
- projectId: "project",
- currentProductId: "product",
- provider: hasProvider
- ? createProvider({ id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan })
- : null,
- status: "unavailable",
- statusActive: false,
- availabilityReason,
- statusMessage: availabilityReason ? "无法创建API Key" : undefined,
- },
- { onRetryCodingPlan: vi.fn() },
- );
- expect(html).toContain("common.retry");
- expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
- expect(html).not.toContain("login.expired.action");
- }
- },
- );
- it("自定义供应商详情仍展示可配置的 API 格式", () => {
- const html = renderDetail({
- key: "custom:provider-a",
- type: "custom",
- label: "Provider A",
- provider: createProvider({ id: "provider-a" }),
- statusActive: false,
- });
- expectConnectionApiFormatVisible(html);
- });
- it.each(["zai", "bigmodel"] as const)(
- "%s 个人套餐失败重新登录,Start 套餐失败保留重试",
- (family) => {
- for (const plan of ["individual-coding-plan", "start-plan"] as const) {
- const providerId = `account:${family}-${plan}` as const;
- const provider = {
- ...createProvider({ id: providerId }),
- accountState: {
- availability: "unavailable" as const,
- entitled: false,
- unavailableReason: "credential-failed" as const,
- },
- };
- const html = renderDetail(
- {
- key: `coding-plan:${providerId}`,
- type: "codingPlan",
- presetId: providerId,
- oauthProviderId: family,
- label: family,
- providerName: family,
- provider,
- status: "unavailable",
- statusActive: false,
- },
- { onRetryCodingPlan: vi.fn() },
- );
- if (plan === "individual-coding-plan") {
- expect(html).toContain("login.expired.action");
- expect(html).toContain("settings.modelProvider.codingPlan.description.credentialFailed");
- expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
- } else {
- expect(html).toContain("common.retry");
- expect(html).not.toContain("login.expired.action");
- expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
- }
- }
- },
- );
- it("内置 GLM-5.2 模型按 1M 上下文窗口展示", () => {
- const html = renderDetail({
- key: `coding-plan:${BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan}`,
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Coding Plan",
- defaultKind: "anthropic",
- endpoints: {
- baseURL: "https://zcode.z.ai/api/v1/zcode-plan/anthropic",
- paths: { anthropic: "/v1/messages" },
- },
- models: [
- createModelProviderModelConfig({
- id: "GLM-5.2",
- kinds: ["anthropic"],
- defaultKind: "anthropic",
- contextWindow: 1_000_000,
- }),
- ],
- }),
- status: "purchased",
- statusActive: true,
- });
- expect(html).toContain("GLM-5.2");
- expect(html).toContain(">1M<");
- expect(html).not.toContain(">200K<");
- });
- it("Account Provider 的 Effective 模型列表允许通过 Personal modelOrder 调序", () => {
- const html = renderDetail(
- {
- key: `coding-plan:${BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan}`,
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Coding Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- models: [
- createModelProviderModelConfig({ id: "GLM-5.2" }),
- createModelProviderModelConfig({ id: "GLM-5-Turbo" }),
- ],
- }),
- status: "purchased",
- statusActive: true,
- },
- { onReorderProviderModels: vi.fn(async () => undefined) },
- );
- expect(html.match(/aria-label="settings\.modelProvider\.reorderModel"/g)).toHaveLength(2);
- });
- it("体验套餐详情允许标准模型配置,但 Built-in 成员不可删除", () => {
- const primaryModel = "start-plan-cloud-primary";
- const secondaryModel = "start-plan-cloud-secondary";
- const html = renderDetail({
- key: `coding-plan:${BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan}`,
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Start Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- name: "BigModel - Start Plan",
- defaultKind: "anthropic",
- endpoints: {
- baseURL: "https://zcode.z.ai/api/v1/zcode-plan/anthropic",
- paths: { anthropic: "/v1/messages" },
- },
- models: [
- createModelProviderModelConfig({
- id: primaryModel,
- builtin: true,
- kinds: ["anthropic"],
- defaultKind: "anthropic",
- }),
- createModelProviderModelConfig({
- id: secondaryModel,
- builtin: true,
- kinds: ["anthropic"],
- defaultKind: "anthropic",
- }),
- ],
- }),
- status: "purchased",
- statusActive: true,
- });
- expect(html).toContain(primaryModel);
- expect(html).toContain(secondaryModel);
- expect(html).toContain(TID_MODEL_PROVIDER_ADD_MODEL_BUTTON);
- expect(html).not.toContain(TID_MODEL_PROVIDER_MODEL_DELETE_BUTTON);
- });
- it("Todo89:Account 已确认可用时,Start 额度卡临时刷新不隐藏模型编辑区", () => {
- const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan;
- const provider = createProvider({
- id: providerId,
- models: ["start-dynamic-model"],
- });
- const view = createProviderSettingsView(provider);
- const item = {
- key: `coding-plan:${providerId}`,
- type: "codingPlan" as const,
- presetId: providerId,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "Start",
- providerName: "BigModel",
- provider,
- status: "checking" as const,
- statusActive: false,
- };
- const availableView = {
- ...view,
- providers: view.providers.map((p) => ({
- ...p,
- accountState: {
- availability: "available" as const,
- entitled: true,
- current: true,
- },
- })),
- };
- expect(renderDetail(item, { providerSettingsView: availableView })).toContain(
- "start-dynamic-model",
- );
- const unavailableView = {
- ...view,
- providers: view.providers.map((p) => ({
- ...p,
- accountState: {
- availability: "unavailable" as const,
- entitled: false,
- current: true,
- },
- })),
- };
- expect(renderDetail(item, { providerSettingsView: unavailableView })).not.toContain(
- "start-dynamic-model",
- );
- });
- it("自定义供应商详情按单一 runtime config 展示可编辑 API 格式且不展示接口路径编辑", () => {
- const html = renderDetail({
- key: "custom:provider-a",
- type: "custom",
- label: "Provider A",
- provider: createProvider({
- id: "provider-a",
- apiFormat: "openai-chat-completions",
- defaultKind: "openai-compatible",
- endpoints: {
- baseURL: "https://api.example.com/v1",
- paths: {
- "openai-compatible": "/chat/completions",
- },
- },
- models: [
- createModelProviderModelConfig({
- id: "glm-5",
- kinds: ["openai-compatible"],
- defaultKind: "openai-compatible",
- }),
- ],
- }),
- statusActive: false,
- });
- const intl = { formatMessage: ({ id }: { id: string }) => id };
- const apiFormatOptions = resolveProviderConnectionApiFormatOptions();
- expect(apiFormatOptions).toEqual([
- "anthropic-messages",
- "openai-chat-completions",
- "openai-responses",
- ]);
- expect(
- apiFormatOptions.map((format) =>
- resolveProviderConnectionApiFormatDisplayLabel(intl, format),
- ),
- ).toEqual([
- "settings.modelProvider.apiFormat.title.anthropicMessages (/v1/messages)",
- "settings.modelProvider.apiFormat.title.chatCompletions (/chat/completions)",
- "settings.modelProvider.apiFormat.title.responses (/responses)",
- ]);
- expect(html).toContain('value="https://api.example.com/v1"');
- expectConnectionApiFormatVisible(html);
- expect(html).not.toContain("settings.modelProvider.endpointPath");
- });
- it("自定义供应商详情隐藏 Claude 映射和自定义 Headers", () => {
- const html = renderDetail({
- key: "custom:provider-a",
- type: "custom",
- label: "Provider A",
- provider: createProvider({
- id: "provider-a",
- }),
- statusActive: false,
- });
- expect(html).not.toContain("settings.modelProvider.claudeMapping");
- expect(html).not.toContain("settings.modelProvider.customHeaders");
- });
- it("Provider sidebar 将预置入口组织成 provider family", () => {
- let capturedGroups: ModelProviderNavGroup[] = [];
- function Harness() {
- const { navigationGroups } = useModelProviderNavigation({
- presetProviders: [
- {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- displayName: "Z.ai - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- }),
- },
- {
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- displayName: "BigModel - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- name: "BigModel",
- }),
- },
- ],
- modelProviders: [],
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedGroups = navigationGroups;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- expect(
- capturedGroups[0]?.items.map((item) => (item.type === "preset" ? item.presetId : item.key)),
- ).toEqual([
- BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- "coding-plan:account:zai-start-plan",
- "coding-plan:account:bigmodel-start-plan",
- ]);
- });
- it("套餐连接入口点击时仍映射回 provider family side key", () => {
- expect(
- resolveModelProviderSideSelectionKey({
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- }),
- status: "purchased",
- planLevel: "Coding Pro",
- currentProductId: "product-zai-pro",
- subscriptionBillingCycle: null,
- subscriptionRenewTime: null,
- subscriptionExpireTime: null,
- quotaLimits: [],
- purchaseUrl: "https://z.ai/manage-apikey/subscription",
- statusActive: true,
- }),
- ).toBe("preset:account:zai-start-plan");
- });
- it.each([
- ["preset", BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan, "BigModel", "BigModel"],
- ["preset", BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan, "Z.ai", "Z.ai"],
- ["codingPlan", BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan, "Start Plan", "Start Plan"],
- ["codingPlan", BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan, "Start Plan", "Start Plan"],
- ] as const)("导航 %s %s 保持品牌与 Start 名称", (type, presetId, en, zh) => {
- const item: ModelProviderNavItem = {
- key: presetId,
- type,
- presetId,
- label: "Old brand",
- ...(type === "preset"
- ? { displayName: "Old brand" }
- : {
- oauthProviderId: "bigmodel" as const,
- providerName: "Old brand",
- status: "notPurchased" as const,
- }),
- provider: null,
- statusActive: false,
- };
- expect(resolveModelProviderSideNavLabel(item)).toBe(en);
- expect(resolveModelProviderSideNavLabel(item)).toBe(zh);
- });
- it("Provider sidebar 不按团队 Coding Plan 数量展开入口", () => {
- const bigmodelApiKeyItem = {
- key: "preset:account:bigmodel-start-plan",
- type: "preset" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- label: "BigModel - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- }),
- displayName: "BigModel - API Key",
- statusActive: true,
- };
- const html = renderWithTooltipProvider(
- createElement(ModelProviderSectionNavigation, {
- navigationGroups: [
- {
- id: "preset",
- title: "Preset",
- items: [bigmodelApiKeyItem],
- },
- ],
- selectedNodeKey: "preset:account:bigmodel-start-plan",
- presetLoading: false,
- customLoading: false,
- onSelectNavItem: vi.fn(),
- }),
- );
- expect(html).toContain("BigModel");
- expect(html).not.toContain("Team A");
- expect(html).not.toContain("Team B");
- });
- it("Z.ai family 导航保持品牌图标,不借用 Start 图标", () => {
- const html = renderWithTooltipProvider(
- createElement(ModelProviderSectionNavigation, {
- navigationGroups: [
- {
- id: "preset",
- title: "Preset",
- items: [
- {
- key: "preset:account:zai-start-plan",
- type: "preset",
- logo: { type: "builtin", key: "zai" },
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- label: "Z.ai - API Key",
- displayName: "Z.ai - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - API Key",
- config: { logo: { type: "builtin", key: "start-plan" } },
- }),
- statusActive: true,
- },
- ],
- },
- ],
- selectedNodeKey: "preset:account:zai-start-plan",
- presetLoading: false,
- customLoading: false,
- onSelectNavItem: vi.fn(),
- }),
- );
- expect(html).toContain("Z.ai");
- expect(html).toContain("<img ");
- expect(html).toContain("model-provider-zai-app.png");
- expect(html).not.toContain("model-provider-start-plan.png");
- expect(html).toContain("object-contain size-4");
- expect(html).toContain("border-border-hover bg-card-selected text-foreground");
- expect(html).not.toContain("border-card-border bg-surface");
- expect(html).toContain("flex h-8 w-full");
- expect(html).not.toContain("settings.modelProvider.connectionMode.startPlan");
- expect(html).not.toContain("settings.modelProvider.codingPlan.start.freeBadge");
- });
- it("仅有个人付费选项时不显示冗余套餐下拉", () => {
- const startPlanItem = {
- key: "coding-plan:account:zai-start-plan",
- type: "codingPlan" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Start Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Start Plan",
- }),
- status: "purchased" as const,
- statusActive: true,
- };
- const oauthItem = {
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- }),
- status: "purchased" as const,
- statusActive: true,
- };
- const html = renderDetail(oauthItem, {
- navigationItems: [startPlanItem, oauthItem],
- connectionSelections: { zai: { kind: "individual-coding-plan" } },
- onSelectNavItem: vi.fn(),
- });
- expect(html).toContain(">Z.ai<");
- expect(html).toContain("settings.modelProvider.planCard.codingPlan");
- expect(html).not.toContain("settings.modelProvider.connectionMode");
- expect(html).not.toContain('role="combobox"');
- expect(html).not.toContain('role="tablist"');
- expect(html).not.toContain('role="tab"');
- });
- it("Start 详情不展示付费连接获取失败提示", () => {
- const startPlanItem = {
- key: "coding-plan:account:zai-start-plan",
- type: "codingPlan" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Start Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Start Plan",
- }),
- status: "purchased" as const,
- statusActive: true,
- };
- const oauthItem = {
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: null,
- status: "disconnected" as const,
- purchaseUrl: "https://z.ai/",
- statusActive: false,
- };
- const html = renderDetail(startPlanItem, {
- navigationItems: [startPlanItem, oauthItem],
- connectionSettingsFailed: true,
- onSelectNavItem: vi.fn(),
- });
- expect(html).not.toContain("settings.modelProvider.connectionMode.loadFailed");
- expect(html).not.toContain("text-warning");
- expect(html).toContain("settings.modelProvider.planCard.startPlan");
- });
- it("付费连接方式下拉平铺 Coding 和多个 Team Plan,排除 Start", () => {
- const startPlanItem = {
- key: "coding-plan:account:bigmodel-start-plan",
- type: "codingPlan" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Start Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- }),
- status: "purchased" as const,
- statusActive: true,
- };
- const codingPlanItem = {
- key: "coding-plan:account:bigmodel-individual-coding-plan",
- type: "codingPlan" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Coding Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- }),
- status: "purchased" as const,
- statusActive: true,
- };
- const teamAItem = {
- ...codingPlanItem,
- key: "team-plan:team-a",
- type: "teamPlan" as const,
- teamPlanName: "TeamA",
- organizationId: "org-a",
- projectId: "proj-a",
- };
- const teamBItem = {
- ...codingPlanItem,
- key: "team-plan:team-b",
- type: "teamPlan" as const,
- teamPlanName: "TeamB Plan",
- organizationId: "org-b",
- projectId: "proj-b",
- };
- const options = buildProviderFamilyConnectionOptions({
- familyId: "bigmodel",
- navigationItems: [teamBItem, codingPlanItem, startPlanItem, teamAItem],
- startPlanLabel: "体验套餐",
- codingPlanLabel: "个人套餐",
- teamPlanFallbackLabel: "Team Plan",
- });
- expect(options.map((option) => option.label)).toEqual(["个人套餐", "TeamB Plan", "TeamA"]);
- });
- it("已购企业套餐会进入连接方式导航项", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [
- {
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- displayName: "BigModel - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- }),
- },
- ],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- name: "BigModel - Coding Plan",
- apiKey: "jwt-token",
- }),
- ],
- codingPlanEntitlements: {},
- subscribedTeamProducts: [
- {
- productId: "product-team-max",
- productName: "Max",
- productBigTitle: "Max",
- originalAmount: 598,
- payAmount: 598,
- renewAmount: 598,
- priceUnit: "month",
- priceCurrency: "CNY",
- productEquityList: [],
- hasPreview: true,
- organizationId: "org-team-a",
- organizationName: "TeamA Org",
- projectId: "proj-team-a",
- projectName: "团队编程套餐项目",
- enterpriseProduct: {
- productId: "product-team-max",
- tier: "MAX",
- subscribeMode: "CONTINUOUS",
- subscribePeriod: "MONTHLY",
- subscribed: true,
- organizationId: "org-team-a",
- organizationName: "TeamA Org",
- projectId: "proj-team-a",
- projectName: "团队编程套餐项目",
- },
- tier: "MAX",
- subscribeMode: "CONTINUOUS",
- subscribePeriod: "MONTHLY",
- purchaseMethodName: "连续订阅",
- subscribed: true,
- },
- ],
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const teamPlan = capturedNavigationItems.find((item) => item.type === "teamPlan");
- const startPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- );
- expect(teamPlan).toMatchObject({
- key: "team:bigmodel:product-team-max:org-team-a:proj-team-a",
- teamPlanName: "TeamA Org",
- label: "BigModel - TeamA Org",
- organizationId: "org-team-a",
- projectId: "proj-team-a",
- status: "purchased",
- currentProductId: "product-team-max",
- });
- expect(startPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
- });
- it("初始化 fallback 只选中 BigModel family 侧栏入口", () => {
- const codingPlanItem = {
- key: "coding-plan:account:bigmodel-individual-coding-plan",
- type: "codingPlan" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Coding Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- }),
- status: "purchased" as const,
- statusActive: true,
- };
- const teamPlanItem = {
- ...codingPlanItem,
- key: "team:bigmodel:product-team-max:org-team:project-team",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
- type: "teamPlan" as const,
- teamPlanName: "TeamA",
- currentProductId: "product-team-max",
- organizationId: "org-team",
- projectId: "project-team",
- };
- expect(
- resolveFallbackModelProviderNodeKey({
- selectedNodeKey: null,
- selectableNavigationItems: [codingPlanItem, teamPlanItem],
- connectionSelections: {
- bigmodel: {
- kind: "team-coding-plan",
- productId: "product-team-max",
- organizationId: "org-team",
- projectId: "project-team",
- },
- },
- }),
- ).toBe("preset:account:bigmodel-start-plan");
- });
- it("Team Plan 异步出现后从默认 Coding Plan 纠偏到已保存连接方式", () => {
- const codingPlanItem = {
- key: "coding-plan:account:bigmodel-individual-coding-plan",
- type: "codingPlan" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Coding Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- }),
- status: "purchased" as const,
- statusActive: true,
- };
- const teamPlanItem = {
- ...codingPlanItem,
- key: "team:bigmodel:product-team-max:org-team:project-team",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
- type: "teamPlan" as const,
- teamPlanName: "TeamA",
- currentProductId: "product-team-max",
- organizationId: "org-team",
- projectId: "project-team",
- };
- expect(
- resolveSelectedFamilyModeNodeKey({
- selectedNavItem: codingPlanItem,
- selectableNavigationItems: [codingPlanItem, teamPlanItem],
- connectionSelections: {
- bigmodel: {
- kind: "team-coding-plan",
- productId: "product-team-max",
- organizationId: "org-team",
- projectId: "project-team",
- },
- },
- }),
- ).toBe("team:bigmodel:product-team-max:org-team:project-team");
- });
- it("Team Plan 商品 ID 变化时仍按项目 key 恢复已保存连接方式", () => {
- const codingPlanItem = {
- key: "coding-plan:account:bigmodel-individual-coding-plan",
- type: "codingPlan" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Coding Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- }),
- status: "purchased" as const,
- statusActive: true,
- };
- const teamPlanItem = {
- ...codingPlanItem,
- key: "team:bigmodel:product-current:org-team:proj-team",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
- type: "teamPlan" as const,
- teamPlanName: "TeamA",
- currentProductId: "product-current",
- organizationId: "org-team",
- projectId: "proj-team",
- };
- expect(
- resolveSelectedFamilyModeNodeKey({
- selectedNavItem: codingPlanItem,
- selectableNavigationItems: [codingPlanItem, teamPlanItem],
- connectionSelections: {
- bigmodel: {
- kind: "team-coding-plan",
- productId: "product-current",
- organizationId: "org-team",
- projectId: "proj-team",
- },
- },
- }),
- ).toBe("team:bigmodel:product-current:org-team:proj-team");
- });
- it("手动选择 Coding Plan 的 pending selectedKey 不被已保存 Team Plan 纠偏", () => {
- const codingPlanItem = {
- key: "coding-plan:account:bigmodel-individual-coding-plan",
- type: "codingPlan" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Coding Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- }),
- status: "purchased" as const,
- statusActive: true,
- };
- const teamPlanItem = {
- ...codingPlanItem,
- key: "team:bigmodel:product-team-max:org-team:project-team",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
- type: "teamPlan" as const,
- teamPlanName: "TeamA",
- currentProductId: "product-team-max",
- organizationId: "org-team",
- projectId: "project-team",
- };
- expect(
- resolveSelectedFamilyModeNodeKey({
- selectedNavItem: codingPlanItem,
- selectableNavigationItems: [codingPlanItem, teamPlanItem],
- connectionSelections: {
- bigmodel: {
- kind: "team-coding-plan",
- productId: "product-team-max",
- organizationId: "org-team",
- projectId: "project-team",
- },
- },
- pendingConnectionSelections: {
- bigmodel: { kind: "individual-coding-plan" },
- },
- }),
- ).toBeNull();
- });
- it("手动选择 Coding Plan 的 pending selectedKey 优先于 Start 初始化优先级", () => {
- let capturedSelectedNavItem: ReturnType<typeof useModelProviderNavigation>["selectedNavItem"] =
- null;
- function Harness() {
- const { selectedNavItem } = useModelProviderNavigation({
- presetProviders: [
- {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- displayName: "Z.ai - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- }),
- },
- ],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Start Plan",
- apiKey: "start-token",
- }),
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- apiKey: "coding-token",
- }),
- ],
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan]: {
- loading: false,
- error: null,
- snapshot: createEntitlementSnapshot({
- provider: { id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan },
- remaining: null,
- subscription: {
- identityType: "unknown",
- identityMasked: null,
- details: [
- {
- productId: "zcode-v3-start-plan",
- productName: "Start Plan",
- purchaseTime: null,
- beginTime: null,
- billingCycle: null,
- renewTime: null,
- expireTime: null,
- },
- ],
- },
- quota: null,
- }),
- },
- [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
- loading: false,
- error: null,
- snapshot: createEntitlementSnapshot({
- provider: {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- },
- remaining: null,
- subscription: {
- identityType: "unknown",
- identityMasked: null,
- details: [
- {
- productId: "product-zai-pro",
- productName: "GLM Coding Pro",
- purchaseTime: null,
- beginTime: null,
- billingCycle: "monthly",
- renewTime: null,
- expireTime: null,
- },
- ],
- },
- quota: null,
- }),
- },
- },
- selectedNodeKey: "preset:account:zai-start-plan",
- connectionSelections: { zai: { kind: "individual-coding-plan" } },
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedSelectedNavItem = selectedNavItem;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- expect(capturedSelectedNavItem).toMatchObject({
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- });
- });
- it("外部打开 Model Settings 时等待连接方式设置 hydrate,避免先闪成 Start Plan", () => {
- let capturedSelectedNavItem: ReturnType<typeof useModelProviderNavigation>["selectedNavItem"] =
- null;
- function Harness() {
- const { selectedNavItem } = useModelProviderNavigation({
- presetProviders: [
- {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- displayName: "Z.ai - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- }),
- },
- ],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Start Plan",
- apiKey: "start-token",
- }),
- ],
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan]: {
- loading: false,
- error: null,
- snapshot: createEntitlementSnapshot({
- provider: { id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan },
- remaining: null,
- subscription: {
- identityType: "unknown",
- identityMasked: null,
- details: [
- {
- productId: "zcode-v3-start-plan",
- productName: "Start Plan",
- purchaseTime: null,
- beginTime: null,
- billingCycle: null,
- renewTime: null,
- expireTime: null,
- },
- ],
- },
- quota: null,
- }),
- },
- },
- selectedNodeKey: "preset:account:zai-start-plan",
- modelProviderFamilyModes: {},
- modelProviderFamilySelectedKeys: {},
- familyConnectionSettingsLoading: true,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedSelectedNavItem = selectedNavItem;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- expect(capturedSelectedNavItem).toBeNull();
- });
- it("OAuth family 的 Plan 连接项未生成时右侧保持 loading,不先显示 API Key", () => {
- let capturedSelectedNavItem: ReturnType<typeof useModelProviderNavigation>["selectedNavItem"] =
- null;
- function Harness() {
- const { selectedNavItem } = useModelProviderNavigation({
- presetProviders: [
- {
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- displayName: "BigModel - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- name: "BigModel - API Key",
- }),
- },
- ],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- name: "BigModel - API Key",
- }),
- ],
- codingPlanEntitlements: {},
- modelProvidersLoading: true,
- selectedNodeKey: "preset:account:bigmodel-start-plan",
- modelProviderFamilyModes: { bigmodel: "oauth" },
- modelProviderFamilySelectedKeys: {},
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedSelectedNavItem = selectedNavItem;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- expect(capturedSelectedNavItem).toBeNull();
- });
- it("连接方式设置获取失败时显示错误并提供可操作入口,不停在 loading", () => {
- let capturedSelectedNavItem: ReturnType<typeof useModelProviderNavigation>["selectedNavItem"] =
- null;
- let unavailable = false;
- function Harness() {
- const { selectedNavItem, navigationUnavailable } = useModelProviderNavigation({
- presetProviders: [
- {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- displayName: "Z.ai - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- }),
- },
- ],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - API Key",
- }),
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Start Plan",
- apiKey: "start-token",
- }),
- ],
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan]: {
- loading: false,
- error: null,
- snapshot: createEntitlementSnapshot({
- provider: { id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan },
- remaining: null,
- subscription: {
- identityType: "unknown",
- identityMasked: null,
- details: [
- {
- productId: "zcode-v3-start-plan",
- productName: "Start Plan",
- purchaseTime: null,
- beginTime: null,
- billingCycle: null,
- renewTime: null,
- expireTime: null,
- },
- ],
- },
- quota: null,
- }),
- },
- },
- selectedNodeKey: "preset:account:zai-start-plan",
- modelProviderFamilyModes: {},
- modelProviderFamilySelectedKeys: {},
- familyConnectionSettingsFailed: true,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedSelectedNavItem = selectedNavItem;
- unavailable = navigationUnavailable;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- expect(unavailable).toBe(true);
- expect(capturedSelectedNavItem).toMatchObject({
- type: "codingPlan",
- status: "disconnected",
- });
- });
- it("Team Plan 使用团队项目上下文生成连接入口", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- name: "BigModel - Coding Plan",
- apiKey: "jwt-token",
- }),
- ],
- subscribedTeamProducts: [
- {
- productId: "product-0e2085",
- productName: "Pro",
- productBigTitle: "Pro",
- originalAmount: 100,
- canRepurchase: true,
- inCurrentPeriod: true,
- productEquityList: [],
- hasPreview: true,
- enterpriseProduct: {
- productId: "product-0e2085",
- tier: "PRO",
- subscribeMode: "CONTINUOUS",
- subscribePeriod: "MONTHLY",
- subscribed: true,
- },
- tier: "PRO",
- subscribeMode: "CONTINUOUS",
- subscribePeriod: "MONTHLY",
- purchaseMethodName: "月付",
- subscribed: true,
- teamProjects: [
- {
- organizationId: "org-team",
- organizationName: "默认机构",
- projectId: "proj-team",
- projectName: "团队编程套餐项目",
- apiKeyStatus: "unavailable",
- apiKeyUnavailableMessage: "您当前暂无有效的团队套餐授权记录,无法创建API Key",
- },
- ],
- },
- ],
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const teamItem = capturedNavigationItems.find((item) => item.type === "teamPlan");
- expect(teamItem).toMatchObject({
- key: "team:bigmodel:product-0e2085:org-team:proj-team",
- organizationId: "org-team",
- projectId: "proj-team",
- status: "unavailable",
- availabilityReason: "credential-unavailable",
- statusLabelId: undefined,
- statusMessage: "您当前暂无有效的团队套餐授权记录,无法创建API Key",
- });
- const codingPlanItem = {
- key: "coding-plan:account:bigmodel-individual-coding-plan",
- type: "codingPlan" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Coding Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- }),
- status: "purchased" as const,
- statusActive: true,
- };
- expect(
- resolveSelectedFamilyModeNodeKey({
- selectedNavItem: codingPlanItem,
- selectableNavigationItems: [codingPlanItem, teamItem!].filter(
- (item) => item.type !== "codingPlanLoading",
- ),
- connectionSelections: {
- bigmodel: {
- kind: "team-coding-plan",
- productId: "product-0e2085",
- organizationId: "org-team",
- projectId: "proj-team",
- },
- },
- }),
- ).toBe("team:bigmodel:product-0e2085:org-team:proj-team");
- });
- it("entitlement snapshot 带团队上下文时不依赖 enterprise pricing 展示 Team Plan", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [
- {
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- displayName: "BigModel - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- }),
- },
- ],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- name: "BigModel - Coding Plan",
- apiKey: "jwt-token",
- }),
- ],
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan]: {
- loading: false,
- error: null,
- snapshot: createEntitlementSnapshot({
- context: {
- scope: "team",
- organizationId: "org-current",
- projectId: "project-current",
- productId: "team-current",
- displayName: "Coding Team",
- },
- subscription: {
- identityType: "email",
- identityMasked: "t***@z.ai",
- details: [
- {
- productId: "team-current",
- productName: "Coding Team",
- purchaseTime: null,
- beginTime: null,
- expireTime: "2026-08-01T00:00:00Z",
- },
- ],
- },
- }),
- },
- },
- subscribedTeamProducts: [],
- showPurchasedTeamPlanFallback: false,
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const teamPlan = capturedNavigationItems.find((item) => item.type === "teamPlan");
- expect(teamPlan).toMatchObject({
- key: "team:bigmodel:team-current:org-current:project-current",
- teamPlanName: "Coding Team",
- status: "purchased",
- currentProductId: "team-current",
- organizationId: "org-current",
- projectId: "project-current",
- });
- });
- it("Start 详情不因没有付费套餐显示连接控件", () => {
- const startPlanItem = {
- key: "coding-plan:account:zai-start-plan",
- type: "codingPlan" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Start Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Start Plan",
- }),
- status: "notPurchased" as const,
- statusActive: false,
- };
- const oauthItem = {
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- }),
- status: "notPurchased" as const,
- purchaseUrl: "https://z.ai/",
- statusActive: false,
- };
- const html = renderDetail(startPlanItem, {
- navigationItems: [startPlanItem, oauthItem],
- connectionSelections: { zai: { kind: "individual-coding-plan" } },
- onSelectNavItem: vi.fn(),
- });
- expect(html).not.toContain("settings.modelProvider.connectionMode");
- expect(html).not.toContain('role="combobox"');
- expect(html).not.toContain("settings.modelProvider.connectionMode.noAvailablePlan");
- expect(html).not.toContain('disabled=""');
- });
- it("Coding Plan 状态同步中展示 checking,避免停留在旧的未连接状态", () => {
- const oauthItem = {
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- apiKey: "",
- }),
- status: "disconnected" as const,
- purchaseUrl: "https://z.ai/",
- statusActive: false,
- };
- const html = renderDetail(oauthItem, {
- codingPlanStatusSyncProviderId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- });
- expect(html).toContain("settings.modelProvider.codingPlan.status.checking");
- expect(html).not.toContain("settings.modelProvider.codingPlan.status.disconnected");
- expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
- });
- it("StartPlanCard 使用远端 startPlanPreview 展示体验套餐权益", () => {
- const html = renderToStaticMarkup(
- createElement(StartPlanCard, {
- preview: {
- planId: "zcode-v3-start-plan",
- name: "ZCode V3 Start Plan",
- entitlements: [
- {
- grantUnits: 3_000_000,
- meter: "model_usage",
- period: "daily",
- showName: "GLM-5.2",
- unitType: "token",
- },
- {
- grantUnits: 4_000_000,
- meter: "model_usage",
- period: "daily",
- showName: "GLM-5-Turbo",
- unitType: "token",
- },
- ],
- },
- }),
- );
- expect(html).toContain("settings.modelProvider.startPlan.quotaSectionTitle");
- expect(html).toContain("ZCode V3 Start Plan");
- expect(html).toContain("7 Million");
- expect(html).toContain("tokens per day");
- expect(html).toContain("GLM-5.2");
- expect(html).toContain("GLM-5-Turbo");
- expect(html).not.toContain("10M");
- expect(html).not.toContain(">7M<");
- expect(html.match(/3M/g)?.length).toBe(1);
- expect(html.match(/4M/g)?.length).toBe(1);
- expect(html.match(/tokens per day/g)?.length).toBe(1);
- expect(html).toContain("Daily quota · GLM-5.2 3M · GLM-5-Turbo 4M");
- expect(html).toContain("settings.modelProvider.startPlan.eligibleNewUser");
- });
- it("StartPlanCard 在模型额度相同时合并为 each 文案", () => {
- const html = renderToStaticMarkup(
- createElement(StartPlanCard, {
- preview: {
- planId: "zcode-v3-start-plan",
- name: "ZCode V3 Start Plan",
- entitlements: [
- {
- grantUnits: 10_000_000,
- meter: "model_usage",
- period: "daily",
- showName: "GLM-5.2",
- unitType: "token",
- },
- {
- grantUnits: 10_000_000,
- meter: "model_usage",
- period: "daily",
- showName: "GLM-5-Turbo",
- unitType: "token",
- },
- ],
- },
- }),
- );
- expect(html).toContain("20 Million");
- expect(html).toContain("Daily quota · GLM-5.2 / GLM-5-Turbo 10M each");
- expect(html.match(/10M/g)?.length).toBe(1);
- });
- it("StartPlanCard 英文主额度使用完整 Million 文案", () => {
- const html = renderToStaticMarkup(
- createElement(StartPlanCard, {
- preview: {
- planId: "zcode-v3-start-plan",
- name: "ZCode V3 Start Plan",
- entitlements: [
- {
- grantUnits: 5_000_000,
- meter: "model_usage",
- period: "daily",
- showName: "GLM-5.2",
- unitType: "token",
- },
- ],
- },
- }),
- );
- expect(html).toContain("5 Million");
- expect(html).toContain("tokens per day");
- expect(html).toContain("Daily quota · GLM-5.2 5M");
- expect(html).not.toContain(">5M<");
- });
- it("StartPlanCard 缺少远端权益时不展示本地硬编码 Trial plan", () => {
- const html = renderToStaticMarkup(
- createElement(StartPlanCard, {
- preview: {
- planId: "zcode-v3-start-plan",
- name: "ZCode V3 Start Plan",
- entitlements: [],
- },
- }),
- );
- expect(html).toBe("");
- expect(html).not.toContain("settings.modelProvider.startPlan.summaryTitle");
- expect(html).not.toContain("settings.modelProvider.startPlan.heroMetric");
- expect(html).not.toContain("settings.modelProvider.startPlan.summaryDescription");
- });
- it("StartPlanCard 中文界面使用本地化紧凑单位展示体验套餐额度", () => {
- intlMockState.locale = "zh-CN";
- try {
- const html = renderToStaticMarkup(
- createElement(StartPlanCard, {
- preview: {
- planId: "zcode-v3-start-plan",
- name: "ZCode V3 Start Plan",
- entitlements: [
- {
- grantUnits: 30_000_000,
- meter: "model_usage",
- period: "daily",
- showName: "GLM-5.2",
- unitType: "token",
- },
- {
- grantUnits: 10_000_000,
- meter: "model_usage",
- period: "daily",
- showName: "GLM-5-Turbo",
- unitType: "token",
- },
- ],
- },
- }),
- );
- expect(html).toContain("4000万");
- expect(html).toContain("每日额度 · GLM-5.2 3000万 · GLM-5-Turbo 1000万");
- expect(html).not.toContain("40M");
- expect(html).not.toContain("30M");
- expect(html).not.toContain("10M");
- } finally {
- intlMockState.locale = "en-US";
- }
- });
- it("StartPlanCard 中文界面单模型每日额度使用本地化紧凑单位", () => {
- intlMockState.locale = "zh-CN";
- try {
- const html = renderToStaticMarkup(
- createElement(StartPlanCard, {
- preview: {
- planId: "zcode-v3-start-plan",
- name: "ZCode V3 Start Plan",
- entitlements: [
- {
- grantUnits: 5_000_000,
- meter: "model_usage",
- period: "daily",
- showName: "GLM-5.2",
- unitType: "token",
- },
- ],
- },
- }),
- );
- expect(html).toContain("500万");
- expect(html).toContain("tokens/日");
- expect(html).toContain("每日额度 · GLM-5.2 500万");
- expect(html).not.toContain("5 Million");
- expect(html).not.toContain("5M");
- } finally {
- intlMockState.locale = "en-US";
- }
- });
- it("Z.ai Start Plan 编程套餐列表复用 Coding Plan 商品来源", () => {
- expect(
- resolveCodingPlanUpgradeProductsProviderId(BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan),
- ).toBe(BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan);
- });
- it("Z.ai Start Plan 未登录且无远端 preview 时不显示 Trial plan 卡片", () => {
- const html = renderDetail({
- key: "coding-plan:account:zai-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: null,
- status: "disconnected",
- purchaseUrl: "https://z.ai/",
- statusActive: false,
- });
- expect(html).toContain("settings.modelProvider.planCard.startPlan");
- expect(html).not.toContain("settings.modelProvider.startPlan.summaryTitle");
- expect(html).not.toContain("settings.modelProvider.startPlan.quotaSectionTitle");
- expect(html).not.toContain("settings.modelProvider.startPlan.heroMetric");
- expect(html).not.toContain("settings.modelProvider.startPlan.heroMetricUnit");
- expect(html).not.toContain("settings.modelProvider.startPlan.summaryDescription");
- expect(html).not.toContain("settings.modelProvider.startPlan.eligibleNewUser");
- expect(html).not.toContain("settings.modelProvider.models");
- expect(html).not.toContain("glm-4.7");
- expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
- expect(html).not.toContain("settings.modelProvider.codingPlan.login");
- expect(html).toContain("settings.modelProvider.startPlan.status.loginRequired");
- expect(html).not.toContain("settings.modelProvider.codingPlan.description.disconnected");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.personalTitle");
- expect(html).not.toContain(
- "settings.modelProvider.codingPlan.purchaseBanner.personalDescription",
- );
- expect(html).not.toContain("CN¥49.00+");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamTitle");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamDescription");
- expect(html).not.toContain("CN¥598.00+");
- expect(html).not.toContain("settings.modelProvider.codingPlan.productsLoading");
- expect(html).not.toContain("settings.modelProvider.baseUrl");
- expectConnectionApiFormatHidden(html);
- expect(html).not.toContain("settings.modelProvider.apiKeyPlaceholder");
- expect(html).not.toContain("settings.modelProvider.disableAction");
- expect(html).not.toContain("settings.modelProvider.addModel");
- });
- it("Z.ai Start 详情不显示体验套餐推广横幅", () => {
- primeStartPlanPreviewCacheForTest({
- planId: "zcode-v3-start-plan",
- name: "ZCode V3 Start Plan",
- entitlements: [
- {
- grantUnits: 5_000_000,
- meter: "model_usage",
- period: "daily",
- showName: "GLM-5.2",
- unitType: "token",
- },
- ],
- });
- const html = renderDetail({
- key: "coding-plan:account:zai-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: null,
- status: "disconnected",
- purchaseUrl: "https://z.ai/",
- statusActive: false,
- });
- expect(html).not.toContain("ZCode V3 Start Plan");
- expect(html).not.toContain("5 Million");
- expect(html).not.toContain("Daily quota · GLM-5.2 5M");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.personalTitle");
- expect(html).not.toContain("CN¥49.00+");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamTitle");
- expect(html).not.toContain("CN¥598.00+");
- });
- it("Z.ai Coding Plan 未连接时显示 Plan Card 且不显示 API Key 字段", () => {
- const html = renderDetail({
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: null,
- status: "disconnected",
- purchaseUrl: "https://z.ai/",
- statusActive: false,
- });
- expect(html).toContain("settings.modelProvider.planCard.codingPlan");
- expect(html).toContain("settings.modelProvider.codingPlan.status.disconnected");
- expect(html).toContain("settings.modelProvider.codingPlan.connect");
- expect(html).not.toContain("settings.modelProvider.codingPlan.dynamicUnsupportedTitle");
- expect(html).not.toContain("settings.modelProvider.codingPlan.productsLoading");
- expect(html).not.toContain("settings.modelProvider.codingPlan.zai.plan.lite.name");
- expect(html).not.toContain("settings.modelProvider.codingPlan.zai.plan.pro.name");
- expect(html).not.toContain("settings.modelProvider.codingPlan.zai.plan.max.name");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.personalTitle");
- expect(html).not.toContain(
- "settings.modelProvider.codingPlan.purchaseBanner.personalDescription",
- );
- expect(html).not.toContain("CN¥49.00+");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamTitle");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamDescription");
- expect(html).not.toContain("CN¥598.00+");
- expect(html).not.toContain("settings.modelProvider.codingPlan.useApiKeyProvider");
- expect(html).not.toContain("settings.modelProvider.apiKey");
- });
- it("BigModel Coding Plan 会按自己的 quota 权益解析为已购买", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- name: "BigModel - Coding Plan",
- }),
- ],
- entitledAccountProviderIds: new Set([
- BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- ]),
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan]: {
- snapshot: createEntitlementSnapshot(),
- loading: false,
- error: null,
- },
- },
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const bigmodelCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- );
- expect(bigmodelCodingPlan).toMatchObject({
- status: "purchased",
- statusActive: true,
- currentProductId: "pro",
- subscriptionBillingCycle: "monthly",
- subscriptionExpireTime: "2026-12-31T00:00:00.000Z",
- });
- });
- it("Coding Plan 已购买但 provider 禁用时导航状态点不点亮", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [
- createProvider({
- enabled: false,
- }),
- ],
- entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]),
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
- snapshot: createEntitlementSnapshot({
- provider: {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- },
- }),
- loading: false,
- error: null,
- },
- },
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const zaiCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- );
- expect(zaiCodingPlan).toMatchObject({
- status: "purchased",
- statusActive: false,
- });
- });
- it("quota 重置时间不显示在 Coding Plan 状态卡片", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- name: "BigModel - Coding Plan",
- }),
- ],
- entitledAccountProviderIds: new Set([
- BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- ]),
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan]: {
- snapshot: createEntitlementSnapshot({
- subscription: {
- identityType: "unknown",
- identityMasked: null,
- details: [
- {
- productId: "personal",
- productName: "GLM Coding Pro",
- purchaseTime: null,
- beginTime: null,
- renewTime: null,
- expireTime: null,
- },
- ],
- },
- quota: {
- level: "pro",
- limits: [
- {
- type: "TOKENS_LIMIT",
- unit: 3,
- number: 5,
- nextResetTime: Date.UTC(2026, 4, 26),
- usageDetails: [],
- },
- {
- type: "TOKENS_LIMIT",
- unit: 6,
- nextResetTime: Date.UTC(2026, 4, 27),
- usageDetails: [],
- },
- {
- type: "TIME_LIMIT",
- unit: 5,
- number: 1,
- nextResetTime: Date.UTC(2026, 4, 28),
- usageDetails: [],
- },
- ],
- },
- }),
- loading: false,
- error: null,
- },
- },
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const bigmodelCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- );
- expect(bigmodelCodingPlan).toMatchObject({
- status: "purchased",
- });
- expect(bigmodelCodingPlan).not.toHaveProperty("resetTimes");
- });
- it("API Key provider 已配置时不会让对应 Coding Plan 变成已连接", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - API Key",
- }),
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- name: "BigModel - API Key",
- }),
- ],
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const codingPlanItems = capturedNavigationItems.filter((item) => item.type === "codingPlan");
- expect(codingPlanItems?.map((item) => item.presetId)).toEqual([
- BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- ]);
- expect(codingPlanItems?.map((item) => item.status)).toEqual([
- "disconnected",
- "disconnected",
- "disconnected",
- "disconnected",
- ]);
- });
- it("未登录 Start/Coding 时仍允许保持 Coding Plan 选中项", () => {
- const apiKeyItem = {
- key: "preset:account:zai-start-plan",
- type: "preset" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- label: "Z.ai - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - API Key",
- }),
- displayName: "Z.ai - API Key",
- statusActive: true,
- };
- const startItem = {
- key: "coding-plan:account:zai-start-plan",
- type: "codingPlan" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: null,
- status: "disconnected" as const,
- planLevel: null,
- currentProductId: null,
- subscriptionBillingCycle: null,
- subscriptionRenewTime: null,
- subscriptionExpireTime: null,
- quotaLimits: [],
- purchaseUrl: "https://z.ai/",
- statusActive: false,
- };
- const selectedNodeKey = resolveSelectedFamilyModeNodeKey({
- selectedNavItem: startItem,
- selectableNavigationItems: [apiKeyItem, startItem],
- modelProviderFamilyModes: {
- zai: "oauth",
- },
- });
- expect(selectedNodeKey).toBeNull();
- });
- it("未登录加载时保留独立 Start 与 Coding,不显示 loading 占位", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [],
- modelProvidersLoading: true,
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const zaiPlanItems = capturedNavigationItems.filter(
- (item) =>
- (item.type === "codingPlan" &&
- (item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan ||
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan)) ||
- item.type === "codingPlanLoading",
- );
- expect(zaiPlanItems).toEqual([
- expect.objectContaining({
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- }),
- expect.objectContaining({
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- status: "checking",
- }),
- ]);
- });
- it("Coding 权益未返回时仍保留独立 Start", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- const setSelectedNodeKey = vi.fn();
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- apiKey: "jwt-token",
- }),
- ],
- entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]),
- selectedNodeKey: null,
- setSelectedNodeKey,
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const zaiPlanItems = capturedNavigationItems.filter(
- (item) =>
- (item.type === "codingPlan" &&
- (item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan ||
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan)) ||
- item.type === "codingPlanLoading",
- );
- expect(zaiPlanItems).toEqual([
- expect.objectContaining({
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- }),
- expect.objectContaining({
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- }),
- ]);
- expect(setSelectedNodeKey).not.toHaveBeenCalledWith("coding-plan:zai:loading");
- });
- it("未登录时保留个人 Coding Plan 与独立 Start Plan", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [],
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const zaiCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- );
- const zaiStartPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- );
- const bigmodelCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- );
- const bigmodelStartPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- );
- expect(zaiCodingPlan).toMatchObject({
- status: "disconnected",
- statusActive: false,
- });
- expect(zaiStartPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
- expect(bigmodelCodingPlan).toMatchObject({
- status: "disconnected",
- statusActive: false,
- });
- expect(bigmodelStartPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
- expect(
- capturedNavigationItems.some(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- ),
- ).toBe(true);
- expect(
- capturedNavigationItems.some(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- ),
- ).toBe(true);
- });
- it("Start 过期快照显示过期提示且隐藏余额和模型,即使旧 Account 仍 available", () => {
- const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan;
- const state = resolveCodingPlanEntitlementState({
- providerId,
- accountEntitled: true,
- modelProvidersLoading: false,
- entitlement: {
- loading: false,
- error: null,
- snapshot: createEntitlementSnapshot({
- unavailableReason: "no_plan",
- startPlanExpired: true,
- subscription: null,
- quota: null,
- remaining: null,
- }),
- },
- });
- expect(state.status).toBe("notPurchased");
- expect(state.statusLabelId).toBe("settings.modelProvider.startPlan.status.expired");
- const provider = createProvider({ id: providerId, models: ["expired-start-model"] });
- const html = renderDetail(
- {
- key: `coding-plan:${providerId}`,
- type: "codingPlan",
- presetId: providerId,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- providerName: "BigModel",
- label: "Start Plan",
- provider,
- ...state,
- statusActive: false,
- },
- { providerSettingsView: createProviderSettingsView(provider) },
- );
- expect(html).toContain("settings.modelProvider.startPlan.status.expired");
- expect(html).not.toContain("expired-start-model");
- expect(html).not.toContain("settings.modelProvider.startPlan.balance.title");
- });
- it("Z.ai Coding Plan 无付费权益时不复用 Start 免费态", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- apiKey: "jwt-token",
- }),
- ],
- entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]),
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
- snapshot: createEntitlementSnapshot({
- provider: {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- },
- remaining: null,
- subscription: null,
- quota: null,
- unavailableReason: "no_plan",
- }),
- loading: false,
- error: null,
- },
- },
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const zaiCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- );
- const zaiStartPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- );
- expect(zaiCodingPlan).toMatchObject({
- status: "notPurchased",
- statusActive: true,
- });
- expect(zaiStartPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
- });
- it("Z.ai 已登录且只有 Start 有权益时显示 Start 和个人 Coding Plan", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- apiKey: "zai-coding-plan-key",
- }),
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Coding Plan",
- apiKey: "zcode-jwt",
- }),
- ],
- entitledAccountProviderIds: new Set([
- BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- ]),
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
- snapshot: createEntitlementSnapshot({
- provider: {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- },
- remaining: null,
- subscription: null,
- quota: null,
- unavailableReason: "no_plan",
- }),
- loading: false,
- error: null,
- },
- [BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan]: {
- snapshot: createEntitlementSnapshot({
- provider: {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Coding Plan",
- },
- subscription: {
- identityType: "unknown",
- identityMasked: null,
- details: [
- {
- productId: "zcode-v3-start-plan",
- productName: "ZCode V3 Start Plan",
- purchaseTime: null,
- beginTime: null,
- billingCycle: "daily",
- renewTime: "2026-06-04T00:00:00.000Z",
- expireTime: "2026-06-08T00:00:00.000Z",
- },
- ],
- },
- quota: null,
- }),
- loading: false,
- error: null,
- },
- },
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const zaiCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- );
- const zaiStartPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- );
- expect(zaiCodingPlan).toMatchObject({
- status: "notPurchased",
- statusActive: true,
- });
- expect(zaiStartPlan).toMatchObject({
- status: "purchased",
- currentProductId: "zcode-v3-start-plan",
- statusActive: true,
- });
- });
- it("Z.ai 未登录且缺少 Coding Key 时仍显示独立 Start", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- apiKey: "",
- }),
- ],
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
- snapshot: createEntitlementSnapshot({
- provider: {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- },
- remaining: null,
- subscription: null,
- quota: null,
- unavailableReason: "no_plan",
- }),
- loading: false,
- error: null,
- },
- },
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const zaiCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- );
- const zaiStartPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- );
- expect(zaiCodingPlan).toMatchObject({
- status: "disconnected",
- planLevel: null,
- });
- expect(zaiStartPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
- });
- it("Z.ai Start 登录后入口互斥时回落到可见的 Z.ai plan", () => {
- const fallbackNodeKey = resolveFallbackModelProviderNodeKey({
- selectedNodeKey: "coding-plan:account:zai-start-plan",
- selectableNavigationItems: [
- {
- key: "preset:account:zai-start-plan",
- type: "preset",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- label: "Z.ai - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- }),
- displayName: "Z.ai - API Key",
- statusActive: true,
- },
- {
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- apiKey: "zai-coding-plan-key",
- }),
- status: "purchased",
- planLevel: "pro",
- currentProductId: "product-zai-pro-monthly",
- subscriptionBillingCycle: null,
- subscriptionRenewTime: null,
- subscriptionExpireTime: null,
- quotaLimits: [],
- purchaseUrl: "https://z.ai/manage-apikey/subscription",
- statusActive: true,
- },
- ],
- });
- expect(fallbackNodeKey).toBe("preset:account:zai-start-plan");
- });
- it("BigModel 登录后当前选中项不可见时回落到 BigModel Coding Plan", () => {
- const fallbackNodeKey = resolveFallbackModelProviderNodeKey({
- selectedNodeKey: "coding-plan:account:zai-individual-coding-plan",
- selectableNavigationItems: [
- {
- key: "preset:account:bigmodel-start-plan",
- type: "preset",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- label: "BigModel - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- }),
- displayName: "BigModel - API Key",
- statusActive: true,
- },
- {
- key: "coding-plan:account:bigmodel-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Coding Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- apiKey: "bigmodel-coding-plan-key",
- }),
- status: "purchased",
- planLevel: "pro",
- currentProductId: "product-bigmodel-pro-monthly",
- subscriptionBillingCycle: null,
- subscriptionRenewTime: null,
- subscriptionExpireTime: null,
- quotaLimits: [],
- purchaseUrl: "https://bigmodel.cn/",
- statusActive: true,
- },
- ],
- });
- expect(fallbackNodeKey).toBe("preset:account:bigmodel-start-plan");
- });
- it("首次进入 Model Providers 默认选中可见的 Z.ai Coding Plan", () => {
- const fallbackNodeKey = resolveFallbackModelProviderNodeKey({
- selectedNodeKey: null,
- selectableNavigationItems: [
- {
- key: "preset:account:zai-start-plan",
- type: "preset",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- label: "Z.ai - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- }),
- displayName: "Z.ai - API Key",
- statusActive: true,
- },
- {
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- apiKey: "zai-coding-plan-key",
- }),
- status: "purchased",
- planLevel: "pro",
- currentProductId: "product-zai-pro-monthly",
- subscriptionBillingCycle: null,
- subscriptionRenewTime: null,
- subscriptionExpireTime: null,
- quotaLimits: [],
- purchaseUrl: "https://z.ai/manage-apikey/subscription",
- statusActive: true,
- },
- ],
- });
- expect(fallbackNodeKey).toBe("preset:account:zai-start-plan");
- });
- it("首次进入 Model Providers Start 和个人 Coding 都有权益时仍选中 family 节点", () => {
- const fallbackNodeKey = resolveFallbackModelProviderNodeKey({
- selectedNodeKey: null,
- selectableNavigationItems: [
- {
- key: "preset:account:zai-start-plan",
- type: "preset",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- label: "Z.ai - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- }),
- displayName: "Z.ai - API Key",
- statusActive: true,
- },
- {
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- apiKey: "zai-coding-plan-key",
- }),
- status: "purchased",
- planLevel: "pro",
- currentProductId: "product-zai-pro-monthly",
- subscriptionBillingCycle: null,
- subscriptionRenewTime: null,
- subscriptionExpireTime: null,
- quotaLimits: [],
- purchaseUrl: "https://z.ai/manage-apikey/subscription",
- statusActive: true,
- },
- {
- key: "coding-plan:account:zai-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - 体验套餐",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- apiKey: "zcode-jwt",
- }),
- status: "purchased",
- planLevel: "Free",
- currentProductId: "zcode-v3-start-plan",
- subscriptionBillingCycle: null,
- subscriptionRenewTime: null,
- subscriptionExpireTime: null,
- quotaLimits: [],
- purchaseUrl: "https://z.ai/manage-apikey/subscription",
- statusActive: true,
- },
- ],
- });
- expect(fallbackNodeKey).toBe("preset:account:zai-start-plan");
- });
- it("首次进入 Model Providers 个人 Coding 不可用时默认选中第一个 Team Plan", () => {
- const teamPlanItemA = {
- key: "team:bigmodel:product-team-a",
- type: "teamPlan" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Team A",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- }),
- status: "purchased" as const,
- planLevel: "team",
- teamPlanName: "Team A",
- organizationId: "org-a",
- projectId: "proj-a",
- currentProductId: "product-team-a",
- subscriptionBillingCycle: null,
- subscriptionRenewTime: null,
- subscriptionExpireTime: null,
- quotaLimits: [],
- statusActive: true,
- };
- const teamPlanItemB = {
- ...teamPlanItemA,
- key: "team:bigmodel:product-team-b",
- label: "BigModel - Team B",
- teamPlanName: "Team B",
- organizationId: "org-b",
- projectId: "proj-b",
- currentProductId: "product-team-b",
- };
- const fallbackNodeKey = resolveFallbackModelProviderNodeKey({
- selectedNodeKey: null,
- selectableNavigationItems: [
- {
- key: "preset:account:bigmodel-start-plan",
- type: "preset",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- label: "BigModel - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- }),
- displayName: "BigModel - API Key",
- statusActive: true,
- },
- {
- key: "coding-plan:account:bigmodel-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Coding Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- }),
- status: "notPurchased",
- planLevel: null,
- currentProductId: null,
- subscriptionBillingCycle: null,
- subscriptionRenewTime: null,
- subscriptionExpireTime: null,
- quotaLimits: [],
- purchaseUrl: "https://bigmodel.cn/",
- statusActive: true,
- },
- teamPlanItemA,
- teamPlanItemB,
- ],
- });
- expect(fallbackNodeKey).toBe("preset:account:bigmodel-start-plan");
- });
- it("首次进入 Model Providers 没有套餐权益时默认选中 API Key", () => {
- const fallbackNodeKey = resolveFallbackModelProviderNodeKey({
- selectedNodeKey: null,
- selectableNavigationItems: [
- {
- key: "preset:account:zai-start-plan",
- type: "preset",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- label: "Z.ai - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- }),
- displayName: "Z.ai - API Key",
- statusActive: true,
- },
- {
- key: "coding-plan:account:zai-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - 体验套餐",
- providerName: "Z.ai",
- provider: null,
- status: "disconnected",
- planLevel: null,
- currentProductId: null,
- subscriptionBillingCycle: null,
- subscriptionRenewTime: null,
- subscriptionExpireTime: null,
- quotaLimits: [],
- purchaseUrl: "https://z.ai/manage-apikey/subscription",
- statusActive: false,
- },
- {
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: null,
- status: "disconnected",
- planLevel: null,
- currentProductId: null,
- subscriptionBillingCycle: null,
- subscriptionRenewTime: null,
- subscriptionExpireTime: null,
- quotaLimits: [],
- purchaseUrl: "https://z.ai/manage-apikey/subscription",
- statusActive: false,
- },
- ],
- });
- expect(fallbackNodeKey).toBe("preset:account:zai-start-plan");
- });
- it("Z.ai Coding Plan 不可见时首次进入默认选中 Z.ai Start Plan", () => {
- const fallbackNodeKey = resolveFallbackModelProviderNodeKey({
- selectedNodeKey: null,
- selectableNavigationItems: [
- {
- key: "preset:account:zai-start-plan",
- type: "preset",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- label: "Z.ai - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- }),
- displayName: "Z.ai - API Key",
- statusActive: true,
- },
- {
- key: "coding-plan:account:zai-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - 体验计划",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- apiKey: "zcode-jwt",
- }),
- status: "purchased",
- planLevel: "Free",
- currentProductId: "zcode-v3-start-plan",
- subscriptionBillingCycle: null,
- subscriptionRenewTime: null,
- subscriptionExpireTime: null,
- quotaLimits: [],
- purchaseUrl: "https://z.ai/manage-apikey/subscription",
- statusActive: true,
- },
- ],
- });
- expect(fallbackNodeKey).toBe("preset:account:zai-start-plan");
- });
- it("Z.ai Coding Plan 权益查询不可用时不误判为未开通或查询中", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [createProvider({ apiKey: "zai-coding-plan-key" })],
- entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]),
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
- snapshot: createEntitlementSnapshot({
- provider: {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- },
- unavailableReason: "not_configured",
- remaining: null,
- subscription: null,
- quota: null,
- }),
- loading: false,
- error: null,
- },
- },
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const zaiCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- );
- const zaiStartPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- );
- expect(zaiCodingPlan).toMatchObject({
- status: "unavailable",
- statusActive: true,
- });
- expect(zaiStartPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
- });
- it("Z.ai Coding Plan 缺少 apiKey 时旧失败快照刷新仍显示未连接", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [createProvider({ apiKey: "" })],
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
- snapshot: createEntitlementSnapshot({
- provider: {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- },
- unavailableReason: "not_configured",
- remaining: null,
- subscription: null,
- quota: null,
- }),
- loading: true,
- error: null,
- },
- },
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const zaiCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- );
- const zaiStartPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- );
- expect(zaiCodingPlan).toMatchObject({
- status: "disconnected",
- });
- expect(zaiStartPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
- });
- it("Account Overlay 已连接时不再受旧 Provider apiKey 空值影响", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [createProvider({ apiKey: "" })],
- entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]),
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
- snapshot: createEntitlementSnapshot({
- provider: {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- },
- unavailableReason: "no_plan",
- remaining: null,
- subscription: null,
- quota: null,
- }),
- loading: false,
- error: null,
- },
- },
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const zaiCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- );
- expect(zaiCodingPlan).toMatchObject({
- accountEntitled: true,
- status: "notPurchased",
- });
- });
- it("BigModel Account Overlay 已连接时也不要求 Renderer 持有 API Key", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- name: "BigModel - Coding Plan",
- apiKey: "",
- }),
- ],
- entitledAccountProviderIds: new Set([
- BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- ]),
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan]: {
- snapshot: createEntitlementSnapshot({
- provider: {
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- name: "BigModel - Coding Plan",
- },
- }),
- loading: false,
- error: null,
- },
- },
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const bigmodelCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- );
- expect(bigmodelCodingPlan).toMatchObject({
- accountEntitled: true,
- status: "purchased",
- });
- });
- it("Account Overlay 未连接时不再被旧 Provider apiKey 误判为已连接", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [createProvider({ apiKey: "legacy-key" })],
- entitledAccountProviderIds: new Set(),
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
- snapshot: createEntitlementSnapshot(),
- loading: false,
- error: null,
- },
- },
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const zaiCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- );
- expect(zaiCodingPlan).toMatchObject({
- accountEntitled: false,
- status: "disconnected",
- });
- });
- it("Account Overlay 首次发布前保持查询中而不读旧 Provider apiKey", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [createProvider({ apiKey: "legacy-key" })],
- entitledAccountProviderIds: new Set(),
- modelProvidersLoading: true,
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const zaiCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- );
- expect(zaiCodingPlan).toMatchObject({
- accountEntitled: false,
- status: "checking",
- });
- });
- it("Z.ai Coding Plan 有 apiKey 但服务端无付费套餐时仍显示付费入口", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [createProvider({ apiKey: "zai-coding-plan-key" })],
- entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]),
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
- snapshot: createEntitlementSnapshot({
- provider: {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- },
- unavailableReason: "no_plan",
- remaining: null,
- subscription: null,
- quota: null,
- }),
- loading: false,
- error: null,
- },
- },
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const zaiCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- );
- const zaiStartPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- );
- expect(zaiCodingPlan).toMatchObject({
- status: "notPurchased",
- statusActive: true,
- });
- expect(zaiStartPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
- });
- it("Z.ai Coding Plan 有订阅详情时优先显示已购买", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [createProvider({ apiKey: "zai-coding-plan-key" })],
- entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]),
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
- snapshot: createEntitlementSnapshot({
- provider: {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- },
- unavailableReason: "no_plan",
- remaining: null,
- subscription: {
- identityType: "unknown",
- identityMasked: null,
- details: [
- {
- productId: "product-zai-pro-monthly",
- productName: "GLM Coding Pro",
- purchaseTime: null,
- beginTime: null,
- billingCycle: "monthly",
- renewTime: "2026-07-10T00:00:00.000Z",
- expireTime: null,
- },
- ],
- },
- quota: null,
- }),
- loading: false,
- error: null,
- },
- },
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const zaiCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- );
- const zaiStartPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- );
- expect(zaiCodingPlan).toMatchObject({
- status: "purchased",
- planLevel: "GLM Coding Pro",
- currentProductId: "product-zai-pro-monthly",
- subscriptionRenewTime: "2026-07-10T00:00:00.000Z",
- statusActive: true,
- });
- expect(zaiStartPlan).toMatchObject({ type: "codingPlan", label: "Start Plan" });
- });
- it("Z.ai Start Plan 加载权益接口时连接方式仍显示 Start 入口", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [
- createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Coding Plan",
- apiKey: "zcode-jwt",
- }),
- ],
- entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan]),
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan]: {
- snapshot: createEntitlementSnapshot({
- provider: {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Coding Plan",
- },
- subscription: {
- identityType: "unknown",
- identityMasked: null,
- details: [
- {
- productId: "zcode-v3-start-plan",
- productName: "ZCode V3 Start Plan",
- purchaseTime: null,
- beginTime: null,
- billingCycle: "daily",
- renewTime: "2026-06-04T00:00:00.000Z",
- expireTime: "2026-06-08T00:00:00.000Z",
- },
- ],
- },
- quota: null,
- }),
- loading: true,
- error: null,
- },
- },
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const startPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" && item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- );
- const loadingItem = capturedNavigationItems.find((item) => item.type === "codingPlanLoading");
- expect(startPlan).toMatchObject({
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- });
- expect(loadingItem).toBeUndefined();
- });
- it("Z.ai Coding Plan token 失效时显示同步失败", () => {
- let capturedNavigationItems: ReturnType<typeof useModelProviderNavigation>["navigationItems"] =
- [];
- function Harness() {
- const { navigationItems } = useModelProviderNavigation({
- presetProviders: [],
- modelProviders: [createProvider({ apiKey: "zai-coding-plan-key" })],
- entitledAccountProviderIds: new Set([BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]),
- codingPlanEntitlements: {
- [BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan]: {
- snapshot: createEntitlementSnapshot({
- provider: {
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- name: "Z.ai - Coding Plan",
- },
- unavailableReason: "unavailable",
- remaining: null,
- subscription: null,
- quota: null,
- }),
- loading: false,
- error: null,
- },
- },
- selectedNodeKey: null,
- setSelectedNodeKey: vi.fn(),
- intl: {
- formatMessage: ({ id }: { id: string }) => id,
- } as never,
- });
- capturedNavigationItems = navigationItems;
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- const zaiCodingPlan = capturedNavigationItems.find(
- (item) =>
- item.type === "codingPlan" &&
- item.presetId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- );
- expect(zaiCodingPlan).toMatchObject({
- status: "unavailable",
- statusActive: true,
- });
- });
- it("Z.ai Coding Plan 未连接时在 Plan Card 右侧显示 Connect 入口", () => {
- const apiKeyItem = {
- key: "preset:account:zai-start-plan",
- type: "preset" as const,
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- label: "Z.ai - API Key",
- displayName: "Z.ai - API Key",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - API Key",
- }),
- statusActive: true,
- };
- const oauthItem = {
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({ apiKey: "", models: [] }),
- status: "disconnected",
- purchaseUrl: "https://z.ai/",
- statusActive: false,
- } as const;
- const html = renderDetail(oauthItem, {
- navigationItems: [oauthItem, apiKeyItem],
- onSelectNavItem: vi.fn(),
- });
- expect(html).toContain("settings.modelProvider.planCard.codingPlan");
- expect(html).toContain("settings.modelProvider.codingPlan.status.disconnected");
- expect(html).toContain("settings.modelProvider.codingPlan.connect");
- expect(html).not.toContain('data-testid="model-provider-enabled-switch"');
- expect(html).not.toContain("settings.modelProvider.codingPlan.productsLoading");
- expect(html).not.toContain("GLM Coding Lite");
- expect(html).not.toContain("GLM Coding Pro");
- expect(html).not.toContain("GLM Coding Max");
- expect(html).not.toContain("lucide-loader-circle");
- expect(html).not.toContain("settings.modelProvider.codingPlan.dynamicUnsupportedTitle");
- expect(html).not.toContain("settings.modelProvider.models");
- expect(html).not.toContain("settings.modelProvider.apiKeyPlaceholder");
- });
- it("Z.ai Coding Plan 连接等待时状态卡片显示 loading", () => {
- const html = renderDetail(
- {
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({ apiKey: "", models: [] }),
- status: "disconnected",
- purchaseUrl: "https://z.ai/",
- statusActive: false,
- },
- {
- presetSubscriptionProviderId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- },
- );
- expect(html).toContain("settings.modelProvider.codingPlan.status.checking");
- expect(html).toContain("lucide-loader-circle");
- expect(html).toContain("settings.modelProvider.codingPlan.connect");
- });
- it("Z.ai Start Plan 连接等待时不提前显示今日余额", () => {
- const html = renderDetail(
- {
- key: "coding-plan:account:zai-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- apiKey: "",
- models: [],
- }),
- status: "disconnected",
- purchaseUrl: "https://z.ai/",
- statusActive: false,
- },
- {
- presetSubscriptionProviderId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- },
- );
- expect(html).toContain("settings.modelProvider.codingPlan.status.checking");
- expect(html).toContain("lucide-loader-circle");
- expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
- expect(html).not.toContain("settings.modelProvider.startPlan.quotaSectionTitle");
- expect(html).not.toContain("settings.modelProvider.startPlan.balance.title");
- });
- it("Z.ai Coding Plan 权益查询中时状态卡片不空白", () => {
- const html = renderDetail({
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({ apiKey: "zai-coding-plan-key" }),
- status: "checking",
- planLevel: null,
- purchaseUrl: "https://z.ai/",
- statusActive: false,
- });
- expect(html).toContain("settings.modelProvider.codingPlan.status.checking");
- expect(html).toContain("lucide-loader-circle");
- expect(html).not.toContain("settings.modelProvider.codingPlan.manage");
- expect(html).not.toContain("settings.modelProvider.codingPlan.upgrade");
- });
- it("Z.ai Coding Plan 有 apiKey 但无静态商品时隐藏个人套餐横幅", () => {
- const html = renderDetail({
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({ apiKey: "zai-coding-plan-key" }),
- status: "notPurchased",
- purchaseUrl: "https://z.ai/",
- statusActive: false,
- });
- expect(html).toContain("settings.modelProvider.codingPlan.status.notPurchased");
- expect(html).not.toContain("settings.modelProvider.codingPlan.description.notPurchased");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.personalTitle");
- expect(html).not.toContain(
- "settings.modelProvider.codingPlan.purchaseBanner.personalDescription",
- );
- expect(html).not.toContain("CN¥49.00+");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamTitle");
- expect(html).not.toContain("CN¥598.00+");
- expect(html).not.toContain("settings.modelProvider.codingPlan.upgrade");
- expect(html).not.toContain("settings.modelProvider.codingPlan.productsLoading");
- expect(html).not.toContain("settings.modelProvider.models");
- expect(html).not.toContain("settings.modelProvider.apiKey");
- });
- it("Z.ai Coding Plan 入口价格跟随 Z.ai 商品币种", () => {
- expect(
- resolvePurchaseChoiceBannerPrice({
- providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- audience: "personal",
- products: [
- {
- productId: "zai-lite-month",
- productName: "GLM Coding Lite",
- productEquityList: [],
- priceCurrency: "USD",
- payAmount: 18,
- },
- ],
- }),
- ).toEqual({ kind: "price", price: 18, currency: "USD" });
- });
- it("个人套餐入口价格在全部售罄时显示售罄状态", () => {
- expect(
- resolvePurchaseChoiceBannerPrice({
- providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- audience: "personal",
- products: [
- {
- productId: "zai-lite-month",
- productName: "GLM Coding Lite",
- productEquityList: [],
- priceCurrency: "USD",
- payAmount: 18,
- soldOut: true,
- },
- {
- productId: "zai-pro-month",
- productName: "GLM Coding Pro",
- productEquityList: [],
- priceCurrency: "USD",
- payAmount: 88,
- soldOut: true,
- },
- ],
- }),
- ).toEqual({ kind: "soldOut" });
- });
- it("未登录个人套餐入口不前置显示售罄状态", () => {
- expect(
- resolvePurchaseChoiceBannerPrice({
- providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- audience: "personal",
- soldOutVisible: false,
- products: [
- {
- productId: "bigmodel-lite-month",
- productName: "GLM Coding Lite",
- productEquityList: [],
- priceCurrency: "CNY",
- payAmount: 49,
- soldOut: true,
- },
- ],
- }),
- ).toBeNull();
- });
- it("Z.ai Start Plan 入口价格读取付费 Coding Plan 商品源", () => {
- expect(
- resolvePurchaseChoiceBannerProductsProviderId(BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan),
- ).toBe(BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan);
- });
- it("BigModel Coding Plan 无静态商品时不补固定价格", () => {
- expect(
- resolvePurchaseChoiceBannerPrice({
- providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- audience: "personal",
- products: [],
- }),
- ).toBeNull();
- });
- it("BigModel 登录后团队入口按企业套餐分组显示标准版和高级版价格", () => {
- const groups = groupEnterpriseCodingPlanProductsByTier(
- [
- {
- productId: "team-pro-year",
- productName: "Pro",
- productEquityList: [],
- priceCurrency: "CNY",
- payAmount: 598,
- tier: "PRO",
- subscribeMode: "CONTINUOUS",
- subscribePeriod: "YEARLY",
- purchaseMethodName: "Auto renew",
- enterpriseProduct: {
- productId: "team-pro-year",
- tier: "PRO",
- subscribeMode: "CONTINUOUS",
- subscribePeriod: "YEARLY",
- payAmount: 598,
- },
- },
- {
- productId: "team-max-year",
- productName: "Max",
- productEquityList: [],
- priceCurrency: "CNY",
- payAmount: 1298,
- tier: "MAX",
- subscribeMode: "CONTINUOUS",
- subscribePeriod: "YEARLY",
- purchaseMethodName: "Auto renew",
- enterpriseProduct: {
- productId: "team-max-year",
- tier: "MAX",
- subscribeMode: "CONTINUOUS",
- subscribePeriod: "YEARLY",
- payAmount: 1298,
- },
- },
- ],
- {
- locale: "zh-CN",
- formatMessage: (id, fallback) => (zhCN as Record<string, string>)[id] ?? fallback,
- },
- );
- expect(groups.map((group) => group.title)).toEqual(["标准版", "高级版"]);
- expect(groups.map(resolveEnterprisePurchaseChoiceBannerPrice)).toEqual([
- { kind: "price", price: 598, currency: "CNY" },
- { kind: "price", price: 1298, currency: "CNY" },
- ]);
- });
- it("Z.ai Coding Plan 已购买时显示 Plan Card、用量卡和解绑入口", () => {
- // Bugfix:用例运行日在 8 月 10 日时,产品会把额度重置时间识别为“今天”并省略日期。
- // 只在同步渲染期间固定到同年的 1 月 15 日,稳定验证“日期 + 时间”展示,并保证断言失败时恢复时钟。
- const currentYear = 2026;
- vi.useFakeTimers();
- let html = "";
- try {
- vi.setSystemTime(new Date(currentYear, 0, 15, 12, 0));
- html = renderDetail({
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider(),
- status: "purchased",
- planLevel: "pro",
- subscriptionBillingCycle: "monthly",
- subscriptionRenewTime: `${currentYear}-07-10T00:00:00.000Z`,
- subscriptionExpireTime: "2026-12-31T00:00:00.000Z",
- purchaseUrl: "https://z.ai/",
- quotaLimits: [
- {
- type: "TOKENS_LIMIT",
- unit: 3,
- number: 5,
- usage: 250_000,
- remaining: 750_000,
- percentage: 25,
- nextResetTime: new Date(currentYear, 7, 10, 9, 30).getTime(),
- usageDetails: [
- {
- modelCode: "glm-coding-lite",
- displayName: "GLM CODING LITE",
- usage: 250_000,
- },
- ],
- },
- {
- type: "TOKENS_LIMIT",
- unit: 6,
- currentValue: 500_000,
- remaining: 500_000,
- percentage: 50,
- nextResetTime: new Date(currentYear, 7, 11).getTime(),
- usageDetails: [],
- },
- {
- type: "TIME_LIMIT",
- unit: 5,
- number: 1,
- usage: 1_000,
- remaining: 9_000,
- percentage: 10,
- nextResetTime: new Date(currentYear, 7, 12).getTime(),
- usageDetails: [
- {
- modelCode: "search-prime",
- displayName: "Search Prime",
- usage: 500,
- },
- {
- modelCode: "web-reader",
- displayName: "Web Reader",
- usage: 300,
- },
- { modelCode: "zr", displayName: "Zr", usage: 200 },
- ],
- },
- ],
- statusActive: true,
- });
- } finally {
- vi.useRealTimers();
- }
- expect(html).not.toContain("settings.modelProvider.codingPlan.status.purchased");
- expect(html).not.toContain("settings.modelProvider.enabledStatus");
- // 套餐卡不提供 Provider 启停;下方模型行仍应提供自己的启停控件。
- expect(html.split("settings.modelProvider.models")[0]).not.toContain(
- "settings.modelProvider.disableAction",
- );
- expect(html).toContain(">PRO<");
- expect(html).toContain("settings.usage.entitlementFiveHourUsage");
- expect(html).toContain("settings.usage.entitlementWeeklyUsage");
- expect(html).toContain("settings.usage.entitlementMonthlyMcpUsage");
- expect(html.match(/class="flex min-h-6 min-w-0 items-center gap-1"/g)).toHaveLength(3);
- expect(html).toContain("GLM Coding Lite");
- expect(html).not.toContain("GLM CODING LITE");
- expect(html).not.toContain("Search Prime");
- expect(html).not.toContain("Web Reader");
- expect(html).not.toContain(">Zr<");
- expect(html).toContain("75%");
- expect(html).toContain("50%");
- expect(html).toContain("90%");
- expect(html).toContain("Aug 10, 09:30");
- expect(html).toContain('text-ui-sm text-foreground-subtle">Aug 10, 09:30');
- expect(html).toContain("Aug 11");
- expect(html).toContain("Aug 12");
- expect(html.indexOf("75%")).toBeLessThan(html.indexOf("Aug 10, 09:30"));
- expect(html.indexOf("Aug 10, 09:30")).toBeLessThan(
- html.indexOf("background-color:var(--color-usage-chart-1)"),
- );
- expect(html).toContain("background-color:var(--color-usage-chart-1)");
- expect(html).toContain("background-color:var(--color-usage-chart-2)");
- expect(html).toContain("background-color:var(--color-usage-chart-3)");
- expect(html).not.toContain("settings.modelProvider.startPlan.balance.used");
- expect(html).not.toContain("settings.modelProvider.codingPlan.period.monthly");
- expect(html).toContain("settings.modelProvider.codingPlan.renewsAt");
- expect(html).toContain("settings.modelProvider.codingPlan.manage");
- expect(html).toContain("settings.modelProvider.codingPlan.upgrade");
- expect(html).toContain("Jul 10");
- expect(html).not.toContain(`Jul 10, ${currentYear}`);
- expect(html).not.toContain("settings.modelProvider.codingPlan.expiresAt");
- expect(html).toContain("settings.modelProvider.codingPlan.disconnect");
- expect(html).not.toContain("settings.modelProvider.codingPlan.resetItem");
- expect(html).toContain("settings.modelProvider.models");
- expect(html).not.toContain("settings.modelProvider.codingPlan.zai.plan.lite.name");
- expect(html).not.toContain("settings.modelProvider.connectionMode");
- expect(html).not.toContain("settings.modelProvider.apiKey");
- });
- it("Z.ai Coding Plan 已购买时升级入口不替换下方模型配置", () => {
- const html = renderDetail({
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider(),
- status: "purchased",
- planLevel: "PRO",
- currentProductId: "zai-coding-pro-monthly",
- purchaseUrl: "https://z.ai/",
- statusActive: true,
- });
- expect(html).toContain("settings.modelProvider.codingPlan.upgrade");
- expect(html).toContain("settings.modelProvider.models");
- expect(html).not.toContain("settings.modelProvider.codingPlan.description.notPurchased");
- });
- it("Z.ai Coding Plan 已购买时允许在官方模型列表添加模型", () => {
- const html = renderDetail({
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider(),
- status: "purchased",
- planLevel: "PRO",
- currentProductId: "zai-coding-pro-monthly",
- purchaseUrl: "https://z.ai/",
- statusActive: true,
- });
- expect(html).toContain("settings.modelProvider.models");
- expect(html).toContain("settings.modelProvider.addModel");
- });
- it("Z.ai Coding Plan 已购买时套餐标题保留模型名大小写", () => {
- const html = renderDetail({
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider(),
- status: "purchased",
- planLevel: "GLM CODING LITE",
- purchaseUrl: "https://z.ai/",
- quotaLimits: [],
- statusActive: true,
- });
- expect(html).toContain(">GLM Coding Lite<");
- expect(html).not.toContain("GLM CODING LITE");
- });
- it("Coding Plan 用量卡 percentage 按已用百分比反转成剩余百分比", () => {
- const html = renderDetail({
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider(),
- status: "purchased",
- planLevel: "pro",
- quotaLimits: [
- {
- type: "TOKENS_LIMIT",
- unit: 3,
- number: 5,
- usage: 100_000,
- remaining: 900_000,
- percentage: 1,
- usageDetails: [],
- },
- ],
- statusActive: true,
- });
- expect(html).toContain("99%");
- expect(html).not.toContain(">0%</");
- });
- it("Team Plan 复用 Coding Plan 用量卡展示 quota/limit 数据", () => {
- const html = renderDetail({
- key: "team:bigmodel:product-team:proj-team",
- type: "teamPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Team Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- }),
- status: "purchased",
- planLevel: "pro",
- teamPlanName: "Team A",
- organizationId: "org-team",
- projectId: "proj-team",
- currentProductId: "product-team",
- quotaLimits: [
- {
- type: "TOKENS_LIMIT",
- unit: 3,
- number: 5,
- usage: 100_000,
- remaining: 900_000,
- percentage: 10,
- usageDetails: [],
- },
- {
- type: "TIME_LIMIT",
- unit: 5,
- number: 1,
- usage: 1_000,
- remaining: 9_000,
- percentage: 10,
- usageDetails: [],
- },
- ],
- statusActive: true,
- });
- expect(html).toContain("settings.usage.entitlementFiveHourUsage");
- expect(html).toContain("settings.usage.entitlementMonthlyMcpUsage");
- expect(html).not.toContain("settings.modelProvider.startPlan.balance.title");
- });
- it("Team Plan 未分配时不显示获取失败 access banner", () => {
- const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan;
- const html = renderDetail({
- key: "team:bigmodel:product-team:org-team:proj-team",
- type: "teamPlan",
- presetId: providerId,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Team A",
- providerName: "BigModel",
- provider: createProvider({
- id: providerId,
- models: ["glm-team-visible"],
- }),
- status: "unavailable",
- statusLabelId: "settings.modelProvider.codingPlan.status.teamUnavailable",
- availabilityReason: "not-allocated",
- inactivePlanTitle: "Team A",
- planLevel: "Team A",
- teamPlanName: "Team A",
- organizationId: "org-team",
- projectId: "proj-team",
- currentProductId: "product-team",
- quotaLimits: [],
- statusActive: false,
- });
- expect(html).toContain("settings.modelProvider.codingPlan.status.teamUnavailable");
- expect(html).not.toContain("settings.modelProvider.codingPlan.status.unavailable");
- expect(html).not.toContain("settings.modelProvider.codingPlan.description.unavailable");
- expect(html).not.toContain("glm-team-visible");
- expectConnectionApiFormatHidden(html);
- expect(html).not.toContain("settings.modelProvider.baseUrl");
- });
- it("Team Plan 只从 Settings View 读取 Effective Provider,套餐状态不能覆盖模型列表", () => {
- const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan;
- const effectiveProvider = createProvider({
- id: providerId,
- models: ["effective-team-model"],
- endpoints: { baseURL: "https://effective.example.com/v1" },
- });
- const html = renderDetail(
- {
- key: "team:bigmodel:product-team:org-team:proj-team",
- type: "teamPlan",
- presetId: providerId,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Team A",
- providerName: "BigModel",
- provider: createProvider({
- id: providerId,
- models: ["stale-nav-model"],
- }),
- status: "checking",
- inactivePlanTitle: "Team A",
- planLevel: "Team A",
- teamPlanName: "Team A",
- organizationId: "org-team",
- projectId: "proj-team",
- currentProductId: "product-team",
- quotaLimits: [],
- statusActive: false,
- },
- { providerSettingsView: createProviderSettingsView(effectiveProvider) },
- );
- expect(html).toContain("effective-team-model");
- expect(html).not.toContain("stale-nav-model");
- expectConnectionApiFormatHidden(html);
- expect(html).not.toContain("settings.modelProvider.baseUrl");
- });
- it("Team Plan 明确无权益且缺少 Provider 时不显示模型配置异常", () => {
- const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan;
- const html = renderDetail(
- {
- key: "team:bigmodel:product-team:org-team:proj-team",
- type: "teamPlan",
- presetId: providerId,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Team A",
- providerName: "BigModel",
- provider: createProvider({
- id: providerId,
- models: ["stale-team-model"],
- }),
- status: "unavailable",
- availabilityReason: "not-allocated",
- teamPlanName: "Team A",
- organizationId: "org-team",
- projectId: "proj-team",
- currentProductId: "product-team",
- statusActive: false,
- },
- {
- providerSettingsView: {
- revision: 18,
- addableProviders: [],
- providerOrder: [],
- providers: [],
- },
- },
- );
- expect(html).not.toContain("settings.modelProvider.accountProviderConfigMissing");
- expect(html).not.toContain("stale-team-model");
- });
- it("Individual Coding Plan 在不可用状态仍显示 Effective 模型,但隐藏 Endpoint 与 API Schema", () => {
- const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan;
- const html = renderDetail({
- key: `coding-plan:${providerId}`,
- type: "codingPlan",
- presetId: providerId,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Coding Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: providerId,
- models: ["individual-visible-model"],
- }),
- status: "unavailable",
- statusActive: false,
- });
- expect(html).toContain("individual-visible-model");
- expectConnectionApiFormatHidden(html);
- expect(html).not.toContain("settings.modelProvider.baseUrl");
- });
- it.each(["disconnected", "notPurchased", "purchased", "checking", "unavailable"] as const)(
- "个人套餐 %s 按明确权益决定模型设置是否展示",
- (status) => {
- const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan;
- const html = renderDetail({
- key: `coding-plan:${providerId}`,
- type: "codingPlan",
- presetId: providerId,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel",
- providerName: "BigModel",
- provider: createProvider({ id: providerId, models: ["entitlement-model"] }),
- status,
- statusActive: status === "purchased",
- });
- expect(html.includes("entitlement-model")).toBe(
- status !== "notPurchased" && status !== "disconnected",
- );
- },
- );
- it("Team Plan 同步 loading 时不显示未分配管理员提示", () => {
- const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan;
- const html = renderDetail(
- {
- key: "team:bigmodel:product-team:org-team:proj-team",
- type: "teamPlan",
- presetId: providerId,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Team A",
- providerName: "BigModel",
- provider: createProvider({ id: providerId }),
- status: "unavailable",
- statusLabelId: "settings.modelProvider.codingPlan.status.teamUnavailable",
- teamPlanAvailabilityReason: "not-allocated",
- inactivePlanTitle: "Team A",
- planLevel: "Team A",
- teamPlanName: "Team A",
- organizationId: "org-team",
- projectId: "proj-team",
- currentProductId: "product-team",
- quotaLimits: [],
- statusActive: false,
- },
- { codingPlanStatusSyncProviderId: providerId },
- );
- expect(html).toContain("settings.modelProvider.codingPlan.status.checking");
- expect(html).not.toContain("settings.modelProvider.codingPlan.status.teamUnavailable");
- });
- it("Team Plan 有效订阅在 quota 缺失时仍保持已启用", () => {
- const item = {
- key: "team:bigmodel:product-team:proj-team",
- type: "teamPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Team A",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- }),
- status: "purchased",
- statusLabelId: "settings.modelProvider.codingPlan.status.teamUnavailable",
- availabilityReason: "not-allocated",
- planLevel: "PRO",
- teamPlanName: "Team A",
- organizationId: "org-team",
- projectId: "proj-team",
- currentProductId: "product-team",
- quotaLimits: [],
- statusActive: true,
- } as const;
- const resolved = resolveTeamScopedPlanNavItem(item, {
- loading: false,
- error: null,
- snapshot: createEntitlementSnapshot({
- subscription: {
- identityType: "unknown",
- identityMasked: null,
- details: [
- {
- productId: "product-team",
- productName: "团队套餐高级版",
- purchaseTime: null,
- beginTime: null,
- billingCycle: "quarterly",
- renewTime: "2026-08-01T00:00:00.000Z",
- expireTime: null,
- },
- ],
- },
- quota: null,
- }),
- refresh: vi.fn(),
- } as never);
- expect(resolved.statusActive).toBe(true);
- expect(resolved.planLevel).toBe("Team A");
- expect(resolved.currentProductId).toBe("product-team");
- expect(resolved.subscriptionBillingCycle).toBeNull();
- expect(resolved.subscriptionRenewTime).toBeNull();
- expect(resolved.teamPlanName).toBe("Team A");
- expect(resolved.statusLabelId).toBeUndefined();
- expect(resolved.availabilityReason).toBeUndefined();
- });
- it("Team Plan 明确无订阅时不继续显示已启用或个人续费日期", () => {
- const item = {
- key: "team:bigmodel:product-team:org-team:proj-team",
- type: "teamPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - GY的组织",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- }),
- status: "purchased",
- planLevel: "PRO",
- teamPlanName: "GY的组织",
- organizationId: "org-team",
- projectId: "proj-team",
- currentProductId: "product-team",
- subscriptionRenewTime: "2026-09-15T00:00:00.000Z",
- subscriptionBillingCycle: "monthly",
- quotaLimits: [],
- statusActive: true,
- } as const;
- const resolved = resolveTeamScopedPlanNavItem(item, {
- loading: false,
- error: null,
- snapshot: createEntitlementSnapshot({
- context: {
- scope: "team",
- organizationId: "org-team",
- projectId: "proj-team",
- productId: "product-team",
- displayName: "GY的组织",
- },
- remaining: null,
- quota: null,
- subscription: null,
- unavailableReason: "no_plan",
- }),
- refresh: vi.fn(),
- } as never);
- expect(resolved.status).toBe("unavailable");
- expect(resolved.statusActive).toBe(false);
- expect(resolved.statusLabelId).toBe("settings.modelProvider.codingPlan.status.teamUnavailable");
- expect(resolved.subscriptionRenewTime).toBeNull();
- expect(resolved.subscriptionBillingCycle).toBeNull();
- });
- it.each(["expired", "unassigned"] as const)("团队明确 %s 不显示查询失败或登录重试", (reason) => {
- const item = {
- key: "team:bigmodel:product:org:project",
- type: "teamPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "团队",
- providerName: "BigModel",
- teamPlanName: "团队",
- organizationId: "org",
- projectId: "project",
- currentProductId: "product",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
- models: ["expired-hidden-model"],
- }),
- status: "unavailable",
- statusActive: false,
- availabilityReason: "credential-unavailable",
- statusMessage: "旧 Key 错误",
- } as const;
- expect(resolveTeamPlanInspectionAccess(item)).toEqual({
- type: "zhipu-account",
- family: "bigmodel",
- planKind: "team-coding-plan",
- productId: "product",
- organizationId: "org",
- projectId: "project",
- });
- expect(resolveTeamPlanInspectionAccess({ ...item, projectId: "" })).toBeUndefined();
- const resolved = resolveTeamScopedPlanNavItem(item, {
- loading: false,
- error: null,
- refresh: vi.fn(),
- snapshot: {
- ...createEntitlementSnapshot(),
- subscription: null,
- unavailableReason: "no_plan",
- teamPlanUnavailableReason: reason,
- },
- } as never);
- const label =
- reason === "expired"
- ? "settings.modelProvider.codingPlan.status.teamExpired"
- : "settings.modelProvider.codingPlan.status.teamUnavailable";
- expect(resolved.statusLabelId).toBe(label);
- const html = renderDetail(resolved, { onRetryCodingPlan: vi.fn() });
- expect(html).toContain(label);
- expect(html).not.toContain("旧 Key 错误");
- expect(html).not.toContain("expired-hidden-model");
- expect(html).not.toContain("common.retry");
- expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
- expect(html).not.toContain("settings.modelProvider.codingPlan.description.unavailable");
- });
- it("Team Plan quota 正在刷新时显示 checking,而不是误报未分配", () => {
- const item = {
- key: "team:bigmodel:product-team:org-team:proj-team",
- type: "teamPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Team A",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
- }),
- status: "unavailable",
- statusLabelId: "settings.modelProvider.codingPlan.status.teamUnavailable",
- planLevel: "Team A",
- teamPlanName: "Team A",
- organizationId: "org-team",
- projectId: "proj-team",
- currentProductId: "product-team",
- quotaLimits: [],
- statusActive: false,
- } as const;
- const resolved = resolveTeamScopedPlanNavItem(item, {
- loading: true,
- error: null,
- snapshot: null,
- refresh: vi.fn(),
- } as never);
- expect(resolved.status).toBe("checking");
- expect(resolved.statusLabelId).toBeUndefined();
- expect(resolved.statusActive).toBe(false);
- });
- it("Team Plan quota 查询报错时显示通用获取失败,而不是误报未分配", () => {
- const item = {
- key: "team:bigmodel:product-team:org-team:proj-team",
- type: "teamPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Team A",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
- }),
- status: "unavailable",
- statusLabelId: "settings.modelProvider.codingPlan.status.teamUnavailable",
- planLevel: "Team A",
- teamPlanName: "Team A",
- organizationId: "org-team",
- projectId: "proj-team",
- currentProductId: "product-team",
- quotaLimits: [],
- statusActive: false,
- } as const;
- const resolved = resolveTeamScopedPlanNavItem(item, {
- loading: false,
- error: new Error("network failed"),
- snapshot: null,
- refresh: vi.fn(),
- } as never);
- expect(resolved.status).toBe("unavailable");
- expect(resolved.statusLabelId).toBeUndefined();
- expect(resolved.statusActive).toBe(false);
- });
- it("Coding Plan 用量卡只展示接口返回且可识别的额度项", () => {
- const html = renderDetail({
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider(),
- status: "purchased",
- planLevel: "pro",
- quotaLimits: [
- {
- type: "TOKENS_LIMIT",
- unit: 3,
- number: 5,
- usage: 100_000,
- remaining: 900_000,
- percentage: 10,
- usageDetails: [],
- },
- {
- type: "TOKENS_LIMIT",
- unit: 6,
- usage: 200_000,
- remaining: 800_000,
- percentage: 20,
- usageDetails: [],
- },
- ],
- statusActive: true,
- });
- expect(html).toContain("settings.usage.entitlementFiveHourUsage");
- expect(html).toContain("settings.usage.entitlementWeeklyUsage");
- expect(html).not.toContain("settings.usage.entitlementMonthlyMcpUsage");
- expect(html).toContain("90%");
- expect(html).toContain("80%");
- expect(html).not.toContain("background-color:var(--color-usage-chart-3)");
- });
- it("Team Plan 非标准额度项也会展示用量卡", () => {
- const html = renderDetail({
- key: "team:bigmodel:product-team-pro",
- type: "teamPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Pro Plan",
- providerName: "BigModel",
- teamPlanName: "Pro",
- organizationId: "org-team-a",
- projectId: "proj-team-a",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- }),
- status: "purchased",
- planLevel: "Pro",
- quotaLimits: [
- {
- type: "team_model_usage",
- number: 2_000_000,
- remaining: 1_500_000,
- usage: 500_000,
- usageDetails: [{ modelCode: "glm-5.2", displayName: "GLM-5.2", usage: 500_000 }],
- },
- ],
- statusActive: true,
- });
- expect(html).toContain("settings.modelProvider.planCard.usage.totalTokens");
- expect(html).toContain("GLM-5.2");
- expect(html).toContain("75%");
- expect(html).toContain("background-color:var(--color-usage-chart-1)");
- });
- it("Z.ai Coding Plan Upgrade 等待 OAuth 时显示 loading", () => {
- const html = renderDetail(
- {
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider(),
- status: "purchased",
- planLevel: "Start",
- currentProductId: "zai-start-free-monthly",
- purchaseUrl: "https://z.ai/",
- statusActive: true,
- },
- {
- presetSubscriptionProviderId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- },
- );
- expect(html).toContain("settings.modelProvider.codingPlan.upgrade");
- expect(html).toContain("lucide-loader-circle");
- });
- it("Coding Plan 已开通但套餐详情为空时状态卡片不空白", () => {
- const html = renderDetail({
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider(),
- status: "purchased",
- planLevel: null,
- subscriptionRenewTime: null,
- subscriptionExpireTime: null,
- statusActive: true,
- });
- expect(html).not.toContain("settings.modelProvider.codingPlan.status.purchased");
- expect(html).toContain("settings.modelProvider.codingPlan.upgrade");
- expect(html).not.toContain("settings.modelProvider.codingPlan.manage");
- });
- it("系统关闭的 Coding Plan 状态卡片不显示启用状态或开关", () => {
- const html = renderDetail({
- key: "coding-plan:account:zai-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({
- enabled: false,
- systemDisabledReason: "coding_plan_auth_failed",
- }),
- status: "purchased",
- planLevel: "pro",
- purchaseUrl: "https://z.ai/",
- statusActive: false,
- });
- expect(html).not.toContain("settings.modelProvider.disabledStatus");
- expect(html).not.toContain("settings.modelProvider.enableAction");
- expect(html.split("settings.modelProvider.models")[0]).not.toContain(
- "settings.modelProvider.disableAction",
- );
- });
- it("用户关闭的 Start Plan 未连接卡片不显示启用开关", () => {
- const html = renderDetail({
- key: "coding-plan:account:zai-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Coding Plan",
- apiKey: "",
- enabled: false,
- systemDisabledReason: undefined,
- }),
- status: "disconnected",
- purchaseUrl: "https://z.ai/",
- statusActive: false,
- });
- expect(html).not.toContain("settings.modelProvider.enableAction");
- });
- it("系统关闭的 Start Plan 未连接卡片不显示启用开关", () => {
- const html = renderDetail({
- key: "coding-plan:account:zai-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Coding Plan",
- apiKey: "",
- enabled: false,
- systemDisabledReason: "coding_plan_not_authenticated",
- }),
- status: "disconnected",
- purchaseUrl: "https://z.ai/",
- statusActive: false,
- });
- expect(html).not.toContain("settings.modelProvider.enableAction");
- expect(html).not.toContain("settings.modelProvider.disableAction");
- });
- it("Z.ai Start Plan 状态卡片隐藏续期时间且不展示管理和解绑入口", () => {
- vi.useFakeTimers();
- try {
- vi.setSystemTime(new Date(2026, 6, 10, 12, 0));
- const html = renderDetail({
- key: "coding-plan:account:zai-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Coding Plan",
- }),
- status: "purchased",
- planLevel: "Start",
- subscriptionRenewTime: new Date(2026, 6, 10, 0, 23).toISOString(),
- subscriptionExpireTime: new Date(2026, 6, 10, 23, 59).toISOString(),
- purchaseUrl: "https://z.ai/",
- statusActive: true,
- });
- expect(html.match(/settings\.modelProvider\.planCard\.startPlan/g)?.length).toBe(1);
- expect(html).not.toContain("settings.modelProvider.enabledStatus");
- expect(html.split("settings.modelProvider.models")[0]).not.toContain(
- "settings.modelProvider.disableAction",
- );
- expect(html).not.toContain("settings.modelProvider.codingPlan.start.freeBadge");
- expect(html).toContain("settings.modelProvider.startPlan.expiresAt");
- expect(html).toContain("Jul 10");
- expect(html).not.toContain("settings.modelProvider.codingPlan.renewsAt");
- expect(html).not.toContain("Jul 10 00:23");
- expect(html).not.toContain("Today 00:23");
- expect(html).not.toContain("settings.modelProvider.codingPlan.title");
- // 语义变更:体验套餐卡片不再提供「管理」「解绑」操作,只保留升级 Coding Plan 入口。
- expect(html).not.toContain("settings.modelProvider.codingPlan.manage");
- expect(html).not.toContain("settings.modelProvider.codingPlan.disconnect");
- expect(html).toContain("settings.modelProvider.codingPlan.upgrade");
- expect(html).not.toContain("settings.modelProvider.baseUrl");
- expectConnectionApiFormatHidden(html);
- expect(html).not.toContain("settings.modelProvider.apiKey");
- expect(html).not.toContain("settings.modelProvider.codingPlan.productsLoading");
- expect(html).not.toContain("settings.modelProvider.startPlan.summaryTitle");
- expect(html).not.toContain("settings.modelProvider.startPlan.heroMetric");
- expect(html).not.toContain("settings.modelProvider.startPlan.summaryDescription");
- } finally {
- vi.useRealTimers();
- }
- });
- it("Z.ai Start Plan 状态卡片只显示过期日期", () => {
- vi.useFakeTimers();
- try {
- vi.setSystemTime(new Date(2026, 5, 3, 12, 0));
- const html = renderDetail({
- key: "coding-plan:account:zai-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Coding Plan",
- }),
- status: "purchased",
- planLevel: "Start",
- subscriptionRenewTime: new Date(2026, 5, 8, 0, 23).toISOString(),
- subscriptionExpireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
- purchaseUrl: "https://z.ai/",
- statusActive: true,
- });
- expect(html).toContain("settings.modelProvider.startPlan.expiresAt");
- expect(html).toContain("Jun 8");
- expect(html).not.toContain("settings.modelProvider.codingPlan.renewsAt");
- expect(html).not.toContain("Jun 8 00:23");
- expect(html).not.toContain("Jun 8, 00:23");
- expect(html).not.toContain("Jun 8 23:59");
- } finally {
- vi.useRealTimers();
- }
- });
- it("Z.ai Start Plan 显示余额卡片", () => {
- const html = renderDetail({
- key: "coding-plan:account:zai-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Coding Plan",
- }),
- status: "purchased",
- planLevel: "Start",
- subscriptionRenewTime: new Date(2026, 5, 8, 23, 2).toISOString(),
- subscriptionExpireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
- // 生产数据形态:purchased 快照必带 active 套餐详情,额度桶带 plan_id。
- subscriptionDetails: [
- {
- productId: "zcode-v3-start-plan",
- productName: "ZCode V3 Start Plan",
- purchaseTime: null,
- beginTime: null,
- billingCycle: "daily",
- renewTime: null,
- expireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
- },
- ],
- quotaLimits: [
- {
- type: "ent_zcode_v3_glm_52",
- planId: "zcode-v3-start-plan",
- number: 3_000_000,
- usage: 500_000,
- remaining: 2_500_000,
- nextResetTime: new Date(2026, 5, 8, 23, 2).getTime(),
- usageDetails: [{ modelCode: "glm-5.2", displayName: "GLM-5.2", usage: 500_000 }],
- },
- {
- type: "ent_zcode_v3_glm_5turbo",
- planId: "zcode-v3-start-plan",
- number: 1_000_000,
- usage: 0,
- remaining: 1_000_000,
- nextResetTime: new Date(2026, 5, 8, 23, 2).getTime(),
- usageDetails: [
- {
- modelCode: "glm-5-turbo",
- displayName: "GLM-5-Turbo",
- usage: 0,
- },
- ],
- },
- {
- type: "ent_zcode_v3_glm_coding_lite",
- planId: "zcode-v3-start-plan",
- number: 2_000_000,
- usage: 0,
- remaining: 2_000_000,
- nextResetTime: new Date(2026, 5, 8, 23, 2).getTime(),
- usageDetails: [
- {
- modelCode: "glm-coding-lite",
- displayName: "GLM CODING LITE",
- usage: 0,
- },
- ],
- },
- ],
- purchaseUrl: "https://z.ai/",
- statusActive: true,
- });
- expect(html).toContain("settings.modelProvider.startPlan.balance.title");
- // 体验套餐用量卡片不展示「管理」「解绑」操作,只保留升级 Coding Plan 入口。
- expect(html).not.toContain("settings.modelProvider.codingPlan.manage");
- expect(html).not.toContain("settings.modelProvider.codingPlan.disconnect");
- expect(html).toContain("settings.modelProvider.codingPlan.upgrade");
- // 多卡路径下套餐到期时间只在 StartPlanStatusMeta 渲染一次;
- // 余额卡不再重复展示套餐级 expireTime。
- expect(html.match(/settings\.modelProvider\.startPlan\.expiresAt/g)?.length).toBe(1);
- expect(html).not.toContain("settings.modelProvider.startPlan.balance.remaining");
- expect(html).toContain("GLM-5.2");
- expect(html).toContain("GLM-5-Turbo");
- expect(html).toContain("GLM Coding Lite");
- expect(html).not.toContain("GLM CODING LITE");
- expect(html.indexOf("GLM-5.2")).toBeLessThan(html.indexOf("GLM-5-Turbo"));
- expect(html).not.toContain("GLM-5Turbo");
- expect(html).toContain("83%");
- // 桶刷新时间非当日仅展示日期(Jun 8),与 Coding Plan 重置时间格式对齐。
- expect(html).not.toContain("23:02");
- expect(html).toContain("2,500,000 / 3,000,000");
- expect(html).toContain("1,000,000 / 1,000,000");
- expect(html).not.toContain("2.5M / 3M");
- expect(html).not.toContain("Used 500K");
- });
- it("Start Plan 按服务端顺序展示多个套餐并按 plan id 隔离额度桶", () => {
- const html = renderToStaticMarkup(
- createElement(CodingPlanStatusPanel, {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- providerName: "Z.ai",
- status: "purchased",
- planLevel: "Welcome Plan",
- subscriptionDetails: [
- {
- productId: "plan-welcome",
- productName: "Welcome Plan",
- purchaseTime: null,
- beginTime: null,
- billingCycle: "daily",
- renewTime: null,
- expireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
- },
- {
- productId: "plan-bonus",
- productName: "Bonus Plan",
- purchaseTime: null,
- beginTime: null,
- billingCycle: "daily",
- renewTime: null,
- expireTime: new Date(2026, 5, 15, 23, 59).toISOString(),
- entitlements: [
- {
- entitlementId: "bonus-glm-5-turbo",
- showName: "GLM-5-Turbo",
- effectiveTime: "2096-08-28T07:00:00.000Z",
- },
- ],
- },
- ],
- quotaLimits: [
- {
- type: "welcome-glm-52",
- planId: "plan-welcome",
- number: 3_000_000,
- remaining: 2_500_000,
- nextResetTime: new Date(2026, 5, 8, 10, 11).getTime(),
- usageDetails: [{ modelCode: "glm-5.2", displayName: "GLM-5.2", usage: 500_000 }],
- },
- {
- type: "bonus-glm-5-turbo",
- planId: "plan-bonus",
- number: 1_000_000,
- remaining: 750_000,
- nextResetTime: new Date(2026, 5, 15, 12, 22).getTime(),
- usageDetails: [
- {
- modelCode: "glm-5-turbo",
- displayName: "GLM-5-Turbo",
- usage: 250_000,
- },
- ],
- },
- ],
- }),
- );
- expect(html.indexOf("Welcome Plan")).toBeLessThan(html.indexOf("Bonus Plan"));
- expect(html).toContain("Jun 8");
- expect(html).toContain("Jun 15");
- // 桶刷新时间与 Coding Plan 对齐:非当日仅展示日期,不携带小时分钟。
- expect(html).not.toContain("10:11");
- expect(html).not.toContain("12:22");
- expect(html).toContain("GLM-5.2");
- expect(html).toContain("GLM-5-Turbo");
- const welcomeIndex = html.indexOf("Welcome Plan");
- const bonusIndex = html.indexOf("Bonus Plan");
- expect(html.slice(welcomeIndex, bonusIndex)).toContain("GLM-5.2");
- expect(html.slice(welcomeIndex, bonusIndex)).not.toContain("GLM-5-Turbo");
- expect(html.slice(bonusIndex)).toContain("GLM-5-Turbo");
- expect(html.slice(bonusIndex)).toContain("settings.modelProvider.startPlan.pendingUntil");
- expect(html.slice(bonusIndex)).toContain('class="whitespace-nowrap text-success"');
- expect(html.slice(bonusIndex)).toContain("settings.modelProvider.startPlan.expiresAt");
- expect(html.slice(bonusIndex)).toContain(">·</span>");
- });
- it("Start Plan 只为尚未生效的 entitlement 展示最早生效时间", () => {
- const now = Date.parse("2026-08-27T00:00:00.000Z");
- expect(
- resolvePendingStartPlanEffectiveTime(
- [
- {
- entitlementId: "immediate",
- effectiveTime: "1970-01-01T00:00:00.000Z",
- },
- { entitlementId: "past", effectiveTime: "2026-08-26T00:00:00.000Z" },
- { entitlementId: "later", effectiveTime: "2026-08-29T00:00:00.000Z" },
- {
- entitlementId: "earlier",
- effectiveTime: "2026-08-28T00:00:00.000Z",
- },
- ],
- now,
- ),
- ).toBe("2026-08-28T00:00:00.000Z");
- expect(
- resolvePendingStartPlanEffectiveTime(
- [
- {
- entitlementId: "immediate",
- effectiveTime: "1970-01-01T00:00:00.000Z",
- },
- ],
- now,
- ),
- ).toBeNull();
- });
- it("Start Plan 刷新完成只认当前 entitlement 对应的额度桶", () => {
- const entitlements = [
- {
- entitlementId: "ent-weekend-glm-53-flash",
- effectiveTime: "2026-09-01T12:00:00.000Z",
- },
- ];
- expect(
- hasStartPlanEntitlementQuota(entitlements, [
- {
- type: "ent-old-glm-52",
- planId: "weekend-build",
- number: 1,
- remaining: 1,
- usageDetails: [],
- },
- ]),
- ).toBe(false);
- expect(
- hasStartPlanEntitlementQuota(entitlements, [
- {
- type: "ent-weekend-glm-53-flash",
- planId: "weekend-build",
- number: 1,
- remaining: 1,
- usageDetails: [],
- },
- ]),
- ).toBe(true);
- });
- it("Start Plan 待生效元信息明确表达尚未生效", () => {
- const now = new Date(2026, 8, 1, 10, 0).getTime();
- const todayEffectiveTime = new Date(2026, 8, 1, 22, 0).toISOString();
- const tomorrowEffectiveTime = new Date(2026, 8, 2, 22, 0).toISOString();
- const laterEffectiveTime = new Date(2026, 8, 4, 22, 0).toISOString();
- expect(zhCN["settings.modelProvider.startPlan.pendingUntil"]).toBe("待生效 {date}");
- expect(enUS["settings.modelProvider.startPlan.pendingUntil"]).toBe("Pending {date}");
- expect(formatStartPlanEffectiveDate(todayEffectiveTime, "zh-CN", now)).toBe("今天 22:00");
- expect(formatStartPlanEffectiveDate(todayEffectiveTime, "en-US", now)).toBe("Today 22:00");
- expect(formatStartPlanEffectiveDate(tomorrowEffectiveTime, "zh-CN", now)).toBe("明天 22:00");
- expect(formatStartPlanEffectiveDate(tomorrowEffectiveTime, "en-US", now)).toBe(
- "Tomorrow 22:00",
- );
- expect(formatStartPlanEffectiveDate(laterEffectiveTime, "zh-CN", now)).toBe("9月4日 22:00");
- expect(formatStartPlanEffectiveDate(laterEffectiveTime, "en-US", now)).toBe("Sep 4, 22:00");
- expect(formatStartPlanExpireDate(laterEffectiveTime, "zh-CN", now)).toBe("9月4日 22:00");
- expect(formatStartPlanExpireDate(laterEffectiveTime, "en-US", now)).toBe("Sep 4, 22:00");
- });
- it("Start Plan 余额卡片不从剩余量反推已用量", () => {
- const html = renderDetail({
- key: "coding-plan:account:zai-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- oauthProviderId: ZAI_PROVIDER_ID,
- label: "Z.ai - Coding Plan",
- providerName: "Z.ai",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- name: "Z.ai - Coding Plan",
- }),
- status: "purchased",
- planLevel: "Start",
- subscriptionExpireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
- // 生产数据形态:purchased 快照必带 active 套餐详情,额度桶带 plan_id。
- subscriptionDetails: [
- {
- productId: "zcode-v3-start-plan",
- productName: "ZCode V3 Start Plan",
- purchaseTime: null,
- beginTime: null,
- billingCycle: "daily",
- renewTime: null,
- expireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
- },
- ],
- quotaLimits: [
- {
- type: "ent_zcode_v3_glm_52",
- planId: "zcode-v3-start-plan",
- number: 3_000_000,
- remaining: 2_734_000,
- usageDetails: [{ modelCode: "glm-5.2", displayName: "GLM-5.2", usage: 0 }],
- },
- ],
- purchaseUrl: "https://z.ai/",
- statusActive: true,
- });
- expect(html).toContain("2,734,000 / 3,000,000");
- expect(html).not.toContain("2.7M");
- expect(html).not.toContain("Used 266K");
- });
- it("BigModel Start Plan 按余额接口顺序和 show_name 显示余额卡片", () => {
- const html = renderDetail({
- key: "coding-plan:account:bigmodel-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel- Coding Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- name: "BigModel- Coding Plan",
- }),
- status: "purchased",
- planLevel: "Start",
- subscriptionExpireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
- subscriptionDetails: [
- {
- productId: "bigmodel-start",
- productName: "Start",
- purchaseTime: null,
- beginTime: null,
- billingCycle: "daily",
- renewTime: null,
- expireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
- },
- ],
- quotaLimits: [
- {
- type: "ent_bigmodel_glm_52",
- planId: "bigmodel-start",
- number: 3_000_000,
- usage: 0,
- remaining: 3_000_000,
- usageDetails: [{ modelCode: "glm-5.2", displayName: "GLM-5.2", usage: 0 }],
- },
- {
- type: "ent_bigmodel_glm_5turbo",
- planId: "bigmodel-start",
- number: 1_000_000,
- usage: 0,
- remaining: 1_000_000,
- usageDetails: [
- {
- modelCode: "glm-5-turbo",
- displayName: "GLM-5-Turbo",
- usage: 0,
- },
- ],
- },
- ],
- purchaseUrl: "https://bigmodel.cn/",
- statusActive: true,
- });
- expect(html).toContain("GLM-5.2");
- expect(html).toContain("GLM-5-Turbo");
- expect(html.indexOf("GLM-5.2")).toBeLessThan(html.indexOf("GLM-5-Turbo"));
- expect(html).not.toContain("GLM-5Turbo");
- });
- it("Start Plan 兜底单卡不再渲染额度桶,余额未落定时仅保留查询占位", () => {
- // 服务端契约保证 balances 只属于 active plans:purchased 快照必有套餐详情,
- // 多卡路径必然可用。兜底分支(nav item 无套餐详情)不得把全量桶塞进单卡,
- // 否则违背 spec「无匹配 plan_id 的桶不得附着到任何卡片」。
- const quotaLimits = [
- {
- type: "ent_zcode_v3_glm_52",
- planId: "zcode-v3-start-plan",
- number: 3_000_000,
- remaining: 2_734_000,
- usageDetails: [{ modelCode: "glm-5.2", displayName: "GLM-5.2", usage: 0 }],
- },
- ];
- const settledHtml = renderToStaticMarkup(
- createElement(CodingPlanStatusPanel, {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- providerName: "Z.ai",
- status: "purchased",
- subscriptionDetails: [],
- quotaLimits,
- }),
- );
- expect(settledHtml).not.toContain("settings.modelProvider.startPlan.balance.title");
- expect(settledHtml).not.toContain("2,734,000 / 3,000,000");
- // 兜底分支的套餐卡本体仍在(标题 + 升级按钮),只是不再渲染额度桶。
- expect(settledHtml).toContain("settings.modelProvider.planCard.startPlan");
- expect(settledHtml).toContain("settings.modelProvider.codingPlan.upgrade");
- const checkingHtml = renderToStaticMarkup(
- createElement(CodingPlanStatusPanel, {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- providerName: "Z.ai",
- status: "purchased",
- viewState: {
- displayStatus: "purchased",
- actionStatus: "purchased",
- balanceStatus: "checking",
- loginLoading: false,
- },
- subscriptionDetails: [],
- quotaLimits,
- }),
- );
- expect(checkingHtml).toContain("settings.modelProvider.startPlan.balance.title");
- expect(checkingHtml).not.toContain("2,734,000 / 3,000,000");
- });
- it("Start 明确要求重新登录时不走网络重试,文案不作为操作判断", () => {
- const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan;
- const provider = createProvider({ id: providerId });
- const html = renderDetail(
- {
- key: `coding-plan:${providerId}`,
- type: "codingPlan",
- presetId: providerId,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "Start",
- providerName: "BigModel",
- provider,
- status: "unavailable",
- statusActive: false,
- accountLoginRequired: true,
- statusLabelId: "custom.login.message",
- },
- { onRetryCodingPlan: vi.fn() },
- );
- expect(html).not.toContain("common.retry");
- expect(html).toContain("chat.error.action.relogin");
- const noPlanHtml = renderDetail(
- {
- key: `coding-plan:${providerId}`,
- type: "codingPlan",
- presetId: providerId,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "Start",
- providerName: "BigModel",
- provider,
- status: "notPurchased",
- statusActive: false,
- },
- { providerSettingsView: createProviderSettingsView(provider) },
- );
- expect(noPlanHtml).not.toContain("settings.modelProvider.accountProviderConfigMissing");
- });
- it("Start 无套餐卡不显示付费订阅按钮", () => {
- const html = renderToStaticMarkup(
- createElement(CodingPlanStatusPanel, {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- providerName: "BigModel",
- status: "notPurchased",
- startPlanPreviewVisible: false,
- }),
- );
- expect(html).toContain("settings.modelProvider.startPlan.status.noPlan");
- expect(html).not.toContain("settings.modelProvider.codingPlan.subscribe");
- });
- it("BigModel Start Plan 未登录且无远端 preview 时显示登录入口,不伪造套餐和模型", () => {
- const html = renderDetail({
- key: "coding-plan:account:bigmodel-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel- Coding Plan",
- providerName: "BigModel",
- provider: null,
- status: "disconnected",
- purchaseUrl: "https://bigmodel.cn/",
- statusActive: false,
- });
- expect(html).toContain("settings.modelProvider.planCard.startPlan");
- expect(html).not.toContain("settings.modelProvider.startPlan.quotaSectionTitle");
- expect(html).not.toContain("settings.modelProvider.startPlan.summaryTitle");
- expect(html).not.toContain("settings.modelProvider.startPlan.heroMetric");
- expect(html).not.toContain("settings.modelProvider.startPlan.summaryDescription");
- expect(html).not.toContain("settings.modelProvider.startPlan.eligibleNewUser");
- expect(html).toContain("settings.modelProvider.startPlan.status.loginRequired");
- expect(html).toContain("settings.modelProvider.startPlan.login");
- expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.startPlanTitle");
- expect(html).not.toContain(
- "settings.modelProvider.codingPlan.purchaseBanner.startPlanDescription",
- );
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.personalTitle");
- expect(html).not.toContain(
- "settings.modelProvider.codingPlan.purchaseBanner.personalDescription",
- );
- expect(html).not.toContain("CN¥49.00+");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamTitle");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamDescription");
- expect(html).not.toContain("CN¥598.00+");
- expect(html).not.toContain("color-mix(in_srgb,var(--color-success)_24%");
- expect(html).not.toContain("color-mix(in_srgb,#4099ff_24%");
- expect(html).not.toContain("color-mix(in_srgb,#0ea5e9_24%");
- expect(html).not.toContain("circle_at_14%_12%");
- expect(html).toContain("w-full");
- expect(html).not.toContain("bg-background/80");
- expect(html).not.toContain("sm:grid-cols-3");
- expect(html).not.toContain("button-gradient");
- expect(html).not.toContain("settings.modelProvider.codingPlan.description.disconnected");
- expect(html).not.toContain("settings.modelProvider.codingPlan.productsLoading");
- expect(html).not.toContain("settings.modelProvider.models");
- expect(html).not.toContain("settings.modelProvider.apiKey");
- });
- it.each(["disconnected", "notPurchased"] as const)(
- "BigModel Start Plan %s 详情隐藏远端体验套餐推广",
- (status) => {
- primeStartPlanPreviewCacheForTest({
- planId: "zcode-v3-start-plan",
- name: "ZCode V3 Start Plan",
- entitlements: [
- {
- grantUnits: 10_000_000,
- meter: "model_usage",
- period: "daily",
- showName: "GLM-5.2",
- unitType: "token",
- },
- {
- grantUnits: 10_000_000,
- meter: "model_usage",
- period: "daily",
- showName: "GLM-5.1",
- unitType: "token",
- },
- {
- grantUnits: 10_000_000,
- meter: "model_usage",
- period: "daily",
- showName: "GLM-5-Turbo",
- unitType: "token",
- },
- ],
- });
- const html = renderDetail({
- key: "coding-plan:account:bigmodel-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel- Coding Plan",
- providerName: "BigModel",
- provider: null,
- status,
- purchaseUrl: "https://bigmodel.cn/",
- statusActive: false,
- });
- expect(html).not.toContain("ZCode V3 Start Plan");
- expect(html).not.toContain("30 Million");
- expect(html).not.toContain("tokens per day");
- expect(html).not.toContain("Daily quota · GLM-5.2 / GLM-5.1 / GLM-5-Turbo 10M each");
- expect(html).not.toContain("color-mix(in_srgb,var(--color-success)_24%");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.personalTitle");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamTitle");
- },
- );
- it("个人套餐未连接时即使缓存有体验套餐也不显示推广或模型列表", () => {
- primeStartPlanPreviewCacheForTest({
- planId: "start-preview",
- name: "cached-start-banner",
- entitlements: [
- {
- grantUnits: 8_000_000,
- meter: "model_usage",
- period: "daily",
- showName: "GLM",
- unitType: "token",
- },
- ],
- });
- const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan;
- const html = renderDetail({
- key: `coding-plan:${providerId}`,
- type: "codingPlan",
- presetId: providerId,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel",
- providerName: "BigModel",
- provider: createProvider({ id: providerId, models: ["disconnected-model"] }),
- status: "disconnected",
- statusActive: false,
- });
- expect(html).not.toContain("cached-start-banner");
- expect(html).not.toContain("disconnected-model");
- expect(html).not.toContain("settings.modelProvider.addModel");
- expect(html).toContain("settings.modelProvider.codingPlan.connect");
- });
- it("BigModel Start Plan 中文详情不显示推广额度", () => {
- intlMockState.locale = "zh-CN";
- primeStartPlanPreviewCacheForTest({
- planId: "zcode-v3-start-plan",
- name: "ZCode V3 Start Plan",
- entitlements: [
- {
- grantUnits: 5_000_000,
- meter: "model_usage",
- period: "daily",
- showName: "GLM-5.2",
- unitType: "token",
- },
- ],
- });
- const html = renderDetail({
- key: "coding-plan:account:bigmodel-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel- Coding Plan",
- providerName: "BigModel",
- provider: null,
- status: "disconnected",
- purchaseUrl: "https://bigmodel.cn/",
- statusActive: false,
- });
- expect(html).not.toContain("ZCode V3 Start Plan");
- expect(html).not.toContain("500万");
- expect(html).not.toContain("tokens/日");
- expect(html).not.toContain("每日额度 · GLM-5.2 500万");
- expect(html).not.toContain("¥49.00");
- expect(html).not.toContain("¥598.00");
- expect(html).not.toContain("人民币 起");
- });
- it("BigModel Start Plan 中文详情保留标题且不显示体验推广", () => {
- intlMockState.locale = "zh-CN";
- primeStartPlanPreviewCacheForTest({
- planId: "zcode-v3-start-plan",
- name: "Start Plan",
- entitlements: [
- {
- grantUnits: 5_000_000,
- meter: "model_usage",
- period: "daily",
- showName: "GLM-5.2",
- unitType: "token",
- },
- ],
- });
- const html = renderDetail({
- key: "coding-plan:account:bigmodel-start-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel- Coding Plan",
- providerName: "BigModel",
- provider: null,
- status: "disconnected",
- purchaseUrl: "https://bigmodel.cn/",
- statusActive: false,
- });
- expect(html).not.toContain(">体验套餐<");
- expect(html).toContain(">Start Plan<");
- });
- it("Coding Plan 权益误落到 Start provider 分支时显示权益名", () => {
- expect(
- resolveCodingPlanStatusCardTitle({
- isPurchased: true,
- isStartPlanProvider: true,
- rawPlanLevel: "GLM Coding Pro",
- displayPlanLevel: "GLM Coding Pro",
- startPlanTitle: "Start Plan",
- codingPlanTitle: "Coding Plan",
- }),
- ).toBe("GLM Coding Pro");
- });
- it("Start Plan 校验未知不会误判为未连接", () => {
- expect(
- resolveCodingPlanEntitlementState({
- providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- accountEntitled: false,
- accountAvailability: "unknown",
- modelProvidersLoading: false,
- }).status,
- ).toBe("unavailable");
- });
- it("Start Plan 刷新失败保留套餐并显示失败和重试", () => {
- const html = renderToStaticMarkup(
- createElement(CodingPlanStatusPanel, {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan,
- providerName: "BigModel",
- status: "purchased",
- planLevel: "Start",
- statusLabelId: "settings.modelProvider.codingPlan.status.unavailable",
- onRetry: vi.fn(),
- }),
- );
- expect(html).toContain("settings.modelProvider.planCard.startPlan");
- expect(html).toContain("settings.modelProvider.codingPlan.status.unavailable");
- expect(html).toContain("common.retry");
- });
- it("Start Plan 获取失败也保留自身标题", () => {
- expect(
- resolveCodingPlanStatusCardTitle({
- isPurchased: false,
- isUnavailable: true,
- isStartPlanProvider: true,
- rawPlanLevel: "",
- displayPlanLevel: "",
- startPlanTitle: "Start Plan",
- codingPlanTitle: "Coding Plan",
- }),
- ).toBe("Start Plan");
- });
- it("Start Plan 权益继续显示 Start Plan", () => {
- expect(
- resolveCodingPlanStatusCardTitle({
- isPurchased: true,
- isStartPlanProvider: true,
- rawPlanLevel: "ZCode V3 Start Plan",
- displayPlanLevel: "ZCode V3 Start Plan",
- startPlanTitle: "Start Plan",
- codingPlanTitle: "Coding Plan",
- }),
- ).toBe("Start Plan");
- });
- it("Team Plan 不可用时状态卡标题保留团队名", () => {
- expect(
- resolveCodingPlanStatusCardTitle({
- isPurchased: false,
- isStartPlanProvider: false,
- inactivePlanTitle: "Org A",
- rawPlanLevel: "Org A",
- displayPlanLevel: "ORG A",
- startPlanTitle: "Start Plan",
- codingPlanTitle: "Coding Plan",
- }),
- ).toBe("Org A");
- });
- it("Start Plan 活动升级按钮使用渐变背景", () => {
- const html = renderToStaticMarkup(
- createElement(CodingPlanUpgradeAction, {
- loginLoading: false,
- upgradePlansVisible: false,
- codingPlanPurchaseTokenAuthenticated: true,
- billingDiscountActive: true,
- billingDiscountConfig: {
- "en-US": {
- badgeBody: "150% Quota",
- infoTitle: "Entitlement Rules",
- infoBody: "Remote campaign rules",
- },
- },
- onUpgradePlansVisibleChange: vi.fn(),
- }),
- );
- expect(html).toContain("button-gradient");
- expect(html).toContain("dark:bg-[#484A58]");
- expect(html).toContain("bg-white");
- expect(html).toContain("text-[#191A1D]");
- expect(html).toContain("rounded-full");
- expect(html).not.toContain("lucide-trending-up");
- expect(html).toContain("lucide-info");
- expect(html).toContain('data-slot="dialog-trigger"');
- expect(html).not.toContain("uppercase");
- expect(html).toContain("150% Quota");
- });
- it("聊天额度 Banner 的活动升级按钮与 Model Settings 使用一致样式", () => {
- const html = renderToStaticMarkup(
- createElement(ConversationQuotaBanner, {
- state: {
- visible: true,
- kind: "model-very-low",
- concurrentLimitBusinessCode: null,
- concurrentLimitReason: null,
- providerLimitedBusinessCode: null,
- providerLimitedMessage: null,
- modelName: "GLM-4.5",
- remainingTokens: 12_800,
- remainingPercent: 10,
- dismissible: true,
- blocksSubmit: false,
- priority: 40,
- },
- billingDiscountActive: true,
- billingDiscountConfig: {
- "en-US": {
- badgeBody: "150% Quota",
- infoTitle: "Entitlement Rules",
- infoBody: "Remote campaign rules",
- },
- },
- onUpgrade: vi.fn(),
- onDismiss: vi.fn(),
- }),
- );
- expect(html).toContain("button-gradient");
- expect(html).toContain("dark:bg-[#484A58]");
- expect(html).toContain("pr-px");
- expect(html).toContain("h-auto");
- expect(html).toContain("150% Quota");
- });
- it("Coding Plan 活动 banner 右侧显示说明入口", () => {
- const html = renderToStaticMarkup(
- createElement(CodingPlanBillingDiscountBanner, {
- config: {
- "en-US": {
- cardTitle: "Limited-time 150% Quota Campaign",
- cardBody: "Upgrade your Coding Plan to get 150% quota during the campaign period",
- badgeBody: "150% Quota",
- infoTitle: "Entitlement Rules",
- infoBody: "Remote campaign rules",
- },
- },
- }),
- );
- expect(html).toContain("Limited-time 150% Quota Campaign");
- expect(html).toContain("150% Quota");
- expect(html).toContain("lucide-trending-up");
- expect(html).toContain("lucide-info");
- expect(html).not.toContain('data-slot="button"');
- expect(html).toContain("bg-white");
- expect(html).toContain("text-[#191A1D]");
- expect(html).toContain("settings.modelProvider.codingPlan.billingDiscountInfo.open");
- });
- it("默认活动徽标旁的说明入口在浅色背景可见", () => {
- const html = renderToStaticMarkup(
- createElement(CodingPlanBillingDiscountBadge, {
- config: {
- "en-US": {
- badgeBody: "150% Quota",
- infoTitle: "Entitlement Rules",
- infoBody: "Remote campaign rules",
- },
- },
- }),
- );
- expect(html).toContain("150% Quota");
- expect(html).toContain("lucide-info");
- expect(html).not.toContain('data-slot="button"');
- expect(html).toContain("text-foreground-subtle");
- expect(html).not.toContain("text-white/90");
- });
- it("compact 活动徽标使用 badge 级字号", () => {
- const html = renderToStaticMarkup(
- createElement(CodingPlanBillingDiscountBadgePill, {
- config: {
- "en-US": {
- badgeBody: "150% Quota",
- },
- },
- size: "compact",
- }),
- );
- expect(html).toContain("text-ui-xs");
- expect(html).not.toContain("text-ui-sm");
- expect(html).toContain("whitespace-nowrap");
- });
- it("远端未下发完整活动说明时不显示 Info 入口且不使用本地兜底", () => {
- const html = renderToStaticMarkup(
- createElement(CodingPlanBillingDiscountBadge, {
- config: {
- "en-US": {
- badgeBody: "150% Quota",
- infoTitle: "Entitlement Rules",
- },
- },
- }),
- );
- expect(html).toContain("150% Quota");
- expect(html).not.toContain("lucide-info");
- expect(html).not.toContain("settings.modelProvider.codingPlan.billingDiscountInfo.title");
- });
- it("Coding Plan 活动说明标题与 Markdown 正文来自远端配置", () => {
- const copy = resolveCodingPlanBillingDiscountCopy(
- {
- "zh-CN": {
- infoTitle: "远端权益规则",
- infoBody: "- 远端规则一\n- 远端规则二",
- },
- },
- "zh-CN",
- );
- expect(copy.infoTitle).toBe("远端权益规则");
- expect(copy.infoBody).toBe("- 远端规则一\n- 远端规则二");
- });
- it("Coding Plan 活动说明弹窗使用紧凑宽度", () => {
- expect(CODING_PLAN_BILLING_DISCOUNT_DIALOG_CONTENT_CLASS).toContain("max-w-lg");
- expect(CODING_PLAN_BILLING_DISCOUNT_DIALOG_CONTENT_CLASS).not.toContain("max-w-2xl");
- });
- it("Coding Plan 活动说明文案区域使用弹窗内 wrapper", () => {
- expect(CODING_PLAN_BILLING_DISCOUNT_DIALOG_BODY_CLASS).toBe("p-3 !space-y-3");
- });
- it("按当前 locale 读取服务端下发的 150% 活动文案", () => {
- expect(
- resolveCodingPlanBillingDiscountCopy(
- {
- "zh-CN": {
- cardTitle: "限时 150% 配额活动",
- cardBody: "升级 Coding Plan,可在活动期内获得150% 配额",
- badgeBody: "150% 配额",
- infoTitle: "权益规则说明",
- infoBody: "远端规则正文",
- },
- "en-US": {
- cardTitle: "Limited-time 150% Quota Campaign",
- cardBody: "Upgrade your Coding Plan to get 150% quota during the campaign period",
- badgeBody: "150% Quota",
- },
- },
- "zh-CN",
- ),
- ).toEqual({
- cardTitle: "限时 150% 配额活动",
- cardBody: "升级 Coding Plan,可在活动期内获得150% 配额",
- badgeBody: "150% 配额",
- infoTitle: "权益规则说明",
- infoBody: "远端规则正文",
- });
- });
- it("服务端 150% 活动文案为空时不返回硬编码兜底", () => {
- expect(
- resolveCodingPlanBillingDiscountCopy(
- {
- "en-US": {
- cardTitle: "",
- cardBody: " ",
- infoTitle: "",
- infoBody: " ",
- },
- },
- "en-US",
- ),
- ).toEqual({
- badgeBody: undefined,
- cardTitle: undefined,
- cardBody: undefined,
- infoTitle: undefined,
- infoBody: undefined,
- });
- expect(resolveCodingPlanBillingDiscountCopy({}, "zh-CN")).toEqual({});
- });
- it("活动配置未透传到 UI 时不渲染 150% 活动入口", () => {
- const badgeHtml = renderToStaticMarkup(
- createElement(CodingPlanBillingDiscountBadge, {
- config: undefined,
- }),
- );
- const bannerHtml = renderToStaticMarkup(
- createElement(CodingPlanBillingDiscountBanner, {
- config: undefined,
- }),
- );
- expect(badgeHtml).toBe("");
- expect(bannerHtml).toBe("");
- });
- it("个人和团队 status card 名称后展示 150% 配额徽标", () => {
- primeCodingPlanBillingDiscountCacheForTest({
- "en-US": {
- badgeBody: "150% Quota",
- },
- });
- const personalHtml = renderToStaticMarkup(
- createElement(CodingPlanStatusPanel, {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- providerName: "Z.ai",
- status: "purchased",
- planLevel: "Pro",
- quotaLimits: [
- {
- type: "TOKENS_LIMIT",
- unit: 3,
- number: 5,
- usage: 100_000,
- remaining: 900_000,
- percentage: 10,
- usageDetails: [],
- },
- ],
- }),
- );
- const teamHtml = renderToStaticMarkup(
- createElement(CodingPlanStatusPanel, {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- providerName: "BigModel",
- status: "purchased",
- planLevel: "Team A",
- quotaLimits: [
- {
- type: "TOKENS_LIMIT",
- unit: 3,
- number: 5,
- usage: 100_000,
- remaining: 900_000,
- percentage: 10,
- usageDetails: [],
- },
- ],
- }),
- );
- expect(personalHtml).toContain("Pro");
- expect(personalHtml).toContain("150% Quota");
- expect(teamHtml).toContain("TEAM A");
- expect(teamHtml).toContain("150% Quota");
- });
- it.each([
- BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- ])("%s 获取失败提供明确的重新登录操作", (providerId) => {
- const html = renderToStaticMarkup(
- createElement(CodingPlanStatusPanel, {
- providerId,
- providerName: "Provider",
- status: "unavailable",
- loginActionVisible: true,
- loginActionPlacement: "trailing",
- onLogin: vi.fn(),
- reloginOnFailure: true,
- }),
- );
- expect(html).toContain("login.expired.action");
- expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
- });
- it("Team Plan 未分配时在状态行展示管理员提示", () => {
- const html = renderToStaticMarkup(
- createElement(CodingPlanStatusPanel, {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- providerName: "BigModel",
- status: "unavailable",
- planLevel: "Org A",
- inactivePlanTitle: "Org A",
- statusLabelId: "settings.modelProvider.codingPlan.status.teamUnavailable",
- teamPlanAvailabilityReason: "not-allocated",
- loginActionVisible: true,
- onLogin: vi.fn(),
- }),
- );
- expect(html).toContain("Org A");
- expect(html).toContain("settings.modelProvider.codingPlan.status.teamUnavailable");
- expect(html).toContain("text-warning");
- expect(html).not.toContain("settings.modelProvider.codingPlan.connect");
- });
- it("Team Plan 检查中不叠加旧错误图标和文案", () => {
- const html = renderToStaticMarkup(
- createElement(CodingPlanStatusPanel, {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- providerName: "BigModel",
- status: "unavailable",
- viewState: resolveCodingPlanStatusPanelViewState({
- status: "unavailable",
- loginPending: true,
- }),
- statusLabelId: "settings.modelProvider.codingPlan.status.teamUnavailable",
- statusMessage: "旧团队授权错误",
- teamPlanAvailabilityReason: "credential-unavailable",
- }),
- );
- expect(html).toContain("lucide-loader-circle");
- expect(html).toContain("settings.modelProvider.codingPlan.status.checking");
- expect(html).not.toContain("旧团队授权错误");
- expect(html).not.toContain("settings.modelProvider.codingPlan.status.teamUnavailable");
- expect(html).not.toContain("text-warning");
- expect(html).not.toMatch(/animate-spin[^]*lucide-info/);
- });
- it("Team Plan API Key 预热返回服务端 message 时状态行优先显示该 message", () => {
- const html = renderToStaticMarkup(
- createElement(CodingPlanStatusPanel, {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- providerName: "BigModel",
- status: "unavailable",
- planLevel: "GY的组织",
- inactivePlanTitle: "GY的组织",
- statusLabelId: "settings.modelProvider.codingPlan.status.teamUnavailable",
- statusMessage: "您当前暂无有效的团队套餐授权记录,无法创建API Key",
- teamPlanAvailabilityReason: "credential-unavailable",
- loginActionVisible: true,
- onLogin: vi.fn(),
- }),
- );
- expect(html).toContain("GY的组织");
- expect(html).toContain("您当前暂无有效的团队套餐授权记录,无法创建API Key");
- expect(html).not.toContain("settings.modelProvider.codingPlan.status.teamUnavailable");
- expect(html).toContain("text-warning");
- });
- it("Z.ai Start Plan 展开升级套餐时保留余额卡片", () => {
- const html = renderToStaticMarkup(
- createElement(CodingPlanStatusPanel, {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiStartPlan,
- providerName: "Z.ai",
- status: "purchased",
- planLevel: "Start",
- subscriptionExpireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
- // 生产数据形态:purchased 快照必带 active 套餐详情,额度桶带 plan_id。
- subscriptionDetails: [
- {
- productId: "zcode-v3-start-plan",
- productName: "ZCode V3 Start Plan",
- purchaseTime: null,
- beginTime: null,
- billingCycle: "daily",
- renewTime: null,
- expireTime: new Date(2026, 5, 8, 23, 59).toISOString(),
- },
- ],
- quotaLimits: [
- {
- type: "ent_zcode_v3_glm_52",
- planId: "zcode-v3-start-plan",
- number: 3_000_000,
- usage: 500_000,
- remaining: 2_500_000,
- usageDetails: [{ modelCode: "glm-5.2", usage: 500_000 }],
- },
- ],
- upgradePlansVisible: true,
- }),
- );
- expect(html).toContain("settings.modelProvider.startPlan.balance.title");
- });
- it("Z.ai Coding Plan 展开升级套餐时保留剩余额度卡片", () => {
- const html = renderToStaticMarkup(
- createElement(CodingPlanStatusPanel, {
- providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
- providerName: "Z.ai",
- status: "purchased",
- planLevel: "Pro",
- quotaLimits: [
- {
- type: "TOKENS_LIMIT",
- unit: 3,
- number: 5,
- usage: 100_000,
- remaining: 900_000,
- percentage: 10,
- usageDetails: [],
- },
- {
- type: "TOKENS_LIMIT",
- unit: 6,
- usage: 200_000,
- remaining: 800_000,
- percentage: 20,
- usageDetails: [],
- },
- {
- type: "TIME_LIMIT",
- unit: 5,
- number: 1,
- usage: 1_000,
- remaining: 9_000,
- percentage: 10,
- usageDetails: [],
- },
- ],
- upgradePlansVisible: true,
- }),
- );
- expect(html).toContain("settings.usage.quotaTitle");
- expect(html.indexOf("settings.usage.quotaTitle")).toBeLessThan(
- html.indexOf("settings.usage.entitlementFiveHourUsage"),
- );
- expect(html).toContain("settings.usage.entitlementFiveHourUsage");
- expect(html).toContain("settings.usage.entitlementWeeklyUsage");
- expect(html).toContain("settings.usage.entitlementMonthlyMcpUsage");
- });
- it("BigModel Coding Plan 已购买时在状态行显示管理和解绑操作", () => {
- const currentYear = new Date().getUTCFullYear();
- const html = renderDetail({
- key: "coding-plan:account:bigmodel-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Coding Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- }),
- status: "purchased",
- planLevel: "pro",
- subscriptionRenewTime: `${currentYear}-07-10T00:00:00.000Z`,
- purchaseUrl: "https://bigmodel.cn/",
- statusActive: true,
- });
- const planIndex = html.indexOf(">PRO<");
- const renewIndex = html.indexOf("settings.modelProvider.codingPlan.renewsAt");
- const manageIndex = html.indexOf("settings.modelProvider.codingPlan.manage");
- const unlinkIndex = html.indexOf("settings.modelProvider.codingPlan.disconnect");
- expect(planIndex).toBeGreaterThan(-1);
- expect(renewIndex).toBeGreaterThan(planIndex);
- expect(manageIndex).toBeGreaterThan(renewIndex);
- expect(unlinkIndex).toBeGreaterThan(manageIndex);
- });
- it("BigModel Coding Plan 未登录且无远端 preview 时隐藏 Start 套餐入口", () => {
- const html = renderDetail({
- key: "coding-plan:account:bigmodel-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Coding Plan",
- providerName: "BigModel",
- provider: null,
- status: "disconnected",
- purchaseUrl: "https://bigmodel.cn/",
- statusActive: false,
- });
- expect(html).toContain("settings.modelProvider.planCard.codingPlan");
- expect(html).toContain("settings.modelProvider.codingPlan.status.disconnected");
- expect(html).toContain("settings.modelProvider.codingPlan.connect");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.startPlanTitle");
- expect(html).not.toContain(
- "settings.modelProvider.codingPlan.purchaseBanner.startPlanDescription",
- );
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.personalTitle");
- expect(html).not.toContain(
- "settings.modelProvider.codingPlan.purchaseBanner.personalDescription",
- );
- expect(html).not.toContain("CN¥49.00+");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamTitle");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamDescription");
- expect(html).not.toContain("CN¥598.00+");
- expect(html).not.toContain("color-mix(in_srgb,var(--color-success)_24%");
- expect(html).not.toContain("color-mix(in_srgb,#4099ff_24%");
- expect(html).not.toContain("color-mix(in_srgb,#0ea5e9_24%");
- expect(html).not.toContain("circle_at_14%_12%");
- expect(html).toContain("w-full");
- expect(html).not.toContain("bg-background/80");
- expect(html).not.toContain("sm:grid-cols-3");
- expect(html).not.toContain("button-gradient");
- expect(html).not.toContain("settings.modelProvider.startPlan.quotaSectionTitle");
- expect(html).not.toContain("settings.modelProvider.codingPlan.productsLoading");
- expect(html).not.toContain("settings.modelProvider.codingPlan.bigmodel.plan.lite.name");
- expect(html).not.toContain("settings.modelProvider.models");
- expect(html).not.toContain("settings.modelProvider.apiKey");
- });
- it("BigModel 未登录点击个人/团队套餐时先登录,已登录未订阅才打开购买", () => {
- expect(resolvePurchaseChoiceSelectionIntent("disconnected")).toBe("login");
- expect(resolvePurchaseChoiceSelectionIntent("notPurchased")).toBe("purchase");
- expect(resolvePurchaseChoiceSelectionIntent("purchased")).toBe("purchase");
- });
- it("BigModel Coding Plan 账号未注册时在查询行显示注册链接", () => {
- const html = renderDetail(
- {
- key: "coding-plan:account:bigmodel-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Coding Plan",
- providerName: "本地化后的智谱账号",
- provider: null,
- status: "disconnected",
- purchaseUrl: "https://bigmodel.cn/",
- statusActive: false,
- },
- {
- presetSubscriptionProviderId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- codingPlanAuthError: "BigModel 账号未注册,请先完成 BigModel 注册后再登录。",
- },
- );
- expect(html).toContain("settings.modelProvider.codingPlan.bigmodel.unregisteredHint");
- expect(html).toContain("settings.modelProvider.codingPlan.bigmodel.registerAction");
- expect(html).not.toContain("settings.modelProvider.codingPlan.status.checking");
- });
- it("BigModel Coding Plan 已连接时显示解绑入口", () => {
- const html = renderDetail({
- key: "coding-plan:account:bigmodel-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Coding Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- apiKey: "",
- models: [],
- }),
- status: "notPurchased",
- purchaseUrl: "https://bigmodel.cn/",
- statusActive: false,
- });
- expect(html).toContain("settings.modelProvider.codingPlan.status.notPurchased");
- expect(html).toContain("settings.modelProvider.codingPlan.disconnect");
- expect(html).toMatch(
- /settings\.modelProvider\.codingPlan\.status\.notPurchased[\s\S]*·[\s\S]*settings\.modelProvider\.codingPlan\.disconnect/,
- );
- expect(html).not.toContain("settings.modelProvider.codingPlan.upgrade");
- expect(html).toContain("settings.modelProvider.codingPlan.description.notPurchased");
- expect(html).not.toContain("settings.modelProvider.codingPlan.productsLoading");
- expect(html).not.toContain("settings.modelProvider.models");
- expect(html).not.toContain("settings.modelProvider.apiKey");
- });
- it("BigModel 已登录但无 Start/Coding 权益时等待团队套餐档位加载完成", () => {
- const html = renderDetail(
- {
- key: "coding-plan:account:bigmodel-individual-coding-plan",
- type: "codingPlan",
- presetId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel - Coding Plan",
- providerName: "BigModel",
- provider: createProvider({
- id: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- apiKey: "",
- models: [],
- }),
- status: "notPurchased",
- purchaseUrl: "https://bigmodel.cn/",
- statusActive: false,
- },
- {
- codingPlanPurchaseTokenAuthenticatedByProviderId: {
- [BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan]: true,
- },
- },
- );
- expect(html).toContain("settings.modelProvider.codingPlan.status.notPurchased");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.personalTitle");
- expect(html).not.toContain(
- "settings.modelProvider.codingPlan.purchaseBanner.personalDescription",
- );
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamTitle");
- expect(html).not.toContain("settings.modelProvider.codingPlan.purchaseBanner.teamDescription");
- expect(html).not.toContain("color-mix(in_srgb,#4099ff_24%");
- expect(html).not.toContain("color-mix(in_srgb,var(--color-warning)_24%");
- expect(html).not.toContain("circle_at_14%_12%");
- expect(html).toContain("w-full");
- expect(html).not.toContain("bg-background/80");
- expect(html).not.toContain("sm:grid-cols-2");
- expect(html).not.toContain("button-gradient");
- expect(html).not.toContain("settings.modelProvider.startPlan.quotaSectionTitle");
- expect(html).not.toContain("settings.modelProvider.models");
- expect(html).not.toContain("settings.modelProvider.apiKey");
- });
- it.each([false, true])("个人未开通时团队 subscribed=%s 仍展示团队 banner", (subscribed) => {
- const spy = vi
- .spyOn(enterpriseProductsHook, "useEnterpriseCodingPlanProducts")
- .mockReturnValue({
- loading: false,
- error: null,
- refresh: vi.fn(),
- snapshot: {
- authenticated: true,
- staticProductIds: ["team-pro"],
- raw: { productList: [] },
- productList: [
- {
- productId: "team-pro",
- productName: "Pro",
- productEquityList: [],
- priceCurrency: "CNY",
- payAmount: 598,
- tier: "PRO",
- subscribeMode: "CONTINUOUS",
- subscribePeriod: "YEARLY",
- purchaseMethodName: "Auto renew",
- subscribed,
- enterpriseProduct: {
- productId: "team-pro",
- tier: "PRO",
- subscribeMode: "CONTINUOUS",
- subscribePeriod: "YEARLY",
- payAmount: 598,
- },
- },
- ],
- },
- });
- try {
- const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan;
- const html = renderDetail(
- {
- key: `coding-plan:${providerId}`,
- type: "codingPlan",
- presetId: providerId,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "BigModel",
- providerName: "BigModel",
- provider: createProvider({ id: providerId }),
- status: "notPurchased",
- statusActive: false,
- },
- { codingPlanPurchaseTokenAuthenticatedByProviderId: { [providerId]: true } },
- );
- expect(html).toContain("settings.modelProvider.codingPlan.purchaseBanner.teamDescription");
- expect(html).toContain("598.00");
- expect(html).not.toContain("settings.modelProvider.models");
- const startId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan;
- const startItem: ModelProviderNavItem = {
- key: "start-expired",
- type: "codingPlan",
- presetId: startId,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "Start Plan",
- providerName: "BigModel",
- provider: createProvider({ id: startId }),
- status: "notPurchased",
- statusActive: false,
- statusLabelId: "settings.modelProvider.startPlan.status.expired",
- };
- for (const type of ["codingPlan", "teamPlan"] as const) {
- for (const available of [false, true]) {
- for (const status of ["purchased", "unavailable", "checking"] as const) {
- const paidItem: ModelProviderNavItem = {
- key: "paid",
- type,
- presetId: providerId,
- oauthProviderId: BIGMODEL_PROVIDER_ID,
- label: "Paid",
- providerName: "BigModel",
- provider: null,
- status,
- statusActive: false,
- ...(type === "teamPlan"
- ? {
- teamPlanName: "Team",
- organizationId: "org",
- projectId: "project",
- currentProductId: "product",
- }
- : {}),
- };
- const paidView = createProviderSettingsView(createProvider({ id: providerId }));
- paidView.providers[0]!.accountState = {
- availability: available ? "available" : "unavailable",
- entitled: available,
- current: true,
- };
- const startHtml = renderDetail(startItem, {
- navigationItems: [startItem, paidItem],
- providerSettingsView: paidView,
- codingPlanPurchaseTokenAuthenticatedByProviderId: { [startId]: true },
- });
- expect(startHtml).toContain("settings.modelProvider.startPlan.status.expired");
- expect(
- startHtml.includes(
- "settings.modelProvider.codingPlan.purchaseBanner.teamDescription",
- ),
- ).toBe(!available);
- const activeStartHtml = renderDetail(
- { ...startItem, status: "purchased", statusLabelId: undefined },
- {
- navigationItems: [startItem, paidItem],
- providerSettingsView: paidView,
- },
- );
- expect(activeStartHtml.includes("settings.modelProvider.codingPlan.upgrade")).toBe(
- !available,
- );
- }
- }
- }
- } finally {
- spy.mockRestore();
- }
- });
- it("团队标准版和高级版使用不同 banner 背景", () => {
- const standardClassName = resolveEnterpriseTeamPlanBannerClass("pro");
- const advancedClassName = resolveEnterpriseTeamPlanBannerClass("max");
- expect(standardClassName).toContain("#0ea5e9");
- expect(advancedClassName).toContain("#14b8a6");
- expect(advancedClassName).not.toBe(standardClassName);
- });
- it("团队标准版和高级版图标颜色跟随 banner 背景", () => {
- expect(resolveEnterpriseTeamPlanBannerIconClass("pro")).toBe("text-[#0ea5e9]");
- expect(resolveEnterpriseTeamPlanBannerIconClass("max")).toBe("text-[#14b8a6]");
- });
- it("团队标准版和高级版使用各自的 banner 描述", () => {
- expect(resolveEnterpriseTeamPlanBannerDescriptionId("pro")).toBe(
- "settings.modelProvider.codingPlan.purchaseBanner.teamStandardDescription",
- );
- expect(resolveEnterpriseTeamPlanBannerDescriptionId("max")).toBe(
- "settings.modelProvider.codingPlan.purchaseBanner.teamAdvancedDescription",
- );
- });
- it("模型供应商手动刷新会同步 Team Plan 产品快照", async () => {
- const calls: string[] = [];
- await refreshModelProviderSection({
- refresh: async () => {
- calls.push("providers");
- },
- refreshTeamPlanProducts: async () => {
- calls.push("team-products");
- },
- });
- expect(calls.sort()).toEqual(["providers", "team-products"]);
- });
- it("连接方式切换只刷新 provider,不强制刷新套餐权益", async () => {
- const calls: string[] = [];
- await refreshProviderPanelAfterAuthChange({
- refreshModelProviders: async () => {
- calls.push("providers");
- },
- refreshCodingPlanEntitlements: async () => {
- calls.push("entitlements");
- },
- refreshTeamPlanProducts: async () => {
- calls.push("team-products");
- },
- refreshCodingPlanProducts: () => {
- calls.push("products");
- },
- refreshPurchaseTokenState: async () => {
- calls.push("token");
- },
- refreshPlanSnapshots: false,
- });
- expect(calls).toEqual(["token", "providers", "products"]);
- });
- it("全局购买弹窗完成 Team Plan 购买后刷新团队产品快照", async () => {
- const calls: string[] = [];
- await refreshCodingPlanUpgradeCompletion({
- providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- productsProviderId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- refreshCodingPlanEntitlements: async () => {
- calls.push("entitlements");
- },
- refreshProviderState: async () => {
- calls.push("registry");
- },
- refreshTeamPlanProducts: async () => {
- calls.push("team-products");
- },
- });
- expect(calls).toContain("team-products");
- // 改造原因:购买流程迁到 webview 后,App 不再维护 purchase token 状态
- // (oauth:active_provider 那套登录态由官网页内部处理),刷新列表里不再有 "token"。
- expect(calls.sort()).toEqual(["entitlements", "registry", "team-products"]);
- });
- it("新 Provider Runtime 购买完成后只刷新 Account Source", async () => {
- const calls: string[] = [];
- await refreshCodingPlanUpgradeCompletion({
- providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- productsProviderId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
- refreshCodingPlanEntitlements: async () => {
- calls.push("entitlements");
- },
- refreshProviderState: async () => {
- calls.push("registry");
- },
- });
- expect(calls.sort()).toEqual(["entitlements", "registry"]);
- });
- it("webview 请求购买完成后先关闭升级弹窗再刷新当前 provider", async () => {
- const calls: string[] = [];
- await closeAndRefreshCodingPlanUpgradeFromWebview({
- onClose: () => {
- calls.push("close");
- },
- refresh: async () => {
- calls.push("refresh:start");
- await Promise.resolve();
- calls.push("refresh:end");
- },
- });
- expect(calls).toEqual(["close", "refresh:start", "refresh:end"]);
- });
- });
- describe("团队初始化的商品元数据变化", () => {
- it.each(["bigmodel", "zai"] as const)(
- "%s 同项目商品更新仍选中团队,且不报连接不可用",
- (family) => {
- const spec = getModelProviderFamilySpec(family);
- let captured: ReturnType<typeof useModelProviderNavigation> | undefined;
- function Harness() {
- captured = useModelProviderNavigation({
- presetProviders: [
- { id: spec.startPlanProviderId, displayName: spec.label, provider: null },
- ],
- modelProviders: [],
- selectedNodeKey: `preset:${spec.startPlanProviderId}`,
- providerFamilyDomain: family,
- connectionSelections: {
- [family]: {
- kind: "team-coding-plan",
- productId: "saved-product",
- organizationId: "org-a",
- projectId: "project-a",
- },
- },
- showPurchasedTeamPlanFallback: true,
- codingPlanEntitlements: {
- [spec.teamCodingPlanProviderId]: {
- loading: false,
- error: null,
- snapshot: {
- generatedAt: 1,
- authenticated: true,
- provider: { id: spec.teamCodingPlanProviderId },
- context: {
- scope: "team",
- organizationId: "org-a",
- projectId: "project-a",
- productId: "current-product",
- displayName: "Current Team",
- },
- subscription: null,
- quota: null,
- remaining: null,
- },
- },
- },
- setSelectedNodeKey: vi.fn(),
- intl: { formatMessage: ({ id }: { id: string }) => id } as never,
- });
- return createElement("div");
- }
- renderToStaticMarkup(createElement(Harness));
- expect(captured?.selectedNavItem).toMatchObject({
- type: "teamPlan",
- currentProductId: "current-product",
- organizationId: "org-a",
- projectId: "project-a",
- });
- expect(captured?.navigationUnavailable).toBe(false);
- const team = captured!.selectedNavItem!;
- for (const selection of [
- { organizationId: "other-org", projectId: "project-a" },
- { organizationId: "org-a", projectId: "other-project" },
- ]) {
- expect(
- connectionSelectionMatchesNavigationItem(
- family,
- {
- kind: "team-coding-plan",
- productId: "current-product",
- ...selection,
- },
- team,
- ),
- ).toBe(false);
- }
- expect(
- connectionSelectionMatchesNavigationItem(
- family === "bigmodel" ? "zai" : "bigmodel",
- {
- kind: "team-coding-plan",
- productId: "current-product",
- organizationId: "org-a",
- projectId: "project-a",
- },
- team,
- ),
- ).toBe(false);
- },
- );
- });
|