mirror of
https://github.com/7836246/cursor2api.git
synced 2026-06-02 03:51:50 +08:00
feat: 添加 npm run test:stealth 诊断 challenge 耗时
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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"
|
||||
},
|
||||
|
||||
52
stealth-proxy/test-challenge.js
Normal file
52
stealth-proxy/test-challenge.js
Normal 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);
|
||||
})();
|
||||
Reference in New Issue
Block a user