优化: 知识检索同项目加权与拒绝池
This commit is contained in:
@@ -46,15 +46,21 @@ pub struct KnowledgeSearchInput {
|
||||
|
||||
/// 状态转换合法矩阵校验
|
||||
///
|
||||
/// candidate → pending_review | published | archived
|
||||
/// pending_review → published | archived
|
||||
/// candidate → pending_review | published | rejected | archived
|
||||
/// pending_review → published | rejected | archived
|
||||
/// published → archived
|
||||
/// rejected → candidate(重新送审;rejected 独立分池语义:拒绝≠归档,
|
||||
/// 被否决的知识可修改后重审,也可留在拒绝池沉淀——与 archived 分开可见)
|
||||
/// archived → published(归档箱恢复;2026-10-05 归档功能尾巴——原 archived 为汇点,
|
||||
/// 归档即不可逆,与项目/任务/灵感/会话归档「可逆语义」不一致)
|
||||
/// (其他组合非法)
|
||||
fn validate_transition(from: &str, to: &str) -> Result<(), String> {
|
||||
let legal = match from {
|
||||
"candidate" => matches!(to, "pending_review" | "published" | "archived"),
|
||||
"pending_review" => matches!(to, "published" | "archived"),
|
||||
"candidate" => matches!(to, "pending_review" | "published" | "rejected" | "archived"),
|
||||
"pending_review" => matches!(to, "published" | "rejected" | "archived"),
|
||||
"published" => matches!(to, "archived"),
|
||||
"rejected" => matches!(to, "candidate"),
|
||||
"archived" => matches!(to, "published"),
|
||||
_ => false,
|
||||
};
|
||||
if legal {
|
||||
@@ -500,6 +506,8 @@ mod tests {
|
||||
fn pending_review_legal_transitions() {
|
||||
assert!(validate_transition("pending_review", "published").is_ok());
|
||||
assert!(validate_transition("pending_review", "archived").is_ok());
|
||||
// 分池:审核否决走 rejected(独立池),不再混入 archived
|
||||
assert!(validate_transition("pending_review", "rejected").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -524,9 +532,32 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn archived_is_terminal() {
|
||||
// 归档为终态,任何转换都非法
|
||||
for to in ["candidate", "pending_review", "published", "archived"] {
|
||||
fn archived_restore_to_published_legal() {
|
||||
// 归档箱恢复(2026-10-05 归档功能尾巴):archived → published 唯一出边
|
||||
assert!(validate_transition("archived", "published").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejected_legal_transitions() {
|
||||
// 分池语义:rejected 唯一出边=回 candidate 重新送审(修改后重审)
|
||||
assert!(validate_transition("candidate", "rejected").is_ok());
|
||||
assert!(validate_transition("pending_review", "rejected").is_ok());
|
||||
assert!(validate_transition("rejected", "candidate").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejected_illegal_transitions() {
|
||||
// 拒绝池不可直接发布(必须走重审 candidate → published)、不可归档/自转
|
||||
for to in ["published", "pending_review", "archived", "rejected"] {
|
||||
assert!(validate_transition("rejected", to).is_err(),
|
||||
"rejected → {to} 应为非法");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn archived_illegal_transitions() {
|
||||
// 归档态除恢复发布外均非法(不回 candidate/pending_review,不自转)
|
||||
for to in ["candidate", "pending_review", "archived"] {
|
||||
assert!(validate_transition("archived", to).is_err(),
|
||||
"archived → {to} 应为非法");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user