@ 261101.7

261026.35 · a60a48373ad0c31834aa0dc699bd09241f0c3613

Bugs are filed in the checkout's csi/bugs

make build embeds the checkout's path, and a binary built so files its bugs in csi/bugs there, beside the project they are about. The package, built without the path, and a checkout without csi keep the state directory.

reading declarations

Makefile

@@ -6,8 +6,10 @@ NAME := $(shell cat WORKING_NAME)  all: build +# build names this checkout in the binary, so its bug button files into+# csi/bugs here; the package is built without it. build:-	CGO_ENABLED=0 go build -o build/$(NAME) .+	CGO_ENABLED=0 go build -ldflags='-X main.sourceDir=$(CURDIR)' -o build/$(NAME) .  # syntax builds the tree-sitter helper beside the binary, which finds it # there. It is a module of its own, in syntax/, since tree-sitter needs cgo

README.md

@@ -80,7 +80,7 @@ The package also ships a system template, `www@.service`, which serves a user's  ## Debugging -A faint `www bug` button at the foot of every page files a numbered bug in www itself, not in the tree you are reading. The report holds a snapshot of what you saw, the server's state and an optional comment, in `~/.local/state/www/bugs/` and the log. `--debug` adds a build stamp above each page. See [doc/debugging.md](doc/debugging.md).+A faint `www bug` button at the foot of every page files a numbered bug in www itself, not in the tree you are reading. The report holds a snapshot of what you saw, the server's state and an optional comment, in `csi/bugs/` of the checkout a `make build` binary came from, else in `~/.local/state/www/bugs/`, and in the log. `--debug` adds a build stamp above each page. See [doc/debugging.md](doc/debugging.md).  ## Online repos 

bug.go

@@ -120,9 +120,19 @@ func clip(s string) string { 	return s } -// bugDir is where bug reports go, $XDG_STATE_HOME/www/bugs, made on first-// use.+// sourceDir is the checkout the binary was built from, set by make build.+var sourceDir string++// bugDir is where bug reports go, made on first use: csi/bugs in the+// checkout the binary was built from, when that checkout has csi, so the+// bugs sit with the project they are about; else $XDG_STATE_HOME/www/bugs. func bugDir() (string, error) {+	if sourceDir != "" {+		if info, err := os.Stat(filepath.Join(sourceDir, "csi")); err == nil && info.IsDir() {+			dir := filepath.Join(sourceDir, "csi", "bugs")+			return dir, os.MkdirAll(dir, 0o700)+		}+	} 	base, err := stateDir() 	if err != nil { 		return "", err

bug_test.go

@@ -110,3 +110,29 @@ func TestNoBug(t *testing.T) { 		t.Errorf("report taken on a share") 	} }++// A binary built from a checkout with csi files its bugs in csi/bugs+// there; without csi, or built elsewhere, in the state directory.+func TestBugDir(t *testing.T) {+	state := t.TempDir()+	t.Setenv("XDG_STATE_HOME", state)+	defer func(d string) { sourceDir = d }(sourceDir)+	src := t.TempDir()+	for _, c := range []struct {+		source string+		csi    bool+		want   string+	}{+		{"", false, filepath.Join(state, progName, "bugs")},+		{src, false, filepath.Join(state, progName, "bugs")},+		{src, true, filepath.Join(src, "csi", "bugs")},+	} {+		if c.csi {+			os.Mkdir(filepath.Join(src, "csi"), 0o700)+		}+		sourceDir = c.source+		if got, err := bugDir(); err != nil || got != c.want {+			t.Errorf("source %q, csi %v: bugDir() = %q, %v, want %q", c.source, c.csi, got, err, c.want)+		}+	}+}

doc/debugging.md

@@ -4,7 +4,7 @@  A small, faint `www bug` button sits at the foot of every page. It reports a bug in www and the server, not in the tree you are reading. A click files a numbered bug with the page attached, and the button says which, eg `bug 7 filed`. Text selected on the page goes in as the note. A field then opens beside the button for a comment: Enter adds it, Escape or clicking away leaves the bug without one. -Each report lands in `~/.local/state/www/bugs/`, or below `$XDG_STATE_HOME` when set:+Each report lands in `csi/bugs/` of the checkout the binary was built from, when `make build` built it there and that checkout has csi, so the bugs sit with www's own project. Otherwise, as for the package, it lands in `~/.local/state/www/bugs/`, or below `$XDG_STATE_HOME` when set:  - `7.kv`: the report as keyval: the time, the page's URL, the note, the window's size and scroll as `view`, the browser as `ua`, the build, then the server: its `pid`, its binary as `exe`, `stale yes` if a rebuild has replaced that binary, its `addr`, when it `started`, its `command` line and each tree it serves as `tree.0`, `tree.1` and on, then each comment as `comment.0`, `comment.1` and on - `7.html`: the page as it stood at the click, script changes included, with its stylesheet and no script, so it opens as you saw it@@ -13,7 +13,7 @@ Each report lands in `~/.local/state/www/bugs/`, or below `$XDG_STATE_HOME` when Each report and comment is also one line in the log. Find them with `journalctl --user -t www -g '^bug '`:  ```-bug 7: http://127.31.1.1/x/nowhere.md note="the coin is cut off" view=1280x800+0 ua="Mozilla/5.0 ..." build=1aa282c snapshot=/home/t/.local/state/www/bugs/7.html+bug 7: http://127.31.1.1/x/nowhere.md note="the coin is cut off" view=1280x800+0 ua="Mozilla/5.0 ..." build=1aa282c snapshot=/home/t/scratch/github.com/unixfile/www/csi/bugs/7.html bug 7 comment: "after a restart" ```