Skip to content

Commit

Permalink
fix(core): native task hashing: respect filenames of inputs when comp…
Browse files Browse the repository at this point in the history
…uting the hash

closed #23106
  • Loading branch information
iAmNathanJ committed Sep 11, 2024
1 parent 5576ba1 commit f3ab7c4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
52 changes: 27 additions & 25 deletions packages/nx/src/hasher/native-task-hasher-impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,24 @@ describe('native task hasher', () => {
"env:TESTENV": "11441948532827618368",
"parent:ProjectConfiguration": "3608670998275221195",
"parent:TsConfig": "2264969541778889434",
"parent:{projectRoot}/**/*": "15295586939211629225",
"parent:{projectRoot}/**/*": "17059468255294227635",
"runtime:echo runtime123": "29846575039086708",
"tagged:ProjectConfiguration": "8596726088057301092",
"tagged:TsConfig": "2264969541778889434",
"tagged:{projectRoot}/**/*": "112200405683630828",
"tagged:{projectRoot}/**/*": "14666997081331501901",
"unrelated:ProjectConfiguration": "11133337791644294114",
"unrelated:TsConfig": "2264969541778889434",
"unrelated:{projectRoot}/**/*": "10505120368757496776",
"unrelated:{projectRoot}/**/*": "4127219831408253695",
"workspace:[{workspaceRoot}/nx.json,{workspaceRoot}/.gitignore,{workspaceRoot}/.nxignore]": "5219582320960288192",
},
"value": "13049022000906481001",
"value": "6752177990229940739",
},
]
`);
});



it('should hash tasks where the project has dependencies', async () => {
const workspaceFiles = await retrieveWorkspaceFiles(tempFs.tempDir, {
'libs/parent': 'parent',
Expand Down Expand Up @@ -226,13 +228,13 @@ describe('native task hasher', () => {
"AllExternalDependencies": "3244421341483603138",
"child:ProjectConfiguration": "710102491746666394",
"child:TsConfig": "2264969541778889434",
"child:{projectRoot}/**/*": "7694964870822928111",
"child:{projectRoot}/**/*": "3347149359534435991",
"parent:ProjectConfiguration": "8031122597231773116",
"parent:TsConfig": "2264969541778889434",
"parent:{projectRoot}/**/*": "15295586939211629225",
"parent:{projectRoot}/**/*": "17059468255294227635",
"workspace:[{workspaceRoot}/nx.json,{workspaceRoot}/.gitignore,{workspaceRoot}/.nxignore]": "5219582320960288192",
},
"value": "17442516481637512275",
"value": "10441723142158830393",
}
`);
});
Expand Down Expand Up @@ -305,13 +307,13 @@ describe('native task hasher', () => {
"AllExternalDependencies": "3244421341483603138",
"child:ProjectConfiguration": "13051054958929525761",
"child:TsConfig": "2264969541778889434",
"child:{projectRoot}/**/*": "7694964870822928111",
"parent:!{projectRoot}/**/*.spec.ts": "7663204892242899157",
"child:{projectRoot}/**/*": "3347149359534435991",
"parent:!{projectRoot}/**/*.spec.ts": "8911122541468969799",
"parent:ProjectConfiguration": "3608670998275221195",
"parent:TsConfig": "2264969541778889434",
"workspace:[{workspaceRoot}/nx.json,{workspaceRoot}/.gitignore,{workspaceRoot}/.nxignore]": "4641558175996703359",
},
"value": "3497993078654537309",
"value": "10915213281046863614",
}
`);
});
Expand Down Expand Up @@ -372,22 +374,22 @@ describe('native task hasher', () => {
{
"details": {
"AllExternalDependencies": "3244421341483603138",
"parent:!{projectRoot}/**/*.spec.ts": "7663204892242899157",
"parent:!{projectRoot}/**/*.spec.ts": "8911122541468969799",
"parent:ProjectConfiguration": "16402137858974842465",
"parent:TsConfig": "2264969541778889434",
"workspace:[{workspaceRoot}/nx.json,{workspaceRoot}/.gitignore,{workspaceRoot}/.nxignore]": "4641558175996703359",
},
"value": "10775755355957559912",
"value": "898401993921705929",
},
{
"details": {
"AllExternalDependencies": "3244421341483603138",
"parent:ProjectConfiguration": "16402137858974842465",
"parent:TsConfig": "2264969541778889434",
"parent:{projectRoot}/**/*": "15295586939211629225",
"parent:{projectRoot}/**/*": "17059468255294227635",
"workspace:[{workspaceRoot}/nx.json,{workspaceRoot}/.gitignore,{workspaceRoot}/.nxignore]": "4641558175996703359",
},
"value": "13219368697419749776",
"value": "17751813489978054762",
},
]
`);
Expand Down Expand Up @@ -467,18 +469,18 @@ describe('native task hasher', () => {
{
"details": {
"AllExternalDependencies": "3244421341483603138",
"child:!{projectRoot}/**/*.spec.ts": "13790135045935437026",
"child:!{projectRoot}/**/*.spec.ts": "6212660753359890679",
"child:ProjectConfiguration": "10085593111011845427",
"child:TsConfig": "2264969541778889434",
"env:MY_TEST_HASH_ENV": "17357374746554314488",
"parent:ProjectConfiguration": "14398811678394411425",
"parent:TsConfig": "2264969541778889434",
"parent:{projectRoot}/**/*": "15295586939211629225",
"parent:{projectRoot}/**/*": "17059468255294227635",
"workspace:[{workspaceRoot}/global1]": "13078141817211771580",
"workspace:[{workspaceRoot}/global2]": "13625885481717016690",
"workspace:[{workspaceRoot}/nx.json,{workspaceRoot}/.gitignore,{workspaceRoot}/.nxignore]": "10897751101872977225",
},
"value": "14298810822113951946",
"value": "715988292529605815",
},
]
`);
Expand Down Expand Up @@ -529,10 +531,10 @@ describe('native task hasher', () => {
"AllExternalDependencies": "3244421341483603138",
"parent:ProjectConfiguration": "3608670998275221195",
"parent:TsConfig": "8661678577354855152",
"parent:{projectRoot}/**/*": "15295586939211629225",
"parent:{projectRoot}/**/*": "17059468255294227635",
"workspace:[{workspaceRoot}/nx.json,{workspaceRoot}/.gitignore,{workspaceRoot}/.nxignore]": "5219582320960288192",
},
"value": "10821775409399212451",
"value": "891874926565434230",
}
`);
});
Expand Down Expand Up @@ -604,13 +606,13 @@ describe('native task hasher', () => {
"AllExternalDependencies": "3244421341483603138",
"child:ProjectConfiguration": "13748859057138736105",
"child:TsConfig": "2264969541778889434",
"child:{projectRoot}/**/*": "7694964870822928111",
"child:{projectRoot}/**/*": "3347149359534435991",
"parent:ProjectConfiguration": "3608670998275221195",
"parent:TsConfig": "2264969541778889434",
"parent:{projectRoot}/**/*": "15295586939211629225",
"parent:{projectRoot}/**/*": "17059468255294227635",
"workspace:[{workspaceRoot}/nx.json,{workspaceRoot}/.gitignore,{workspaceRoot}/.nxignore]": "5219582320960288192",
},
"value": "12197760444984597111",
"value": "6344665026201462314",
}
`);

Expand All @@ -626,13 +628,13 @@ describe('native task hasher', () => {
"AllExternalDependencies": "3244421341483603138",
"child:ProjectConfiguration": "13748859057138736105",
"child:TsConfig": "2264969541778889434",
"child:{projectRoot}/**/*": "7694964870822928111",
"child:{projectRoot}/**/*": "3347149359534435991",
"parent:ProjectConfiguration": "3608670998275221195",
"parent:TsConfig": "2264969541778889434",
"parent:{projectRoot}/**/*": "15295586939211629225",
"parent:{projectRoot}/**/*": "17059468255294227635",
"workspace:[{workspaceRoot}/nx.json,{workspaceRoot}/.gitignore,{workspaceRoot}/.nxignore]": "5219582320960288192",
},
"value": "12197760444984597111",
"value": "6344665026201462314",
}
`);
});
Expand Down
15 changes: 13 additions & 2 deletions packages/nx/src/native/tasks/hashers/hash_project_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub fn hash_project_files(
let mut hasher = xxhash_rust::xxh3::Xxh3::new();
for file in collected_files {
hasher.update(file.hash.as_bytes());
hasher.update(file.file.as_bytes());
}
Ok(hasher.digest().to_string())
}
Expand Down Expand Up @@ -157,7 +158,12 @@ mod tests {
let hash_result = hash_project_files(proj_name, proj_root, file_sets, &file_map).unwrap();
assert_eq!(
hash_result,
hash(&[file_data1.hash.as_bytes(), file_data3.hash.as_bytes()].concat())
hash(&[
file_data1.hash.as_bytes(),
file_data1.file.as_bytes(),
file_data3.hash.as_bytes(),
file_data3.file.as_bytes()
].concat())
);
}

Expand Down Expand Up @@ -199,7 +205,12 @@ mod tests {
let hash_result = hash_project_files(proj_name, proj_root, file_sets, &file_map).unwrap();
assert_eq!(
hash_result,
hash(&[file_data1.hash.as_bytes(), file_data3.hash.as_bytes()].concat())
hash(&[
file_data1.hash.as_bytes(),
file_data1.file.as_bytes(),
file_data3.hash.as_bytes(),
file_data3.file.as_bytes(),
].concat())
);
}
}

0 comments on commit f3ab7c4

Please sign in to comment.