~bigbes/sr-ht-dolt

ref: 1b35456ae619d7fe15eb0acad7bac1d2af7702e1 sr-ht-dolt/web/realdata_test.go -rw-r--r-- 2.6 KiB
1b35456a — Eugene Blikh refine(web/beads): concise label events, drop standalone close reason, wrap long lines 30 days ago
                                                                                
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
package web

import (
	"context"
	"net/url"
	"os"
	"testing"

	"sourcecraft.dev/bigbes/sr-ht-dolt/browse"
)

// TestRealBeadsStore is a manual smoke test against a real beads database. It
// is skipped unless BEADS_REAL_DB points at a *bare* NBS store dir (the shape
// production serves — an embedded working store has a chunk journal and won't
// open; push it to a file remote first: `dolt push file:///path/bare main`).
// Optionally set BEADS_REAL_ISSUE=<id> to dump one issue's epic rollup and
// merged history. Kept because browse reaches into version-fragile dolt
// internals, so a module bump should be re-verified against real data here.
//
//	dolt push file:///tmp/bare main            # from the working store
//	BEADS_REAL_DB=/tmp/bare BEADS_REAL_ISSUE=<epic-id> \
//	  go test -tags gms_pure_go -run TestRealBeadsStore -v ./web/
func TestRealBeadsStore(t *testing.T) {
	path := os.Getenv("BEADS_REAL_DB")
	if path == "" {
		t.Skip("set BEADS_REAL_DB to a real beads noms store dir")
	}
	ctx := context.Background()
	dbh, err := browse.Open(ctx, path)
	if err != nil {
		t.Fatalf("open: %v", err)
	}
	defer dbh.Close()

	branches, err := dbh.Branches(ctx)
	if err != nil {
		t.Fatalf("branches: %v", err)
	}
	ref := browse.DefaultBranch(branches)
	t.Logf("branches=%v default=%q", branches, ref)

	tables, err := dbh.Tables(ctx, ref)
	if err != nil {
		t.Fatalf("tables: %v", err)
	}
	var names []string
	for _, tb := range tables {
		names = append(names, tb.Name)
	}
	t.Logf("tables=%v", names)

	issues, err := dbh.Rows(ctx, ref, "issues", 0, 5)
	if err != nil {
		t.Fatalf("rows: %v", err)
	}
	t.Logf("issues cols=%v total=%d", issues.Columns, issues.Total)

	// Drive the real view. With BEADS_REAL_ISSUE set to an epic id, dump the
	// subtask rollup and merged history so a human can eyeball the output.
	want := os.Getenv("BEADS_REAL_ISSUE")
	if want == "" {
		return
	}
	v := &beadsView{}
	raw, err := v.Build(ctx, dbh, nil, ref, url.Values{"issue": {want}})
	if err != nil {
		t.Fatalf("build: %v", err)
	}
	data := raw.(*BeadsData)
	if data.Issue == nil {
		t.Fatalf("issue %q not found", want)
	}
	t.Logf("mode=%q issue=%q type=%q", data.Mode, data.Issue.Title, data.Issue.IssueType)
	t.Logf("desc=%.80q closeReason=%.80q", data.Issue.Description, data.Issue.CloseReason)
	t.Logf("subtasks %d/%d done (%d%%):", data.SubtaskDone, data.SubtaskTotal, data.SubtaskPct())
	for _, s := range data.Subtasks {
		t.Logf("  - %s [%s/%s] %s @%s", s.ID, s.Category, s.Status, s.Title, s.Assignee)
	}
	t.Logf("history (%d entries):", len(data.History))
	for _, a := range data.History {
		t.Logf("  %s | %s: %s %s | %s", a.CreatedAt, a.Kind, a.Actor, a.Summary, a.Text)
	}
}