forked from EduCraft/curriculum-project-hub
c684d25d50
Spec母本噪音清理 + 一处 spec↔impl 对齐 + 一处契约自洽修正。 Part A — spec doc 瘦身:每条 doc 收到"语义点 + 标签 + ADR ref + 承载性 why", 把跨文件复读的方法论(element-kind 开放性对比、likec4 画不出、分歧点测试)上移到 module header。OPEN 框架保持清晰(RunState/Capability 完整性仍明示须 surface)。 Part B — Courseware/ 由 10 文件平铺重组为 Model/ Export/ Check/ Open/ 四子命名空间 (namespace Spec.Courseware 不变,零引用改动)+ 四个子 aggregator。lake build 绿(24 jobs)。 Part C — 渲染覆盖落为数据(ADR-0011 对齐):去掉 cph-check 里硬编码的 COVERED_TARGETS,改读 TargetConfig.covers。cph-model 新增 covers: Option<Vec<String>> (None=未声明,由 cph-check 默认为全部 known kinds;显式 [] 表示不覆盖任何 kind)。 新增 3 个覆盖行为测试。 ADR-0012 — DanglingReference 退役(诊断 7→6 类):其两种情形(未解析 @ref、越界/缺失 相对 import)都是 typst 编译期失败,归 typstCompile。同步移除 Oracle.refsResolve (被 compiles 蕴含),Legal 少一个合取项。impl 删去从未被发射的 DiagCode::DanglingReference, 闭合 named-but-unemitted 的 spec↔impl 缝。ADR-0010 加修订指针。 OPEN 点(RunState/Capability 完整性、QuestionBank、Course)按既定纪律保持 OPEN,本次 只改善其框架措辞,不决策。 验证:spec lake build 绿;cargo test 全绿(含新增覆盖测试);clippy 静默; TH-141 check 0 errors/0 warnings 无回归。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
67 lines
2.7 KiB
Lean4
67 lines
2.7 KiB
Lean4
import Spec.Prelude
|
|
|
|
/-!
|
|
# Permission —— 角色、能力与授权
|
|
|
|
ADR-0004:权限走"飞书云文档式"——grant(`resource + principal + role`)与 settings
|
|
分离;role 取自封闭的 `read / edit / manage`,且 **read ⊂ edit ⊂ manage** 累积赋能;
|
|
强制释放锁是 **admin-only**,在 role 体系之外。本模块把这套结构与"高 role 含低
|
|
role 全部能力"的单调性钉死。
|
|
-/
|
|
|
|
namespace Spec.System
|
|
|
|
/-- 协作者角色(`PINNED` 封闭, ADR-0004 逐字 "roles are read, edit, or manage")。 -/
|
|
inductive Role where
|
|
| read
|
|
| edit
|
|
| manage
|
|
|
|
/-- 角色赋能层级(`PINNED` 序, ADR-0004 read⊂edit⊂manage 数值化)。仅服务于
|
|
`Role.le` 与能力推导,不对外承诺"层级就是 `Nat`"。 -/
|
|
def Role.level : Role → Nat
|
|
| .read => 0
|
|
| .edit => 1
|
|
| .manage => 2
|
|
|
|
/-- 角色偏序:`r₁ ≤ r₂` 即 `r₁` 赋能不强于 `r₂`(`PINNED`, ADR-0004)。 -/
|
|
def Role.le (r₁ r₂ : Role) : Prop := r₁.level ≤ r₂.level
|
|
|
|
/-- 受 role 调控的操作能力(各项 `PINNED` 取自 ADR-0004;**枚举完整性 `OPEN`**——
|
|
这是 ADR 当前点名的能力,不保证穷尽,新增产品操作时可能扩)。注意 force-release
|
|
**不在此列**——它是 admin-only override,见 `RequiresAdmin`。 -/
|
|
inductive Capability where
|
|
| view
|
|
| discussComment
|
|
| editArtifact
|
|
| triggerAgent
|
|
| answerChoiceCard
|
|
| manageCollaborators
|
|
| projectSettings
|
|
| groupBinding
|
|
| normalCancel
|
|
|
|
/-- 某能力所**要求的最低角色**(`PINNED`, ADR-0004 各 role 能力展开)。授权判定
|
|
`Role.can` 据此定义,"谁能做什么"只有这一处真相。 -/
|
|
def Capability.requiredRole : Capability → Role
|
|
| .view => .read
|
|
| .discussComment | .editArtifact | .triggerAgent | .answerChoiceCard => .edit
|
|
| .manageCollaborators | .projectSettings | .groupBinding | .normalCancel => .manage
|
|
|
|
/-- 角色 `r` **具备**能力 `c`(`PINNED`, ADR-0004)。定义为"`c` 的最低角色 ≤ `r`",
|
|
这一处同时编码了 read⊂edit⊂manage 的累积性。 -/
|
|
def Role.can (r : Role) (c : Capability) : Prop := c.requiredRole |>.le r
|
|
|
|
/-- **单调性**:`r₁ ≤ r₂` 且 `r₁` 能做 `c` ⇒ `r₂` 也能(`PINNED` 定理, ADR-0004 累积
|
|
赋能的形式化保证)。证明即偏序传递性,得益于 `can` 按"最低角色阈值"定义。 -/
|
|
theorem Role.can_mono {r₁ r₂ : Role} {c : Capability}
|
|
(h : r₁.le r₂) (hc : r₁.can c) : r₂.can c :=
|
|
Nat.le_trans hc h
|
|
|
|
/-- **强制释放锁**要求 admin,**在 role 体系之外**(`PINNED`, ADR-0004 admin-only
|
|
override)。即便 `manage` 也不经 `Role.can` 获得它,故它不是 `Capability` 而是独立
|
|
谓词;`isAdmin` 由平台另行判定(本层不建 admin 模型)。 -/
|
|
def RequiresAdmin (isAdmin : Prop) : Prop := isAdmin
|
|
|
|
end Spec.System
|