@@ -27,16 +27,6 @@ type ElectronDownload = {
2727 totalBytes ?: number
2828}
2929
30- type NormalizedElectronDownload = ElectronDownload & {
31- status : DownloadStatus
32- receivedBytes : number
33- totalBytes : number
34- }
35-
36- type NormalizeElectronDownloadState = (
37- download : DownloadState
38- ) => NormalizedElectronDownload
39-
4030type ElectronDownloadStore = {
4131 findByUrl : ( url : string ) => ElectronDownload | undefined
4232 initialize : ( ) => Promise < void >
@@ -46,7 +36,6 @@ type ElectronDownloadStore = {
4636}
4737
4838type ElectronDownloadStoreModule = {
49- normalizeElectronDownloadState : NormalizeElectronDownloadState
5039 useElectronDownloadStore : ( ) => ElectronDownloadStore
5140}
5241
@@ -56,8 +45,6 @@ function isElectronDownloadStoreModule(
5645 return (
5746 typeof value === 'object' &&
5847 value !== null &&
59- 'normalizeElectronDownloadState' in value &&
60- typeof value . normalizeElectronDownloadState === 'function' &&
6148 'useElectronDownloadStore' in value &&
6249 typeof value . useElectronDownloadStore === 'function'
6350 )
@@ -108,37 +95,6 @@ function progressUpdate(overrides: Partial<ElectronDownload> = {}) {
10895 }
10996}
11097
111- describe ( 'normalizeElectronDownloadState' , ( ) => {
112- it ( 'maps restored state, bytes, and a valid byte fraction' , ( ) => {
113- expect (
114- getModule ( ) . normalizeElectronDownloadState (
115- downloadState ( { state : DownloadStatus . PAUSED } )
116- )
117- ) . toEqual ( {
118- url : 'https://example.com/model.safetensors' ,
119- filename : 'model.safetensors' ,
120- status : DownloadStatus . PAUSED ,
121- receivedBytes : 256 ,
122- totalBytes : 1024 ,
123- progress : 0.25
124- } )
125- } )
126-
127- it ( 'keeps restored bytes without inventing a fraction for an empty total' , ( ) => {
128- expect (
129- getModule ( ) . normalizeElectronDownloadState (
130- downloadState ( { receivedBytes : 0 , totalBytes : 0 } )
131- )
132- ) . toEqual ( {
133- url : 'https://example.com/model.safetensors' ,
134- filename : 'model.safetensors' ,
135- status : DownloadStatus . IN_PROGRESS ,
136- receivedBytes : 0 ,
137- totalBytes : 0
138- } )
139- } )
140- } )
141-
14298describe ( 'useElectronDownloadStore progress observation' , ( ) => {
14399 let emitProgress : ( ( download : ElectronDownload ) => void ) | undefined
144100
@@ -153,6 +109,41 @@ describe('useElectronDownloadStore progress observation', () => {
153109 } )
154110 } )
155111
112+ it ( 'restores status, bytes, and a valid byte fraction' , async ( ) => {
113+ downloadManager . getAllDownloads . mockResolvedValueOnce ( [
114+ downloadState ( { state : DownloadStatus . PAUSED } )
115+ ] )
116+ const store = getModule ( ) . useElectronDownloadStore ( )
117+
118+ await vi . waitFor ( ( ) => {
119+ expect ( store . findByUrl ( 'https://example.com/model.safetensors' ) ) . toEqual ( {
120+ url : 'https://example.com/model.safetensors' ,
121+ filename : 'model.safetensors' ,
122+ status : DownloadStatus . PAUSED ,
123+ receivedBytes : 256 ,
124+ totalBytes : 1024 ,
125+ progress : 0.25
126+ } )
127+ } )
128+ } )
129+
130+ it ( 'keeps restored bytes without inventing a fraction for an empty total' , async ( ) => {
131+ downloadManager . getAllDownloads . mockResolvedValueOnce ( [
132+ downloadState ( { receivedBytes : 0 , totalBytes : 0 } )
133+ ] )
134+ const store = getModule ( ) . useElectronDownloadStore ( )
135+
136+ await vi . waitFor ( ( ) => {
137+ expect ( store . findByUrl ( 'https://example.com/model.safetensors' ) ) . toEqual ( {
138+ url : 'https://example.com/model.safetensors' ,
139+ filename : 'model.safetensors' ,
140+ status : DownloadStatus . IN_PROGRESS ,
141+ receivedBytes : 0 ,
142+ totalBytes : 0
143+ } )
144+ } )
145+ } )
146+
156147 it ( 'installs the live listener before awaiting the restored snapshot' , ( ) => {
157148 downloadManager . getAllDownloads . mockReturnValueOnce (
158149 deferred < DownloadState [ ] > ( ) . promise
0 commit comments