保存模拟部署迁移与最新构建校验阶段成果
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-08 18:33:21 +08:00
1 parent 519e2b4a5f
commit d7837de561
45 files changed
+1588 -109

No files matched your search

+8 -8
View File
@@ -42,15 +42,15 @@ test('前端入口按需加载 Element Plus,并延迟设置页和写信编辑
test('开发启动必须固定运行配置根目录并集中保存日志', async () => {
const content = await read('deploy/start-dev.ps1')
assert.match(content, /\$env:SMAIL_ROOT = \$root\r?\n/)
assert.match(content, /\$env:SMAIL_ROOT = \$runtime\r?\n/)
assert.match(content, /\$legacyConfig = Join-Path \$root 'backend\\config'/)
assert.match(content, /Test-Path -LiteralPath \(Join-Path \$legacyConfig \$name\)/)
assert.match(content, /\$workingDirectory = Join-Path \$root 'out'/)
assert.match(content, /\$workingDirectory = \$runtime/)
for (const name of ['spam_block.exe', 'pmail_telegram_push.exe', 'wechat_push.exe']) assert.ok(content.includes(name))
assert.match(content, /out\\backend\\smail-dev\.exe/)
assert.match(content, /test-log\\runtime/)
assert.match(content, /Join-Path \$runtime 'smail\.exe'/)
assert.match(content, /Join-Path \$runtime 'log'/)
assert.match(content, /-WindowStyle Hidden/)
assert.match(content, /\[switch\]\$SkipBuild/)
assert.doesNotMatch(content, /SkipBuild/)
assert.match(content, /--dev-disable-admin-reset/)
assert.match(content, /SMAIL_HTTP_PORT_OVERRIDE = '5201'/)
assert.match(content, /SMAIL_HTTP_TLS_MODE_OVERRIDE = 'proxy'/)
@@ -59,7 +59,7 @@ test('开发启动必须固定运行配置根目录并集中保存日志', async
assert.match(await read('frontend/.env.development'), /VITE_DEV_BACKEND_URL=http:\/\/127\.0\.0\.1:5201/)
assert.match(await read('frontend/vite.config.js'), /port: 443/)
assert.match(await read('frontend/vite.config.js'), /smail-development-http-redirect/)
assert.match(content, /默认先编译当前工作区/)
assert.match(content, /deploy-runtime\.ps1/)
assert.ok(content.charCodeAt(0) === 0xfeff, 'Windows PowerShell 5 脚本应有 UTF-8 BOM')
})
@@ -74,8 +74,8 @@ test('六个平台默认包含三个插件,构建和发布名称与后端目
assert.ok(catalog.includes(`"${path.basename(item.output)}"`))
}
const files = packagePlan(target)
assert.equal(files.length, 6)
assert.equal(files.filter(file => path.basename(path.dirname(file.target)) === 'plugins').length, 3)
assert.equal(files.length, 2)
assert.equal(files.filter(file => path.basename(path.dirname(file.target)) === 'plugins').length, 0)
assert.ok(files.every(file => file.target.startsWith(path.join(root, 'out', 'package', target))))
}
assert.ok(buildPlan({ development: true }).every(item => path.dirname(item.output) === path.join(root, 'out', 'plugins')))
+61
View File
@@ -0,0 +1,61 @@
import assert from 'node:assert/strict'
import { mkdtemp, mkdir, readFile, writeFile } from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import test from 'node:test'
import { readDevelopmentRuntime, resolveRuntimeFile, runtimeRoot, sourceRoot } from '../../deploy/runtime-config.mjs'
import { fileDigest, sourceFingerprint } from '../../deploy/build-state.mjs'
test('开发配置只从模拟部署目录读取且不返回凭据字段', async () => {
const root = await mkdtemp(path.join(os.tmpdir(), 'smail-runtime-config-'))
await mkdir(path.join(root, 'config'))
await mkdir(path.join(root, 'ssl'))
await writeFile(path.join(root, 'config/config.json'), JSON.stringify({
generation: 9, domains: { web: 'mail.example.test' }, database: { password: 'not-exported' }
}))
await writeFile(path.join(root, 'config/ssl.json'), JSON.stringify({
tls: { certificateRef: 'ssl/public.crt', privateKeyRef: 'ssl/private.key' }
}))
await writeFile(path.join(root, 'ssl/public.crt'), 'certificate')
await writeFile(path.join(root, 'ssl/private.key'), 'key')
const runtime = readDevelopmentRuntime(root)
assert.equal(runtime.origin, 'https://mail.example.test')
assert.equal(runtime.generation, 9)
assert.equal(runtime.privateKeyPath, path.join(root, 'ssl/private.key'))
assert.equal(JSON.stringify(runtime).includes('not-exported'), false)
assert.equal(runtimeRoot, path.join(sourceRoot, 'yunx-test'))
assert.throws(() => resolveRuntimeFile(root, '../outside.key'))
assert.throws(() => resolveRuntimeFile(root, path.join(root, 'ssl/private.key')))
})
test('源码指纹检测编辑且忽略编译嵌入目录', async () => {
const root = await mkdtemp(path.join(os.tmpdir(), 'smail-build-state-'))
for (const name of ['backend', 'frontend', 'plugins/pmail_telegram_push', 'deploy']) {
await mkdir(path.join(root, name), { recursive: true })
}
await writeFile(path.join(root, 'backend/main.go'), 'package main')
const before = await sourceFingerprint(root)
await mkdir(path.join(root, 'backend/dist'))
await writeFile(path.join(root, 'backend/dist/index.html'), 'generated')
assert.equal(await sourceFingerprint(root), before)
await writeFile(path.join(root, 'backend/main.go'), 'package main\n')
assert.notEqual(await sourceFingerprint(root), before)
assert.equal((await fileDigest(path.join(root, 'backend/main.go'))).length, 64)
await writeFile(path.join(root, 'empty.exe'), '')
await assert.rejects(fileDigest(path.join(root, 'empty.exe')))
})
test('部署和启动必须完整构建、验证产物且不覆盖运行配置', async () => {
const read = name => readFile(path.join(sourceRoot, name), 'utf8')
const deploy = await read('deploy/deploy-runtime.ps1')
const start = await read('deploy/start-dev.ps1')
assert.ok(deploy.indexOf("'build.ps1'") < deploy.indexOf('Copy-Item'))
assert.match(deploy, /verify --deployed/)
assert.match(deploy, /deployment-history/)
assert.doesNotMatch(deploy, /Copy-Item[^\n]*(config|data|ssl)/)
assert.doesNotMatch(start, /SkipBuild|SkipFrontend/)
assert.match(start, /\$env:SMAIL_ROOT = \$runtime/)
assert.match(start, /\$workingDirectory = \$runtime/)
assert.match(start, /build-state\.mjs'\) verify --deployed/)
assert.match(await read('.gitignore'), /^\/yunx-test\/$/m)
})