image.domain\self_evolve\regression.mbt

60% · 15 / 25 points · 168 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/regression
  3. 3///
  4. 4/// 图像处理库子模块
  5. 5/// 图像处理库子模块 Image processing library submodule
  6. 6// 跨版本回归检测 — 检测版本间退化回归
  7. 7// Cross-version regression detection: detect degradation regressions across versions
  8. 8//
  9. 9// Phase 9 v302: 将演化从"调度"推向"回归检测" — 比较历史快照,发现退化回归。
  10. 10
  11. 11///|
  12. 12/// 回归类型。
  13. 13/// 描述 Regression kind.
  14. 14/// `#non_exhaustive` 表示未来可能添加新构造器
  15. 15#derive(Eq, @debug.Debug)
  16. 16#non_exhaustive
  17. 17pub(all) enum RegressionKind {
  18. 18 DegradationIncrease
  19. 19 TestDecrease
  20. 20 OpCountChange
  21. 21 NoRegression
  22. 22}
  23. 23
  24. 24///|
  25. 25pub extend RegressionKind with @debug.Debug::{to_repr}
  26. 26
  27. 27///|
  28. 28pub extend RegressionKind with Eq::{not_equal, equal}
  29. 29
  30. 30///|
  31. 31/// 单个回归案例。
  32. 32/// 描述 Single regression case.
  33. 33#derive(Eq, @debug.Debug)
  34. 34pub(all) struct RegressionCase {
  35. 35 from_version : String
  36. 36 to_version : String
  37. 37 kind : RegressionKind
  38. 38 delta : Int32
  39. 39 description : String
  40. 40}
  41. 41
  42. 42///|
  43. 43pub extend RegressionCase with @debug.Debug::{to_repr}
  44. 44
  45. 45///|
  46. 46pub extend RegressionCase with Eq::{not_equal, equal}
  47. 47
  48. 48///|
  49. 49/// 回归检测报告。
  50. 50/// 描述 Regression detection report.
  51. 51#derive(Eq, @debug.Debug)
  52. 52pub(all) struct RegressionReport {
  53. 53 cases : Array[RegressionCase]
  54. 54 total_regressions : Int32
  55. 55 total_improvements : Int32
  56. 56 summary : String
  57. 57}
  58. 58
  59. 59///|
  60. 60pub extend RegressionReport with @debug.Debug::{to_repr}
  61. 61
  62. 62///|
  63. 63pub extend RegressionReport with Eq::{not_equal, equal}
  64. 64
  65. 65///|
  66. 66/// 检测历史快照间的回归。
  67. 67/// 检测 Detect regressions across history snapshots.
  68. 68pub fn detect_regressions() -> RegressionReport {
  69. 69● let log = history_log()
  70. 70 let entries = log.entries
  71. 71● let n = entries.length()
  72. 72 let cases : Array[RegressionCase] = []
  73. 73 let mut reg_count = 0
  74. 74 let mut imp_count = 0
  75. 75 for i in 1..<n {
  76. 76● let prev = entries[i - 1]
  77. 77 let curr = entries[i]
  78. 78 let deg_delta = curr.degradation_count - prev.degradation_count
  79. 79 let test_delta = curr.test_count - prev.test_count
  80. 80 if deg_delta > 0 {
  81. 81○ cases.push({
  82. 82 from_version: prev.version,
  83. 83 to_version: curr.version,
  84. 84 kind: DegradationIncrease,
  85. 85 delta: deg_delta,
  86. 86 description: prev.version +
  87. 87 " → " +
  88. 88 curr.version +
  89. 89 ": 退化增加 " +
  90. 90○ deg_delta.to_string(),
  91. 91 })
  92. 92 reg_count = reg_count + 1
  93. 93 }
  94. 94 if test_delta < 0 {
  95. 95○ cases.push({
  96. 96 from_version: prev.version,
  97. 97 to_version: curr.version,
  98. 98 kind: TestDecrease,
  99. 99 delta: test_delta,
  100. 100 description: prev.version +
  101. 101 " → " +
  102. 102 curr.version +
  103. 103 ": 测试减少 " +
  104. 104○ (-test_delta).to_string(),
  105. 105 })
  106. 106 reg_count = reg_count + 1
  107. 107 }
  108. 108 if prev.op_count != curr.op_count {
  109. 109○ cases.push({
  110. 110 from_version: prev.version,
  111. 111 to_version: curr.version,
  112. 112 kind: OpCountChange,
  113. 113 delta: curr.op_count - prev.op_count,
  114. 114 description: prev.version +
  115. 115 " → " +
  116. 116 curr.version +
  117. 117 ": 算子数 " +
  118. 118○ prev.op_count.to_string() +
  119. 119 " → " +
  120. 120○ curr.op_count.to_string(),
  121. 121 })
  122. 122 }
  123. 123 if deg_delta <= 0 && test_delta >= 0 {
  124. 124● cases.push({
  125. 125 from_version: prev.version,
  126. 126 to_version: curr.version,
  127. 127 kind: NoRegression,
  128. 128 delta: 0,
  129. 129 description: prev.version + " → " + curr.version + ": 无回归",
  130. 130 })
  131. 131 imp_count = imp_count + 1
  132. 132 }
  133. 133 }
  134. 134● let total = cases.length()
  135. 135 let summary = "回归检测: " +
  136. 136● total.to_string() +
  137. 137 " 个比较, " +
  138. 138● reg_count.to_string() +
  139. 139 " 回归, " +
  140. 140● imp_count.to_string() +
  141. 141 " 改进"
  142. 142 {
  143. 143 cases,
  144. 144 total_regressions: reg_count,
  145. 145 total_improvements: imp_count,
  146. 146 summary,
  147. 147 }
  148. 148}
  149. 149
  150. 150///|
  151. 151/// 检查指定版本是否有回归(退化数 > 0)。
  152. 152/// 描述 Whether a specific version has regressions (degradation count > 0).
  153. 153pub fn has_regression(version : String) -> Bool {
  154. 154● let log = history_log()
  155. 155 for e in log.entries {
  156. 156● if e.version == version {
  157. 157● return e.degradation_count > 0
  158. 158 }
  159. 159 }
  160. 160 false
  161. 161}
  162. 162
  163. 163///|
  164. 164/// 回归报告是否无回归。
  165. 165/// 描述 Whether regression report is clean (no regressions).
  166. 166pub fn RegressionReport::is_clean(self : RegressionReport) -> Bool {
  167. 167● self.total_regressions == 0
  168. 168}