Skip to content

Commit bfe4940

Browse files
committed
Remove redundant order test
1 parent aefc063 commit bfe4940

2 files changed

Lines changed: 5 additions & 55 deletions

File tree

packages/theme/src/cli/utilities/theme-uploader.test.ts

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import {renderTasksToStdErr} from './theme-ui.js'
22
import {fakeThemeFileSystem} from './theme-fs/theme-fs-mock-factory.js'
33
import {
4-
ChecksumWithSize,
54
MAX_BATCH_BYTESIZE,
65
MAX_BATCH_FILE_COUNT,
76
MAX_UPLOAD_RETRY_COUNT,
87
MINIMUM_THEME_ASSETS,
9-
orderFilesToBeUploaded,
108
uploadTheme,
119
updateUploadErrors,
1210
} from './theme-uploader.js'
@@ -416,47 +414,6 @@ describe('theme-uploader', () => {
416414
)
417415
})
418416

419-
test('orders settings_schema.json first and settings_data.json last in the dependent chain, surrounding every validator-consumer asset', () => {
420-
// Regression for the fresh-theme bootstrap bug: blocks, sections, section-group
421-
// JSONs and template JSONs run server-side validators that resolve dynamic-source
422-
// defaults of the form `{{ settings.<theme_setting>.* }}` against the theme's
423-
// currently-stored settings_schema.json. If the user's new schema lands AFTER
424-
// those assets, validators see an empty schema and the first push errors out.
425-
// settings_data.json must then go LAST because its values are validated against
426-
// the freshly-uploaded schema and may reference earlier-uploaded sections/templates.
427-
const file = (key: string): ChecksumWithSize => ({key, checksum: '_', size: 0})
428-
const files: ChecksumWithSize[] = [
429-
file('config/settings_schema.json'),
430-
file('config/settings_data.json'),
431-
file('layout/theme.liquid'),
432-
file('blocks/quantity.liquid'),
433-
file('sections/header.liquid'),
434-
file('sections/header-group.json'),
435-
file('templates/product.json'),
436-
file('templates/product.context.uk.json'),
437-
]
438-
439-
const {dependentFiles} = orderFilesToBeUploaded(files)
440-
const flat = dependentFiles.flat().map((f) => f.key)
441-
442-
expect(flat.at(0)).toBe('config/settings_schema.json')
443-
expect(flat.at(-1)).toBe('config/settings_data.json')
444-
445-
const validatorConsumers = [
446-
'blocks/quantity.liquid',
447-
'sections/header.liquid',
448-
'sections/header-group.json',
449-
'templates/product.json',
450-
'templates/product.context.uk.json',
451-
]
452-
for (const key of validatorConsumers) {
453-
const index = flat.indexOf(key)
454-
expect(index, `${key} missing from dependent chain`).not.toBe(-1)
455-
expect(index, `${key} should be after settings_schema.json`).toBeGreaterThan(0)
456-
expect(index, `${key} should be before settings_data.json`).toBeLessThan(flat.length - 1)
457-
}
458-
})
459-
460417
test('should create batches for files when bulk upload file count limit is reached', async () => {
461418
// Given
462419
const remoteChecksums: Checksum[] = []

packages/theme/src/cli/utilities/theme-uploader.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface UploadOptions {
2020
multiEnvironment?: boolean
2121
}
2222

23-
export type ChecksumWithSize = Checksum & {size: number}
23+
type ChecksumWithSize = Checksum & {size: number}
2424
type FileBatch = ChecksumWithSize[]
2525

2626
/**
@@ -202,6 +202,7 @@ function getRemoteFilesToBeDeleted(remoteChecksums: Checksum[], themeFileSystem:
202202
}
203203

204204
// Contextual Json Files -> Json Files -> Liquid Files -> Config Files -> Static Asset Files
205+
// Config file consideration: Inverse of the upload order: data first (consumes schema), then schema.
205206
function orderFilesToBeDeleted(files: Checksum[]): Checksum[] {
206207
const fileSets = partitionThemeFiles(files)
207208
return [
@@ -213,7 +214,6 @@ function orderFilesToBeDeleted(files: Checksum[]): Checksum[] {
213214
...fileSets.blockLiquidFiles,
214215
...fileSets.layoutFiles,
215216
...fileSets.otherLiquidFiles,
216-
// Inverse of the upload order: data first (consumes schema), then schema.
217217
...fileSets.configDataFile,
218218
...fileSets.configSchemaFile,
219219
...fileSets.staticAssetFiles,
@@ -317,10 +317,7 @@ function selectUploadableFiles(themeFileSystem: ThemeFileSystem, remoteChecksums
317317
* 1. config/settings_schema.json must be uploaded FIRST. It declares the
318318
* theme-level settings that block / section / section-group / template
319319
* validators resolve dynamic-source defaults against (e.g. defaults of
320-
* the form {{ settings.<theme_setting>.<property> }}). On a fresh
321-
* theme the stored schema is empty, so any later asset whose schema
322-
* references a not-yet-declared theme setting fails server-side
323-
* validation. Uploading the schema first primes those references.
320+
* the form {{ settings.<theme_setting>.<property> }}).
324321
* 2. Layout files don't necessarily need to be the first, but they must be
325322
* uploaded before templates.
326323
* 3. Liquid blocks need to be uploaded before sections
@@ -340,7 +337,7 @@ function selectUploadableFiles(themeFileSystem: ThemeFileSystem, remoteChecksums
340337
* - The static assets
341338
*
342339
*/
343-
export function orderFilesToBeUploaded(files: ChecksumWithSize[]): {
340+
function orderFilesToBeUploaded(files: ChecksumWithSize[]): {
344341
independentFiles: ChecksumWithSize[][]
345342
dependentFiles: ChecksumWithSize[][]
346343
} {
@@ -351,17 +348,13 @@ export function orderFilesToBeUploaded(files: ChecksumWithSize[]): {
351348
independentFiles: [fileSets.otherLiquidFiles, fileSets.otherJsonFiles, fileSets.staticAssetFiles],
352349
// Follow order of dependencies:
353350
dependentFiles: [
354-
// Theme setting declarations must land before any asset that may
355-
// reference them via dynamic-source defaults. See header comment.
356351
fileSets.configSchemaFile,
357352
fileSets.layoutFiles,
358353
fileSets.blockLiquidFiles,
359354
fileSets.sectionLiquidFiles,
360355
fileSets.sectionJsonFiles,
361356
fileSets.templateJsonFiles,
362357
fileSets.contextualizedJsonFiles,
363-
// Settings values reference the schema we just uploaded, plus any
364-
// sections / templates referenced by presets.
365358
fileSets.configDataFile,
366359
],
367360
}
@@ -399,7 +392,7 @@ function calculateLocalChecksums(localThemeFileSystem: ThemeFileSystem): Checksu
399392
localThemeFileSystem.files.forEach((file, key) => {
400393
// Text files: use UTF-8 byte count
401394
// Binary files: use base64 length
402-
const size = file.value ? Buffer.byteLength(file.value, 'utf8') : (file.attachment?.length ?? 0)
395+
const size = file.value ? Buffer.byteLength(file.value, 'utf8') : file.attachment?.length ?? 0
403396

404397
checksums.push({
405398
key,

0 commit comments

Comments
 (0)