'use strict'; const assert = require('assert'); const fs = require('fs'); const path = require('path'); const root = path.join(__dirname, '..'); const html = fs.readFileSync(path.join(root, 'public', 'index.html'), 'utf8'); const app = fs.readFileSync(path.join(root, 'public', 'app.js'), 'utf8'); const server = fs.readFileSync(path.join(root, 'server.js'), 'utf8'); const operations = fs.readFileSync(path.join(root, 'src', 'routes', 'operations.js'), 'utf8'); const worker = fs.readFileSync(path.join(root, 'src', 'workers', 'task_runner.js'), 'utf8'); assert.match(html, /openRechargeModal\(\)[\s\S]{0,300}runWorkspaceRefund\(\)/, '退款按钮应位于充值按钮右侧'); assert.match(html, /退款母号[\s\S]{0,1500}workspaceRefundCredentialForm\.value/, '设置页应提供退款母号输入框'); assert.match(html, /退款专用代理[\s\S]{0,1000}workspaceRefundCredentialForm\.proxy/, '设置页应提供退款专用代理输入框'); assert(app.includes('workspaceRefundCredentialMeta.proxyConfigured'), '退款前应校验退款专用代理已经配置'); assert(app.includes("this.runTask('workspace_refund'"), '前端应启动独立退款任务'); assert(app.includes('loadWorkspaceRefundCredentialMeta'), '页面初始化应读取退款母号配置状态'); assert(server.includes("/api/workspace-refund-credentials"), '服务端应注册退款母号配置路由'); assert(operations.includes("'workspace_refund'"), '退款任务必须受本机凭据任务保护'); assert.match(operations, /workspace_refund[\s\S]{0,900}threadCount\s*=\s*1/, '退款任务必须由服务端强制固定串行'); assert(worker.includes("case 'workspace_refund':"), 'Worker 应实现退款任务'); assert(worker.includes('waitForRandomRefundSpacing'), '手动退款账号之间必须执行 15-25 秒随机间隔'); assert(worker.includes('proxies: adminCredentials.proxies'), '退款接口请求必须使用独立加密保存的退款代理池'); assert(worker.includes("updateAccountRefundProcessStatus', [email, '已发起']"), '成功后应将独立退款流程状态标记为已发起'); assert(worker.includes("updateAccountRefundProcessStatus', [email, '发起失败']"), '明确失败后应将独立退款流程状态标记为发起失败'); assert(!/case 'workspace_refund':[\s\S]*?updateAccountRefundStatus/.test(worker), '发起退款流程不得修改账号退款字段'); assert(!/currentRefundStatus/.test(worker), '是否执行退款流程不得依赖账号退款状态'); console.log('workspace_refund_feature.test.js: PASS');