@@ -3,6 +3,11 @@ import { IInputs } from '../../../src/interface';
33import DevClient from '@alicloud/devs20230714' ;
44import * as $OpenApi from '@alicloud/openapi-client' ;
55import { sleep } from '../../../src/utils' ;
6+ import {
7+ initClient ,
8+ _displayProgress ,
9+ _displayProgressComplete ,
10+ } from '../../../src/subCommands/model/utils' ;
611
712// Mock dependencies
813jest . mock ( '../../../src/logger' , ( ) => {
@@ -83,14 +88,14 @@ describe('ArtModelService', () => {
8388 securityToken : 'test-token' ,
8489 protocol : 'https' ,
8590 endpoint : 'devs-pre.cn-hangzhou.aliyuncs.com' ,
86- readTimeout : 86400000 ,
87- connectTimeout : 60000 ,
88- userAgent : 'test-agent ' ,
91+ readTimeout : 300000 ,
92+ connectTimeout : 300000 ,
93+ userAgent : 'Component:fun-art;Nodejs:;OS:darwin- ' ,
8994 } ;
9095
9196 ( $OpenApi . Config as unknown as jest . Mock ) . mockImplementation ( ( config ) => config ) ;
9297
93- const client = await artModelService . initClient ( ) ;
98+ const client = await initClient ( mockInputs , 'cn-hangzhou' , artModelService . logger , 'fun-art' ) ;
9499
95100 expect ( $OpenApi . Config ) . toHaveBeenCalledWith ( expect . objectContaining ( mockConfig ) ) ;
96101 expect ( client ) . toBeInstanceOf ( DevClient ) ;
@@ -101,27 +106,31 @@ describe('ArtModelService', () => {
101106
102107 ( $OpenApi . Config as unknown as jest . Mock ) . mockImplementation ( ( config ) => config ) ;
103108
104- await artModelService . initClient ( ) ;
109+ const client = await initClient ( mockInputs , 'cn-hangzhou' , artModelService . logger , 'fun-art' ) ;
105110
106111 expect ( $OpenApi . Config ) . toHaveBeenCalledWith (
107112 expect . objectContaining ( {
108113 endpoint : 'custom.endpoint.com' ,
114+ userAgent : 'Component:fun-art;Nodejs:;OS:darwin-' ,
109115 } ) ,
110116 ) ;
117+ expect ( client ) . toBeInstanceOf ( DevClient ) ;
111118 } ) ;
112119
113120 it ( 'should use custom endpoint from artifact_endpoint environment variable' , async ( ) => {
114121 process . env . artifact_endpoint = 'custom2.endpoint.com' ;
115122
116123 ( $OpenApi . Config as unknown as jest . Mock ) . mockImplementation ( ( config ) => config ) ;
117124
118- await artModelService . initClient ( ) ;
125+ const client = await initClient ( mockInputs , 'cn-hangzhou' , artModelService . logger , 'fun-art' ) ;
119126
120127 expect ( $OpenApi . Config ) . toHaveBeenCalledWith (
121128 expect . objectContaining ( {
122129 endpoint : 'custom2.endpoint.com' ,
130+ userAgent : 'Component:fun-art;Nodejs:;OS:darwin-' ,
123131 } ) ,
124132 ) ;
133+ expect ( client ) . toBeInstanceOf ( DevClient ) ;
125134 } ) ;
126135 } ) ;
127136
@@ -135,7 +144,9 @@ describe('ArtModelService', () => {
135144 getFileManagerTask : jest . fn ( ) ,
136145 } as any ;
137146
138- artModelService . initClient = jest . fn ( ) . mockResolvedValue ( mockDevClient ) ;
147+ // Mock the initClient function from utils
148+ const utils = require ( '../../../src/subCommands/model/utils' ) ;
149+ jest . spyOn ( utils , 'initClient' ) . mockResolvedValue ( mockDevClient ) ;
139150 ( sleep as jest . Mock ) . mockResolvedValue ( undefined ) ;
140151 } ) ;
141152
@@ -458,7 +469,9 @@ describe('ArtModelService', () => {
458469 fileManagerRm : jest . fn ( ) ,
459470 } as any ;
460471
461- artModelService . initClient = jest . fn ( ) . mockResolvedValue ( mockDevClient ) ;
472+ // Mock the initClient function from utils
473+ const utils = require ( '../../../src/subCommands/model/utils' ) ;
474+ jest . spyOn ( utils , 'initClient' ) . mockResolvedValue ( mockDevClient ) ;
462475 } ) ;
463476
464477 it ( 'should successfully remove model files' , async ( ) => {
@@ -492,9 +505,9 @@ describe('ArtModelService', () => {
492505 } ) ;
493506 } ) ;
494507
495- describe ( 'getSource ' , ( ) => {
508+ describe ( 'getSourceAndDestination ' , ( ) => {
496509 it ( 'should correctly generate source and destination paths' , ( ) => {
497- const result = artModelService . getSource (
510+ const result = artModelService . getSourceAndDestination (
498511 'modelscope://test-model' ,
499512 { source : { path : 'file1.txt' } , target : { path : 'file1.txt' } } ,
500513 [ { mountDir : '/mnt/nas' } ] ,
@@ -510,7 +523,7 @@ describe('ArtModelService', () => {
510523
511524 it ( 'should handle invalid source URI' , ( ) => {
512525 expect ( ( ) => {
513- artModelService . getSource (
526+ artModelService . getSourceAndDestination (
514527 'invalid://test-model' ,
515528 { source : { path : 'file1.txt' } , target : { path : 'file1.txt' } } ,
516529 [ { mountDir : '/mnt/nas' } ] ,
@@ -526,19 +539,17 @@ describe('ArtModelService', () => {
526539 describe ( '_getSourcePath' , ( ) => {
527540 it ( 'should correctly generate source path with valid URI' , ( ) => {
528541 const result = ( artModelService as any ) . _getSourcePath (
529- { path : 'file1.txt' } ,
542+ { source : { path : 'file1.txt' } } ,
530543 'modelscope://test-model' ,
531- / ^ ( m o d e l s c o p e | o s s | n a s ) : \/ \/ / ,
532544 ) ;
533545
534546 expect ( result ) . toBe ( 'modelscope://test-model/file1.txt' ) ;
535547 } ) ;
536548
537549 it ( 'should handle URI ending with slash' , ( ) => {
538550 const result = ( artModelService as any ) . _getSourcePath (
539- { path : 'file1.txt' } ,
551+ { source : { path : 'file1.txt' } } ,
540552 'modelscope://test-model/' ,
541- / ^ ( m o d e l s c o p e | o s s | n a s ) : \/ \/ / ,
542553 ) ;
543554
544555 expect ( result ) . toBe ( 'modelscope://test-model/file1.txt' ) ;
@@ -595,7 +606,8 @@ describe('ArtModelService', () => {
595606 it ( 'should display progress correctly' , ( ) => {
596607 const stdoutSpy = jest . spyOn ( process . stdout , 'write' ) . mockImplementation ( ( ) => true as any ) ;
597608
598- ( artModelService as any ) . _displayProgress ( 'file1.txt' , 512 , 1024 ) ;
609+ // Import and call the _displayProgress function directly from utils
610+ _displayProgress ( 'file1.txt' , 512 , 1024 ) ;
599611
600612 expect ( stdoutSpy ) . toHaveBeenCalledWith (
601613 expect . stringContaining (
@@ -611,7 +623,8 @@ describe('ArtModelService', () => {
611623 it ( 'should display complete progress correctly' , ( ) => {
612624 const stdoutSpy = jest . spyOn ( process . stdout , 'write' ) . mockImplementation ( ( ) => true as any ) ;
613625
614- ( artModelService as any ) . _displayProgressComplete ( 'file1.txt' , 1024 , 1024 ) ;
626+ // Import and call the _displayProgressComplete function directly from utils
627+ _displayProgressComplete ( 'file1.txt' , 1024 , 1024 ) ;
615628
616629 expect ( stdoutSpy ) . toHaveBeenCalledWith (
617630 expect . stringContaining (
0 commit comments