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