Skip to content
Merged
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: 40 additions & 0 deletions generator/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@ fn validate_single(path: &Path) -> std::result::Result<Vec<String>, Vec<String>>
}
}

// Check for duplicate package names
let mut pkg_names: Vec<&str> = def.packages.iter().map(|p| p.name.as_str()).collect();
pkg_names.sort();
for window in pkg_names.windows(2) {
if window[0] == window[1] {
errors.push(format!("duplicate package name: '{}'", window[0]));
}
}

// Check for duplicate package paths
let mut pkg_paths: Vec<&str> = def.packages.iter().map(|p| p.path.as_str()).collect();
pkg_paths.sort();
for window in pkg_paths.windows(2) {
if window[0] == window[1] {
errors.push(format!("duplicate package path: '{}'", window[0]));
}
}
Comment on lines +105 to +112
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

packages[*].path is used to create directories/files via output_dir.join(&pkg.path) in generate.rs, but validate_single doesn't validate package paths for absolute paths or .. traversal (unlike commits/hooks/config). This can write outside the output directory, and also allows semantically equivalent paths (e.g. "./", "", "a/.") to bypass the duplicate-path check and still overwrite the same version.toml. Consider (1) rejecting absolute/traversal components for package paths using the existing has_traversal helper, and (2) normalizing/cleaning paths before the duplicate-path comparison so logically identical paths are treated as duplicates.

Copilot uses AI. Check for mistakes.

// Validate branch references
let default_branch = def.meta.default_branch.as_deref().unwrap_or("main");
let branch_names: Vec<&str> = def.branches.iter().map(|b| b.name.as_str()).collect();
Expand Down Expand Up @@ -311,4 +329,26 @@ mod tests {
);
assert!(!validate_definitions(tmp.path()).unwrap());
}

#[test]
fn duplicate_package_names() {
let tmp = TempDir::new().unwrap();
write_def(
tmp.path(),
"dup",
r#"{"meta":{"name":"t","description":"d"},"packages":[{"name":"app","path":"a","initial_version":"1.0.0"},{"name":"app","path":"b","initial_version":"1.0.0"}]}"#,
);
assert!(!validate_definitions(tmp.path()).unwrap());
}

#[test]
fn duplicate_package_paths() {
let tmp = TempDir::new().unwrap();
write_def(
tmp.path(),
"dup",
r#"{"meta":{"name":"t","description":"d"},"packages":[{"name":"a","path":".","initial_version":"1.0.0"},{"name":"b","path":".","initial_version":"1.0.0"}]}"#,
);
assert!(!validate_definitions(tmp.path()).unwrap());
}
}
Loading