✨ 初始提交:月读第三方书源插件集合

每个书源一个独立插件目录,含微信读书公众号订阅、书架导入等完整功能。

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
GarfieldandCopilot committed 2026-11-16 12:08:03 +08:00
commit d08a5b45c0
24 files changed
+2973

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
--[[--
书旗进度的各阶段取消:同步桩不能覆盖下一阶段,异步首阶段也必须可取消。
@module tests.moonsource_shuqi.progress_spec
--]]
---@diagnostic disable: undefined-field, missing-fields, param-type-mismatch
local Assert = require("support.assert")
local pending
local function request(cb)
pending = { cb = cb }
local operation = pending
return { cancel = function() operation.cancelled = true end }
end
local sync = false
local client = {
loggedIn = function() return true end,
progressAsync = function(_id, cb)
if sync then
cb({ chapter_id = "11", fraction = 0.5 })
return { cancel = function() error("stale first handle") end }
end
return request(cb)
end,
putProgressAsync = function(_id, _chapter, _title, fraction, cb)
Assert.eq(fraction, 0.5)
return request(cb)
end,
}
package.loaded["moonsource_shuqi.client"] = client
package.loaded["source.toc"] = { index = function() return 1 end }
local source = require("moonsource_shuqi.source").new()
local toc = { { uid = "11", title = "第一章" }, { uid = "12", title = "第二章" } }
source.loadTocAsync = function(_self, _identity, cb) return request(cb) end
local identity = { source_id = "ext.shuqi", stable_id = "9" }
local calls = 0
local handle = source:getProgressAsync(identity, function() calls = calls + 1 end)
handle:cancel()
Assert.is_true(pending.cancelled, "异步书签请求必须可取消")
pending.cb({ chapter_id = "11", fraction = 0.5 })
Assert.eq(calls, 0)
sync = true
handle = source:getProgressAsync(identity, function() calls = calls + 1 end)
handle:cancel()
Assert.is_true(pending.cancelled, "同步书签回调后取消目录请求")
pending.cb(toc)
Assert.eq(calls, 0)
handle = source:putProgressAsync(identity, { chapter_idx = 1 }, function() calls = calls + 1 end)
handle:cancel()
Assert.is_true(pending.cancelled, "异步目录请求必须可取消")
pending.cb(toc)
Assert.eq(calls, 0)
source.loadTocAsync = function(_self, _identity, cb)
cb(toc)
return { cancel = function() error("stale toc handle") end }
end
handle = source:putProgressAsync(identity, { chapter_idx = 1 }, function() calls = calls + 1 end)
handle:cancel()
Assert.is_true(pending.cancelled)
pending.cb(true)
Assert.eq(calls, 0)