Files
gogobee/internal/plugin/dnd_expedition_threat_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

274 lines
7.5 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 E2a — Threat Clock state-machine tests.
func TestThreatBandFor(t *testing.T) {
cases := []struct {
level int
siege bool
want ThreatBand
}{
{0, false, ThreatBandQuiet},
{20, false, ThreatBandQuiet},
{21, false, ThreatBandStirring},
{40, false, ThreatBandStirring},
{41, false, ThreatBandAlert},
{60, false, ThreatBandAlert},
{61, false, ThreatBandHostile},
{80, false, ThreatBandHostile},
{81, false, ThreatBandSiege},
{100, false, ThreatBandSiege},
{50, true, ThreatBandSiege},
}
for _, c := range cases {
got := threatBandFor(c.level, c.siege)
if got != c.want {
t.Errorf("threatBandFor(%d, %v) = %v, want %v", c.level, c.siege, got, c.want)
}
}
}
func TestThreatBandInfo_SiegeFlags(t *testing.T) {
info := threatBandInfo(ThreatBandSiege)
if !info.NoShortRest {
t.Error("siege should disable short rests")
}
if info.SupplyMult != 2 {
t.Errorf("siege supply mult = %v, want 2", info.SupplyMult)
}
if !info.InitAdv || !info.TrapsArm {
t.Error("siege should grant init advantage and re-arm traps")
}
}
func TestDailyThreatDrift_MoodMod(t *testing.T) {
// Phase 5-B: base threat drift lowered from 3 to 1 to slow the
// threat clock (paired with the player floor + supply burn cut).
// All expected values shift by -2 (base 3 → 1) but the mood-mod
// shape is unchanged.
cases := []struct {
mood int
want int
}{
{50, 1}, // neutral: 1 + 0
{60, 1}, // friendly (still neutral): 1 + 0
{80, -2}, // effusive → elated: 1 + -3
{19, 6}, // hostile → wrathful: 1 + 5
{0, 6}, // hostile lower bound
}
for _, c := range cases {
got, _ := dailyThreatDrift(c.mood)
if got != c.want {
t.Errorf("mood=%d drift=%d, want %d", c.mood, got, c.want)
}
}
}
func TestApplyDailyThreatDrift_PersistsAndCrossesThreshold(t *testing.T) {
setupZoneRunTestDB(t)
uid := id.UserID("@exp-threat-drift:example")
defer cleanupExpeditions(uid)
exp, err := startExpedition(uid, ZoneGoblinWarrens, "",
ExpeditionSupplies{Current: 10, Max: 10, DailyBurn: 1, HarshMod: 1})
if err != nil {
t.Fatal(err)
}
// Phase 5-B: base drift dropped to 1. Pre-load to 20 (Quiet band) so
// the +1 drift crosses into Stirring at 21.
if err := applyThreatDelta(exp.ID, 20, "test seed"); err != nil {
t.Fatal(err)
}
exp, _ = getExpedition(exp.ID)
delta, _, err := applyDailyThreatDrift(exp)
if err != nil {
t.Fatal(err)
}
if delta != 1 {
t.Errorf("delta = %d, want 1", delta)
}
got, _ := getExpedition(exp.ID)
if got.ThreatLevel != 21 {
t.Errorf("threat = %d, want 21", got.ThreatLevel)
}
// Threshold transition log entry should exist with TwinBee narration.
entries, _ := recentExpeditionLog(exp.ID, 10)
foundTransition := false
for _, e := range entries {
if e.Type == "threat" && strings.Contains(strings.ToLower(e.Summary), "stirring") {
if e.Flavor == "" {
t.Error("threat transition missing flavor line")
}
foundTransition = true
}
}
if !foundTransition {
t.Error("expected threat transition log entry into Stirring")
}
}
func TestApplyDailyThreatDrift_NoOpAfterBoss(t *testing.T) {
setupZoneRunTestDB(t)
uid := id.UserID("@exp-threat-postboss:example")
defer cleanupExpeditions(uid)
exp, err := startExpedition(uid, ZoneGoblinWarrens, "",
ExpeditionSupplies{Current: 10, Max: 10, DailyBurn: 1, HarshMod: 1})
if err != nil {
t.Fatal(err)
}
if _, err := db.Get().Exec(`UPDATE dnd_expedition SET boss_defeated = 1 WHERE expedition_id = ?`, exp.ID); err != nil {
t.Fatal(err)
}
exp, _ = getExpedition(exp.ID)
delta, _, err := applyDailyThreatDrift(exp)
if err != nil {
t.Fatal(err)
}
if delta != 0 {
t.Errorf("delta = %d, want 0 after boss kill", delta)
}
}
func TestDeliverBriefing_AppliesThreatDrift(t *testing.T) {
setupZoneRunTestDB(t)
uid := id.UserID("@exp-brief-drift: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.deliverBriefing(exp, time.Now().UTC()); err != nil {
t.Fatal(err)
}
got, _ := getExpedition(exp.ID)
if got.ThreatLevel != 1 {
t.Errorf("post-briefing threat = %d, want 1 (mood-neutral drift, Phase 5-B base)", got.ThreatLevel)
}
}
func TestApplyDailyThreatDrift_LogsApproachingSiegeOnceAt70(t *testing.T) {
setupZoneRunTestDB(t)
uid := id.UserID("@exp-threat-70warn:example")
defer cleanupExpeditions(uid)
exp, err := startExpedition(uid, ZoneGoblinWarrens, "",
ExpeditionSupplies{Current: 10, Max: 10, DailyBurn: 1, HarshMod: 1})
if err != nil {
t.Fatal(err)
}
// Phase 5-B: base drift dropped to 1. Seed to 69 so a +1 drift
// crosses 70 → 70.
if err := applyThreatDelta(exp.ID, 69, "seed"); err != nil {
t.Fatal(err)
}
exp, _ = getExpedition(exp.ID)
if _, _, err := applyDailyThreatDrift(exp); err != nil {
t.Fatal(err)
}
entries, _ := recentExpeditionLog(exp.ID, 20)
count := 0
for _, e := range entries {
if e.Type == "threat" && strings.Contains(e.Summary, "past 70") {
count++
}
}
if count != 1 {
t.Errorf("expected exactly one approaching-siege log, got %d", count)
}
// A subsequent drift past 70 should not re-emit the warning.
exp, _ = getExpedition(exp.ID)
if _, _, err := applyDailyThreatDrift(exp); err != nil {
t.Fatal(err)
}
entries, _ = recentExpeditionLog(exp.ID, 20)
count = 0
for _, e := range entries {
if e.Type == "threat" && strings.Contains(e.Summary, "past 70") {
count++
}
}
if count != 1 {
t.Errorf("expected approaching-siege log still 1 after second drift, got %d", count)
}
}
func TestThreatBandEffectsBlock_Bands(t *testing.T) {
q := threatBandEffectsBlock(threatBandInfo(ThreatBandQuiet))
if !strings.Contains(strings.ToLower(q), "unaware") {
t.Errorf("Quiet block should mention unaware, got %q", q)
}
s := threatBandEffectsBlock(threatBandInfo(ThreatBandSiege))
if !strings.Contains(strings.ToLower(s), "short rests blocked") {
t.Errorf("Siege block should call out blocked short rests, got %q", s)
}
if !strings.Contains(s, "×2") {
t.Errorf("Siege block should show ×2 supply mult, got %q", s)
}
}
func TestHandleThreatCmd_NoExpeditionDoesNotPanic(t *testing.T) {
setupZoneRunTestDB(t)
uid := id.UserID("@threat-cmd-noexp:example")
defer cleanupExpeditions(uid)
p := &AdventurePlugin{}
if err := p.handleThreatCmd(MessageContext{Sender: uid}); err != nil {
t.Fatal(err)
}
}
func TestHandleThreatCmd_ActiveExpeditionLogsEvents(t *testing.T) {
setupZoneRunTestDB(t)
uid := id.UserID("@threat-cmd-active:example")
defer cleanupExpeditions(uid)
exp, err := startExpedition(uid, ZoneGoblinWarrens, "",
ExpeditionSupplies{Current: 10, Max: 10, DailyBurn: 1, HarshMod: 1})
if err != nil {
t.Fatal(err)
}
if err := applyThreatDelta(exp.ID, 45, "test seed"); err != nil {
t.Fatal(err)
}
p := &AdventurePlugin{}
if err := p.handleThreatCmd(MessageContext{Sender: uid}); err != nil {
t.Fatal(err)
}
}
func TestApplyBossDefeatThreat_DropsLevel(t *testing.T) {
setupZoneRunTestDB(t)
uid := id.UserID("@exp-boss-threat:example")
defer cleanupExpeditions(uid)
exp, err := startExpedition(uid, ZoneGoblinWarrens, "",
ExpeditionSupplies{Current: 10, Max: 10, DailyBurn: 1, HarshMod: 1})
if err != nil {
t.Fatal(err)
}
if err := applyThreatDelta(exp.ID, 50, "seed"); err != nil {
t.Fatal(err)
}
if err := applyBossDefeatThreat(exp.ID); err != nil {
t.Fatal(err)
}
got, _ := getExpedition(exp.ID)
if got.ThreatLevel != 30 {
t.Errorf("post-boss threat = %d, want 30", got.ThreatLevel)
}
}