92 lines
5.3 KiB
JavaScript
92 lines
5.3 KiB
JavaScript
'use strict'
|
||
|
||
const assert = require('assert')
|
||
const fs = require('fs')
|
||
const path = require('path')
|
||
const vm = require('vm')
|
||
|
||
const root = path.resolve(__dirname, '..')
|
||
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
|
||
const build = fs.readFileSync(path.join(root, 'scripts', 'build.js'), 'utf8')
|
||
const migrationSource = fs.readFileSync(path.join(root, 'src', 'storage-migrations.js'), 'utf8')
|
||
const migrationSandbox = {}
|
||
vm.runInNewContext(migrationSource, migrationSandbox)
|
||
const migrations = migrationSandbox.IWBStorageMigrations
|
||
|
||
assert.match(pkg.version, /^\d+\.\d+\.\d+(-[\w.]+)?$/) // 允许 SemVer pre-release 后缀(如 3.1.0-pre.1)
|
||
// P4-16a:src/ + app.js 的 ESLint 门禁不得被静默摘除(lint 脚本存在且 verify 链里真的调用它)
|
||
assert.strictEqual(pkg.scripts.lint, 'eslint src app.js')
|
||
assert.ok(/\bnpm run lint\b/.test(pkg.scripts['verify:ci']), 'verify:ci 必须包含 npm run lint')
|
||
assert.strictEqual(pkg.scripts.verify, 'npm run verify:ci && npm run test:e2e', 'verify 必须由 verify:ci + test:e2e 组合而成(单一来源,防漂移)')
|
||
assert.ok(typeof pkg.devDependencies.eslint === 'string' && typeof pkg.devDependencies.globals === 'string')
|
||
assert.ok(fs.existsSync(path.join(root, 'eslint.config.js')), 'eslint.config.js 必须存在')
|
||
assert.strictEqual(JSON.stringify(migrations.current), JSON.stringify({ workspace: 1, canvas: 1, backup: 2, groups: 1 }))
|
||
const legacyWorkspace = migrations.migrateWorkspace({ workspaces: [], activeId: '', rev: 0 })
|
||
assert.strictEqual(legacyWorkspace.ok, true)
|
||
assert.strictEqual(legacyWorkspace.value.schemaVersion, 1)
|
||
assert.strictEqual(legacyWorkspace.value.workspaces.length, 1)
|
||
assert.strictEqual(migrations.migrateWorkspace({ schemaVersion: 99 }).code, 'unsupported-schema')
|
||
assert.strictEqual(migrations.migrateWorkspace(null).code, 'invalid-schema')
|
||
const legacyCanvas = migrations.migrateCanvas({ app: 'image-workbench', nodes: [] })
|
||
assert.strictEqual(legacyCanvas.ok, true)
|
||
assert.strictEqual(legacyCanvas.value.schemaVersion, 1)
|
||
assert.strictEqual(migrations.migrateCanvas({ schemaVersion: 99 }).code, 'unsupported-schema')
|
||
const legacyGroups = { groups: [{ id: 'g1' }], groupGroups: [{ id: 'gg1' }] }
|
||
const migratedGroups = migrations.migrateGroups(legacyGroups)
|
||
assert.strictEqual(migratedGroups.ok, true)
|
||
assert.strictEqual(migratedGroups.value.schemaVersion, 1)
|
||
assert.strictEqual(JSON.stringify(legacyGroups), JSON.stringify({ groups: [{ id: 'g1' }], groupGroups: [{ id: 'gg1' }] }))
|
||
assert.strictEqual(migrations.migrateGroups({ schemaVersion: 99 }).code, 'unsupported-schema')
|
||
const legacyBackup = migrations.migrateBackup({ kind: 'backup', items: {} })
|
||
assert.strictEqual(legacyBackup.ok, true)
|
||
assert.strictEqual(legacyBackup.value.schemaVersion, 2)
|
||
assert.strictEqual(migrations.migrateBackup({ schemaVersion: 99 }).code, 'unsupported-schema')
|
||
assert.strictEqual(migrations.migrateBackup([]).code, 'invalid-schema')
|
||
assert.match(build, /version\.json/)
|
||
assert.match(build, /rev-parse['\", ]+['\"]--short=7['\", ]+['\"]HEAD/)
|
||
assert.match(build, /appWithBuildMeta/)
|
||
assert.match(build, /gallery-query\.js/)
|
||
assert.match(build, /gallery-hydration\.js/)
|
||
assert.match(build, /storage-result\.js/)
|
||
assert.match(build, /runtime-error\.js/)
|
||
assert.match(build, /runtime-lifecycle\.js/)
|
||
assert.match(build, /runtime-fetch\.js/)
|
||
assert.match(build, /runtime-channel\.js/)
|
||
assert.match(build, /runtime-boundary\.js/)
|
||
assert.match(build, /runtime-record\.js/)
|
||
assert.match(build, /runtime-recovery\.js/)
|
||
assert.match(build, /runtime-diagnostic-record\.js/)
|
||
assert.match(build, /runtime-metrics\.js/)
|
||
assert.match(build, /runtime-run-context\.js/)
|
||
assert.match(build, /runtime-execution-context\.js/)
|
||
assert.ok(fs.existsSync(path.join(root, 'src', 'runtime-fetch.js')))
|
||
assert.ok(fs.existsSync(path.join(root, 'src', 'runtime-channel.js')))
|
||
assert.ok(fs.existsSync(path.join(root, 'src', 'runtime-boundary.js')))
|
||
assert.ok(fs.existsSync(path.join(root, 'src', 'runtime-record.js')))
|
||
assert.ok(fs.existsSync(path.join(root, 'src', 'runtime-recovery.js')))
|
||
assert.ok(fs.existsSync(path.join(root, 'src', 'runtime-diagnostic-record.js')))
|
||
assert.ok(fs.existsSync(path.join(root, 'src', 'runtime-metrics.js')))
|
||
assert.match(build, /storage-health\.js/)
|
||
assert.match(build, /generation-state\.js/)
|
||
assert.match(build, /runtime-diagnostics\.js/)
|
||
assert.match(build, /runtime-record\.js/)
|
||
assert.match(build, /runtime-recovery\.js/)
|
||
assert.match(build, /runtime-diagnostic-record\.js/)
|
||
assert.match(build, /runtime-metrics\.js/)
|
||
assert.ok(fs.existsSync(path.join(root, 'src', 'runtime-error.js')))
|
||
assert.ok(fs.existsSync(path.join(root, 'src', 'runtime-lifecycle.js')))
|
||
assert.match(build, /storage-local\.js/)
|
||
assert.match(build, /storage-indexeddb\.js/)
|
||
assert.match(build, /storage-workspace\.js/)
|
||
assert.match(build, /storage-groups\.js/)
|
||
assert.match(build, /storage-outputs\.js/)
|
||
assert.match(build, /storage-backup\.js/)
|
||
assert.match(build, /runtime-constants\.js/)
|
||
assert.match(build, /canvas-store\.js/)
|
||
assert.ok(fs.existsSync(path.join(root, 'src', 'canvas-store.js')))
|
||
assert.ok(fs.existsSync(path.join(root, 'src', 'storage-backup.js')))
|
||
assert.ok(fs.existsSync(path.join(root, 'dist', 'version.json')))
|
||
assert.ok(fs.existsSync(path.join(root, 'app.js')))
|
||
assert.ok(fs.existsSync(path.join(root, 'tests', 'iwb-stability.spec.js')))
|
||
console.log('unit checks passed')
|