| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- const test = require('node:test');
- const assert = require('node:assert/strict');
- const fs = require('node:fs');
- const source = fs.readFileSync('content/signup-page.js', 'utf8');
- function extractFunction(name) {
- const markers = [`async function ${name}(`, `function ${name}(`];
- const start = markers
- .map((marker) => source.indexOf(marker))
- .find((index) => index >= 0);
- if (start < 0) {
- throw new Error(`missing function ${name}`);
- }
- let parenDepth = 0;
- let signatureEnded = false;
- let braceStart = -1;
- for (let index = start; index < source.length; index += 1) {
- const char = source[index];
- if (char === '(') {
- parenDepth += 1;
- } else if (char === ')') {
- parenDepth -= 1;
- if (parenDepth === 0) {
- signatureEnded = true;
- }
- } else if (char === '{' && signatureEnded) {
- braceStart = index;
- break;
- }
- }
- if (braceStart < 0) {
- throw new Error(`missing body for function ${name}`);
- }
- let depth = 0;
- let end = braceStart;
- for (; end < source.length; end += 1) {
- const char = source[end];
- if (char === '{') depth += 1;
- if (char === '}') {
- depth -= 1;
- if (depth === 0) {
- end += 1;
- break;
- }
- }
- }
- return source.slice(start, end);
- }
- test('step 7 timeout recoverable result no longer clicks retry before asking background to rerun', async () => {
- const api = new Function(`
- const logs = [];
- let recoverCalls = 0;
- const location = {
- href: 'https://auth.openai.com/log-in',
- };
- function inspectLoginAuthState() {
- return {
- state: 'login_timeout_error_page',
- url: location.href,
- };
- }
- async function recoverCurrentAuthRetryPage() {
- recoverCalls += 1;
- return { recovered: true };
- }
- function log(message, level = 'info') {
- logs.push({ message, level });
- }
- ${extractFunction('createStep6RecoverableResult')}
- ${extractFunction('normalizeStep6Snapshot')}
- ${extractFunction('createStep6LoginTimeoutRecoverableResult')}
- return {
- async run() {
- return createStep6LoginTimeoutRecoverableResult(
- 'login_timeout_error_page',
- { state: 'login_timeout_error_page', url: location.href },
- '当前页面处于登录超时报错页。'
- );
- },
- snapshot() {
- return { logs, recoverCalls };
- },
- };
- `)();
- const result = await api.run();
- const snapshot = api.snapshot();
- assert.equal(snapshot.recoverCalls, 0);
- assert.equal(result.step6Outcome, 'recoverable');
- assert.equal(result.reason, 'login_timeout_error_page');
- assert.equal(result.state, 'login_timeout_error_page');
- assert.equal(result.message, '当前页面处于登录超时报错页。');
- });
|