repos
/ orchard main

orchard

mirror

Every site I host, in one repo, along with the Cloudflare Tunnel and Caddy that front them. It's all Go, Vite, and SQLite, and it runs on a desktop at home with nothing listening on an inbound port.

blogbuncaddycloudflare-tunneldockergogolanghomelabhtml-templatemonorepoself-hostedseosqlitestatic-sitetypstuptime-monitoringviteweb-analytics

1.7 KB · 51 lines · Go Raw History
 1package main
 2
 3import (
 4	"strings"
 5	"testing"
 6)
 7
 8// The rewrite is a model call and an address is the one thing in a question
 9// that cannot survive being paraphrased.
10func TestKeepURLs(t *testing.T) {
11	const q = "and this one https://example.com/post"
12	cases := []struct{ standalone, want string }{
13		{"What does the post say?", "What does the post say? https://example.com/post"},
14		{"What does https://example.com/post say?", "What does https://example.com/post say?"},
15	}
16	for _, c := range cases {
17		if got := keepURLs(q, c.standalone); got != c.want {
18			t.Errorf("got %q, want %q", got, c.want)
19		}
20	}
21	if got := keepURLs("who won the game", "who won the game"); got != "who won the game" {
22		t.Errorf("added something to a question with no address in it: %q", got)
23	}
24}
25
26// The planner picks a shape from a reading of the question, and a summary is
27// not one of those: it happens because the question carried the address of the
28// page to read, which is known before any planning.
29func TestSummaryIsNotPlannable(t *testing.T) {
30	for _, n := range shapeNames() {
31		if n == string(ShapeSummary) {
32			t.Error("the planner is offered summary, which it cannot know to pick")
33		}
34	}
35	c := contractFor(ShapeSummary)
36	if c.Shape != ShapeSummary {
37		t.Fatalf("summary falls back to %s", c.Shape)
38	}
39	// The one rule this shape exists for.
40	if !strings.Contains(c.Instruction, "nothing you know about the subject from elsewhere") {
41		t.Error("the summary contract does not hold the answer to the page it was given")
42	}
43}
44
45func TestListHosts(t *testing.T) {
46	got := listHosts([]string{"https://cloudinabottle.org/blog/launch-post", "http://go.dev/blog/go1.24"})
47	if want := "cloudinabottle.org, go.dev"; got != want {
48		t.Errorf("got %q, want %q", got, want)
49	}
50}