app_auto_all/fanqie_auto/tests/flow-order.test.js
2026-10-21 15:14:07 +08:00

1422 lines
76 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const vm = require('node:vm');
const path = require('node:path');
const source = fs.readFileSync(path.join(__dirname, '../fanqie-daily.auto.js'), 'utf8');
function load(state, page = []) {
const context = vm.createContext({console, Date, JSON, Math, Error, isFinite});
vm.runInContext(source.slice(0, source.lastIndexOf('\ntry {\n runDaily();')), context);
const calls = [];
context.files = {write() {}, exists: () => true, read: () => JSON.stringify(state)};
context.engines = {myEngine: () => ({id: 1, getSource: () => '/sdcard/脚本/fanqie-daily.auto.js'}), all: () => []};
context.events = {observeToast() {}, onToast() {}, removeListener() {}};
context.writeRunLog = () => {};
context.localOcrEnabled = true;
context.snapshot = () => page;
context.publicationEnd = () => false;
context.isPublicationReader = () => false;
context.findFlipButton = () => null;
context.runStep = name => {calls.push(name); return {ok: true};};
context.runNextPublication = () => calls.push('阅读与领奖');
return {context, calls};
}
for (const state of [{pendingClaim: true}, {pendingClaim: false, nextTask: 'readingChallenge'}]) {
test('历史状态不跳过福利中心的前置任务:' + JSON.stringify(state), () => {
const {context, calls} = load(state);
context.runDaily();
assert.deepEqual(calls.slice(2), ['当前页面及启动签到弹窗', '进入赚钱页面', '签到', '吃饭补贴', '连续5天当日奖励', '翻卡赢金币', '阅读与领奖']);
});
}
test('当前确实在阅读正文时仍能恢复,不强行退出重跑签到', () => {
const {context, calls} = load({pendingClaim: false});
context.isPublicationReader = () => true;
context.runDaily();
assert.deepEqual(calls.slice(2), ['阅读与领奖']);
});
test('领取饭点补贴不会污染出版物待领奖状态', () => {
const {context} = load({pendingClaim: false}, [popupItem('饭点领金币补贴', 200, 200), popupItem('领早餐补贴', 300, 1000)]);
context.device = {width: 1080, height: 2400};
let written = 0, tapped = 0;
context.savePublicationClaimState = () => written++;
context.tap = () => tapped++;
context.handleVideos = () => {};
assert.equal(context.finishMealPage(), true);
assert.equal(tapped, 1);
assert.equal(written, 0);
});
for (const label of ['105金币', '|领午饭补贴105金币', '领取300金币', '看视频领1,000金币', '|领午饭补贴303金市']) {
test('饭点页金额按钮可领取,不套弹窗500金币门槛:' + label, () => {
const button = popupItem(label, 300, 1000);
const page = [popupItem('饭点领金币补贴', 200, 200), button];
const {context} = load({}, page);
context.device = {width: 1080, height: 2400};
const actions = [];
context.tap = item => actions.push(item);
context.handleVideos = pattern => {
assert.equal(pattern.test('饭点领金币补贴'), true);
actions.push('通用规则');
};
assert.equal(context.finishMealPage(), true);
assert.deepEqual(actions, [button, '通用规则']);
});
}
test('金额规则限定饭点主补贴区,不领取余额、已领取说明或连续奖励数字', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const page = [popupItem('饭点领金币补贴', 200, 200),
popupItem('已领取105金币', 300, 600), popupItem('余额1000金币', 300, 650),
popupItem('连续5天', 200, 1300), popupItem('44金币', 300, 1500)];
assert.equal(context.findMealCoinClaim(page), null);
assert.equal(context.findMealCoinClaim([popupItem('105金币', 300, 1000)]), null);
});
test('同文案金额按钮领取后继续检查,直到消失才查连续奖励并退出补贴页', () => {
const heading = popupItem('饭点领金币补贴', 200, 200);
const button = popupItem('105金币', 300, 1000);
const {context} = load({});
context.device = {width: 1080, height: 2400};
let remaining = 2, inPopup = false;
const actions = [];
context.snapshot = () => {
assert.equal(inPopup, false, '不能越过前景弹窗扫描下一任务');
return remaining ? [heading, button] : [heading];
};
context.tap = item => {
assert.equal(item, button);
assert.ok(remaining > 0);
remaining--;
inPopup = true;
context.actionSerial++;
actions.push('领取');
};
context.handleVideos = () => {actions.push('通用规则'); inPopup = false;};
context.finishStreak = () => {
assert.equal(remaining, 0);
actions.push('查连续奖励');
};
context.back = () => {actions.push('返回'); return true;};
context.waitFor = () => true;
context.sleep = () => {};
context.runMealPageLoop();
assert.deepEqual(actions, ['领取', '通用规则', '领取', '通用规则', '查连续奖励', '查连续奖励', '返回']);
assert.equal(context.mealPageDone, true);
});
test('现场活动繁忙Toast阻止本轮重复点击,继续连续奖励并退出,下轮重新尝试', () => {
const button = popupItem('领午饭补贴303金币', 300, 1000);
const {context} = load({}, [popupItem('饭点领金币补贴', 200, 200), button]);
context.device = {width: 1080, height: 2400};
let tapped = 0, streaks = 0;
context.tap = () => {
tapped++;
context.actionSerial++;
context.receiveMealToast({getPackageName: () => 'com.dragon.read', getText: () => '活动繁忙,请稍后再试'});
};
context.handleVideos = () => {};
context.finishStreak = () => streaks++;
context.back = () => true;
context.waitFor = () => true;
context.sleep = () => {};
context.runMealPageLoop();
assert.equal(tapped, 3);
assert.equal(streaks, 2);
assert.equal(context.findMealCoinClaim([popupItem('饭点领金币补贴', 200, 200), popupItem('|领午饭补贴303金市', 300, 1000)]), null);
context.runMealPageLoop();
assert.equal(tapped, 6, '每轮最多3次繁忙尝试,跳过只在本轮生效');
});
test('Toast监听在runStep外注册和移除,不让补贴任务线程保持事件循环', () => {
const {context} = load({});
const order = [];
context.events.observeToast = () => order.push('监听');
context.events.onToast = fn => {assert.equal(fn, context.receiveMealToast);};
context.runStep = (name, action) => {
assert.equal(name, '吃饭补贴');
assert.equal(action, context.mealStep);
order.push('任务');
return {ok: true};
};
context.events.removeListener = (event, fn) => {
assert.equal(event, 'toast');
assert.equal(fn, context.receiveMealToast);
order.push('移除');
};
assert.equal(context.runMealStep().ok, true);
assert.deepEqual(order, ['监听', '任务', '移除']);
});
test('其他应用相同Toast不影响饭点按钮,真实连续颌标题可识别', () => {
const {context} = load({});
context.receiveMealToast({getPackageName: () => 'other.app', getText: () => '活动繁忙,请稍后再试'});
assert.equal(context.mealBusyFeedback, null);
assert.equal(context.STREAK_SECTION.test('连续颌吃饭补贴第2天'), true);
});
test('补贴退出挽留弹窗领991金币吃饭补贴仍优先执行通用规则', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const button = {...popupItem('领991金币吃饭补贴', 261, 1770, 819, 1846), darkButton: true};
const close = popupItem('关闭', 468, 1976, 612, 2120);
const page = [popupItem('吃饭还能赚金币', 288, 473, 792, 552),
popupItem('991', 443, 1516, 556, 1594), popupItem('金币', 556, 1541, 638, 1583), button, close];
assert.equal(context.needsCommonHandling(page), true);
assert.equal(context.singleButtonPopupDecision(page).button, button);
button.darkButton = false;
assert.equal(context.singleButtonPopupDecision(page).button, close);
});
test('连续奖励也遇活动繁忙时本轮跳过,继续扫描而非抛错', () => {
const pending = popupItem('待领取', 492, 2286, 589, 2318);
const {context} = load({}, [popupItem('饭点领金币补贴', 200, 200),
popupItem('连续颌吃饭补贴第2天', 111, 1885, 473, 1920), pending]);
context.device = {width: 1080, height: 2400};
context.swipe = () => {throw Error('连续奖励可见时不应滚动');};
let taps = 0;
context.tap = () => {
taps++;
context.receiveMealToast({getPackageName: () => 'com.dragon.read', getText: () => '活动繁忙,请稍后再试'});
};
context.handleVideos = () => {};
context.sleep = () => {};
context.finishStreak();
context.finishStreak();
assert.equal(taps, 3);
});
test('现场签到高金额含OCR竖线时仍选3928而非1928', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const item = (text, left, top, right, bottom) => ({text, rect: {left, top, right, bottom}});
const high = item('|领3928金币', 602, 1467, 852, 1508);
const page = [item('今日签到领1928金币', 113, 549, 518, 590),
item('领1928金币', 168, 1467, 409, 1508), high,
item('看视頻奖励', 808, 1420, 940, 1445)];
assert.equal(context.findHigherCoinClaim(page), high);
});
test('广告切换后下一帧出现关闭按钮时继续通用处理,不全局抛错', () => {
const {context} = load({});
const pages = [[{text: '第一广告'}], [{text: '直播关闭'}], []];
context.readPage = () => pages.shift();
context.needsCommonHandling = page => page.length > 0;
let handled = 0;
context.handleVideos = () => handled++;
// 恢复真正snapshot,load里的snapshot仅用于调度隔离。
vm.runInContext(source.slice(source.indexOf('function snapshot() {'), source.indexOf('\n// 小号X')), context);
assert.equal(context.snapshot().length, 0);
assert.equal(handled, 2);
});
test('直播退出提示优先选择暂不使用,不点击立即开启', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const item = text => ({text, rect: {left: 100, top: 1100, right: 500, bottom: 1200}});
const dismiss = item('暂不使用');
assert.equal(context.findPlaybackPopupDismiss([item('悬浮窗播放功能上线啦'), dismiss, item('立即开启')]), dismiss);
assert.equal(context.needsCommonHandling([item('悬浮窗播放功能上线啦'), dismiss]), true);
assert.equal(context.findPlaybackPopupDismiss([dismiss]), null);
});
function popupItem(text, left, top, right = left + 200, bottom = top + 40) {
return {text, rect: {left, top, right, bottom}};
}
test('真实视頻误识别的前景追加奖励弹窗优先坚持退出,不反复点击背景X', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
assert.equal(context.compact('再看一个視頻颜外狭得'), '再看一个视频颜外狭得');
const exit = popupItem('坚持退出', 458, 1424, 618, 1462);
const page = [popupItem(context.compact('再看一个视頻颜外狭得'), 252, 922, 816, 976),
popupItem('最高(', 297, 1057, 438, 1131), popupItem('800', 410, 1010, 668, 1122),
popupItem('金币', 684, 1072, 776, 1118), popupItem('领取奖励', 446, 1273, 631, 1317), exit,
popupItem('领取成功×', 804, 151, 994, 184), popupItem('广告)', 75, 147, 254, 184),
popupItem('20秒后可领奖励', 850, 150)];
assert.equal(context.offerAmount(page).amount, null);
let exited = false;
context.snapshot = () => exited ? [] : page;
context.tap = item => {assert.equal(item, exit); exited = true;};
context.handleVideos(/./);
assert.equal(exited, true);
});
test('追加奖励标题完全漏识别时,领取奖励与坚持退出组合仍选择退出', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const exit = popupItem('|坚持退出', 458, 1424, 618, 1462);
const page = [popupItem('领取奖励', 446, 1273, 631, 1317), exit, popupItem('领取成功×', 804, 151, 994, 184)];
assert.equal(context.offerAmount(page).amount, null);
let exited = false;
context.snapshot = () => exited ? [] : page;
context.tap = item => {assert.equal(item, exit); exited = true;};
context.handleVideos(/./);
assert.equal(exited, true);
assert.equal(context.offerAmount([page[0]]), null, '普通领取按钮不能单独冒充挽留弹窗');
});
test('直播退出高于倒计时、金币和翻卡,确认退出并拒绝悬浮窗后继续', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const room = [popupItem('58万本场点赞', 180, 205), popupItem('60秒后可领奖励', 850, 150),
popupItem('恭喜获得', 400, 800), popupItem('领2136金币', 700, 1500),
popupItem('领2868金币', 200, 1500)];
const exit = popupItem('退出直播间', 300, 1400);
const dismiss = popupItem('暂不使用', 300, 1400);
const pages = [room, [popupItem('是否退出直播间', 300, 900), exit, popupItem('继续观看', 600, 1400)],
[popupItem('退出直播间后也能继续观看', 300, 900), dismiss, popupItem('立即开启', 600, 1400)], []];
assert.equal(context.needsCommonHandling(room), true);
const actions = [];
context.snapshot = () => pages.shift() || [];
context.sleep = () => {};
context.back = () => {actions.push('返回'); return true;};
context.tap = button => actions.push(button.text);
context.handleVideos(/./);
assert.deepEqual(actions, ['返回', '退出直播间', '暂不使用']);
});
test('更多直播或底部聊天工具可识别直播,普通任务文案不触发退出', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
for (const page of [[popupItem('更多直播', 793, 298)], [popupItem('1万在线观众', 816, 167)],
[popupItem('说点什么', 86, 2234), popupItem('礼物', 734, 2234)]]) {
assert.equal(context.liveExitAction(page).back, true);
}
assert.equal(context.liveExitAction([popupItem('看直播赚金币', 100, 1500), popupItem('去观看', 800, 1500)]), null);
});
test('原生控件已确认直播时不调用截屏OCR,避免识别超时阻挡退出', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
context.foregroundPackage = () => context.CONFIG.packageName;
const rect = {left: 180, top: 205, right: 377, bottom: 244};
const node = {bounds: () => rect, text: () => '58万本场点赞', visibleToUser: () => true};
context.textMatches = () => ({find: () => ({size: () => 1, get: () => node})});
context.descMatches = () => ({find: () => ({size: () => 0})});
context.captureScreen = () => {throw Error('直播页面不应截屏');};
context.images = {copy: () => {throw Error('直播页面不应复制截图');}};
assert.equal(context.readSnapshot()[0].text, '58万本场点赞');
});
test('广告关闭复查时进入直播,优先返回,不点击直播右上关闭或等倒计时', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const close = popupItem('关闭', 970, 150, 1030, 195);
const live = [popupItem('更多直播', 793, 298), close, popupItem('60秒后可领奖励', 850, 150)];
const pages = [[close], live, live, []];
context.snapshot = () => pages.shift() || [];
context.sleep = () => {};
let backs = 0;
context.back = () => {backs++; return true;};
context.tap = () => {throw Error('直播应优先返回');};
context.handleVideos(/./);
assert.equal(backs, 1);
});
test('直播连续返回未响应时有界退出,不无限发送返回键', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
context.snapshot = () => [popupItem('更多直播', 793, 298)];
context.sleep = () => {};
let backs = 0;
context.back = () => {backs++; return true;};
assert.throws(() => context.handleVideos(/./), /连续六次退出直播/);
assert.equal(backs, 6);
});
const liveRetentionPage = JSON.parse(fs.readFileSync(path.join(__dirname,
'../debug/2026-10-21/oppo-monitor79-live-exit-popup.json'), 'utf8'));
test('OPPO真实直播挽留层点击坚持退出,背景点赞和高金币不触发重复返回', () => {
const context = loadReader(liveRetentionPage);
context.device.height = 2374;
const decision = context.liveExitAction(liveRetentionPage);
assert.equal(decision.button.text, '坚持退出');
assert.equal(decision.back, undefined);
let exited = false;
context.snapshot = () => exited ? [] : liveRetentionPage;
context.back = () => {throw Error('前景有退出按钮时不应按返回');};
context.tap = item => {assert.equal(item.text, '坚持退出'); exited = true;};
context.handleVideos(/./);
assert.equal(exited, true);
assert.equal(context.liveReturnPending, false);
});
test('已执行直播返回后背景标志漏识别,仍点坚持退出,退出后清除状态', () => {
const context = loadReader([]);
const exit = popupItem('|坚持退出', 301, 1426);
let phase = 0;
context.snapshot = () => phase === 0 ? [popupItem('本场点赞10.9万', 145, 391)] :
phase === 1 ? [exit, popupItem('再看44秒可领奖励', 324, 926)] : [];
context.back = () => {assert.equal(phase, 0); phase++; return true;};
context.tap = item => {assert.equal(item, exit); assert.equal(phase, 1); phase++;};
context.handleVideos(/./);
assert.equal(phase, 2);
assert.equal(context.liveReturnPending, false);
assert.equal(context.liveExitAction([exit, popupItem('继续观看', 446, 1272)]), null,
'普通广告没有直播证据时仍交给原金币规则');
});
test('原生直播按返回后允许本地OCR识别挽留按钮,不再一直跳过前景识别', () => {
const context = loadReader([]);
context.liveReturnPending = true;
const rect = {left: 145, top: 391, right: 290, bottom: 411};
const node = {bounds: () => rect, text: () => '本场点赞10.9万', visibleToUser: () => true};
context.textMatches = () => ({find: () => ({size: () => 1, get: () => node})});
context.descMatches = () => ({find: () => ({size: () => 0})});
let captures = 0, recycled = 0;
context.captureScreen = () => {captures++; return {};};
context.images = {copy: () => ({recycle: () => recycled++})};
context.$ocr = {detect: () => [
{text: '坚持退出', bounds: {left: 301, top: 1426, right: 461, bottom: 1464}},
{text: 'X', bounds: {left: 970, top: 150, right: 1000, bottom: 180}}
]};
const page = context.readSnapshot();
assert.equal(context.liveExitAction(page).button.text, '坚持退出');
assert.equal(captures, 1);
assert.equal(recycled, 1);
});
test('翻字按钮不能阻止无倒计时的右上角关闭', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const flip = popupItem('立即翻开十位数', 400, 1400);
const close = popupItem('关闭', 970, 150, 1030, 195);
const page = [popupItem('继续翻卡领更多金币', 300, 800), flip, close];
context.findFlipButton = items => items.includes(flip) ? flip : null;
context.flipEntryOpened = true;
assert.equal(context.needsCommonHandling(page), true);
let closed = false;
context.snapshot = () => closed ? [] : page;
context.sleep = () => {};
context.tap = item => {assert.equal(item, close); closed = true;};
context.handleVideos(/./);
assert.equal(closed, true);
});
test('有翻字和右上角关闭时仍先等真实倒计时结束', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const flip = popupItem('立即翻开十位数', 400, 1400);
const close = popupItem('X', 970, 150, 995, 180);
const timer = popupItem('1秒后关闭', 850, 150);
context.findFlipButton = items => items.includes(flip) ? flip : null;
context.flipEntryOpened = true;
const pages = [[flip, close, timer], [flip, close], [flip, close], []];
let waited = 0, taps = 0;
context.snapshot = () => pages.shift() || [];
context.sleep = () => waited++;
context.tap = item => {assert.equal(item, close); assert.ok(waited >= 1); taps++;};
context.handleVideos(/./);
assert.equal(taps, 1);
});
test('广告恭喜获得文案没有领取按钮时,等待倒计时后执行右上关闭', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const heading = popupItem('恭喜获得', 417, 1142, 664, 1203);
const coins = popupItem('5182金币', 389, 1521, 682, 1585);
const timer = popupItem('广告1)39秒|27秒后可领奖励×', 89, 130, 976, 197);
const close = popupItem('领取成功×', 850, 130, 976, 197);
const pages = [[heading, coins, timer], [heading, coins, close], [heading, coins, close], []];
let waited = 0, taps = 0;
context.snapshot = () => pages.shift() || [];
context.sleep = () => waited++;
context.tap = item => {assert.match(item.text, /^关闭/); assert.ok(waited >= 1); taps++;};
context.handleVideos(/./);
assert.equal(taps, 1);
});
test('只有奖励标题和金额,没有可执行控件时不反复进入通用规则', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const page = [popupItem('恭喜获得', 417, 1142), popupItem('5182金币', 389, 1521)];
assert.equal(context.needsCommonHandling(page), false);
context.snapshot = () => page;
context.tap = () => {throw Error('没有领取或关闭控件不能盲点');};
context.handleVideos(/./);
});
test('没有右上角关闭时仍保留翻卡的中央操作弹窗', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const flip = popupItem('立即翻开十位数', 400, 1400);
const page = [popupItem('继续翻卡领更多金币', 300, 800), flip, popupItem('X', 520, 1750, 560)];
context.findFlipButton = () => flip;
context.flipEntryOpened = true;
context.snapshot = () => page;
context.tap = () => {throw Error('中央翻卡弹窗不应关闭');};
context.handleVideos(/./);
});
test('前景121元现金邀请弹窗无金币领取按钮,忽略背景金币任务并关闭', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const close = popupItem('X', 526, 1724, 554, 1751);
const page = [popupItem('送你现金红包', 410, 765, 670, 807),
popupItem('121元', 414, 902, 670, 1005), popupItem('邀靖好友立得', 418, 1444, 662, 1481), close,
popupItem('天天领金币最高471', 92, 1673, 613, 1721), popupItem('去领取', 841, 1727, 938, 1758),
popupItem('立即参与', 826, 2152, 953, 2183)];
assert.equal(context.findEmptyRewardPopupClose(page), close);
assert.equal(context.needsCommonHandling(page), true);
let closed = false;
context.snapshot = () => closed ? [] : page;
context.sleep = () => {};
context.tap = item => {assert.equal(item, close); closed = true;};
context.handleVideos(/./);
assert.equal(closed, true);
});
test('普通页面上的X和现金金额不冒充现金邀请弹窗', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
assert.equal(context.findEmptyRewardPopupClose([popupItem('121元', 414, 902), popupItem('X', 526, 1724)]), null);
});
test('正常结束前再扫描一轮,处理晚出现的通用弹窗', () => {
const {context} = load({});
context.foregroundPackage = () => context.CONFIG.packageName;
let scans = 0, pauses = 0;
context.snapshot = () => {scans++;};
context.sleep = () => {pauses++;};
context.drainCommonBeforeExit();
assert.equal(scans, 2);
assert.equal(pauses, 1);
});
function loadReader(page) {
const {context} = load({}, page);
vm.runInContext(source.slice(source.indexOf('function isPublicationReader('), source.indexOf('function readingPageKey(')), context);
context.device = {width: 1080, height: 2400};
context.foregroundPackage = () => context.CONFIG.packageName;
let now = 100000;
context.Date = class extends Date { static now() { return now; } };
context.sleep = ms => {now += ms;};
return context;
}
const readerPage = current => [popupItem('正文第' + current + '页', 100, 600), popupItem(current + '/3', 86, 2300)];
test('真实阅读页倒计时交给翻页流程,广告倒计时仍执行通用等待', () => {
const timer = popupItem('30秒后可领奖励', 850, 150);
const close = popupItem('X', 970, 150, 995, 180);
const context = loadReader(readerPage(1));
const page = [...readerPage(1), timer, close];
assert.equal(context.needsCommonHandling(page), false);
assert.equal(context.needsCommonHandling([...page, popupItem('广告1)', 60, 150)]), true);
const claim = popupItem('领2136金币', 600, 1400);
assert.equal(context.needsCommonHandling([...page, popupItem('签到奖励', 300, 700), claim,
popupItem('领100金币', 200, 1400)]), true, '前景领取弹窗仍优先');
});
test('左滑到书末仍有倒计时则持续右滑,到首页即结束,即使倒计时仍存在', () => {
const timer = popupItem('30秒后可领奖励', 850, 150);
const context = loadReader(readerPage(1));
let current = 1, saved = false;
const directions = [];
context.snapshot = () => [...readerPage(current), timer];
context.swipe = (x1, y1, x2) => {
assert.equal(saved, false);
const direction = x2 > x1 ? 1 : -1;
directions.push(direction);
current += direction > 0 ? -1 : 1;
return true;
};
context.savePublicationClaimState = (pending, evidence) => {
assert.equal(current, 1);
assert.equal(pending, true);
assert.equal(evidence, '3/3');
saved = true;
};
assert.equal(context.runPublicationPages(), true);
assert.deepEqual(directions, [-1, -1, 1, 1]);
assert.equal(saved, true);
});
test('本轮左滑到书末且无倒计时则确认2秒,不额外右滑', () => {
const context = loadReader(readerPage(2));
const start = context.Date.now();
let current = 2, turns = 0;
context.snapshot = () => readerPage(current);
context.swipe = (x1, y1, x2) => {assert.ok(x2 < x1); current = 3; turns++; return true;};
let saved = false;
context.savePublicationClaimState = () => {
assert.ok(context.Date.now() - start >= 2000 + context.CONFIG.readingPagePauseMs);
saved = true;
};
assert.equal(context.runPublicationPages(), true);
assert.equal(turns, 1);
assert.equal(saved, true);
});
test('书末倒计时短暂漏识别后重新出现,清空2秒窗口并继续右滑', () => {
const timer = popupItem('30秒后可领奖励', 850, 150);
const page = (n, timed) => [popupItem('正文', 100, 600), popupItem(n + '/10', 86, 2300), ...(timed ? [timer] : [])];
const context = loadReader(page(10, true));
const pages = [page(10, true), page(9, false), page(8, true), page(7, false), page(6, false), page(5, false)];
let turns = 0;
context.snapshot = () => pages.shift() || page(5, false);
context.swipe = (x1, y1, x2) => {assert.ok(x2 > x1); turns++; return true;};
const initial = context.snapshot();
context.finishPublicationCountdown(initial, context.Date.now() + 60000);
assert.equal(turns, 5);
});
test('书末右滑失败不能记录待领奖完成状态', () => {
const timer = popupItem('30秒后可领奖励', 850, 150);
const context = loadReader([...readerPage(3), timer]);
context.swipe = () => false;
context.savePublicationClaimState = () => {throw Error('失败不应保存完读');};
assert.throws(() => context.runPublicationPages(), /右滑执行失败/);
});
test('左滑两次页码不变且有倒计时则右滑到首页,不冒充全书读完', () => {
const timer = popupItem('01:58得1353金市>', 701, 176);
const context = loadReader(readerPage(2));
let current = 2;
const directions = [], logs = [];
context.snapshot = () => [...readerPage(current), timer];
context.swipe = (x1, y1, x2) => {directions.push(x2 > x1 ? '右' : '左'); if (x2 > x1) current--; return true;};
context.savePublicationClaimState = () => {throw Error('卡页不应保存全书完状态');};
context.writeRunLog = value => logs.push(value);
assert.equal(context.runPublicationPages(), true);
assert.deepEqual(directions, ['左', '左', '右']);
assert.equal(current, 1);
assert.ok(logs.some(value => value.startsWith('READ STALLED:')));
assert.equal(logs.some(value => value.startsWith('READ FINISHED:')), false);
});
test('阅读倒计时支持分秒合框与OPPO原生逐字控件,排除底部时钟和无效秒数', () => {
const context = loadReader([]);
for (const label of ['01:58', '1:02', '01:58得1353金市>', '00:09得1353金币']) {
const item = popupItem(label, 701, 176);
assert.equal(context.publicationCountdown([item]), item);
}
const split = ['0', '1', ':', '5', '8'].map((text, i) =>
({...popupItem(text, 712 + i * 18, 174, 730 + i * 18, 209), node: {}}));
assert.equal(context.publicationCountdown(split).text, '01:58');
assert.equal(context.publicationCountdown([popupItem('17:23', 806, 2290)]), null);
assert.equal(context.publicationCountdown([popupItem('01:88', 701, 176)]), null);
});
test('无页码正文不变也触发右滑,倒计时消失连续2秒后退出', () => {
const timer = popupItem('30秒后可领奖励', 850, 150);
const context = loadReader([]);
let rightTurns = 0, noTimerAt = null;
const directions = [];
const body = [popupItem('相同正文', 100, 600), popupItem('目录', 100, 2200), popupItem('设置', 600, 2200)];
context.snapshot = () => {
if (rightTurns && noTimerAt === null) noTimerAt = context.Date.now();
return [...body, ...(rightTurns ? [] : [timer])];
};
context.swipe = (x1, y1, x2) => {
directions.push(x2 > x1 ? '右' : '左');
if (x2 > x1) rightTurns++;
return true;
};
context.savePublicationClaimState = () => {throw Error('没有书末证据不保存完读');};
assert.equal(context.runPublicationPages(), true);
assert.deepEqual(directions, ['左', '左', '右', '右', '右']);
assert.ok(context.Date.now() - noTimerAt >= context.CONFIG.readingCountdownClearMs);
});
test('左滑连续无变化但没有倒计时仍继续左滑,直到明确书末', () => {
const context = loadReader(readerPage(2));
let lefts = 0;
context.snapshot = () => readerPage(lefts >= 3 ? 3 : 2);
context.swipe = (x1, y1, x2) => {assert.ok(x2 < x1); lefts++; return true;};
context.savePublicationClaimState = () => {};
assert.equal(context.runPublicationPages(), true);
assert.equal(lefts, 3);
});
test('一次左滑未推进后恢复翻页时不提前切右滑', () => {
const timer = popupItem('30秒后可领奖励', 850, 150);
const context = loadReader(readerPage(1));
let lefts = 0;
context.snapshot = () => [...readerPage(Math.max(1, Math.min(3, lefts))), ...(lefts < 3 ? [timer] : [])];
context.swipe = (x1, y1, x2) => {assert.ok(x2 < x1); lefts++; return true;};
context.savePublicationClaimState = () => {};
assert.equal(context.runPublicationPages(), true);
assert.equal(lefts, 3);
});
test('历史待领奖状态不能跳过当前阅读现场的书末倒计时处理', () => {
const {context} = load({pendingClaim: true});
vm.runInContext(source.slice(source.indexOf('function runNextPublication('), source.indexOf('function runDaily()')), context);
const calls = [];
context.runStep = name => {calls.push(name); return {ok: false};};
context.runNextPublication(true);
assert.deepEqual(calls, ['读出版物赚金币:持续左滑阅读']);
});
test('补贴常驻最高可领说明不当作追加奖励弹窗', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const page = [popupItem('饭点领金而补贴', 100, 150), popupItem('看视频最高可领50金币', 291, 1340)];
assert.equal(context.offerAmount(page), null);
assert.equal(context.needsCommonHandling(page), false);
});
const cappedTreasurePage = JSON.parse(fs.readFileSync(path.join(__dirname,
'../debug/2026-10-21/oppo-stopped-popup.json'), 'utf8'));
const flipRewardPage = JSON.parse(fs.readFileSync(path.join(__dirname,
'../debug/2026-10-21/oppo-monitor80-flip-reward.json'), 'utf8'));
test('真实翻卡奖励层优先关闭,不被背景明日签到和其他任务立即领取抢占', () => {
const context = loadReader(flipRewardPage);
context.device.height = 2374;
context.flipEntryOpened = true;
assert.equal(context.rewardReceiptHeading(flipRewardPage).text, '|恭喜获得翻卡奖励');
assert.equal(context.needsCommonHandling(flipRewardPage), true);
const close = context.findRewardReceiptClose(flipRewardPage);
assert.equal(close.text, 'X');
let closed = false;
context.snapshot = () => closed ? [] : flipRewardPage;
context.tap = item => {assert.equal(item, close); closed = true;};
context.handleVideos(/./);
assert.equal(context.flipSettlementDone, true);
assert.equal(context.flipActionDone, true);
});
test('翻卡奖励标题即使低于屏幕中部也不能当翻卡操作按钮', () => {
const context = loadReader([]);
vm.runInContext(source.slice(source.indexOf('function isFlipButton('), source.indexOf('function flipCardStep(')), context);
context.flipEntryOpened = true;
const page = [popupItem('|恭喜获得翻卡奖励', 324, 1100), popupItem('翻卡奖励已到账', 324, 1200)];
assert.equal(context.findFlipButton(page), null);
assert.equal(context.flipPopupHasAction(page), false);
assert.equal(context.findFlipButton([popupItem('立即翻开十位数', 350, 1400)]).text, '立即翻开十位数');
});
test('翻卡奖励层缺关闭时不搜索背景、不标记翻卡已处理', () => {
const context = loadReader([]);
context.device.height = 2374;
const missing = flipRewardPage.filter(item => item.text !== 'X');
context.readPage = () => missing;
context.tap = () => {throw Error('不应点击背景领取');};
restoreSnapshot(context);
assert.throws(() => context.snapshot(), /翻卡奖励弹窗仍在前台.*不搜索背景任务/);
assert.equal(context.flipSettlementDone, false);
});
test('OPPO翻卡现场带竖线的标题不抢占真正的翻百位卡按钮', () => {
const page = JSON.parse(fs.readFileSync(path.join(__dirname,
'../debug/2026-10-21/oppo-monitor82-flip-title.json'), 'utf8'));
const context = loadReader(page);
context.device.height = 2374;
vm.runInContext(source.slice(source.indexOf('function isFlipButton('), source.indexOf('function flipCardStep(')), context);
assert.equal(context.findFlipButton(page).text, '看1个视频翻百位卡');
for (const text of ['|已翻出个位数,继续翻卡赚更多金币', '|继续翻卡领更多金币', '|翻卡赢金币最高99999', '看继续翻卡领更多金币']) {
assert.equal(context.findFlipButton([popupItem(text, 92, 1100)]), null);
}
});
test('翻卡奖励确认关闭失败不标记为处理完成', () => {
const context = loadReader(flipRewardPage);
context.device.height = 2374;
context.tap = () => {throw Error('点击失败');};
assert.throws(() => context.handleVideos(/./), /点击失败/);
assert.equal(context.flipSettlementDone, false);
});
test('已进入翻卡入口但没有操作按钮时继续阅读,真实错误仍保留现场', () => {
for (const ok of [true, false]) {
const {context} = load({});
context.runStep = name => {
if (name === '翻卡赢金币') {context.flipEntryOpened = true; return {ok, skipped: true};}
return {ok: true};
};
let next = 0;
context.runNextPublication = () => next++;
context.toastLog = () => {};
context.runDaily();
assert.equal(next, ok ? 1 : 0);
}
});
test('翻卡奖励弹窗被启动通用处理关闭后直接继续出版物,不重跑签到翻卡', () => {
const {context, calls} = load({});
context.snapshot = () => {context.flipSettlementDone = true; context.flipActionDone = true; return [];};
context.runDaily();
assert.deepEqual(calls.slice(2), ['阅读与领奖']);
});
test('翻卡按钮连续两次缺失直接跳过,不再额外重复三轮空检查', () => {
const context = loadReader([]);
context.flipEntryOpened = true;
let waits = 0;
context.waitFor = () => {waits++; return null;};
assert.throws(() => context.flipCardStep(), /没有翻卡按钮/);
assert.equal(waits, 2);
});
test('OPPO真实最高再领150宝箱弹窗优先关闭,不等待冷却、不点击背景去阅读', () => {
const context = loadReader(cappedTreasurePage);
context.device.height = 2374;
assert.equal(context.needsCommonHandling(cappedTreasurePage), true);
const close = context.cappedRewardPopup(cappedTreasurePage).close;
assert.equal(close.text, 'X');
let closed = false;
context.snapshot = () => closed ? [] : cappedTreasurePage;
context.tap = item => {assert.equal(item, close); closed = true;};
context.handleVideos(/./);
assert.equal(closed, true);
});
function restoreSnapshot(context) {
vm.runInContext(source.slice(source.indexOf('function snapshot()'), source.indexOf('// 小号X')), context);
}
test('宝箱最高再领文案和金额拆开、关闭晚一帧出现时,清理前不返回背景页面', () => {
const context = loadReader([]);
context.device.height = 2374;
const split = cappedTreasurePage.filter(item => item.text !== '看视频最高再领150金币');
const missing = split.filter(item => item.text !== 'X');
assert.ok(context.cappedRewardPopup(missing));
assert.equal(context.needsCommonHandling(missing), true);
let reads = 0, closed = false;
context.readPage = () => closed ? [] : ++reads < 3 ? missing : split;
context.tap = item => {assert.equal(item.text, 'X'); closed = true;};
restoreSnapshot(context);
assert.equal(context.snapshot().length, 0);
assert.equal(closed, true);
assert.ok(reads >= 3);
});
test('已确认宝箱前景但一直没有关闭控件时有界报错,不把背景当作任务缺失', () => {
const missing = cappedTreasurePage.filter(item => item.text !== 'X');
const context = loadReader(missing);
context.device.height = 2374;
context.readPage = () => missing;
context.tap = () => {throw Error('不应点任何背景按钮');};
restoreSnapshot(context);
assert.throws(() => context.snapshot(), /不搜索背景任务/);
});
test('最高再领即使标高金额仍按上限关闭;无前景证据的普通文字不触发', () => {
const context = loadReader([]);
const heading = popupItem('看视频最高再领8000金币', 288, 1344, 793, 1397);
assert.equal(context.cappedRewardPopup([heading]), null);
const close = popupItem('X', 531, 1649, 554, 1675);
const page = [heading, close];
let closed = false;
context.snapshot = () => closed ? [] : page;
context.tap = item => {assert.equal(item, close); closed = true;};
context.handleVideos(/./);
assert.equal(closed, true);
});
test('宝箱最高再领关闭漏识别时仅在手机本地裁剪其下方区域找X', () => {
const context = loadReader([]);
context.device.height = 2374;
const page = cappedTreasurePage.filter(item => item.text !== 'X');
let recycled = 0;
context.images = {
clip: () => ({recycle: () => recycled++}), resize: () => ({recycle: () => recycled++})
};
context.$ocr = {detect: () => [{text: 'X', bounds: {left: 460, top: 756, right: 530, bottom: 834}}]};
context.readReceiptCloseRegion({}, page);
assert.equal(context.cappedRewardPopup(page).close.text, 'X');
assert.equal(recycled, 2);
});
test('OPPO宝箱X与背景文字合框时只点击最后关闭字形,不点击整行背景', () => {
const page = JSON.parse(fs.readFileSync(path.join(__dirname,
'../debug/2026-10-21/oppo-monitor81-treasure-close-miss.json'), 'utf8'));
const context = loadReader(page);
context.device.height = 2374;
const close = context.cappedRewardPopup(page).close;
assert.ok(close.rect.left > 510);
assert.equal(close.rect.right, 554);
assert.equal(close.rect.top, 1632);
let closed = false;
context.snapshot = () => closed ? [] : page;
context.tap = item => {assert.deepEqual(item.rect, close.rect); closed = true;};
context.handleVideos(/./);
assert.equal(closed, true);
});
test('宝箱合框关闭只接受前景标题下方中央的末尾X', () => {
const context = loadReader([]);
const heading = popupItem('看视频最高再领150金币', 288, 1344, 793, 1397);
for (const item of [popupItem('背景X', 840, 1632, 1000, 1677),
popupItem('背景X', 400, 500, 554, 550), popupItem('X背景', 400, 1632, 554, 1677)]) {
assert.equal(context.cappedRewardPopup([heading, item]), null);
}
});
test('宝箱同一关闭按钮三次未响应后保留现场,不无限点击', () => {
const context = loadReader(cappedTreasurePage);
context.device.height = 2374;
let clicks = 0;
context.tap = () => clicks++;
assert.throws(() => context.handleVideos(/./), /同一关闭按钮连续三次未响应/);
assert.equal(clicks, 3);
});
test('补贴领取确认层下方小X通过本机局部OCR找回并关闭', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const page = [popupItem('饭点领金而补贴', 100, 150), popupItem('恭喜获得', 475, 794, 603, 826),
popupItem('看视频最高可领50金币', 291, 1340, 785, 1384)];
let recycled = 0;
context.images = {
clip: (frame, x, y, w, h) => {assert.deepEqual([x, y, w, h], [378, 1384, 324, 824]); return {recycle: () => recycled++};},
resize: () => ({recycle: () => recycled++})
};
context.$ocr = {detect: () => [{text: '×', bounds: {left: 420, top: 150, right: 510, bottom: 240}}]};
context.readReceiptCloseRegion({}, page);
const close = context.findRewardReceiptClose(page);
assert.equal(close.text, 'X');
assert.equal(close.rect.left, 518);
assert.equal(close.rect.top, 1434);
assert.equal(recycled, 2);
let closed = false;
context.snapshot = () => closed ? [] : page;
context.tap = item => {assert.equal(item, close); closed = true;};
context.handleVideos(/./);
assert.equal(closed, true);
});
test('阅读先收起工具栏再左滑,直到末页才记录完读', () => {
const toolbar = [...readerPage(1), popupItem('上一章', 86, 1974), popupItem('目录', 182, 2276)];
const context = loadReader(toolbar);
let page = toolbar, turns = 0, pressed = 0, finished = false;
context.snapshot = () => page;
context.press = () => {pressed++; page = readerPage(1); return true;};
context.swipe = () => {
assert.equal(context.publicationToolbarVisible(page), false);
page = readerPage(++turns + 1);
return true;
};
context.savePublicationClaimState = pending => {finished = pending;};
assert.equal(context.runPublicationPages(), true);
assert.equal(pressed, 1);
assert.equal(turns, 2);
assert.equal(finished, true);
});
test('五次卡页后仍继续左滑,页码不变时OCR噪声不算进度', () => {
const context = loadReader(readerPage(1));
let turns = 0, finished = false;
const swipeYs = [];
context.snapshot = () => readerPage(turns < 6 ? 1 : turns < 7 ? 2 : 3);
context.swipe = (x1, y) => {
assert.ok(++turns <= 7, '应在真实末页结束');
swipeYs.push(y);
return true;
};
context.savePublicationClaimState = () => {finished = true;};
context.runPublicationPages();
assert.equal(turns, 7);
assert.notEqual(swipeYs[5], swipeYs[0], '卡页后更换左滑位置');
assert.equal(finished, true);
});
test('阅读未完返回福利中心后重新点对应去阅读,继续到末页', () => {
const context = loadReader(readerPage(1));
let page = readerPage(1), turns = 0, reentered = 0;
context.snapshot = () => page;
context.searchPublicationEntry = () => popupItem('去阅读', 841, 403);
context.tap = () => {reentered++; page = readerPage(2);};
context.swipe = () => {page = ++turns === 1 ? [popupItem('福利中心', 72, 129)] : readerPage(3); return true;};
context.savePublicationClaimState = () => {};
context.runPublicationPages();
assert.equal(reentered, 1);
assert.equal(turns, 2);
});
test('繁忙提示在通用处理期间迟到时也执行有限重试,提示消失后不禁用按钮', () => {
const button = popupItem('领午饭补贴303金币', 300, 1000);
const {context} = load({}, [popupItem('饭点领金币补贴', 200, 200), button]);
context.device = {width: 1080, height: 2400};
context.sleep = () => {};
let taps = 0;
context.tap = () => {taps++; context.mealBusyFeedback = null;};
context.handleVideos = () => {
if (taps === 1) context.receiveMealToast({getPackageName: () => context.CONFIG.packageName, getText: () => '活动繁忙,请稍后再试'});
};
context.claimMealButton(button);
assert.equal(taps, 2);
assert.equal(context.mealClaimAvailable(button), true);
});
for (const [left, right, expected] of [[100, 400, 100], [499, 500, 500], [600, 900, 900], [500, 500, 500]]) {
test(`双按钮金币 ${left}/${right} 选${expected}`, () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const page = [popupItem('签到奖励', 200, 600), popupItem(`领${left}金币`, 160, 1200), popupItem(`领${right}金币`, 600, 1200)];
assert.equal(Number(context.findHigherCoinClaim(page).text.replace(/\D/g, '')), expected);
});
}
for (const [amount, dark, take] of [[499, true, false], [500, true, true], [501, false, false]]) {
test(`单按钮正文${amount}金币 深色=${dark} 领取=${take}`, () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const button = {...popupItem('开心收下', 400, 1400), darkButton: dark};
const close = popupItem('X', 520, 1750, 560);
const page = [popupItem('恭喜获得', 300, 700), popupItem(`${amount}金币`, 300, 900), button, close];
const decision = context.singleButtonPopupDecision(page);
assert.equal(decision.take, take);
assert.equal(decision.button, take ? button : close);
});
}
test('正文只有奖励上限不能当确定金币,关闭单按钮弹窗', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const close = popupItem('X', 520, 1750, 560);
const page = [popupItem('恭喜获得', 300, 700), popupItem('最高1000金币', 300, 900),
{...popupItem('立即领取', 400, 1400), darkButton: true}, close];
assert.equal(context.singleButtonPopupDecision(page).button, close);
});
test('深色判定取当前手机像素:深背景通过,白背景不通过', () => {
const {context} = load({});
let level = 40;
context.images = {pixel: () => level};
context.colors = {red: c => c, green: c => c, blue: c => c};
assert.equal(context.isDarkButton({}, popupItem('领取奖励', 400, 1400)), true);
level = 255;
assert.equal(context.isDarkButton({}, popupItem('领取奖励', 400, 1400)), false);
});
test('广告过渡帧仍属于通用处理,不能把后续任务全部判缺失', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const ad = popupItem('广告|1)', 70, 150);
assert.equal(context.isAdvertisementPage([ad]), true);
assert.equal(context.needsCommonHandling([ad]), true);
assert.equal(context.isAdvertisementPage([popupItem('广告', 70, 1800)]), false);
});
test('奖励弹窗两按钮都不足500时优先小额,不走旧的直接关闭分支', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const small = popupItem('直接领取100金币', 160, 1400);
const page = [popupItem('恭喜获得', 300, 700), small, popupItem('看视频得400金币', 600, 1400), popupItem('X', 520, 1750, 560)];
let tapped;
context.snapshot = () => tapped ? [] : page;
context.tap = item => {tapped = item;};
context.handleVideos(/./);
assert.equal(tapped, small);
});
test('无恭喜标题的单按钮弹窗也依据正文金币与深色判断', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const button = {...popupItem('领更多金币', 400, 1400), darkButton: true};
const close = popupItem('X', 520, 1750, 560);
const page = [popupItem('500金币', 300, 900), button, close];
assert.equal(context.singleButtonPopupDecision(page).button, button);
button.darkButton = false;
assert.equal(context.singleButtonPopupDecision(page).button, close);
});
test('四段广告同位置X不会累计为连续三次未响应', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
context.sleep = () => {};
const timer = popupItem('1秒后关闭', 850, 150);
const close = popupItem('X', 970, 150, 995, 180);
const pages = [];
for (let i = 0; i < 4; i++) pages.push([timer], [close], [close]);
pages.push([]);
context.snapshot = () => pages.shift() || [];
let taps = 0;
context.tap = () => taps++;
context.handleVideos(/./);
assert.equal(taps, 4);
});
test('同一个X持续存在且无页面进展时仍在三次点击后保护退出', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
context.sleep = () => {};
const close = popupItem('X', 970, 150, 995, 180);
context.snapshot = () => [close];
let taps = 0;
context.tap = () => taps++;
assert.throws(() => context.handleVideos(/./), /同一关闭按钮连续三次未响应/);
assert.equal(taps, 3);
});
test('赚钱页签到无需日常福利标题,按钮带竖线仍匹配', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const sign = popupItem('|去签到', 854, 237, 949, 267);
const page = [popupItem('签到领金币', 80, 206, 293, 246), sign,
popupItem('去领取', 854, 845, 951, 875)];
context.snapshot = () => page;
context.swipe = () => {throw Error('入口已可见,不应滚动');};
assert.equal(context.searchEarningTask(/^[||]?(?:签到|每日签到)(?:领金币.*)?$/, /^[||]?(?:去签到|立即签到|签到)$/, '签到'), sign);
});
test('vivo领吃饭补贴991直接匹配本行去领取,不需要日常福利', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const meal = popupItem('去领取', 854, 845, 951, 875);
const page = [popupItem('领吃饭补贴991', 79, 811, 438, 857), meal,
popupItem('预约领金币', 80, 1008), popupItem('去领取', 854, 1037)];
context.snapshot = () => page;
context.swipe = () => {throw Error('入口已可见,不应滚动');};
assert.equal(context.findMealEntry(), meal);
});
for (const caption of ['7天签到必得18万金币', '今日签到领100金币', '签到奖励']) {
test('单按钮签到弹窗'+caption+'直接点击唯一深色按钮', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const button = {...popupItem('立即领取', 400, 1400), darkButton: true};
const page = [popupItem(caption, 250, 600), button, popupItem('X', 520, 1750, 560)];
assert.equal(context.singleButtonPopupDecision(page).button, button);
assert.equal(context.singleButtonPopupDecision(page).signIn, true);
});
}
test('普通签到任务行不当作签到弹窗,也不能越过双按钮金额规则', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
assert.equal(context.findSingleSignPopupClaim([popupItem('签到领金币', 80, 600), {...popupItem('去签到', 850, 600), darkButton: true}]), null);
const page = [popupItem('今日签到', 250, 600), {...popupItem('领100金币', 160, 1400), darkButton: true},
{...popupItem('领400金币', 600, 1400), darkButton: true}, popupItem('X', 520, 1750, 560)];
assert.equal(context.findSingleSignPopupClaim(page), null);
assert.equal(context.findHigherCoinClaim(page).text, '领100金币');
});
test('vivo弹窗无障碍closebutton明确按关闭识别', () => {
const {context} = load({});
assert.equal(context.compact('closebutton'), '关闭');
assert.equal(context.compact('close_button'), '关闭');
});
test('真实32216金币听读弹窗排除听读操作,直接关闭', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const button = {...popupItem('立即听读', 426, 1505, 654, 1573), darkButton: true};
const page = [popupItem('连续7天听读赚金币', 266, 883, 814, 973),
popupItem('每天听读15分钟赚大额金币奖励', 188, 1002, 893, 1061),
popupItem('32216', 224, 1129, 640, 1345), popupItem('金币', 654, 1179, 754, 1251),
popupItem('common-info-modalbackground', 36, 858, 1044, 1650), button,
popupItem('关闭', 468, 1848, 612, 1992)];
assert.equal(context.isPopupAction(button), false);
assert.equal(context.findListeningPopupClose(page), page[page.length - 1]);
assert.equal(context.singleButtonPopupDecision(page), null);
});
test('补贴标签可见但右侧按钮漏识别时直接点标签,不滚动', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const label = popupItem('领吃饭补贴991', 79, 811, 438, 857);
context.snapshot = () => [label];
context.swipe = () => {throw Error('标签已存在,不应继续滚动');};
assert.equal(context.findMealEntry(), label);
});
test('中央立即参与提示无领取入口时关闭遮挡层,不进入参与任务', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const close = popupItem('X', 515, 1731, 563, 1779);
const page = [popupItem('立即参与', 455, 1529, 624, 1570), close];
assert.equal(context.findEmptyRewardPopupClose(page), close);
});
test('vivo独立签到页没有X也领取;无障碍大按钮与OCR文字框合并为一个', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const native = {...popupItem('立即领取', 183, 1839, 896, 1972), darkButton: false};
const ocr = {...popupItem('立即领取', 450, 1882, 630, 1925), darkButton: true};
const page = [popupItem('已签0/7今日签到,额外奖励立即到账+7125', 82, 1674, 997, 1789),
popupItem('活动时间:10月20日-11月18日', 262, 356, 817, 406), popupItem('back', 64, 194, 86, 230), native, ocr];
assert.equal(context.findSingleSignPopupClaim(page), native);
assert.equal(context.singleButtonPopupDecision(page).signIn, true);
});
test('首次奖励弹窗明确看视频领1198金币按金额规则处理,不漏过通用规则', () => {
const {context} = load({});
context.device = {width: 1080, height: 2400};
const button = popupItem('看视频领1198金币', 277, 1770, 803, 1846);
const page = [popupItem('首次完成额外送金币', 0, 447, 1080, 598), button,
popupItem('关闭', 468, 1976, 612, 2120)];
assert.equal(context.offerAmount(page).amount, 1198);
assert.equal(context.needsCommonHandling(page), true);
});
function loadPublicationFlow(state, targets = []) {
const {context} = load(state);
vm.runInContext(source.slice(source.indexOf('function runNextPublication('), source.indexOf('function runDaily()')), context);
context.device = {width: 1080, height: 2374};
context.snapshot = () => [popupItem('福利中心', 60, 142), popupItem('赚钱', 486, 2224)];
const calls = [];
context.runStep = (name, action) => {
try { return {ok: true, value: action()}; }
catch (error) { return {ok: !!error.noMatch, skipped: true}; }
};
context.searchPublicationTask = () => {calls.push('复查'); return targets.shift() || null;};
context.publicationReadingStep = () => {calls.push('阅读');};
context.publicationClaimStep = button => {calls.push(button.text); return {};};
context.runNextReadingChallenge = () => {calls.push('挑战赛'); return {ok: true};};
context.sleep = () => {};
return {context, calls};
}
const publicationRead = () => ({action: 'read', button: popupItem('去阅读', 842, 1433)});
const publicationClaim = () => ({action: 'claim', button: popupItem('去领取', 842, 1433)});
const publicationUnavailable = () => ({action: 'none', label: popupItem('读出版物赚金币', 93, 1400)});
test('旧待领奖状态不限制当前按钮,连续阅读后领取,再复查两次无匹配才进入下一任务', () => {
const {context, calls} = loadPublicationFlow({pendingClaim: true},
[publicationRead(), publicationRead(), publicationClaim(), publicationUnavailable(), publicationUnavailable()]);
context.runNextPublication();
assert.deepEqual(calls, ['复查', '阅读', '复查', '阅读', '复查', '去领取', '复查', '复查', '挑战赛']);
});
test('没有待领奖记录也执行去领取,领取后仍有同按钮继续,不直接去下一任务', () => {
const {context, calls} = loadPublicationFlow({pendingClaim: false},
[publicationClaim(), publicationClaim(), publicationRead(), publicationUnavailable(), publicationUnavailable()]);
context.runNextPublication();
assert.deepEqual(calls.filter(value => value !== '复查'), ['去领取', '去领取', '阅读', '挑战赛']);
});
test('读完回页仍有去阅读就一直执行,不按本书已读完或重复次数退出', () => {
const {context, calls} = loadPublicationFlow({pendingClaim: true},
[...Array.from({length: 5}, publicationRead), publicationUnavailable(), publicationUnavailable()]);
context.runNextPublication();
assert.equal(calls.filter(value => value === '阅读').length, 5);
assert.equal(calls.at(-1), '挑战赛');
});
test('出版物标签连续两次不存在才退出,保留未确认的待领奖记录', () => {
const {context, calls} = loadPublicationFlow({pendingClaim: true}, [null, null]);
context.files.write = () => {throw Error('标签消失不等于奖励到账,不能清状态');};
context.runNextPublication();
assert.deepEqual(calls, ['复查', '复查', '挑战赛']);
});
test('一次没有匹配后去阅读重现,重置无匹配计数并继续执行', () => {
const {context, calls} = loadPublicationFlow({pendingClaim: false},
[publicationUnavailable(), publicationRead(), publicationUnavailable(), publicationUnavailable()]);
context.runNextPublication();
assert.deepEqual(calls, ['复查', '复查', '阅读', '复查', '复查', '挑战赛']);
});
test('当前阅读现场先恢复,返回仍有去阅读时再次执行', () => {
const {context, calls} = loadPublicationFlow({pendingClaim: true},
[publicationRead(), publicationUnavailable(), publicationUnavailable()]);
context.runNextPublication(true);
assert.deepEqual(calls, ['阅读', '复查', '阅读', '复查', '复查', '挑战赛']);
});
test('阅读真实异常保留现场,不冒充无匹配或完读', () => {
const {context, calls} = loadPublicationFlow({pendingClaim: false}, [publicationRead()]);
context.publicationReadingStep = () => {calls.push('阅读异常'); throw Error('翻页失败');};
context.runNextPublication();
assert.deepEqual(calls, ['复查', '阅读异常']);
});
test('真实出版物去阅读可点击,上方其他任务的立即领取不可误领', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const reading = popupItem('去阅读', 842, 1433, 937, 1464);
const page = [popupItem('读出版物赚金币', 93, 1400, 392, 1446),
popupItem('继续阅读《王阳明心学》,攒满领奖', 92, 1464, 616, 1496),
popupItem('立即领取', 826, 1222, 955, 1253), reading];
assert.equal(context.findPublicationClaim(page), null);
assert.equal(context.findPublicationEntry(page), reading);
});
test('出版物同任务行优先去领取,兼容OCR长标题,不点击其他任务去领取', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const claim = popupItem('去领取', 842, 1433, 937, 1464);
const page = [popupItem('去领取', 842, 1222, 937, 1253), popupItem('读出版物賺全币最高5805', 93, 1400, 950, 1446),
popupItem('去阅读', 842, 1433, 937, 1464), claim];
assert.equal(context.findPublicationEntry(page), claim);
assert.equal(context.findPublicationClaim(page), claim);
});
const earningTreasurePage = amount => [popupItem('福利中心', 60, 142), popupItem('赚钱', 486, 2224),
popupItem('点击颌' + amount, 810, 2071, 989, 2102)];
for (const [amount, take] of [[999, false], [1000, false], [1001, true], [2205, true]]) {
test(`右下宝箱金币${amount} 严格大于1000才领取=${take}`, () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const page = earningTreasurePage(amount);
assert.equal(!!context.findEarningTreasureClaim(page), take);
assert.equal(context.needsCommonHandling(page), take);
});
}
test('宝箱规则只匹配赚钱页右下角,不误点任务列表、普通金币或其他页面', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
assert.equal(context.findEarningTreasureClaim(earningTreasurePage(2205).slice(1)), null);
assert.equal(context.findEarningTreasureClaim(earningTreasurePage(2205).slice(0, 1)), null);
const nav = earningTreasurePage(2205).slice(0, 2);
assert.equal(context.findEarningTreasureClaim([...nav, popupItem('领2205', 300, 2071)]), null);
assert.equal(context.findEarningTreasureClaim([...nav, popupItem('去领取', 810, 2071)]), null);
assert.equal(context.findEarningTreasureClaim([...nav, popupItem('2205金币', 810, 2071)]), null);
});
test('宝箱金币与下方领金币分开显示时绑定同一宝箱,不使用远处余额', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const button = popupItem('领金币', 810, 2071, 989, 2102);
const page = [...earningTreasurePage(2205).slice(0, 2), popupItem('宝箱', 810, 1900),
popupItem('2205金币', 810, 1980), button];
assert.equal(context.findEarningTreasureClaim(page).button, button);
assert.equal(context.findEarningTreasureClaim(page.filter(item => item.text !== '宝箱')), null);
});
test('前景弹窗优先于背景宝箱,点宝箱后执行通用流程,同金额不连点阻塞', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const earning = earningTreasurePage(2205);
const close = popupItem('X', 526, 1724, 554, 1751);
const popup = [popupItem('送你现金红包', 410, 765), popupItem('121元', 414, 902),
popupItem('邀靖好友立得', 418, 1444), close];
const exit = popupItem('坚持退出', 458, 1424, 618, 1462);
let stage = 0;
const taps = [];
context.snapshot = () => stage === 0 ? [...earning, ...popup] : stage === 1 ? earning : stage === 2 ?
[popupItem('再看一个视频最高可领800金币', 252, 922, 816, 976), exit] : earning;
context.sleep = () => {};
context.tap = item => {taps.push(item.text); stage++;};
context.handleVideos(/./);
assert.deepEqual(taps, ['X', '点击颌2205', '坚持退出']);
assert.equal(context.findEarningTreasureClaim(earning), null);
assert.equal(context.needsCommonHandling(earning), false);
});
test('完整可见出版物行只有去阅读时直接选中,不滚动寻找其他任务立即领取', () => {
const {context} = load({pendingClaim: true, claimTapped: false});
context.device = {width: 1080, height: 2374};
const button = popupItem('去阅读', 842, 1433, 937, 1464);
const page = [popupItem('福利中心', 60, 142), popupItem('读出版物赚金币', 93, 1400, 392, 1446),
button, popupItem('立即领取', 826, 1222, 955, 1253)];
context.snapshot = () => page;
context.swipe = () => {throw Error('任务行完整可见,无需滚动');};
const target = context.searchPublicationTask();
assert.equal(target.action, 'read');
assert.equal(target.button, button);
});
test('现场己使出版物廉金币OCR仍绑定出版物任务入口', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const claim = popupItem('|去领取', 842, 1433, 937, 1464);
const page = [popupItem('己使出版物廉金币最高5805', 93, 1400, 678, 1446), claim];
assert.equal(context.findPublicationEntry(page), claim);
assert.equal(context.findPublicationClaim(page), claim);
});
test('出版物行在底部但按钮完整可见时直接阅读,不先滚动把标题滑出屏幕', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const button = popupItem('去阅读', 842, 2030, 937, 2061);
context.snapshot = () => [popupItem('福利中心', 60, 142),
popupItem('|读出版物賺金币', 93, 1996, 392, 2042), button];
context.swipe = () => {throw Error('完整可见按钮不应强制对齐');};
const target = context.searchPublicationTask();
assert.equal(target.button, button);
assert.equal(target.action, 'read');
});
test('出版物按钮被底部导航遮挡时小幅慢滑,重新识别当前按钮', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const heading = popupItem('福利中心', 60, 142);
let page = [heading, popupItem('读出版物赚金币', 93, 2180, 392, 2226)];
const button = popupItem('去阅读', 842, 1830, 937, 1861);
context.snapshot = () => page;
context.sleep = () => {};
let swipes = 0;
context.swipe = (x1, y1, x2, y2, ms) => {
assert.equal(x1, x2);
assert.ok(y1 - y2 < 300);
assert.equal(ms, 800);
swipes++;
page = [heading, popupItem('读出版物赚金币', 93, 1800, 392, 1846), button];
return true;
};
assert.equal(context.searchPublicationTask().button, button);
assert.equal(swipes, 1);
});
test('真实宝箱选204/选2204双金额弹窗优先2204,不被背景视频任务干扰', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const page = JSON.parse(fs.readFileSync(path.join(__dirname, '../debug/2026-10-20/oppo-monitor72-treasure-popup.json'), 'utf8'));
page.forEach(item => {item.text = context.compact(item.text);});
assert.equal(context.findHigherCoinClaim(page).text, '选2204金币');
let tapped;
context.snapshot = () => tapped ? [] : page;
context.tap = item => {tapped = item;};
context.handleVideos(/./);
assert.equal(tapped.text, '选2204金币');
});
test('宝箱双按钮都不足500仍选较小,原生关闭按钮文字归一', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const page = [popupItem('请选择宝箱奖励', 195, 726), popupItem('选204金币', 193, 1404), popupItem('选404金币', 646, 1405)];
assert.equal(context.findHigherCoinClaim(page).text, '选204金币');
assert.equal(context.compact('关闭按钮'), '关闭');
});
test('去领取按钮在没有旧状态文件时也先点击再执行通用规则,不捏造读完', () => {
const {context} = load({pendingClaim: false});
context.device = {width: 1080, height: 2374};
context.files.exists = () => false;
const actions = [];
const button = popupItem('去领取', 842, 1433, 937, 1464);
context.tap = item => {assert.equal(item, button); actions.push('点击');};
context.savePublicationClaimState = (pending, evidence, tapped) => {
assert.equal(pending, true);
assert.equal(tapped, true);
assert.doesNotMatch(evidence, /全书完/);
actions.push('记录实际点击');
};
context.handleVideos = () => actions.push('通用');
context.snapshot = () => [];
context.publicationClaimStep(button);
assert.deepEqual(actions, ['点击', '记录实际点击', '通用']);
});
test('出版物标签存在但按钮不符合时返回无动作;其他任务的按钮不能续出版物循环', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const page = [popupItem('福利中心', 60, 142), popupItem('读出版物赚金币', 93, 1400, 392, 1446),
popupItem('已完成', 842, 1433, 937, 1464), popupItem('去阅读', 842, 1813, 937, 1847)];
assert.equal(context.publicationTaskTarget(page).action, 'none');
assert.equal(context.publicationTaskTarget(page).button, null);
});
test('进入阅读前按钮变成去领取时交回循环,不点击后原地等待正文', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
context.searchPublicationEntry = () => popupItem('去领取', 842, 1433);
context.tap = () => {throw Error('该按钮应交给领取分支');};
assert.throws(() => context.enterPublicationReader([popupItem('福利中心', 60, 142)]), /交回循环执行领取/);
});
test('进入即全书完且无倒计时也先右滑一次,再开始2秒判断,不记成本轮重新完读', () => {
const ending = [popupItem('全书完', 400, 1200)];
const context = loadReader(ending);
let page = ending, rights = 0, saved = false, firstRightAt;
const logs = [];
context.snapshot = () => page;
context.writeRunLog = value => logs.push(value);
context.swipe = (x1, y1, x2) => {
assert.ok(x2 > x1);
assert.equal(rights, 0);
assert.equal(saved, false);
firstRightAt = context.Date.now();
rights++;
page = readerPage(2);
return true;
};
context.countdown = () => {assert.equal(rights, 1, '必须先右滑,后判断倒计时'); return null;};
context.savePublicationClaimState = () => {
assert.ok(context.Date.now() - firstRightAt >= context.CONFIG.readingPagePauseMs + 2000);
saved = true;
};
assert.equal(context.runPublicationPages(), true);
assert.equal(rights, 1);
assert.equal(saved, true);
assert.equal(logs.some(value => value.startsWith('READ FINISHED:')), false);
assert.equal(logs.some(value => value.startsWith('READ END HANDLED:')), true);
});
test('进入即书末的首次右滑失败时不开始后续倒计时判断,不保存完成状态', () => {
const context = loadReader([popupItem('全书完', 400, 1200)]);
context.swipe = () => false;
context.countdown = () => {throw Error('右滑失败前不能执行后续判断');};
context.savePublicationClaimState = () => {throw Error('失败不应保存完成');};
assert.throws(() => context.runPublicationPages(), /右滑执行失败/);
});
test('入口仅识别全书完而无页码或工具栏,也确认已进入阅读页', () => {
const ending = [popupItem('全书完', 400, 1200)];
const context = loadReader(ending);
const button = popupItem('去阅读', 842, 1433);
let taps = 0;
context.searchPublicationEntry = () => button;
context.tap = item => {assert.equal(item, button); taps++;};
assert.equal(context.isPublicationReader(ending), false);
assert.equal(context.enterPublicationReader([popupItem('福利中心', 60, 142)]), ending);
assert.equal(taps, 1);
});
function navigationPage(selected, welfare = false) {
const tab = (text, left) => ({...popupItem(text, left, 2230, left + 100, 2290), node: {selected: () => selected === text}});
return [...(welfare ? [popupItem('福利中心', 60, 142)] : []), tab('书城', 79), tab('赚钱', 486)];
}
test('阅读结束先返回带导航页面,再点击首页并确认,最后点底部赚钱', () => {
const context = loadReader(readerPage(2));
let page = readerPage(2);
const actions = [];
context.snapshot = () => page;
context.back = () => {actions.push('返回'); page = navigationPage('赚钱', true); return true;};
context.tap = item => {actions.push(item.text); page = navigationPage(item.text, item.text === '赚钱');};
context.returnHomeAndOpenEarning();
assert.deepEqual(actions, ['返回', '书城', '赚钱']);
});
test('首页点击后推荐页面打断,缺赚钱导航时继续返回,恢复首页再点击赚钱', () => {
const context = loadReader(readerPage(2));
let page = navigationPage('赚钱', true);
const actions = [];
context.snapshot = () => page;
context.tap = item => {
actions.push(item.text);
page = item.text === '书城' ? readerPage(1) : navigationPage('赚钱', true);
};
context.back = () => {actions.push('返回'); page = navigationPage('书城'); return true;};
context.returnHomeAndOpenEarning();
assert.deepEqual(actions, ['书城', '返回', '赚钱']);
});
test('已经在首页时直接点击底部赚钱,等待福利中心加载后才确认成功', () => {
const context = loadReader(readerPage(2));
let page = navigationPage('书城'), tapped = 0, loading = 0;
context.snapshot = () => {
if (tapped && ++loading >= 3) page = navigationPage('赚钱', true);
return page;
};
context.tap = item => {assert.equal(item.text, '赚钱'); tapped++; page = navigationPage('赚钱');};
context.back = () => {throw Error('加载中不应随意返回');};
context.returnHomeAndOpenEarning();
assert.equal(tapped, 1);
assert.ok(loading >= 3);
});
test('点击首页仍停在赚钱页时重新确认首页,不把点击成功当作首页已到达', () => {
const context = loadReader(readerPage(2));
let page = navigationPage('赚钱', true), homeTaps = 0;
const actions = [];
context.snapshot = () => page;
context.tap = item => {
actions.push(item.text);
if (item.text === '书城') {if (++homeTaps >= 2) page = navigationPage('书城');}
else page = navigationPage('赚钱', true);
};
context.returnHomeAndOpenEarning();
assert.deepEqual(actions, ['书城', '书城', '赚钱']);
});
test('返回按钮失败或应用切走时保留现场,不能记录回到赚钱页', () => {
const context = loadReader(readerPage(2));
context.back = () => false;
assert.throws(() => context.returnHomeAndOpenEarning(), /返回键执行失败/);
context.foregroundPackage = () => 'other.app';
assert.throws(() => context.returnHomeAndOpenEarning(), /已离开番茄/);
});
test('首页右侧真实原生Close Button优先于图片局部OCR的可疑X', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const native = {...popupItem(context.compact('Close Button'), 954, 1243, 1080, 1387), node: {}};
const falseX = popupItem('X', 987, 548, 994, 558);
const page = [...navigationPage('书城'), falseX, native];
assert.equal(context.findTopRightClose(page), native);
assert.equal(context.findTopRightClose([...page, popupItem('广告1)', 75, 147)]), falseX,
'广告页仍保留原先的顶部关闭规则');
});
test('首页书封的微小OCR X不当作关闭,正常大小X及原生关闭仍响应', () => {
const {context} = load({});
context.device = {width: 1080, height: 2374};
const tiny = popupItem('X', 987, 548, 994, 558);
assert.equal(context.findTopRightClose([...navigationPage('书城'), tiny]), null);
const normal = popupItem('X', 970, 530, 1002, 562);
assert.equal(context.findTopRightClose([...navigationPage('书城'), normal]), normal);
const native = {...tiny, node: {}};
assert.equal(context.findTopRightClose([...navigationPage('书城'), native]), native);
assert.equal(context.findTopRightClose([tiny]), tiny, '非主导航页保持既有关闭匹配');
});