|
| 1 | +// Build a tiny git repo with two committed checkpoints so the entire |
| 2 | +// binary can be exercised against real data without spinning up an agent. |
| 3 | +// Used by manual end-to-end verification of `entire checkpoint search --local`. |
| 4 | +// Run: go run ./scripts/seed-local-search-fixture <repo-dir> |
| 5 | +package main |
| 6 | + |
| 7 | +import ( |
| 8 | + "context" |
| 9 | + "fmt" |
| 10 | + "os" |
| 11 | + "os/exec" |
| 12 | + "path/filepath" |
| 13 | + |
| 14 | + "github.com/entireio/cli/cmd/entire/cli/checkpoint" |
| 15 | + "github.com/entireio/cli/cmd/entire/cli/checkpoint/id" |
| 16 | + "github.com/entireio/cli/redact" |
| 17 | + |
| 18 | + "github.com/go-git/go-git/v6" |
| 19 | + "github.com/go-git/go-git/v6/plumbing/object" |
| 20 | +) |
| 21 | + |
| 22 | +func main() { |
| 23 | + if len(os.Args) != 2 { |
| 24 | + fmt.Fprintln(os.Stderr, "usage: seed-local-search-fixture <repo-dir>") |
| 25 | + os.Exit(2) |
| 26 | + } |
| 27 | + dir := os.Args[1] |
| 28 | + if err := run(dir); err != nil { |
| 29 | + fmt.Fprintf(os.Stderr, "seed failed: %v\n", err) |
| 30 | + os.Exit(1) |
| 31 | + } |
| 32 | + fmt.Printf("seeded fixture repo at %s\n", dir) |
| 33 | +} |
| 34 | + |
| 35 | +func run(dir string) error { |
| 36 | + if err := os.MkdirAll(dir, 0o755); err != nil { |
| 37 | + return fmt.Errorf("mkdir: %w", err) |
| 38 | + } |
| 39 | + repo, err := git.PlainInit(dir, false) |
| 40 | + if err != nil { |
| 41 | + return fmt.Errorf("git init: %w", err) |
| 42 | + } |
| 43 | + // Disable gpg signing for the initial commit, otherwise PlainInit-created |
| 44 | + // repos pick up the user's global config and the commit will fail in CI. |
| 45 | + cmd := exec.Command("git", "-C", dir, "config", "commit.gpgsign", "false") |
| 46 | + if out, err := cmd.CombinedOutput(); err != nil { |
| 47 | + return fmt.Errorf("disable gpgsign: %w: %s", err, out) |
| 48 | + } |
| 49 | + |
| 50 | + readme := filepath.Join(dir, "README.md") |
| 51 | + if err := os.WriteFile(readme, []byte("# fixture\n"), 0o644); err != nil { |
| 52 | + return fmt.Errorf("write README: %w", err) |
| 53 | + } |
| 54 | + wt, err := repo.Worktree() |
| 55 | + if err != nil { |
| 56 | + return fmt.Errorf("worktree: %w", err) |
| 57 | + } |
| 58 | + if _, err := wt.Add("README.md"); err != nil { |
| 59 | + return fmt.Errorf("git add: %w", err) |
| 60 | + } |
| 61 | + if _, err := wt.Commit("init", &git.CommitOptions{ |
| 62 | + Author: &object.Signature{Name: "Fixture", Email: "fixture@example.com"}, |
| 63 | + }); err != nil { |
| 64 | + return fmt.Errorf("git commit: %w", err) |
| 65 | + } |
| 66 | + |
| 67 | + store := checkpoint.NewGitStore(repo) |
| 68 | + fixtures := []struct { |
| 69 | + id string |
| 70 | + branch string |
| 71 | + filesTouched []string |
| 72 | + prompt string |
| 73 | + transcript string |
| 74 | + }{ |
| 75 | + { |
| 76 | + id: "a1b2c3d4e5f6", |
| 77 | + branch: "main", |
| 78 | + filesTouched: []string{"src/auth.go"}, |
| 79 | + prompt: "Fix the login flow", |
| 80 | + transcript: "assistant: I rewrote the Lefthook config to call entire instead.\n", |
| 81 | + }, |
| 82 | + { |
| 83 | + id: "b2c3d4e5f6a7", |
| 84 | + branch: "feature", |
| 85 | + filesTouched: []string{"docs/intro.md"}, |
| 86 | + prompt: "Add intro docs", |
| 87 | + transcript: "assistant: drafted an intro section about onboarding.\n", |
| 88 | + }, |
| 89 | + } |
| 90 | + for _, f := range fixtures { |
| 91 | + if err := store.WriteCommitted(context.Background(), checkpoint.WriteCommittedOptions{ |
| 92 | + CheckpointID: id.MustCheckpointID(f.id), |
| 93 | + SessionID: "session-" + f.id, |
| 94 | + Strategy: "manual-commit", |
| 95 | + Branch: f.branch, |
| 96 | + FilesTouched: f.filesTouched, |
| 97 | + Prompts: []string{f.prompt}, |
| 98 | + Transcript: redact.AlreadyRedacted([]byte(f.transcript)), |
| 99 | + AuthorName: "Fixture", |
| 100 | + AuthorEmail: "fixture@example.com", |
| 101 | + }); err != nil { |
| 102 | + return fmt.Errorf("write checkpoint %s: %w", f.id, err) |
| 103 | + } |
| 104 | + } |
| 105 | + return nil |
| 106 | +} |
0 commit comments