modelProviderCodingPlan.test.ts 244 KB

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