Skip to content

Commit 2ed4ea7

Browse files
committed
refactor: keep template setup internals private
1 parent 491e931 commit 2ed4ea7

7 files changed

Lines changed: 47 additions & 59 deletions

File tree

src/platform/workflow/templates/types/templateDetail.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { TemplateModelDownloadState } from '@/platform/workflow/templates/utils/templateModelDownloadState'
22

3-
export interface TemplateDetailLink {
3+
interface TemplateDetailLink {
44
label: string
55
href: string
66
}
77

8-
export type TemplateDetailRowStatus =
8+
type TemplateDetailRowStatus =
99
| {
1010
kind: 'installed'
1111
label: string

src/platform/workflow/templates/utils/templateCustomNodeAvailability.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type TemplateCustomNodeManagerCapability =
88
| 'legacy'
99
| 'incompatible'
1010

11-
export type TemplateCustomNodeUnavailableReason =
11+
type TemplateCustomNodeUnavailableReason =
1212
| 'manager-disabled'
1313
| 'manager-legacy'
1414
| 'manager-incompatible'

src/platform/workflow/templates/utils/templateModelAvailability.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import type { ModelFile } from '@/platform/workflow/validation/schemas/workflowSchema'
22

3-
export type TemplateModelAvailabilityStatus =
4-
| 'installed'
5-
| 'missing'
6-
| 'unknown'
3+
type TemplateModelAvailabilityStatus = 'installed' | 'missing' | 'unknown'
74

8-
export type TemplateModelInventoryEntry = {
5+
type TemplateModelInventoryEntry = {
96
directory: string
107
name: string
118
}

src/platform/workflow/templates/utils/templateModelDownloadState.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export type TemplateModelDownloadActivity = 'active' | 'paused'
1+
type TemplateModelDownloadActivity = 'active' | 'paused'
22

3-
export type TemplateModelDownloadFailureReason = 'error' | 'cancelled'
3+
type TemplateModelDownloadFailureReason = 'error' | 'cancelled'
44

55
export type TemplateModelDownloadState =
66
| { status: 'idle'; attempt: 0 }

src/platform/workflow/templates/utils/templateModelSetup.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ import type { ResolvedTemplateModelAvailability } from '@/platform/workflow/temp
77
import type { TemplateModelRequirementDetail } from '@/platform/workflow/templates/utils/templateModelRequirements'
88
import type { ModelFile } from '@/platform/workflow/validation/schemas/workflowSchema'
99

10-
export type TemplateModelSetupStatus =
10+
type TemplateModelSetupStatus =
1111
| 'installed'
1212
| 'downloadable'
1313
| 'manual'
1414
| 'unavailable'
1515
| 'unknown'
1616

17-
export type TemplateModelTypeKey =
17+
type TemplateModelTypeKey =
1818
| 'model'
1919
| 'checkpoint'
2020
| 'diffusionModel'
2121
| 'textEncoder'
2222
| 'vae'
2323
| 'lora'
2424

25-
export type TemplateModelType =
25+
type TemplateModelType =
2626
| { kind: 'known'; key: TemplateModelTypeKey }
2727
| { kind: 'directory'; raw: string }
2828

@@ -42,7 +42,7 @@ export type TemplateModelSetupRow =
4242
status: Exclude<TemplateModelSetupStatus, 'manual'>
4343
})
4444

45-
export type TemplateModelSetupTotal = {
45+
type TemplateModelSetupTotal = {
4646
bytes: number
4747
isComplete: boolean
4848
}

src/stores/electronDownloadStore.test.ts

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
4030
type ElectronDownloadStore = {
4131
findByUrl: (url: string) => ElectronDownload | undefined
4232
initialize: () => Promise<void>
@@ -46,7 +36,6 @@ type ElectronDownloadStore = {
4636
}
4737

4838
type 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-
14298
describe('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

src/stores/electronDownloadStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface ElectronDownload extends Pick<
1717
totalBytes?: number
1818
}
1919

20-
export function normalizeElectronDownloadState({
20+
function normalizeElectronDownloadState({
2121
url,
2222
filename,
2323
state,

0 commit comments

Comments
 (0)