[2.x] test: Test transitive cached task (#8579)

Co-authored-by: mkdev11 <noreply@users.noreply.github.com>
This commit is contained in:
MkDev11 2026-01-19 22:40:37 -05:00 committed by GitHub
parent c5af677632
commit b6cdfe0d81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,27 @@
import sbt.internal.util.StringVirtualFile1
val task2 = taskKey[Unit]("Upstream cached task that produces t2.txt")
val task1 = taskKey[Unit]("Downstream cached task that depends on task2 and produces t1.txt")
val checkTask = taskKey[Unit]("Check that files exist")
Global / localCacheDirectory := baseDirectory.value / "diskcache"
task2 := {
val output = StringVirtualFile1("target/out/t2.txt", "task2 output")
Def.declareOutput(output)
()
}
task1 := {
task2.value
val output = StringVirtualFile1("target/out/t1.txt", "task1 output")
Def.declareOutput(output)
()
}
checkTask := Def.uncached {
val t1File = baseDirectory.value / "target" / "out" / "t1.txt"
val t2File = baseDirectory.value / "target" / "out" / "t2.txt"
assert(t1File.exists(), s"t1.txt should exist")
assert(t2File.exists(), s"t2.txt should exist")
}

View File

@ -0,0 +1,18 @@
# Test for transitive cached task side effects
# See https://github.com/sbt/sbt/issues/8578
# First run: both tasks execute and produce outputs
> startServer
> task1
$ exists target/out/t1.txt
$ exists target/out/t2.txt
> checkTask
# Test cache restoration after clean
> clean
# After clean, running task1 should restore both t1.txt and t2.txt from cache
> task1
$ exists target/out/t1.txt
$ exists target/out/t2.txt
> checkTask