拆分插件三级配置菜单并统一三插件构建打包
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-06 16:22:38 +08:00
1 parent 7d0e84a381
commit 4ea3a39e41
20 files changed
+486 -66

No files matched your search

+29 -1
View File
@@ -45,6 +45,34 @@ test('各协议仅编辑自己的监听端口,邮箱策略没有重复端口
assert.ok(validateFormConfig('smtp', { ...config, listener: { ...config.listener, tlsPort: 587 } })['listener.tlsPort'])
})
test('三个插件页面只展示和编辑自身字段,完整保留其他插件和未知字段', () => {
const config = { meta: { generation: 9 }, plugins: {
spam_block: { enabled: false, settings: { threshold: 20 }, secretStatus: { configured: true } },
telegram_push: { enabled: false, settings: { timeout: 30, futureField: '保留值' } },
wechat_push: { enabled: true, settings: { appId: 'test-only' } },
future_plugin: { enabled: false, settings: ['原样保留'] }
} }
const text = JSON.stringify(config)
for (const id of ['spam_block', 'telegram_push', 'wechat_push']) {
const groups = getFieldGroups(id, config)
assert.equal(groups.length, 1)
assert.equal(groups[0].id, id)
assert.ok(groups[0].fields.every(field => field.path[1] === id))
const edited = readFormConfig(updateFormConfig(text, id, ['plugins', id, 'enabled'], true))
for (const other of Object.keys(config.plugins).filter(key => key !== id)) {
assert.deepEqual(edited.plugins[other], config.plugins[other])
assert.equal(updateFormConfig(text, id, ['plugins', other, 'enabled'], true), text)
}
assert.deepEqual(edited.meta, config.meta)
assert.deepEqual(edited.plugins[id].settings, config.plugins[id].settings)
}
assert.deepEqual(getFieldGroups('wechat_push', { plugins: {} }), [])
const invalidOther = structuredClone(config)
invalidOther.plugins.telegram_push.settings.timeout = 999
assert.deepEqual(validateFormConfig('spam_block', invalidOther), {})
assert.ok(validateFormConfig('telegram_push', invalidOther)['plugins.telegram_push.settings.timeout'])
})
test('文本输入的左右留白属于原生输入框,不影响数字、选择和开关控件', () => {
const require = createRequire(new URL('../../frontend/package.json', import.meta.url))
const { parse, compileStyle } = require('@vue/compiler-sfc')
@@ -85,7 +113,7 @@ test('分组不显示重复标题和介绍,保留无障碍名称、凭据状
assert.doesNotMatch(template, /<h[1-6]\b|form-group-heading|form-group-description|group\.description/)
assert.doesNotMatch(template, /aria-labelledby/)
assert.match(template, /<section\b[^>]*:aria-label="group.title"/)
assert.match(template, /v-if="section === 'plugins'" class="credential-status"/)
assert.match(template, /v-if="group.secretConfigured !== undefined" class="credential-status"/)
assert.match(template, /group.secretConfigured \? '凭据已配置' : '未配置凭据'/)
assert.match(template, /v-if="group.note" class="form-group-note" role="note"/)
assert.match(template, /v-if="!groups.length" class="form-empty"/)
+23 -1
View File
@@ -18,10 +18,20 @@ function fixture(capabilities = ['config.read']) {
return { page, allowed }
}
test('七个菜单对应七个不同页面组件,无权限的维护入口不可打开', async () => {
test('配置菜单包含三个独立插件三级页面,无权限的维护入口不可打开', async () => {
const { page, allowed } = fixture()
assert.equal(new Set(page.sectionOptions.value.map(item => item.component)).size, 7)
assert.deepEqual(page.sectionOptions.value.map(item => item.value), ['base', 'smtp', 'imap', 'pop3', 'email', 'ssl', 'plugins'])
const children = page.sectionOptions.value.find(item => item.value === 'plugins').children
assert.deepEqual(children.map(item => item.value), ['spam_block', 'telegram_push', 'wechat_push'])
await page.selectSection('plugins')
assert.equal(page.selectedSection.value, 'spam_block')
assert.equal(page.activePage.value.label, '垃圾邮件拦截')
await page.selectSection('telegram_push')
assert.equal(page.activePage.value.label, 'Telegram 推送')
await page.selectSection('plugins')
assert.equal(page.selectedSection.value, 'telegram_push')
await page.selectSection('base')
assert.equal(page.maintenanceOptions.value.length, 0)
await page.selectSection('audit')
await page.selectSection('invalid')
@@ -34,6 +44,18 @@ test('七个菜单对应七个不同页面组件,无权限的维护入口不
assert.equal(page.activePage.value, undefined)
})
test('插件三级菜单切换保留离开确认及权限检查', async () => {
const { page, allowed } = fixture()
await page.selectSection('wechat_push')
page.currentPage.value = { beforeLeave: async () => false }
await page.selectSection('spam_block')
assert.equal(page.selectedSection.value, 'wechat_push')
page.currentPage.value = { beforeLeave: async () => { allowed.delete('config.read'); return true } }
await page.selectSection('telegram_push')
assert.equal(page.selectedSection.value, 'wechat_push')
assert.equal(page.activePage.value, undefined)
})
test('切页等待离开确认,取消和快速重复点击不会更改页面', async () => {
const { page } = fixture()
let resolve
+66
View File
@@ -684,3 +684,69 @@ test('共用邮箱分区的候选明确提示其他页面的改动,忽略代
const template = readFileSync(new URL('../../frontend/src/views/components/ConfigSettings/ConfigEditor/ConfigEditor.vue', import.meta.url), 'utf8')
assert.match(template, /:title="pendingScopeHint"/)
})
for (const key of ['spam_block', 'telegram_push', 'wechat_push']) {
test(`${key} 独立页面保留整个插件分区,验证、候选恢复和应用使用统一接口`, async () => {
let active = { meta: { generation: 1 }, plugins: {
spam_block: { enabled: false, executable: 'spam_block.exe', permissions: { network: [] }, settings: { threshold: 20 } },
telegram_push: { enabled: false, executable: 'pmail_telegram_push.exe', settings: { timeout: 30 }, secretStatus: { configured: true }, settingsConfigured: true },
wechat_push: { enabled: false, executable: 'wechat_push.exe', settings: { appId: 'test-only', future: 'preserved' } }
} }
const original = structuredClone(active)
let pending = null
const requests = []
const http = {
get: async path => {
requests.push(path)
return { errorNo: 0, data: path.endsWith('/status') ? { activeGeneration: active.meta.generation }
: path.endsWith('/pending') ? pending : active }
},
put: async (path, body) => {
assert.equal(path, '/api/v1/config/plugins')
assert.equal(body.expectedGeneration, 1)
assert.deepEqual(body.secretChanges, {})
assert.equal(body.payload.plugins.telegram_push.secretStatus, undefined)
assert.equal(body.payload.plugins.telegram_push.settingsConfigured, undefined)
for (const id of Object.keys(original.plugins)) {
assert.deepEqual(body.payload.plugins[id].settings, original.plugins[id].settings)
assert.equal(body.payload.plugins[id].enabled, id === key)
}
pending = { generation: 2, section: 'plugins', sameSession: true, candidateId: 'plugin-test', payload: body.payload }
return { errorNo: 0, data: pending }
},
post: async (path, body) => {
requests.push(path)
if (path.endsWith('/apply')) {
assert.equal(body.generation, 2)
assert.equal(body.candidateId, 'plugin-test')
active = pending.payload
active.meta.generation = 2
pending = null
}
return { errorNo: 0, data: { valid: true } }
}
}
const { page, messages, dispose } = fixture(() => {}, key, { http })
await page.loadAll()
assert.deepEqual(requests, ['/api/v1/config/status', '/api/v1/config/plugins', '/api/v1/config/pending'])
assert.equal(page.selectedSection.value, key)
page.updateField(['plugins', key, 'enabled'], true)
await page.validateConfig()
await page.saveConfig()
assert.ok(requests.includes('/api/v1/config/plugins/validate'))
assert.match(page.pendingScopeHint.value, new RegExp(`本次候选涉及:${page.currentSection.value.label}。`))
const other = Object.keys(original.plugins).find(id => id !== key)
page.updateField(['plugins', other, 'enabled'], true)
assert.equal(page.formConfig.value.plugins[other].enabled, false)
dispose()
const restored = fixture(() => {}, other, { http }).page
await restored.loadAll()
assert.equal(restored.savedGeneration.value, 2)
assert.match(restored.pendingScopeHint.value, /三个插件共用一个配置分区/)
assert.ok(restored.pendingScopeHint.value.includes(page.currentSection.value.label))
await restored.applyConfig()
assert.ok(requests.includes('/api/v1/config/plugins/apply'))
assert.equal(restored.savedGeneration.value, 0)
assert.deepEqual(messages, [])
})
}
+29 -2
View File
@@ -3,6 +3,8 @@ import { readFile } from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import test from 'node:test'
import { buildPlan, hostTarget, plugins, targets } from '../../deploy/build-plugins.mjs'
import { packagePlan } from '../../deploy/package.mjs'
const root = fileURLToPath(new URL('../../', import.meta.url))
const read = relative => readFile(path.join(root, relative), 'utf8')
@@ -10,7 +12,7 @@ const read = relative => readFile(path.join(root, relative), 'utf8')
test('跨平台构建输出不得越过项目 out 目录', async () => {
const content = await read('Makefile')
const commands = [...content.matchAll(/cd ([^\s]+) && [^\n]*go build [^\n]* -o ([^\s]+) /g)]
assert.equal(commands.length, 30)
assert.equal(commands.length, 12)
for (const [, directory, output] of commands) {
const relative = path.relative(path.join(root, 'out'), path.resolve(root, directory, output))
assert.ok(relative && !relative.startsWith('..') && !path.isAbsolute(relative), output)
@@ -31,13 +33,38 @@ test('开发启动必须固定运行配置根目录并集中保存日志', async
assert.match(content, /\$env:SMAIL_ROOT = \$root\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 'backend'/)
assert.match(content, /\$workingDirectory = Join-Path \$root 'out'/)
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, /-WindowStyle Hidden/)
assert.ok(content.charCodeAt(0) === 0xfeff, 'Windows PowerShell 5 脚本应有 UTF-8 BOM')
})
test('六个平台默认包含三个插件,构建和发布名称与后端目录完全匹配', async () => {
const catalog = await read('backend/plugins/catalog/catalog.go')
for (const target of targets) {
const plan = buildPlan({ target })
assert.equal(plan.length, 3)
assert.deepEqual(plan.map(item => item.id), plugins.map(item => item.id))
for (const item of plan) {
assert.equal(path.dirname(item.output), path.join(root, 'out', 'plugins', target))
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.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')))
assert.throws(() => buildPlan({ target: '../invalid' }))
assert.throws(() => buildPlan({ plugin: 'unknown' }))
assert.throws(() => buildPlan({ development: true, target: targets.find(target => target !== hostTarget()) }))
assert.match(await read('deploy/build.ps1'), /build-plugins\.mjs'\) --dev/)
assert.match(await read('Makefile'), /package: build_server plugin/)
assert.match(await read('.github/workflows/release.yml'), /node deploy\/build-plugins\.mjs --target=/)
})
test('安全工作流必须先构建嵌入资源再执行 Go 测试', async () => {
for (const file of ['.github/workflows/release.yml', '.github/workflows/security.yml']) {
const content = (await read(file)).split(' security:')[1]
+16
View File
@@ -62,6 +62,22 @@ test('一级菜单保留能力过滤和当前分类标题联动', () => {
assert.equal(page.activeSettings.value, undefined)
})
test('三级菜单只发送当前分组的可见子项,选中状态仍由父页面确认', () => {
const props = reactive({ modelValue: 'spam_block', items: [{ value: 'plugins', children: [{ value: 'spam_block' }, { value: 'telegram_push' }] }] })
const events = []
const { select } = useSubmenu(props, (...event) => events.push(event))
select('unknown')
select('spam_block')
select('telegram_push')
assert.deepEqual(events, [['select', 'telegram_push']])
assert.equal(props.modelValue, 'spam_block')
props.items = []
select('telegram_push')
assert.equal(events.length, 1)
assert.match(read('SettingsSubmenu/SettingsSubmenu.vue'), /settings-tertiary-list/)
assert.match(read('SettingsSubmenu/SettingsSubmenu.css'), /\.settings-tertiary-item:focus-visible/)
})
test('菜单模板可编译并保留按钮、当前项语义及原有选区处理器', () => {
for (const name of ['HomeHeader', 'SettingsSubmenu', 'SecuritySettings', 'ConfigSettings']) {
const source = read(`${name}/${name}.vue`)