# Add Entire local public-repo smoke test

`cd57c23`→[main](/content/gh/entireio/git-sync/commits/main/index.html)·

Soph·3mo ago·6 files·+378 added/-4 removed

## Sessions

3ad59c31a883View transcript

## Changes

6

- MREADME.md+23

- Mgo.mod+7/-2

- Mgo.sum+10/-2

- internal/syncer

- Aentire_local_smoke_test.go+298

- Aentire_local_smoke_test_test.go+36

- Mmise.toml+4

```
315 unmodified lines

316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344

315 unmodified lines

- `mise run test:linux-smoke`
- `mise run test:linux-smoke:batched`
- `mise run test:entire-local-smoke`

The Entire local smoke expects:

- a running Entire local instance reachable at `GITSYNC_E2E_ENTIRE_BASE_URL` or `ENTIRE_BASE_URL`
- an authenticated local Entire CLI session for that host, so the smoke can discover the active user and OAuth token from `hosts.json` and the keyring
- `entiredb` on `PATH`, or `GITSYNC_E2E_ENTIREDB_BIN` pointing to it

Useful overrides:

- `GITSYNC_E2E_ENTIRE_SOURCE_URL=https://github.com/entireio/cli.git`
- `GITSYNC_E2E_ENTIRE_BRANCH=main`
- `GITSYNC_E2E_ENTIRE_REPO=git-sync-smoke`
- `GITSYNC_E2E_ENTIRE_USERNAME=...`
- `GITSYNC_E2E_ENTIRE_TOKEN=...`
- `GITSYNC_E2E_ENTIRE_SKIP_TLS_VERIFY=true`

For local/self-signed targets, `git-sync` also supports:

- `--source-insecure-skip-tls-verify`
- `--target-insecure-skip-tls-verify`
- `GITSYNC_SOURCE_INSECURE_SKIP_TLS_VERIFY=true`
- `GITSYNC_TARGET_INSECURE_SKIP_TLS_VERIFY=true`

## Planned Bootstrap Path
```
MREADME.md+23

```
1 unmodified line

2
3
4
5
5
6
7
8
9
10
11
12
1 unmodified line

14
15
16
17
18
19
15
20
21
22
23

1 unmodified line

go 1.25.2

require github.com/go-git/go-git/v5 v5.17.0
require (
	github.com/go-git/go-billy/v5 v5.8.0
	github.com/go-git/go-git/v5 v5.17.0
	github.com/zalando/go-keyring v0.2.8
)

require (
	dario.cat/mergo v1.0.0 // indirect
1 unmodified line

github.com/ProtonMail/go-crypto v1.1.6 // indirect
	github.com/cloudflare/circl v1.6.1 // indirect
	github.com/cyphar/filepath-securejoin v0.4.1 // indirect
	github.com/danieljoos/wincred v1.2.3 // indirect
	github.com/emirpasic/gods v1.18.1 // indirect
	github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
	github.com/go-git/go-billy/v5 v5.8.0 // indirect
	github.com/godbus/dbus/v5 v5.2.2 // indirect
	github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
	github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
	github.com/kevinburke/ssh_config v1.2.0 // indirect
```

Mgo.mod+7/-2

```
12 unmodified lines

13
14
15
16
17
18
19
20
11 unmodified lines

32
33
34
35
36
37
38
39
25 unmodified lines

65
66
67
68
69
70
71
66
67
72
73
74
75
76
77
78
79
80

12 unmodified lines

github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
github.com/cyphar/filepath-securejoin v0.4.1 h1:JyxxyPEaktOD+GAnqIqTf9A8tHyAG22rowi7HkoSU1s=
github.com/cyphar/filepath-securejoin v0.4.1/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI=
github.com/danieljoos/wincred v1.2.3 h1:v7dZC2x32Ut3nEfRH+vhoZGvN72+dQ/snVXo/vMFLdQ=
github.com/danieljoos/wincred v1.2.3/go.mod h1:6qqX0WNrS4RzPZ1tnroDzq9kY3fu1KwE7MRLQK4X0bs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

11 unmodified lines

github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
github.com/go-git/go-git/v5 v5.17.0 h1:AbyI4xf+7DsjINHMu35quAh4wJygKBKBuXVjV/pxesM=
github.com/go-git/go-git/v5 v5.17.0/go.mod h1:f82C4YiLx+Lhi8eHxltLeGC5uBTXSFa6PC5WW9o4SjI=
github.com/godbus/dbus/v5 v5.2.2 h1:TUR3TgtSVDmjiXOgAAyaZbYmIeP3DPkld3jgKGV8mXQ=
github.com/godbus/dbus/v5 v5.2.2/go.mod h1:3AAv2+hPq5rdnr5txxxRwiGjPXamgoIHgz9FPBfOp3c=
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ=
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=

25 unmodified lines

github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnBY8=
github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/zalando/go-keyring v0.2.8 h1:6sD/Ucpl7jNq10rM2pgqTs0sZ9V3qMrqfIIy5YPccHs=
github.com/zalando/go-keyring v0.2.8/go.mod h1:tsMo+VpRq5NGyKfxoBVjCuMrG47yj8cmakZDO5QGii0=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
```

Mgo.sum+10/-2

```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298

package syncer

import (
	"context"
	"encoding/json"
	"fmt"
	"net/url"
	"os"
	"os/exec"
	"path/filepath"
	"strings"
	"testing"

"github.com/zalando/go-keyring"
)

const entireLocalSmokeEnv = "GITSYNC_E2E_ENTIRE"

type entireHosts map[string]entireHostInfo

type entireHostInfo struct {
	ActiveUser string   `json:"activeUser"`
	Users      []string `json:"users"`
}

type entireHostsFile struct {
	ActiveHost string      `json:"activeHost"`
	Hosts      entireHosts `json:"hosts"`
}

func TestRun_EntireLocalPublicRepoSmoke(t *testing.T) {
	if os.Getenv(entireLocalSmokeEnv) == "" {
		t.Skip("set GITSYNC_E2E_ENTIRE=1 to run the Entire local smoke test")
	}

baseURL := firstNonEmpty(
		os.Getenv("GITSYNC_E2E_ENTIRE_BASE_URL"),
		os.Getenv("ENTIRE_BASE_URL"),
	)
	if baseURL == "" {
		t.Skip("set GITSYNC_E2E_ENTIRE_BASE_URL or ENTIRE_BASE_URL to your local Entire base URL")
	}

sourceURL := firstNonEmpty(
		os.Getenv("GITSYNC_E2E_ENTIRE_SOURCE_URL"),
		"https://github.com/entireio/cli.git",
	)
	branch := firstNonEmpty(
		os.Getenv("GITSYNC_E2E_ENTIRE_BRANCH"),
		"main",
	)
	repoName := firstNonEmpty(
		os.Getenv("GITSYNC_E2E_ENTIRE_REPO"),
		"git-sync-smoke",
	)
	username := os.Getenv("GITSYNC_E2E_ENTIRE_USERNAME")
	token := os.Getenv("GITSYNC_E2E_ENTIRE_TOKEN")
	skipTLSVerify := envBoolDefault("GITSYNC_E2E_ENTIRE_SKIP_TLS_VERIFY", true)

host, err := credentialHost(baseURL)
	if err != nil {
		t.Fatalf("parse entire base URL: %%v", err)
	}
	resolvedHost, err := resolveEntireCredentialHost(host)
	if err != nil {
		t.Fatalf("resolve Entire credential host: %%v", err)
	}
	host = resolvedHost
	if username == "" {
		username, err = activeEntireUser(host)
		if err != nil {
			t.Fatalf("determine active Entire user: %%v", err)
		}
	}
	if token == "" {
		token, err = lookupEntireToken(host, username)
		if err != nil {
			t.Fatalf("lookup Entire token: %%v", err)
		}
	}

if err := ensureEntireRepo(t, baseURL, repoName, skipTLSVerify); err != nil {
		t.Fatalf("ensure Entire repo exists: %%v", err)
	}

targetURL := strings.TrimRight(baseURL, "/") + "/git/" + username + "/" + repoName
	result, err := Run(context.Background(), Config{
		Source: Endpoint{URL: sourceURL},
		Target: Endpoint{
			URL:           targetURL,
			Username:      "git",
			Token:         token,
			SkipTLSVerify: skipTLSVerify,
		},
		Branches: []string{branch},
		Verbose:  true,
	})
	if err != nil {
		t.Fatalf("sync public source into Entire failed: %%v", err)
	}
	if result.Blocked != 0 {
		t.Fatalf("expected no blocked refs, got %+v", result)
	}

sourceProbe, err := Probe(context.Background(), Config{
		Source: Endpoint{URL: sourceURL},
	})
	if err != nil {
		t.Fatalf("probe source refs: %%v", err)
	}
	targetProbe, err := Probe(context.Background(), Config{
		Source: Endpoint{
			URL:           targetURL,
			Username:      "git",
			Token:         token,
			SkipTLSVerify: skipTLSVerify,
		},
	})
	if err != nil {
		t.Fatalf("probe target refs: %%v", err)
	}

wantRef := "refs/heads/" + branch
	sourceHash, ok := refHashFromInfos(sourceProbe.Refs, wantRef)
	if !ok {
		t.Fatalf("source ref %%s not found in probe response", wantRef)
	}
	targetHash, ok := refHashFromInfos(targetProbe.Refs, wantRef)
	if !ok {
		t.Fatalf("target ref %%s not found in probe response", wantRef)
	}
	if sourceHash != targetHash {
		t.Fatalf("target ref %%s mismatch: source=%%s target=%%s", wantRef, sourceHash, targetHash)
	}
}

func ensureEntireRepo(t *testing.T, baseURL, repoName string, skipTLSVerify bool) error {
	t.Helper()

bin, err := entireCLIBinary()
	if err != nil {
		return err
	}

listCmd := exec.CommandContext(t.Context(), bin, "repo", "list")
	listCmd.Env = append(os.Environ(), entireCLIEnv(baseURL, skipTLSVerify)...)  
	output, err := listCmd.CombinedOutput()
	if err != nil {
		return fmt.Errorf("list repos with entiredb: %%w\n%s", err, strings.TrimSpace(string(output)))
	}
	for _, line := range strings.Split(string(output), "\n") {
		if strings.TrimSpace(line) == repoName {
			return nil
		}
	}

createCmd := exec.CommandContext(t.Context(), bin, "repo", "create", repoName)
	createCmd.Env = append(os.Environ(), entireCLIEnv(baseURL, skipTLSVerify)...)  
	output, err = createCmd.CombinedOutput()
	if err != nil {
		return fmt.Errorf("create repo with entiredb: %%w\n%s", err, strings.TrimSpace(string(output)))
	}
	return nil
}

func entireCLIBinary() (string, error) {
	if path := os.Getenv("GITSYNC_E2E_ENTIREDB_BIN"); path != "" {
		return path, nil
	}
	if path, err := exec.LookPath("entiredb"); err == nil {
		return path, nil
	}
	return "", fmt.Errorf("could not find entiredb; set GITSYNC_E2E_ENTIREDB_BIN or put entiredb on PATH")
}

func entireCLIEnv(baseURL string, skipTLSVerify bool) []string {
	env := []string{"ENTIRE_BASE_URL=" + baseURL}
	if configDir := os.Getenv("ENTIRE_CONFIG_DIR"); configDir != "" {
		env = append(env, "ENTIRE_CONFIG_DIR="+configDir)
	}
	if skipTLSVerify {
		env = append(env, "ENTIRE_TLS_SKIP_VERIFY=true")
	}
	return env
}

func credentialHost(baseURL string) (string, error) {
	parsed, err := url.Parse(baseURL)
	if err != nil {
		return "", err
	}
	if parsed.Host == "" {
		return "", fmt.Errorf("missing host in %%q", baseURL)
	}
	return parsed.Host, nil
}

func activeEntireUser(host string) (string, error) {
	hosts, _, err := loadEntireHosts()
	if err != nil {
		return "", err
	}
	info, ok := hosts[host]
	if !ok || info.ActiveUser == "" {
		return "", fmt.Errorf("no active Entire user recorded for host %%s", host)
	}
	return info.ActiveUser, nil
}

func resolveEntireCredentialHost(requestedHost string) (string, error) {
	hosts, activeHost, err := loadEntireHosts()
	if err != nil {
		return "", err
	}
	if requestedHost != "" {
		if _, ok := hosts[requestedHost]; ok {
			return requestedHost, nil
		}
	}
	if activeHost != "" {
		if _, ok := hosts[activeHost]; ok {
			return activeHost, nil
		}
	}
	return requestedHost, nil
}

func lookupEntireToken(host, username string) (string, error) {
	encoded, err := keyring.Get("entire:"+host, username)
	if err != nil {
		return "", err
	}
	if idx := strings.LastIndex(encoded, "|"); idx != -1 {
		return encoded[:idx], nil
	}
	return encoded, nil
}

func entireConfigDir() string {
	if dir := os.Getenv("ENTIRE_CONFIG_DIR"); dir != "" {
		return dir
	}
	home, err := os.UserHomeDir()
	if err != nil {
		return "."
	}
	return filepath.Join(home, ".config", "entire")
}

func loadEntireHosts() (entireHosts, string, error) {
	data, err := os.ReadFile(filepath.Join(entireConfigDir(), "hosts.json"))
	if err != nil {
		return nil, "", fmt.Errorf("read hosts.json: %%w", err)
	}

var wrapped entireHostsFile
	if err := json.Unmarshal(data, &wrapped); err == nil && len(wrapped.Hosts) > 0 {
		return wrapped.Hosts, wrapped.ActiveHost, nil
	}

var hosts entireHosts
	if err := json.Unmarshal(data, &hosts); err != nil {
		return nil, "", fmt.Errorf("decode hosts.json: %%w", err)
	}
	return hosts, "", nil
}

func envBoolDefault(key string, defaultValue bool) bool {
	value := strings.TrimSpace(strings.ToLower(os.Getenv(key)))
	switch value {
	case "1", "true", "yes", "on":
		return true
	case "0", "false", "no", "off":
		return false
	case "":
		return defaultValue
	default:
		return defaultValue
	}
}

func firstNonEmpty(values ...string) string {
	for _, value := range values {
		if strings.TrimSpace(value) != "" {
			return value
		}
	}
	return ""
}

func refHashFromInfos(refs []RefInfo, name string) (string, bool) {
	for _, ref := range refs {
		if ref.Name == name {
			return ref.Hash.String(), true
		}
	}
	return "", false
}
}

Ainternal/syncer/entire_local_smoke_test.go+298

```

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

package syncer

import (
	"os"
	"path/filepath"
	"testing"
)

func TestLoadEntireHostsWrappedFormat(t *testing.T) {
	configDir := t.TempDir()
	 t.Setenv("ENTIRE_CONFIG_DIR", configDir)

data := []byte(`{
  "activeHost": "127.0.0.1:8080",
  "hosts": {
    "127.0.0.1:8080": {
      "activeUser": "soph",
      "users": ["soph"]
    }
  }
}`)
	if err := os.WriteFile(filepath.Join(configDir, "hosts.json"), data, 0o600); err != nil {
		t.Fatalf("write hosts.json: %%v", err)
	}

hosts, activeHost, err := loadEntireHosts()
	if err != nil {
		t.Fatalf("load hosts: %%v", err)
	}
	if activeHost != "127.0.0.1:8080" {
		t.Fatalf("unexpected active host: %%q", activeHost)
	}
	if hosts["127.0.0.1:8080"].ActiveUser != "soph" {
		t.Fatalf("unexpected active user: %+v", hosts["127.0.0.1:8080"])
	}
}
}

Ainternal/syncer/entire_local_smoke_test_test.go+36

```

23 unmodified lines

24
25
26
27
28
29
30
31
32
33

23 unmodified lines

description = "Run optional live linux batched bootstrap smoke test"
run = "GITSYNC_E2E_LIVE_LINUX=1 go test ./internal/syncer -run TestBootstrap_LiveLinuxSourceBatched -timeout 60m -v"

[tasks."test:entire-local-smoke"]
description = "Run optional smoke syncing a public repo into a running Entire local instance"
run = "GITSYNC_E2E_ENTIRE=1 go test ./internal/syncer -run TestRun_EntireLocalPublicRepoSmoke -timeout 30m -v"

[tasks.build]
description = "Build git-sync"
run = "go build ./cmd/git-sync"
```
