Files
gogobee/internal/plugin/dnd_expedition_cycle_test.go
prosolis 5ef10e35dc Phase 5b: player power floor + Phase-3 winners shipped to live
Closes the 'fairly breezy with some death' target the user picked
for Phase 5. Five-piece ship; Phase 1 matrix lands T1 88%, T2 74%,
T4 72%, T5 ~57% in or above band. T3 remains the design hump at
~45% (manor 39, underforge 47) — Wraith promotion to elite was
already done in Phase 4-B, the remaining standard-pool deaths are
the irreducible part of T3.

Pieces:
  1. computeMaxHP × 1.5 (phase5BHPMult in dnd.go). Uniform across
     class/level so the class-balance harness's in-tier parity
     assertion stays green. Bootstrap (bootstrap_phase5b_hp.go)
     refreshes hp_max for existing characters at startup;
     idempotent via db.JobCompleted. hp_current is bumped by the
     same delta so a full-HP character stays at full.
  2. applyPhase5BPlayerFloor (dnd_combat.go): +3 AC, +3 AttackBonus,
     +3 weapon.MagicBonus (damage). Applied at the END of
     applyDnDEquipmentLayer (after computeArmorAC's AC override)
     and inside buildHarnessPlayer so live and harness measurement
     match.
  3. Elite bracket 19 → 23 (resolveCombatInterrupt). Case order
     puts Elite (≥23) before Patrol (≥22) so a 23+ total prefers
     the single dangerous fight. Elite is now effectively a
     high-threat event reachable only via the +1-per-20-threat-
     above-40 mod — Phase 4-B's elite-pool monsters still appear,
     just less often.
  4. dailyThreatDrift base 3 → 1. Slows the threat clock so
     players have the days they need before threat tips zones
     into the new 23+ elite band.
  5. applyDailyBurn default → 50% (phase5BDailyBurnRatePct). Also
     applied in the temporal-override branch in
     dnd_expedition_cycle.go so tidal / unraveling days scale by
     the same 0.5× — otherwise those days would be
     disproportionately harsh against the new baseline.

The harness's expedition_balance.go reads phase5BDailyBurnRatePct
as the default-burn fallback when the override knob is zero, so
Phase 1 matrix measurements now reflect what live players
experience.

Test debt: 13 pinned-numbers unit tests across combat_stats_test,
dnd_test, dnd_xp_test, dnd_equipment_profiles_test,
dnd_expedition_supplies_test, dnd_expedition_cycle_test,
dnd_expedition_extract_test, dnd_expedition_region_cmd_test,
dnd_expedition_combat_test, dnd_expedition_threat_test,
dnd_expedition_temporal_test, expedition_balance_test were
pinning pre-Phase-5-B baselines; updated with comments noting
the cause. Class-balance suite stayed green (uniform buff
preserves spread).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 12:11:27 -07:00

229 lines
6.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package plugin
import (
"strings"
"testing"
"time"
"gogobee/internal/db"
"maunium.net/go/mautrix/id"
)
// Phase 12 E1d — day cycle tests. We can't easily fast-forward UTC time,
// so the tests drive deliverBriefing / deliverRecap directly with a
// synthetic "now" and verify state transitions. Ticker scheduling is a
// thin wrapper over those.
func TestPickMorningBriefing_DayBands(t *testing.T) {
cases := []struct {
day int
want []string // any-of pool
}{
{1, []string{"First morning", "Day one", "day two"}},
{3, []string{"Day three", "Three days"}},
{7, []string{"One week", "Seven days", "A week underground"}},
{14, []string{"Two weeks", "Fourteen days", "Day fifteen"}},
{21, []string{"Three weeks", "Day twenty-one"}},
}
for _, c := range cases {
got := pickMorningBriefing(c.day)
matched := false
for _, prefix := range c.want {
if strings.Contains(got, prefix) {
matched = true
break
}
}
if !matched {
t.Errorf("Day %d picked %q — none of %v matched", c.day, got, c.want)
}
}
// Generic fallback for off-band days.
if got := pickMorningBriefing(2); got == "" {
t.Error("generic fallback empty")
}
if got := pickMorningBriefing(99); got == "" {
t.Error("generic fallback empty")
}
}
func TestDeliverBriefing_AdvancesDayAndBurnsSupplies(t *testing.T) {
setupZoneRunTestDB(t)
uid := id.UserID("@exp-cycle-brief:example")
defer cleanupExpeditions(uid)
exp, err := startExpedition(uid, ZoneGoblinWarrens, "",
ExpeditionSupplies{Current: 10, Max: 10, DailyBurn: 1, HarshMod: 1})
if err != nil {
t.Fatal(err)
}
p := &AdventurePlugin{}
now := time.Now().UTC()
if err := p.deliverBriefing(exp, now); err != nil {
t.Fatal(err)
}
got, _ := getExpedition(exp.ID)
if got.CurrentDay != 2 {
t.Errorf("current_day = %d, want 2", got.CurrentDay)
}
// Phase 5-B: applyDailyBurn scales by phase5BDailyBurnRatePct=50, so
// raw burn 1 × 0.5 = 0.5 SU. Current 10 - 0.5 = 9.5.
if got.Supplies.Current != 9.5 {
t.Errorf("supplies = %v, want 9.5", got.Supplies.Current)
}
if got.LastBriefingAt == nil {
t.Error("LastBriefingAt should be set")
}
// Briefing log entry should exist.
entries, _ := recentExpeditionLog(exp.ID, 5)
foundBriefing := false
for _, e := range entries {
if e.Type == "briefing" {
foundBriefing = true
}
}
if !foundBriefing {
t.Error("briefing log entry missing")
}
}
func TestDeliverBriefing_HarshConditionsBurnFaster(t *testing.T) {
setupZoneRunTestDB(t)
uid := id.UserID("@exp-cycle-harsh:example")
defer cleanupExpeditions(uid)
exp, err := startExpedition(uid, ZoneGoblinWarrens, "",
ExpeditionSupplies{Current: 10, Max: 10, DailyBurn: 1, HarshMod: 2})
if err != nil {
t.Fatal(err)
}
// Force harsh conditions via threat clock above 60.
if err := applyThreatDelta(exp.ID, 70, "test"); err != nil {
t.Fatal(err)
}
exp, _ = getExpedition(exp.ID)
p := &AdventurePlugin{}
if err := p.deliverBriefing(exp, time.Now().UTC()); err != nil {
t.Fatal(err)
}
got, _ := getExpedition(exp.ID)
// Phase 5-B: 1 base × 2 harsh × phase5B 50% = 1 SU; current 10 - 1 = 9.
if got.Supplies.Current != 9 {
t.Errorf("harsh burn supplies = %v, want 9", got.Supplies.Current)
}
}
func TestLoadExpeditionsNeedingBriefing_FiltersByThreshold(t *testing.T) {
setupZoneRunTestDB(t)
uid := id.UserID("@exp-cycle-load:example")
defer cleanupExpeditions(uid)
// Start an expedition; rewind start_date so threshold falls past it.
exp, err := startExpedition(uid, ZoneGoblinWarrens, "",
ExpeditionSupplies{Current: 10, Max: 10, DailyBurn: 1, HarshMod: 1})
if err != nil {
t.Fatal(err)
}
yesterday := time.Now().UTC().Add(-25 * time.Hour)
if _, err := db.Get().Exec(`UPDATE dnd_expedition SET start_date = ? WHERE expedition_id = ?`,
yesterday, exp.ID); err != nil {
t.Fatal(err)
}
threshold := time.Now().UTC()
got, err := loadExpeditionsNeedingBriefing(threshold)
if err != nil {
t.Fatal(err)
}
found := false
for _, e := range got {
if e.ID == exp.ID {
found = true
}
}
if !found {
t.Error("expected expedition in needs-briefing list")
}
// Stamp briefing → should drop out.
now := time.Now().UTC()
if _, err := db.Get().Exec(`UPDATE dnd_expedition SET last_briefing_at = ? WHERE expedition_id = ?`,
now, exp.ID); err != nil {
t.Fatal(err)
}
got, err = loadExpeditionsNeedingBriefing(threshold.Add(-1 * time.Minute))
if err != nil {
t.Fatal(err)
}
for _, e := range got {
if e.ID == exp.ID {
t.Error("expedition should be filtered out after briefing stamped")
}
}
}
func TestDeliverRecap_StampsAndLogs(t *testing.T) {
setupZoneRunTestDB(t)
uid := id.UserID("@exp-cycle-recap:example")
defer cleanupExpeditions(uid)
exp, err := startExpedition(uid, ZoneGoblinWarrens, "",
ExpeditionSupplies{Current: 10, Max: 10, DailyBurn: 1, HarshMod: 1})
if err != nil {
t.Fatal(err)
}
p := &AdventurePlugin{}
if err := p.deliverRecap(exp, time.Now().UTC()); err != nil {
t.Fatal(err)
}
got, _ := getExpedition(exp.ID)
if got.LastRecapAt == nil {
t.Error("LastRecapAt should be set")
}
entries, _ := recentExpeditionLog(exp.ID, 5)
foundRecap := false
for _, e := range entries {
if e.Type == "recap" {
foundRecap = true
}
}
if !foundRecap {
t.Error("recap log entry missing")
}
}
func TestPickEveningRecap_BossOverridesAll(t *testing.T) {
exp := &Expedition{}
today := []ExpeditionEntry{
{Type: "combat"},
{Type: "boss", Summary: "boss defeated"},
}
got := pickEveningRecap(exp, today)
if got == "" {
t.Fatal("expected boss-killed flavor")
}
// Boss-killed pool entries reference the kill in varied ways — "boss",
// "thing in the chamber", "vacancy", etc. Match any of the recurring
// motifs rather than the literal word.
low := strings.ToLower(got)
matched := false
for _, marker := range []string{"boss", "thing in the chamber", "vacancy"} {
if strings.Contains(low, marker) {
matched = true
break
}
}
if !matched {
t.Errorf("expected boss-killed pool, got %q", got)
}
}
func TestPickEveningRecap_NothingHappenedFallback(t *testing.T) {
exp := &Expedition{}
today := []ExpeditionEntry{} // no entries today
got := pickEveningRecap(exp, today)
if got == "" {
t.Error("expected fallback flavor")
}
}