Repository navigation
refactor(operator): 多身份模型收敛 — 语义契约 + P1~P5 落地 - #312
Merged
Merged
Conversation
P1 相等收敛: - OperatorKey 新增 matches(key, mode) / identityEquals(identity) / of(IFlowOperator) - OperatorIdentityMatchMode 由「被外部 if 判断的枚举」改为策略,自己实现 match 与 identityDistinguishes - OperatorIdentityPolicy#matches/sameOperator 改为委托,删除重复的 id+身份比较逻辑 - OperatorManager 去掉 getOperator(long) / getOperator(long,String) 两个重叠重载,收为一个 match(IFlowOperator) - FlowOperatorLocalThreadCache#isIdentityMatched 改为委托 identityEquals P2 键收敛(参与人键部分): - OperatorKey#key() 成为唯一键生成点,分隔符常量收敛为 1 份(改为 U+0001,身份不可能包含) - OperatorKey#key(mode) 承接「模式是否区分身份」,调用方不再自行判断模式后拼键 - 缓存键、身份告警去重键、当前节点待审批人去重键全部改用 OperatorKey - 删除 4 份重复的分隔符声明(cache/guard/todoKey/FlowContent 各自一份) 行为零变化:现有身份相关测试断言未修改。 Refs #311
- 新增 record/TodoMergeKey:基础段 {人员id}-{workRuntimeId}-{nodeId} 不可变,
严格模式且身份非默认时追加 #identity,仅人员模式不追加
- FlowRecord#getTodoKey() 只保留「谁参与合并」的领域决策,键拼装委托 TodoMergeKey
- 删除 FlowRecord 自declared 的 IDENTITY_KEY_SUFFIX 与手写 String.format 拼装
- OperatorIdentity.KEY_SEPARATOR 更名为 RESERVED_KEY_MARK,语义明确为「身份保留字符」,
TodoMergeKey 引用同一常量
- 新增 TodoMergeKeyTest 锁住三种格式
Refs #311
…,匹配模式策略化 P3 模式策略化: - OperatorIdentityPolicy → OperatorIdentityContext:它只持有当前模式并传递,判定逻辑不再复制一份 - 删除 reset()(测试专用静态清理),改为 use(mode),测试显式设定与还原 - 4 处「请求人 vs 记录当前办理人」的重复校验收敛为 FlowRecord#verifyOperator(OperatorKey) - 新增 FlowRecord#currentOperatorKey(),调用方不再把 (id, identity) 拆开传 - 8 个调用点改为 OperatorKey + Context,方法体里不再有 if (mode == USER_ONLY) - starter: OperatorIdentityPolicyRegister → OperatorIdentityConfigurer 行为零变化:framework 全量 539 个测试通过。 Refs #311
P4 对象化(#308、#311): - OperatorScriptResultResolver:4 个静态 resolve 重载 → 构造注入 (IRepositoryHolder, scriptType) + 单个 resolve(result) - 解析主流程拆为「归一化 → 元素化 → 批量回查 → 按序还原」,五段 instanceof + continue 下沉为元素对象 - 新增 OperatorScriptElement(sealed,Direct/Pending 各自回答「是否有效」「对应谁」) - 新增 PendingOperators:键集合 + 仓储即状态,按身份分组一次查完,替代原 batchResolve 私有函数 - OperatorAssignmentService:静态函数集合 → 构造注入 FlowSession;hasAssignment(nodeId) / assign(processId, selections) - 新增 OperatorSelections:两种表达形式(id / key)归并为一种,携带身份优先的规则只有一个定义点 - FlowActionService / FlowCreateService 的 if-else 二选一消失,改为传 OperatorSelections 行为零变化:framework 全量 550 个测试通过(含新增 20 个)。 Closes #308
P5 类型化(#311): - OperatorIdentity:静态工具类 + 常量集合 → 不可变值对象(of / value / isDefault / validate / equals) - 归一化、判等、校验收为实例语义,全仓调用点迁移为 of(x).value() / .isDefault() / .equals(...) - OperatorIdentity.pick 与三个请求头常量移入接入层 OperatorIdentityHeader(starter-api), 查询侧复用同一份常量(query → api 依赖) - OperatorIdentityGuard → diagnostic.OperatorIdentityWarnLog:可观测性组件移出领域包, 去重状态由静态集合改为实例字段,删除测试专用 resetWarnedCache() - 规范文档同步落地记录与 API 变更清单 行为零变化:全仓 6 个模块测试通过(framework 554)。 Refs #311
This was referenced Dec 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
这次做了什么
把「多身份」这一族类按 #311 的 P1~P5 全部落地,行为零变化(同类测试断言未因行为修改过),并把规范从「纸面」变成「可执行」。
分支:
refactor/operator-identity(基线dev),未合并。五个批次
docs/conventions/domain/operator-identity.md+design/model-design.md;AGENTS.md/CLAUDE.md增硬线OperatorKey#matches成为唯一判定入口;MatchMode变策略;OperatorManager去掉 2 个重叠重载OperatorKey#key(mode)唯一;新增TodoMergeKey;分隔符常量 4 份 → 1 份Policy→OperatorIdentityContext;删reset();4 处权限校验收敛为FlowRecord#verifyOperatorOperatorScriptElement、PendingOperators、OperatorSelectionsOperatorIdentity变值对象;请求头解析移接入层;告警移出领域包关键判断
1. 病根不是静态方法,是身份没有成为类型。
盘点时发现同一语义有 5 处判定、5 处拼键、4 份分隔符声明。加一种匹配模式要改 3 处,漏一处就是半开状态——#297 的「能审批不能撤回」正是这样产生的。
2. H4 按实现事实改写了。
原稿写「匹配模式不得改变存储键格式」,但
USER_ONLY下同人两个身份必须合并成一条待办,这是业务事实,禁止不了。改成「影响必须经由键模型」:模式只给键模型一个布尔语义(identityDistinguishes()),键格式在OperatorKey#key(mode)与TodoMergeKey#value()各定义一次,迁移服务复用同一模型。3.
OperatorManager.match固定严格口径,不跟运行时模式。配置里写的是「某个人以某身份参与」,若 USER_ONLY 也放宽到只比 id,「配置了部门A的张三」会被部门B的张三命中,属越权。已补测试锁死。
4. 「带身份优先」原来是两处 if/else。
发起与办理两条路径各写一遍,一旦不一致就会出现「带身份的设定被静默忽略」。收进
OperatorSelections后只有一个定义点。验证
./mvnw test:framework 545 / infra 8 / api 7 / starter 10 / example 7,全绿OperatorKeyTest、OperatorManagerTest、TodoMergeKeyTest、OperatorIdentityContextTest、OperatorScriptElementTest、OperatorSelectionsTest、OperatorIdentityWarnLogTest破坏性变更(集成方需注意)
OperatorIdentity.normalize/isDefault/same/validateof(x).value()/.isDefault()/.equals(...)/.validate().value()OperatorIdentity.DEFAULT(String)OperatorIdentity.DEFAULT.value()OperatorIdentityPolicy.setMatchMode/matchMode/resetOperatorIdentityContext.getInstance().use/matchMode(reset删除)OperatorIdentity.pick+HEADER_*api.OperatorIdentityHeader.resolve/OPERATOR_IDENTITY等OperatorIdentityGuard.checkdiagnostic.OperatorIdentityWarnLog.getInstance().warnOnceOperatorScriptResultResolver.resolve(holder, result, type)new OperatorScriptResultResolver(holder, type).resolve(result)OperatorAssignmentService.validateAndSave*new OperatorAssignmentService(session).assign(processId, selections)OperatorManager.getOperator(long[, String])match(IFlowOperator)未做(需单独版本窗口)
OperatorKey内部仍以String存身份(identity()返回String)。改为OperatorIdentity字段属公开签名变更,影响约百处调用,按 H1 的渐进策略留待后续。验收记录(2026-12-03 补充)
一、单元测试改动审计
结论:修改了单元测试,但没有断言被删除或放宽,全部改动可追溯到本次公开 API 变更。
OperatorIdentityHeaderResolveTest→starter-api/OperatorIdentityHeaderTest)@Disabled/ 跳过四类改动理由:
OperatorIdentity.isDefault(x)→of(x).isDefault(),期望值与语义未变。OperatorIdentityPolicy.setMatchMode(X)→OperatorIdentityContext.getInstance().use(X);reset()→use(STRICT),语义等价且去掉隐含依赖。OperatorScriptResultResolverTest13 个用例断言全保留,仅把静态调用换成new OperatorScriptResultResolver(holder, type).resolve(x)(文件内 3 行私有包装,让新语义在用例中显式可见)。OperatorIdentityGuardTest(5) →OperatorIdentityWarnLogTest(5+1),OperatorIdentityPolicyTest(4) →OperatorIdentityContextTest(6)。新增用例含一条防漂移护栏:穷举 2 种模式 × 3 种身份,断言context.matches与OperatorKey#matches结果完全一致。模块用例数:framework 518 → 545(-9 随类删除、-5 迁移至 api 模块、+41 新增)。
二、前后端本地运行 + 点击验证
后端用本分支代码启动(
../flow-engine-identity/flow-engine-example,端口 8090,全新 H2 库),前端 app-pc dev server(3000)代理至 8090,演示数据由IdentityDemoInitializer从零生成。点击路径与结果:
department1/ 张三·默认身份),身份标签渲染正常。department1的待办 → 通过,多身份语义收口:身份只影响脚本与留痕,不阻断同人办理(演示层放开身份限制) #297 核心场景(同人跨身份审批)成立。department1身份办理默认身份的待办 → 通过。record.urge.limit拦截。接口层交叉核对(最关键的身份语义):
department1''''department1归属身份未被办理行为改写、办理身份按当前操作身份留痕,与契约 H4 一致。另验证:张三持
department2身份查待办total=0,李四department2的待办未泄露。三、合并方式
请人工 review 后手动合并,不启用自动合并。 当前 PR 未设置 auto-merge,状态
CLEAN、无冲突。若希望分批合并,commit 已按 P0→P5 切好,可逐个 cherry-pick。