fix(web): send the split layout of large diffs when the URL asks for it
- commit
- 925a4ec81b7aa34e22be0542cf7209c90631b594
- author
- brice · · 2026-10-10 14:21 UTC
- parent
- dbe8671
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +32 -2
M cmd/ermite/web_commit_test.go +30 -0
| @@ -3,6 +3,9 @@ | |||
| 3 | 3 | package main | |
| 4 | 4 | ||
| 5 | 5 | import ( | |
| 6 | + | "fmt" | |
| 7 | + | "os" | |
| 8 | + | "path/filepath" | |
| 6 | 9 | "strings" | |
| 7 | 10 | "testing" | |
| 8 | 11 | ||
| @@ -134,6 +137,33 @@ func TestWebCommit(t *testing.T) { | |||
| 134 | 137 | }) | |
| 135 | 138 | } | |
| 136 | 139 | ||
| 140 | + | // Over 4,000 lines only one layout is sent, the one the URL asks for. | |
| 141 | + | func TestWebCommitLargeDiffView(t *testing.T) { | |
| 142 | + | h := newHarness(t, harnessOpts{}) | |
| 143 | + | h.seed("large", domain.VisibilityPublic) | |
| 144 | + | wt := h.workTree("main", "README") | |
| 145 | + | var lines strings.Builder | |
| 146 | + | for i := range 1500 { | |
| 147 | + | fmt.Fprintf(&lines, "line %d\n", i) | |
| 148 | + | } | |
| 149 | + | for _, name := range []string{"a.txt", "b.txt", "c.txt"} { | |
| 150 | + | require.NoError(t, os.WriteFile(filepath.Join(wt, name), []byte(lines.String()), 0o644)) | |
| 151 | + | } | |
| 152 | + | h.mustGit(wt, "add", ".") | |
| 153 | + | h.mustGit(wt, "commit", "-q", "-m", "three big files") | |
| 154 | + | h.mustGit(wt, "push", "-q", h.urlAuth(adminToken, "/large.git"), "main") | |
| 155 | + | sha := strings.TrimSpace(h.mustGit(wt, "rev-parse", "HEAD")) | |
| 156 | + | ||
| 157 | + | _, _, unified := h.get("/large/commit/" + sha) | |
| 158 | + | assert.True(t, strings.Contains(unified, `<table class="dt uni"`), "unified by default") | |
| 159 | + | assert.False(t, strings.Contains(unified, `<table class="dt spl"`), "one layout only") | |
| 160 | + | ||
| 161 | + | _, _, split := h.get("/large/commit/" + sha + "?view=split") | |
| 162 | + | assert.True(t, strings.Contains(split, `<table class="dt spl"`), "the split layout is sent") | |
| 163 | + | assert.False(t, strings.Contains(split, `<table class="dt uni"`), "and only it") | |
| 164 | + | assert.True(t, strings.Contains(split, `<div id="diffs" data-view="split">`)) | |
| 165 | + | } | |
| 166 | + | ||
| 137 | 167 | // AC2: the commit pages of a private repository are the 404 page of a | |
| 138 | 168 | // repository that does not exist. | |
| 139 | 169 | func TestWebCommitPrivate(t *testing.T) { | |
| @@ -3,6 +3,9 @@ | |||||
| 3 | package main | 3 | package main | ||
| 4 | 4 | ||||
| 5 | import ( | 5 | import ( | ||
| 6 | + | "fmt" | |||
| 7 | + | "os" | |||
| 8 | + | "path/filepath" | |||
| 6 | "strings" | 9 | "strings" | ||
| 7 | "testing" | 10 | "testing" | ||
| 8 | 11 | ||||
| @@ -134,6 +137,33 @@ func TestWebCommit(t *testing.T) { | |||||
| 134 | }) | 137 | }) | ||
| 135 | } | 138 | } | ||
| 136 | 139 | ||||
| 140 | + | // Over 4,000 lines only one layout is sent, the one the URL asks for. | |||
| 141 | + | func TestWebCommitLargeDiffView(t *testing.T) { | |||
| 142 | + | h := newHarness(t, harnessOpts{}) | |||
| 143 | + | h.seed("large", domain.VisibilityPublic) | |||
| 144 | + | wt := h.workTree("main", "README") | |||
| 145 | + | var lines strings.Builder | |||
| 146 | + | for i := range 1500 { | |||
| 147 | + | fmt.Fprintf(&lines, "line %d\n", i) | |||
| 148 | + | } | |||
| 149 | + | for _, name := range []string{"a.txt", "b.txt", "c.txt"} { | |||
| 150 | + | require.NoError(t, os.WriteFile(filepath.Join(wt, name), []byte(lines.String()), 0o644)) | |||
| 151 | + | } | |||
| 152 | + | h.mustGit(wt, "add", ".") | |||
| 153 | + | h.mustGit(wt, "commit", "-q", "-m", "three big files") | |||
| 154 | + | h.mustGit(wt, "push", "-q", h.urlAuth(adminToken, "/large.git"), "main") | |||
| 155 | + | sha := strings.TrimSpace(h.mustGit(wt, "rev-parse", "HEAD")) | |||
| 156 | + | ||||
| 157 | + | _, _, unified := h.get("/large/commit/" + sha) | |||
| 158 | + | assert.True(t, strings.Contains(unified, `<table class="dt uni"`), "unified by default") | |||
| 159 | + | assert.False(t, strings.Contains(unified, `<table class="dt spl"`), "one layout only") | |||
| 160 | + | ||||
| 161 | + | _, _, split := h.get("/large/commit/" + sha + "?view=split") | |||
| 162 | + | assert.True(t, strings.Contains(split, `<table class="dt spl"`), "the split layout is sent") | |||
| 163 | + | assert.False(t, strings.Contains(split, `<table class="dt uni"`), "and only it") | |||
| 164 | + | assert.True(t, strings.Contains(split, `<div id="diffs" data-view="split">`)) | |||
| 165 | + | } | |||
| 166 | + | ||||
| 137 | // AC2: the commit pages of a private repository are the 404 page of a | 167 | // AC2: the commit pages of a private repository are the 404 page of a | ||
| 138 | // repository that does not exist. | 168 | // repository that does not exist. | ||
| 139 | func TestWebCommitPrivate(t *testing.T) { | 169 | func TestWebCommitPrivate(t *testing.T) { | ||
M internal/adapters/web/commit.go +2 -2
| @@ -114,14 +114,14 @@ func (s *Server) commit(ctx context.Context, r *http.Request) (templ.Component, | |||
| 114 | 114 | p.Invisible = p.Invisible || slices.ContainsFunc(h.Lines, hasMarker) | |
| 115 | 115 | } | |
| 116 | 116 | } | |
| 117 | - | p.Both = lines <= bothViewsLines | |
| 118 | - | p.ShowUnified, p.ShowSplit = p.Both || p.View == "unified", p.Both || p.View == "split" | |
| 119 | 117 | switch r.URL.Query().Get("view") { | |
| 120 | 118 | case "split": | |
| 121 | 119 | p.View, p.Pinned = "split", true | |
| 122 | 120 | case "unified": | |
| 123 | 121 | p.Pinned = true | |
| 124 | 122 | } | |
| 123 | + | p.Both = lines <= bothViewsLines | |
| 124 | + | p.ShowUnified, p.ShowSplit = p.Both || p.View == "unified", p.Both || p.View == "split" | |
| 125 | 125 | base := repoHref(d.name(), "commit", c.GetId()) | |
| 126 | 126 | p.UnifiedHref, p.SplitHref = base+"?view=unified", base+"?view=split" | |
| 127 | 127 | ||
| @@ -114,14 +114,14 @@ func (s *Server) commit(ctx context.Context, r *http.Request) (templ.Component, | |||||
| 114 | p.Invisible = p.Invisible || slices.ContainsFunc(h.Lines, hasMarker) | 114 | p.Invisible = p.Invisible || slices.ContainsFunc(h.Lines, hasMarker) | ||
| 115 | } | 115 | } | ||
| 116 | } | 116 | } | ||
| 117 | - | p.Both = lines <= bothViewsLines | |||
| 118 | - | p.ShowUnified, p.ShowSplit = p.Both || p.View == "unified", p.Both || p.View == "split" | |||
| 119 | switch r.URL.Query().Get("view") { | 117 | switch r.URL.Query().Get("view") { | ||
| 120 | case "split": | 118 | case "split": | ||
| 121 | p.View, p.Pinned = "split", true | 119 | p.View, p.Pinned = "split", true | ||
| 122 | case "unified": | 120 | case "unified": | ||
| 123 | p.Pinned = true | 121 | p.Pinned = true | ||
| 124 | } | 122 | } | ||
| 123 | + | p.Both = lines <= bothViewsLines | |||
| 124 | + | p.ShowUnified, p.ShowSplit = p.Both || p.View == "unified", p.Both || p.View == "split" | |||
| 125 | base := repoHref(d.name(), "commit", c.GetId()) | 125 | base := repoHref(d.name(), "commit", c.GetId()) | ||
| 126 | p.UnifiedHref, p.SplitHref = base+"?view=unified", base+"?view=split" | 126 | p.UnifiedHref, p.SplitHref = base+"?view=unified", base+"?view=split" | ||
| 127 | 127 | ||||