diff options
| author | Gabriel Schneider <[email protected]> | 2026-08-02 23:43:08 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-03 09:54:39 -0300 |
| commit | 5ec72f8723d795d0b02d7e9ebb9f555f0c7e6a2e (patch) | |
| tree | f12f4b700fff4ff6f7e818d2a542672ba0b8d76e /vrsite/permalink_test.go | |
| parent | a9263daee9413c5eff3c1f1bebcd224442fd8685 (diff) | |
| download | notevi-5ec72f8723d795d0b02d7e9ebb9f555f0c7e6a2e.tar.gz notevi-5ec72f8723d795d0b02d7e9ebb9f555f0c7e6a2e.zip | |
rebrand to notevi: one CLI over the jj sidecar
vr and vrsite become a single binary. vrsite/ folds into a web package in
one module (0x4200.cafe/notevi); "notevi web" serves and exports exactly
what vrsite did, and "notevi read/grep/note/query" is unchanged.
The sidecar is renamed with it: notevi_log, notevi-log.jsonl, and the
description "private: notevi log". The pre-rebrand names are still
recognized, so an old repository opens and reads; it is renamed in place
on the first write, or up front with "notevi migrate DIR...".
That rename cannot be a single mv inside jj run. jj only auto-tracks a
*new* file in the run working copy below a size limit it does not take
from the command line, so writing a whole log under a name the change has
never held is silently dropped while jj reports success. ensureLogFile
creates the file empty first and lets every later byte be a modification
of a tracked file, which snapshots at any size; that also fixes the same
latent bug when importing a large legacy vr-log.jsonl.
Adds a bem-te-vi mark (favicon and nav brand) and a README.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Diffstat (limited to 'vrsite/permalink_test.go')
| -rw-r--r-- | vrsite/permalink_test.go | 210 |
1 files changed, 0 insertions, 210 deletions
diff --git a/vrsite/permalink_test.go b/vrsite/permalink_test.go deleted file mode 100644 index c3d572f..0000000 --- a/vrsite/permalink_test.go +++ /dev/null @@ -1,210 +0,0 @@ -package main - -import ( - "os" - "path/filepath" - "strconv" - "strings" - "testing" -) - -func TestNoteByIDSpansTheWholeLog(t *testing.T) { - entries := parseLog([]byte(logLines(noteA, noteB))) - full := buildModel("test", entries, "") - if n := full.NoteByID(2); n == nil || n.Text != "entry point does too much" { - t.Fatalf("NoteByID(2) = %+v", n) - } - if n := full.NoteByID(99); n != nil { - t.Errorf("NoteByID(99) = %+v, want nil", n) - } - // ids are counted over the whole log, so a link keeps meaning the same - // note when the site is scoped to one change — that is the whole point of - // a permalink - scoped := buildModel("test", entries, "aaa") - for _, id := range []int{1, 2} { - a, b := full.NoteByID(id), scoped.NoteByID(id) - if a == nil || b == nil || a.Text != b.Text { - t.Errorf("note %d differs between scopes: %+v vs %+v", id, a, b) - } - } -} - -func TestPermaHref(t *testing.T) { - n := &Note{ID: 7} - if got := (&page{Live: true, Root: "/"}).PermaHref(n); got != "/note/7" { - t.Errorf("live permalink = %q", got) - } - // a permalink names nothing but the note: no rev, no scope, so it means - // the same thing wherever it is pasted - wide := &page{Live: true, Root: "/", Rev: "xyz", Scope: "all"} - if got := wide.PermaHref(n); got != "/note/7" { - t.Errorf("permalink from a scoped view = %q", got) - } - static := &page{Root: "", Site: &Site{Notes: []*Note{n}}} - if got := static.PermaHref(n); got != "note/7.html" { - t.Errorf("static permalink = %q", got) - } - // on the note's own page there is nowhere to go - if got := (&page{Live: true, Root: "/", Kind: "note"}).PermaHref(n); got != "" { - t.Errorf("self permalink = %q, want none", got) - } - // an export holding another change has no page to point at - empty := &page{Root: "", Site: &Site{}} - if got := empty.PermaHref(n); got != "" { - t.Errorf("permalink into an export without the note = %q, want none", got) - } -} - -func TestExcerptShowsTheNotedLinesInContext(t *testing.T) { - hl := newHighlighter(loadTheme("", "", "dark"), loadTheme("", "", "light")) - var b strings.Builder - for i := 1; i <= 60; i++ { - b.WriteString("line\n") - } - src := []byte(b.String()) - - body, from, to := excerptFor("x.txt", src, nil, hl, &Note{ID: 3, Start: 20, End: 24}) - if from != 20-excerptContext || to != 24+excerptContext { - t.Errorf("range = %d–%d, want %d–%d", from, to, 20-excerptContext, 24+excerptContext) - } - got := string(body) - // real line numbers, not the excerpt's own - if !strings.Contains(got, `id="L16"`) || !strings.Contains(got, `id="L28"`) { - t.Errorf("excerpt is not numbered from the file:\n%s", got) - } - if strings.Contains(got, `id="L15"`) || strings.Contains(got, `id="L29"`) { - t.Errorf("excerpt reaches past its context:\n%s", got) - } - // only the noted lines are marked, and they carry the note's anchor - for _, want := range []string{`<li id="L20"`, `class="noted"`, `data-note="note-3"`} { - if !strings.Contains(got, want) { - t.Errorf("missing %q in:\n%s", want, got) - } - } - if n := strings.Count(got, "noted"); n != 5 { - t.Errorf("marked %d lines, want 5 (20–24)", n) - } - - // context is clamped to the file, never past either end - if _, from, to = excerptFor("x.txt", src, nil, hl, &Note{Start: 2, End: 2}); from != 1 { - t.Errorf("excerpt from = %d, want 1", from) - } - if _, from, to = excerptFor("x.txt", src, nil, hl, &Note{Start: 59, End: 59}); to != 60 { - t.Errorf("excerpt to = %d, want 60", to) - } - // a note pinned to no line has nothing to excerpt - if body, _, _ := excerptFor("x.txt", src, nil, hl, &Note{}); body != "" { - t.Errorf("whole-file note produced an excerpt: %s", body) - } -} - -// content-visibility: auto brings style containment with it, and a contained -// element's own counter-reset comes out as 0 whatever value it names. Every -// chunk after the first would then count from 1, so the number a line shows -// has to be set on the line itself. -func TestChunksAreNumberedFromTheirFirstLine(t *testing.T) { - hl := newHighlighter(loadTheme("", "", "dark"), loadTheme("", "", "light")) - var b strings.Builder - for i := 1; i <= chunkLines*2+10; i++ { - b.WriteString("x\n") - } - f := &File{Path: "big.txt", NoteAt: map[int]int{}} - f.render([]byte(b.String()), hl) - got := string(f.Body) - - if strings.Contains(got, "counter-reset") { - t.Error("a chunk still resets the counter on the <ol>, which containment ignores") - } - for _, ln := range []int{1, chunkLines + 1, chunkLines*2 + 1} { - want := `<li id="L` + strconv.Itoa(ln) + `" style="counter-set: ln ` + strconv.Itoa(ln) + `"` - if !strings.Contains(got, want) { - t.Errorf("chunk starting at line %d does not set its number (want %q)", ln, want) - } - } - if n := strings.Count(got, "counter-set"); n != 3 { - t.Errorf("%d lines set the counter, want 3 — one per chunk", n) - } -} - -// The permalink is the link handed to someone else, so it has to open on its -// own: the note, and the code it is about, at the change it was written at. -func TestNotePermalinkOverHTTP(t *testing.T) { - sv, _, _ := testServer(t) - h := sv.handler() - - // testServer's log holds one note, on hello.txt:2 - w := get(t, h, "/note/1", false) - if w.Code != 200 { - t.Fatalf("GET /note/1 = %d: %s", w.Code, w.Body) - } - body := w.Body.String() - for _, want := range []string{ - "second line matters", // the note - `data-kind="note"`, // and its own page, not a list - `<li id="L2"`, // the line it is about… - "two", // …with the code on it - `<li id="L1"`, // in context - "open the whole file", - } { - if !strings.Contains(body, want) { - t.Errorf("permalink page is missing %q", want) - } - } - // the card does not link to the page it is already on - if strings.Contains(body, `class="perma" href`) { - t.Error("the note links to its own page") - } - - // and the notes list offers the link in the first place - if list := get(t, h, "/notes", false).Body.String(); !strings.Contains(list, `class="perma" href="/note/1"`) { - t.Error("the notes page offers no permalink") - } - - for _, path := range []string{"/note/999", "/note/abc", "/note/0"} { - if code := get(t, h, path, false).Code; code != 404 { - t.Errorf("GET %s = %d, want 404", path, code) - } - } -} - -func TestStaticExportWritesNotePages(t *testing.T) { - sv, logPath, change := testServer(t) - extra := logLines( - `{"time":"2026-07-20T10:02:00Z","op":"note","session":"s2","agent":"claude","change":"`+change+`","note_id":1,"reply_to":1,"text":"static child"}`, - `{"time":"2026-07-20T10:03:00Z","op":"note","session":"s3","agent":"codex","change":"`+change+`","note_id":1,"text":"[static mention](note/1)"}`, - ) - if err := os.WriteFile(logPath, append(mustRead(t, logPath), extra...), 0o644); err != nil { - t.Fatal(err) - } - site, _, _ := sv.snap() - out := t.TempDir() - writeSite(site, out, sv.repo, testThemes(sv.theme, sv.light)) - - b, err := os.ReadFile(filepath.Join(out, "note", "1.html")) - if err != nil { - t.Fatalf("no page for note 1: %v", err) - } - page := string(b) - for _, want := range []string{"second line matters", `<li id="L2"`, "two", - `href="../code/hello.txt.html?note=1#L2"`, "static child", "static mention", - `class="threadnode via-reply"`, `class="threadnode via-mention"`, - `href="../note/1.html"`} { - if !strings.Contains(page, want) { - t.Errorf("exported note page is missing %q", want) - } - } - // the links out have to be relative, since an export is opened off a disk - if strings.Contains(page, `href="/`) { - t.Errorf("exported note page carries an absolute link:\n%s", page) - } - if strings.Contains(page, `class="replybox"`) { - t.Error("the static thread offers a reply form without a server") - } - notes, err := os.ReadFile(filepath.Join(out, "notes.html")) - if err != nil { - t.Fatal(err) - } - if !strings.Contains(string(notes), `class="perma" href="note/1.html"`) { - t.Error("the exported notes page offers no permalink") - } -} |
