feat: 更新 Plus Return 确认逻辑,增加等待时间至 40 秒并添加测试用例

This commit is contained in:
QLHazyCoder
2026-04-26 17:19:29 +08:00
parent f577487670
commit e9c3a61e55
3 changed files with 56 additions and 4 deletions
-1
View File
@@ -7109,7 +7109,6 @@ const plusReturnConfirmExecutor = self.MultiPageBackgroundPlusReturnConfirm?.cre
isTabAlive,
setState,
sleepWithStop,
waitForTabCompleteUntilStopped,
waitForTabUrlMatchUntilStopped,
});
const step10Executor = self.MultiPageBackgroundStep10?.createStep10Executor({
+3 -3
View File
@@ -3,6 +3,7 @@
})(typeof self !== 'undefined' ? self : globalThis, function createBackgroundPlusReturnConfirmModule() {
const PAYPAL_SOURCE = 'paypal-flow';
const PLUS_CHECKOUT_SOURCE = 'plus-checkout';
const PLUS_RETURN_SETTLE_WAIT_MS = 40000;
function createPlusReturnConfirmExecutor(deps = {}) {
const {
@@ -12,7 +13,6 @@
isTabAlive,
setState,
sleepWithStop,
waitForTabCompleteUntilStopped,
waitForTabUrlMatchUntilStopped,
} = deps;
@@ -41,8 +41,8 @@
const tabId = await resolveReturnTabId(state);
await addLog('步骤 9:正在等待 PayPal 授权后回跳到 ChatGPT / OpenAI 页面...', 'info');
const tab = await waitForTabUrlMatchUntilStopped(tabId, isReturnUrl);
await waitForTabCompleteUntilStopped(tabId);
await sleepWithStop(1000);
await addLog('步骤 9:已检测到订阅回跳页面,固定等待 40 秒让页面完成加载。', 'info');
await sleepWithStop(PLUS_RETURN_SETTLE_WAIT_MS);
await setState({
plusCheckoutTabId: tabId,
+53
View File
@@ -0,0 +1,53 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const source = fs.readFileSync('background/steps/plus-return-confirm.js', 'utf8');
const globalScope = {};
const api = new Function('self', `${source}; return self.MultiPageBackgroundPlusReturnConfirm;`)(globalScope);
test('Plus return confirm waits a fixed 40 seconds after return URL is detected', async () => {
const events = [];
const executor = api.createPlusReturnConfirmExecutor({
addLog: async (message, level = 'info') => {
events.push({ type: 'log', message, level });
},
completeStepFromBackground: async (step, payload) => {
events.push({ type: 'complete', step, payload });
},
getTabId: async (source) => (source === 'paypal-flow' ? 77 : null),
isTabAlive: async (source) => source === 'paypal-flow',
setState: async (payload) => {
events.push({ type: 'set-state', payload });
},
sleepWithStop: async (ms) => {
events.push({ type: 'sleep', ms });
},
waitForTabUrlMatchUntilStopped: async (tabId, matcher) => {
const url = 'https://chatgpt.com/backend-api/payments/success';
assert.equal(tabId, 77);
assert.equal(matcher(url), true);
events.push({ type: 'url-match', tabId, url });
return { id: tabId, url };
},
});
await executor.executePlusReturnConfirm({});
assert.deepEqual(
events.find((event) => event.type === 'sleep'),
{ type: 'sleep', ms: 40000 }
);
assert.equal(
events.some((event) => event.type === 'log' && /固定等待 40 秒/.test(event.message)),
true
);
assert.deepEqual(
events.find((event) => event.type === 'complete'),
{
type: 'complete',
step: 9,
payload: { plusReturnUrl: 'https://chatgpt.com/backend-api/payments/success' },
}
);
});