From 1dce6fbf592b20dcf274cc74b45f3660fa7ff2b0 Mon Sep 17 00:00:00 2001 From: Kenny <48362370+masterred92@users.noreply.github.com> Date: Mon, 30 Nov 2026 12:21:12 -0800 Subject: [PATCH 1/2] fix: reject invalid price timestamps and clarify theoretical flip profits --- NeutralFlip.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/NeutralFlip.lua b/NeutralFlip.lua index 968a716..46310dc 100644 --- a/NeutralFlip.lua +++ b/NeutralFlip.lua @@ -196,7 +196,18 @@ function NF.CurrentKind() return currentKind end function NF.KindLabel(kind) return kind == NEUTRAL and "neutral" or (kind or "?") end local function fresh(rec, now) - return rec and (now - rec.t) <= settings.maxAgeHours * 3600 + if type(rec) ~= "table" then return false end + local p, t = C.SafeNumber(rec.p), C.SafeNumber(rec.t) + if not (p and p > 0 and p < math.huge and t and t > 0 and t <= now + and now - t <= settings.maxAgeHours * 3600) then return false end + -- Missing listing quantities are permitted; malformed or secret quantities are not. + for _, key in ipairs({ "q", "n" }) do + if rec[key] ~= nil then + local n = C.SafeNumber(rec[key]) + if not n or n < 0 or n >= math.huge or n ~= math.floor(n) then return false end + end + end + return true end -- One route: buy at `from` for buy.p, list at `to` 1c under its lowest listing. @@ -255,11 +266,12 @@ local function ago(sec) end function NF.FormatLine(i, o) - local s = ("%d. %s: BUY at %s AH at %s or less (%s%d) -> LIST at %s AH at %s -> +%s each, about %s total"):format( + local s = ("%d. %s: BUY at %s AH at %s or less (%s%d) -> LIST at %s AH at %s -> +%s each, about %s if all sell"):format( i, o.name, NF.KindLabel(o.from), C.Money(o.buy), o.qtyKnown and "x" or "x?", o.qty, NF.KindLabel(o.to), C.Money(o.listAt), C.Money(o.profit), C.Money(o.total)) local notes = { ("%s %s %s, %s %s %s"):format(NF.KindLabel(o.from), L["price"], ago(o.buyAge), NF.KindLabel(o.to), L["price"], ago(o.sellAge)) .. " " .. L["old"] } - if o.deposit then notes[#notes + 1] = "deposit at risk " .. C.Money(o.deposit) end + if not o.qtyKnown then notes[#notes + 1] = "quantity at lowest buy price unknown" end + if o.deposit then notes[#notes + 1] = "deposit at risk " .. C.Money(o.deposit) else notes[#notes + 1] = "deposit unknown" end if o.carried > 0 then notes[#notes + 1] = "you carry " .. o.carried end if o.thin then notes[#notes + 1] = "THIN MARKET: check by hand" end return s .. " [" .. table.concat(notes, ", ") .. "]" @@ -279,7 +291,7 @@ function NF.ListText(now) end for i = 1, math.min(#list, settings.listSize) do lines[#lines + 1] = NF.FormatLine(i, list[i]) end lines[#lines + 1] = "" - lines[#lines + 1] = "You press every buy and post. Prices are the lowest listing you last saw; they may have moved." + lines[#lines + 1] = "You press every buy and post. Observed listings are not completed sales or proof of demand. Prices may have moved; unsold auctions can lose the deposit." return table.concat(lines, "\n"), #list end From 2662412a2629381af8fa600e1218955f2804bcd6 Mon Sep 17 00:00:00 2001 From: Kenny <48362370+masterred92@users.noreply.github.com> Date: Mon, 30 Nov 2026 12:21:15 -0800 Subject: [PATCH 2/2] test: reject invalid or future market observations --- tests/test_neutralflip.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_neutralflip.lua b/tests/test_neutralflip.lua index 29e6495..1b01e9a 100644 --- a/tests/test_neutralflip.lua +++ b/tests/test_neutralflip.lua @@ -55,6 +55,20 @@ check(not o.thin, "19x ratio not thin") local text = NF.ListText() check(text:find("BUY at Alliance AH") and text:find("LIST at neutral AH"), "list text: " .. text) +-- Invalid data must not produce a recommendation, and listing profits are conditional. +check(text:find("if all sell", 1, true) and text:find("not completed sales", 1, true), "conditional estimated profit") +local savedHome = db.houses["TestRealm-Alliance"].items[785] +for _, bad in ipairs({ + { p = 100, q = 40, n = 50, t = W.now + 60 }, + { p = 100, q = 40, n = 50 }, + { p = "100", q = 40, n = 50, t = W.now }, + { p = 100, q = "40", n = 50, t = W.now }, +}) do + db.houses["TestRealm-Alliance"].items[785] = bad + check(#NF.ItemRoutes(785, W.now, {}) == 0, "invalid comparison ignored") +end +db.houses["TestRealm-Alliance"].items[785] = savedHome + -- Reverse direction, outlier flag W.commodity[2589] = { { unitPrice = 10, quantity = 100 } } W.fire("COMMODITY_SEARCH_RESULTS_UPDATED", 2589)