You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functioncheckStateMachine(rule,mode,data,previous){// Insert has no prior state — the field-level select check already// constrains the initial value to a declared option.if(mode==='insert'||!previous)returnnull;// ← insert 直接放过
...
}
概述
state_machine验证规则(ADR-0020)在 insert 模式下直接 no-op,因此无法强制记录的初始状态——例如「新建的审批单必须以draft开始,不能直接建成approved」这类约束今天并不生效。packages/objectql/src/validation/rule-validator.tscheckStateMachine:注释的理由是「field-level select 校验已把初始值约束在声明的选项内」——但 select 只保证「值是合法枚举之一」,不保证「是合法的初始状态」。一个 4 级审批 FSM 的
approved也是合法枚举值,select 校验拦不住「初始即 approved」。为什么现在提
这是在 #3043(静态 readonly INSERT 剥离)探索中浮现的:#3043 备选方案 1 曾设想「审批/状态字段叠
state_machine强制初始状态」作为缓解,但该能力今天不存在。属于 ADR-0049「enforce-or-remove」精神下的 declared ≠ enforced 候选,也呼应 AGENTS.md Prime Directive #10。备选方向
state_machine规则一个可选的initial(或initialStates)声明;insert 时校验状态字段值 ∈ 允许的初始态集合。未声明则维持现状(向后兼容)。describe/ 文档里明确state_machine只约束 UPDATE 的 transition,不管初始态;让作者改用defaultValue+readonly(+ 现已修复的 安全/设计:静态 readonly 的 INSERT 豁免让审批/状态字段可在创建时被直接播种(比 #3003 少一步) #3043 INSERT 剥离)来固定初始态。关联
readonlyon INSERT at the data-write ingress (#3043) #3162(探索来源;README 式缓解设想的落空点)