| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013 |
- 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,
- type UsageEntitlementSnapshot,
- } from "@zcode/shared";
- import {
- TID_MODEL_PROVIDER_ADD_MODEL_BUTTON,
- TID_MODEL_PROVIDER_MODEL_DELETE_BUTTON,
- } from "@zcode/shared/test-ids";
- 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,
- 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 } from "@/settings/model-provider-section/Navigation.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 { 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("付费下拉按完整保存选择显示团队,不读取复制的个人 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 {
- clearCodingPlanBillingDiscountCacheForTest,
- CodingPlanBillingDiscountBadge,
- 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 状态显示 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,
- });
- expect(html).toContain('value="https://api.example.com/v1"');
- expectConnectionApiFormatVisible(html);
- expect(html).not.toContain("settings.modelProvider.endpointPath");
- });
- 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("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).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("");
- });
- 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).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("Aug 11");
- expect(html).toContain("Aug 12");
- expect(html.indexOf("75%")).toBeLessThan(html.indexOf("Aug 10, 09:30"));
- 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("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%");
- });
- 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%");
- });
- 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(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("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("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("完整活动配置在升级入口旁显示说明入口和远端徽标文案", () => {
- 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("lucide-info");
- expect(html).toContain('data-slot="dialog-trigger"');
- 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-info");
- 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");
- });
- 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("按当前 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("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("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("模型供应商手动刷新会同步 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);
- },
- );
- });
|