feat(hermes): add update backup controls

This commit is contained in:
晴天
2026-05-27 02:33:57 +08:00
parent 77ab060e9c
commit 66a23f861c
8 changed files with 365 additions and 4 deletions

View File

@@ -36,6 +36,16 @@ test('Hermes 配置页会暴露会话维护结构化配置字段', () => {
}
})
test('Hermes 配置页会暴露更新备份结构化配置字段', () => {
for (const id of [
'hm-updates-save',
'hm-updates-pre-update-backup',
'hm-updates-backup-keep',
]) {
assert.match(source, new RegExp(`id="${id}"`), `缺少 ${id}`)
}
})
test('Hermes 配置页会暴露工具循环防护结构化配置字段', () => {
for (const id of [
'hm-tool-guardrails-save',
@@ -514,6 +524,7 @@ test('Hermes 配置页新增结构化配置不会暴露翻译 key', () => {
key.includes('SttConfig') ||
key.includes('KanbanConfig') ||
key.includes('CheckpointsConfig') ||
key.includes('UpdatesConfig') ||
key.includes('ApprovalsConfig') ||
key.includes('CronConfig') ||
key.includes('LoggingConfig') ||

View File

@@ -0,0 +1,59 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import {
buildHermesUpdatesConfigValues,
mergeHermesUpdatesConfig,
} from '../scripts/dev-api.js'
test('Hermes 更新配置读取会提供上游默认值', () => {
const values = buildHermesUpdatesConfigValues({})
assert.deepEqual(values, {
updatesPreUpdateBackup: false,
updatesBackupKeep: 5,
})
})
test('Hermes 更新配置读取会回显 YAML 字段', () => {
const values = buildHermesUpdatesConfigValues({
updates: {
pre_update_backup: true,
backup_keep: 9,
},
})
assert.equal(values.updatesPreUpdateBackup, true)
assert.equal(values.updatesBackupKeep, 9)
})
test('Hermes 更新配置保存会保留未知字段并写入 updates', () => {
const next = mergeHermesUpdatesConfig({
updates: {
pre_update_backup: false,
custom_flag: 'keep-updates',
},
sessions: { auto_prune: true },
model: { provider: 'anthropic' },
}, {
updatesPreUpdateBackup: true,
updatesBackupKeep: '7',
})
assert.deepEqual(next.sessions, { auto_prune: true })
assert.deepEqual(next.model, { provider: 'anthropic' })
assert.equal(next.updates.pre_update_backup, true)
assert.equal(next.updates.backup_keep, 7)
assert.equal(next.updates.custom_flag, 'keep-updates')
})
test('Hermes 更新配置保存会拒绝非法保留数量', () => {
assert.throws(
() => mergeHermesUpdatesConfig({}, { updatesBackupKeep: '0' }),
/updates\.backup_keep/,
)
assert.throws(
() => mergeHermesUpdatesConfig({}, { updatesBackupKeep: '1001' }),
/updates\.backup_keep/,
)
})