From 7e0a01f14f8a5bc4fcc870f1678ceede5d819315 Mon Sep 17 00:00:00 2001 From: BaskDuan <133692311@qq.com> Date: Thu, 2 Apr 2026 23:40:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20npm=20run=20test:s?= =?UTF-8?q?tealth=20=E8=AF=8A=E6=96=AD=20challenge=20=E8=80=97=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 (1M context) --- package.json | 1 + stealth-proxy/test-challenge.js | 52 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 stealth-proxy/test-challenge.js diff --git a/package.json b/package.json index 5d99323..e8414b2 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/stealth-proxy/test-challenge.js b/stealth-proxy/test-challenge.js new file mode 100644 index 0000000..fce9566 --- /dev/null +++ b/stealth-proxy/test-challenge.js @@ -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); +})();