diff --git a/CHANGELOG.md b/CHANGELOG.md index 483d4a5..b44cb4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.4.1 +- Cancel pending and chunked scans on a new result, AH close, market correction or price wipe; never mark empty, incomplete or timed-out snapshots successful. +- Keep known faction and neutral price buckets isolated; pause recording at unknown locations or deposit-rate conflicts until confirmed. +- Bind delayed deposit checks to their own AH session, and show generation-safe scan status and market diagnostics in /nflip status and /nflip report. +- Preserve saved data, settings, integrations and packaging. Add mock regressions for scan and market lifecycle. + ## 0.4.0 - Adds conditional cash recovery: minimum units that must sell at the observed listing price to recover acquisition outlay and one failed posting's estimated deposit on unsold units. Unsold stock is assigned no cash proceeds, not zero asset value. - Unknown deposits remain unknown; listing quantity is not demand. diff --git a/NeutralFlip.lua b/NeutralFlip.lua index 7c9300c..0c8ede2 100644 --- a/NeutralFlip.lua +++ b/NeutralFlip.lua @@ -10,6 +10,7 @@ KennyNeutralFlip = NF local SCHEMA = 2 local SCAN_COOLDOWN = 15 * 60 +local SCAN_TIMEOUT = 120 local NEUTRAL = "Neutral" local DEFAULTS = { cutFaction = 0.05, -- faction AH cut (ahledger.com/wow-forever/auction-house); override with /nflip cut @@ -31,7 +32,16 @@ NF.NEUTRAL_NAMES = { ["Booty Bay"] = true, ["Gadgetzan"] = true, ["Everlook"] = NF.NEUTRAL_MAPS = { [1434] = true, [1446] = true, [1452] = true } local db, settings -local ahOpen, house, scanToken, processing = false, nil, 0, false +local ahOpen, house, currentKind, location, classification = false, nil, nil, nil, "closed" +local session, scanToken, scanState = 0, 0, nil +local recordingReady = false +local lastScanStatus = "none" +local FACTION_NAMES = { + ["Stormwind City"] = "Alliance", ["Stormwind"] = "Alliance", ["Ironforge"] = "Alliance", + ["Darnassus"] = "Alliance", ["Exodar"] = "Alliance", ["The Exodar"] = "Alliance", + ["Orgrimmar"] = "Horde", ["Thunder Bluff"] = "Horde", ["Undercity"] = "Horde", + ["Silvermoon City"] = "Horde", +} local migrations = { [1] = function(old) return { houses = {}, overrides = {}, rates = {}, settings = old.settings or {} } end, @@ -59,13 +69,24 @@ end -- "Neutral" or the player's faction, plus how we decided. function NF.DetectKind() local key, zone, sub = NF.LocationKey() - local o = db.overrides[key] + local o = key ~= "/" and db.overrides[key] or nil if o == "neutral" then return NEUTRAL, "your /nflip here setting" end - if o == "faction" then return playerFaction(), "your /nflip here setting" end + if o == "faction" then + local faction = playerFaction() + if faction == "Alliance" or faction == "Horde" then return faction, "your /nflip here setting" end + return nil, "player faction unavailable" + end local mapID = C_Map and C_Map.GetBestMapForUnit and C.SafeNumber(C_Map.GetBestMapForUnit("player")) - if mapID and NF.NEUTRAL_MAPS[mapID] then return NEUTRAL, "map " .. mapID end - if NF.NEUTRAL_NAMES[sub] or NF.NEUTRAL_NAMES[zone] then return NEUTRAL, "zone " .. key end - return playerFaction(), "zone " .. key + local namedNeutral = NF.NEUTRAL_NAMES[sub] or NF.NEUTRAL_NAMES[zone] + local namedFaction = FACTION_NAMES[sub] or FACTION_NAMES[zone] + local mappedNeutral = mapID and NF.NEUTRAL_MAPS[mapID] + if namedFaction and (namedNeutral or mappedNeutral or namedFaction ~= playerFaction()) then + return nil, "conflicting location or player faction " .. key + end + if namedNeutral then return NEUTRAL, "zone " .. key end + if namedFaction then return namedFaction, "zone " .. key end + if mappedNeutral then return NEUTRAL, "map " .. mapID end + return nil, "unrecognized location " .. key end local function houseData(kind) @@ -139,47 +160,118 @@ end -- Capturing prices (only what the AH already shows you) ------------------------------------- -function NF.ProcessReplicate() - if processing or not house then return end +-- A session owns its market and each scan owns its callbacks. Never commit a partial snapshot. +local function sameHouse() + return ahOpen and house and NF.LocationKey() == location +end + +local function activeHouse() + return recordingReady and sameHouse() +end + +local function cancelScan(reason, notify) + if scanState and reason then + lastScanStatus = reason + if notify then Core.Print("full scan " .. reason .. "; no full scan recorded.") end + end + scanToken = scanToken + 1 + scanState = nil +end + +local function beginScan(phase) + cancelScan() + local state = { token = scanToken, session = session, house = house, kind = currentKind, + phase = phase, deadline = C.Clock() + SCAN_TIMEOUT } + scanState = state + C_Timer.After(SCAN_TIMEOUT, function() + if scanState == state and C.Clock() >= state.deadline then cancelScan("timed out (" .. state.phase .. ")", true) end + end) + return state +end + +local function validScan(state) + return scanState == state and state.token == scanToken and state.session == session + and activeHouse() and state.house == house and state.kind == currentKind +end + +local function positiveInteger(v) + return v and v > 0 and v < math.huge and v == math.floor(v) +end + +-- The shared helper conflates incomplete rows and valid bid-only auctions. Inspect +-- the documented fields here so a bid-only auction can be skipped safely. +local function scanRow(i) + local _, _, count, _, _, _, _, _, _, buyout, _, _, _, _, _, _, itemID, hasAll = + C_AuctionHouse.GetReplicateItemInfo(i) + if C.Safe(hasAll) ~= true then return nil, "incomplete row" end + itemID, count, buyout = C.SafeNumber(itemID), C.SafeNumber(count), C.SafeNumber(buyout) + if not (positiveInteger(itemID) and positiveInteger(count) and buyout and buyout >= 0 + and buyout < math.huge and buyout == math.floor(buyout)) then return nil, "invalid row" end + if buyout == 0 then return nil end -- complete bid-only auction, not a price observation + if buyout < count then return nil, "invalid unit price" end + return itemID, nil, count, math.floor(buyout / count) +end + +function NF.ProcessReplicate(state) + state = state or scanState + if not state or not validScan(state) or state.phase == "processing" then return end local n = C.AHNumReplicate() - if n == 0 then return end - processing = true - local h, acc, i, now = house, {}, 0, C.Now() + if not positiveInteger(n) then cancelScan("returned no usable rows", true); return end + state.phase = "processing" + local acc, i, accepted, now = {}, 0, 0, C.Now() local function finish() + if not validScan(state) then return end + if accepted == 0 then cancelScan("contained no usable buyouts", true); return end local k = 0 - for id, a in pairs(acc) do NF.Record(h, id, a.min, a.qmin, a.qty, now); k = k + 1 end - h.lastScan = now - processing = false - Core.Print(("saved %d prices for the %s auction house."):format(k, NF.KindLabel(NF.CurrentKind()))) + for id, a in pairs(acc) do + local previous = state.house.items[id] + if not previous or not C.SafeNumber(previous.t) or previous.t <= now then + NF.Record(state.house, id, a.min, a.qmin, a.qty, now) + end + k = k + 1 + end + state.house.lastScan = now + lastScanStatus = ("complete: %d rows, %d buyouts, %d items (%s)"):format(n, accepted, k, NF.KindLabel(state.kind)) + cancelScan() + Core.Print(("saved %d prices for the %s auction house."):format(k, NF.KindLabel(state.kind))) end - local function step() - if C.InCombat() then C_Timer.After(1, step) return end + local step, run + step = function() + if not validScan(state) then return end + if C.Clock() >= state.deadline then cancelScan("timed out (processing)", true); return end + if C.InCombat() then C_Timer.After(1, run); return end + if C.AHNumReplicate() ~= n then cancelScan("row count changed during processing", true); return end local stop = math.min(i + 500, n) while i < stop do - local itemID, _, count, buyout = C.AHReplicateRow(i) + local itemID, err, count, unit = scanRow(i) + if err then cancelScan(err .. " at " .. (i + 1), true); return end if itemID then - local unit = math.floor(buyout / count) local a = acc[itemID] if not a then a = { min = unit, qmin = 0, qty = 0 }; acc[itemID] = a end if unit < a.min then a.min, a.qmin = unit, 0 end if unit == a.min then a.qmin = a.qmin + count end a.qty = a.qty + count + accepted = accepted + 1 end i = i + 1 end - if i < n then C_Timer.After(0, function() if not Core.SafeCall("scan", step) then processing = false end end) else finish() end + if i < n then C_Timer.After(0, run) else finish() end end - if not Core.SafeCall("scan", step) then processing = false end + run = function() + if not validScan(state) then return end + if not Core.SafeCall("scan", step) and scanState == state then cancelScan("failed", true) end + end + run() end local function OnBrowse() - if not house then return end + if not activeHouse() then return end for _, r in ipairs(C.AHBrowse()) do NF.Record(house, r.itemID, r.price, nil, r.quantity) end end local function OnCommodity(itemID) itemID = C.SafeNumber(itemID) - if not (house and itemID) then return end + if not (activeHouse() and itemID) then return end local minP, qmin, total = nil, 0, 0 for _, r in ipairs(C.AHCommodity(itemID)) do if not minP or r.price < minP then minP, qmin = r.price, 0 end @@ -191,7 +283,6 @@ end -- The verdict ------------------------------------------------------------------------------- -local currentKind function NF.CurrentKind() return currentKind end function NF.KindLabel(kind) return kind == NEUTRAL and "neutral" or (kind or "?") end @@ -348,10 +439,18 @@ f:RegisterEvent("COMMODITY_SEARCH_RESULTS_UPDATED") local announced = {} function NF.OnAHShow() - ahOpen = true + cancelScan("cancelled: market changed", true) + session = session + 1 + local generation = session + ahOpen, recordingReady = true, false local kind, why = NF.DetectKind() + location, classification = NF.LocationKey(), why currentKind = kind - house = houseData(kind) + house = kind and houseData(kind) or nil + if not kind then + Core.Print("auction house market unknown (" .. why .. "); recording paused. Use /nflip here neutral|faction.") + return + end -- One line per auction house per session (not on every visit), unless there are flips to report. local _, n = NF.ListText() local key = NF.LocationKey() @@ -361,13 +460,25 @@ function NF.OnAHShow() n > 0 and (n .. " flips found: /nflip") or "Search or /nflip scan to record prices.")) end C_Timer.After(1, function() - if not ahOpen then return end - Core.SafeCall("deposit", function() - local rate = NF.ProbeDepositRate() + if not sameHouse() or session ~= generation or currentKind ~= kind then return end + local ok = Core.SafeCall("deposit", function() + local rate = not C.InCombat() and NF.ProbeDepositRate() or nil local warn = NF.CrossCheck(kind, rate) - if warn then Core.Print(warn) + if warn then + Core.Print(warn) + if not db.overrides[location] then + classification = "deposit mismatch; recording paused pending /nflip here override" + cancelScan("cancelled: deposit mismatch", true) + house = nil + return + end elseif rate then db.rates[kind == NEUTRAL and "neutral" or "faction"] = rate end + recordingReady = true end) + if not ok then + classification = "deposit check failed; recording paused" + cancelScan("cancelled: deposit check failed", true) + end end) end @@ -390,12 +501,20 @@ f:SetScript("OnEvent", function(_, event, arg1) if next(h.items) == nil then db.houses[key] = nil end end elseif event == "AUCTION_HOUSE_SHOW" then Core.SafeCall("show", NF.OnAHShow) - elseif event == "AUCTION_HOUSE_CLOSED" then ahOpen, house = false, nil + elseif event == "AUCTION_HOUSE_CLOSED" then + cancelScan("cancelled: auction house closed", true) + session = session + 1 + ahOpen, house, currentKind, location, classification = false, nil, nil, nil, "closed" + recordingReady = false elseif event == "REPLICATE_ITEM_LIST_UPDATE" then -- Also catches a full scan started by PriceLog or MatTooltip, so one scan feeds all three. - scanToken = scanToken + 1 - local token = scanToken - C_Timer.After(2, function() if token == scanToken then NF.ProcessReplicate() end end) + if not sameHouse() then return end + local state = beginScan("waiting for rows") + C_Timer.After(2, function() + if validScan(state) and not Core.SafeCall("scan start", NF.ProcessReplicate, state) and scanState == state then + cancelScan("failed to start", true) + end + end) elseif C.InCombat() then return elseif event == "AUCTION_HOUSE_BROWSE_RESULTS_UPDATED" then Core.SafeCall("browse", OnBrowse) elseif event == "COMMODITY_SEARCH_RESULTS_UPDATED" then Core.SafeCall("commodity", OnCommodity, arg1) @@ -450,17 +569,22 @@ SlashCmdList.KENNYNEUTRALFLIP = function(msg) Core.OpenView(function() Core.ShowText("List", "NeutralFlip: what to carry where (Ctrl+C copies)", (NF.ListText())) end) elseif cmd == "scan" then if not ahOpen then Core.Print("open an auction house first.") return end + if not activeHouse() then Core.Print("market not ready; wait for the deposit check or use /nflip here neutral|faction if unknown.") return end + if scanState then Core.Print("a full scan is already " .. scanState.phase .. ".") return end if C.InCombat() then Core.Print("not in combat.") return end local wait = SCAN_COOLDOWN - (C.Now() - (house.lastScan or 0)) if wait > 0 then Core.Print(("full scan available in %d min. Your searches are still recorded."):format(math.ceil(wait / 60))) return end if not C.AHReady() then Core.Print("AH busy, try again shortly.") return end local mine, by, left = ns.Hub.ClaimScan(ADDON) if not mine then Core.Print(("%s %s; %s %d min. %s"):format(L["a full scan was already started by"], by or "?", L["next one in"], math.ceil(left / 60), L["Its results are recorded here too."])) return end - C.AHReplicate() + beginScan("waiting for results") + local ok, requested = Core.SafeCall("replicate", C.AHReplicate) + if not ok or not requested then cancelScan("request failed", true); return end Core.Print("full scan requested. Stay at the AH until it reports.") elseif cmd == "here" then local key = NF.LocationKey() local v = rest:lower() + if key == "/" then Core.Print("location unavailable; cannot set a location override.") return end if v == "neutral" or v == "faction" then db.overrides[key] = v elseif v == "auto" then db.overrides[key] = nil else Core.Print("usage: /nflip here neutral|faction|auto") return end @@ -477,6 +601,8 @@ SlashCmdList.KENNYNEUTRALFLIP = function(msg) settings.tooltip = not settings.tooltip Core.Print("tooltip lines " .. (settings.tooltip and "on." or "off.")) elseif cmd == "status" then + Core.Print("market: " .. (ahOpen and NF.KindLabel(currentKind) or "closed") .. " (" .. classification .. "); recording " .. (activeHouse() and "enabled" or "paused") .. ".") + Core.Print("scan: " .. (scanState and scanState.phase or "idle") .. "; last result: " .. lastScanStatus .. ".") if next(db.houses) == nil then Core.Print("no prices recorded yet. Search or /nflip scan at an auction house.") end for key, h in pairs(db.houses) do local n = 0 @@ -486,19 +612,24 @@ SlashCmdList.KENNYNEUTRALFLIP = function(msg) Core.Print(("deposit/vendor rate learned: faction %s, neutral %s."):format( db.rates.faction and ("%.2f"):format(db.rates.faction) or "?", db.rates.neutral and ("%.2f"):format(db.rates.neutral) or "?")) elseif cmd == "report" then - local lines = { "schema " .. tostring(db.schema), "kind " .. tostring(currentKind), "location " .. NF.LocationKey() } + local lines = { "schema " .. tostring(db.schema), "kind " .. tostring(currentKind), "location " .. NF.LocationKey(), + "classification " .. classification, "AH open " .. tostring(ahOpen), + "recording " .. (activeHouse() and "enabled" or "paused"), + "scan " .. (scanState and scanState.phase or "idle"), "last scan result " .. lastScanStatus, + "deposit rates: faction " .. tostring(db.rates.faction) .. ", neutral " .. tostring(db.rates.neutral) } for key, h in pairs(db.houses) do local n = 0 for _ in pairs(h.items) do n = n + 1 end - lines[#lines + 1] = key .. " items " .. n + lines[#lines + 1] = key .. " items " .. n .. ", last full scan " .. tostring(h.lastScan or 0) end Core.ShowReport(lines) elseif cmd == "debug" then Core.PrintDebug() elseif cmd == "way" then NF.Waypoint(rest) elseif cmd == "wipe" then + cancelScan("cancelled: prices wiped", true) db.houses = {} - if ahOpen and currentKind then house = houseData(currentKind) end -- keep recording at the open AH + if sameHouse() and currentKind then house = houseData(currentKind) end -- keep recording at the open AH Core.Print("all recorded prices wiped.") else Core.Print(HELP) diff --git a/NeutralFlip.toc b/NeutralFlip.toc index 66d5244..19a6ead 100644 --- a/NeutralFlip.toc +++ b/NeutralFlip.toc @@ -2,7 +2,7 @@ ## Title: NeutralFlip ## Notes: Compares your faction AH with the neutral (Booty Bay / Gadgetzan / Everlook) AH and lists buys worth carrying across, after the 5%/15% cuts. You press every button. ## Author: Kenny -## Version: 0.4.0 +## Version: 0.4.1 ## SavedVariables: KennyNeutralFlipDB ## OptionalDeps: PriceLog, MatTooltip, LibDataBroker-1.1, TomTom ## X-License: MIT diff --git a/README.md b/README.md index 23f29c2..db09ddc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

NeutralFlip logo

-# NeutralFlip (WoW: Forever) v0.4.0 +# NeutralFlip (WoW: Forever) v0.4.1 The list includes conditional cash recovery when the deposit is known: how many units need to sell to recover acquisition outlay and one failed posting on unsold units. This is not a probability of sale. @@ -25,13 +25,15 @@ NeutralFlip keeps **separate prices for your faction AH and the neutral AH**. It - **Net of the cut:** each listing is priced 1c under the lowest one you saw, and the profit shown is after the 5% or 15% cut. - **Filters:** a flip only shows if its profit is at least 20% of the buy price and at least 50c a unit. Prices older than 24 hours are ignored. - **Quantity:** capped at what's listed at the lowest price and at what the other house lists. -- **Deposit at risk:** you get the deposit back if the item sells. The rate is measured with `C_AuctionHouse.CalculateCommodityDeposit` the first time you open each kind of AH. +- **Deposit at risk:** you get the deposit back if the item sells. The rate is checked with `C_AuctionHouse.CalculateCommodityDeposit` shortly after opening a recognized AH, when suitable item data is available. - **Thin-market flag:** shown when the gap is 20x or more, because that's usually a troll listing. - **Tooltip:** adds one or two lines: both prices, plus the flip if there is one. **It never buys, posts or clicks anything.** It only records prices the AH already shows you, from your own searches or a full scan you start yourself. It also picks up full scans started by PriceLog or MatTooltip. You make every purchase and post. -**Good to know:** the 5% faction / 15% neutral cuts come from [AHledger](https://ahledger.com/wow-forever/auction-house), and you can change them with `/nflip cut`. If a spot is detected as the wrong auction house, `/nflip here neutral` or `/nflip here faction` fixes it for that spot. +**Good to know:** the 5% faction / 15% neutral cuts come from [AHledger](https://ahledger.com/wow-forever/auction-house), and you can change them with `/nflip cut`. Unknown or conflicting locations pause recording; a deposit-rate conflict also pauses automatic recording until you explicitly confirm the market. If a spot is detected as the wrong auction house, `/nflip here neutral` or `/nflip here faction` fixes it for that spot. + +Full scans are committed only after all rows have been inspected. Empty, incomplete, interrupted and timed-out scans do not update the last successful scan. `/nflip status` and `/nflip report` show the market classification and scan outcome. **Extras** - **TomTom arrow:** `/nflip way` points a TomTom arrow at the nearest neutral AH (Gadgetzan on Kalimdor, Booty Bay in the Eastern Kingdoms), or `/nflip way everlook`. Only if TomTom is installed. It sets a waypoint; you do the walking. diff --git a/tests/test_neutralflip.lua b/tests/test_neutralflip.lua index d9ed231..5edc7ca 100644 --- a/tests/test_neutralflip.lua +++ b/tests/test_neutralflip.lua @@ -94,7 +94,7 @@ W.now = W.now + 25 * 3600 check(#NF.Opportunities() == 0, "prices older than 24h ignored") -- Cross-check warns when the zone guess disagrees with the deposit rate -W.zone, W.subzone = "Elwynn Forest", "Goldshire" +W.zone, W.subzone = "Stormwind City", "Trade District" W.depositRate = 1.5 W.prints = {} W.fire("AUCTION_HOUSE_SHOW"); W.runTimers() @@ -102,9 +102,9 @@ local warned = false for _, p in ipairs(W.prints) do if p:find("look like the NEUTRAL") then warned = true end end check(NF.CurrentKind() == "Alliance" and warned, "deposit cross-check warns") SlashCmdList.KENNYNEUTRALFLIP("here neutral") -check(NF.CurrentKind() == "Neutral" and db.overrides["Elwynn Forest/Goldshire"] == "neutral", "/nflip here override") +check(NF.CurrentKind() == "Neutral" and db.overrides["Stormwind City/Trade District"] == "neutral", "/nflip here override") SlashCmdList.KENNYNEUTRALFLIP("here auto") -check(db.overrides["Elwynn Forest/Goldshire"] == nil, "override cleared") +check(db.overrides["Stormwind City/Trade District"] == nil, "override cleared") -- map ID detection W.zone, W.subzone, W.mapID = "Somewhere", "", 1446 W.fire("AUCTION_HOUSE_SHOW"); W.runTimers() diff --git a/tests/test_scan_lifecycle.lua b/tests/test_scan_lifecycle.lua new file mode 100644 index 0000000..02dd3f4 --- /dev/null +++ b/tests/test_scan_lifecycle.lua @@ -0,0 +1,115 @@ +package.path = "tests/?.lua;" .. package.path +local W = require("mock_wow"); W.install() +local check = W.check +local timers = {} +C_Timer.After = function(delay, fn) timers[#timers + 1] = { at = W.clock + delay, fn = fn } end +local function advance(seconds) + W.clock = W.clock + seconds + local ready, later = {}, {} + for _, t in ipairs(timers) do + local dest = t.at <= W.clock and ready or later + dest[#dest + 1] = t + end + timers = later + for _, t in ipairs(ready) do t.fn() end +end +local function printed(needle) + for _, line in ipairs(W.prints) do if line:find(needle, 1, true) then return true end end + return false +end +GetSubZoneText = function() return W.subzone end +C_Map = { GetBestMapForUnit = function() return W.mapID end } +C_AuctionHouse.CalculateCommodityDeposit = function(id, _, q) + return math.floor(W.items[id][4] * q * W.rate) +end +W.bags[0] = { [1] = { 249427, 5 } } +W.rate = 0.3 +local ns = W.loadAddon(".", "NeutralFlip"); W.fire("PLAYER_LOGIN") +local NF, db = KennyNeutralFlip, KennyNeutralFlipDB +local function open(zone, sub, rate) + W.zone, W.subzone, W.rate = zone, sub, rate + W.fire("AUCTION_HOUSE_SHOW") +end +local function close() W.fire("AUCTION_HOUSE_CLOSED") end +local function update(rows) + W.replicate = rows + W.fire("REPLICATE_ITEM_LIST_UPDATE") +end +local function many() + local rows = {} + for i = 1, 501 do rows[i] = { 2447, 1, 100 } end + return rows +end +open("Stormwind City", "Trade District", 0.3); advance(1) +local home = db.houses["TestRealm-Alliance"] +check(db.rates.faction == 0.3, "known faction deposit") +update(many()); advance(2) -- first batch staged, not committed +check(home.lastScan == 0 and next(home.items) == nil, "batch is atomic before completion") +close(); open("Tanaris", "Gadgetzan", 1.5); advance(1) +local neutral = db.houses["TestRealm-Neutral"] +check(home.lastScan == 0 and next(home.items) == nil and next(neutral.items) == nil, "closing cancels staged scan") +check(db.rates.neutral == 1.5 and db.rates.faction == 0.3, "reopen kept rate buckets separate") +update(many()); advance(2) +update({ { 2318, 1, 777 } }); advance(0); advance(2) +check(neutral.items[2447] == nil and neutral.items[2318].p == 777 and neutral.lastScan == W.now, "new replicate event replaces old generation") +local prior = neutral.lastScan +W.now = W.now + 10 +update({}); advance(2) +check(neutral.lastScan == prior and printed("no usable rows"), "empty scan leaves success timestamp unchanged") +update({ { 2447, 1, 0 } }); advance(2) +check(neutral.lastScan == prior and printed("no usable buyouts"), "bid-only results cannot count as success") +local normalRow = C_AuctionHouse.GetReplicateItemInfo +C_AuctionHouse.GetReplicateItemInfo = function(i) + if i == 1 then return nil end + return normalRow(i) +end +update({ { 2447, 1, 10 }, { 2318, 1, 100 } }); advance(2) +check(neutral.lastScan == prior and neutral.items[2447] == nil and printed("incomplete row"), "incomplete row rolls back whole scan") +C_AuctionHouse.GetReplicateItemInfo = normalRow +update({ { 2447, 1, 0 }, { 2318, 1, 900 } }); advance(2) +check(neutral.lastScan == W.now and neutral.items[2447] == nil and neutral.items[2318].p == 900, "valid bid-only row skipped in valid scan") +prior = neutral.lastScan +update(many()); advance(2); W.replicate[501] = nil; advance(0) +check(neutral.lastScan == prior and neutral.items[2447] == nil and printed("row count changed"), "changing row count cancels scan") +update(many()); advance(2); W.combat = true; advance(0); advance(120); W.combat = false +check(neutral.lastScan == prior and printed("timed out"), "processing deadline cancels combat-deferred work") +close(); W.mapID = 1446; open("Ironforge", "The Commons", 0.3); advance(1) +check(NF.CurrentKind() == nil, "contradictory map and faction city do not choose a market") +close(); W.mapID = nil; open("Unknown Place", "Unknown", 1.5); advance(1) +check(NF.CurrentKind() == nil and printed("market unknown"), "unrecognized location does not default to faction") +W.browse = { { itemKey = { itemID = 2447 }, minPrice = 42, totalQuantity = 1 } } +W.fire("AUCTION_HOUSE_BROWSE_RESULTS_UPDATED"); update({ { 2447, 1, 9 } }); advance(2) +check(home.items[2447] == nil and neutral.items[2447] == nil, "unknown market blocks browse and replicate") +SlashCmdList.KENNYNEUTRALFLIP("scan") +check(not W.replicateRequested, "unknown market blocks manual request") +SlashCmdList.KENNYNEUTRALFLIP("here neutral"); advance(1) +W.fire("AUCTION_HOUSE_BROWSE_RESULTS_UPDATED") +check(neutral.items[2447].p == 42 and home.items[2447] == nil, "explicit override enables correct bucket") +close(); open("Stormwind City", "Trade District", 0.3) +close(); open("Tanaris", "Gadgetzan", 1.5); advance(1) +check(db.rates.faction == 0.3 and db.rates.neutral == 1.5, "stale AH deposit callback cannot overwrite faction rate") +close(); open("Stormwind City", "Trade District", 1.5) +W.fire("AUCTION_HOUSE_BROWSE_RESULTS_UPDATED"); advance(1) +W.fire("AUCTION_HOUSE_BROWSE_RESULTS_UPDATED") +check(home.items[2447] == nil and db.rates.faction == 0.3, "deposit mismatch pauses recording before and after check") +SlashCmdList.KENNYNEUTRALFLIP("status") +check(printed("deposit mismatch") and printed("recording paused"), "status exposes classification conflict") +SlashCmdList.KENNYNEUTRALFLIP("here neutral"); advance(1) +W.fire("AUCTION_HOUSE_BROWSE_RESULTS_UPDATED") +check(neutral.items[2447].p == 42 and home.items[2447] == nil, "market correction does not write into wrong bucket") +close(); open("Ironforge", "The Commons", 0.3); advance(1) +SlashCmdList.KENNYNEUTRALFLIP("scan") +check(W.replicateRequested == 1, "valid manual scan request") +advance(120) +check(home.lastScan == 0 and printed("timed out (waiting for results)"), "missing event times out and never records a scan") +update(many()); advance(2) +SlashCmdList.KENNYNEUTRALFLIP("wipe"); advance(0) +check(next(db.houses["TestRealm-Alliance"].items) == nil and db.houses["TestRealm-Alliance"].lastScan == 0, "wipe cancels staged scan") +SlashCmdList.KENNYNEUTRALFLIP("status") +check(printed("last result: cancelled: prices wiped"), "status reports cancellation") +local report +ns.Core.ShowReport = function(lines) report = table.concat(lines, "\n") end +SlashCmdList.KENNYNEUTRALFLIP("report") +check(report and report:find("classification", 1, true) and report:find("last scan result", 1, true) + and report:find("deposit rates", 1, true), "report provides actionable diagnostics") +W.done("NeutralFlip scan lifecycle")