Skip to content

Commit 5cd5689

Browse files
committed
fix(locate): determinism layer 10 — total preference order for suffix path resolution
resolve_path_in_graph's fallback used .find() over tracked files in map iteration order; with multiple suffix matches (vendored copies, e.g. benchmark's test/CMakeLists.txt) the explicit-path +200 priority landed on a per-process-random winner — when it hit the vendored copy it was then dropped by vendored filtering, so the real file's priority flipped on/off across runs (c5d5fa00 top-3 reorder). Preference: exact > shortest > lexicographic.
1 parent cef9f44 commit 5cd5689

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

crates/kin-cli/src/commands/locate.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11921,10 +11921,15 @@ fn resolve_path_in_graph(graph: &kin_db::InMemoryGraph, partial_path: &str) -> O
1192111921
return Some(candidate.to_string());
1192211922
}
1192311923

11924+
// Several tracked files can match one suffix (e.g. a vendored copy of
11925+
// test/CMakeLists.txt), and the tracked list iterates in map order —
11926+
// pick by a total preference (exact > shortest > lexicographic) so the
11927+
// winner never depends on per-process iteration order.
1192411928
if let Some(path) = tracked_non_entity_files(graph)
1192511929
.into_iter()
1192611930
.map(|tracked| tracked.path)
11927-
.find(|path| path == candidate || path.ends_with(&format!("/{}", candidate)))
11931+
.filter(|path| path == candidate || path.ends_with(&format!("/{}", candidate)))
11932+
.min_by_key(|path| (path != candidate, path.len(), path.clone()))
1192811933
{
1192911934
return Some(path);
1193011935
}

0 commit comments

Comments
 (0)