Skip to content

Commit 8d85ffd

Browse files
Fix equality error in modified filepaths logic (#229)
This check was on the wrong type of object
1 parent 37e65d7 commit 8d85ffd

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

cli/src/main/kotlin/com/bazel_diff/hash/SourceFileHasher.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ class SourceFileHasher : KoinComponent {
7474
if (file.isFile) {
7575
if (modifiedFilepaths.isEmpty()) {
7676
putFile(file)
77-
} else if (modifiedFilepaths.stream().anyMatch { workingDirectory.resolve(it) == file }) {
77+
} else if (modifiedFilepaths.any {
78+
workingDirectory.resolve(it) == absoluteFilePath
79+
}) {
7880
putFile(file)
7981
}
8082
}

cli/src/test/kotlin/com/bazel_diff/hash/SourceFileHasherTest.kt

+32-1
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import java.nio.file.Paths
1818
internal class SourceFileHasherTest : KoinTest {
1919
private val repoAbsolutePath = Paths.get("").toAbsolutePath()
2020
private val outputBasePath = Files.createTempDirectory("SourceFileHasherTest")
21+
private val path = Paths.get("cli/src/test/kotlin/com/bazel_diff/hash/fixture/foo.ts")
2122
private val fixtureFileTarget = "//cli/src/test/kotlin/com/bazel_diff/hash/fixture:foo.ts"
2223
private val fixtureFileContent: ByteArray
2324
private val seed = "seed".toByteArray()
2425
private val externalRepoResolver = ExternalRepoResolver(repoAbsolutePath, Paths.get("bazel"), outputBasePath)
2526

2627
init {
27-
val path = Paths.get("cli/src/test/kotlin/com/bazel_diff/hash/fixture/foo.ts")
2828
fixtureFileContent = Files.readAllBytes(path)
2929
}
3030

@@ -47,6 +47,37 @@ internal class SourceFileHasherTest : KoinTest {
4747
assertThat(actual).isEqualTo(expected)
4848
}
4949

50+
@Test
51+
fun testHashConcreteFileWithModifiedFilepathsEnabled() = runBlocking {
52+
val hasher = SourceFileHasher(repoAbsolutePath, null, externalRepoResolver)
53+
val bazelSourceFileTarget = BazelSourceFileTarget(fixtureFileTarget, seed)
54+
val actual = hasher.digest(
55+
bazelSourceFileTarget,
56+
setOf(path)
57+
).toHexString()
58+
val expected = sha256 {
59+
safePutBytes(fixtureFileContent)
60+
safePutBytes(seed)
61+
safePutBytes(fixtureFileTarget.toByteArray())
62+
}.toHexString()
63+
assertThat(actual).isEqualTo(expected)
64+
}
65+
66+
@Test
67+
fun testHashConcreteFileWithModifiedFilepathsEnabledNoMatch() = runBlocking {
68+
val hasher = SourceFileHasher(repoAbsolutePath, null, externalRepoResolver)
69+
val bazelSourceFileTarget = BazelSourceFileTarget(fixtureFileTarget, seed)
70+
val actual = hasher.digest(
71+
bazelSourceFileTarget,
72+
setOf(Paths.get("some/other/path"))
73+
).toHexString()
74+
val expected = sha256 {
75+
safePutBytes(seed)
76+
safePutBytes(fixtureFileTarget.toByteArray())
77+
}.toHexString()
78+
assertThat(actual).isEqualTo(expected)
79+
}
80+
5081
@Test
5182
fun testHashConcreteFileInExternalRepo() = runBlocking {
5283
val hasher = SourceFileHasher(repoAbsolutePath, null, externalRepoResolver, setOf("external_repo"))

0 commit comments

Comments
 (0)