import fs from "node:fs"; import path from "node:path"; function assert(condition: unknown, message: string): asserts condition { if (!condition) throw new Error(message); } export function runTests() { const projectRoot = process.cwd(); const accountDir = path.join(projectRoot, "components", "account"); const accountCenterSource = fs.readFileSync( path.join(accountDir, "AccountCenter.tsx"), "utf8", ); const feedbackPanelPath = path.join(accountDir, "AccountFeedbackPanel.tsx"); assert(fs.existsSync(feedbackPanelPath), "account center must ship a My Feedback panel component"); const feedbackPanelSource = fs.readFileSync(feedbackPanelPath, "utf8"); assert( accountCenterSource.includes('import { AccountFeedbackPanel } from "./AccountFeedbackPanel";') && accountCenterSource.includes("= 0 && feedbackFetchIndex >= 0 && sessionLookupIndex < feedbackFetchIndex && feedbackPanelSource.includes("accessToken") && feedbackPanelSource.includes("Authorization: `Bearer ${accessToken}`") && feedbackPanelSource.includes("if (!accessToken)") && feedbackPanelSource.includes("setAvailable(false)"), "account feedback panel must avoid unauthenticated 401 requests by checking the browser session before fetching feedback", ); assert( feedbackPanelSource.includes("reward_points") && feedbackPanelSource.includes("reward_reason") && feedbackPanelSource.includes("reward_status") && feedbackPanelSource.includes("formatRewardPoints") && feedbackPanelSource.includes("renderFeedbackReward") && feedbackPanelSource.includes("奖励原因"), "account feedback panel must show per-feedback reward points and reward reasons", ); }