Skip to content
Open
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
98 changes: 95 additions & 3 deletions crates/mcb-providers/src/vector_store/edgevec/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use mcb_utils::constants::vector_store::{
STATS_FIELD_COLLECTION, STATS_FIELD_VECTORS_COUNT, VECTOR_FIELD_FILE_PATH,
VECTOR_FIELD_LANGUAGE,
};
use mcb_utils::utils::path::normalize_path_separators;

use super::*;

Expand Down Expand Up @@ -298,15 +299,15 @@ impl EdgeVecActor {
file_path: &str,
) -> Result<Vec<SearchResult>> {
let mut results = Vec::new();
// Normalize to forward slashes for cross-platform path matching
let normalized_query = file_path.replace('\\', "/");
// Normalize to forward slashes for cross-platform path matching.
let normalized_query = normalize_path_separators(file_path);
if let Some(collection_metadata) = self.get_collection_metadata(collection) {
for (ext_id, meta_val) in collection_metadata.iter() {
if let Some(meta) = meta_val.as_object()
&& meta
.get(VECTOR_FIELD_FILE_PATH)
.and_then(|v| v.as_str())
.is_some_and(|p| p.replace('\\', "/") == normalized_query)
.is_some_and(|p| normalize_path_separators(p) == normalized_query)
{
Comment on lines +302 to 311

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

2. Non-canonical file_path returned 🐞 Bug ≡ Correctness

After normalizing separators for matching in handle_get_chunks_by_file, the code still overwrites
SearchResult.file_path with the raw query string, so a src\lib.rs query returns results whose
file_path contains backslashes. This violates the workspace’s forward-slash canonical path
convention and can cause mismatches when callers reuse or key/group on returned file_path values.
Agent Prompt
### Issue description
`EdgeVecActor::handle_get_chunks_by_file` now normalizes path separators so backslash queries match stored forward-slash metadata, but it still returns `SearchResult.file_path` as the **raw** query string. This can leak backslashes into results even though the system canonicalizes workspace-relative paths to forward slashes.

### Issue Context
- The indexing pipeline canonicalizes paths to forward slashes (via `workspace_relative_path` → `path_to_utf8_string`).
- `handle_get_chunks_by_file` should return results with canonical `file_path` (preferably the stored metadata path or the normalized query), not whatever separator the caller used.

### Fix Focus Areas
- crates/mcb-providers/src/vector_store/edgevec/actor.rs[296-316]

### Suggested fix
- Prefer **not** overriding `result.file_path` at all (keep `search_result_from_json_metadata`’s metadata-derived canonical path), OR set it to the normalized form:
  - Replace `result.file_path = file_path.to_owned();` with `result.file_path.clone_from(&normalized_query);` (or `result.file_path = normalized_query.clone();`).
- Strengthen the regression test to assert the returned `file_path` is normalized (e.g., both queries return `"src/lib.rs"`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

let mut result =
search_result_from_json_metadata(ext_id.to_owned(), meta_val, 1.0);
Expand Down Expand Up @@ -413,3 +414,94 @@ impl EdgeVecActor {
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use mcb_domain::value_objects::Embedding;
use mcb_utils::utils::path::normalize_path_separators;
use tokio::sync::mpsc;
Comment on lines +420 to +423

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

1. Test imports incorrectly ordered 📘 Rule violation ⚙ Maintainability

The new test module orders local and mcb_* imports before the external tokio import, contrary to
the required external → mcb_* → local grouping. This makes the changed Rust file noncompliant with
the repository import-order rule.
Agent Prompt
## Issue description
The new test module's imports are not grouped in the required order: external crates, then `mcb_*` crates, then local modules.

## Issue Context
Move `tokio` first, keep the `mcb_domain` and `mcb_utils` imports together next, and place `super::*` last.

## Fix Focus Areas
- crates/mcb-providers/src/vector_store/edgevec/actor.rs[420-423]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


type TestResult<T = ()> = std::result::Result<T, Box<dyn std::error::Error>>;

const TEST_DIMS: usize = 8;

/// Build a minimal `EdgeVecActor` with a small dimension for fast tests.
fn make_actor() -> TestResult<EdgeVecActor> {
let (_tx, rx) = mpsc::channel(1);
let cfg = EdgeVecConfig {
dimensions: TEST_DIMS,
..EdgeVecConfig::default()
};
Ok(EdgeVecActor::new(rx, cfg)?)
}

/// Insert one vector with a `file_path` metadata field stored with forward slashes.
///
/// Returns the collection name used, so callers can query it.
fn insert_forward_slash_chunk(actor: &mut EdgeVecActor) -> TestResult<String> {
let collection = "test_col";
actor.handle_create_collection(collection.to_owned())?;

let embedding = Embedding {
vector: vec![1.0_f32; TEST_DIMS],
model: "test".to_owned(),
dimensions: TEST_DIMS,
};

let metadata = vec![{
let mut m = std::collections::HashMap::new();
m.insert(
VECTOR_FIELD_FILE_PATH.to_owned(),
serde_json::json!("src/lib.rs"),
);
m.insert("content".to_owned(), serde_json::json!("fn foo() {}"));
m.insert("language".to_owned(), serde_json::json!("rust"));
m.insert("start_line".to_owned(), serde_json::json!(1_u32));
m.insert("end_line".to_owned(), serde_json::json!(3_u32));
m.insert("chunk_index".to_owned(), serde_json::json!(0_u32));
m
}];

let ids = actor.handle_insert_vectors(collection, vec![embedding], metadata)?;
assert_eq!(ids.len(), 1, "expected one inserted id");
Ok(collection.to_owned())
}

/// Regression test for mcb-ns8z: forward-slash and backslash queries must
/// return the same chunks, regardless of the separator used by the caller.
#[test]
fn get_chunks_by_file_backslash_and_forward_slash_are_equivalent() -> TestResult {
let mut actor = make_actor()?;
let collection = insert_forward_slash_chunk(&mut actor)?;

let forward = actor.handle_get_chunks_by_file(&collection, "src/lib.rs")?;
let backward = actor.handle_get_chunks_by_file(&collection, "src\\lib.rs")?;

assert_eq!(
forward.len(),
1,
"forward-slash query must return 1 chunk, got {}: {forward:?}",
forward.len()
);
assert_eq!(
backward.len(),
forward.len(),
"backslash query must return same number of chunks as forward-slash query"
);
Ok(())
}

/// Confirm that `normalize_path_separators` is a no-op for paths without backslashes.
#[test]
fn normalize_path_separators_forward_slash_unchanged() {
assert_eq!(normalize_path_separators("src/lib.rs"), "src/lib.rs");
}

/// Confirm that `normalize_path_separators` replaces backslashes.
#[test]
fn normalize_path_separators_backslash_replaced() {
assert_eq!(normalize_path_separators("src\\lib.rs"), "src/lib.rs");
assert_eq!(normalize_path_separators("a\\b\\c.rs"), "a/b/c.rs");
}
}
Comment on lines +418 to +507

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

1. Tests bloat actor.rs 📘 Rule violation ⚙ Maintainability

crates/mcb-providers/src/vector_store/edgevec/actor.rs is now ~507 lines after adding a large
in-file test module, exceeding the ~200-line limit. This increases maintenance burden and makes the
module harder to navigate.
Agent Prompt
## Issue description
`crates/mcb-providers/src/vector_store/edgevec/actor.rs` exceeds the ~200-line limit after adding an in-file `#[cfg(test)] mod tests` block.

## Issue Context
The compliance rule requires modified source files to stay under ~200 lines by splitting into submodules. The newly added tests can live in a dedicated test module/file without increasing the production module size.

## Fix Focus Areas
- crates/mcb-providers/src/vector_store/edgevec/actor.rs[418-507]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

12 changes: 12 additions & 0 deletions crates/mcb-utils/src/utils/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ pub fn path_to_utf8_string(path: &Path) -> Result<String, UtilsError> {
Ok(s.replace('\\', "/"))
}

/// Normalizes path separators to forward slashes.
///
/// Replaces every backslash (`\`) with a forward slash (`/`) so that
/// paths stored or compared inside vector-store metadata are consistent
/// across Windows and Unix platforms.
///
/// This is a pure string operation and does **not** access the filesystem.
#[must_use]
pub fn normalize_path_separators(path: &str) -> String {
path.replace('\\', "/")

@cubic-dev-ai cubic-dev-ai Bot Jul 29, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: Path-separator normalization now has two implementations in the same module, so future normalization changes can diverge between string and Path callers. Consider making path_to_utf8_string delegate to this helper so there is one normalization boundary.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At crates/mcb-utils/src/utils/path.rs, line 63:

<comment>Path-separator normalization now has two implementations in the same module, so future normalization changes can diverge between string and `Path` callers. Consider making `path_to_utf8_string` delegate to this helper so there is one normalization boundary.</comment>

<file context>
@@ -51,6 +51,18 @@ pub fn path_to_utf8_string(path: &Path) -> Result<String, UtilsError> {
+/// This is a pure string operation and does **not** access the filesystem.
+#[must_use]
+pub fn normalize_path_separators(path: &str) -> String {
+    path.replace('\\', "/")
+}
+
</file context>
Fix with cubic

}
Comment on lines +54 to +64

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Informational

1. Path docs drift 🐞 Bug ⚙ Maintainability

mcb_utils::utils::path’s module docs state that all functions return Result, but this PR adds
normalize_path_separators(&str) -> String, making that contract literally untrue. The new
function’s doc comment also references “vector-store metadata”, which conflicts with mcb-utils’
stated “zero domain knowledge” principle.
Agent Prompt
## Issue description
`crates/mcb-utils/src/utils/path.rs` contains module-level documentation claiming all functions return `Result`, but this PR adds `normalize_path_separators(&str) -> String`. Additionally, the new function’s documentation mentions “vector-store metadata”, which is domain-specific and clashes with the `mcb-utils` crate’s stated goal of having zero domain knowledge.

## Issue Context
This is not a runtime bug: `normalize_path_separators` is infallible by design. The problem is that module/crate documentation and layering guidance become misleading/inconsistent after this addition.

## Fix Focus Areas
- crates/mcb-utils/src/utils/path.rs[1-65]
- crates/mcb-utils/src/lib.rs[16-21]

Suggested changes:
- Update the module-level comment to clarify that *fallible* path operations return `Result`, while infallible string transforms may return plain values.
- Rewrite the `normalize_path_separators` doc comment to be domain-agnostic (avoid mentioning vector-store metadata).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


/// Canonicalizes a path via the filesystem.
///
/// # Errors
Expand Down
Loading