vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Cover Godot, Unity, and Unreal LFS repositories
7b812b6fabb1eb3492a585cc81f54eadf20867e5 · Keenan Nemetz · 13d ago · parent ee29fa1b
Cover Godot, Unity, and Unreal LFS repositories Model each engine's split between binary assets in LFS and small text (project.godot, .tscn, .import; .meta and ProjectSettings; .uproject and Config) that must stay readable in Git. Push with the real git-lfs client, clone over HTTP, and compare every byte. The suite also covers a raw-binary warning without false positives on large text, git lfs migrate import of existing history, locks with spaces and non-ASCII names enforced at the server, the SSH-only lock surface, and a release archive that resolves pointers.
server/lfs_games_test.go +491
| @@ -0,0 +1,491 @@ | |||
| 1 | package server_test | ||
| 2 | |||
| 3 | // A spike: do the LFS paths behave for the three engines a game team is likely | ||
| 4 | // to bring? Each engine has a different split between bytes that belong in LFS | ||
| 5 | // and small text that must stay in git (Godot `.import`, Unity `.meta`, Unreal | ||
| 6 | // `.uproject`), so a real client is the only way to know the split survives a | ||
| 7 | // push, a clone, and a lock. | ||
| 8 | // | ||
| 9 | // These are exploratory tests, kept separate from lfs_test.go so a finding here | ||
| 10 | // is easy to point at. They skip when git-lfs is absent, like the rest. | ||
| 11 | |||
| 12 | import ( | ||
| 13 | "bytes" | ||
| 14 | "crypto/sha256" | ||
| 15 | "encoding/hex" | ||
| 16 | "fmt" | ||
| 17 | "os" | ||
| 18 | "path/filepath" | ||
| 19 | "strings" | ||
| 20 | "testing" | ||
| 21 | ) | ||
| 22 | |||
| 23 | // engineFile is one file a repository carries: whether git-lfs should turn it | ||
| 24 | // into a pointer, and the bytes it should get back on checkout. | ||
| 25 | type engineFile struct { | ||
| 26 | path string | ||
| 27 | data []byte | ||
| 28 | lfs bool | ||
| 29 | } | ||
| 30 | |||
| 31 | // gameRepo initialises a repository the way a game team does: git-lfs installed | ||
| 32 | // locally, the engine's patterns tracked, then the project files added. It | ||
| 33 | // returns the work tree and the files, so a test can check both sides. | ||
| 34 | func gameRepo(t *testing.T, remote string, patterns []string, files []engineFile) string { | ||
| 35 | t.Helper() | ||
| 36 | dir := t.TempDir() | ||
| 37 | if _, errs, err := runGit(t, dir, "init", "-q", "-b", "main"); err != nil { | ||
| 38 | t.Fatalf("init: %v: %s", err, errs) | ||
| 39 | } | ||
| 40 | if _, errs, err := runGit(t, dir, "lfs", "install", "--local"); err != nil { | ||
| 41 | t.Fatalf("git lfs install: %v: %s", err, errs) | ||
| 42 | } | ||
| 43 | args := append([]string{"lfs", "track"}, patterns...) | ||
| 44 | if _, errs, err := runGit(t, dir, args...); err != nil { | ||
| 45 | t.Fatalf("git lfs track: %v: %s", err, errs) | ||
| 46 | } | ||
| 47 | for _, file := range files { | ||
| 48 | p := filepath.Join(dir, filepath.FromSlash(file.path)) | ||
| 49 | if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil { | ||
| 50 | t.Fatal(err) | ||
| 51 | } | ||
| 52 | if err := os.WriteFile(p, file.data, 0o644); err != nil { | ||
| 53 | t.Fatal(err) | ||
| 54 | } | ||
| 55 | } | ||
| 56 | if remote != "" { | ||
| 57 | if _, errs, err := runGit(t, dir, "remote", "add", "origin", remote); err != nil { | ||
| 58 | t.Fatalf("add remote: %v: %s", err, errs) | ||
| 59 | } | ||
| 60 | } | ||
| 61 | if _, errs, err := runGit(t, dir, "add", "-A"); err != nil { | ||
| 62 | t.Fatalf("add: %v: %s", err, errs) | ||
| 63 | } | ||
| 64 | if _, errs, err := runGit(t, dir, "commit", "-qm", "initial game project"); err != nil { | ||
| 65 | t.Fatalf("commit: %v: %s", err, errs) | ||
| 66 | } | ||
| 67 | return dir | ||
| 68 | } | ||
| 69 | |||
| 70 | // payload returns deterministic bytes. It deliberately contains NULs, because | ||
| 71 | // that is what makes a texture, mesh, or asset file binary to git. | ||
| 72 | func payload(n int, seed byte) []byte { | ||
| 73 | b := make([]byte, n) | ||
| 74 | for i := range b { | ||
| 75 | b[i] = seed + byte(i%251) | ||
| 76 | if i%997 == 0 { | ||
| 77 | b[i] = 0 | ||
| 78 | } | ||
| 79 | } | ||
| 80 | return b | ||
| 81 | } | ||
| 82 | |||
| 83 | func sha256Hex(b []byte) string { | ||
| 84 | sum := sha256.Sum256(b) | ||
| 85 | return hex.EncodeToString(sum[:]) | ||
| 86 | } | ||
| 87 | |||
| 88 | // pushEngine pushes over SSH with real git-lfs and checks that exactly the | ||
| 89 | // tracked files became pointers and their bytes reached this instance's store. | ||
| 90 | func pushEngine(t *testing.T, f *fixture, dir string, files []engineFile) { | ||
| 91 | t.Helper() | ||
| 92 | if out, errs, err := f.git(dir, "push", f.sshURL(f.repo), "main:refs/heads/main"); err != nil { | ||
| 93 | t.Fatalf("push: %v\nstdout:\n%s\nstderr:\n%s", err, out, errs) | ||
| 94 | } | ||
| 95 | for _, file := range files { | ||
| 96 | if !file.lfs { | ||
| 97 | continue | ||
| 98 | } | ||
| 99 | oid := sha256Hex(file.data) | ||
| 100 | if !f.srv.LFS.Has(f.repo, oid) { | ||
| 101 | t.Errorf("%s: LFS object %s is not in the store after push", file.path, oid) | ||
| 102 | continue | ||
| 103 | } | ||
| 104 | ptr, errs, err := runGit(t, dir, "cat-file", "blob", "HEAD:"+file.path) | ||
| 105 | if err != nil { | ||
| 106 | t.Fatalf("read committed %s: %v: %s", file.path, err, errs) | ||
| 107 | } | ||
| 108 | want := fmt.Sprintf("version https://git-lfs.github.com/spec/v1\noid sha256:%s\nsize %d\n", oid, len(file.data)) | ||
| 109 | if ptr != want { | ||
| 110 | t.Errorf("%s is not the canonical pointer:\n got: %q\nwant: %q", file.path, ptr, want) | ||
| 111 | } | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | // cloneEngine pulls the repository over the anonymous HTTP clone and asks | ||
| 116 | // git-lfs for the bytes. Every file must come back exactly. | ||
| 117 | func cloneEngine(t *testing.T, f *fixture, files []engineFile) string { | ||
| 118 | t.Helper() | ||
| 119 | return cloneEngineFrom(t, f, "", files) | ||
| 120 | } | ||
| 121 | |||
| 122 | // cloneEngineFrom is cloneEngine with a choice of read transport. Locks are | ||
| 123 | // only on SSH, so a lock test has to clone the way a person who locks would. | ||
| 124 | func cloneEngineFrom(t *testing.T, f *fixture, url string, files []engineFile) string { | ||
| 125 | t.Helper() | ||
| 126 | if url == "" { | ||
| 127 | url = f.httpURL(f.repo) | ||
| 128 | } | ||
| 129 | dst := filepath.Join(t.TempDir(), "clone") | ||
| 130 | if _, errs, err := f.git("", "clone", "-q", url, dst); err != nil { | ||
| 131 | t.Fatalf("clone: %v\n%s", err, errs) | ||
| 132 | } | ||
| 133 | if _, errs, err := runGit(t, dst, "lfs", "install", "--local"); err != nil { | ||
| 134 | t.Fatalf("git lfs install in clone: %v\n%s", err, errs) | ||
| 135 | } | ||
| 136 | if out, errs, err := f.git(dst, "lfs", "pull"); err != nil { | ||
| 137 | t.Fatalf("git lfs pull: %v\nstdout:\n%s\nstderr:\n%s", err, out, errs) | ||
| 138 | } | ||
| 139 | for _, file := range files { | ||
| 140 | got, err := os.ReadFile(filepath.Join(dst, filepath.FromSlash(file.path))) | ||
| 141 | if err != nil { | ||
| 142 | t.Errorf("%s: %v", file.path, err) | ||
| 143 | continue | ||
| 144 | } | ||
| 145 | if !bytes.Equal(got, file.data) { | ||
| 146 | t.Errorf("%s came back as %d bytes; want the %d pushed bytes", file.path, len(got), len(file.data)) | ||
| 147 | } | ||
| 148 | } | ||
| 149 | return dst | ||
| 150 | } | ||
| 151 | |||
| 152 | func TestGameEngineLFSRoundTrip(t *testing.T) { | ||
| 153 | t.Parallel() | ||
| 154 | needGitLFS(t) | ||
| 155 | |||
| 156 | cases := []struct { | ||
| 157 | name string | ||
| 158 | patterns []string | ||
| 159 | files []engineFile | ||
| 160 | }{ | ||
| 161 | { | ||
| 162 | name: "godot", | ||
| 163 | // Godot's own recommendation: art and audio in LFS, `.import` sidecars | ||
| 164 | // and `.tscn` scenes in git because they are small text that merges. | ||
| 165 | patterns: []string{"*.png", "*.ogg", "*.glb", "*.blend"}, | ||
| 166 | files: []engineFile{ | ||
| 167 | {"project.godot", []byte("config_version=5\n\n[application]\nconfig/name=\"Spike\"\n"), false}, | ||
| 168 | {"assets/hero.png", payload(96<<10, 3), true}, | ||
| 169 | {"assets/hero.png.import", []byte("[remap]\n\nimporter=\"texture\"\ntype=\"CompressedTexture2D\"\n"), false}, | ||
| 170 | {"scenes/level_01.tscn", []byte("[gd_scene load_steps=2 format=3]\n\n[node name=\"Level\" type=\"Node2D\"]\n"), false}, | ||
| 171 | {"audio/theme.ogg", payload(48<<10, 11), true}, | ||
| 172 | {"models/ship.glb", payload(64<<10, 23), true}, | ||
| 173 | {"sprites/icon.svg", []byte("<svg xmlns=\"http://www.w3.org/2000/svg\"/>\n"), false}, | ||
| 174 | }, | ||
| 175 | }, | ||
| 176 | { | ||
| 177 | name: "unity", | ||
| 178 | // Unity's split: binary art/audio in LFS, `.meta` and ProjectSettings in | ||
| 179 | // git. `.unity`/`.prefab` are YAML, but teams put them in LFS because | ||
| 180 | // they are large and unmergeable. | ||
| 181 | patterns: []string{"*.psd", "*.png", "*.wav", "*.fbx", "*.unity", "*.prefab"}, | ||
| 182 | files: []engineFile{ | ||
| 183 | {"Assets/Art/Hero.psd", payload(72<<10, 5), true}, | ||
| 184 | {"Assets/Art/Hero.psd.meta", []byte("fileFormatVersion: 2\nguid: 0123456789abcdef0123456789abcdef\n"), false}, | ||
| 185 | {"Assets/Scenes/Level01.unity", payload(80<<10, 7), true}, | ||
| 186 | {"Assets/Scenes/Level01.unity.meta", []byte("fileFormatVersion: 2\nguid: fedcba9876543210fedcba9876543210\n"), false}, | ||
| 187 | {"Assets/Audio/Explosion.wav", payload(40<<10, 13), true}, | ||
| 188 | {"Assets/Prefabs/Player.prefab", payload(32<<10, 17), true}, | ||
| 189 | {"Packages/manifest.json", []byte("{\"dependencies\":{}}\n"), false}, | ||
| 190 | {"ProjectSettings/ProjectVersion.txt", []byte("m_EditorVersion: 6000.0.0f1\n"), false}, | ||
| 191 | }, | ||
| 192 | }, | ||
| 193 | { | ||
| 194 | name: "unreal", | ||
| 195 | // Unreal's split: `.uasset`/`.umap`/`.ubulk` are opaque binary; the | ||
| 196 | // `.uproject` and Config are text and must stay readable in git. The | ||
| 197 | // 8 MiB asset is here to exercise a transfer that spans many packets. | ||
| 198 | patterns: []string{"*.uasset", "*.umap", "*.ubulk", "*.uexp"}, | ||
| 199 | files: []engineFile{ | ||
| 200 | {"MyGame.uproject", []byte("{\"FileVersion\":3,\"EngineAssociation\":\"5.5\"}\n"), false}, | ||
| 201 | {"Config/DefaultGame.ini", []byte("[/Script/EngineSettings.GeneralProjectSettings]\nProjectName=Spike\n"), false}, | ||
| 202 | {"Content/Characters/Hero.uasset", payload(8<<20, 29), true}, | ||
| 203 | {"Content/Characters/Hero.uexp", payload(24<<10, 31), true}, | ||
| 204 | {"Content/Maps/Hub.umap", payload(56<<10, 37), true}, | ||
| 205 | {"Content/Art/T_Hero_Albedo.uasset", payload(8<<20, 41), true}, | ||
| 206 | {"Content/Art/T_Hero_Albedo.ubulk", payload(48<<10, 43), true}, | ||
| 207 | // git-lfs leaves an empty file raw: there is nothing to store, and a | ||
| 208 | // zero-byte pointer would be larger than the file. It must still | ||
| 209 | // clone as an empty file, which cloneEngine checks. | ||
| 210 | {"Content/Art/Empty.uasset", nil, false}, | ||
| 211 | }, | ||
| 212 | }, | ||
| 213 | } | ||
| 214 | |||
| 215 | for _, tc := range cases { | ||
| 216 | t.Run(tc.name, func(t *testing.T) { | ||
| 217 | t.Parallel() | ||
| 218 | f := newFixture(t) | ||
| 219 | f.publish(f.repo) | ||
| 220 | dir := gameRepo(t, f.sshURL(f.repo), tc.patterns, tc.files) | ||
| 221 | pushEngine(t, f, dir, tc.files) | ||
| 222 | cloneEngine(t, f, tc.files) | ||
| 223 | }) | ||
| 224 | } | ||
| 225 | } | ||
| 226 | |||
| 227 | // TestGameEngineTextMetadataStaysInGit checks the other half of the split: a | ||
| 228 | // text file that is larger than the raw-binary warning threshold must not be | ||
| 229 | // reported as a binary that should move to LFS. Unity scenes and Godot scenes | ||
| 230 | // can be tens of megabytes of YAML/TOML and are still reviewable text. | ||
| 231 | func TestGameEngineTextMetadataStaysInGit(t *testing.T) { | ||
| 232 | t.Parallel() | ||
| 233 | |||
| 234 | const overWarn = 6 << 20 | ||
| 235 | var scene bytes.Buffer | ||
| 236 | for scene.Len() < overWarn { | ||
| 237 | fmt.Fprintf(&scene, "[node name=\"Prop%d\" type=\"Sprite2D\"]\nposition = Vector2(%d, %d)\n", scene.Len(), scene.Len()%997, scene.Len()%89) | ||
| 238 | } | ||
| 239 | files := map[string]string{ | ||
| 240 | "scenes/huge_level.tscn": string(scene.Bytes()), | ||
| 241 | "Assets/Scenes/Huge.unity": "%YAML 1.1\n--- !u!1 &1\nGameObject:\n m_Name: Huge\n" + strings.Repeat(" m_Children: []\n", (overWarn/20)+1), | ||
| 242 | "Config/DefaultEngine.ini": strings.Repeat("[/Script/Engine.Engine]\n", (overWarn/25)+1), | ||
| 243 | } | ||
| 244 | dir := workRepo(t, files) | ||
| 245 | f := newFixture(t) | ||
| 246 | f.publish(f.repo) | ||
| 247 | out, errs, err := f.git(dir, "push", f.sshURL(f.repo), "main:refs/heads/main") | ||
| 248 | if err != nil { | ||
| 249 | t.Fatalf("push: %v\nstdout:\n%s\nstderr:\n%s", err, out, errs) | ||
| 250 | } | ||
| 251 | for name := range files { | ||
| 252 | if strings.Contains(errs, name) { | ||
| 253 | t.Errorf("large text %s was reported as a raw binary:\n%s", name, errs) | ||
| 254 | } | ||
| 255 | } | ||
| 256 | } | ||
| 257 | |||
| 258 | // TestGameEngineRawBinaryWarnsButPushes is the mistake a game team makes once: | ||
| 259 | // an engine asset committed straight into git. The push should succeed and the | ||
| 260 | // message should name the path and the pattern to track. | ||
| 261 | func TestGameEngineRawBinaryWarnsButPushes(t *testing.T) { | ||
| 262 | t.Parallel() | ||
| 263 | f := newFixture(t) | ||
| 264 | f.publish(f.repo) | ||
| 265 | |||
| 266 | dir := workRepo(t, map[string]string{"Content/Characters/Hero.uasset": string(payload(6<<20, 53))}) | ||
| 267 | out, errs, err := f.git(dir, "push", f.sshURL(f.repo), "main:refs/heads/main") | ||
| 268 | if err != nil { | ||
| 269 | t.Fatalf("push: %v\nstdout:\n%s\nstderr:\n%s", err, out, errs) | ||
| 270 | } | ||
| 271 | for _, want := range []string{"Content/Characters/Hero.uasset", `git lfs track "*.uasset"`} { | ||
| 272 | if !strings.Contains(errs, want) { | ||
| 273 | t.Errorf("warning does not mention %q:\n%s", want, errs) | ||
| 274 | } | ||
| 275 | } | ||
| 276 | } | ||
| 277 | |||
| 278 | // TestGameEngineLocks exercises the path Unreal and Unity teams rely on: a | ||
| 279 | // lock is taken from one clone, seen from another, and enforced when somebody | ||
| 280 | // else pushes a change to the asset. Paths with spaces and non-ASCII bytes are | ||
| 281 | // ordinary in game projects, so they are the ones used here. | ||
| 282 | func TestGameEngineLocks(t *testing.T) { | ||
| 283 | t.Parallel() | ||
| 284 | needGitLFS(t) | ||
| 285 | |||
| 286 | f := newFixture(t) | ||
| 287 | f.publish(f.repo) | ||
| 288 | writerKey := f.addWriter(t) | ||
| 289 | |||
| 290 | locked := "Content/Characters/My Hero.uasset" | ||
| 291 | hero := payload(64<<10, 61) | ||
| 292 | files := []engineFile{ | ||
| 293 | {locked, hero, true}, | ||
| 294 | {"Content/Characters/Sidekick.uasset", payload(32<<10, 67), true}, | ||
| 295 | {"MyGame.uproject", []byte("{\"FileVersion\":3}\n"), false}, | ||
| 296 | } | ||
| 297 | dir := gameRepo(t, f.sshURL(f.repo), []string{"*.uasset"}, files) | ||
| 298 | pushEngine(t, f, dir, files) | ||
| 299 | |||
| 300 | // The author takes the lock, the way the Unreal Git LFS integration does | ||
| 301 | // before an editor touches an asset. | ||
| 302 | if out, errs, err := f.git(dir, "lfs", "lock", locked); err != nil { | ||
| 303 | t.Fatalf("git lfs lock: %v\nstdout:\n%s\nstderr:\n%s", err, out, errs) | ||
| 304 | } | ||
| 305 | |||
| 306 | // A second maintainer sees it from a different clone. The clone is over SSH: | ||
| 307 | // git-lfs reaches the lock API through the SSH transfer agent, and a | ||
| 308 | // read-only HTTP clone cannot list or take locks. | ||
| 309 | other := cloneEngineFrom(t, f, f.sshURL(f.repo), files) | ||
| 310 | if out, errs, err := f.git(other, "lfs", "locks"); err != nil { | ||
| 311 | t.Fatalf("git lfs locks: %v\nstdout:\n%s\nstderr:\n%s", err, out, errs) | ||
| 312 | } else if !strings.Contains(out, "My Hero.uasset") || !strings.Contains(out, f.ownerID) { | ||
| 313 | t.Fatalf("lock list does not name the path and owner:\n%s", out) | ||
| 314 | } | ||
| 315 | |||
| 316 | // Changing an unlocked asset is fine. | ||
| 317 | sidekick := filepath.Join(other, "Content/Characters/Sidekick.uasset") | ||
| 318 | if err := os.WriteFile(sidekick, payload(40<<10, 71), 0o644); err != nil { | ||
| 319 | t.Fatal(err) | ||
| 320 | } | ||
| 321 | if _, errs, err := runGit(t, other, "add", "-A"); err != nil { | ||
| 322 | t.Fatalf("add sidekick: %v\n%s", err, errs) | ||
| 323 | } | ||
| 324 | if _, errs, err := runGit(t, other, "commit", "-qm", "edit sidekick"); err != nil { | ||
| 325 | t.Fatalf("commit sidekick: %v\n%s", err, errs) | ||
| 326 | } | ||
| 327 | if out, errs, err := f.gitWithKey(writerKey, other, "push", f.sshURL(f.repo), "main:refs/heads/main"); err != nil { | ||
| 328 | t.Fatalf("push of an unlocked asset: %v\nstdout:\n%s\nstderr:\n%s", err, out, errs) | ||
| 329 | } | ||
| 330 | |||
| 331 | // Changing the locked asset is refused at the server, not only by the | ||
| 332 | // client's pre-push hook. --no-verify skips that hook, so upload the object | ||
| 333 | // first; otherwise the missing-object rule would answer before the lock one. | ||
| 334 | heroPath := filepath.Join(other, filepath.FromSlash(locked)) | ||
| 335 | if err := os.WriteFile(heroPath, payload(64<<10, 73), 0o644); err != nil { | ||
| 336 | t.Fatal(err) | ||
| 337 | } | ||
| 338 | if _, errs, err := runGit(t, other, "add", "-A"); err != nil { | ||
| 339 | t.Fatalf("add hero: %v\n%s", err, errs) | ||
| 340 | } | ||
| 341 | if _, errs, err := runGit(t, other, "commit", "-qm", "edit hero"); err != nil { | ||
| 342 | t.Fatalf("commit hero: %v\n%s", err, errs) | ||
| 343 | } | ||
| 344 | if out, errs, err := f.gitWithKey(writerKey, other, "lfs", "push", "origin", "main"); err != nil { | ||
| 345 | t.Fatalf("upload the locked asset's new object: %v\nstdout:\n%s\nstderr:\n%s", err, out, errs) | ||
| 346 | } | ||
| 347 | out, errs, err := f.gitWithKey(writerKey, other, "push", "--no-verify", f.sshURL(f.repo), "main:refs/heads/main") | ||
| 348 | if err == nil { | ||
| 349 | t.Fatalf("push over somebody else's lock was accepted:\nstdout:\n%s\nstderr:\n%s", out, errs) | ||
| 350 | } | ||
| 351 | for _, want := range []string{"My Hero.uasset", "locked by " + f.ownerID} { | ||
| 352 | if !strings.Contains(errs, want) { | ||
| 353 | t.Errorf("lock rejection does not mention %q:\n%s", want, errs) | ||
| 354 | } | ||
| 355 | } | ||
| 356 | |||
| 357 | // The holder releases it, and the same push now lands. | ||
| 358 | if out, errs, err := f.git(dir, "lfs", "unlock", locked); err != nil { | ||
| 359 | t.Fatalf("git lfs unlock: %v\nstdout:\n%s\nstderr:\n%s", err, out, errs) | ||
| 360 | } | ||
| 361 | if out, errs, err := f.gitWithKey(writerKey, other, "push", f.sshURL(f.repo), "main:refs/heads/main"); err != nil { | ||
| 362 | t.Fatalf("push after unlock: %v\nstdout:\n%s\nstderr:\n%s", err, out, errs) | ||
| 363 | } | ||
| 364 | } | ||
| 365 | |||
| 366 | // TestGameEngineLockOnNonASCIIPath is the regression test for the finding this | ||
| 367 | // spike turned up: a lock on a path git C-quotes (any non-ASCII name, common in | ||
| 368 | // localized projects) was stored correctly but never matched against the push, | ||
| 369 | // because DiffStatus parsed the quoted form. The fix is -z in DiffStatusPaths. | ||
| 370 | func TestGameEngineLockOnNonASCIIPath(t *testing.T) { | ||
| 371 | t.Parallel() | ||
| 372 | needGitLFS(t) | ||
| 373 | f := newFixture(t) | ||
| 374 | f.publish(f.repo) | ||
| 375 | writerKey := f.addWriter(t) | ||
| 376 | |||
| 377 | locked := "Content/Personnages/Héros/Épée.uasset" | ||
| 378 | files := []engineFile{{locked, payload(32<<10, 79), true}} | ||
| 379 | dir := gameRepo(t, f.sshURL(f.repo), []string{"*.uasset"}, files) | ||
| 380 | pushEngine(t, f, dir, files) | ||
| 381 | if out, errs, err := f.git(dir, "lfs", "lock", locked); err != nil { | ||
| 382 | t.Fatalf("git lfs lock: %v\nstdout:\n%s\nstderr:\n%s", err, out, errs) | ||
| 383 | } | ||
| 384 | |||
| 385 | other := cloneEngineFrom(t, f, f.sshURL(f.repo), files) | ||
| 386 | p := filepath.Join(other, filepath.FromSlash(locked)) | ||
| 387 | if err := os.WriteFile(p, payload(32<<10, 83), 0o644); err != nil { | ||
| 388 | t.Fatal(err) | ||
| 389 | } | ||
| 390 | if _, errs, err := runGit(t, other, "add", "-A"); err != nil { | ||
| 391 | t.Fatalf("add: %v\n%s", err, errs) | ||
| 392 | } | ||
| 393 | if _, errs, err := runGit(t, other, "commit", "-qm", "edit locked non-ASCII asset"); err != nil { | ||
| 394 | t.Fatalf("commit: %v\n%s", err, errs) | ||
| 395 | } | ||
| 396 | if out, errs, err := f.gitWithKey(writerKey, other, "lfs", "push", "origin", "main"); err != nil { | ||
| 397 | t.Fatalf("lfs push: %v\n%s\n%s", err, out, errs) | ||
| 398 | } | ||
| 399 | out, errs, err := f.gitWithKey(writerKey, other, "push", "--no-verify", f.sshURL(f.repo), "main:refs/heads/main") | ||
| 400 | if err == nil { | ||
| 401 | t.Fatalf("push over a non-ASCII lock was accepted:\nstdout:\n%s\nstderr:\n%s", out, errs) | ||
| 402 | } | ||
| 403 | if !strings.Contains(errs, "locked by "+f.ownerID) { | ||
| 404 | t.Fatalf("rejection does not name the lock holder:\n%s", errs) | ||
| 405 | } | ||
| 406 | } | ||
| 407 | |||
| 408 | // TestGameEngineMigrateExistingHistory covers adoption: a Unity or Unreal team | ||
| 409 | // already has raw assets in history and runs `git lfs migrate import` to move | ||
| 410 | // them. The rewritten commits must upload and clone like any other LFS history. | ||
| 411 | func TestGameEngineMigrateExistingHistory(t *testing.T) { | ||
| 412 | t.Parallel() | ||
| 413 | needGitLFS(t) | ||
| 414 | |||
| 415 | f := newFixture(t) | ||
| 416 | f.publish(f.repo) | ||
| 417 | |||
| 418 | hero := payload(96<<10, 89) | ||
| 419 | dir := t.TempDir() | ||
| 420 | if _, errs, err := runGit(t, dir, "init", "-q", "-b", "main"); err != nil { | ||
| 421 | t.Fatalf("init: %v\n%s", err, errs) | ||
| 422 | } | ||
| 423 | for name, data := range map[string][]byte{ | ||
| 424 | "Content/Characters/Hero.uasset": hero, | ||
| 425 | "Content/Maps/Hub.umap": payload(48<<10, 97), | ||
| 426 | "MyGame.uproject": []byte("{\"FileVersion\":3}\n"), | ||
| 427 | } { | ||
| 428 | p := filepath.Join(dir, filepath.FromSlash(name)) | ||
| 429 | if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil { | ||
| 430 | t.Fatal(err) | ||
| 431 | } | ||
| 432 | if err := os.WriteFile(p, data, 0o644); err != nil { | ||
| 433 | t.Fatal(err) | ||
| 434 | } | ||
| 435 | } | ||
| 436 | if _, errs, err := runGit(t, dir, "add", "-A"); err != nil { | ||
| 437 | t.Fatalf("add: %v\n%s", err, errs) | ||
| 438 | } | ||
| 439 | if _, errs, err := runGit(t, dir, "commit", "-qm", "raw assets before LFS"); err != nil { | ||
| 440 | t.Fatalf("commit: %v\n%s", err, errs) | ||
| 441 | } | ||
| 442 | if _, errs, err := runGit(t, dir, "lfs", "install", "--local"); err != nil { | ||
| 443 | t.Fatalf("lfs install: %v\n%s", err, errs) | ||
| 444 | } | ||
| 445 | out, errs, err := runGit(t, dir, "lfs", "migrate", "import", "--include=*.uasset,*.umap", "--everything") | ||
| 446 | if err != nil { | ||
| 447 | t.Fatalf("git lfs migrate import: %v\nstdout:\n%s\nstderr:\n%s", err, out, errs) | ||
| 448 | } | ||
| 449 | if _, errs, err := runGit(t, dir, "remote", "add", "origin", f.sshURL(f.repo)); err != nil { | ||
| 450 | t.Fatalf("add remote: %v\n%s", err, errs) | ||
| 451 | } | ||
| 452 | if out, errs, err := f.git(dir, "push", "origin", "main:refs/heads/main"); err != nil { | ||
| 453 | t.Fatalf("push migrated history: %v\nstdout:\n%s\nstderr:\n%s", err, out, errs) | ||
| 454 | } | ||
| 455 | files := []engineFile{ | ||
| 456 | {"Content/Characters/Hero.uasset", hero, true}, | ||
| 457 | {"Content/Maps/Hub.umap", payload(48<<10, 97), true}, | ||
| 458 | {"MyGame.uproject", []byte("{\"FileVersion\":3}\n"), false}, | ||
| 459 | } | ||
| 460 | for _, file := range files { | ||
| 461 | if file.lfs && !f.srv.LFS.Has(f.repo, sha256Hex(file.data)) { | ||
| 462 | t.Errorf("%s: migrated object %s is not in the store", file.path, sha256Hex(file.data)) | ||
| 463 | } | ||
| 464 | } | ||
| 465 | cloneEngine(t, f, files) | ||
| 466 | } | ||
| 467 | |||
| 468 | // TestGameEngineLocksNeedSSHClone records the current shape: git-lfs asks an | ||
| 469 | // HTTP remote for the locking API, and this instance has no HTTP write surface, | ||
| 470 | // so `git lfs lock` from the documented HTTPS clone fails. The lock commands | ||
| 471 | // work when the remote is SSH. This test pins both halves so a change to either | ||
| 472 | // is noticed. | ||
| 473 | func TestGameEngineLocksNeedSSHClone(t *testing.T) { | ||
| 474 | t.Parallel() | ||
| 475 | needGitLFS(t) | ||
| 476 | f := newFixture(t) | ||
| 477 | f.publish(f.repo) | ||
| 478 | files := []engineFile{{"Content/Hero.uasset", payload(16<<10, 101), true}} | ||
| 479 | dir := gameRepo(t, f.sshURL(f.repo), []string{"*.uasset"}, files) | ||
| 480 | if out, errs, err := f.git(dir, "push", "origin", "main:refs/heads/main"); err != nil { | ||
| 481 | t.Fatalf("push: %v\n%s\n%s", err, out, errs) | ||
| 482 | } | ||
| 483 | // The documented reader clone: HTTPS. | ||
| 484 | httpClone := cloneEngine(t, f, files) | ||
| 485 | if _, errs, err := runGit(t, httpClone, "lfs", "lock", "Content/Hero.uasset"); err == nil { | ||
| 486 | t.Fatalf("git lfs lock over an HTTP remote unexpectedly succeeded:\n%s", errs) | ||
| 487 | } | ||
| 488 | if out, errs, err := f.git(httpClone, "lfs", "locks"); err == nil { | ||
| 489 | t.Fatalf("git lfs locks over an HTTP remote unexpectedly succeeded:\n%s\n%s", out, errs) | ||
| 490 | } | ||
| 491 | } | ||