feat(dict-dataupdate): v0.11e+ dirty check (Phase A2)

dict/dataupdate.ts:
- 加 --expected-enCode/--force 选项
- 跑 dirty check (A2 防 AI 误覆盖)
This commit is contained in:
ssw committed 2026-06-27 06:18:24 +08:00
1 parent e83a1a7b52
commit 888bc42bb8
1 file changed
+24 -1
+24 -1
View File
@@ -9,6 +9,7 @@ import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
import { initWebapi, loadDict } from '../../webapi/dict.ts'
import { dirtyCheck, dirtyCheckFailAndExit } from '../_dirty_check.ts'
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
interface Opts {
@@ -17,18 +18,22 @@ interface Opts {
fullName?: string
sortCode?: string
enabledMark?: string
expectedEnCode?: string
force?: boolean
json?: boolean
}
export function buildDictDataUpdateCommand(): Command {
const cmd = new Command('dataUpdate')
.alias('data-update')
.description('字典项修改 (改名/排序/启用, PUT 语义, v0.11+ webapi)')
.description('字典项修改 (改名/排序/启用, PUT 语义, v0.11+ webapi + v0.11e+ dirty check)')
.requiredOption('--id <id>', '字典项 id')
.option('--enCode <e>', '字典项编码')
.option('--fullName <n>', '字典项名')
.option('--sortCode <s>', '排序', (v) => parseInt(v, 10))
.option('--enabledMark <0|1>', '启用/禁用')
.option('--expected-enCode <e>', 'v0.11e+ Phase A2: 校验 enCode 未变 (防 AI session 误覆盖)')
.option('--force', 'v0.11e+ Phase A2: 跳过 dirty check', false)
.option('--json', '原始 JSON 输出', false)
.action(async (opts: Opts) => {
const c = await JnpfClient.fromToken()
@@ -40,6 +45,24 @@ export function buildDictDataUpdateCommand(): Command {
log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '配置拉取' })}`)
process.exit(1)
}
// v0.11e+ Phase A2: dirty check (防 AI session 误覆盖)
const dirtyResult = dirtyCheck({
expectedEnCode: opts.expectedEnCode,
force: opts.force,
current: {
enCode: orig.enCode as string | undefined,
state: orig.enabledMark as string | number | undefined,
fullName: orig.fullName as string | undefined,
type: 'di',
},
id: opts.id,
})
if (!dirtyResult.ok) {
dirtyCheckFailAndExit(dirtyResult, { type: 'di', id: opts.id, current: { enCode: orig.enCode as string | undefined, fullName: orig.fullName as string | undefined } }, log.error)
} else if (dirtyResult.skipped) {
log.info(`⚠ dirty check 已 --force 跳过`)
}
const body: Record<string, unknown> = { ...orig, id: opts.id }
if (opts.enCode) body.enCode = opts.enCode
if (opts.fullName) body.fullName = opts.fullName