classifyStepTargets function
Classifies a tour's steps by their targetId against the registry's known ids.
Typo policy:
- a step with candidates (similar ids exist) — a typo: fails loudly in debug, is skipped in release (waiting for it is pointless);
- a step without candidates — a legitimate deferred target: wait, the timeout produces its own diagnosis;
- a step whose only difference from a candidate is digits
(
target1/target2sequences) — also deferred: numeric suffixes are naming, not typos; otherwise every following step in a sequence would look like a typo of the previous one. A pure function: tested directly, applied by the controller.
Implementation
@visibleForTesting
({List<HintStep> deferred, List<UnknownHintTarget> typos}) classifyStepTargets(
HintTour tour, Set<String> knownIds) {
final deferred = <HintStep>[];
final typos = <UnknownHintTarget>[];
for (var i = 0; i < tour.steps.length; i++) {
final step = tour.steps[i];
if (knownIds.contains(step.targetId)) continue;
final candidates = closestTargetIds(step.targetId, knownIds);
if (candidates.isEmpty ||
_differsOnlyInDigits(step.targetId, candidates.first)) {
deferred.add(step);
} else {
typos.add((step: step, index: i, candidates: candidates));
}
}
return (deferred: deferred, typos: typos);
}