Improve ClassicAPI scans and move request handling

This commit is contained in:
2026-11-06 16:14:25 -04:00
parent d66c6e59cb
commit e23e2c4454
5 changed files with 117 additions and 18 deletions
+55
View File
@@ -467,5 +467,60 @@ check(table.getn(categories) == 0 and string.find(chat[1] or "", "needs ClassicA
SlashCmdList.SHARDCAP("")
check(string.find(chat[2] or "", "5/12", 1, true) == nil and string.find(chat[2] or "", "in bank", 1, true) == nil, "no bank text without ClassicAPI")
-- New ClassicAPI buffer contract: empty slots leave stale buffer fields intact.
reset(); setBag(0, 4); setBag(4, 4, 22243)
put(0, 1, 6265, 3); put(0, 2, 16583, 2); put(4, 1, 5565, 1)
load(true)
local bufferSeen, bufferCalls = nil, 0
C_Container.GetContainerItemInfo = function(b, s, buf)
check(type(buf) == "table" and (not bufferSeen or bufferSeen == buf), "one shared item-info buffer")
bufferSeen = buf; bufferCalls = bufferCalls + 1
local it = bags[b].slots[s]
if not it then return nil end
buf.itemID, buf.stackCount, buf.isLocked = it.id, it.count, false
return buf
end
local shards, reagents, soul = ShardCapAPI.StatusLines()
check(bufferCalls == 8 and string.find(shards, "3/12", 1, true) ~= nil,
"buffer scan ignores stale data in empty slots")
check(string.find(reagents, "2|r", 1, true) ~= nil and string.find(reagents, "1|r", 1, true) ~= nil
and string.find(soul, "3 free soul slots", 1, true) ~= nil, "count-only status includes reagents and free soul slots")
-- Status refresh must not build action records (table.insert is used by Scan).
local oldInsert = table.insert
table.insert = function(t, value)
if type(value) == "table" then error("status allocated an action record") end
return oldInsert(t, value)
end
local statusOK = pcall(ShardCapAPI.StatusLines)
table.insert = oldInsert
check(statusOK, "status avoids sorting records")
run()
check(count() == 3 and count(0) == 0 and not F.shown,
"action scans copy values from the shared buffer before reusing it")
-- Refused sends must stop rather than notify, retry, or reject a reagent.
for _, kind in ipairs({ "merge", "shard", "reagent", "shard MoveItem" }) do
reset(); setBag(0, 4); setBag(4, 8, 22243)
if kind == "merge" then put(0, 1, 6265, 1); put(4, 1, 6265, 1)
elseif kind ~= "reagent" then put(0, 1, 6265, 3)
else put(0, 1, 16583, 2) end
load(true); ShardCapDB.notify = true
if kind == "shard MoveItem" then
C_Container.SwapItems = nil
fire("ADDON_LOADED", "ShardCap") -- detect MoveItem without SwapItems
end
local calls = 0
local function refuse() calls = calls + 1; return false end
local move, swap = C_Container.MoveItem, C_Container.SwapItems
C_Container.MoveItem, C_Container.SwapItems = refuse, refuse
chat = {}; run()
check(calls == 1 and table.getn(chat) == 0 and not F.shown,
kind .. " refused send stops without a success notice or polling")
C_Container.MoveItem, C_Container.SwapItems = move, swap
fire("BAG_UPDATE_DELAYED"); run()
check(not F.shown and (kind == "reagent" and bags[0].slots[1] == nil
or kind ~= "reagent" and count(0) == 0), kind .. " retries on a later bag event")
end
print(string.format("\n%d passed, %d failed", passes, fails))
if fails > 0 then os.exit(1) end