2026-10-21 15:14:07 +08:00

60 lines
2.6 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 path = require('node:path');
const vm = require('node:vm');
const source = fs.readFileSync(path.join(__dirname, '../hongguo-daily.auto.js'), 'utf8');
function load() {
const c = vm.createContext({Date, Math, JSON, Error, isFinite});
vm.runInContext(source.slice(0, source.lastIndexOf('\ntry {\n var endMessage')), c);
c.device = {width: 1080, height: 2374};
c.writeRunLog = () => {};
return c;
}
function mealPage() {
return JSON.parse(fs.readFileSync(path.join(__dirname, '../debug/2026-10-21/oppo-hongguo11-meal-inspect.jsonl'), 'utf8').split('\n')[0]);
}
test('OPPO连续五帧补补贴误识别仍执行真实午饭领取,不判定为空页', () => {
const frames = fs.readFileSync(path.join(__dirname, '../debug/2026-10-21/oppo-hongguo11-meal-inspect.jsonl'), 'utf8').trim().split('\n').map(JSON.parse);
assert.equal(frames.length, 5);
for (const page of frames) {
const c = load();
const button = page.find(i => i.text === '领午饭补补贴90金币');
assert.ok(button);
assert.equal(c.findMealCoinClaim(page), button);
c.snapshot = () => page;
let claims = 0;
c.claimMealButton = target => {assert.equal(target, button); claims++; return true;};
assert.equal(c.finishMealPage(true), true);
assert.equal(claims, 1);
}
});
test('重复补字兼容保留正常按钮识别与已领取说明、区域约束', () => {
for (const text of ['领午饭补贴90金币', '领午饭补补贴90金币', '|领午饭补补贴90金市']) {
const c = load();
const page = mealPage();
const button = page.find(i => i.text === '领午饭补补贴90金币');
button.text = text;
assert.equal(c.findMealCoinClaim(page), button);
button.text = '已领取午饭补补贴90金币';
assert.equal(c.findMealCoinClaim(page), null);
button.text = text;
button.rect.top = 100; button.rect.bottom = 145;
assert.equal(c.findMealCoinClaim(page), null);
}
});
test('补贴繁忙去重兼容OCR重复补字变化,不能绕过有限重试', () => {
const c = load();
const page = mealPage();
const button = page.find(i => i.text === '领午饭补补贴90金币');
const key = c.mealClaimKey(button);
c.mealUnavailableClaims[key] = true;
assert.equal(c.findMealCoinClaim(page), null);
button.text = '领午饭补贴90金币';
assert.equal(c.mealClaimKey(button), key);
assert.equal(c.findMealCoinClaim(page), null);
});