@@ -59,6 +59,8 @@ func TestIsDeltaExcluded(t *testing.T) {
5959 excluded := []string {
6060 "fileHashes" ,
6161 "module-metadata.bin" ,
62+ "module-artifact.bin" ,
63+ "resource-at-url.bin" ,
6264 }
6365 for _ , name := range excluded {
6466 if ! IsDeltaExcluded (name ) {
@@ -806,6 +808,67 @@ func TestDeltaTarZstdRoundTrip(t *testing.T) {
806808 }
807809}
808810
811+ func TestStampedDeltaRoundTrip (t * testing.T ) {
812+ baseCommit := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
813+ gradleHome := t .TempDir ()
814+ cachesDir := filepath .Join (gradleHome , "caches" , "modules-2" )
815+ must (t , os .MkdirAll (cachesDir , 0o755 ))
816+ must (t , os .WriteFile (filepath .Join (cachesDir , "delta-file.bin" ), []byte ("delta" ), 0o644 ))
817+
818+ // Create a stamped delta archive.
819+ var buf bytes.Buffer
820+ must (t , createStampedDeltaTarZstdMulti (& buf , baseCommit ,
821+ DeltaSource {BaseDir : gradleHome , RelPaths : []string {"caches/modules-2/delta-file.bin" }}))
822+
823+ // ReadDeltaBaseCommit should return the embedded stamp.
824+ r := bytes .NewReader (buf .Bytes ())
825+ got , err := ReadDeltaBaseCommit (r )
826+ must (t , err )
827+ if got != baseCommit {
828+ t .Fatalf ("ReadDeltaBaseCommit = %q, want %q" , got , baseCommit )
829+ }
830+
831+ // The file should still extract correctly (stamp entry is skipped).
832+ dstDir := t .TempDir ()
833+ must (t , extractTarZstd (context .Background (), bytes .NewReader (buf .Bytes ()), dstDir ))
834+
835+ data , err := os .ReadFile (filepath .Join (dstDir , "caches" , "modules-2" , "delta-file.bin" ))
836+ must (t , err )
837+ if string (data ) != "delta" {
838+ t .Fatalf ("extracted content = %q, want %q" , string (data ), "delta" )
839+ }
840+
841+ // __base_commit__ should NOT exist as a file on disk.
842+ if _ , err := os .Stat (filepath .Join (dstDir , deltaBaseCommitEntry )); err == nil {
843+ t .Fatal ("__base_commit__ should not be extracted as a real file" )
844+ }
845+ }
846+
847+ func TestReadDeltaBaseCommitMissing (t * testing.T ) {
848+ // An unstamped delta should return empty string.
849+ var buf bytes.Buffer
850+ must (t , CreateDeltaTarZstdMulti (& buf ,
851+ DeltaSource {BaseDir : t .TempDir (), RelPaths : nil }))
852+
853+ r := bytes .NewReader (buf .Bytes ())
854+ got , err := ReadDeltaBaseCommit (r )
855+ must (t , err )
856+ if got != "" {
857+ t .Fatalf ("ReadDeltaBaseCommit on unstamped delta = %q, want empty" , got )
858+ }
859+ }
860+
861+ func TestBaseCommitFileRoundTrip (t * testing.T ) {
862+ dir := t .TempDir ()
863+ sha := "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
864+ must (t , writeBaseCommitFile (dir , sha ))
865+ got , err := readBaseCommitFile (dir )
866+ must (t , err )
867+ if got != sha {
868+ t .Fatalf ("readBaseCommitFile = %q, want %q" , got , sha )
869+ }
870+ }
871+
809872func TestSaveDeltaDefaultsProjectDirToWorkingDirectory (t * testing.T ) {
810873 ctx := context .Background ()
811874 gradleHome := t .TempDir ()
@@ -817,6 +880,8 @@ func TestSaveDeltaDefaultsProjectDirToWorkingDirectory(t *testing.T) {
817880
818881 markerPath := filepath .Join (gradleHome , ".cache-restore-marker" )
819882 must (t , touchMarkerFile (markerPath ))
883+ // Write a base commit file so SaveDelta can stamp the delta.
884+ must (t , writeBaseCommitFile (gradleHome , "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ))
820885
821886 // Sleep to ensure files created below have a strictly newer mtime than
822887 // the marker. On Linux ext4 the mtime granularity is 1 ms, but rapid
0 commit comments