image.domain\self_evolve\history.mbt

84% · 21 / 25 points · 183 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

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