image.vision\aoci\aoci_verifier.mbt

67.9% · 36 / 53 points · 141 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/// # AOCI 验证器 AOCI Verifier
  3. 3///
  4. 4/// 依赖一致性/过期检测/边界冲突
  5. 5/// 依赖一致性/过期检测/边界冲突 Dependency consistency
  6. 6// AOCI-Verifier — 依赖一致性/过期检测/边界冲突
  7. 7// 验证符号索引的完整性和一致性
  8. 8
  9. 9///|
  10. 10#derive(Eq, @debug.Debug)
  11. 11pub(all) struct VerifyResult {
  12. 12 is_valid : Bool
  13. 13 issues : Array[String]
  14. 14}
  15. 15
  16. 16///|
  17. 17pub extend VerifyResult with Eq::{not_equal, equal}
  18. 18
  19. 19///|
  20. 20pub extend VerifyResult with @debug.Debug::{to_repr}
  21. 21
  22. 22///|
  23. 23pub fn VerifyResult::make(
  24. 24 is_valid~ : Bool,
  25. 25 issues~ : Array[String] = [],
  26. 26) -> VerifyResult {
  27. 27○ { is_valid, issues, }
  28. 28}
  29. 29
  30. 30///|
  31. 31pub fn verify_consistency(index : SymbolIndex) -> VerifyResult {
  32. 32● let issues : Array[String] = []
  33. 33 let names : Array[String] = []
  34. 34 for sym in index.symbols {
  35. 35● if sym.name.length() == 0 {
  36. 36● issues.push("empty symbol name in package: \{sym.pkg}")
  37. 37 }
  38. 38● if sym.pkg.length() == 0 {
  39. 39○ issues.push("empty package for symbol: \{sym.name}")
  40. 40 }
  41. 41● let full = sym.full_name()
  42. 42 let mut found = false
  43. 43 for n in names {
  44. 44● if n == full {
  45. 45○ found = true
  46. 46 break
  47. 47 }
  48. 48 }
  49. 49 if found {
  50. 50○ issues.push("duplicate symbol: \{full}")
  51. 51 } else {
  52. 52● names.push(full)
  53. 53 }
  54. 54 }
  55. 55● let is_valid = issues.length() == 0
  56. 56 { is_valid, issues, }
  57. 57}
  58. 58
  59. 59///|
  60. 60pub fn verify_keyword_coverage(index : SymbolIndex) -> VerifyResult {
  61. 61● let issues : Array[String] = []
  62. 62 for sym in index.symbols {
  63. 63● if sym.keywords.length() == 0 {
  64. 64● issues.push("no keywords for symbol: \{sym.full_name()}")
  65. 65 }
  66. 66 }
  67. 67● let is_valid = issues.length() == 0
  68. 68 { is_valid, issues, }
  69. 69}
  70. 70
  71. 71///|
  72. 72pub fn verify_dependencies(
  73. 73 index : SymbolIndex,
  74. 74 graph : Array[(String, Array[String])],
  75. 75) -> VerifyResult {
  76. 76● let issues : Array[String] = []
  77. 77 let names : Array[String] = []
  78. 78 for sym in index.symbols {
  79. 79● names.push(sym.name)
  80. 80 }
  81. 81 for entry in graph {
  82. 82● for dep in entry.1 {
  83. 83○ let mut found = false
  84. 84 for n in names {
  85. 85○ if n == dep {
  86. 86○ found = true
  87. 87 break
  88. 88 }
  89. 89 }
  90. 90 if !found {
  91. 91○ issues.push("unresolved dependency: \{entry.0} -> \{dep}")
  92. 92 }
  93. 93 }
  94. 94 }
  95. 95● let is_valid = issues.length() == 0
  96. 96 { is_valid, issues, }
  97. 97}
  98. 98
  99. 99///|
  100. 100pub fn verify_budget(
  101. 101 index : SymbolIndex,
  102. 102 budget : ContextBudget,
  103. 103) -> VerifyResult {
  104. 104● let issues : Array[String] = []
  105. 105● let total = index.total_tokens()
  106. 106 if total > budget.total_quota {
  107. 107● issues.push("index tokens (\{total}) exceed budget (\{budget.total_quota})")
  108. 108 }
  109. 109 for sym in index.symbols {
  110. 110● let cost = sym.estimated_tokens()
  111. 111 if cost > budget.total_quota {
  112. 112● issues.push(
  113. 113 "single symbol exceeds budget: \{sym.full_name()} (\{cost} tokens)",
  114. 114 )
  115. 115 }
  116. 116 }
  117. 117● let is_valid = issues.length() == 0
  118. 118 { is_valid, issues, }
  119. 119}
  120. 120
  121. 121///|
  122. 122pub fn verify_all(
  123. 123 index : SymbolIndex,
  124. 124 budget~ : ContextBudget = ContextBudget::make(1000000),
  125. 125) -> VerifyResult {
  126. 126● let issues : Array[String] = []
  127. 127● let r1 = verify_consistency(index)
  128. 128 for issue in r1.issues {
  129. 129○ issues.push(issue)
  130. 130 }
  131. 131● let r2 = verify_keyword_coverage(index)
  132. 132 for issue in r2.issues {
  133. 133○ issues.push(issue)
  134. 134 }
  135. 135● let r3 = verify_budget(index, budget)
  136. 136 for issue in r3.issues {
  137. 137○ issues.push(issue)
  138. 138 }
  139. 139● let is_valid = issues.length() == 0
  140. 140 { is_valid, issues, }
  141. 141}