load method
Recorded golden for metric, preferring the references in preferRefs
(default: android, then any), then — when fallbackAny — the first
recorded value. Null when the file is missing, corrupt, or has no
entry. Head-to-head refs (android-scv, android-tcm) plug in via
preferRefs.
Implementation
num? load(
String metric, {
List<String> preferRefs = const ['android', 'any'],
bool fallbackAny = true,
}) {
final file = File(path);
if (!file.existsSync()) return null;
try {
final doc = jsonDecode(file.readAsStringSync()) as Map<String, dynamic>;
final metricsDoc = (doc['metrics'] as Map?)?.cast<String, dynamic>();
final byRef =
((metricsDoc?[metric] as Map?)?['goldens'] as Map?)
?.cast<String, dynamic>() ??
const <String, dynamic>{};
for (final ref in preferRefs) {
final value = byRef[ref];
if (value is num) return value;
}
// When no preferred ref matches, optionally fall back to whatever ref
// recorded this metric. Rival columns pass fallbackAny: false — a
// rival must never inherit hintful's numbers.
if (!fallbackAny) return null;
return byRef.values.whereType<num>().firstOrNull;
} on FormatException {
return null;
}
}