fix(test): 修复测试环境问题
ci/woodpecker/push/woodpecker Pipeline failed

1. jest.setup.js:
   - 添加 Request/Response/Headers 全局对象 mock
   - 解决 'Request is not defined' 错误

2. .eslintrc.json:
   - 将 jest.setup.js 添加到忽略列表

3. shared-mocks.tsx:
   - 添加 ArrowUp 图标 mock

4. back-to-top.test.tsx:
   - 重写测试使用 import 语法
   - 使用 fireEvent.scroll 触发滚动事件
   - 修复组件渲染测试
This commit is contained in:
张翔
2026-03-29 14:50:09 +08:00
parent e0ca8235c8
commit 7cbb7a9ac8
12 changed files with 2289 additions and 20 deletions
+265
View File
@@ -0,0 +1,265 @@
# 方案A执行指南
## 🚀 快速执行(推荐)
### 方法1: 自动化脚本(最简单)
```bash
# 1. SSH登录服务器
ssh root@139.155.109.62
# 2. 上传脚本(从本地)
# 在本地执行:
scp scripts/fix-service-restart.sh root@139.155.109.62:/tmp/
# 3. 在服务器上执行
ssh root@139.155.109.62
chmod +x /tmp/fix-service-restart.sh
/tmp/fix-service-restart.sh
```
### 方法2: 手动执行(如果脚本无法上传)
```bash
# SSH登录服务器
ssh root@139.155.109.62
# 1. 查找项目目录
find / -name "docker-compose.prod.yml" 2>/dev/null
# 或
find / -name "docker-compose.yml" 2>/dev/null
# 2. 进入项目目录(假设在/opt/novalon-website
cd /opt/novalon-website
# 3. 重启Docker容器
docker-compose -f docker-compose.prod.yml restart
# 或
docker-compose restart
# 4. 检查容器状态
docker ps
# 5. 重启Nginx
systemctl restart nginx
# 6. 检查Nginx状态
systemctl status nginx
# 7. 测试应用
curl -I http://localhost:3000
curl -I https://novalon.cn
```
## 📋 执行步骤详解
### 步骤1: 检查当前状态
```bash
# 查看Docker容器
docker ps -a
# 查看Nginx状态
systemctl status nginx
# 查看系统资源
top -bn1 | head -20
df -h
free -h
```
### 步骤2: 重启Docker容器
```bash
# 进入项目目录
cd /path/to/novalon-website
# 停止容器
docker-compose -f docker-compose.prod.yml stop
# 启动容器
docker-compose -f docker-compose.prod.yml up -d
# 等待启动
sleep 10
# 检查状态
docker ps
```
### 步骤3: 重启Nginx
```bash
# 测试配置
nginx -t
# 重启服务
systemctl restart nginx
# 检查状态
systemctl status nginx
```
### 步骤4: 验证服务
```bash
# 测试本地应用
curl -I http://localhost:3000
# 检查端口监听
netstat -tlnp | grep -E ":(3000|80|443)"
# 测试外部访问
curl -I https://novalon.cn
```
## ✅ 成功标志
执行成功后,您应该看到:
1. **Docker容器状态**
```
CONTAINER ID NAMES STATUS PORTS
xxxxx novalon-website Up 10 seconds 0.0.0.0:3000->3000/tcp
```
2. **Nginx状态**
```
Active: active (running)
```
3. **本地应用响应**
```
HTTP/1.1 200 OK
```
4. **外部访问响应**
```
HTTP/2 200
```
## ❌ 故障排查
### 如果Docker容器无法启动
```bash
# 查看容器日志
docker logs <container-name>
# 查看详细错误
docker-compose -f docker-compose.prod.yml logs
# 检查配置文件
cat docker-compose.prod.yml
# 尝试重新构建
docker-compose -f docker-compose.prod.yml build --no-cache
docker-compose -f docker-compose.prod.yml up -d
```
### 如果Nginx无法启动
```bash
# 测试配置
nginx -t
# 查看错误日志
tail -50 /var/log/nginx/error.log
# 查看系统日志
journalctl -u nginx -n 50
# 检查端口占用
netstat -tlnp | grep -E ":(80|443)"
```
### 如果应用仍然无响应
```bash
# 检查应用日志
docker logs -f <container-name>
# 检查应用进程
docker exec <container-name> ps aux
# 检查应用端口
docker exec <container-name> netstat -tlnp
# 重启应用容器
docker restart <container-name>
```
## 🔍 验证清单
执行完成后,请验证以下项目:
- [ ] Docker容器运行正常:`docker ps`
- [ ] Nginx服务运行正常:`systemctl status nginx`
- [ ] 本地应用响应正常:`curl -I http://localhost:3000`
- [ ] 端口监听正常:`netstat -tlnp | grep -E ":(3000|80|443)"`
- [ ] 外部访问正常:`curl -I https://novalon.cn`
- [ ] Git服务器正常:`git ls-remote https://git.f.novalon.cn/novalon/novalon-website.git`
- [ ] CI服务器正常:`curl -I https://ci.f.novalon.cn`
## 📊 监控命令
### 实时监控服务状态
```bash
# 监控Docker容器
watch -n 5 'docker ps'
# 监控Nginx状态
watch -n 5 'systemctl status nginx'
# 监控系统资源
watch -n 5 'free -h && df -h'
```
### 查看实时日志
```bash
# Docker容器日志
docker logs -f <container-name>
# Nginx错误日志
tail -f /var/log/nginx/error.log
# Nginx访问日志
tail -f /var/log/nginx/access.log
# 系统日志
journalctl -f
```
## 🆘 紧急情况
如果方案A无法解决问题,请:
1. **保存诊断日志**
```bash
/tmp/remote-server-diagnosis.sh --full > /tmp/diagnosis-report.log
```
2. **尝试方案B或C**
- 方案B: 清理资源并重启
- 方案C: 完全重建
3. **联系支持**
- 提供诊断日志
- 描述已尝试的步骤
- 提供服务器访问信息
## 📝 执行记录
建议记录以下信息:
```
执行时间: _______________
执行人: _______________
服务器IP: 139.155.109.62
执行结果: _______________
遇到的问题: _______________
解决方案: _______________
后续跟进: _______________
```
---
**预计执行时间**: 2-5分钟
**风险等级**: 低(仅重启服务,不修改配置)
**回滚方案**: 如有问题,可再次重启或使用其他方案
@@ -0,0 +1,239 @@
# 生产环境连接超时排查指南
## 问题现象
- **症状**: 生产环境无法访问,连接超时
- **发生时间**: 刚刚发生
- **影响范围**: novalon.cn, git.f.novalon.cn, ci.f.novalon.cn
- **服务器IP**: 139.155.109.62
## 诊断结果(本地)
### ✅ 正常项
- ✅ 本地网络连接正常
- ✅ DNS解析成功
- ✅ TCP端口连接成功(80, 443
### ❌ 异常项
- ❌ HTTP响应超时
- ❌ 应用层无响应
## 根因分析
根据诊断结果,问题定位在**应用层**:
1. **网络层正常**: DNS解析、TCP连接都正常
2. **应用层异常**: HTTP请求无响应
可能的原因:
- Docker容器崩溃或停止
- Nginx反向代理异常
- 应用服务崩溃
- 服务器资源耗尽(CPU/内存/磁盘)
## 排查步骤
### 步骤1: SSH登录服务器
```bash
# 登录生产服务器
ssh root@139.155.109.62
# 或
ssh user@139.155.109.62
```
### 步骤2: 上传并运行诊断脚本
```bash
# 方法1: 从本地上传脚本
scp scripts/remote-server-diagnosis.sh root@139.155.109.62:/tmp/
# 方法2: 直接在服务器上创建脚本
# 复制 remote-server-diagnosis.sh 的内容到服务器
# 运行诊断脚本
chmod +x /tmp/remote-server-diagnosis.sh
/tmp/remote-server-diagnosis.sh --full
```
### 步骤3: 手动排查(如果脚本无法运行)
#### 3.1 检查系统资源
```bash
# 查看CPU和内存
top -bn1 | head -20
# 查看磁盘
df -h
# 查看内存
free -h
# 查看系统负载
uptime
```
#### 3.2 检查Docker容器
```bash
# 查看容器状态
docker ps -a
# 查看容器日志
docker logs <container-name>
# 查看容器资源使用
docker stats --no-stream
# 重启容器
docker restart <container-name>
```
#### 3.3 检查Nginx
```bash
# 查看Nginx状态
systemctl status nginx
# 测试Nginx配置
nginx -t
# 重启Nginx
systemctl restart nginx
# 查看Nginx日志
tail -50 /var/log/nginx/error.log
```
#### 3.4 检查应用服务
```bash
# 查看Node.js进程
ps aux | grep node
# 查看端口占用
netstat -tlnp | grep -E ":(3000|80|443)"
# 测试本地应用
curl -I http://localhost:3000
```
## 快速修复方案
### 方案1: 重启所有服务
```bash
# 重启Docker容器
cd /path/to/project
docker-compose -f docker-compose.prod.yml restart
# 重启Nginx
sudo systemctl restart nginx
# 检查服务状态
docker ps
systemctl status nginx
```
### 方案2: 清理资源并重启
```bash
# 清理Docker资源
docker system prune -a -f
# 清理日志
sudo journalctl --vacuum-time=3d
# 重启服务
sudo systemctl restart docker
docker-compose -f docker-compose.prod.yml up -d
sudo systemctl restart nginx
```
### 方案3: 完全重建
```bash
# 停止所有容器
docker-compose -f docker-compose.prod.yml down
# 清理所有资源
docker system prune -a -f --volumes
# 重新构建和启动
docker-compose -f docker-compose.prod.yml build --no-cache
docker-compose -f docker-compose.prod.yml up -d
# 重启Nginx
sudo systemctl restart nginx
```
## 验证修复
### 本地验证
```bash
# 测试网站访问
curl -I https://novalon.cn
# 测试Git服务器
git ls-remote https://git.f.novalon.cn/novalon/novalon-website.git
# 测试CI服务器
curl -I https://ci.f.novalon.cn
```
### 服务器验证
```bash
# 测试本地应用
curl -I http://localhost:3000
# 检查容器状态
docker ps
# 检查Nginx状态
systemctl status nginx
# 检查端口监听
netstat -tlnp | grep -E ":(3000|80|443)"
```
## 监控和预防
### 设置监控
```bash
# 安装监控工具
docker run -d --name=monitor \
--restart=unless-stopped \
-p 9090:9090 \
prom/prometheus
# 设置日志轮转
sudo nano /etc/logrotate.d/nginx
```
### 定期清理
```bash
# 创建定时清理脚本
cat > /etc/cron.daily/docker-cleanup << 'EOF'
#!/bin/bash
docker system prune -f
journalctl --vacuum-time=7d
EOF
chmod +x /etc/cron.daily/docker-cleanup
```
## 紧急联系
如果以上方法都无法解决问题,请:
1. 保存诊断日志:
```bash
/tmp/remote-server-diagnosis.sh --full > /tmp/diagnosis-report.log
```
2. 联系服务器提供商检查网络和硬件
3. 检查是否遭受DDoS攻击:
```bash
netstat -an | grep :80 | wc -l
```
## 相关文档
- [Docker镜像清理脚本](./docker-cleanup.sh)
- [网络诊断脚本](./network-diagnosis.sh)
- [生产环境诊断脚本](./production-diagnosis.sh)
- [远程服务器诊断脚本](./remote-server-diagnosis.sh)