import { chromium } from "playwright"; import postgres from "postgres"; const sql = postgres(process.env.DATABASE_URL || "postgresql://postgres:postgres@127.0.0.1:15433/ai_directory", { prepare: false }); const count = async () => Number((await sql`SELECT COUNT(*) FROM vote WHERE tool_id='tool_claude'`)[0].count); const browser = await chromium.launch(); const context = await browser.newContext(); const page = await context.newPage(); // 登录 await page.goto("http://localhost:3001/login", { waitUntil: "domcontentloaded" }); await page.fill('input[type="email"]', "bob@demo.dev"); await page.fill('input[type="password"]', "password123"); await page.click('button[type="submit"]'); await page.waitForTimeout(2500); // 记录 → 点击 → 对比 const before = await count(); await page.goto("http://localhost:3001/tools/claude", { waitUntil: "domcontentloaded" }); await page.waitForTimeout(1500); const btn = page.locator("button", { hasText: /Upvote|Upvoted/ }).first(); await btn.click(); await page.waitForTimeout(2500); const after = await count(); const label = await btn.textContent(); console.log(`DB votes before=${before} after=${after} | button="${(label ?? "").trim()}"`); console.log(before !== after ? "TOGGLE PASS" : "TOGGLE FAIL"); // 再点一次恢复 await btn.click(); await page.waitForTimeout(2500); const restored = await count(); console.log(`再次点击后 DB=${restored} (${restored === before ? "恢复原状 PASS" : "FAIL"})`); await browser.close(); await sql.end();