Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions crates/ripr/src/analysis/diff/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,50 @@ pub(super) fn is_new_path_marker(raw: &str) -> bool {
/// snapshot lookup can reference the escaping path. Byte-native raw forms
/// confine through the platform's own path components, so traversal
/// detection is unchanged (#3609).
///
/// The confined path keeps the spelling git itself gave the diff, not the
/// analyzing platform's separator (#7937): git names diff paths with `/` on
/// every host, and re-synthesizing the accepted components with the native
/// separator re-spelled every `ChangedFile.path` (and every probe identity
/// cloned from it) as `src\a.rs` on Windows while fixtures, goldens, sibling
/// producers and POSIX hosts all spell `src/a.rs`. `root.join` and `Path`
/// equality compare components, so the portable spelling reads and matches
/// identically on both hosts.
fn confine_to_relative_path(path: &DecodedPath) -> Option<PathBuf> {
let mut confined = PathBuf::new();
let mut parts: Vec<&std::ffi::OsStr> = Vec::new();
for component in path.as_path().components() {
match component {
Component::Normal(part) => confined.push(part),
Component::Normal(part) => parts.push(part),
Component::CurDir => {}
Component::ParentDir | Component::RootDir | Component::Prefix(_) => return None,
}
}
if confined.as_os_str().is_empty() {
None
} else {
if parts.is_empty() {
return None;
}
// Unix native separators are `/`, so the platform join already
// reproduces the diff spelling byte for byte, including the invalid-byte
// raw form whose identity must stay injective (#3609) — lossy text there
// would not. Windows re-joins the accepted text segments with the diff's
// own `/` instead of the native `\`.
#[cfg(unix)]
{
let mut confined = PathBuf::new();
for part in parts {
confined.push(part);
}
Some(confined)
}
#[cfg(windows)]
{
Some(PathBuf::from(
parts
.iter()
.map(|part| part.to_string_lossy().into_owned())
.collect::<Vec<_>>()
.join("/"),
))
}
}

/// Detect whether `raw` is a syntactically valid `--- <path>` old-path marker.
Expand Down
2 changes: 1 addition & 1 deletion crates/ripr/src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ pub(crate) fn finding_location_text_with_platform(
/// spelling and the plain drive spelling name the same file, and every other
/// surface renders the plain one. Other verbatim forms (`\\?\UNC\..`,
/// `\\?\Volume{..}`) have no plain spelling, so they stay.
fn plain_drive_verbatim_path(path: &Path, windows: bool) -> PathBuf {
pub(crate) fn plain_drive_verbatim_path(path: &Path, windows: bool) -> PathBuf {
if !windows {
return path.to_path_buf();
}
Expand Down
30 changes: 24 additions & 6 deletions crates/ripr/src/analysis/workspace/cargo_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,25 +454,43 @@ impl ManifestInventory {
/// verified 1.95.0) but canonicalizes symlinks on Unix (#3637
/// review, demonstrated by the Linux CI run of the alias pin), so
/// one form alone cannot cover both hosts.
///
/// #7937: both resolved forms go through the shared plain-drive
/// spelling first. `WorkspaceRootAuthority` canonicalizes its root,
/// and Windows `fs::canonicalize` returns the verbatim `\\?\` drive
/// form; carried through here, the anchor's prefix compared as
/// verbatim against cargo's plain echoed keys, every lookup
/// missed, and each metadata-owned verdict failed closed (`test =
/// false` / `required-features` / `harness = false` skips went
/// unestablished; nested members went uncredited). The two spellings
/// name the same file, so the anchor compares in the family cargo
/// echoes — the same rule `finding_location_text` applies to
/// rendered locations.
fn lookup_test_owners(
&mut self,
workspace_root: &Path,
registration_target: &Path,
) -> (PathBuf, InventoryLookup) {
let joined = workspace_root.join(registration_target);
let absolute = std::path::absolute(&joined).unwrap_or(joined);
let anchored = lexical(&normalize(&absolute));
let anchored = lexical(&normalize(&crate::analysis::plain_drive_verbatim_path(
&absolute,
cfg!(windows),
)));
self.ensure_workspace_metadata(workspace_root);
let lookup = match &self.metadata {
MetadataState::Loaded(targets) => {
let owners = targets.get(&anchored).cloned().or_else(|| {
// `fs::canonicalize` returns verbatim `\\?\`
// paths on Windows; those can only match
// verbatim keys cargo never echoes, so a miss
// there is harmless — the alias-form lookup
// above already covered the Windows behavior.
// paths on Windows; stripped to the plain drive
// spelling, the real path compares in the same
// family as the echoed keys (#7937).
let real = std::fs::canonicalize(&absolute).ok()?;
targets.get(&lexical(&normalize(&real))).cloned()
targets
.get(&lexical(&normalize(
&crate::analysis::plain_drive_verbatim_path(&real, cfg!(windows)),
)))
.cloned()
});
match owners {
Some(owners) => InventoryLookup::Present(owners),
Expand Down
16 changes: 14 additions & 2 deletions crates/ripr/src/app/explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,21 @@ mod tests {
assert!(rendered.contains("Static exposure"));
assert!(rendered.contains("no_static_path"));
assert!(rendered.contains("InvoiceError::InvalidCurrency"));
let root = crate::agent::loop_commands::shell_arg(&sample_root().display().to_string());
// #7937: the expectation goes through the same rendering owners the
// drill-in builder uses (`bound_root` for the analyzed root,
// `bound_root_path` + `root_path_display` for the diff file, then
// `shell_arg`). Re-deriving the spelling from `Path::display`
// asserted the renderer's POSIX form against the renderer's own
// Windows form: a native-separator display spelling versus the
// stable-separator bound spelling, so the pin failed only where it
// was already honest.
let root = crate::agent::loop_commands::shell_arg(
&crate::agent::loop_commands::bound_root(&sample_root().display().to_string()),
);
let diff = crate::agent::loop_commands::shell_arg(
&sample_root().join("example.diff").display().to_string(),
&crate::agent::loop_commands::root_path_display(
&crate::agent::loop_commands::bound_root_path(&sample_root().join("example.diff")),
),
);
assert!(rendered.contains(
&format!(
Expand Down
13 changes: 11 additions & 2 deletions crates/ripr/src/lsp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15562,9 +15562,18 @@ fn execute_command_collect_context_returns_packet_for_known_finding() -> Result<
// that diff source with the session root — re-running it re-selects
// the finding the packet ships with, instead of exiting 2 with "no
// finding matched" against the committed default-branch diff.
// #7937: the root spelling comes from the same binding owner the
// packet builder uses (`bound_root` + `shell_arg`), not a hardcoded
// POSIX literal — a rooted `/workspace` binds to the process drive
// on Windows and renders the bound drive-absolute form, and the
// pin must accept the producer's own replayable form on every host.
if let Some(witness) = expected_context_packet.witness.as_mut() {
witness.explain_command =
"ripr explain --root /workspace --worktree probe:pricing:88:predicate".to_string();
witness.explain_command = format!(
"ripr explain --root {} --worktree probe:pricing:88:predicate",
crate::agent::loop_commands::shell_arg(&crate::agent::loop_commands::bound_root(
"/workspace"
)),
);
Comment thread
EffortlessSteven marked this conversation as resolved.
Resolved
}
let expected_json =
crate::output::json::render_context_packet_dto(&expected_context_packet);
Expand Down
10 changes: 9 additions & 1 deletion crates/ripr/src/output/evidence_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,19 @@ fn canonical_item_for(
/// word. The producer knows its inputs, so it rebuilds the display from them
/// and grants the trusted spec only on a byte-for-byte match; any other or
/// substituted display still recovers nothing.
///
/// The rebuild uses the same `root_display` builder the display itself
/// came from, not a fresh bind (#7937): a rooted selected root such as
/// `/tmp/repo` is absolute on POSIX but only rooted on Windows, where
/// binding re-spelled it against the process drive and the producer's own
/// display failed its own byte-match, losing every typed spec. `root_display`
/// binds absolute roots, keeps the portable relative spellings verbatim, and
/// agrees with the display on every host and input family.
fn bound_snapshot_verify_spec(
display: &str,
verify_root: &std::path::Path,
) -> Option<crate::domain::CommandSpec> {
let root = crate::agent::loop_commands::bound_root(&verify_root.to_string_lossy());
let root = crate::agent::loop_commands::root_display(&verify_root.to_string_lossy());
let spec = crate::agent::command_specs::agent_verify_command_spec(
&root,
WORKFLOW_BEFORE_SNAPSHOT_ARTIFACT,
Expand Down
33 changes: 30 additions & 3 deletions crates/ripr/src/output/gap_source_subject/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ pub(crate) fn absolute_root(root: &Path) -> PathBuf {
/// - whitespace in a filename or directory is identity, not padding (#5128).
pub(crate) fn subject_relative_path(root: &Path, raw: &str) -> Option<String> {
let file = subject_named_file(raw)?;
// #7937: a derived artifact can echo the verbatim `\\?\F:\...` spelling
// its producer resolved (the gap-ledger selected root is canonicalized),
// and that spelling compares against a plain-spelled root as a different
// prefix component. Both spellings name the same file, so the token is
// compared in the plain drive family before normalization.
let file = match file.strip_prefix(r"\\?\") {
Some(rest) if rest.as_bytes().get(1) == Some(&b':') => rest,
_ => file,
};
let normalized = file.replace('\\', "/");
let path = Path::new(&normalized);
let relative = if path.is_absolute() {
Expand Down Expand Up @@ -124,16 +133,34 @@ fn relative_stamp_path(relative: &Path) -> Option<String> {
Some(parts.join("/"))
}

/// Strip the Windows verbatim prefix from a drive-letter path, comparing it
/// in the plain spelling every other artifact side spells (#7937): the
/// gap-ledger CLI resolves the selected root with `fs::canonicalize`, which
/// on Windows returns the verbatim `\\?\` drive form, while the analysis
/// stamp and the records name plain drive paths. Both spellings name the
/// same file; other verbatim forms (`\\?\UNC\..`) have no plain spelling
/// and stay.
fn plain_drive_root(path: &Path) -> PathBuf {
let text = path.to_string_lossy();
match text.strip_prefix(r"\\?\") {
Some(rest) if rest.as_bytes().get(1) == Some(&b':') => PathBuf::from(rest),
_ => path.to_path_buf(),
}
}

fn strip_absolute_root(root: &Path, path: &Path) -> Option<PathBuf> {
let absolute = absolute_root(root);
let absolute = plain_drive_root(&absolute_root(root));
if let Ok(relative) = path.strip_prefix(&absolute) {
return Some(relative.to_path_buf());
}
let canonical_root = std::fs::canonicalize(&absolute).ok()?;
let canonical_root = plain_drive_root(&std::fs::canonicalize(&absolute).ok()?);
Comment thread
EffortlessSteven marked this conversation as resolved.
Resolved
if let Ok(relative) = path.strip_prefix(&canonical_root) {
return Some(relative.to_path_buf());
}
let canonical_path = std::fs::canonicalize(path).ok()?;
// Same family on both sides: Windows canonicalize returns the verbatim
// spelling, and a verbatim remainder cannot strip a plain root (#8030
// review). Both spellings name the same file.
let canonical_path = plain_drive_root(&std::fs::canonicalize(path).ok()?);
canonical_path
.strip_prefix(&canonical_root)
.ok()
Expand Down
9 changes: 8 additions & 1 deletion crates/ripr/src/process_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,14 @@ mod tests {
#[cfg(windows)]
#[test]
fn terminate_tree_leaves_unrelated_processes_alive() -> Result<(), String> {
let mut unrelated_command = platform_sleep_command(5);
// The unrelated process must outlive the whole observation window,
// not merely start alive: under full-suite parallelism the cold
// PowerShell starts, the bounded termination and the PowerShell
// alive-check itself can legitimately exceed a short sleep, and an
// expired unrelated process misreads as "terminated" (#7937). The
// window matches the sibling containment tests; the test kills the
// unrelated process itself on every exit path, so nothing leaks.
let mut unrelated_command = platform_sleep_command(60);
let mut unrelated = unrelated_command
.stdin(Stdio::null())
.stdout(Stdio::null())
Expand Down
35 changes: 35 additions & 0 deletions docs/LEARNINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,41 @@
This log captures repo knowledge that should survive individual PRs and chat
sessions. It is intentionally short and actionable.

## 2026-10-14: One path can spell three ways on Windows; compare at a shared owner (#7937)

Fifteen lib tests failed deterministically on Windows at a Linux-green main.
The diagnosis grouped them into one family — the same path spelled three
host-dependent ways — with four distinct leak sites:

- `fs::canonicalize` returns the verbatim `\\?\F:\...` form on Windows. A
canonicalized root carried into a component comparison against a
plain-spelled counterpart misses (`Prefix(VerbatimDisk)` is a different
component from `Prefix(Disk)`): the cargo-metadata inventory anchored
verbatim roots against cargo's plain echoed keys, and the gap-ledger
selected root dropped stamped entries whose file did not exist (the
`canonicalize(path)` fallback arm cannot rescue an absent file). Compare
both sides in the plain drive family (`plain_drive_verbatim_path`,
`strip_absolute_root`), not at each call site.
- `components()` round-trips re-synthesize with the native separator. A
confinement that re-pushed each accepted component spelled git's
`src/a.rs` as `src\a.rs` in every Windows consumer while tests, goldens
and rendered locations spell `/`. When a boundary accepts components of
a TEXT path (diff paths are always `/`), re-join with the text's own
separator.
- A rooted path (`/tmp/x`) is absolute on POSIX but only rooted on Windows,
where `PathBuf::join` rewrites it against the process drive. Two
producers of the same string must pass the root through the SAME
spelling owner (`root_display` vs `bound_root` disagreed); a test
expectation must call that owner, not rebuild the spelling from
`Path::display`.

Durable rules: (1) never compare paths across a canonicalize boundary
without normalizing both sides to one family; (2) never rebuild a rendered
path spelling in a test — call the producer's own owner; (3) a stamped
entry with `digest: null` is legal and must survive derivation for absent
files, so lexical prefix strips must not depend on `canonicalize`
succeeding; (4) these failures are invisible to a Linux-only lib CI lane —
a Windows lib run at the exact base is the discriminator.
## 2026-10-15: Pytest evidence must not skip the unittest scan (#7664)

`detect_python_test_frameworks` collects a set. Config markers and
Expand Down
Loading