adventure: keep the facts, not just the sentence we made of them
gogobee already sends boss/opponent/zone/outcome/level on every dispatch. renderAdventure melted them into prose and only the prose was persisted, so "how many bosses has she downed" was answerable only by parsing English back out of a headline. adventure_events keeps the fact as fact. It's the one adventure table that's a log rather than a snapshot: the roster answers where Josie is now and is replaced every tick; this answers what she has ever done, which no snapshot can. INSERT OR IGNORE on the guid because gogobee retries a fact whose ack it lost, and this is the only adventure store where a duplicate is permanently wrong — the roster forgives one by replacing itself, a double-counted kill is in the tally forever. On top of it the who page grows two public sections, counted from dispatches that were already public: the record (tallies, per-boss and per-zone, realm firsts, milestones) and the trail (the last 40 facts, each linking to the dispatch that told it). One read feeds both — the pool is MaxOpenConns(1), so six COUNT queries would serialize for an answer that fits in memory. Only the trail is capped. A limit on the read would truncate a *tally* rather than a list, and a veteran's kill count frozen at 40 reads as a fact instead of a missing page. Only the subject of a fact earns a trophy: a duel you lost still names you, and it belongs on your trail but not in your record. Trophies count forward only. Every adventurer's past is prose in the feed and can't be counted back out, so they show no record until they next do something — a clean absence rather than a wall of zeroes. No treasures: there's no loot fact on the wire, and inventory is current-state with no history, so counting the vault would score a bought sword as a trophy. Needs a fact type upstream.
This commit is contained in:
@@ -81,6 +81,33 @@ func seedWho(t *testing.T, owner string) *Server {
|
||||
return s
|
||||
}
|
||||
|
||||
// seedHistory pushes facts about Josie through the real ingest path, so the
|
||||
// history panels are driven by rows that arrived the way gogobee sends them
|
||||
// rather than by a hand-built struct that could drift from the contract.
|
||||
func seedHistory(t *testing.T, s *Server) {
|
||||
t.Helper()
|
||||
facts := []AdvFact{
|
||||
{GUID: "boss_first:a:1", EventType: "boss_first", Tier: "priority", Actors: []string{"Josie"},
|
||||
Subject: "Josie", Boss: "The Rotmother", Zone: "holymachina", Region: "the Reach", OccurredAt: 100},
|
||||
{GUID: "boss_kill:b:2", EventType: "boss_kill", Tier: "bulletin", Actors: []string{"Josie"},
|
||||
Subject: "Josie", Boss: "The Rotmother", Zone: "holymachina", OccurredAt: 200},
|
||||
{GUID: "death:c:3", EventType: "death", Tier: "priority", Actors: []string{"Josie"},
|
||||
Subject: "Josie", Zone: "holymachina", Level: 14, OccurredAt: 300},
|
||||
{GUID: "milestone:d:4", EventType: "milestone", Tier: "bulletin", Actors: []string{"Josie"},
|
||||
Subject: "Josie", Milestone: "level 14", OccurredAt: 400},
|
||||
}
|
||||
for _, f := range facts {
|
||||
body, _ := json.Marshal(f)
|
||||
req := httptest.NewRequest("POST", "/api/ingest/adventure", bytes.NewReader(body))
|
||||
req.Header.Set("Authorization", "Bearer tok")
|
||||
w := httptest.NewRecorder()
|
||||
s.handleAdventureIngest(w, req)
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("seed fact %s = %d: %s", f.GUID, w.Code, w.Body.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getWho(t *testing.T, s *Server, token, asUser string) *httptest.ResponseRecorder {
|
||||
t.Helper()
|
||||
var req = httptest.NewRequest("GET", "/adventure/who/"+token, nil)
|
||||
@@ -197,3 +224,45 @@ func TestDetailIngestReplacesAndAuth(t *testing.T) {
|
||||
t.Error("public page vanished when only the private detail was dropped")
|
||||
}
|
||||
}
|
||||
|
||||
// TestWhoHistoryPanels: the record and the trail render for an adventurer with
|
||||
// facts on file. Driven through the real template and the real ingest path, so a
|
||||
// field slip in either 500s here rather than in prod.
|
||||
func TestWhoHistoryPanels(t *testing.T) {
|
||||
s := seedWho(t, "josie")
|
||||
seedHistory(t, s)
|
||||
|
||||
w := getWho(t, s, "tok-josie", "")
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("who = %d: %s", w.Code, w.Body.String())
|
||||
}
|
||||
body := w.Body.String()
|
||||
for _, want := range []string{
|
||||
"The record",
|
||||
"The Rotmother", // the boss tally
|
||||
"bosses down",
|
||||
"realm-first", // the boss_first got flagged
|
||||
"level 14", // the milestone chip
|
||||
"The trail",
|
||||
"/adventure/boss_first:a:1", // the trail links back to the dispatch
|
||||
} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("history render missing %q", want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestWhoHistoryAbsent: an adventurer with no facts on file gets no empty
|
||||
// scaffolding. Every veteran looks like this the day this ships — their past is
|
||||
// prose in the feed and was never counted — so the blank state has to be a clean
|
||||
// absence, not a wall of zeroes.
|
||||
func TestWhoHistoryAbsent(t *testing.T) {
|
||||
s := seedWho(t, "josie")
|
||||
|
||||
body := getWho(t, s, "tok-josie", "").Body.String()
|
||||
for _, leak := range []string{"The record", "The trail", "bosses down"} {
|
||||
if strings.Contains(body, leak) {
|
||||
t.Errorf("no-history page should not render %q", leak)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user