feat: 添加 npm run test:stealth 诊断 challenge 耗时

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
BaskDuan
2026-04-02 23:40:23 +08:00
parent 848a265aec
commit 7e0a01f14f
2 changed files with 53 additions and 0 deletions

View File

@@ -19,6 +19,7 @@
"test:tool-fixer": "node test/unit-tool-fixer.mjs",
"test:openai-compat": "node test/unit-openai-compat.mjs",
"test:all": "node test/unit-tolerant-parse.mjs && node test/unit-tool-fixer.mjs && node test/unit-openai-compat.mjs && node test/unit-proxy-agent.mjs && node test/unit-image-paths.mjs && node test/unit-vision.mjs && node test/unit-openai-chat-input.mjs && node test/unit-openai-image-file.mjs && node test/unit-handler-truncation.mjs && node test/unit-openai-stream-truncation.mjs",
"test:stealth": "node stealth-proxy/test-challenge.js",
"test:e2e": "node test/e2e-chat.mjs",
"test:agentic": "node test/e2e-agentic.mjs"
},

View File

@@ -0,0 +1,52 @@
/**
* 测试 Vercel Challenge 耗时
* 用法: npm run test:stealth
*/
const CHALLENGE_URL = process.env.CHALLENGE_URL || 'https://cursor.com/cn/docs';
(async () => {
const { chromium } = require('playwright-extra');
const stealth = require('puppeteer-extra-plugin-stealth');
chromium.use(stealth());
const start = Date.now();
const elapsed = () => ((Date.now() - start) / 1000).toFixed(1) + 's';
console.log(`[Test] Launching browser...`);
const browser = await chromium.launch({
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],
});
const ctx = await browser.newContext({
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36',
});
const page = await ctx.newPage();
console.log(`[Test] [${elapsed()}] Navigating to ${CHALLENGE_URL}...`);
try {
await page.goto(CHALLENGE_URL, { waitUntil: 'domcontentloaded', timeout: 120000 });
console.log(`[Test] [${elapsed()}] Page loaded, waiting for _vcrcs cookie...`);
} catch (e) {
console.error(`[Test] [${elapsed()}] Page load failed: ${e.message}`);
await browser.close();
process.exit(1);
}
for (let i = 0; i < 60; i++) {
const cookies = await ctx.cookies();
const vcrcs = cookies.find(c => c.name === '_vcrcs');
if (vcrcs) {
console.log(`[Test] [${elapsed()}] ✅ Got _vcrcs cookie!`);
console.log(`[Test] Value: ${vcrcs.value.substring(0, 50)}...`);
await browser.close();
process.exit(0);
}
await new Promise(r => setTimeout(r, 2000));
}
console.error(`[Test] [${elapsed()}] ❌ Failed to get _vcrcs cookie after 120s`);
await browser.close();
process.exit(1);
})();