@@ -212,20 +212,71 @@ describe("UsageAggregator", () => {
212212
213213describe ( "resolveModelAliases" , ( ) => {
214214 it ( "follows chains to the final model and drops chains that enter a loop" , ( ) => {
215- expect (
216- resolveModelAliases ( {
217- "preview[1m]" : "preview" ,
218- preview : "example-model" ,
219- loop : "back" ,
220- back : "loop" ,
221- intoLoop : "loop" ,
222- self : "self" ,
223- } ) ,
224- ) . toEqual (
225- new Map ( [
226- [ "preview[1m]" , "example-model" ] ,
227- [ "preview" , "example-model" ] ,
228- ] ) ,
229- ) ;
215+ const aliases = Object . freeze ( {
216+ "preview[1m]" : "preview" ,
217+ unrelated : "other-model" ,
218+ preview : "example-model" ,
219+ shared : "preview" ,
220+ intoLoop : "loop" ,
221+ loop : "back" ,
222+ back : "loop" ,
223+ laterIntoLoop : "back" ,
224+ deepIntoLoop : "intoLoop" ,
225+ self : "self" ,
226+ intoSelf : "self" ,
227+ validAfterLoops : "shared" ,
228+ } ) ;
229+
230+ expect ( [ ...resolveModelAliases ( aliases ) ] ) . toEqual ( [
231+ [ "preview[1m]" , "example-model" ] ,
232+ [ "unrelated" , "other-model" ] ,
233+ [ "preview" , "example-model" ] ,
234+ [ "shared" , "example-model" ] ,
235+ [ "validAfterLoops" , "example-model" ] ,
236+ ] ) ;
237+ expect ( [ ...resolveModelAliases ( { } ) ] ) . toEqual ( [ ] ) ;
238+ } ) ;
239+
240+ it ( "keeps Object.keys order and follows only own targets, including non-enumerable ones" , ( ) => {
241+ const aliases = {
242+ "10" : "constructor" ,
243+ "2" : "toString" ,
244+ first : "hidden" ,
245+ [ "__proto__" ] : "hasOwnProperty" ,
246+ constructor : "terminal" ,
247+ hasOwnProperty : "constructor" ,
248+ inheritedTarget : "inherited" ,
249+ } ;
250+ Object . setPrototypeOf ( aliases , { inherited : "must-not-follow" } ) ;
251+ Object . defineProperty ( aliases , "hidden" , { value : "constructor" } ) ;
252+
253+ expect ( [ ...resolveModelAliases ( aliases ) ] ) . toEqual ( [
254+ [ "2" , "toString" ] ,
255+ [ "10" , "terminal" ] ,
256+ [ "first" , "terminal" ] ,
257+ [ "__proto__" , "terminal" ] ,
258+ [ "constructor" , "terminal" ] ,
259+ [ "hasOwnProperty" , "terminal" ] ,
260+ [ "inheritedTarget" , "inherited" ] ,
261+ ] ) ;
262+ expect ( [ ...resolveModelAliases ( { prototypeTarget : "__proto__" } ) ] ) . toEqual ( [
263+ [ "prototypeTarget" , "__proto__" ] ,
264+ ] ) ;
265+ } ) ;
266+
267+ it ( "preserves empty terminal strings and follows an own empty-string alias" , ( ) => {
268+ expect ( [ ...resolveModelAliases ( { first : "next" , next : "" , last : "next" } ) ] ) . toEqual ( [
269+ [ "first" , "" ] ,
270+ [ "next" , "" ] ,
271+ [ "last" , "" ] ,
272+ ] ) ;
273+ expect ( [ ...resolveModelAliases ( { first : "" , "" : "terminal" , last : "first" } ) ] ) . toEqual ( [
274+ [ "first" , "terminal" ] ,
275+ [ "" , "terminal" ] ,
276+ [ "last" , "terminal" ] ,
277+ ] ) ;
278+ expect ( [ ...resolveModelAliases ( { first : "" , "" : "" , valid : "terminal" } ) ] ) . toEqual ( [
279+ [ "valid" , "terminal" ] ,
280+ ] ) ;
230281 } ) ;
231282} ) ;
0 commit comments