package game import ( "aeternalis/server/content" p "aeternalis/server/internal/protocol" "encoding/json" "math" "testing" "time" ) func TestHouseInventoryPreservesCraftedProvenance(t *testing.T) { b, _ := content.Load() w := New("craft-origin", 1, time.Now(), b) c, _ := w.Join("crafter", "Crafter") c.View.Inventory["bandage"] = 5 provenance := p.CraftProvenance{At: 1, CharacterID: c.View.Entity.ID, CrafterName: "Crafter", Level: 1, Profession: "alchemist", RecipeID: "recipe_bandage", RecipeRevision: 1, WorldID: w.ID} c.View.CraftedStacks = []p.CraftedStack{{ID: ID(), Item: "bandage", Quantity: 5, Provenance: provenance}} from, to := HouseInventoryOf(c), EmptyHouseInventory() if e := MoveHouseItem(&from, &to, "bandage", 2); e != nil { t.Fatal(e) } if from.Inventory["bandage"] != 3 || to.Inventory["bandage"] != 2 || to.CraftedStacks[0].Provenance != provenance || from.CraftedStacks[0].ID == to.CraftedStacks[0].ID { t.Fatal("split damaged provenance or duplicated batch ID") } seen := map[string]bool{} if e := ValidateHouseInventory(from, seen); e != nil { t.Fatal(e) } if e := ValidateHouseInventory(to, seen); e != nil { t.Fatal(e) } if e := w.AdminItems(c, "grant-item", "storage_chest:1"); e != nil { t.Fatal(e) } item := c.View.Items[len(c.View.Items)-1] h := p.House{Size: 12, Furniture: map[string]p.HouseFurniture{item.ID: {Item: item, X: 0, Z: 0}}} if FurnitureFits(h, "", item, 0, 0) || FurnitureFits(h, "", item, 6, 0) || FurnitureFits(h, "", item, math.NaN(), 0) || !FurnitureFits(h, item.ID, item, 3, 0) { t.Fatal("furniture collision validation") } before, _ := json.Marshal(to) if e := MoveHouseItem(&from, &to, "bandage", 999); e == nil { t.Fatal("overdraw accepted") } after, _ := json.Marshal(to) if string(before) != string(after) { t.Fatal("overdraw changed destination") } } func TestHousingDailyLimitAndNoMovement(t *testing.T) { b, _ := content.Load() now := time.Date(2026, 9, 10, 12, 0, 0, 0, time.UTC) w := New("daily-house", 1, now, b) c, _ := w.Join("owner", "Owner") _ = w.Connect(c.View.Entity.ID) w.Kind = "hub" w.Phase = "hub" id := ID() c.View.HouseID = &id before := c.View.Entity.Position c.MoveX = 1 c.LastMove = now c.DailySeconds = b.DailyPlaySeconds - 1 w.Advance(now.Add(500*time.Millisecond), .5) if c.View.Entity.Position != before || c.DailySeconds != b.DailyPlaySeconds-.5 { t.Fatal("housing moved avatar or stopped daily budget") } w.Advance(now.Add(2*time.Second), 1.5) if c.Online || c.View.HouseID != nil || c.View.RemainingSeconds != 0 { t.Fatal("daily cap did not exit housing") } }