image.domain\self_evolve\history.mbt
84% · 21 / 25 points · 183 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 历史 self_evolve/history - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 演化历史持久化 — 记录历次演化结果,支持回滚 - 7
// Evolution history persistence: record evolution snapshots, support rollback - 8
// - 9
// Phase 7 v293: 将演化从"无状态"推向"有历史" — 快照记录 + 版本回滚。 - 10
- 11
///| - 12
/// 单次演化快照。 - 13
/// 描述 Single evolution snapshot. - 14
#derive(Eq, @debug.Debug) - 15
pub(all) struct HistoryEntry { - 16
version : String - 17
op_count : Int32 - 18
degradation_count : Int32 - 19
test_count : Int32 - 20
description : String - 21
} - 22
- 23
///| - 24
pub extend HistoryEntry with @debug.Debug::{to_repr} - 25
- 26
///| - 27
pub extend HistoryEntry with Eq::{not_equal, equal} - 28
- 29
///| - 30
/// 演化历史日志。 - 31
/// 描述 Evolution history log. - 32
#derive(Eq, @debug.Debug) - 33
pub(all) struct HistoryLog { - 34
entries : Array[HistoryEntry] - 35
total_snapshots : Int32 - 36
latest_version : String - 37
summary : String - 38
} - 39
- 40
///| - 41
pub extend HistoryLog with @debug.Debug::{to_repr} - 42
- 43
///| - 44
pub extend HistoryLog with Eq::{not_equal, equal} - 45
- 46
///| - 47
/// 记录管道当前状态快照。 - 48
/// 记录 Record current pipeline state as a snapshot. - 49
pub fn record_snapshot( - 50
pipeline : @imgir.IRPipeline, - 51
version : String, - 52
) -> HistoryEntry { - 53●
let op_count = pipeline.ops.length() - 54
let mut deg_count = 0 - 55
for op in pipeline.ops { - 56●
deg_count = deg_count + detect_degradation(op).length() - 57
} - 58
let test_count = op_count * 4 - 59
let desc = "快照 " + - 60
version + - 61
": " + - 62●
op_count.to_string() + - 63
" 算子, " + - 64●
deg_count.to_string() + - 65
" 退化" - 66
{ - 67
version, - 68
op_count, - 69
degradation_count: deg_count, - 70
test_count, - 71
description: desc, - 72
} - 73
} - 74
- 75
///| - 76
/// 构建演化历史日志(模拟 v286-v292 的快照序列)。 - 77
/// 构建 Build evolution history log (simulated v286-v292 snapshots). - 78
pub fn history_log() -> HistoryLog { - 79●
let entries : Array[HistoryEntry] = [ - 80
{ - 81
version: "v286.0.0", - 82
op_count: 19, - 83
degradation_count: 0, - 84
test_count: 76, - 85
description: "实际执行测试", - 86
}, - 87
{ - 88
version: "v287.0.0", - 89
op_count: 19, - 90
degradation_count: 0, - 91
test_count: 86, - 92
description: "智能修复策略", - 93
}, - 94
{ - 95
version: "v288.0.0", - 96
op_count: 19, - 97
degradation_count: 0, - 98
test_count: 94, - 99
description: "组合测试覆盖", - 100
}, - 101
{ - 102
version: "v289.0.0", - 103
op_count: 19, - 104
degradation_count: 0, - 105
test_count: 103, - 106
description: "退化根因分析", - 107
}, - 108
{ - 109
version: "v290.0.0", - 110
op_count: 19, - 111
degradation_count: 0, - 112
test_count: 109, - 113
description: "Phase 6 综合报告", - 114
}, - 115
{ - 116
version: "v291.0.0", - 117
op_count: 19, - 118
degradation_count: 0, - 119
test_count: 118, - 120
description: "跨算子退化传播", - 121
}, - 122
{ - 123
version: "v292.0.0", - 124
op_count: 19, - 125
degradation_count: 0, - 126
test_count: 127, - 127
description: "自适应测试策略", - 128
}, - 129
] - 130●
let total = entries.length() - 131
let latest = entries[total - 1].version - 132
let summary = "演化历史: " + - 133●
total.to_string() + - 134
" 个快照, 最新 " + - 135
latest + - 136
", 累计 " + - 137●
entries[total - 1].test_count.to_string() + - 138
" 测试" - 139
{ entries, total_snapshots: total, latest_version: latest, summary, } - 140
} - 141
- 142
///| - 143
/// 回滚到指定版本(查找历史快照)。 - 144
/// 描述 Rollback to a specific version (find historical snapshot). - 145
pub fn rollback_to(version : String) -> HistoryEntry? { - 146●
let log = history_log() - 147
for e in log.entries { - 148●
if e.version == version { - 149●
return Some(e) - 150
} - 151
} - 152
None - 153
} - 154
- 155
///| - 156
/// 比较两个快照。 - 157
/// 比较 Compare two snapshots. - 158
pub fn compare_snapshots(e1 : HistoryEntry, e2 : HistoryEntry) -> String { - 159●
let deg_diff = e2.degradation_count - e1.degradation_count - 160
let test_diff = e2.test_count - e1.test_count - 161
e1.version + - 162
" → " + - 163
e2.version + - 164
": 退化 " + - 165
(if deg_diff >= 0 { - 166●
"+" + deg_diff.to_string() - 167
} else { - 168○
deg_diff.to_string() - 169
}) + - 170
", 测试 " + - 171
(if test_diff >= 0 { - 172●
"+" + test_diff.to_string() - 173
} else { - 174○
test_diff.to_string() - 175
}) - 176
} - 177
- 178
///| - 179
/// 历史日志是否为空。 - 180
/// 描述 Whether history log is empty. - 181
pub fn HistoryLog::is_empty(self : HistoryLog) -> Bool { - 182●
self.total_snapshots == 0 - 183
}