可靠性与数据一致性:为 SQLite、MySQL、PostgreSQL 增加 00017 至 00021 迁移,引入账号暂停时间、默认回复和批量铺货租约、自动化运行恢复、延迟任务、动作检查点与通知 outbox。补强订单、卡密发货、Cookie、批量铺货和自动化任务的原子认领、幂等更新、并发控制、失败分类、重试与进程重启恢复,并扩展跨方言覆盖。 登录与风控恢复:完善扫码、密码登录、Cookie 续期、MTOP token、UA 与 WebSocket 生命周期;加入账号级持久化浏览器目录、Playwright 主引擎和直接 Chromium/CDP 备用引擎、严格的新 x5sec 成功判定、失败控件恢复及真实浏览器集成测试。增加可配置远程滑块服务,在明确失败、链接过期和服务不可用场景中保持既定的本地回退语义。 安全与配置:通过 XIANYU_DATA_KEY 为 Cookie、登录密码、设备与访问令牌、AI/SMTP 密钥及通知配置提供 AES-256-GCM 落库加密和历史明文升级。新增出站网络目标分级、防 DNS rebinding、登录限流、HTTP 客户端超时与 SMTP 目标校验;管理员配置的 AI 服务允许可信内网地址,非可信 Webhook 和远程资源继续限制为公网目标。 自动化与通知:为发货、评价赠送、邀评和回复动作增加断点、租约、延迟执行及人工继续/重试/取消入口;通知改为 outbox 驱动的可恢复投递。同步完善账号运行态、暂停状态、续期冷却、告警审计和异常查询接口。 前端体验:新增风控验证面板、方形二维码、账号运行态合并、暂停状态保护、自动化异常处置、批量铺货状态选择、订单导入结果和最新请求门禁。完善订单搜索与导入、规则编辑、批次恢复、通知与设置页面,并为请求取消、超时、陈旧响应和主要状态转换补充 Vitest 覆盖。 测试与部署:扩展三库功能编排、SQLite 一致性备份、数据卷持久化、浏览器集成镜像、前端类型检查和构建资产分包;功能测试覆盖健康检查、订单、铺货、自动化异常、账号暂停、关键词和系统设置。更新 README 中数据密钥、可信 AI 地址和测试端口说明。 验证结果:go vet ./...、go build ./cmd/server、gofmt 检查、npm run typecheck、npm test(17 个文件、95 个用例)及 npm run build 通过。go test ./... 未完全通过:internal/adapter 仍有 2 个密码续期用例失败,internal/renewal 仍有 4 个浏览器续期调度用例失败;其余 Go 包通过,失败现状随本次既有工作区一并提交。
174 lines
7.4 KiB
TypeScript
174 lines
7.4 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
|
import { resolve } from 'node:path';
|
|
import { describe, expect, test } from 'vitest';
|
|
|
|
const repoRoot = resolve(__dirname);
|
|
|
|
const readFrontendFile = (relativePath: string) =>
|
|
readFileSync(resolve(repoRoot, relativePath), 'utf8');
|
|
|
|
const extractSingleQuotedValues = (source: string, pattern: RegExp) => {
|
|
const values = new Set<string>();
|
|
for (const match of source.matchAll(pattern)) {
|
|
values.add(match[1]);
|
|
}
|
|
return values;
|
|
};
|
|
|
|
describe('frontend navigation routing', () => {
|
|
test('sidebar entries and App activeTab routes stay in sync', () => {
|
|
const sidebar = readFrontendFile('components/Sidebar.tsx');
|
|
const app = readFrontendFile('App.tsx');
|
|
|
|
const sidebarIDs = extractSingleQuotedValues(sidebar, /id:\s*'([^']+)'/g);
|
|
const appRouteIDs = extractSingleQuotedValues(app, /case\s+'([^']+)'/g);
|
|
|
|
expect([...sidebarIDs].sort()).toEqual([...appRouteIDs].sort());
|
|
});
|
|
|
|
test('logout button invalidates the backend session before clearing UI state', () => {
|
|
const app = readFrontendFile('App.tsx');
|
|
|
|
expect(app).toContain('import { login, logout, verifySession }');
|
|
expect(app).toContain('await logout();');
|
|
expect(app).toContain('onLogout={handleLogout}');
|
|
});
|
|
|
|
test('settings page does not expose backend-inactive system controls', () => {
|
|
const settings = readFrontendFile('components/Settings.tsx');
|
|
|
|
expect(settings).not.toContain('允许用户注册');
|
|
expect(settings).not.toContain('显示默认登录信息');
|
|
expect(settings).not.toContain('启用商品自动同步');
|
|
expect(settings).not.toContain('商品同步间隔');
|
|
expect(settings).not.toContain('默认自动回复内容');
|
|
expect(settings).toContain('SETTINGS_SAVE_OMIT_KEYS');
|
|
expect(settings).toContain('保存后需重启服务生效');
|
|
});
|
|
|
|
test('admin-only settings navigation is gated by session role', () => {
|
|
const app = readFrontendFile('App.tsx');
|
|
const sidebar = readFrontendFile('components/Sidebar.tsx');
|
|
const settings = readFrontendFile('components/Settings.tsx');
|
|
|
|
expect(app).toContain('const [isAdmin, setIsAdmin] = useState(false)');
|
|
expect(app).toContain('setIsAdmin(res.is_admin === true)');
|
|
expect(app).toContain("activeTab === 'settings'");
|
|
expect(app).toContain('isAdmin ? <Settings /> : <Dashboard />');
|
|
expect(sidebar).toContain('isAdmin = false');
|
|
expect(sidebar).toContain("...(isAdmin ? [{ id: 'settings'");
|
|
expect(settings).toContain('setLoadError');
|
|
});
|
|
|
|
test('captcha remote settings expose the reference privacy and fallback semantics', () => {
|
|
const settings = readFrontendFile('components/Settings.tsx');
|
|
|
|
expect(settings).toContain('远程过滑块配置');
|
|
expect(settings).toContain("'captcha.remote_service_url'");
|
|
expect(settings).toContain("'captcha.remote_secret_key'");
|
|
expect(settings).toContain("'captcha.remote_pass_cookies'");
|
|
expect(settings).toContain('默认关闭');
|
|
expect(settings).toContain('只有网络不可用或超时才回退本机引擎');
|
|
});
|
|
|
|
test('email notification config uses backend recipient field names', () => {
|
|
const notifications = readFrontendFile('components/Notifications.tsx');
|
|
|
|
expect(notifications).toContain('interface NotificationsProps');
|
|
expect(notifications).toContain('isAdmin && (');
|
|
expect(notifications).toContain("key: 'to_email'");
|
|
expect(notifications).toContain('留空时使用上方系统级 SMTP 配置');
|
|
expect(notifications).not.toContain("key: 'from'");
|
|
expect(notifications).not.toContain('注册验证码');
|
|
});
|
|
|
|
test('keyword reply UI matches contains-based backend behavior', () => {
|
|
const rules = readFrontendFile('components/Rules.tsx');
|
|
|
|
expect(rules).toContain('包含匹配');
|
|
expect(rules).not.toContain('精确匹配');
|
|
expect(rules).not.toContain('模糊包含');
|
|
expect(rules).not.toContain('匹配类型');
|
|
});
|
|
|
|
test('vite proxy does not advertise removed backend routes', () => {
|
|
const vite = readFrontendFile('vite.config.ts');
|
|
|
|
for (const staleRoute of [
|
|
'/backup',
|
|
'/logs',
|
|
'/register',
|
|
'/generate-captcha',
|
|
'/verify-captcha',
|
|
'/geetest',
|
|
'/send-verification-code',
|
|
]) {
|
|
expect(vite).not.toContain(`'${staleRoute}'`);
|
|
}
|
|
});
|
|
|
|
test('item delivery shortcut opens existing automation rule modal', () => {
|
|
const rules = readFrontendFile('components/Rules.tsx');
|
|
const existingRuleBranch = rules.match(/if \(rule\) \{([\s\S]*?)\} else \{/);
|
|
|
|
expect(existingRuleBranch?.[1]).toContain('openAutomationRule(rule)');
|
|
});
|
|
|
|
test('item delivery shortcut is not marked handled before async open completes', () => {
|
|
const rules = readFrontendFile('components/Rules.tsx');
|
|
|
|
expect(rules).not.toContain('handledDeliveryTarget.current = initialDeliveryTarget.requestId');
|
|
expect(rules).toContain('onDeliveryTargetHandled?.();');
|
|
});
|
|
|
|
test('automation editor keeps multiple delivery contents for normal products', () => {
|
|
const rules = readFrontendFile('components/Rules.tsx');
|
|
|
|
expect(rules).toContain('添加发货内容');
|
|
expect(rules).toContain('{displayVariants.map((variant, index) => (');
|
|
expect(rules).toContain(': variants.map(variant => ({');
|
|
expect(rules).not.toContain(': (isMultiSpecRule ? variants : [variants[0]]).map');
|
|
});
|
|
|
|
test('batch publishing help explains card fields without required-field jargon', () => {
|
|
const itemList = readFrontendFile('components/ItemList.tsx');
|
|
|
|
expect(itemList).not.toContain('条件必填');
|
|
expect(itemList).toContain('“付款后发送的卡密”怎么填');
|
|
expect(itemList).toContain('101:1:0;102:2:3');
|
|
expect(itemList).toContain('买家购买 3 件时会发送 6 份');
|
|
});
|
|
|
|
test('item publish image previews revoke object urls', () => {
|
|
const itemList = readFrontendFile('components/ItemList.tsx');
|
|
|
|
expect(itemList).toContain('setPublishImagePreviews');
|
|
expect(itemList).toContain('URL.createObjectURL(file)');
|
|
expect(itemList).toContain('URL.revokeObjectURL(preview.url)');
|
|
expect(itemList).not.toContain('src={URL.createObjectURL(file)}');
|
|
});
|
|
|
|
test('QR verification removes the external link and clearly requires in-app risk verification', () => {
|
|
const accounts = readFrontendFile('components/AccountList.tsx');
|
|
const riskPanel = readFrontendFile('components/RiskVerificationPanel.tsx');
|
|
expect(accounts).not.toContain('href={verificationUrl}');
|
|
expect(accounts).not.toContain('setVerificationUrl');
|
|
expect(accounts).toContain('RiskVerificationPanel');
|
|
expect(riskPanel).toContain('需要完成安全风控验证');
|
|
expect(riskPanel).toContain('请勿在浏览器中打开验证链接');
|
|
expect(riskPanel).toContain('系统会自动检测并刷新登录状态');
|
|
expect(riskPanel).not.toContain('我已在闲鱼 App 完成验证');
|
|
expect(riskPanel).not.toContain('<button');
|
|
expect(riskPanel).not.toContain('重试');
|
|
});
|
|
|
|
test('account editor exposes password-login refresh and never renders its verification URL', () => {
|
|
const accounts = readFrontendFile('components/AccountList.tsx');
|
|
expect(accounts).toContain('passwordLogin({');
|
|
expect(accounts).toContain('checkPasswordLoginStatus(sessionId, controller.signal)');
|
|
expect(accounts).toContain('密码登录刷新授权');
|
|
expect(accounts).toContain('账号已触发平台风控,需要完成人脸识别');
|
|
expect(accounts).not.toContain('result.verification_url');
|
|
});
|
|
});
|