Git designed for AI agents.
quarantine: a test of the writers' durability contract (WP95)
Federico Eliae30c83390d39
diff --git a/internal/git/quarantine/writers_test.go b/internal/git/quarantine/writers_test.gonew file mode 100644index 0000000..f7ea643--- /dev/null+++ b/internal/git/quarantine/writers_test.go@@ -0,0 +1,83 @@+package quarantine++import (+ "os"+ "path/filepath"+ "sort"+ "strings"+ "testing"++ "github.com/stretchr/testify/require"+)++// TestQuarantineWritersKeepTheDurabilityContract checks the source of the server for the places+// that decide how the writers of a quarantine fsync their objects, so that a new one is noticed and+// checked against the contract of Dir (every file of a quarantine is durable before Migrate):+//+// - core.fsync is set only by the command factory, for every git command, with objects in it;+// by WithoutObjectFsync, whose helpers' objects the batch attempts pack into one fsynced pack+// before their update; and by the custom hooks' environment, which repeats the factory's value.+// - WithoutObjectFsync is used only by the rebase engine's deferred durability, which only the+// pack mode of the batch attempts asks for.+//+// It cannot see a configuration key that is not written as a literal, such as the configuration+// options of a client's push, which git receive-pack applies to its own quarantine and not to one+// that Migrate moves.+func TestQuarantineWritersKeepTheDurabilityContract(t *testing.T) {+ t.Parallel()++ root, err := filepath.Abs(filepath.Join("..", "..", ".."))+ require.NoError(t, err)+ require.FileExists(t, filepath.Join(root, "go.mod"))++ uses := map[string][]string{}+ for _, dir := range []string{"internal", "cmd"} {+ require.NoError(t, filepath.WalkDir(filepath.Join(root, dir), func(path string, entry os.DirEntry, err error) error {+ if err != nil {+ return err+ }+ if entry.IsDir() || !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") {+ return nil+ }++ data, err := os.ReadFile(path)+ if err != nil {+ return err+ }+ rel, err := filepath.Rel(root, path)+ if err != nil {+ return err+ }+ for _, needle := range []string{`"core.fsync"`, `"core.fsyncMethod"`, `WithoutObjectFsync()`} {+ if strings.Contains(string(data), needle) {+ uses[needle] = append(uses[needle], rel)+ }+ }+ return nil+ }))+ }+ for _, files := range uses {+ sort.Strings(files)+ }++ require.Equal(t, map[string][]string{+ `"core.fsync"`: {+ "internal/git/gitcmd/command_factory.go",+ "internal/git/localrepo/merge_tree_stream.go",+ "internal/gitaly/hook/custom.go",+ },+ `"core.fsyncMethod"`: {+ "internal/git/gitcmd/command_factory.go",+ "internal/gitaly/hook/custom.go",+ },+ `WithoutObjectFsync()`: {+ "internal/git/localrepo/merge_tree_stream.go",+ "internal/graft/rebase/engine.go",+ },+ }, uses, "a new place decides how objects are fsynced: check it against the durability contract of quarantine.Dir and add it here")++ factory, err := os.ReadFile(filepath.Join(root, "internal/git/gitcmd/command_factory.go"))+ require.NoError(t, err)+ require.Contains(t, string(factory), `ConfigPair{Key: "core.fsync", Value: "objects,derived-metadata,reference"}`,+ "the command factory fsyncs the objects of every git command")+}