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
33 changes: 33 additions & 0 deletions pkgs/id/src/world_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ pub fn validate_spec(spec: &CompileSpec) -> Result<()> {
"the first file must be main.roc"
);
let mut total = 0usize;
let mut seen = std::collections::HashSet::new();
for (name, content) in &spec.files {
ensure!(
seen.insert(name.as_str()),
"file name {name:?} appears more than once in the compile request"
);
ensure!(
!name.is_empty()
&& name.len() <= 64
Expand Down Expand Up @@ -602,6 +607,34 @@ mod tests {
assert!(validate_spec(&spec(many)).is_err());
}

#[test]
fn duplicate_file_names_are_refused() {
// A duplicated helper: staging writes both to the same job path, so
// the first would be silently overwritten — and digest_sources would
// still hash it into the recorded provenance.
let duplicate = spec(vec![
("main.roc", "app"),
("Helper.roc", "first"),
("Helper.roc", "second"),
]);
let error = validate_spec(&duplicate).unwrap_err().to_string();
assert!(error.contains("Helper.roc"), "{error}");
assert!(error.contains("more than once"), "{error}");

// A duplicated main.roc: files[0] satisfies the main.roc rule, but
// the main.roc read back from the job directory would be the second.
let duplicate_main = spec(vec![
("main.roc", "app"),
("Helper.roc", "helper"),
("main.roc", "other"),
]);
assert!(validate_spec(&duplicate_main).is_err());

// Control: unique names still validate.
let unique = spec(vec![("main.roc", "app"), ("Helper.roc", "helper")]);
assert!(validate_spec(&unique).is_ok());
}

#[test]
fn source_digest_is_independent_of_file_order_but_tracks_names_and_contents() {
let first = vec![
Expand Down
Loading